Alexandre Lision | 7c6f4a6 | 2013-09-05 13:27:01 -0400 | [diff] [blame] | 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 | #include <stdio.h> |
| 8 | #include <assert.h> |
| 9 | |
| 10 | #include "gsm610_priv.h" |
| 11 | |
| 12 | /* 4.2.0 .. 4.2.3 PREPROCESSING SECTION |
| 13 | * |
| 14 | * After A-law to linear conversion (or directly from the |
| 15 | * Ato D converter) the following scaling is assumed for |
| 16 | * input to the RPE-LTP algorithm: |
| 17 | * |
| 18 | * in: 0.1.....................12 |
| 19 | * S.v.v.v.v.v.v.v.v.v.v.v.v.*.*.* |
| 20 | * |
| 21 | * Where S is the sign bit, v a valid bit, and * a "don't care" bit. |
| 22 | * The original signal is called sop[..] |
| 23 | * |
| 24 | * out: 0.1................... 12 |
| 25 | * S.S.v.v.v.v.v.v.v.v.v.v.v.v.0.0 |
| 26 | */ |
| 27 | |
| 28 | |
| 29 | void Gsm_Preprocess ( |
| 30 | struct gsm_state * S, |
| 31 | word * s, |
| 32 | word * so ) /* [0..159] IN/OUT */ |
| 33 | { |
| 34 | |
| 35 | word z1 = S->z1; |
| 36 | longword L_z2 = S->L_z2; |
| 37 | word mp = S->mp; |
| 38 | |
| 39 | word s1; |
| 40 | longword L_s2; |
| 41 | |
| 42 | longword L_temp; |
| 43 | |
| 44 | word msp, lsp; |
| 45 | word SO; |
| 46 | |
| 47 | register int k = 160; |
| 48 | |
| 49 | while (k--) { |
| 50 | |
| 51 | /* 4.2.1 Downscaling of the input signal |
| 52 | */ |
| 53 | SO = SASR_W( *s, 3 ) << 2; |
| 54 | s++; |
| 55 | |
| 56 | assert (SO >= -0x4000); /* downscaled by */ |
| 57 | assert (SO <= 0x3FFC); /* previous routine. */ |
| 58 | |
| 59 | |
| 60 | /* 4.2.2 Offset compensation |
| 61 | * |
| 62 | * This part implements a high-pass filter and requires extended |
| 63 | * arithmetic precision for the recursive part of this filter. |
| 64 | * The input of this procedure is the array so[0...159] and the |
| 65 | * output the array sof[ 0...159 ]. |
| 66 | */ |
| 67 | /* Compute the non-recursive part |
| 68 | */ |
| 69 | |
| 70 | s1 = SO - z1; /* s1 = gsm_sub( *so, z1 ); */ |
| 71 | z1 = SO; |
| 72 | |
| 73 | assert(s1 != MIN_WORD); |
| 74 | |
| 75 | /* Compute the recursive part |
| 76 | */ |
| 77 | L_s2 = s1; |
| 78 | L_s2 <<= 15; |
| 79 | |
| 80 | /* Execution of a 31 bv 16 bits multiplication |
| 81 | */ |
| 82 | |
| 83 | msp = SASR_L( L_z2, 15 ); |
| 84 | lsp = L_z2-((longword)msp<<15); /* gsm_L_sub(L_z2,(msp<<15)); */ |
| 85 | |
| 86 | L_s2 += GSM_MULT_R( lsp, 32735 ); |
| 87 | L_temp = (longword)msp * 32735; /* GSM_L_MULT(msp,32735) >> 1;*/ |
| 88 | L_z2 = GSM_L_ADD( L_temp, L_s2 ); |
| 89 | |
| 90 | /* Compute sof[k] with rounding |
| 91 | */ |
| 92 | L_temp = GSM_L_ADD( L_z2, 16384 ); |
| 93 | |
| 94 | /* 4.2.3 Preemphasis |
| 95 | */ |
| 96 | |
| 97 | msp = GSM_MULT_R( mp, -28180 ); |
| 98 | mp = SASR_L( L_temp, 15 ); |
| 99 | *so++ = GSM_ADD( mp, msp ); |
| 100 | } |
| 101 | |
| 102 | S->z1 = z1; |
| 103 | S->L_z2 = L_z2; |
| 104 | S->mp = mp; |
| 105 | } |