78cb853c1d79e0530103362c058779c8b4a727be
[Faustine.git] / interpretor / libsndfile-1.0.25 / src / GSM610 / code.c
1 /*
2 * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
3 * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
4 * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
5 */
6
7
8 #include <stdlib.h>
9 #include <string.h>
10
11 #include "gsm610_priv.h"
12
13 /*
14 * 4.2 FIXED POINT IMPLEMENTATION OF THE RPE-LTP CODER
15 */
16
17 void Gsm_Coder (
18
19 struct gsm_state * State,
20
21 word * s, /* [0..159] samples IN */
22
23 /*
24 * The RPE-LTD coder works on a frame by frame basis. The length of
25 * the frame is equal to 160 samples. Some computations are done
26 * once per frame to produce at the output of the coder the
27 * LARc[1..8] parameters which are the coded LAR coefficients and
28 * also to realize the inverse filtering operation for the entire
29 * frame (160 samples of signal d[0..159]). These parts produce at
30 * the output of the coder:
31 */
32
33 word * LARc, /* [0..7] LAR coefficients OUT */
34
35 /*
36 * Procedure 4.2.11 to 4.2.18 are to be executed four times per
37 * frame. That means once for each sub-segment RPE-LTP analysis of
38 * 40 samples. These parts produce at the output of the coder:
39 */
40
41 word * Nc, /* [0..3] LTP lag OUT */
42 word * bc, /* [0..3] coded LTP gain OUT */
43 word * Mc, /* [0..3] RPE grid selection OUT */
44 word * xmaxc,/* [0..3] Coded maximum amplitude OUT */
45 word * xMc /* [13*4] normalized RPE samples OUT */
46 )
47 {
48 int k;
49 word * dp = State->dp0 + 120; /* [ -120...-1 ] */
50 word * dpp = dp; /* [ 0...39 ] */
51
52 word so[160];
53
54 Gsm_Preprocess (State, s, so);
55 Gsm_LPC_Analysis (State, so, LARc);
56 Gsm_Short_Term_Analysis_Filter (State, LARc, so);
57
58 for (k = 0; k <= 3; k++, xMc += 13) {
59
60 Gsm_Long_Term_Predictor ( State,
61 so+k*40, /* d [0..39] IN */
62 dp, /* dp [-120..-1] IN */
63 State->e + 5, /* e [0..39] OUT */
64 dpp, /* dpp [0..39] OUT */
65 Nc++,
66 bc++);
67
68 Gsm_RPE_Encoding ( /*-S,-*/
69 State->e + 5, /* e ][0..39][ IN/OUT */
70 xmaxc++, Mc++, xMc );
71 /*
72 * Gsm_Update_of_reconstructed_short_time_residual_signal
73 * ( dpp, State->e + 5, dp );
74 */
75
76 { register int i;
77 for (i = 0; i <= 39; i++)
78 dp[ i ] = GSM_ADD( State->e[5 + i], dpp[i] );
79 }
80 dp += 40;
81 dpp += 40;
82
83 }
84 (void)memcpy( (char *)State->dp0, (char *)(State->dp0 + 160),
85 120 * sizeof(*State->dp0) );
86 }
87