|
@@ -1,706 +0,0 @@
|
1
|
|
-#include "SKP_Silk_main.h"
|
2
|
|
-
|
3
|
|
-typedef struct {
|
4
|
|
- SKP_int RandState[ DECISION_DELAY ];
|
5
|
|
- SKP_int32 Q_Q10[ DECISION_DELAY ];
|
6
|
|
- SKP_int32 Xq_Q10[ DECISION_DELAY ];
|
7
|
|
- SKP_int32 Pred_Q16[ DECISION_DELAY ];
|
8
|
|
- SKP_int32 Shape_Q10[ DECISION_DELAY ];
|
9
|
|
- SKP_int32 Gain_Q16[ DECISION_DELAY ];
|
10
|
|
- SKP_int32 sLPC_Q14[ MAX_FRAME_LENGTH / NB_SUBFR + NSQ_LPC_BUF_LENGTH ];
|
11
|
|
- SKP_int32 LF_AR_Q12;
|
12
|
|
- SKP_int32 Seed;
|
13
|
|
- SKP_int32 SeedInit;
|
14
|
|
- SKP_int32 RD_Q10;
|
15
|
|
-} NSQ_del_dec_struct;
|
16
|
|
-
|
17
|
|
-typedef struct {
|
18
|
|
- SKP_int32 Q_Q10;
|
19
|
|
- SKP_int32 RD_Q10;
|
20
|
|
- SKP_int32 xq_Q14;
|
21
|
|
- SKP_int32 LF_AR_Q12;
|
22
|
|
- SKP_int32 sLTP_shp_Q10;
|
23
|
|
- SKP_int32 LPC_exc_Q16;
|
24
|
|
-} NSQ_sample_struct;
|
25
|
|
-
|
26
|
|
-SKP_INLINE void SKP_Silk_copy_del_dec_state(
|
27
|
|
- NSQ_del_dec_struct *DD_dst, /* I Dst del dec state */
|
28
|
|
- NSQ_del_dec_struct *DD_src, /* I Src del dec state */
|
29
|
|
- SKP_int LPC_state_idx /* I Index to LPC buffer */
|
30
|
|
-);
|
31
|
|
-
|
32
|
|
-SKP_INLINE void SKP_Silk_nsq_del_dec_scale_states(
|
33
|
|
- SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */
|
34
|
|
- NSQ_del_dec_struct psDelDec[], /* I/O Delayed decision states */
|
35
|
|
- const SKP_int16 x[], /* I Input in Q0 */
|
36
|
|
- SKP_int32 x_sc_Q10[], /* O Input scaled with 1/Gain in Q10 */
|
37
|
|
- SKP_int length, /* I Length of input */
|
38
|
|
- SKP_int16 sLTP[], /* I Re-whitened LTP state in Q0 */
|
39
|
|
- SKP_int32 sLTP_Q16[], /* O LTP state matching scaled input */
|
40
|
|
- SKP_int subfr, /* I Subframe number */
|
41
|
|
- SKP_int nStatesDelayedDecision, /* I Number of del dec states */
|
42
|
|
- SKP_int smpl_buf_idx, /* I Index to newest samples in buffers */
|
43
|
|
- const SKP_int LTP_scale_Q14, /* I LTP state scaling */
|
44
|
|
- const SKP_int32 Gains_Q16[ NB_SUBFR ], /* I */
|
45
|
|
- const SKP_int pitchL[ NB_SUBFR ] /* I Pitch lag */
|
46
|
|
-);
|
47
|
|
-
|
48
|
|
-/******************************************/
|
49
|
|
-/* 子帧的噪声去除量化器 */
|
50
|
|
-/******************************************/
|
51
|
|
-SKP_INLINE void SKP_Silk_noise_shape_quantizer_del_dec(
|
52
|
|
- SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */
|
53
|
|
- NSQ_del_dec_struct psDelDec[], /* I/O Delayed decision states */
|
54
|
|
- SKP_int sigtype, /* I Signal type */
|
55
|
|
- const SKP_int32 x_Q10[], /* I */
|
56
|
|
- SKP_int q[], /* O */
|
57
|
|
- SKP_int16 xq[], /* O */
|
58
|
|
- SKP_int32 sLTP_Q16[], /* I/O LTP filter state */
|
59
|
|
- const SKP_int16 a_Q12[], /* I Short term prediction coefs */
|
60
|
|
- const SKP_int16 b_Q14[], /* I Long term prediction coefs */
|
61
|
|
- const SKP_int16 AR_shp_Q13[], /* I Noise shaping coefs */
|
62
|
|
- SKP_int lag, /* I Pitch lag */
|
63
|
|
- SKP_int32 HarmShapeFIRPacked_Q14, /* I */
|
64
|
|
- SKP_int Tilt_Q14, /* I Spectral tilt */
|
65
|
|
- SKP_int32 LF_shp_Q14, /* I */
|
66
|
|
- SKP_int32 Gain_Q16, /* I */
|
67
|
|
- SKP_int Lambda_Q10, /* I */
|
68
|
|
- SKP_int offset_Q10, /* I */
|
69
|
|
- SKP_int length, /* I Input length */
|
70
|
|
- SKP_int subfr, /* I Subframe number */
|
71
|
|
- SKP_int shapingLPCOrder, /* I Shaping LPC filter order */
|
72
|
|
- SKP_int predictLPCOrder, /* I Prediction LPC filter order */
|
73
|
|
- SKP_int nStatesDelayedDecision, /* I Number of states in decision tree */
|
74
|
|
- SKP_int *smpl_buf_idx, /* I Index to newest samples in buffers */
|
75
|
|
- SKP_int decisionDelay /* I */
|
76
|
|
-);
|
77
|
|
-
|
78
|
|
-void SKP_Silk_NSQ_del_dec(
|
79
|
|
- SKP_Silk_encoder_state *psEncC, /* I/O Encoder State */
|
80
|
|
- SKP_Silk_encoder_control *psEncCtrlC, /* I Encoder Control */
|
81
|
|
- SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */
|
82
|
|
- const SKP_int16 x[], /* I Prefiltered input signal */
|
83
|
|
- SKP_int q[], /* O Quantized pulse signal */
|
84
|
|
- const SKP_int LSFInterpFactor_Q2, /* I LSF interpolation factor in Q2 */
|
85
|
|
- const SKP_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Prediction coefs */
|
86
|
|
- const SKP_int16 LTPCoef_Q14[ LTP_ORDER * NB_SUBFR ], /* I LT prediction coefs */
|
87
|
|
- const SKP_int16 AR2_Q13[ NB_SUBFR * SHAPE_LPC_ORDER_MAX ], /* I */
|
88
|
|
- const SKP_int HarmShapeGain_Q14[ NB_SUBFR ], /* I */
|
89
|
|
- const SKP_int Tilt_Q14[ NB_SUBFR ], /* I Spectral tilt */
|
90
|
|
- const SKP_int32 LF_shp_Q14[ NB_SUBFR ], /* I */
|
91
|
|
- const SKP_int32 Gains_Q16[ NB_SUBFR ], /* I */
|
92
|
|
- const SKP_int Lambda_Q10, /* I */
|
93
|
|
- const SKP_int LTP_scale_Q14 /* I LTP state scaling */
|
94
|
|
-)
|
95
|
|
-{
|
96
|
|
- SKP_int i, k, lag, start_idx, LSF_interpolation_flag, Winner_ind, subfr;
|
97
|
|
- SKP_int last_smple_idx, smpl_buf_idx, decisionDelay, subfr_length;
|
98
|
|
- const SKP_int16 *A_Q12, *B_Q14, *AR_shp_Q13;
|
99
|
|
- SKP_int16 *pxq;
|
100
|
|
- SKP_int32 sLTP_Q16[ 2 * MAX_FRAME_LENGTH ];
|
101
|
|
- SKP_int16 sLTP[ 2 * MAX_FRAME_LENGTH ];
|
102
|
|
- SKP_int32 HarmShapeFIRPacked_Q14;
|
103
|
|
- SKP_int offset_Q10;
|
104
|
|
- SKP_int32 FiltState[ MAX_LPC_ORDER ], RDmin_Q10;
|
105
|
|
- SKP_int32 x_sc_Q10[ MAX_FRAME_LENGTH / NB_SUBFR ];
|
106
|
|
- NSQ_del_dec_struct psDelDec[ DEL_DEC_STATES_MAX ];
|
107
|
|
- NSQ_del_dec_struct *psDD;
|
108
|
|
- SKP_int Restart; /* I LTP state scaling
|
109
|
|
-
|
110
|
|
- subfr_length = psEncC->frame_length / NB_SUBFR;
|
111
|
|
-
|
112
|
|
- /* Set unvoiced lag to the previous one, overwrite later for voiced */
|
113
|
|
- lag = NSQ->lagPrev;
|
114
|
|
-
|
115
|
|
- SKP_assert( NSQ->prev_inv_gain_Q16 != 0 );
|
116
|
|
-
|
117
|
|
- /* Initialize delayed decision states */
|
118
|
|
- SKP_memset( psDelDec, 0, psEncC->nStatesDelayedDecision * sizeof( NSQ_del_dec_struct ) );
|
119
|
|
- for( k = 0; k < psEncC->nStatesDelayedDecision; k++ ) {
|
120
|
|
- psDD = &psDelDec[ k ];
|
121
|
|
- psDD->Seed = ( k + psEncCtrlC->Seed ) & 3;
|
122
|
|
- psDD->SeedInit = psDD->Seed;
|
123
|
|
- psDD->RD_Q10 = 0;
|
124
|
|
- psDD->LF_AR_Q12 = NSQ->sLF_AR_shp_Q12;
|
125
|
|
- psDD->Shape_Q10[ 0 ] = NSQ->sLTP_shp_Q10[ psEncC->frame_length - 1 ];
|
126
|
|
- SKP_memcpy( psDD->sLPC_Q14, NSQ->sLPC_Q14, NSQ_LPC_BUF_LENGTH * sizeof( SKP_int32 ) );
|
127
|
|
- }
|
128
|
|
-
|
129
|
|
- offset_Q10 = SKP_Silk_Quantization_Offsets_Q10[ psEncCtrlC->sigtype ][ psEncCtrlC->QuantOffsetType ];
|
130
|
|
- smpl_buf_idx = 0; /* index of oldest samples */
|
131
|
|
-
|
132
|
|
- decisionDelay = SKP_min_int( DECISION_DELAY, subfr_length );
|
133
|
|
- /* For voiced frames limit the decision delay to lower than the pitch lag */
|
134
|
|
- if( psEncCtrlC->sigtype == SIG_TYPE_VOICED ) {
|
135
|
|
- for( k = 0; k < NB_SUBFR; k++ ) {
|
136
|
|
- decisionDelay = SKP_min_int( decisionDelay, psEncCtrlC->pitchL[ k ] - LTP_ORDER / 2 - 1 );
|
137
|
|
- }
|
138
|
|
- }
|
139
|
|
-
|
140
|
|
- if( LSFInterpFactor_Q2 == ( 1 << 2 ) ) {
|
141
|
|
- LSF_interpolation_flag = 0;
|
142
|
|
- } else {
|
143
|
|
- LSF_interpolation_flag = 1;
|
144
|
|
- }
|
145
|
|
-
|
146
|
|
- /* Setup pointers to start of sub frame */
|
147
|
|
- pxq = &NSQ->xq[ psEncC->frame_length ];
|
148
|
|
- NSQ->sLTP_shp_buf_idx = psEncC->frame_length;
|
149
|
|
- NSQ->sLTP_buf_idx = psEncC->frame_length;
|
150
|
|
- subfr = 0;
|
151
|
|
- for( k = 0; k < NB_SUBFR; k++ ) {
|
152
|
|
- A_Q12 = &PredCoef_Q12[ ( ( k >> 1 ) | ( 1 - LSF_interpolation_flag ) ) * MAX_LPC_ORDER ];
|
153
|
|
- B_Q14 = <PCoef_Q14[ k * LTP_ORDER ];
|
154
|
|
- AR_shp_Q13 = &AR2_Q13[ k * SHAPE_LPC_ORDER_MAX ];
|
155
|
|
-
|
156
|
|
- NSQ->rewhite_flag = 0;
|
157
|
|
- if( psEncCtrlC->sigtype == SIG_TYPE_VOICED ) {
|
158
|
|
- /* Voiced */
|
159
|
|
- lag = psEncCtrlC->pitchL[ k ];
|
160
|
|
-
|
161
|
|
- /* Re-whitening */
|
162
|
|
- if( ( k & ( 3 - SKP_LSHIFT( LSF_interpolation_flag, 1 ) ) ) == 0 ) {
|
163
|
|
- if( k == 2 ) {
|
164
|
|
- /* RESET DELAYED DECISIONS */
|
165
|
|
- /* Find winner */
|
166
|
|
- RDmin_Q10 = psDelDec[ 0 ].RD_Q10;
|
167
|
|
- Winner_ind = 0;
|
168
|
|
- for( i = 1; i < psEncC->nStatesDelayedDecision; i++ ) {
|
169
|
|
- if( psDelDec[ i ].RD_Q10 < RDmin_Q10 ) {
|
170
|
|
- RDmin_Q10 = psDelDec[ i ].RD_Q10;
|
171
|
|
- Winner_ind = i;
|
172
|
|
- }
|
173
|
|
- }
|
174
|
|
- for( i = 0; i < psEncC->nStatesDelayedDecision; i++ ) {
|
175
|
|
- if( i != Winner_ind ) {
|
176
|
|
- psDelDec[ i ].RD_Q10 += ( SKP_int32_MAX >> 4 );
|
177
|
|
- SKP_assert( psDelDec[ i ].RD_Q10 >= 0 );
|
178
|
|
- }
|
179
|
|
- }
|
180
|
|
-
|
181
|
|
- /* Copy final part of signals from winner state to output and long-term filter states */
|
182
|
|
- psDD = &psDelDec[ Winner_ind ];
|
183
|
|
- last_smple_idx = smpl_buf_idx + decisionDelay;
|
184
|
|
- for( i = 0; i < decisionDelay; i++ ) {
|
185
|
|
- last_smple_idx = ( last_smple_idx - 1 ) & DECISION_DELAY_MASK;
|
186
|
|
- q[ i - decisionDelay ] = ( SKP_int )SKP_RSHIFT( psDD->Q_Q10[ last_smple_idx ], 10 );
|
187
|
|
- pxq[ i - decisionDelay ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND(
|
188
|
|
- SKP_SMULWW( psDD->Xq_Q10[ last_smple_idx ],
|
189
|
|
- psDD->Gain_Q16[ last_smple_idx ] ), 10 ) );
|
190
|
|
- NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - decisionDelay + i ] = psDD->Shape_Q10[ last_smple_idx ];
|
191
|
|
- }
|
192
|
|
-
|
193
|
|
- subfr = 0;
|
194
|
|
- }
|
195
|
|
-
|
196
|
|
- /* Rewhiten with new A coefs */
|
197
|
|
- start_idx = psEncC->frame_length - lag - psEncC->predictLPCOrder - LTP_ORDER / 2;
|
198
|
|
- start_idx = SKP_LIMIT( start_idx, 0, psEncC->frame_length - psEncC->predictLPCOrder );
|
199
|
|
-
|
200
|
|
- SKP_memset( FiltState, 0, psEncC->predictLPCOrder * sizeof( SKP_int32 ) );
|
201
|
|
- SKP_Silk_MA_Prediction( &NSQ->xq[ start_idx + k * psEncC->subfr_length ],
|
202
|
|
- A_Q12, FiltState, sLTP + start_idx, psEncC->frame_length - start_idx, psEncC->predictLPCOrder );
|
203
|
|
-
|
204
|
|
- NSQ->sLTP_buf_idx = psEncC->frame_length;
|
205
|
|
- NSQ->rewhite_flag = 1;
|
206
|
|
- }
|
207
|
|
- }
|
208
|
|
-
|
209
|
|
- /* Noise shape parameters */
|
210
|
|
- SKP_assert( HarmShapeGain_Q14[ k ] >= 0 );
|
211
|
|
- HarmShapeFIRPacked_Q14 = SKP_RSHIFT( HarmShapeGain_Q14[ k ], 2 );
|
212
|
|
- HarmShapeFIRPacked_Q14 |= SKP_LSHIFT( ( SKP_int32 )SKP_RSHIFT( HarmShapeGain_Q14[ k ], 1 ), 16 );
|
213
|
|
-
|
214
|
|
- SKP_Silk_nsq_del_dec_scale_states( NSQ, psDelDec, x, x_sc_Q10,
|
215
|
|
- subfr_length, sLTP, sLTP_Q16, k, psEncC->nStatesDelayedDecision, smpl_buf_idx,
|
216
|
|
- LTP_scale_Q14, Gains_Q16, psEncCtrlC->pitchL );
|
217
|
|
-
|
218
|
|
- SKP_Silk_noise_shape_quantizer_del_dec( NSQ, psDelDec, psEncCtrlC->sigtype, x_sc_Q10, q, pxq, sLTP_Q16,
|
219
|
|
- A_Q12, B_Q14, AR_shp_Q13, lag, HarmShapeFIRPacked_Q14, Tilt_Q14[ k ], LF_shp_Q14[ k ], Gains_Q16[ k ],
|
220
|
|
- Lambda_Q10, offset_Q10, psEncC->subfr_length, subfr++, psEncC->shapingLPCOrder, psEncC->predictLPCOrder,
|
221
|
|
- psEncC->nStatesDelayedDecision, &smpl_buf_idx, decisionDelay
|
222
|
|
- );
|
223
|
|
-
|
224
|
|
- x += psEncC->subfr_length;
|
225
|
|
- q += psEncC->subfr_length;
|
226
|
|
- pxq += psEncC->subfr_length;
|
227
|
|
- }
|
228
|
|
-
|
229
|
|
- /* Find winner */
|
230
|
|
- RDmin_Q10 = psDelDec[ 0 ].RD_Q10;
|
231
|
|
- Winner_ind = 0;
|
232
|
|
- for( k = 1; k < psEncC->nStatesDelayedDecision; k++ ) {
|
233
|
|
- if( psDelDec[ k ].RD_Q10 < RDmin_Q10 ) {
|
234
|
|
- RDmin_Q10 = psDelDec[ k ].RD_Q10;
|
235
|
|
- Winner_ind = k;
|
236
|
|
- }
|
237
|
|
- }
|
238
|
|
-
|
239
|
|
- /* Copy final part of signals from winner state to output and long-term filter states */
|
240
|
|
- psDD = &psDelDec[ Winner_ind ];
|
241
|
|
- psEncCtrlC->Seed = psDD->SeedInit;
|
242
|
|
- last_smple_idx = smpl_buf_idx + decisionDelay;
|
243
|
|
- for( i = 0; i < decisionDelay; i++ ) {
|
244
|
|
- last_smple_idx = ( last_smple_idx - 1 ) & DECISION_DELAY_MASK;
|
245
|
|
- q[ i - decisionDelay ] = ( SKP_int )SKP_RSHIFT( psDD->Q_Q10[ last_smple_idx ], 10 );
|
246
|
|
- pxq[ i - decisionDelay ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND(
|
247
|
|
- SKP_SMULWW( psDD->Xq_Q10[ last_smple_idx ], psDD->Gain_Q16[ last_smple_idx ] ), 10 ) );
|
248
|
|
- NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - decisionDelay + i ] = psDD->Shape_Q10[ last_smple_idx ];
|
249
|
|
- sLTP_Q16[ NSQ->sLTP_buf_idx - decisionDelay + i ] = psDD->Pred_Q16[ last_smple_idx ];
|
250
|
|
-
|
251
|
|
- }
|
252
|
|
- SKP_memcpy( NSQ->sLPC_Q14, &psDD->sLPC_Q14[ psEncC->subfr_length ], NSQ_LPC_BUF_LENGTH * sizeof( SKP_int32 ) );
|
253
|
|
-
|
254
|
|
- /* Update states */
|
255
|
|
- NSQ->sLF_AR_shp_Q12 = psDD->LF_AR_Q12;
|
256
|
|
- NSQ->prev_inv_gain_Q16 = NSQ->prev_inv_gain_Q16;
|
257
|
|
- NSQ->lagPrev = psEncCtrlC->pitchL[ NB_SUBFR - 1 ];
|
258
|
|
-
|
259
|
|
- /* Save quantized speech and noise shaping signals */
|
260
|
|
- SKP_memcpy( NSQ->xq, &NSQ->xq[ psEncC->frame_length ], psEncC->frame_length * sizeof( SKP_int16 ) );
|
261
|
|
- SKP_memcpy( NSQ->sLTP_shp_Q10, &NSQ->sLTP_shp_Q10[ psEncC->frame_length ], psEncC->frame_length * sizeof( SKP_int32 ) );
|
262
|
|
-
|
263
|
|
-}
|
264
|
|
-
|
265
|
|
-/******************************************/
|
266
|
|
-/* 子帧去噪 */
|
267
|
|
-/******************************************/
|
268
|
|
-SKP_INLINE void SKP_Silk_noise_shape_quantizer_del_dec(
|
269
|
|
- SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */
|
270
|
|
- NSQ_del_dec_struct psDelDec[], /* I/O Delayed decision states */
|
271
|
|
- SKP_int sigtype, /* I Signal type */
|
272
|
|
- const SKP_int32 x_Q10[], /* I */
|
273
|
|
- SKP_int q[], /* O */
|
274
|
|
- SKP_int16 xq[], /* O */
|
275
|
|
- SKP_int32 sLTP_Q16[], /* I/O LTP filter state */
|
276
|
|
- const SKP_int16 a_Q12[], /* I Short term prediction coefs */
|
277
|
|
- const SKP_int16 b_Q14[], /* I Long term prediction coefs */
|
278
|
|
- const SKP_int16 AR_shp_Q13[], /* I Noise shaping coefs */
|
279
|
|
- SKP_int lag, /* I Pitch lag */
|
280
|
|
- SKP_int32 HarmShapeFIRPacked_Q14, /* I */
|
281
|
|
- SKP_int Tilt_Q14, /* I Spectral tilt */
|
282
|
|
- SKP_int32 LF_shp_Q14, /* I */
|
283
|
|
- SKP_int32 Gain_Q16, /* I */
|
284
|
|
- SKP_int Lambda_Q10, /* I */
|
285
|
|
- SKP_int offset_Q10, /* I */
|
286
|
|
- SKP_int length, /* I Input length */
|
287
|
|
- SKP_int subfr, /* I Subframe number */
|
288
|
|
- SKP_int shapingLPCOrder, /* I Shaping LPC filter order */
|
289
|
|
- SKP_int predictLPCOrder, /* I Prediction LPC filter order */
|
290
|
|
- SKP_int nStatesDelayedDecision, /* I Number of states in decision tree */
|
291
|
|
- SKP_int *smpl_buf_idx, /* I Index to newest samples in buffers */
|
292
|
|
- SKP_int decisionDelay /* I */
|
293
|
|
-)
|
294
|
|
-{
|
295
|
|
- SKP_int i, j, k, Winner_ind, RDmin_ind, RDmax_ind, last_smple_idx;
|
296
|
|
- SKP_int32 Winner_rand_state;
|
297
|
|
- SKP_int32 LTP_pred_Q14, LPC_pred_Q10, n_AR_Q10, n_LTP_Q14;
|
298
|
|
- SKP_int32 n_LF_Q10;
|
299
|
|
- SKP_int32 r_Q10, rr_Q20, rd1_Q10, rd2_Q10, RDmin_Q10, RDmax_Q10;
|
300
|
|
- SKP_int32 q1_Q10, q2_Q10;
|
301
|
|
- SKP_int32 Atmp, dither;
|
302
|
|
- SKP_int32 exc_Q10, LPC_exc_Q10, xq_Q10;
|
303
|
|
- SKP_int32 tmp, sLF_AR_shp_Q10;
|
304
|
|
- SKP_int32 *pred_lag_ptr, *shp_lag_ptr;
|
305
|
|
- SKP_int32 *psLPC_Q14;
|
306
|
|
- SKP_int32 a_Q12_tmp[ MAX_LPC_ORDER / 2 ], AR_shp_Q13_tmp[ MAX_LPC_ORDER / 2 ];
|
307
|
|
- NSQ_sample_struct psSampleState[ DEL_DEC_STATES_MAX ][ 2 ];
|
308
|
|
- NSQ_del_dec_struct *psDD;
|
309
|
|
- NSQ_sample_struct *psSS;
|
310
|
|
-
|
311
|
|
- shp_lag_ptr = &NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - lag + HARM_SHAPE_FIR_TAPS / 2 ];
|
312
|
|
- pred_lag_ptr = &sLTP_Q16[ NSQ->sLTP_buf_idx - lag + LTP_ORDER / 2 ];
|
313
|
|
-
|
314
|
|
- /* Preload LPC coeficients to array on stack. Gives small performance gain */
|
315
|
|
- SKP_memcpy( a_Q12_tmp, a_Q12, predictLPCOrder * sizeof( SKP_int16 ) );
|
316
|
|
- SKP_memcpy( AR_shp_Q13_tmp, AR_shp_Q13, shapingLPCOrder * sizeof( SKP_int16 ) );
|
317
|
|
-
|
318
|
|
- for( i = 0; i < length; i++ ) {
|
319
|
|
- /* Perform common calculations used in all states */
|
320
|
|
-
|
321
|
|
- /* Long-term prediction */
|
322
|
|
- if( sigtype == SIG_TYPE_VOICED ) {
|
323
|
|
- /* Unrolled loop */
|
324
|
|
- LTP_pred_Q14 = SKP_SMULWB( pred_lag_ptr[ 0 ], b_Q14[ 0 ] );
|
325
|
|
- LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -1 ], b_Q14[ 1 ] );
|
326
|
|
- LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -2 ], b_Q14[ 2 ] );
|
327
|
|
- LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -3 ], b_Q14[ 3 ] );
|
328
|
|
- LTP_pred_Q14 = SKP_SMLAWB( LTP_pred_Q14, pred_lag_ptr[ -4 ], b_Q14[ 4 ] );
|
329
|
|
- pred_lag_ptr++;
|
330
|
|
- } else {
|
331
|
|
- LTP_pred_Q14 = 0;
|
332
|
|
- }
|
333
|
|
-
|
334
|
|
- cout "czb " + LTP_pred_Q14;
|
335
|
|
-
|
336
|
|
- /* Long-term shaping */
|
337
|
|
- if( lag > 0 ) {
|
338
|
|
- /* Symmetric, packed FIR coefficients */
|
339
|
|
- n_LTP_Q14 = SKP_SMULWB( SKP_ADD32( shp_lag_ptr[ 0 ], shp_lag_ptr[ -2 ] ), HarmShapeFIRPacked_Q14 );
|
340
|
|
- n_LTP_Q14 = SKP_SMLAWT( n_LTP_Q14, shp_lag_ptr[ -1 ], HarmShapeFIRPacked_Q14 );
|
341
|
|
- n_LTP_Q14 = SKP_LSHIFT( n_LTP_Q14, 6 );
|
342
|
|
- shp_lag_ptr++;
|
343
|
|
- } else if(lag > 0 && n_LTP_Q14 < shp_lag_ptr) {
|
344
|
|
- n_LTP_Q14 = SKP_LSHIFT( n_LTP_Q14, n_LTP_Q14<<);
|
345
|
|
- } else {
|
346
|
|
- n_LTP_Q14 = 0;
|
347
|
|
- }
|
348
|
|
-
|
349
|
|
- cout "czb " + n_LTP_Q14;
|
350
|
|
-
|
351
|
|
- for( k = 0; k < nStatesDelayedDecision; k++ ) {
|
352
|
|
- /* Delayed decision state */
|
353
|
|
- psDD = &psDelDec[ k ];
|
354
|
|
-
|
355
|
|
- /* Sample state */
|
356
|
|
- psSS = psSampleState[ k ];
|
357
|
|
-
|
358
|
|
- /* Generate dither */
|
359
|
|
- psDD->Seed = SKP_RAND( psDD->Seed );
|
360
|
|
-
|
361
|
|
- /* dither = rand_seed < 0 ? 0xFFFFFFFF : 0; */
|
362
|
|
- dither = SKP_RSHIFT( psDD->Seed, 31 );
|
363
|
|
-
|
364
|
|
- /* Pointer used in short term prediction and shaping */
|
365
|
|
- psLPC_Q14 = &psDD->sLPC_Q14[ NSQ_LPC_BUF_LENGTH - 1 + i ];
|
366
|
|
- /* Short-term prediction */
|
367
|
|
- SKP_assert( ( predictLPCOrder & 1 ) == 0 ); /* check that order is even */
|
368
|
|
- SKP_assert( ( (SKP_int64)a_Q12 & 3 ) == 0 ); /* check that array starts at 4-byte aligned address */
|
369
|
|
- SKP_assert( predictLPCOrder >= 10 ); /* check that unrolling works */
|
370
|
|
-
|
371
|
|
- /* Partially unrolled */
|
372
|
|
- Atmp = a_Q12_tmp[ 0 ]; /* read two coefficients at once */
|
373
|
|
- LPC_pred_Q10 = SKP_SMULWB( psLPC_Q14[ 0 ], Atmp );
|
374
|
|
- LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -1 ], Atmp );
|
375
|
|
- Atmp = a_Q12_tmp[ 1 ];
|
376
|
|
- LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -2 ], Atmp );
|
377
|
|
- LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -3 ], Atmp );
|
378
|
|
- Atmp = a_Q12_tmp[ 2 ];
|
379
|
|
- LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -4 ], Atmp );
|
380
|
|
- LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -5 ], Atmp );
|
381
|
|
- Atmp = a_Q12_tmp[ 3 ];
|
382
|
|
- LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -6 ], Atmp );
|
383
|
|
- LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -7 ], Atmp );
|
384
|
|
- Atmp = a_Q12_tmp[ 4 ];
|
385
|
|
- LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -8 ], Atmp );
|
386
|
|
- LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -9 ], Atmp );
|
387
|
|
-
|
388
|
|
- /*for( j = 10; j < predictLPCOrder; j += 2 ) {
|
389
|
|
- Atmp = a_Q12_tmp[ j >> 1 ]; *//* read two coefficients at once *//*
|
390
|
|
- LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ -j ], Atmp );
|
391
|
|
- LPC_pred_Q10 = SKP_SMLAWT( LPC_pred_Q10, psLPC_Q14[ -j - 1 ], Atmp );
|
392
|
|
- }*/
|
393
|
|
-
|
394
|
|
- LPC_pred_Q10 = SKP_SMLAWB( LPC_pred_Q10, psLPC_Q14[ 0], Atmp );
|
395
|
|
- cout "czb " + LPC_pred_Q10;
|
396
|
|
-
|
397
|
|
- /* Noise shape feedback */
|
398
|
|
- SKP_assert( ( shapingLPCOrder & 1 ) == 0 ); /* check that order is even */
|
399
|
|
- SKP_assert( ( (SKP_int64)AR_shp_Q13 & 3 ) == 0 ); /* check that array starts at 4-byte aligned address */
|
400
|
|
- SKP_assert( shapingLPCOrder >= 12 ); /* check that unrolling works */
|
401
|
|
-
|
402
|
|
- /* Partially unrolled */
|
403
|
|
- Atmp = AR_shp_Q13_tmp[ 0 ]; /* read two coefficients at once */
|
404
|
|
- n_AR_Q10 = SKP_SMULWB( psLPC_Q14[ 0 ], Atmp );
|
405
|
|
- n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -1 ], Atmp );
|
406
|
|
- Atmp = AR_shp_Q13_tmp[ 1 ];
|
407
|
|
- n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -2 ], Atmp );
|
408
|
|
- n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -3 ], Atmp );
|
409
|
|
- Atmp = AR_shp_Q13_tmp[ 2 ];
|
410
|
|
- n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -4 ], Atmp );
|
411
|
|
- n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -5 ], Atmp );
|
412
|
|
- Atmp = AR_shp_Q13_tmp[ 3 ];
|
413
|
|
- n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -6 ], Atmp );
|
414
|
|
- n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -7 ], Atmp );
|
415
|
|
- Atmp = AR_shp_Q13_tmp[ 4 ];
|
416
|
|
- n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -8 ], Atmp );
|
417
|
|
- n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -9 ], Atmp );
|
418
|
|
- Atmp = AR_shp_Q13_tmp[ 5 ];
|
419
|
|
- n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -10 ], Atmp );
|
420
|
|
- n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -11 ], Atmp );
|
421
|
|
- for( j = 12; j < shapingLPCOrder; j += 2 ) {
|
422
|
|
- Atmp = AR_shp_Q13_tmp[ j >> 1 ]; /* read two coefficients at once */
|
423
|
|
- n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psLPC_Q14[ -j ], Atmp );
|
424
|
|
- n_AR_Q10 = SKP_SMLAWT( n_AR_Q10, psLPC_Q14[ -j - 1 ], Atmp );
|
425
|
|
- }
|
426
|
|
- n_AR_Q10 = SKP_RSHIFT( n_AR_Q10, 1 ); /* Q11 -> Q10 */
|
427
|
|
- n_AR_Q10 = SKP_SMLAWB( n_AR_Q10, psDD->LF_AR_Q12, Tilt_Q14 );
|
428
|
|
-
|
429
|
|
- n_LF_Q10 = SKP_LSHIFT( SKP_SMULWB( psDD->Shape_Q10[ *smpl_buf_idx ], LF_shp_Q14 ), 2 );
|
430
|
|
- n_LF_Q10 = SKP_SMLAWT( n_LF_Q10, psDD->LF_AR_Q12, LF_shp_Q14 );
|
431
|
|
-
|
432
|
|
- /* Input minus prediction plus noise feedback */
|
433
|
|
- /* r = x[ i ] - LTP_pred - LPC_pred + n_AR + n_Tilt + n_LF + n_LTP */
|
434
|
|
- tmp = SKP_SUB32( LTP_pred_Q14, n_LTP_Q14 ); /* Add Q14 stuff */
|
435
|
|
- tmp = SKP_RSHIFT_ROUND( tmp, 4 ); /* round to Q10 */
|
436
|
|
- tmp = SKP_ADD32( tmp, LPC_pred_Q10 ); /* add Q10 stuff */
|
437
|
|
- tmp = SKP_SUB32( tmp, n_AR_Q10 ); /* subtract Q10 stuff */
|
438
|
|
- tmp = SKP_SUB32( tmp, n_LF_Q10 ); /* subtract Q10 stuff */
|
439
|
|
- r_Q10 = SKP_SUB32( x_Q10[ i ], tmp ); /* residual error Q10 */
|
440
|
|
-
|
441
|
|
- r_Q10 = ( r_Q10 ^ dither ) - dither;
|
442
|
|
- r_Q10 = SKP_SUB32( r_Q10, offset_Q10 );
|
443
|
|
- r_Q10 = SKP_LIMIT( r_Q10, -64 << 10, 64 << 10 );
|
444
|
|
-
|
445
|
|
- if( r_Q10 < -1536 ) {
|
446
|
|
- q1_Q10 = SKP_LSHIFT( SKP_RSHIFT_ROUND( r_Q10, 10 ), 10 );
|
447
|
|
- r_Q10 = SKP_SUB32( r_Q10, q1_Q10 );
|
448
|
|
- rd1_Q10 = SKP_RSHIFT( SKP_SMLABB( SKP_MUL( -SKP_ADD32( q1_Q10, offset_Q10 ), Lambda_Q10 ), r_Q10, r_Q10 ), 10 );
|
449
|
|
- rd2_Q10 = SKP_ADD32( rd1_Q10, 1024 );
|
450
|
|
- rd2_Q10 = SKP_SUB32( rd2_Q10, SKP_ADD_LSHIFT32( Lambda_Q10, r_Q10, 1 ) );
|
451
|
|
- q2_Q10 = SKP_ADD32( q1_Q10, 1024 );
|
452
|
|
- } else if( r_Q10 > 512 ) {
|
453
|
|
- q1_Q10 = SKP_LSHIFT( SKP_RSHIFT_ROUND( r_Q10, 10 ), 10 );
|
454
|
|
- r_Q10 = SKP_SUB32( r_Q10, q1_Q10 );
|
455
|
|
- rd1_Q10 = SKP_RSHIFT( SKP_SMLABB( SKP_MUL( SKP_ADD32( q1_Q10, offset_Q10 ), Lambda_Q10 ), r_Q10, r_Q10 ), 10 );
|
456
|
|
- rd2_Q10 = SKP_ADD32( rd1_Q10, 1024 );
|
457
|
|
- rd2_Q10 = SKP_SUB32( rd2_Q10, SKP_SUB_LSHIFT32( Lambda_Q10, r_Q10, 1 ) );
|
458
|
|
- q2_Q10 = SKP_SUB32( q1_Q10, 1024 );
|
459
|
|
- } else { /* r_Q10 >= -1536 && q1_Q10 <= 512 */
|
460
|
|
- rr_Q20 = SKP_SMULBB( offset_Q10, Lambda_Q10 );
|
461
|
|
- rd2_Q10 = SKP_RSHIFT( SKP_SMLABB( rr_Q20, r_Q10, r_Q10 ), 10 );
|
462
|
|
- rd1_Q10 = SKP_ADD32( rd2_Q10, 1024 );
|
463
|
|
- rd1_Q10 = SKP_ADD32( rd1_Q10, SKP_SUB_RSHIFT32( SKP_ADD_LSHIFT32( Lambda_Q10, r_Q10, 1 ), rr_Q20, 9 ) );
|
464
|
|
- q1_Q10 = -1024;
|
465
|
|
- q2_Q10 = 0;
|
466
|
|
- }
|
467
|
|
-
|
468
|
|
- if( rd1_Q10 < rd2_Q10 ) {
|
469
|
|
- psSS[ 0 ].RD_Q10 = SKP_ADD32( psDD->RD_Q10, rd1_Q10 );
|
470
|
|
- psSS[ 1 ].RD_Q10 = SKP_ADD32( psDD->RD_Q10, rd2_Q10 );
|
471
|
|
- psSS[ 0 ].Q_Q10 = q1_Q10;
|
472
|
|
- psSS[ 1 ].Q_Q10 = q2_Q10;
|
473
|
|
- } else {
|
474
|
|
- psSS[ 0 ].RD_Q10 = SKP_ADD32( psDD->RD_Q10, rd2_Q10 );
|
475
|
|
- psSS[ 1 ].RD_Q10 = SKP_ADD32( psDD->RD_Q10, rd1_Q10 );
|
476
|
|
- psSS[ 0 ].Q_Q10 = q2_Q10;
|
477
|
|
- psSS[ 1 ].Q_Q10 = q1_Q10;
|
478
|
|
- }
|
479
|
|
-
|
480
|
|
- /* Update states for best quantization */
|
481
|
|
-
|
482
|
|
- /* Quantized excitation */
|
483
|
|
- exc_Q10 = SKP_ADD32( offset_Q10, psSS[ 0 ].Q_Q10 );
|
484
|
|
- exc_Q10 = ( exc_Q10 ^ dither ) - dither;
|
485
|
|
-
|
486
|
|
- /* Add predictions */
|
487
|
|
- LPC_exc_Q10 = exc_Q10 + SKP_RSHIFT_ROUND( LTP_pred_Q14, 4 );
|
488
|
|
- xq_Q10 = SKP_ADD32( LPC_exc_Q10, LPC_pred_Q10 );
|
489
|
|
-
|
490
|
|
- /* Update states */
|
491
|
|
- sLF_AR_shp_Q10 = SKP_SUB32( xq_Q10, n_AR_Q10 );
|
492
|
|
- psSS[ 0 ].sLTP_shp_Q10 = SKP_SUB32( sLF_AR_shp_Q10, n_LF_Q10 );
|
493
|
|
- psSS[ 0 ].LF_AR_Q12 = SKP_LSHIFT( sLF_AR_shp_Q10, 2 );
|
494
|
|
- psSS[ 0 ].xq_Q14 = SKP_LSHIFT( xq_Q10, 4 );
|
495
|
|
- psSS[ 0 ].LPC_exc_Q16 = SKP_LSHIFT( LPC_exc_Q10, 6 );
|
496
|
|
-
|
497
|
|
- /* Update states for second best quantization */
|
498
|
|
-
|
499
|
|
- /* Quantized excitation */
|
500
|
|
- exc_Q10 = SKP_ADD32( offset_Q10, psSS[ 1 ].Q_Q10 );
|
501
|
|
- exc_Q10 = ( exc_Q10 ^ dither ) - dither;
|
502
|
|
-
|
503
|
|
- /* Add predictions */
|
504
|
|
- LPC_exc_Q10 = exc_Q10 + SKP_RSHIFT_ROUND( LTP_pred_Q14, 4 );
|
505
|
|
- xq_Q10 = SKP_ADD32( LPC_exc_Q10, LPC_pred_Q10 );
|
506
|
|
-
|
507
|
|
- /* Update states */
|
508
|
|
- sLF_AR_shp_Q10 = SKP_SUB32( xq_Q10, n_AR_Q10 );
|
509
|
|
- psSS[ 1 ].sLTP_shp_Q10 = SKP_SUB32( sLF_AR_shp_Q10, n_LF_Q10 );
|
510
|
|
- psSS[ 1 ].LF_AR_Q12 = SKP_LSHIFT( sLF_AR_shp_Q10, 2 );
|
511
|
|
- psSS[ 1 ].xq_Q14 = SKP_LSHIFT( xq_Q10, 4 );
|
512
|
|
- psSS[ 1 ].LPC_exc_Q16 = SKP_LSHIFT( LPC_exc_Q10, 6 );
|
513
|
|
- }
|
514
|
|
-
|
515
|
|
- *smpl_buf_idx = ( *smpl_buf_idx - 1 ) & DECISION_DELAY_MASK; /* Index to newest samples */
|
516
|
|
- last_smple_idx = ( *smpl_buf_idx + decisionDelay ) & DECISION_DELAY_MASK; /* Index to decisionDelay old samples */
|
517
|
|
-
|
518
|
|
- /* Find winner */
|
519
|
|
- RDmin_Q10 = psSampleState[ 0 ][ 0 ].RD_Q10;
|
520
|
|
- Winner_ind = 0;
|
521
|
|
- for( k = 1; k < nStatesDelayedDecision; k++ ) {
|
522
|
|
- if( psSampleState[ k ][ 0 ].RD_Q10 < RDmin_Q10 ) {
|
523
|
|
- RDmin_Q10 = psSampleState[ k ][ 0 ].RD_Q10;
|
524
|
|
- Winner_ind = k;
|
525
|
|
- }
|
526
|
|
- }
|
527
|
|
-
|
528
|
|
- /* Increase RD values of expired states */
|
529
|
|
- Winner_rand_state = psDelDec[ Winner_ind ].RandState[ last_smple_idx ];
|
530
|
|
- for( k = 0; k < nStatesDelayedDecision; k++ ) {
|
531
|
|
- if( psDelDec[ k ].RandState[ last_smple_idx ] != Winner_rand_state ) {
|
532
|
|
- psSampleState[ k ][ 0 ].RD_Q10 = SKP_ADD32( psSampleState[ k ][ 0 ].RD_Q10, ( SKP_int32_MAX >> 4 ) );
|
533
|
|
- psSampleState[ k ][ 1 ].RD_Q10 = SKP_ADD32( psSampleState[ k ][ 1 ].RD_Q10, ( SKP_int32_MAX >> 4 ) );
|
534
|
|
- SKP_assert( psSampleState[ k ][ 0 ].RD_Q10 >= 0 );
|
535
|
|
- }
|
536
|
|
- }
|
537
|
|
-
|
538
|
|
- /* Find worst in first set and best in second set */
|
539
|
|
- RDmax_Q10 = psSampleState[ 0 ][ 0 ].RD_Q10;
|
540
|
|
- RDmin_Q10 = psSampleState[ 0 ][ 1 ].RD_Q10;
|
541
|
|
- RDmax_ind = 0;
|
542
|
|
- RDmin_ind = 0;
|
543
|
|
- for( k = 1; k < nStatesDelayedDecision; k++ ) {
|
544
|
|
- /* find worst in first set */
|
545
|
|
- if( psSampleState[ k ][ 0 ].RD_Q10 > RDmax_Q10 ) {
|
546
|
|
- RDmax_Q10 = psSampleState[ k ][ 0 ].RD_Q10;
|
547
|
|
- RDmax_ind = k;
|
548
|
|
- }
|
549
|
|
- /* find best in second set */
|
550
|
|
- if( psSampleState[ k ][ 1 ].RD_Q10 < RDmin_Q10 ) {
|
551
|
|
- RDmin_Q10 = psSampleState[ k ][ 1 ].RD_Q10;
|
552
|
|
- RDmin_ind = k;
|
553
|
|
- }
|
554
|
|
- }
|
555
|
|
-
|
556
|
|
- cout "czb " + RDmax_Q10;
|
557
|
|
-
|
558
|
|
- /* Replace a state if best from second set outperforms worst in first set */
|
559
|
|
- if( RDmin_Q10 < RDmax_Q10 ) {
|
560
|
|
- SKP_Silk_copy_del_dec_state( &psDelDec[ RDmax_ind ], &psDelDec[ RDmin_ind ], i );
|
561
|
|
- SKP_memcpy( &psSampleState[ RDmax_ind ][ 0 ], &psSampleState[ RDmin_ind ][ 1 ], sizeof( NSQ_sample_struct ) );
|
562
|
|
- }
|
563
|
|
-
|
564
|
|
- /* Write samples from winner to output and long-term filter states */
|
565
|
|
- psDD = &psDelDec[ Winner_ind ];
|
566
|
|
- if( subfr > 0 || i >= decisionDelay ) {
|
567
|
|
- q[ i - decisionDelay ] = ( SKP_int )SKP_RSHIFT( psDD->Q_Q10[ last_smple_idx ], 10 );
|
568
|
|
- xq[ i - decisionDelay ] = ( SKP_int16 )SKP_SAT16( SKP_RSHIFT_ROUND(
|
569
|
|
- SKP_SMULWW( psDD->Xq_Q10[ last_smple_idx ], psDD->Gain_Q16[ last_smple_idx ] ), 10 ) );
|
570
|
|
- NSQ->sLTP_shp_Q10[ NSQ->sLTP_shp_buf_idx - decisionDelay ] = psDD->Shape_Q10[ last_smple_idx ];
|
571
|
|
- sLTP_Q16[ NSQ->sLTP_buf_idx - decisionDelay ] = psDD->Pred_Q16[ last_smple_idx ];
|
572
|
|
- }
|
573
|
|
- NSQ->sLTP_shp_buf_idx++;
|
574
|
|
- NSQ->sLTP_buf_idx++;
|
575
|
|
-
|
576
|
|
- /* Update states */
|
577
|
|
- for( k = 0; k < nStatesDelayedDecision; k++ ) {
|
578
|
|
- psDD = &psDelDec[ k ];
|
579
|
|
- psSS = &psSampleState[ k ][ 0 ];
|
580
|
|
- psDD->LF_AR_Q12 = psSS->LF_AR_Q12;
|
581
|
|
- psDD->sLPC_Q14[ NSQ_LPC_BUF_LENGTH + i ] = psSS->xq_Q14;
|
582
|
|
- psDD->Xq_Q10[ *smpl_buf_idx ] = SKP_RSHIFT( psSS->xq_Q14, 4 );
|
583
|
|
- psDD->Q_Q10[ *smpl_buf_idx ] = psSS->Q_Q10;
|
584
|
|
- psDD->Pred_Q16[ *smpl_buf_idx ] = psSS->LPC_exc_Q16;
|
585
|
|
- psDD->Shape_Q10[ *smpl_buf_idx ] = psSS->sLTP_shp_Q10;
|
586
|
|
- psDD->Seed = SKP_ADD_RSHIFT32( psDD->Seed, psSS->Q_Q10, 10 );
|
587
|
|
- psDD->RandState[ *smpl_buf_idx ] = psDD->Seed;
|
588
|
|
- psDD->RD_Q10 = psSS->RD_Q10;
|
589
|
|
- psDD->Gain_Q16[ *smpl_buf_idx ] = Gain_Q16;
|
590
|
|
- }
|
591
|
|
- }
|
592
|
|
- /* Update LPC states */
|
593
|
|
- for( k = 0; k < nStatesDelayedDecision; k++ ) {
|
594
|
|
- psDD = &psDelDec[ k ];
|
595
|
|
- SKP_memcpy( psDD->sLPC_Q14, &psDD->sLPC_Q14[ length ], NSQ_LPC_BUF_LENGTH * sizeof( SKP_int32 ) );
|
596
|
|
- }
|
597
|
|
-}
|
598
|
|
-
|
599
|
|
-SKP_INLINE void SKP_Silk_nsq_del_dec_scale_states(
|
600
|
|
- SKP_Silk_nsq_state *NSQ, /* I/O NSQ state */
|
601
|
|
- NSQ_del_dec_struct psDelDec[], /* I/O Delayed decision states */
|
602
|
|
- const SKP_int16 x[], /* I Input in Q0 */
|
603
|
|
- SKP_int32 x_sc_Q10[], /* O Input scaled with 1/Gain in Q10 */
|
604
|
|
- SKP_int length, /* I Length of input */
|
605
|
|
- SKP_int16 sLTP[], /* I Re-whitened LTP state in Q0 */
|
606
|
|
- SKP_int32 sLTP_Q16[], /* O LTP state matching scaled input */
|
607
|
|
- SKP_int subfr, /* I Subframe number */
|
608
|
|
- SKP_int nStatesDelayedDecision, /* I Number of del dec states */
|
609
|
|
- SKP_int smpl_buf_idx, /* I Index to newest samples in buffers */
|
610
|
|
- const SKP_int LTP_scale_Q14, /* I LTP state scaling */
|
611
|
|
- const SKP_int32 Gains_Q16[ NB_SUBFR ], /* I */
|
612
|
|
- const SKP_int pitchL[ NB_SUBFR ] /* I Pitch lag */
|
613
|
|
-)
|
614
|
|
-{
|
615
|
|
- SKP_int i, k, scale_length, lag;
|
616
|
|
- SKP_int32 inv_gain_Q16, gain_adj_Q16, inv_gain_Q32;
|
617
|
|
- NSQ_del_dec_struct *psDD;
|
618
|
|
-
|
619
|
|
- inv_gain_Q16 = SKP_DIV32( SKP_int32_MAX, SKP_RSHIFT( Gains_Q16[ subfr ], 1 ) );
|
620
|
|
- inv_gain_Q16 = SKP_min( inv_gain_Q16, SKP_int16_MAX );
|
621
|
|
- lag = pitchL[ subfr ];
|
622
|
|
- /* After rewhitening the LTP state is un-scaled. So scale with inv_gain_Q16 */
|
623
|
|
- if( NSQ->rewhite_flag ) {
|
624
|
|
- inv_gain_Q32 = SKP_LSHIFT( inv_gain_Q16, 16 );
|
625
|
|
- if( subfr == 0 ) {
|
626
|
|
- /* Do LTP downscaling */
|
627
|
|
- inv_gain_Q32 = SKP_LSHIFT( SKP_SMULWB( inv_gain_Q32, LTP_scale_Q14 ), 2 );
|
628
|
|
- }
|
629
|
|
- for( i = NSQ->sLTP_buf_idx - lag - LTP_ORDER / 2; i < NSQ->sLTP_buf_idx; i++ ) {
|
630
|
|
- SKP_assert( i < MAX_FRAME_LENGTH );
|
631
|
|
- sLTP_Q16[ i ] = SKP_SMULWB( inv_gain_Q32, sLTP[ i ] );
|
632
|
|
- }
|
633
|
|
- }
|
634
|
|
-
|
635
|
|
- /* Adjust for changing gain */
|
636
|
|
- if( inv_gain_Q16 != NSQ->prev_inv_gain_Q16 ) {
|
637
|
|
- gain_adj_Q16 = SKP_DIV32_varQ( inv_gain_Q16, NSQ->prev_inv_gain_Q16, 16 );
|
638
|
|
-
|
639
|
|
- for( k = 0; k < nStatesDelayedDecision; k++ ) {
|
640
|
|
- psDD = &psDelDec[ k ];
|
641
|
|
-
|
642
|
|
- /* Scale scalar states */
|
643
|
|
- psDD->LF_AR_Q12 = SKP_SMULWW( gain_adj_Q16, psDD->LF_AR_Q12 );
|
644
|
|
-
|
645
|
|
- /* scale short term state */
|
646
|
|
- for( i = 0; i < NSQ_LPC_BUF_LENGTH; i++ ) {
|
647
|
|
- psDD->sLPC_Q14[ NSQ_LPC_BUF_LENGTH - i - 1 ] = SKP_SMULWW( gain_adj_Q16, psDD->sLPC_Q14[ NSQ_LPC_BUF_LENGTH - i - 1 ] );
|
648
|
|
- }
|
649
|
|
- for( i = 0; i < DECISION_DELAY; i++ ) {
|
650
|
|
- psDD->Pred_Q16[ i ] = SKP_SMULWW( gain_adj_Q16, psDD->Pred_Q16[ i ] );
|
651
|
|
- psDD->Shape_Q10[ i ] = SKP_SMULWW( gain_adj_Q16, psDD->Shape_Q10[ i ] );
|
652
|
|
- }
|
653
|
|
- }
|
654
|
|
-
|
655
|
|
- ostream& operator<<(ostream& psDD);
|
656
|
|
-
|
657
|
|
- /* Scale long term shaping state */
|
658
|
|
-
|
659
|
|
- /* Calculate length to be scaled, Worst case: Next frame is voiced with max lag */
|
660
|
|
- scale_length = length * NB_SUBFR; /* aprox max lag */
|
661
|
|
- scale_length = scale_length - SKP_SMULBB( NB_SUBFR - ( subfr + 1 ), length ); /* subtract samples that will be too old in next frame */
|
662
|
|
- scale_length = SKP_max_int( scale_length, lag + LTP_ORDER ); /* make sure to scale whole pitch period if voiced */
|
663
|
|
-
|
664
|
|
- for( i = NSQ->sLTP_shp_buf_idx - scale_length; i < NSQ->sLTP_shp_buf_idx; i++ ) {
|
665
|
|
- NSQ->sLTP_shp_Q10[ i ] = SKP_SMULWW( gain_adj_Q16, NSQ->sLTP_shp_Q10[ i ] );
|
666
|
|
- }
|
667
|
|
-
|
668
|
|
- /* Scale LTP predict state */
|
669
|
|
- if( NSQ->rewhite_flag == 0 ) {
|
670
|
|
- for( i = NSQ->sLTP_buf_idx - lag - LTP_ORDER / 2; i < NSQ->sLTP_buf_idx; i++ ) {
|
671
|
|
- sLTP_Q16[ i ] = SKP_SMULWW( gain_adj_Q16, sLTP_Q16[ i ] );
|
672
|
|
- }
|
673
|
|
- }
|
674
|
|
- }
|
675
|
|
-
|
676
|
|
- /* Scale input */
|
677
|
|
- for( i = 0; i < length; i++ ) {
|
678
|
|
- x_sc_Q10[ i ] = SKP_RSHIFT( SKP_SMULBB( x[ i ], ( SKP_int16 )inv_gain_Q16 ), 6 );
|
679
|
|
- }
|
680
|
|
-
|
681
|
|
- /* save inv_gain */
|
682
|
|
- SKP_assert( inv_gain_Q16 != 0 );
|
683
|
|
- NSQ->prev_inv_gain_Q16 = inv_gain_Q16;
|
684
|
|
-}
|
685
|
|
-
|
686
|
|
-SKP_INLINE void SKP_Silk_copy_del_dec_state(
|
687
|
|
- NSQ_del_dec_struct *DD_dst, // 目标
|
688
|
|
- NSQ_del_dec_struct *DD_src, // 源
|
689
|
|
- SKP_int LPC_state_idx
|
690
|
|
-)
|
691
|
|
-{
|
692
|
|
- SKP_memcpy( DD_dst->RandState, DD_src->RandState, DECISION_DELAY * sizeof( SKP_int ) );
|
693
|
|
- SKP_memcpy( DD_dst->Q_Q10, DD_src->Q_Q10, DECISION_DELAY * sizeof( SKP_int32 ) );
|
694
|
|
- SKP_memcpy( DD_dst->Pred_Q16, DD_src->Pred_Q16, DECISION_DELAY * sizeof( SKP_int32 ) );
|
695
|
|
- SKP_memcpy( DD_dst->Shape_Q10, DD_src->Shape_Q10, DECISION_DELAY * sizeof( SKP_int32 ) );
|
696
|
|
- SKP_memcpy( DD_dst->Xq_Q10, DD_src->Xq_Q10, DECISION_DELAY * sizeof( SKP_int32 ) );
|
697
|
|
-
|
698
|
|
- SKP_memcpy( &DD_dst->sLPC_Q14[ LPC_state_idx ], &DD_src->sLPC_Q14[ LPC_state_idx ], NSQ_LPC_BUF_LENGTH * sizeof( SKP_int32 ) );
|
699
|
|
- DD_dst->LF_AR_Q12 = DD_src->LF_AR_Q12;
|
700
|
|
- DD_dst->Seed = DD_src->Seed;
|
701
|
|
- DD_dst->SeedInit = DD_src->SeedInit;
|
702
|
|
- DD_dst->RD_Q10 = DD_src->RD_Q10;
|
703
|
|
-
|
704
|
|
- // TODO
|
705
|
|
- // 释放源资源
|
706
|
|
-}
|