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