Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit 6e40eb5

Browse files
koenvosjmvalin
authored andcommitted
removed prefilter
The NSQ SSE optimizations are disabled for now because they need to be updated
1 parent 52cfffe commit 6e40eb5

31 files changed

+257
-981
lines changed

silk/NSQ.c

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
3737
static OPUS_INLINE void silk_nsq_scale_states(
3838
const silk_encoder_state *psEncC, /* I Encoder State */
3939
silk_nsq_state *NSQ, /* I/O NSQ state */
40-
const opus_int32 x_Q3[], /* I input in Q3 */
40+
const opus_int16 x16[], /* I input */
4141
opus_int32 x_sc_Q10[], /* O input scaled with 1/Gain */
4242
const opus_int16 sLTP[], /* I re-whitened LTP state in Q0 */
4343
opus_int32 sLTP_Q15[], /* O LTP state matching scaled input */
@@ -78,11 +78,11 @@ void silk_NSQ_c
7878
const silk_encoder_state *psEncC, /* I/O Encoder State */
7979
silk_nsq_state *NSQ, /* I/O NSQ state */
8080
SideInfoIndices *psIndices, /* I/O Quantization Indices */
81-
const opus_int32 x_Q3[], /* I Prefiltered input signal */
81+
const opus_int16 x16[], /* I Input */
8282
opus_int8 pulses[], /* O Quantized pulse signal */
8383
const opus_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Short term prediction coefs */
8484
const opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ], /* I Long term prediction coefs */
85-
const opus_int16 AR2_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I Noise shaping coefs */
85+
const opus_int16 AR_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I Noise shaping coefs */
8686
const opus_int HarmShapeGain_Q14[ MAX_NB_SUBFR ], /* I Long term shaping coefs */
8787
const opus_int Tilt_Q14[ MAX_NB_SUBFR ], /* I Spectral tilt */
8888
const opus_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I Low frequency shaping coefs */
@@ -117,8 +117,7 @@ void silk_NSQ_c
117117
LSF_interpolation_flag = 1;
118118
}
119119

120-
ALLOC( sLTP_Q15,
121-
psEncC->ltp_mem_length + psEncC->frame_length, opus_int32 );
120+
ALLOC( sLTP_Q15, psEncC->ltp_mem_length + psEncC->frame_length, opus_int32 );
122121
ALLOC( sLTP, psEncC->ltp_mem_length + psEncC->frame_length, opus_int16 );
123122
ALLOC( x_sc_Q10, psEncC->subfr_length, opus_int32 );
124123
/* Set up pointers to start of sub frame */
@@ -128,7 +127,7 @@ void silk_NSQ_c
128127
for( k = 0; k < psEncC->nb_subfr; k++ ) {
129128
A_Q12 = &PredCoef_Q12[ (( k >> 1 ) | ( 1 - LSF_interpolation_flag )) * MAX_LPC_ORDER ];
130129
B_Q14 = &LTPCoef_Q14[ k * LTP_ORDER ];
131-
AR_shp_Q13 = &AR2_Q13[ k * MAX_SHAPE_LPC_ORDER ];
130+
AR_shp_Q13 = &AR_Q13[ k * MAX_SHAPE_LPC_ORDER ];
132131

133132
/* Noise shape parameters */
134133
silk_assert( HarmShapeGain_Q14[ k ] >= 0 );
@@ -154,13 +153,13 @@ void silk_NSQ_c
154153
}
155154
}
156155

157-
silk_nsq_scale_states( psEncC, NSQ, x_Q3, x_sc_Q10, sLTP, sLTP_Q15, k, LTP_scale_Q14, Gains_Q16, pitchL, psIndices->signalType );
156+
silk_nsq_scale_states( psEncC, NSQ, x16, x_sc_Q10, sLTP, sLTP_Q15, k, LTP_scale_Q14, Gains_Q16, pitchL, psIndices->signalType );
158157

