fix for 8 and 64 kHz

This commit is contained in:
Christian R. Helmrich 2020-09-28 11:00:00 +02:00
parent e9bd99bf84
commit 9323a9d0e8
3 changed files with 12 additions and 8 deletions

View File

@ -12,11 +12,11 @@
#include "loudnessEstim.h"
#if LE_ACCURATE_CALC
static const int64_t kFilterCoeffs[4][8] = { // first 4: numerator, last 4: denominator, values fit into 32 bit
{ -974848000, 1329463296, -808124416, 185073664, -946145526, 1253229580, -741406522, 165888320}, // <=32 kHz
{-1007157248, 1418657792, -889585664, 209649664, -986120192, 1360482752, -836214568, 193416912}, // 44.1 kHz
{-1007547085, 1419341519, -889783607, 209553717, -988032194, 1365543311, -840618073, 194671779}, // 48.0 kHz
{-1007547085, 1419341519, -889783607, 209553717, -988032194, 1365543311, -840618073, 194671779} // >=64 kHz TODO
static const int64_t kFilterCoeffs[4][8] = { // first 4: numerator (16->-32 bit), last 4: denominator (32 bit)
{ -974848000, 1329463296, -808124416, 185073664, -946145519, 1253229559, -741406502, 165888314}, // <=32 k
{-1001717760, 1403125760, -874840064, 204996608, -980574000, 1345222905, -822320842, 189236866}, // 44.1 k
{-1007550464, 1419378688, -889847808, 209584128, -988032194, 1365543311, -840618073, 194671779}, // 48.0 k
{-1024000000, 1465647104, -933036032, 222953472, -1009281050, 1424244875, -894338686, 210939497} // >=64 k
};
#endif
@ -26,7 +26,7 @@ LoudnessEstimator::LoudnessEstimator (int32_t* const inputPcmData, con
{
#if LE_ACCURATE_CALC
m_filterCoeffs = kFilterCoeffs[sampleRate <= 44100 ? (sampleRate <= 32000 ? 0 : 1) : (sampleRate <= 48000 ? 2 : 3)];
m_filterFactor = (sampleRate < 48000 ? (48200 - sampleRate) >> 12 : 0);
m_filterFactor = (sampleRate < 48000 ? (48200 - sampleRate) >> 12 : (48000 - sampleRate) >> 14);
#else
m_filterFactor = 224 + (__min (SHRT_MAX, (int) sampleRate - 47616) >> 10);
#endif

View File

@ -40,7 +40,11 @@ private:
#endif
uint64_t m_powerValue[4][8]; // channel-wise power in each gating block quarter
float m_gbNormFactor; // 64-sample normalization factor, 1/(4*m_gbHopSize64)
#if LE_ACCURATE_CALC
int8_t m_filterFactor; // sampling rate dependent K-weighting filter constant
#else
uint8_t m_filterFactor; // sampling rate dependent K-weighting filter constant
#endif
uint8_t m_gbHopLength64; // number of 64-sample units in gating block quarter
uint8_t m_gbHopSize64; // hop-size between gating blocks, 25% of block length
uint8_t m_inputChannels;

View File

@ -213,7 +213,7 @@ uint8_t SfbQuantizer::quantizeMagnSfb (const unsigned* const coeffMagn, const ui
{
const double normalizedMagn = (double) coeffMagn[i] * magnNormDiv;
dNum += normalizedMagn * normalizedMagn; // TODO: use SIMD?
dNum += normalizedMagn * normalizedMagn;
}
if (dNum > SF_THRESH_POS * SF_THRESH_POS * dDen) sf++;
@ -520,7 +520,7 @@ unsigned SfbQuantizer::initQuantMemory (const unsigned maxTransfLength,
{
const unsigned numScaleFactors = (unsigned) maxScaleFacIndex + 1;
#if EC_TRELLIS_OPT_CODING
const uint8_t complexityOffset = (samplingRate < 28800 ? 8 - (samplingRate >> 13) : 5) + (bitRateMode == 0 ? 1 : 0);
const uint8_t complexityOffset = (samplingRate < 28800 ? 8 - (samplingRate >> 13) : 5) + ((bitRateMode == 0) && (samplingRate >= 8192) ? 1 : 0);
const uint8_t numTrellisStates = complexityOffset - __min (2, (bitRateMode + 2) >> 2); // number of states per SFB
const uint8_t numSquaredStates = numTrellisStates * numTrellisStates;
const uint16_t quantRateLength = (samplingRate < 28800 || samplingRate >= 57600 ? 512 : 256); // quantizeMagnRDOC()