Skip to content

Commit 86101c0

Browse files
committed
Improve encoder allocation on tones
Compensates for the spectral leakage and the fact that we don't have an explicit masking curve.
1 parent 3b68a48 commit 86101c0

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

celt/celt_encoder.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ static opus_val16 dynalloc_analysis(const opus_val16 *bandLogE, const opus_val16
991991
int nbEBands, int start, int end, int C, int *offsets, int lsb_depth, const opus_int16 *logN,
992992
int isTransient, int vbr, int constrained_vbr, const opus_int16 *eBands, int LM,
993993
int effectiveBytes, opus_int32 *tot_boost_, int lfe, opus_val16 *surround_dynalloc,
994-
AnalysisInfo *analysis, int *importance, int *spread_weight)
994+
AnalysisInfo *analysis, int *importance, int *spread_weight, opus_val16 tone_freq, opus_val32 toneishness)
995995
{
996996
int i, c;
997997
opus_int32 tot_boost=0;
@@ -1142,6 +1142,20 @@ static opus_val16 dynalloc_analysis(const opus_val16 *bandLogE, const opus_val16
11421142
if (i>=12)
11431143
follower[i] = HALF16(follower[i]);
11441144
}
1145+
/* Compensate for Opus' under-allocation on tones. */
1146+
if (toneishness > QCONST32(.98f, 29)) {
1147+
#ifdef FIXED_POINT
1148+
int freq_bin = PSHR32(MULT16_16(tone_freq, QCONST16(120/M_PI, 9)), 13+9);
1149+
#else
1150+
int freq_bin = (int)floor(.5 + tone_freq*120/M_PI);
1151+
#endif
1152+
for (i=start;i<end;i++) {
1153+
if (freq_bin >= eBands[i] && freq_bin <= eBands[i+1]) follower[i] += QCONST16(2., DB_SHIFT);
1154+
if (freq_bin >= eBands[i]-1 && freq_bin <= eBands[i+1]+1) follower[i] += QCONST16(1., DB_SHIFT);
1155+
if (freq_bin >= eBands[i]-2 && freq_bin <= eBands[i+1]+2) follower[i] += QCONST16(1., DB_SHIFT);
1156+
if (freq_bin >= eBands[i]-3 && freq_bin <= eBands[i+1]+3) follower[i] += QCONST16(.5, DB_SHIFT);
1157+
}
1158+
}
11451159
#ifdef DISABLE_FLOAT_API
11461160
(void)analysis;
11471161
#else
@@ -2068,7 +2082,7 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm,
20682082

20692083
maxDepth = dynalloc_analysis(bandLogE, bandLogE2, oldBandE, nbEBands, start, end, C, offsets,
20702084
st->lsb_depth, mode->logN, isTransient, st->vbr, st->constrained_vbr,
2071-
eBands, LM, effectiveBytes, &tot_boost, st->lfe, surround_dynalloc, &st->analysis, importance, spread_weight);
2085+
eBands, LM, effectiveBytes, &tot_boost, st->lfe, surround_dynalloc, &st->analysis, importance, spread_weight, tone_freq, toneishness);
20722086

20732087
ALLOC(tf_res, nbEBands, int);
20742088
/* Disable variable tf resolution for hybrid and at very low bitrate */

0 commit comments

Comments
 (0)