@@ -109,6 +109,7 @@ use crate::silk::structs::{silk_encoder_state, silk_nsq_state, SideInfoIndices};
109
109
use crate :: silk:: tables_other:: silk_Quantization_Offsets_Q10;
110
110
use crate :: silk:: Inlines :: { silk_DIV32_varQ, silk_INVERSE32_varQ} ;
111
111
use crate :: silk:: LPC_analysis_filter :: silk_LPC_analysis_filter;
112
+ use crate :: silk:: SigProc_FIX :: silk_RAND;
112
113
113
114
pub unsafe fn silk_NSQ_c (
114
115
psEncC : & silk_encoder_state ,
@@ -152,17 +153,17 @@ pub unsafe fn silk_NSQ_c(
152
153
let mut sLTP: Vec < i16 > = :: std:: vec:: from_elem ( 0 , vla_0) ;
153
154
let vla_1 = psEncC. subfr_length as usize ;
154
155
let mut x_sc_Q10: Vec < i32 > = :: std:: vec:: from_elem ( 0 , vla_1) ;
155
- ( * NSQ ) . sLTP_shp_buf_idx = psEncC. ltp_mem_length ;
156
- ( * NSQ ) . sLTP_buf_idx = psEncC. ltp_mem_length ;
156
+ ( * NSQ ) . sLTP_shp_buf_idx = psEncC. ltp_mem_length as i32 ;
157
+ ( * NSQ ) . sLTP_buf_idx = psEncC. ltp_mem_length as i32 ;
157
158
pxq = & mut * ( ( * NSQ ) . xq )
158
159
. as_mut_ptr ( )
159
160
. offset ( psEncC. ltp_mem_length as isize ) as * mut i16 ;
160
161
k = 0 ;
161
- while k < psEncC. nb_subfr {
162
+ while k < psEncC. nb_subfr as i32 {
162
163
A_Q12 = & * PredCoef_Q12
163
- . offset ( ( ( k >> 1 | 1 - LSF_interpolation_flag ) * MAX_LPC_ORDER ) as isize )
164
+ . offset ( ( ( k >> 1 | 1 - LSF_interpolation_flag ) * MAX_LPC_ORDER as i32 ) as isize )
164
165
as * const i16 ;
165
- B_Q14 = & * LTPCoef_Q14 . offset ( ( k * LTP_ORDER ) as isize ) as * const i16 ;
166
+ B_Q14 = & * LTPCoef_Q14 . offset ( ( k * LTP_ORDER as i32 ) as isize ) as * const i16 ;
166
167
AR_shp_Q13 = & * AR_Q13 . offset ( ( k * MAX_SHAPE_LPC_ORDER ) as isize ) as * const i16 ;
167
168
HarmShapeFIRPacked_Q14 = * HarmShapeGain_Q14 . offset ( k as isize ) >> 2 ;
168
169
HarmShapeFIRPacked_Q14 |=
@@ -171,17 +172,19 @@ pub unsafe fn silk_NSQ_c(
171
172
if ( * psIndices) . signalType as i32 == TYPE_VOICED {
172
173
lag = * pitchL. offset ( k as isize ) ;
173
174
if k & 3 - ( ( LSF_interpolation_flag as u32 ) << 1 ) as i32 == 0 {
174
- start_idx =
175
- psEncC. ltp_mem_length - lag - psEncC. predictLPCOrder - LTP_ORDER / 2 ;
175
+ start_idx = psEncC. ltp_mem_length as i32
176
+ - lag
177
+ - psEncC. predictLPCOrder
178
+ - LTP_ORDER as i32 / 2 ;
176
179
assert ! ( start_idx > 0 ) ;
177
180
silk_LPC_analysis_filter (
178
181
& mut sLTP[ start_idx as usize ..psEncC. ltp_mem_length as usize ] ,
179
- & ( * NSQ ) . xq [ ( start_idx + k * psEncC. subfr_length ) as usize ..]
180
- [ ..( psEncC. ltp_mem_length - start_idx) as usize ] ,
182
+ & ( * NSQ ) . xq [ ( start_idx + k * psEncC. subfr_length as i32 ) as usize ..]
183
+ [ ..( psEncC. ltp_mem_length - start_idx as usize ) as usize ] ,
181
184
std:: slice:: from_raw_parts ( A_Q12 , psEncC. predictLPCOrder as usize ) ,
182
185
) ;
183
186
( * NSQ ) . rewhite_flag = 1 ;
184
- ( * NSQ ) . sLTP_buf_idx = psEncC. ltp_mem_length ;
187
+ ( * NSQ ) . sLTP_buf_idx = psEncC. ltp_mem_length as i32 ;
185
188
}
186
189
}
187
190
silk_nsq_scale_states (
@@ -214,7 +217,7 @@ pub unsafe fn silk_NSQ_c(
214
217
* Gains_Q16 . offset ( k as isize ) ,
215
218
Lambda_Q10 ,
216
219
offset_Q10,
217
- psEncC. subfr_length ,
220
+ psEncC. subfr_length as i32 ,
218
221
psEncC. shapingLPCOrder ,
219
222
psEncC. predictLPCOrder ,
220
223
psEncC. arch ,
@@ -229,16 +232,14 @@ pub unsafe fn silk_NSQ_c(
229
232
( ( * NSQ ) . xq ) . as_mut_ptr ( ) as * mut core:: ffi:: c_void ,
230
233
& mut * ( ( * NSQ ) . xq )
231
234
. as_mut_ptr ( )
232
- . offset ( psEncC. frame_length as isize ) as * mut i16
233
- as * const core:: ffi:: c_void ,
235
+ . offset ( psEncC. frame_length as isize ) as * mut i16 as * const core:: ffi:: c_void ,
234
236
( psEncC. ltp_mem_length as u64 ) . wrapping_mul ( :: core:: mem:: size_of :: < i16 > ( ) as u64 ) ,
235
237
) ;
236
238
memmove (
237
239
( ( * NSQ ) . sLTP_shp_Q14 ) . as_mut_ptr ( ) as * mut core:: ffi:: c_void ,
238
240
& mut * ( ( * NSQ ) . sLTP_shp_Q14 )
239
241
. as_mut_ptr ( )
240
- . offset ( psEncC. frame_length as isize ) as * mut i32
241
- as * const core:: ffi:: c_void ,
242
+ . offset ( psEncC. frame_length as isize ) as * mut i32 as * const core:: ffi:: c_void ,
242
243
( psEncC. ltp_mem_length as u64 ) . wrapping_mul ( :: core:: mem:: size_of :: < i32 > ( ) as u64 ) ,
243
244
) ;
244
245
}
@@ -292,16 +293,16 @@ unsafe fn silk_noise_shape_quantizer(
292
293
. as_mut_ptr ( )
293
294
. offset ( ( ( * NSQ ) . sLTP_shp_buf_idx - lag + HARM_SHAPE_FIR_TAPS / 2 ) as isize )
294
295
as * mut i32 ;
295
- pred_lag_ptr =
296
- & mut * sLTP_Q15. offset ( ( ( * NSQ ) . sLTP_buf_idx - lag + LTP_ORDER / 2 ) as isize ) as * mut i32 ;
296
+ pred_lag_ptr = & mut * sLTP_Q15
297
+ . offset ( ( ( * NSQ ) . sLTP_buf_idx - lag + LTP_ORDER as i32 / 2 ) as isize )
298
+ as * mut i32 ;
297
299
Gain_Q10 = Gain_Q16 >> 6 ;
298
300
psLPC_Q14 = & mut * ( ( * NSQ ) . sLPC_Q14 )
299
301
. as_mut_ptr ( )
300
302
. offset ( ( NSQ_LPC_BUF_LENGTH - 1 ) as isize ) as * mut i32 ;
301
303
i = 0 ;
302
304
while i < length {
303
- ( * NSQ ) . rand_seed =
304
- 907633515_u32 . wrapping_add ( ( ( * NSQ ) . rand_seed as u32 ) . wrapping_mul ( 196314165 ) ) as i32 ;
305
+ ( * NSQ ) . rand_seed = silk_RAND ( ( * NSQ ) . rand_seed ) ;
305
306
LPC_pred_Q10 =
306
307
silk_noise_shape_quantizer_short_prediction_c ( psLPC_Q14, a_Q12, predictLPCOrder) ;
307
308
if signalType == TYPE_VOICED {
@@ -518,7 +519,7 @@ unsafe fn silk_nsq_scale_states(
518
519
( inv_gain_Q31 >> 5 - 1 ) + 1 >> 1
519
520
} ;
520
521
i = 0 ;
521
- while i < psEncC. subfr_length {
522
+ while i < psEncC. subfr_length as i32 {
522
523
* x_sc_Q10. offset ( i as isize ) =
523
524
( * x16. offset ( i as isize ) as i64 * inv_gain_Q26 as i64 >> 16 ) as i32 ;
524
525
i += 1 ;
@@ -529,7 +530,7 @@ unsafe fn silk_nsq_scale_states(
529
530
as u32 )
530
531
<< 2 ) as i32 ;
531
532
}
532
- i = ( * NSQ ) . sLTP_buf_idx - lag - LTP_ORDER / 2 ;
533
+ i = ( * NSQ ) . sLTP_buf_idx - lag - LTP_ORDER as i32 / 2 ;
533
534
while i < ( * NSQ ) . sLTP_buf_idx {
534
535
* sLTP_Q15. offset ( i as isize ) =
535
536
( inv_gain_Q31 as i64 * * sLTP. offset ( i as isize ) as i64 >> 16 ) as i32 ;
@@ -538,14 +539,14 @@ unsafe fn silk_nsq_scale_states(
538
539
}
539
540
if * Gains_Q16 . offset ( subfr as isize ) != ( * NSQ ) . prev_gain_Q16 {
540
541
gain_adj_Q16 = silk_DIV32_varQ ( ( * NSQ ) . prev_gain_Q16 , * Gains_Q16 . offset ( subfr as isize ) , 16 ) ;
541
- i = ( * NSQ ) . sLTP_shp_buf_idx - psEncC. ltp_mem_length ;
542
+ i = ( * NSQ ) . sLTP_shp_buf_idx - psEncC. ltp_mem_length as i32 ;
542
543
while i < ( * NSQ ) . sLTP_shp_buf_idx {
543
544
( * NSQ ) . sLTP_shp_Q14 [ i as usize ] =
544
545
( gain_adj_Q16 as i64 * ( * NSQ ) . sLTP_shp_Q14 [ i as usize ] as i64 >> 16 ) as i32 ;
545
546
i += 1 ;
546
547
}
547
548
if signal_type == TYPE_VOICED && ( * NSQ ) . rewhite_flag == 0 {
548
- i = ( * NSQ ) . sLTP_buf_idx - lag - LTP_ORDER / 2 ;
549
+ i = ( * NSQ ) . sLTP_buf_idx - lag - LTP_ORDER as i32 / 2 ;
549
550
while i < ( * NSQ ) . sLTP_buf_idx {
550
551
* sLTP_Q15. offset ( i as isize ) =
551
552
( gain_adj_Q16 as i64 * * sLTP_Q15. offset ( i as isize ) as i64 >> 16 ) as i32 ;
@@ -555,7 +556,7 @@ unsafe fn silk_nsq_scale_states(
555
556
( * NSQ ) . sLF_AR_shp_Q14 = ( gain_adj_Q16 as i64 * ( * NSQ ) . sLF_AR_shp_Q14 as i64 >> 16 ) as i32 ;
556
557
( * NSQ ) . sDiff_shp_Q14 = ( gain_adj_Q16 as i64 * ( * NSQ ) . sDiff_shp_Q14 as i64 >> 16 ) as i32 ;
557
558
i = 0 ;
558
- while i < NSQ_LPC_BUF_LENGTH {
559
+ while i < NSQ_LPC_BUF_LENGTH as i32 {
559
560
( * NSQ ) . sLPC_Q14 [ i as usize ] =
560
561
( gain_adj_Q16 as i64 * ( * NSQ ) . sLPC_Q14 [ i as usize ] as i64 >> 16 ) as i32 ;
561
562
i += 1 ;
0 commit comments