@@ -43,6 +43,7 @@ typedef struct {
43
43
opus_int32 Shape_Q14 [ DECISION_DELAY ];
44
44
opus_int32 sAR2_Q14 [ MAX_SHAPE_LPC_ORDER ];
45
45
opus_int32 LF_AR_Q14 ;
46
+ opus_int32 Diff_Q14 ;
46
47
opus_int32 Seed ;
47
48
opus_int32 SeedInit ;
48
49
opus_int32 RD_Q10 ;
@@ -53,6 +54,7 @@ typedef struct {
53
54
opus_int32 RD_Q10 ;
54
55
opus_int32 xq_Q14 ;
55
56
opus_int32 LF_AR_Q14 ;
57
+ opus_int32 Diff_Q14 ;
56
58
opus_int32 sLTP_shp_Q14 ;
57
59
opus_int32 LPC_exc_Q14 ;
58
60
} NSQ_sample_struct ;
@@ -66,7 +68,7 @@ static OPUS_INLINE void silk_nsq_del_dec_scale_states(
66
68
const silk_encoder_state * psEncC , /* I Encoder State */
67
69
silk_nsq_state * NSQ , /* I/O NSQ state */
68
70
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 */
70
72
opus_int32 x_sc_Q10 [], /* O Input scaled with 1/Gain in Q10 */
71
73
const opus_int16 sLTP [], /* I Re-whitened LTP state in Q0 */
72
74
opus_int32 sLTP_Q15 [], /* O LTP state matching scaled input */
@@ -116,11 +118,11 @@ void silk_NSQ_del_dec_c(
116
118
const silk_encoder_state * psEncC , /* I/O Encoder State */
117
119
silk_nsq_state * NSQ , /* I/O NSQ state */
118
120
SideInfoIndices * psIndices , /* I/O Quantization Indices */
119
- const opus_int32 x_Q3 [], /* I Prefiltered input signal */
121
+ const opus_int16 x16 [], /* I Input */
120
122
opus_int8 pulses [], /* O Quantized pulse signal */
121
123
const opus_int16 PredCoef_Q12 [ 2 * MAX_LPC_ORDER ], /* I Short term prediction coefs */
122
124
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 */
124
126
const opus_int HarmShapeGain_Q14 [ MAX_NB_SUBFR ], /* I Long term shaping coefs */
125
127
const opus_int Tilt_Q14 [ MAX_NB_SUBFR ], /* I Spectral tilt */
126
128
const opus_int32 LF_shp_Q14 [ MAX_NB_SUBFR ], /* I Low frequency shaping coefs */
@@ -159,6 +161,7 @@ void silk_NSQ_del_dec_c(
159
161
psDD -> SeedInit = psDD -> Seed ;
160
162
psDD -> RD_Q10 = 0 ;
161
163
psDD -> LF_AR_Q14 = NSQ -> sLF_AR_shp_Q14 ;
164
+ psDD -> Diff_Q14 = NSQ -> sDiff_shp_Q14 ;
162
165
psDD -> Shape_Q14 [ 0 ] = NSQ -> sLTP_shp_Q14 [ psEncC -> ltp_mem_length - 1 ];
163
166
silk_memcpy ( psDD -> sLPC_Q14 , NSQ -> sLPC_Q14 , NSQ_LPC_BUF_LENGTH * sizeof ( opus_int32 ) );
164
167
silk_memcpy ( psDD -> sAR2_Q14 , NSQ -> sAR2_Q14 , sizeof ( NSQ -> sAR2_Q14 ) );
@@ -186,8 +189,7 @@ void silk_NSQ_del_dec_c(
186
189
LSF_interpolation_flag = 1 ;
187
190
}
188
191
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 );
191
193
ALLOC ( sLTP , psEncC -> ltp_mem_length + psEncC -> frame_length , opus_int16 );
192
194
ALLOC ( x_sc_Q10 , psEncC -> subfr_length , opus_int32 );
193
195
ALLOC ( delayedGain_Q10 , DECISION_DELAY , opus_int32 );
@@ -199,7 +201,7 @@ void silk_NSQ_del_dec_c(
199
201
for ( k = 0 ; k < psEncC -> nb_subfr ; k ++ ) {
200
202
A_Q12 = & PredCoef_Q12 [ ( ( k >> 1 ) | ( 1 - LSF_interpolation_flag ) ) * MAX_LPC_ORDER ];
201
203
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 ];
203
205
204
206
/* Noise shape parameters */
205
207
silk_assert ( HarmShapeGain_Q14 [ k ] >= 0 );
@@ -257,15 +259,15 @@ void silk_NSQ_del_dec_c(
257
259
}
258
260
}
259
261
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 ,
261
263
psEncC -> nStatesDelayedDecision , LTP_scale_Q14 , Gains_Q16 , pitchL , psIndices -> signalType , decisionDelay );
262
264
263
265
silk_noise_shape_quantizer_del_dec ( NSQ , psDelDec , psIndices -> signalType , x_sc_Q10 , pulses , pxq , sLTP_Q15 ,
264
266
delayedGain_Q10 , A_Q12 , B_Q14 , AR_shp_Q13 , lag , HarmShapeFIRPacked_Q14 , Tilt_Q14 [ k ], LF_shp_Q14 [ k ],
265
267
Gains_Q16 [ k ], Lambda_Q10 , offset_Q10 , psEncC -> subfr_length , subfr ++ , psEncC -> shapingLPCOrder ,
266
268
psEncC -> predictLPCOrder , psEncC -> warping_Q16 , psEncC -> nStatesDelayedDecision , & smpl_buf_idx , decisionDelay , psEncC -> arch );
267
269
268
- x_Q3 += psEncC -> subfr_length ;
270
+ x16 += psEncC -> subfr_length ;
269
271
pulses += psEncC -> subfr_length ;
270
272
pxq += psEncC -> subfr_length ;
271
273
}
@@ -297,6 +299,7 @@ void silk_NSQ_del_dec_c(
297
299
298
300
/* Update states */
299
301
NSQ -> sLF_AR_shp_Q14 = psDD -> LF_AR_Q14 ;
302
+ NSQ -> sDiff_shp_Q14 = psDD -> Diff_Q14 ;
300
303
NSQ -> lagPrev = pitchL [ psEncC -> nb_subfr - 1 ];
301
304
302
305
/* Save quantized speech signal */
@@ -419,7 +422,7 @@ static OPUS_INLINE void silk_noise_shape_quantizer_del_dec(
419
422
/* Noise shape feedback */
420
423
silk_assert ( ( shapingLPCOrder & 1 ) == 0 ); /* check that order is even */
421
424
/* 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 );
423
426
/* Output of allpass section */
424
427
tmp1 = silk_SMLAWB ( psDD -> sAR2_Q14 [ 0 ], psDD -> sAR2_Q14 [ 1 ] - tmp2 , warping_Q16 );
425
428
psDD -> sAR2_Q14 [ 0 ] = tmp2 ;
@@ -531,7 +534,8 @@ static OPUS_INLINE void silk_noise_shape_quantizer_del_dec(
531
534
xq_Q14 = silk_ADD32 ( LPC_exc_Q14 , LPC_pred_Q14 );
532
535
533
536
/* 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 );
535
539
psSS [ 0 ].sLTP_shp_Q14 = silk_SUB32 ( sLF_AR_shp_Q14 , n_LF_Q14 );
536
540
psSS [ 0 ].LF_AR_Q14 = sLF_AR_shp_Q14 ;
537
541
psSS [ 0 ].LPC_exc_Q14 = LPC_exc_Q14 ;
@@ -545,13 +549,13 @@ static OPUS_INLINE void silk_noise_shape_quantizer_del_dec(
545
549
exc_Q14 = - exc_Q14 ;
546
550
}
547
551
548
-
549
552
/* Add predictions */
550
553
LPC_exc_Q14 = silk_ADD32 ( exc_Q14 , LTP_pred_Q14 );
551
554
xq_Q14 = silk_ADD32 ( LPC_exc_Q14 , LPC_pred_Q14 );
552
555
553
556
/* 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 );
555
559
psSS [ 1 ].sLTP_shp_Q14 = silk_SUB32 ( sLF_AR_shp_Q14 , n_LF_Q14 );
556
560
psSS [ 1 ].LF_AR_Q14 = sLF_AR_shp_Q14 ;
557
561
psSS [ 1 ].LPC_exc_Q14 = LPC_exc_Q14 ;
@@ -623,6 +627,7 @@ static OPUS_INLINE void silk_noise_shape_quantizer_del_dec(
623
627
psDD = & psDelDec [ k ];
624
628
psSS = & psSampleState [ k ][ 0 ];
625
629
psDD -> LF_AR_Q14 = psSS -> LF_AR_Q14 ;
630
+ psDD -> Diff_Q14 = psSS -> Diff_Q14 ;
626
631
psDD -> sLPC_Q14 [ NSQ_LPC_BUF_LENGTH + i ] = psSS -> xq_Q14 ;
627
632
psDD -> Xq_Q14 [ * smpl_buf_idx ] = psSS -> xq_Q14 ;
628
633
psDD -> Q_Q10 [ * smpl_buf_idx ] = psSS -> Q_Q10 ;
@@ -647,7 +652,7 @@ static OPUS_INLINE void silk_nsq_del_dec_scale_states(
647
652
const silk_encoder_state * psEncC , /* I Encoder State */
648
653
silk_nsq_state * NSQ , /* I/O NSQ state */
649
654
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 */
651
656
opus_int32 x_sc_Q10 [], /* O Input scaled with 1/Gain in Q10 */
652
657
const opus_int16 sLTP [], /* I Re-whitened LTP state in Q0 */
653
658
opus_int32 sLTP_Q15 [], /* O LTP state matching scaled input */
@@ -661,29 +666,19 @@ static OPUS_INLINE void silk_nsq_del_dec_scale_states(
661
666
)
662
667
{
663
668
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 ;
665
670
NSQ_del_dec_struct * psDD ;
666
671
667
672
lag = pitchL [ subfr ];
668
673
inv_gain_Q31 = silk_INVERSE32_varQ ( silk_max ( Gains_Q16 [ subfr ], 1 ), 47 );
669
674
silk_assert ( inv_gain_Q31 != 0 );
670
675
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
-
678
676
/* Scale input */
679
- inv_gain_Q23 = silk_RSHIFT_ROUND ( inv_gain_Q31 , 8 );
677
+ inv_gain_Q26 = silk_RSHIFT_ROUND ( inv_gain_Q31 , 5 );
680
678
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 );
682
680
}
683
681
684
- /* Save inverse gain */
685
- NSQ -> prev_gain_Q16 = Gains_Q16 [ subfr ];
686
-
687
682
/* After rewhitening the LTP state is un-scaled, so scale with inv_gain_Q16 */
688
683
if ( NSQ -> rewhite_flag ) {
689
684
if ( subfr == 0 ) {
@@ -697,7 +692,9 @@ static OPUS_INLINE void silk_nsq_del_dec_scale_states(
697
692
}
698
693
699
694
/* 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
+
701
698
/* Scale long-term shaping state */
702
699
for ( i = NSQ -> sLTP_shp_buf_idx - psEncC -> ltp_mem_length ; i < NSQ -> sLTP_shp_buf_idx ; i ++ ) {
703
700
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(
715
712
716
713
/* Scale scalar states */
717
714
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 );
718
716
719
717
/* Scale short-term prediction and shaping states */
720
718
for ( i = 0 ; i < NSQ_LPC_BUF_LENGTH ; i ++ ) {
@@ -728,5 +726,8 @@ static OPUS_INLINE void silk_nsq_del_dec_scale_states(
728
726
psDD -> Shape_Q14 [ i ] = silk_SMULWW ( gain_adj_Q16 , psDD -> Shape_Q14 [ i ] );
729
727
}
730
728
}
729
+
730
+ /* Save inverse gain */
731
+ NSQ -> prev_gain_Q16 = Gains_Q16 [ subfr ];
731
732
}
732
733
}
0 commit comments