Skip to main content

g729_sys/g729/
pre_processing.rs

1use crate::g729::basic_operations::*;
2use crate::g729::ld8k::*;
3
4/* coefficients a stored in Q1.12 for A1 (the only one having a float value > 1) and Q0.12 for all the others */
5const A1: Word16 = 7807;
6const A2: Word16 = -3733;
7const B0: Word16 = 1899;
8const B1: Word16 = -3798;
9const B2: Word16 = 1899;
10
11pub struct PreProcessingState {
12    output_y2: Word32,
13    output_y1: Word32,
14    input_x0: Word16,
15    input_x1: Word16,
16}
17
18impl PreProcessingState {
19    pub fn new() -> Self {
20        Self {
21            output_y2: 0,
22            output_y1: 0,
23            input_x0: 0,
24            input_x1: 0,
25        }
26    }
27
28    pub fn pre_processing(&mut self, signal: &[Word16], pre_processed_signal: &mut [Word16]) {
29        let mut input_x2: Word16;
30        let mut acc: Word32;
31
32        for i in 0..L_FRAME {
33            input_x2 = self.input_x1;
34            self.input_x1 = self.input_x0;
35            self.input_x0 = signal[i];
36
37            /* compute with acc and coefficients in Q12 */
38            acc = mult16_32_q12(A1, self.output_y1);
39            acc = mac16_32_q12(acc, A2, self.output_y2);
40            acc = mac16_16(acc, self.input_x0, B0);
41            acc = mac16_16(acc, self.input_x1, B1);
42            acc = mac16_16(acc, input_x2, B2);
43
44            acc = saturate(acc, MAXINT28);
45
46            pre_processed_signal[i] = pshr(acc, 12) as Word16;
47            self.output_y2 = self.output_y1;
48            self.output_y1 = acc;
49        }
50    }
51}