From 1e41f6702633f14e631ab9a42786a48515ba79ad Mon Sep 17 00:00:00 2001 From: "Christian R. Helmrich" Date: Thu, 11 Jun 2020 00:00:07 +0200 Subject: [PATCH] more rate reduction --- src/lib/exhaleEnc.cpp | 3 ++- src/lib/specGapFilling.cpp | 29 +++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/lib/exhaleEnc.cpp b/src/lib/exhaleEnc.cpp index 639342f..a347ebb 100644 --- a/src/lib/exhaleEnc.cpp +++ b/src/lib/exhaleEnc.cpp @@ -759,7 +759,8 @@ unsigned ExhaleEncoder::psychBitAllocation () // perceptual bit-allocation via s 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 uint64_t scaleSr = (samplingRate < 27713 ? (samplingRate < 24000 ? 32 : 34) - m_bitRateMode : 37) - (nChannels >> 1); - const uint64_t scaleBr = (m_bitRateMode == 0 ? 4 + (samplingRate >> 10) : scaleSr - eightTimesSqrt256Minus[256 - m_bitRateMode] - __min (3, (m_bitRateMode - 1) >> 1)); + const uint64_t scaleBr = (m_bitRateMode == 0 ? __min (38, 3 + (samplingRate >> 10) + (samplingRate >> 13)) - (nChannels >> 1) + : 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]; //uint8_t meanTempFlat[USAC_MAX_NUM_CHANNELS]; diff --git a/src/lib/specGapFilling.cpp b/src/lib/specGapFilling.cpp index 384afbd..51a0b26 100644 --- a/src/lib/specGapFilling.cpp +++ b/src/lib/specGapFilling.cpp @@ -21,6 +21,16 @@ SpecGapFiller::SpecGapFiller () memset (m_1stNonZeroSfb, 0, sizeof (m_1stNonZeroSfb)); } +#if SGF_SF_PEAK_SMOOTHING +static const unsigned smallDeltaHuffBitCount[15] = {8, 7, 6, 6, 5, 4, 3, 1, 4, 4, 5, 6, 6, 7, 7}; + +static inline unsigned huffBitCountEstimate (const int scaleFactorDelta) +{ + if (abs (scaleFactorDelta) < 8) return smallDeltaHuffBitCount[scaleFactorDelta + 7]; + return (abs (scaleFactorDelta) >> 1) + 4; +} +#endif + // public functions uint8_t SpecGapFiller::getSpecGapFillParams (const SfbQuantizer& sfbQuantizer, const uint8_t* const quantMagn, const uint8_t numSwbShort, SfbGroupData& grpData /*modified*/, @@ -239,16 +249,31 @@ uint8_t SpecGapFiller::getSpecGapFillParams (const SfbQuantizer& sfbQuantizer, c for (x = start + 1; x < sfbsPerGrp; x++) { - const int32_t xZ = size * (x - start) - xSum; // zero-mean + const int32_t xZ = size * (x - start) - xSum; // zero-mean + a += xZ * xZ; b += xZ * (size * grpScFacs[x] - ySum); } if (a > 0) // complete line and adjust gap-fill scale factors { + unsigned countOld = 0, countNew = 0; + b = CLIP_PM (((b << 8) + (a >> 1)) / a, SHRT_MAX); a = ((ySum << 8) - b * xSum + (size >> 1)) / size; - for (x = start + 1; x < sfbsPerGrp; x++) grpScFacs[x] = CLIP_UCHAR ((a + b * (x - start) - SCHAR_MIN) >> 8); + ySum = grpScFacs[start]; + for (x = start + 1; x < sfbsPerGrp; x++) + { + const int32_t y = CLIP_UCHAR ((a + b * (x - start) - SCHAR_MIN) >> 8); + + countOld += huffBitCountEstimate ((int) grpScFacs[x] - grpScFacs[x - 1]); + countNew += huffBitCountEstimate (y - ySum); + ySum = y; + } + if (countNew < countOld) + { + for (x = start + 1; x < sfbsPerGrp; x++) grpScFacs[x] = CLIP_UCHAR ((a + b * (x - start) - SCHAR_MIN) >> 8); + } } } #endif