preprocess.c 2.5 KB

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