MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / SetupEncoder

Function SetupEncoder

AudioEncode/aencode.cpp:647–693  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

645}
646
647int SetupEncoder(Encoder &enc, int someVal, float std_lo_filter[], float std_hi_filter[], int8_t levels,
648 int samples_per_subband) {
649 enc.m_someVal = someVal;
650 enc.m_lo_filter = std_lo_filter;
651 enc.m_hi_filter = std_hi_filter;
652 enc.m_levels = levels;
653 enc.m_numColumns = 1 << levels;
654 enc.m_samples_per_subband = samples_per_subband;
655 enc.m_samplesPerBlock = samples_per_subband * enc.m_numColumns;
656
657 int adjustedSomeVal = (((someVal < -1) ? (someVal + 1) : (someVal)) + 1) >> 1;
658 enc.m_adjustedSamplesTimeNumColumns = adjustedSomeVal * (enc.m_numColumns - 1);
659 enc.m_levelSlots = reinterpret_cast<float **>(malloc(sizeof(float *) * (levels + 1)));
660 if (enc.m_levelSlots == NULL)
661 return 0;
662
663 if (levels >= 0) {
664 for (int8_t i = 0; i <= levels; ++i) {
665 int extraSamples = 0;
666 if (i != levels) {
667 extraSamples = (someVal - 1) << i;
668 }
669
670 float *blockData = reinterpret_cast<float *>(malloc((enc.m_samplesPerBlock + extraSamples) * sizeof(float)));
671 enc.m_levelSlots[i] = blockData;
672 if (blockData == NULL)
673 return 0;
674
675 memset(blockData, 0, (enc.m_samplesPerBlock + extraSamples) * sizeof(float));
676 enc.m_levelSlots[i] += extraSamples;
677 }
678 }
679
680 enc.m_pFormatIdPerColumn = reinterpret_cast<uint32_t *>(malloc(enc.m_numColumns * sizeof(uint32_t)));
681 if (enc.m_pFormatIdPerColumn == NULL)
682 return 0;
683
684 enc.m_sampleCount = 0;
685
686 int32_t edxOffset =
687 ((enc.m_samplesPerBlock * sizeof(float) * 25) - enc.m_adjustedSamplesTimeNumColumns) % enc.m_samplesPerBlock;
688 enc.m_pCurrBlockData = enc.m_levelSlots[0] + edxOffset;
689 enc.m_blockSamplesRemaining = enc.m_samplesPerBlock - edxOffset;
690 enc.m_bandWriteEnabled = 0;
691 enc.m_finishedReading = 0;
692 return 1;
693}
694
695void DestroyEncoder(Encoder &enc) {
696 if (enc.m_levelSlots != NULL) {

Callers 1

AudioEncodeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected