@@ -991,7 +991,7 @@ static opus_val16 dynalloc_analysis(const opus_val16 *bandLogE, const opus_val16
991
991
int nbEBands , int start , int end , int C , int * offsets , int lsb_depth , const opus_int16 * logN ,
992
992
int isTransient , int vbr , int constrained_vbr , const opus_int16 * eBands , int LM ,
993
993
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 )
995
995
{
996
996
int i , c ;
997
997
opus_int32 tot_boost = 0 ;
@@ -1142,6 +1142,20 @@ static opus_val16 dynalloc_analysis(const opus_val16 *bandLogE, const opus_val16
1142
1142
if (i >=12 )
1143
1143
follower [i ] = HALF16 (follower [i ]);
1144
1144
}
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
+ }
1145
1159
#ifdef DISABLE_FLOAT_API
1146
1160
(void )analysis ;
1147
1161
#else
@@ -2068,7 +2082,7 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm,
2068
2082
2069
2083
maxDepth = dynalloc_analysis (bandLogE , bandLogE2 , oldBandE , nbEBands , start , end , C , offsets ,
2070
2084
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 );
2072
2086
2073
2087
ALLOC (tf_res , nbEBands , int );
2074
2088
/* Disable variable tf resolution for hybrid and at very low bitrate */
0 commit comments