mirror of
https://gitlab.com/ecodis/exhale.git
synced 2025-06-05 21:59:32 +02:00
tuning, cleanup
This commit is contained in:
@ -235,22 +235,12 @@ static inline uint8_t brModeAndFsToMaxSfbShort(const unsigned bitRateMode, const
|
||||
return (samplingRate > 51200 ? 11 : 13) - 2 + (bitRateMode >> 2);
|
||||
}
|
||||
|
||||
#if SA_IMPROVED_REAL_ABS
|
||||
static inline uint32_t squareMeanRoot (const uint32_t value1, const uint32_t value2)
|
||||
{
|
||||
const double meanRoot = (sqrt ((double) value1) + sqrt ((double) value2)) * 0.5;
|
||||
|
||||
return uint32_t (meanRoot * meanRoot + 0.5);
|
||||
}
|
||||
#else
|
||||
static inline uint32_t getComplexRmsValue (const uint32_t rmsValue, const unsigned sfbGroup, const unsigned sfbIndex,
|
||||
const uint8_t numSwb, const TnsData& tnsData)
|
||||
{
|
||||
// compensate for missing MDST coefficients in RMS calculation of SFBs where TNS is active
|
||||
return ((tnsData.numFilters > 0) && (sfbGroup == tnsData.filteredWindow) && (rmsValue <= UINT_MAX / 5) &&
|
||||
(tnsData.filterLength[0] + sfbIndex >= numSwb) ? (rmsValue * 5u) >> 2 : rmsValue);
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline uint8_t stereoCorrGrouping (const SfbGroupData& grpData, const unsigned nSamplesInFrame, uint8_t* stereoCorrData)
|
||||
{
|
||||
@ -520,17 +510,12 @@ unsigned ExhaleEncoder::applyTnsToWinGroup (TnsData& tnsData, SfbGroupData& grpD
|
||||
return errorValue;
|
||||
}
|
||||
|
||||
unsigned ExhaleEncoder::eightShortGrouping (SfbGroupData& grpData, uint16_t* const grpOffsets, int32_t* const mdctSignal
|
||||
#if SA_IMPROVED_REAL_ABS
|
||||
, int32_t* const mdstSignal /*= nullptr*/
|
||||
#endif
|
||||
)
|
||||
unsigned ExhaleEncoder::eightShortGrouping (SfbGroupData& grpData, uint16_t* const grpOffsets, int32_t* const mdctSignal,
|
||||
int32_t* const mdstSignal /*= nullptr*/)
|
||||
{
|
||||
const unsigned nSamplesInFrame = toFrameLength (m_frameLength);
|
||||
const unsigned nSamplesInShort = nSamplesInFrame >> 3;
|
||||
#if SA_IMPROVED_REAL_ABS
|
||||
int32_t* const tempIntBuf/*2*/ = m_timeSignals[1]; // NOTE: requires at least stereo input
|
||||
#endif
|
||||
unsigned grpStartLine = nSamplesInFrame;
|
||||
|
||||
if ((grpOffsets == nullptr) || (mdctSignal == nullptr))
|
||||
@ -543,9 +528,8 @@ unsigned ExhaleEncoder::eightShortGrouping (SfbGroupData& grpData, uint16_t* con
|
||||
const unsigned grpLength = grpData.windowGroupLength[gr];
|
||||
uint16_t* const grpOffset = &grpOffsets[m_numSwbShort * gr];
|
||||
int32_t* const grpMdctSig = &mdctSignal[grpStartLine -= nSamplesInShort * grpLength];
|
||||
#if SA_IMPROVED_REAL_ABS
|
||||
int32_t* const grpMdstSig = (mdstSignal != nullptr ? &mdstSignal[grpStartLine] : nullptr);
|
||||
#endif
|
||||
|
||||
for (uint16_t b = 0; b < m_numSwbShort; b++)
|
||||
{
|
||||
const unsigned swbOffset = grpOffsets[b];
|
||||
@ -557,24 +541,21 @@ unsigned ExhaleEncoder::eightShortGrouping (SfbGroupData& grpData, uint16_t* con
|
||||
for (uint16_t w = 0; w < grpLength; w++)
|
||||
{
|
||||
memcpy (&m_tempIntBuf[grpOffset[b] + w * numCoeffs], &grpMdctSig[swbOffset + w * nSamplesInShort], numCoeffs * sizeof (int32_t));
|
||||
#if SA_IMPROVED_REAL_ABS
|
||||
if (grpMdstSig != nullptr)
|
||||
{
|
||||
memcpy (&tempIntBuf[grpOffset[b] + w * numCoeffs], &grpMdstSig[swbOffset + w * nSamplesInShort], numCoeffs * sizeof (int32_t));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
grpOffset[m_numSwbShort] = uint16_t (grpStartLine + nSamplesInShort * grpLength);
|
||||
} // for gr
|
||||
|
||||
memcpy (mdctSignal, m_tempIntBuf, nSamplesInFrame * sizeof (int32_t));
|
||||
#if SA_IMPROVED_REAL_ABS
|
||||
if (mdstSignal != nullptr)
|
||||
{
|
||||
memcpy (mdstSignal, tempIntBuf, nSamplesInFrame * sizeof (int32_t));
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0; // no error
|
||||
}
|
||||
|
||||
@ -598,7 +579,6 @@ unsigned ExhaleEncoder::getOptParCorCoeffs (const int32_t* const mdctSignal, con
|
||||
{
|
||||
tnsData.filterOrder[0] = (uint8_t) m_specAnalyzer.getLinPredCoeffs (tnsData.coeffParCor, channelIndex);
|
||||
|
||||
#if EE_OPT_TNS_SPEC_RANGE
|
||||
if (tnsData.filterOrder[0] > 0) // try to reduce TNS start band as long as SNR increases
|
||||
{
|
||||
const uint16_t filtOrder = tnsData.filterOrder[0];
|
||||
@ -651,7 +631,7 @@ unsigned ExhaleEncoder::getOptParCorCoeffs (const int32_t* const mdctSignal, con
|
||||
}
|
||||
m_specAnaCurr[channelIndex] = (m_specAnaCurr[channelIndex] & (UINT_MAX - 31)) | (b + 1);
|
||||
} // if order > 0
|
||||
#endif // EE_OPT_TNS_SPEC_RANGE
|
||||
|
||||
return (m_specAnaCurr[channelIndex] >> 24) & UCHAR_MAX; // spectral analyzer's pred gain
|
||||
}
|
||||
// SHORT window: find short group with maximum pred gain, then determine best filter order
|
||||
@ -692,8 +672,8 @@ unsigned ExhaleEncoder::psychBitAllocation () // perceptual bit-allocation via s
|
||||
const unsigned samplingRate = toSamplingRate (m_frequencyIdx);
|
||||
const unsigned lfeChannelIndex = (m_channelConf >= CCI_6_CH ? __max (5, nChannels - 1) : USAC_MAX_NUM_CHANNELS);
|
||||
const uint32_t maxSfbLong = (samplingRate < 37566 ? 51 /*32 kHz*/ : brModeAndFsToMaxSfbLong (m_bitRateMode, samplingRate));
|
||||
const uint32_t reductionFactor = (samplingRate < 37566 ? 2 : 3); // undercoding reduction
|
||||
const uint64_t scaleSr = (samplingRate < 27713 ? 37 - m_bitRateMode : 37) - (m_bitRateMode > 2 ? nChannels >> 1 : 0);
|
||||
const uint32_t reductionFactor = (m_bitRateMode < 3 ? 2 : 3); // for undercoding reduction
|
||||
const uint64_t scaleSr = (samplingRate < 27713 ? 37 - m_bitRateMode : 37) - (m_bitRateMode > 1 ? nChannels >> 1 : 0);
|
||||
const uint64_t scaleBr = (m_bitRateMode == 0 ? 32 : scaleSr - eightTimesSqrt256Minus[256 - m_bitRateMode] - __min (3, (m_bitRateMode - 1) >> 1));
|
||||
uint32_t* sfbStepSizes = (uint32_t*) m_tempIntBuf;
|
||||
uint8_t meanSpecFlat[USAC_MAX_NUM_CHANNELS];
|
||||
@ -857,23 +837,16 @@ unsigned ExhaleEncoder::psychBitAllocation () // perceptual bit-allocation via s
|
||||
const uint32_t* refRms = &coreConfig.groupingData[1 - ch].sfbRmsValues[m_numSwbShort * gr];
|
||||
uint8_t* grpScaleFacs = &grpData.scaleFactors[m_numSwbShort * gr];
|
||||
uint32_t* grpStepSizes = &stepSizes[m_numSwbShort * gr];
|
||||
#if SA_IMPROVED_REAL_ABS
|
||||
uint8_t* grpStereoData = &coreConfig.stereoDataCurr[m_numSwbShort * gr];
|
||||
#endif
|
||||
uint32_t b, grpRmsMin = INT_MAX; // min. RMS value, used for overcoding reduction
|
||||
|
||||
// undercoding reduction for case where large number of coefs is quantized to zero
|
||||
s = (eightShorts ? (nSamplesInFrame * grpData.windowGroupLength[gr]) >> 1 : nSamplesInFrame << 2);
|
||||
for (b = 0; b < maxSfbCh; b++)
|
||||
{
|
||||
#if SA_IMPROVED_REAL_ABS
|
||||
const uint32_t rmsComp = (grpStereoData[b] > 0 ? squareMeanRoot (refRms[b], grpRms[b]) : grpRms[b]);
|
||||
const uint32_t rmsRef9 = (coreConfig.commonWindow ? refRms[b] >> 9 : rmsComp);
|
||||
#else
|
||||
const uint32_t rmsComp = getComplexRmsValue (grpRms[b], gr, b, numSwbCh, coreConfig.tnsData[ch]);
|
||||
const uint32_t rmsRef9 = (!coreConfig.commonWindow ? rmsComp :
|
||||
getComplexRmsValue (refRms[b], gr, b, numSwbCh, coreConfig.tnsData[1 - ch]) >> 9);
|
||||
#endif
|
||||
|
||||
if (grpRms[b] < grpRmsMin) grpRmsMin = grpRms[b];
|
||||
#ifndef NO_DTX_MODE
|
||||
if ((m_bitRateMode > 3) || (meanSpecFlat[ci] > (SCHAR_MAX >> 1)) || (rmsComp >= TA_EPS))
|
||||
@ -885,14 +858,8 @@ unsigned ExhaleEncoder::psychBitAllocation () // perceptual bit-allocation via s
|
||||
}
|
||||
if ((samplingRate >= 27713) && (b < maxSfbLong) && !eightShorts) // uncoded coefs
|
||||
{
|
||||
#if SA_IMPROVED_REAL_ABS
|
||||
const uint32_t rmsComp = (grpStereoData[b] > 0 ? squareMeanRoot (refRms[b], grpRms[b]) : grpRms[b]);
|
||||
const uint32_t rmsRef9 = (coreConfig.commonWindow ? refRms[b] >> 9 : rmsComp);
|
||||
#else
|
||||
const uint32_t rmsComp = getComplexRmsValue (grpRms[b], gr, b, numSwbCh, coreConfig.tnsData[ch]);
|
||||
const uint32_t rmsRef9 = (!coreConfig.commonWindow ? rmsComp :
|
||||
getComplexRmsValue (refRms[b], gr, b, numSwbCh, coreConfig.tnsData[1 - ch]) >> 9);
|
||||
#endif
|
||||
#ifndef NO_DTX_MODE
|
||||
if ((m_bitRateMode > 3) || (meanSpecFlat[ci] > (SCHAR_MAX >> 1)) || (rmsComp >= TA_EPS))
|
||||
#endif
|
||||
@ -1353,11 +1320,8 @@ unsigned ExhaleEncoder::spectralProcessing () // complete ics_info(), calc TNS
|
||||
memcpy (grpData.windowGroupLength, windowGroupingTable[icsCurr.windowGrouping], NUM_WINDOW_GROUPS * sizeof (uint8_t));
|
||||
#endif
|
||||
while (grpSO[icsCurr.maxSfb] > __max (m_bandwidCurr[ci], m_bandwidPrev[ci])) icsCurr.maxSfb--; // not a bug!!
|
||||
#if SA_IMPROVED_REAL_ABS
|
||||
|
||||
errorValue |= eightShortGrouping (grpData, grpSO, m_mdctSignals[ci], nChannels < 2 ? nullptr : m_mdstSignals[ci]);
|
||||
#else
|
||||
errorValue |= eightShortGrouping (grpData, grpSO, m_mdctSignals[ci]);
|
||||
#endif
|
||||
} // if EIGHT_SHORT
|
||||
|
||||
// compute and quantize optimal TNS coefficients, then find optimal TNS filter order
|
||||
@ -1384,7 +1348,7 @@ unsigned ExhaleEncoder::spectralProcessing () // complete ics_info(), calc TNS
|
||||
|
||||
if ((coreConfig.tnsData[0].filteredWindow == coreConfig.tnsData[1].filteredWindow) &&
|
||||
(abs (specFlat[0] - specFlat[1]) <= (UCHAR_MAX >> 3)) &&
|
||||
(abs (tnsStart[0] - tnsStart[1]) <= (UCHAR_MAX >> 5))) // TNS synchronization
|
||||
(abs (tnsStart[0] - tnsStart[1]) <= (UCHAR_MAX >> 4))) // TNS synchronization
|
||||
{
|
||||
const uint16_t maxTnsOrder = __max (coreConfig.tnsData[0].filterOrder[0], coreConfig.tnsData[1].filterOrder[0]);
|
||||
TnsData& tnsData0 = coreConfig.tnsData[0];
|
||||
@ -1460,7 +1424,6 @@ unsigned ExhaleEncoder::spectralProcessing () // complete ics_info(), calc TNS
|
||||
if (icsCurr.maxSfb > 0)
|
||||
{
|
||||
// use MCLTs for LONG but only MDCTs for SHORT windows when the MDSTs aren't grouped
|
||||
#if SA_IMPROVED_REAL_ABS
|
||||
for (uint16_t gr = 0; gr < grpData.numWindowGroups; gr++)
|
||||
{
|
||||
s = m_numSwbShort * gr;
|
||||
@ -1468,10 +1431,6 @@ unsigned ExhaleEncoder::spectralProcessing () // complete ics_info(), calc TNS
|
||||
grpSO[grpData.sfbsPerGroup + s], (eightShorts ? USAC_MAX_NUM_CHANNELS : ci),
|
||||
&grpSO[s], grpData.sfbsPerGroup, &grpData.sfbRmsValues[s]);
|
||||
}
|
||||
#else
|
||||
errorValue |= m_specAnalyzer.getMeanAbsValues (m_mdctSignals[ci], eightShorts ? nullptr : m_mdstSignals[ci], nSamplesInFrame,
|
||||
ci, grpSO, grpData.sfbsPerGroup * grpData.numWindowGroups, grpData.sfbRmsValues);
|
||||
#endif
|
||||
errorValue |= applyTnsToWinGroup (coreConfig.tnsData[ch], grpData, eightShorts, grpData.sfbsPerGroup, ci);
|
||||
coreConfig.tnsActive |= (coreConfig.tnsData[ch].numFilters > 0); // tns_data_present
|
||||
}
|
||||
|
@ -26,7 +26,6 @@
|
||||
|
||||
// constant and experimental macro
|
||||
#define WIN_SCALE double (1 << 23)
|
||||
#define EE_OPT_TNS_SPEC_RANGE 1
|
||||
|
||||
// channelConfigurationIndex setup
|
||||
typedef enum USAC_CCI : char
|
||||
@ -118,11 +117,8 @@ private:
|
||||
// helper functions
|
||||
unsigned applyTnsToWinGroup (TnsData& tnsData, SfbGroupData& grpData, const bool eightShorts, const uint8_t maxSfb,
|
||||
const unsigned channelIndex);
|
||||
unsigned eightShortGrouping (SfbGroupData& grpData, uint16_t* const grpOffsets, int32_t* const mdctSignal
|
||||
#if SA_IMPROVED_REAL_ABS
|
||||
, int32_t* const mdstSignal = nullptr
|
||||
#endif
|
||||
);
|
||||
unsigned eightShortGrouping (SfbGroupData& grpData, uint16_t* const grpOffsets, int32_t* const mdctSignal,
|
||||
int32_t* const mdstSignal = nullptr);
|
||||
unsigned getOptParCorCoeffs (const int32_t* const mdctSignal, const SfbGroupData& grpData, const uint8_t maxSfb,
|
||||
const unsigned channelIndex, TnsData& tnsData, const uint8_t firstGroupIndexToTest = 0);
|
||||
unsigned psychBitAllocation ();
|
||||
|
@ -120,7 +120,6 @@ unsigned SpecAnalyzer::getMeanAbsValues (const int32_t* const mdctSignal, const
|
||||
const unsigned bandOffset = __min (nSamplesInFrame, bandStartOffsets[b]);
|
||||
const unsigned bandWidth = __min (nSamplesInFrame, bandStartOffsets[b + 1]) - bandOffset;
|
||||
const int32_t* const bMdct = &mdctSignal[bandOffset];
|
||||
#if SA_IMPROVED_REAL_ABS
|
||||
uint64_t sumAbsVal = (bandStartOffsets[b + 1] == nSamplesInFrame ? abs (bMdct[bandWidth - 1]) : 0);
|
||||
|
||||
for (int s = bandWidth - (bandStartOffsets[b + 1] == nSamplesInFrame ? 2 : 1); s >= 0; s--)
|
||||
@ -140,14 +139,6 @@ unsigned SpecAnalyzer::getMeanAbsValues (const int32_t* const mdctSignal, const
|
||||
sumAbsVal -= (absReal > absEstIm ? absReal + ((absEstIm * 3) >> 3) : absEstIm + ((absReal * 3) >> 3));
|
||||
sumAbsVal += absReal;
|
||||
}
|
||||
#else
|
||||
uint64_t sumAbsVal = 0;
|
||||
|
||||
for (int s = bandWidth - 1; s >= 0; s--)
|
||||
{
|
||||
sumAbsVal += abs (bMdct[s]);
|
||||
}
|
||||
#endif
|
||||
// average spectral sample magnitude across frequency band
|
||||
meanBandValues[b] = uint32_t ((sumAbsVal + (bandWidth >> 1)) / bandWidth);
|
||||
} // for b
|
||||
|
@ -19,7 +19,6 @@
|
||||
#define SA_BW (1 << SA_BW_SHIFT)
|
||||
#define SA_EPS 1024
|
||||
#define SA_EXACT_COMPLEX_ABS 0
|
||||
#define SA_IMPROVED_REAL_ABS 1
|
||||
#define SA_IMPROVED_SFM_ESTIM 1
|
||||
#define SA_OPT_WINDOW_GROUPING 1
|
||||
|
||||
|
Reference in New Issue
Block a user