build: fix symlink selection
[sox.git] / libgsm / preprocess.c
blob4fbff865c63fdd5786c6f42f9294dbf7336f6265
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 */
7 /* $Header: /cvsroot/sox/sox/libgsm/preprocess.c,v 1.1 2007/09/06 16:50:55 cbagwell Exp $ */
9 #include <stdio.h>
10 #include <assert.h>
12 #include "private.h"
14 #include "gsm.h"
16 /* 4.2.0 .. 4.2.3 PREPROCESSING SECTION
18 * After A-law to linear conversion (or directly from the
19 * Ato D converter) the following scaling is assumed for
20 * input to the RPE-LTP algorithm:
22 * in: 0.1.....................12
23 * S.v.v.v.v.v.v.v.v.v.v.v.v.*.*.*
25 * Where S is the sign bit, v a valid bit, and * a "don't care" bit.
26 * The original signal is called sop[..]
28 * out: 0.1................... 12
29 * S.S.v.v.v.v.v.v.v.v.v.v.v.v.0.0
33 void Gsm_Preprocess (
34 struct gsm_state * S,
35 word * s,
36 word * so ) /* [0..159] IN/OUT */
39 word z1 = S->z1;
40 longword L_z2 = S->L_z2;
41 word mp = S->mp;
43 word s1;
44 longword L_s2;
46 longword L_temp;
48 word msp, lsp;
49 word SO;
51 longword ltmp; /* for ADD */
52 ulongword utmp; /* for L_ADD */
54 register int k = 160;
56 while (k--) {
58 /* 4.2.1 Downscaling of the input signal
60 SO = SASR( *s, 3 ) << 2;
61 s++;
63 assert (SO >= -0x4000); /* downscaled by */
64 assert (SO <= 0x3FFC); /* previous routine. */
67 /* 4.2.2 Offset compensation
69 * This part implements a high-pass filter and requires extended
70 * arithmetic precision for the recursive part of this filter.
71 * The input of this procedure is the array so[0...159] and the
72 * output the array sof[ 0...159 ].
74 /* Compute the non-recursive part
77 s1 = SO - z1; /* s1 = gsm_sub( *so, z1 ); */
78 z1 = SO;
80 assert(s1 != MIN_WORD);
82 /* Compute the recursive part
84 L_s2 = s1;
85 L_s2 <<= 15;
87 /* Execution of a 31 bv 16 bits multiplication
90 msp = SASR( L_z2, 15 );
91 lsp = L_z2-((longword)msp<<15); /* gsm_L_sub(L_z2,(msp<<15)); */
93 L_s2 += GSM_MULT_R( lsp, 32735 );
94 L_temp = (longword)msp * 32735; /* GSM_L_MULT(msp,32735) >> 1;*/
95 L_z2 = GSM_L_ADD( L_temp, L_s2 );
97 /* Compute sof[k] with rounding
99 L_temp = GSM_L_ADD( L_z2, 16384 );
101 /* 4.2.3 Preemphasis
104 msp = GSM_MULT_R( mp, -28180 );
105 mp = SASR( L_temp, 15 );
106 *so++ = GSM_ADD( mp, msp );
109 S->z1 = z1;
110 S->L_z2 = L_z2;
111 S->mp = mp;