1
- use crate :: externs:: { memcpy, memset} ;
2
1
use crate :: silk:: bwexpander:: silk_bwexpander;
3
2
use crate :: silk:: decode_pitch:: silk_decode_pitch;
4
3
use crate :: silk:: define:: { BWE_AFTER_LOSS_Q16 , CODE_CONDITIONALLY , LTP_ORDER , TYPE_VOICED } ;
@@ -9,103 +8,121 @@ use crate::silk::tables_other::silk_LTPScales_table_Q14;
9
8
use crate :: silk:: NLSF_decode :: silk_NLSF_decode;
10
9
use crate :: silk:: NLSF2A :: silk_NLSF2A;
11
10
12
- pub unsafe fn silk_decode_parameters (
11
+ /// Decode parameters from payload
12
+ ///
13
+ /// ```text
14
+ /// psDec I/O State
15
+ /// psDecCtrl I/O Decoder control
16
+ /// condCoding I The type of conditional coding to use
17
+ /// ```
18
+ pub fn silk_decode_parameters (
13
19
psDec : & mut silk_decoder_state ,
14
- psDecCtrl : * mut silk_decoder_control ,
20
+ psDecCtrl : & mut silk_decoder_control ,
15
21
condCoding : i32 ,
16
22
) {
17
- let mut i: i32 = 0 ;
18
- let mut k: i32 = 0 ;
19
- let mut Ix : i32 = 0 ;
20
- let mut pNLSF_Q15: [ i16 ; 16 ] = [ 0 ; 16 ] ;
21
- let mut pNLSF0_Q15: [ i16 ; 16 ] = [ 0 ; 16 ] ;
22
- let mut cbk_ptr_Q7: * const i8 = 0 as * const i8 ;
23
+ let [ PredCoef_Q12_0 , PredCoef_Q12_1 ] = & mut psDecCtrl. PredCoef_Q12 ;
24
+ let PredCoef_Q12_0 = & mut PredCoef_Q12_0 [ ..psDec. LPC_order as usize ] ;
25
+ let PredCoef_Q12_1 = & mut PredCoef_Q12_1 [ ..psDec. LPC_order as usize ] ;
26
+
27
+ let Gains_Q16 = & mut psDecCtrl. Gains_Q16 [ ..psDec. nb_subfr as usize ] ;
28
+ let GainsIndices = & psDec. indices . GainsIndices [ ..psDec. nb_subfr as usize ] ;
29
+
30
+ let NLSFIndices = & psDec. indices . NLSFIndices [ ..psDec. psNLSF_CB . order as usize + 1 ] ;
31
+
32
+ let prevNLSF_Q15 = & mut psDec. prevNLSF_Q15 [ ..psDec. LPC_order as usize ] ;
33
+
34
+ let pitchL = & mut psDecCtrl. pitchL [ ..psDec. nb_subfr as usize ] ;
35
+
36
+ let LTPCoef_Q14 = & mut psDecCtrl. LTPCoef_Q14 [ ..psDec. nb_subfr as usize * LTP_ORDER as usize ] ;
37
+
38
+ /* Dequant Gains */
23
39
silk_gains_dequant (
24
- & mut ( ( * psDecCtrl ) . Gains_Q16 ) [ ..psDec . nb_subfr as usize ] ,
25
- & psDec . indices . GainsIndices [ ..psDec . nb_subfr as usize ] ,
40
+ Gains_Q16 ,
41
+ GainsIndices ,
26
42
& mut psDec. LastGainIndex ,
27
43
condCoding == CODE_CONDITIONALLY ,
28
44
) ;
29
- silk_NLSF_decode (
30
- & mut pNLSF_Q15[ ..psDec. psNLSF_CB . order as usize ] ,
31
- & psDec. indices . NLSFIndices [ ..psDec. psNLSF_CB . order as usize + 1 ] ,
32
- psDec. psNLSF_CB ,
33
- ) ;
34
- silk_NLSF2A (
35
- & mut ( * psDecCtrl) . PredCoef_Q12 [ 1 ] [ ..psDec. LPC_order as usize ] ,
36
- & pNLSF_Q15[ ..psDec. LPC_order as usize ] ,
37
- ) ;
45
+
46
+ /****************/
47
+ /* Decode NLSFs */
48
+ /****************/
49
+ let mut pNLSF_Q15: [ i16 ; 16 ] = [ 0 ; 16 ] ;
50
+ let pNLSF_Q15 = & mut pNLSF_Q15[ ..psDec. LPC_order as usize ] ;
51
+ silk_NLSF_decode ( pNLSF_Q15, NLSFIndices , psDec. psNLSF_CB ) ;
52
+
53
+ /* Convert NLSF parameters to AR prediction filter coefficients */
54
+ silk_NLSF2A ( PredCoef_Q12_1 , pNLSF_Q15) ;
55
+
56
+ /* If just reset, e.g., because internal Fs changed, do not allow interpolation */
57
+ /* improves the case of packet loss in the first frame after a switch */
38
58
if psDec. first_frame_after_reset == 1 {
39
59
psDec. indices . NLSFInterpCoef_Q2 = 4 ;
40
60
}
41
61
if ( psDec. indices . NLSFInterpCoef_Q2 as i32 ) < 4 {
42
- i = 0 ;
43
- while i < psDec. LPC_order {
44
- pNLSF0_Q15[ i as usize ] = ( psDec. prevNLSF_Q15 [ i as usize ] as i32
45
- + ( psDec. indices . NLSFInterpCoef_Q2 as i32
46
- * ( pNLSF_Q15[ i as usize ] as i32 - psDec. prevNLSF_Q15 [ i as usize ] as i32 )
62
+ /* Calculation of the interpolated NLSF0 vector from the interpolation factor, */
63
+ /* the previous NLSF1, and the current NLSF1 */
64
+ let mut pNLSF0_Q15: [ i16 ; 16 ] = [ 0 ; 16 ] ;
65
+ let pNLSF0_Q15 = & mut pNLSF0_Q15[ ..psDec. LPC_order as usize ] ;
66
+
67
+ for i in 0 ..psDec. LPC_order as usize {
68
+ pNLSF0_Q15[ i] = ( prevNLSF_Q15[ i] as i32
69
+ + ( ( psDec. indices . NLSFInterpCoef_Q2 as i32
70
+ * ( pNLSF_Q15[ i] as i32 - prevNLSF_Q15[ i] as i32 ) )
47
71
>> 2 ) ) as i16 ;
48
- i += 1 ;
49
72
}
50
- silk_NLSF2A (
51
- & mut ( * psDecCtrl) . PredCoef_Q12 [ 0 ] [ ..psDec. LPC_order as usize ] ,
52
- & pNLSF0_Q15[ ..psDec. LPC_order as usize ] ,
53
- ) ;
73
+
74
+ /* Convert NLSF parameters to AR prediction filter coefficients */
75
+ silk_NLSF2A ( PredCoef_Q12_0 , pNLSF0_Q15) ;
54
76
} else {
55
- memcpy (
56
- ( ( * psDecCtrl) . PredCoef_Q12 [ 0 as usize ] ) . as_mut_ptr ( ) as * mut core:: ffi:: c_void ,
57
- ( ( * psDecCtrl) . PredCoef_Q12 [ 1 as usize ] ) . as_mut_ptr ( ) as * const core:: ffi:: c_void ,
58
- ( psDec. LPC_order as u64 ) . wrapping_mul ( :: core:: mem:: size_of :: < i16 > ( ) as u64 ) ,
59
- ) ;
77
+ /* Copy LPC coefficients for first half from second half */
78
+ PredCoef_Q12_0 . copy_from_slice ( PredCoef_Q12_1 ) ;
60
79
}
61
- memcpy (
62
- ( psDec . prevNLSF_Q15 ) . as_mut_ptr ( ) as * mut core :: ffi :: c_void ,
63
- pNLSF_Q15 . as_mut_ptr ( ) as * const core :: ffi :: c_void ,
64
- ( psDec . LPC_order as u64 ) . wrapping_mul ( :: core :: mem :: size_of :: < i16 > ( ) as u64 ) ,
65
- ) ;
80
+
81
+ prevNLSF_Q15[ ..psDec . LPC_order as usize ]
82
+ . copy_from_slice ( & pNLSF_Q15 [ ..psDec . LPC_order as usize ] ) ;
83
+
84
+ /* After a packet loss do BWE of LPC coefs */
66
85
if psDec. lossCnt != 0 {
67
- silk_bwexpander (
68
- & mut ( * psDecCtrl) . PredCoef_Q12 [ 0 ] [ ..psDec. LPC_order as usize ] ,
69
- BWE_AFTER_LOSS_Q16 ,
70
- ) ;
71
- silk_bwexpander (
72
- & mut ( * psDecCtrl) . PredCoef_Q12 [ 1 ] [ ..psDec. LPC_order as usize ] ,
73
- BWE_AFTER_LOSS_Q16 ,
74
- ) ;
86
+ silk_bwexpander ( PredCoef_Q12_0 , BWE_AFTER_LOSS_Q16 ) ;
87
+ silk_bwexpander ( PredCoef_Q12_1 , BWE_AFTER_LOSS_Q16 ) ;
75
88
}
89
+
76
90
if psDec. indices . signalType as i32 == TYPE_VOICED {
91
+ /*********************/
92
+ /* Decode pitch lags */
93
+ /*********************/
94
+
95
+ /* Decode pitch values */
77
96
silk_decode_pitch (
78
97
psDec. indices . lagIndex ,
79
98
psDec. indices . contourIndex ,
80
- & mut ( * psDecCtrl ) . pitchL [ ..psDec . nb_subfr as usize ] ,
99
+ pitchL,
81
100
psDec. fs_kHz ,
82
101
) ;
83
- cbk_ptr_Q7 = & * ( * silk_LTP_vq_ptrs_Q7[ psDec. indices . PERIndex as usize ] . as_ptr ( ) ) . as_ptr ( ) ;
84
- k = 0 ;
85
- while k < psDec. nb_subfr {
86
- Ix = psDec. indices . LTPIndex [ k as usize ] as i32 ;
87
- i = 0 ;
88
- while i < LTP_ORDER {
89
- ( * psDecCtrl) . LTPCoef_Q14 [ ( k * LTP_ORDER + i) as usize ] =
90
- ( ( * cbk_ptr_Q7. offset ( ( Ix * 5 + i) as isize ) as u32 ) << 7 ) as i32 as i16 ;
91
- i += 1 ;
102
+
103
+ /* Decode Codebook Index */
104
+ let cbk_ptr_Q7 = silk_LTP_vq_ptrs_Q7[ psDec. indices . PERIndex as usize ] ;
105
+
106
+ for k in 0 ..psDec. nb_subfr as usize {
107
+ let Ix = psDec. indices . LTPIndex [ k] as usize ;
108
+ for i in 0 ..LTP_ORDER as usize {
109
+ // ugh, I tried making it into a 2D array, but stuff broke
110
+ // no idea why
111
+ // LTPCoef_Q14[k * LTP_ORDER as usize + i] = (cbk_ptr_Q7[Ix][i] as i16) << 7;
112
+ LTPCoef_Q14 [ k * LTP_ORDER as usize + i] = ( cbk_ptr_Q7[ Ix ] [ i] as i16 ) << 7 ;
92
113
}
93
- k += 1 ;
94
114
}
95
- Ix = psDec. indices . LTP_scaleIndex as i32 ;
96
- ( * psDecCtrl) . LTP_scale_Q14 = silk_LTPScales_table_Q14[ Ix as usize ] as i32 ;
115
+
116
+ /**********************/
117
+ /* Decode LTP scaling */
118
+ /**********************/
119
+ let Ix = psDec. indices . LTP_scaleIndex as usize ;
120
+ psDecCtrl. LTP_scale_Q14 = silk_LTPScales_table_Q14[ Ix ] as i32 ;
97
121
} else {
98
- memset (
99
- ( ( * psDecCtrl) . pitchL ) . as_mut_ptr ( ) as * mut core:: ffi:: c_void ,
100
- 0 ,
101
- ( psDec. nb_subfr as u64 ) . wrapping_mul ( :: core:: mem:: size_of :: < i32 > ( ) as u64 ) ,
102
- ) ;
103
- memset (
104
- ( ( * psDecCtrl) . LTPCoef_Q14 ) . as_mut_ptr ( ) as * mut core:: ffi:: c_void ,
105
- 0 ,
106
- ( ( 5 * psDec. nb_subfr ) as u64 ) . wrapping_mul ( :: core:: mem:: size_of :: < i16 > ( ) as u64 ) ,
107
- ) ;
122
+ pitchL. fill ( 0 ) ;
123
+ LTPCoef_Q14 . fill ( 0 ) ;
124
+
108
125
psDec. indices . PERIndex = 0 ;
109
- ( * psDecCtrl) . LTP_scale_Q14 = 0 ;
126
+ psDecCtrl. LTP_scale_Q14 = 0 ;
110
127
} ;
111
128
}
0 commit comments