tuning and cleanup

This commit is contained in:
Christian R. Helmrich 2020-02-28 22:00:06 +01:00
parent c3f793aaeb
commit a88a515d31

View File

@ -676,14 +676,16 @@ uint8_t SfbQuantizer::quantizeSpecSfb (EntropyCoder& entropyCoder, const int32_t
if ((sfBest < sfCurr) && (sfBest != sfIndexPred) && rdOptimQuant) // R/D re-optimization if ((sfBest < sfCurr) && (sfBest != sfIndexPred) && rdOptimQuant) // R/D re-optimization
{ {
#if EC_TRELLIS_OPT_CODING
const double refSfbNmrDiv = m_lutSfNorm[sfCurr];
const double lambda = getLagrangeValue (m_rateIndex);
#endif
sfCurr = quantizeMagnSfb (coeffMagn, sfCurr - 1, ptrCurr, sfbWidth, sfCurr = quantizeMagnSfb (coeffMagn, sfCurr - 1, ptrCurr, sfbWidth,
#if EC_TRELLIS_OPT_CODING #if EC_TRELLIS_OPT_CODING
entrCoder, sfbStart - grpStart, entrCoder, sfbStart - grpStart,
#endif #endif
&maxQCurr, &numQCurr); &maxQCurr, &numQCurr);
if (maxQCurr <= maxQBest)
{
distCurr = getQuantDist (coeffMagn, sfCurr, ptrCurr, sfbWidth); distCurr = getQuantDist (coeffMagn, sfCurr, ptrCurr, sfbWidth);
if (quantCoeffs) if (quantCoeffs)
{ {
@ -694,30 +696,24 @@ uint8_t SfbQuantizer::quantizeSpecSfb (EntropyCoder& entropyCoder, const int32_t
numQCurr += getBitCount (entropyCoder, sfCurr, sfIndexPred, grpLength, &quantCoeffs[grpStart], sfbStart - grpStart, sfbWidth); numQCurr += getBitCount (entropyCoder, sfCurr, sfIndexPred, grpLength, &quantCoeffs[grpStart], sfbStart - grpStart, sfbWidth);
} }
// rate-distortion decision with empirical Lagrange value // rate-distortion decision, using empirical Lagrange value
#if EC_TRELLIS_OPT_CODING #if EC_TRELLIS_OPT_CODING
if (distCurr + getLagrangeValue (m_rateIndex) * numQCurr < distBest + getLagrangeValue (m_rateIndex) * numQBest) if (distCurr * refSfbNmrDiv * refSfbNmrDiv + lambda * numQCurr < distBest * refSfbNmrDiv * refSfbNmrDiv + lambda * numQBest)
#else #else
if ((numQCurr <= numQBest + (distCurr >= distBest ? -1 : short (0.5 + distBest / __max (1.0, distCurr))))) if ((maxQCurr <= maxQBest) && (numQCurr <= numQBest + (distCurr >= distBest ? -1 : short (0.5 + distBest / __max (1.0, distCurr)))))
#endif #endif
{ {
uint8_t* ptrTemp = ptrBest;
ptrBest = ptrCurr;
ptrCurr = ptrTemp;
distBest = distCurr;
maxQBest = maxQCurr; maxQBest = maxQCurr;
numQBest = numQCurr; numQBest = numQCurr;
sfBest = sfCurr; sfBest = sfCurr;
} }
else if (quantCoeffs) // discard result, recover best try else if (quantCoeffs) // discard result, recover best trial
{ {
memcpy (&quantCoeffs[sfbStart], ptrBest, cpyWidth); memcpy (&quantCoeffs[sfbStart], ptrBest, cpyWidth);
entropyCoder.arithSetCodState (codFinal); // set state entropyCoder.arithSetCodState (codFinal); // reset state
entropyCoder.arithSetCtxState (ctxFinal); entropyCoder.arithSetCtxState (ctxFinal);
} }
} // if (maxQCurr <= maxQBest)
} }
if (grpStats) if (grpStats)