159158
silk_noise_shape_quantizer( NSQ, psIndices->signalType, x_sc_Q10, pulses, pxq, sLTP_Q15, A_Q12, B_Q14,
160159
AR_shp_Q13, lag, HarmShapeFIRPacked_Q14, Tilt_Q14[ k ], LF_shp_Q14[ k ], Gains_Q16[ k ], Lambda_Q10,
161160
offset_Q10, psEncC->subfr_length, psEncC->shapingLPCOrder, psEncC->predictLPCOrder, psEncC->arch );
162161

163-
x_Q3 += psEncC->subfr_length;
162+
x16 += psEncC->subfr_length;
164163
pulses += psEncC->subfr_length;
165164
pxq += psEncC->subfr_length;
166165
}
@@ -254,7 +253,7 @@ void silk_noise_shape_quantizer(
254253

255254
/* Noise shape feedback */
256255
silk_assert( ( shapingLPCOrder & 1 ) == 0 ); /* check that order is even */
257-
n_AR_Q12 = silk_NSQ_noise_shape_feedback_loop(psLPC_Q14, NSQ->sAR2_Q14, AR_shp_Q13, shapingLPCOrder, arch);
256+
n_AR_Q12 = silk_NSQ_noise_shape_feedback_loop(&NSQ->sDiff_shp_Q14, NSQ->sAR2_Q14, AR_shp_Q13, shapingLPCOrder, arch);
258257

259258
n_AR_Q12 = silk_SMLAWB( n_AR_Q12, NSQ->sLF_AR_shp_Q14, Tilt_Q14 );
260259

@@ -283,8 +282,8 @@ void silk_noise_shape_quantizer(
283282
r_Q10 = silk_SUB32( x_sc_Q10[ i ], tmp1 ); /* residual error Q10 */
284283

285284
/* Flip sign depending on dither */
286-
if ( NSQ->rand_seed < 0 ) {
287-
r_Q10 = -r_Q10;
285+
if( NSQ->rand_seed < 0 ) {
286+
r_Q10 = -r_Q10;
288287
}
289288
r_Q10 = silk_LIMIT_32( r_Q10, -(31 << 10), 30 << 10 );
290289

@@ -354,7 +353,8 @@ void silk_noise_shape_quantizer(
354353
/* Update states */
355354
psLPC_Q14++;
356355
*psLPC_Q14 = xq_Q14;
357-
sLF_AR_shp_Q14 = silk_SUB_LSHIFT32( xq_Q14, n_AR_Q12, 2 );
356+
NSQ->sDiff_shp_Q14 = silk_SUB_LSHIFT32( xq_Q14, x_sc_Q10[ i ], 4 );
357+
sLF_AR_shp_Q14 = silk_SUB_LSHIFT32( NSQ->sDiff_shp_Q14, n_AR_Q12, 2 );
358358
NSQ->sLF_AR_shp_Q14 = sLF_AR_shp_Q14;
359359

360360
NSQ->sLTP_shp_Q14[ NSQ->sLTP_shp_buf_idx ] = silk_SUB_LSHIFT32( sLF_AR_shp_Q14, n_LF_Q12, 2 );
@@ -373,7 +373,7 @@ void silk_noise_shape_quantizer(
373373
static OPUS_INLINE void silk_nsq_scale_states(
374374
const silk_encoder_state *psEncC, /* I Encoder State */
375375
silk_nsq_state *NSQ, /* I/O NSQ state */
376-
const opus_int32 x_Q3[], /* I input in Q3 */
376+
const opus_int16 x16[], /* I input */
377377
opus_int32 x_sc_Q10[], /* O input scaled with 1/Gain */
378378
const opus_int16 sLTP[], /* I re-whitened LTP state in Q0 */
379379
opus_int32 sLTP_Q15[], /* O LTP state matching scaled input */
@@ -385,28 +385,18 @@ static OPUS_INLINE void silk_nsq_scale_states(
385385
)
386386
{
387387
opus_int i, lag;
388-
opus_int32 gain_adj_Q16, inv_gain_Q31, inv_gain_Q23;
388+
opus_int32 gain_adj_Q16, inv_gain_Q31, inv_gain_Q26;
389389

390390
lag = pitchL[ subfr ];
391391
inv_gain_Q31 = silk_INVERSE32_varQ( silk_max( Gains_Q16[ subfr ], 1 ), 47 );
392392
silk_assert( inv_gain_Q31 != 0 );
393393

394-
/* Calculate gain adjustment factor */
395-
if( Gains_Q16[ subfr ] != NSQ->prev_gain_Q16 ) {
396-
gain_adj_Q16 = silk_DIV32_varQ( NSQ->prev_gain_Q16, Gains_Q16[ subfr ], 16 );
397-
} else {
398-
gain_adj_Q16 = (opus_int32)1 << 16;
399-
}
400-
401394
/* Scale input */
402-
inv_gain_Q23 = silk_RSHIFT_ROUND( inv_gain_Q31, 8 );
395+
inv_gain_Q26 = silk_RSHIFT_ROUND( inv_gain_Q31, 5 );
403396
for( i = 0; i < psEncC->subfr_length; i++ ) {
404-
x_sc_Q10[ i ] = silk_SMULWW( x_Q3[ i ], inv_gain_Q23 );
397+
x_sc_Q10[ i ] = silk_SMULWW( x16[ i ], inv_gain_Q26 );
405398
}
406399

407-
/* Save inverse gain */
408-
NSQ->prev_gain_Q16 = Gains_Q16[ subfr ];
409-
410400
/* After rewhitening the LTP state is un-scaled, so scale with inv_gain_Q16 */
411401
if( NSQ->rewhite_flag ) {
412402
if( subfr == 0 ) {
@@ -420,7 +410,9 @@ static OPUS_INLINE void silk_nsq_scale_states(
420410
}
421411

422412
/* Adjust for changing gain */
423-
if( gain_adj_Q16 != (opus_int32)1 << 16 ) {
413+
if( Gains_Q16[ subfr ] != NSQ->prev_gain_Q16 ) {
414+
gain_adj_Q16 = silk_DIV32_varQ( NSQ->prev_gain_Q16, Gains_Q16[ subfr ], 16 );
415+
424416
/* Scale long-term shaping state */
425417
for( i = NSQ->sLTP_shp_buf_idx - psEncC->ltp_mem_length; i < NSQ->sLTP_shp_buf_idx; i++ ) {
426418
NSQ->sLTP_shp_Q14[ i ] = silk_SMULWW( gain_adj_Q16, NSQ->sLTP_shp_Q14[ i ] );
@@ -434,6 +426,7 @@ static OPUS_INLINE void silk_nsq_scale_states(
434426
}
435427

436428
NSQ->sLF_AR_shp_Q14 = silk_SMULWW( gain_adj_Q16, NSQ->sLF_AR_shp_Q14 );
429+
NSQ->sDiff_shp_Q14 = silk_SMULWW( gain_adj_Q16, NSQ->sDiff_shp_Q14 );
437430

438431
/* Scale short-term prediction and shaping states */
439432
for( i = 0; i < NSQ_LPC_BUF_LENGTH; i++ ) {
@@ -442,5 +435,8 @@ static OPUS_INLINE void silk_nsq_scale_states(
442435
for( i = 0; i < MAX_SHAPE_LPC_ORDER; i++ ) {
443436
NSQ->sAR2_Q14[ i ] = silk_SMULWW( gain_adj_Q16, NSQ->sAR2_Q14[ i ] );
444437
}
438+
439+
/* Save inverse gain */
440+
NSQ->prev_gain_Q16 = Gains_Q16[ subfr ];
445441
}
446442
}

silk/NSQ_del_dec.c

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ typedef struct {
4343
opus_int32 Shape_Q14[ DECISION_DELAY ];
4444
opus_int32 sAR2_Q14[ MAX_SHAPE_LPC_ORDER ];
4545
opus_int32 LF_AR_Q14;
46+
opus_int32 Diff_Q14;
4647
opus_int32 Seed;
4748
opus_int32 SeedInit;
4849
opus_int32 RD_Q10;
@@ -53,6 +54,7 @@ typedef struct {
5354
opus_int32 RD_Q10;
5455
opus_int32 xq_Q14;
5556
opus_int32 LF_AR_Q14;
57+
opus_int32 Diff_Q14;
5658
opus_int32 sLTP_shp_Q14;
5759
opus_int32 LPC_exc_Q14;
5860
} NSQ_sample_struct;
@@ -66,7 +68,7 @@ static OPUS_INLINE void silk_nsq_del_dec_scale_states(
6668
const silk_encoder_state *psEncC, /* I Encoder State */
6769
silk_nsq_state *NSQ, /* I/O NSQ state */
6870
NSQ_del_dec_struct psDelDec[], /* I/O Delayed decision states */
69-
const opus_int32 x_Q3[], /* I Input in Q3 */
71+
const opus_int16 x16[], /* I Input */
7072
opus_int32 x_sc_Q10[], /* O Input scaled with 1/Gain in Q10 */
7173
const opus_int16 sLTP[], /* I Re-whitened LTP state in Q0 */
7274
opus_int32 sLTP_Q15[], /* O LTP state matching scaled input */
@@ -116,11 +118,11 @@ void silk_NSQ_del_dec_c(
116118
const silk_encoder_state *psEncC, /* I/O Encoder State */
117119
silk_nsq_state *NSQ, /* I/O NSQ state */
118120
SideInfoIndices *psIndices, /* I/O Quantization Indices */
119-
const opus_int32 x_Q3[], /* I Prefiltered input signal */
121+
const opus_int16 x16[], /* I Input */
120122
opus_int8 pulses[], /* O Quantized pulse signal */
121123
const opus_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Short term prediction coefs */
122124
const opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ], /* I Long term prediction coefs */
123-
const opus_int16 AR2_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I Noise shaping coefs */
125+
const opus_int16 AR_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I Noise shaping coefs */
124126
const opus_int HarmShapeGain_Q14[ MAX_NB_SUBFR ], /* I Long term shaping coefs */
125127
const opus_int Tilt_Q14[ MAX_NB_SUBFR ], /* I Spectral tilt */
126128
const opus_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I Low frequency shaping coefs */
@@ -159,6 +161,7 @@ void silk_NSQ_del_dec_c(
159161
psDD->SeedInit = psDD->Seed;
160162
psDD->RD_Q10 = 0;
161163
psDD->LF_AR_Q14 = NSQ->sLF_AR_shp_Q14;
164+
psDD->Diff_Q14 = NSQ->sDiff_shp_Q14;
162165
psDD->Shape_Q14[ 0 ] = NSQ->sLTP_shp_Q14[ psEncC->ltp_mem_length - 1 ];
163166
silk_memcpy( psDD->sLPC_Q14, NSQ->sLPC_Q14, NSQ_LPC_BUF_LENGTH * sizeof( opus_int32 ) );
164167
silk_memcpy( psDD->sAR2_Q14, NSQ->sAR2_Q14, sizeof( NSQ->sAR2_Q14 ) );
@@ -186,8 +189,7 @@ void silk_NSQ_del_dec_c(
186189
LSF_interpolation_flag = 1;
187190
}
188191

189-
ALLOC( sLTP_Q15,
190-
psEncC->ltp_mem_length + psEncC->frame_length, opus_int32 );
192+
ALLOC( sLTP_Q15, psEncC->ltp_mem_length + psEncC->frame_length, opus_int32 );
191193
ALLOC( sLTP, psEncC->ltp_mem_length + psEncC->frame_length, opus_int16 );
192194
ALLOC( x_sc_Q10, psEncC->subfr_length, opus_int32 );
193195
ALLOC( delayedGain_Q10, DECISION_DELAY, opus_int32 );
@@ -199,7 +201,7 @@ void silk_NSQ_del_dec_c(
199201
for( k = 0; k < psEncC->nb_subfr; k++ ) {
200202
A_Q12 = &PredCoef_Q12[ ( ( k >> 1 ) | ( 1 - LSF_interpolation_flag ) ) * MAX_LPC_ORDER ];
201203
B_Q14 = &LTPCoef_Q14[ k * LTP_ORDER ];
202-
AR_shp_Q13 = &AR2_Q13[ k * MAX_SHAPE_LPC_ORDER ];
204+
AR_shp_Q13 = &AR_Q13[ k * MAX_SHAPE_LPC_ORDER ];
203205

204206
/* Noise shape parameters */
205207
silk_assert( HarmShapeGain_Q14[ k ] >= 0 );
@@ -257,15 +259,15 @@ void silk_NSQ_del_dec_c(
257259
}
258260
}
259261

260-
silk_nsq_del_dec_scale_states( psEncC, NSQ, psDelDec, x_Q3, x_sc_Q10, sLTP, sLTP_Q15, k,
262+
silk_nsq_del_dec_scale_states( psEncC, NSQ, psDelDec, x16, x_sc_Q10, sLTP, sLTP_Q15, k,
261263
psEncC->nStatesDelayedDecision, LTP_scale_Q14, Gains_Q16, pitchL, psIndices->signalType, decisionDelay );
262264

263265
silk_noise_shape_quantizer_del_dec( NSQ, psDelDec, psIndices->signalType, x_sc_Q10, pulses, pxq, sLTP_Q15,
264266
delayedGain_Q10, A_Q12, B_Q14, AR_shp_Q13, lag, HarmShapeFIRPacked_Q14, Tilt_Q14[ k ], LF_shp_Q14[ k ],
265267
Gains_Q16[ k ], Lambda_Q10, offset_Q10, psEncC->subfr_length, subfr++, psEncC->shapingLPCOrder,
266268
psEncC->predictLPCOrder, psEncC->warping_Q16, psEncC->nStatesDelayedDecision, &smpl_buf_idx, decisionDelay, psEncC->arch );
267269

268-
x_Q3 += psEncC->subfr_length;
270+
x16 += psEncC->subfr_length;
269271
pulses += psEncC->subfr_length;
270272
pxq += psEncC->subfr_length;
271273
}
@@ -297,6 +299,7 @@ void silk_NSQ_del_dec_c(
297299

298300
/* Update states */
299301
NSQ->sLF_AR_shp_Q14 = psDD->LF_AR_Q14;
302+
NSQ->sDiff_shp_Q14 = psDD->Diff_Q14;
300303
NSQ->lagPrev = pitchL[ psEncC->nb_subfr - 1 ];
301304

302305
/* Save quantized speech signal */
@@ -419,7 +422,7 @@ static OPUS_INLINE void silk_noise_shape_quantizer_del_dec(
419422
/* Noise shape feedback */
420423
silk_assert( ( shapingLPCOrder & 1 ) == 0 ); /* check that order is even */
421424
/* Output of lowpass section */
422-
tmp2 = silk_SMLAWB( psLPC_Q14[ 0 ], psDD->sAR2_Q14[ 0 ], warping_Q16 );
425+
tmp2 = silk_SMLAWB( psDD->Diff_Q14, psDD->sAR2_Q14[ 0 ], warping_Q16 );
423426
/* Output of allpass section */
424427
tmp1 = silk_SMLAWB( psDD->sAR2_Q14[ 0 ], psDD->sAR2_Q14[ 1 ] - tmp2, warping_Q16 );
425428
psDD->sAR2_Q14[ 0 ] = tmp2;
@@ -531,7 +534,8 @@ static OPUS_INLINE void silk_noise_shape_quantizer_del_dec(
531534
xq_Q14 = silk_ADD32( LPC_exc_Q14, LPC_pred_Q14 );
532535

533536
/* Update states */
534-
sLF_AR_shp_Q14 = silk_SUB32( xq_Q14, n_AR_Q14 );
537+
psSS[ 0 ].Diff_Q14 = silk_SUB_LSHIFT32( xq_Q14, x_Q10[ i ], 4 );
538+
sLF_AR_shp_Q14 = silk_SUB32( psSS[ 0 ].Diff_Q14, n_AR_Q14 );
535539
psSS[ 0 ].sLTP_shp_Q14 = silk_SUB32( sLF_AR_shp_Q14, n_LF_Q14 );
536540
psSS[ 0 ].LF_AR_Q14 = sLF_AR_shp_Q14;
537541
psSS[ 0 ].LPC_exc_Q14 = LPC_exc_Q14;
@@ -545,13 +549,13 @@ static OPUS_INLINE void silk_noise_shape_quantizer_del_dec(
545549
exc_Q14 = -exc_Q14;
546550
}
547551

548-
549552
/* Add predictions */
550553
LPC_exc_Q14 = silk_ADD32( exc_Q14, LTP_pred_Q14 );
551554
xq_Q14 = silk_ADD32( LPC_exc_Q14, LPC_pred_Q14 );
552555

553556
/* Update states */
554-
sLF_AR_shp_Q14 = silk_SUB32( xq_Q14, n_AR_Q14 );
557+
psSS[ 1 ].Diff_Q14 = silk_SUB_LSHIFT32( xq_Q14, x_Q10[ i ], 4 );
558+
sLF_AR_shp_Q14 = silk_SUB32( psSS[ 1 ].Diff_Q14, n_AR_Q14 );
555559
psSS[ 1 ].sLTP_shp_Q14 = silk_SUB32( sLF_AR_shp_Q14, n_LF_Q14 );
556560
psSS[ 1 ].LF_AR_Q14 = sLF_AR_shp_Q14;
557561
psSS[ 1 ].LPC_exc_Q14 = LPC_exc_Q14;
@@ -623,6 +627,7 @@ static OPUS_INLINE void silk_noise_shape_quantizer_del_dec(
623627
psDD = &psDelDec[ k ];
624628
psSS = &psSampleState[ k ][ 0 ];
625629
psDD->LF_AR_Q14 = psSS->LF_AR_Q14;
630+
psDD->Diff_Q14 = psSS->Diff_Q14;
626631
psDD->sLPC_Q14[ NSQ_LPC_BUF_LENGTH + i ] = psSS->xq_Q14;
627632
psDD->Xq_Q14[ *smpl_buf_idx ] = psSS->xq_Q14;
628633
psDD->Q_Q10[ *smpl_buf_idx ] = psSS->Q_Q10;
@@ -647,7 +652,7 @@ static OPUS_INLINE void silk_nsq_del_dec_scale_states(
647652
const silk_encoder_state *psEncC, /* I Encoder State */
648653
silk_nsq_state *NSQ, /* I/O NSQ state */
649654
NSQ_del_dec_struct psDelDec[], /* I/O Delayed decision states */
650-
const opus_int32 x_Q3[], /* I Input in Q3 */
655+
const opus_int16 x16[], /* I Input */
651656
opus_int32 x_sc_Q10[], /* O Input scaled with 1/Gain in Q10 */
652657
const opus_int16 sLTP[], /* I Re-whitened LTP state in Q0 */
653658
opus_int32 sLTP_Q15[], /* O LTP state matching scaled input */
@@ -661,29 +666,19 @@ static OPUS_INLINE void silk_nsq_del_dec_scale_states(
661666
)
662667
{
663668
opus_int i, k, lag;
664-
opus_int32 gain_adj_Q16, inv_gain_Q31, inv_gain_Q23;
669+
opus_int32 gain_adj_Q16, inv_gain_Q31, inv_gain_Q26;
665670
NSQ_del_dec_struct *psDD;
666671

667672
lag = pitchL[ subfr ];
668673
inv_gain_Q31 = silk_INVERSE32_varQ( silk_max( Gains_Q16[ subfr ], 1 ), 47 );
669674
silk_assert( inv_gain_Q31 != 0 );
670675

671-
/* Calculate gain adjustment factor */
672-
if( Gains_Q16[ subfr ] != NSQ->prev_gain_Q16 ) {
673-
gain_adj_Q16 = silk_DIV32_varQ( NSQ->prev_gain_Q16, Gains_Q16[ subfr ], 16 );
674-
} else {
675-
gain_adj_Q16 = (opus_int32)1 << 16;
676-
}
677-
678676
/* Scale input */
679-
inv_gain_Q23 = silk_RSHIFT_ROUND( inv_gain_Q31, 8 );
677+
inv_gain_Q26 = silk_RSHIFT_ROUND( inv_gain_Q31, 5 );
680678
for( i = 0; i < psEncC->subfr_length; i++ ) {
681-
x_sc_Q10[ i ] = silk_SMULWW( x_Q3[ i ], inv_gain_Q23 );
679+
x_sc_Q10[ i ] = silk_SMULWW( x16[ i ], inv_gain_Q26 );
682680
}
683681

684-
/* Save inverse gain */
685-
NSQ->prev_gain_Q16 = Gains_Q16[ subfr ];
686-
687682
/* After rewhitening the LTP state is un-scaled, so scale with inv_gain_Q16 */
688683
if( NSQ->rewhite_flag ) {
689684
if( subfr == 0 ) {
@@ -697,7 +692,9 @@ static OPUS_INLINE void silk_nsq_del_dec_scale_states(
697692
}
698693

699694
/* Adjust for changing gain */
700-
if( gain_adj_Q16 != (opus_int32)1 << 16 ) {
695+
if( Gains_Q16[ subfr ] != NSQ->prev_gain_Q16 ) {
696+
gain_adj_Q16 = silk_DIV32_varQ( NSQ->prev_gain_Q16, Gains_Q16[ subfr ], 16 );
697+
701698
/* Scale long-term shaping state */
702699
for( i = NSQ->sLTP_shp_buf_idx - psEncC->ltp_mem_length; i < NSQ->sLTP_shp_buf_idx; i++ ) {
703700
NSQ->sLTP_shp_Q14[ i ] = silk_SMULWW( gain_adj_Q16, NSQ->sLTP_shp_Q14[ i ] );
@@ -715,6 +712,7 @@ static OPUS_INLINE void silk_nsq_del_dec_scale_states(
715712

716713
/* Scale scalar states */
717714
psDD->LF_AR_Q14 = silk_SMULWW( gain_adj_Q16, psDD->LF_AR_Q14 );
715+
psDD->Diff_Q14 = silk_SMULWW( gain_adj_Q16, psDD->Diff_Q14 );
718716

719717
/* Scale short-term prediction and shaping states */
720718
for( i = 0; i < NSQ_LPC_BUF_LENGTH; i++ ) {
@@ -728,5 +726,8 @@ static OPUS_INLINE void silk_nsq_del_dec_scale_states(
728726
psDD->Shape_Q14[ i ] = silk_SMULWW( gain_adj_Q16, psDD->Shape_Q14[ i ] );
729727
}
730728
}
729+
730+
/* Save inverse gain */
731+
NSQ->prev_gain_Q16 = Gains_Q16[ subfr ];
731732
}
732733
}

0 commit comments

Comments
 (0)