Asterisk - The Open Source Telephony Project  18.5.0
Macros | Functions
short_term.c File Reference
#include <stdio.h>
#include <assert.h>
#include "private.h"
#include "gsm.h"
#include "proto.h"
Include dependency graph for short_term.c:

Go to the source code of this file.

Macros

#define FILTER   Short_term_analysis_filtering
 
#define FILTER   Short_term_synthesis_filtering
 
#define STEP(B_TIMES_TWO, MIC, INVA)
 

Functions

static void LARp_to_rp P1 ((LARp), register word *LARp)
 
static void Decoding_of_the_coded_Log_Area_Ratios P2 ((LARc, LARpp), word *LARc, word *LARpp)
 
static void Coefficients_40_159 P2 ((LARpp_j, LARp), register word *LARpp_j, register word *LARp)
 
static void Coefficients_0_12 P3 ((LARpp_j_1, LARpp_j, LARp), register word *LARpp_j_1, register word *LARpp_j, register word *LARp)
 
void Gsm_Short_Term_Analysis_Filter P3 ((S, LARc, s), struct gsm_state *S, word *LARc, word *s)
 
static void Short_term_analysis_filtering P4 ((u0, rp0, k_n, s), register word *u0, register word *rp0, register int k_n, register word *s)
 
void Gsm_Short_Term_Synthesis_Filter P4 ((S, LARcr, wt, s), struct gsm_state *S, word *LARcr, word *wt, word *s)
 
static void Short_term_synthesis_filtering P5 ((S, rrp, k, wt, sr), struct gsm_state *S, register word *rrp, register int k, register word *wt, register word *sr)
 

Macro Definition Documentation

◆ FILTER [1/2]

#define FILTER   Short_term_analysis_filtering

Referenced by P3(), and P4().

◆ FILTER [2/2]

#define FILTER   Short_term_synthesis_filtering

◆ STEP

#define STEP (   B_TIMES_TWO,
  MIC,
  INVA 
)
Value:
temp1 = GSM_ADD( *LARc++, MIC ) << 10; \
temp1 = GSM_SUB( temp1, B_TIMES_TWO ); \
temp1 = (word)GSM_MULT_R( INVA, temp1 ); \
*LARpp++ = GSM_ADD( temp1, temp1 );
static word GSM_ADD(longword a, longword b)
static word GSM_SUB(longword a, longword b)
#define GSM_MULT_R(a, b)
#define LARc
short word

Referenced by P2().

Function Documentation

◆ P1()

static void LARp_to_rp P1 ( (LARp)  ,
register word LARp 
)
static

Definition at line 145 of file short_term.c.

References GSM_ADD(), MAX_WORD, and MIN_WORD.

152 {
153  register int i;
154  register word temp;
155 
156  for (i = 1; i <= 8; i++, LARp++) {
157 
158  /* temp = GSM_ABS( *LARp );
159  *
160  * if (temp < 11059) temp <<= 1;
161  * else if (temp < 20070) temp += 11059;
162  * else temp = GSM_ADD( temp >> 2, 26112 );
163  *
164  * *LARp = *LARp < 0 ? -temp : temp;
165  */
166 
167  if (*LARp < 0) {
168  temp = *LARp == MIN_WORD ? MAX_WORD : -(*LARp);
169  *LARp = - ((temp < 11059) ? temp << 1
170  : ((temp < 20070) ? temp + 11059
171  : GSM_ADD( temp >> 2, 26112 )));
172  } else {
173  temp = *LARp;
174  *LARp = (temp < 11059) ? temp << 1
175  : ((temp < 20070) ? temp + 11059
176  : GSM_ADD( temp >> 2, 26112 ));
177  }
178  }
179 }
static word GSM_ADD(longword a, longword b)
#define MAX_WORD
#define MIN_WORD
short word

◆ P2() [1/2]

static void Decoding_of_the_coded_Log_Area_Ratios P2 ( (LARc, LARpp)  ,
word LARc,
word LARpp 
)
static

Definition at line 28 of file short_term.c.

References STEP.

31 {
32  register word temp1 /* , temp2 */;
33 
34  /* This procedure requires for efficient implementation
35  * two tables.
36  *
37  * INVA[1..8] = integer( (32768 * 8) / real_A[1..8])
38  * MIC[1..8] = minimum value of the LARc[1..8]
39  */
40 
41  /* Compute the LARpp[1..8]
42  */
43 
44  /* for (i = 1; i <= 8; i++, B++, MIC++, INVA++, LARc++, LARpp++) {
45  *
46  * temp1 = GSM_ADD( *LARc, *MIC ) << 10;
47  * temp2 = *B << 1;
48  * temp1 = GSM_SUB( temp1, temp2 );
49  *
50  * assert(*INVA != MIN_WORD);
51  *
52  * temp1 = GSM_MULT_R( *INVA, temp1 );
53  * *LARpp = GSM_ADD( temp1, temp1 );
54  * }
55  */
56 
57 #undef STEP
58 #define STEP( B_TIMES_TWO, MIC, INVA ) \
59  temp1 = GSM_ADD( *LARc++, MIC ) << 10; \
60  temp1 = GSM_SUB( temp1, B_TIMES_TWO ); \
61  temp1 = (word)GSM_MULT_R( INVA, temp1 ); \
62  *LARpp++ = GSM_ADD( temp1, temp1 );
63 
64  STEP( 0, -32, 13107 );
65  STEP( 0, -32, 13107 );
66  STEP( 4096, -16, 13107 );
67  STEP( -5120, -16, 13107 );
68 
69  STEP( 188, -8, 19223 );
70  STEP( -3584, -8, 17476 );
71  STEP( -682, -4, 31454 );
72  STEP( -2288, -4, 29708 );
73 
74  /* NOTE: the addition of *MIC is used to restore
75  * the sign of *LARc.
76  */
77 }
#define STEP(B_TIMES_TWO, MIC, INVA)
short word

◆ P2() [2/2]

static void Coefficients_40_159 P2 ( (LARpp_j, LARp)  ,
register word LARpp_j,
register word LARp 
)
static

Definition at line 133 of file short_term.c.

136 {
137  register int i;
138 
139  for (i = 1; i <= 8; i++, LARp++, LARpp_j++)
140  *LARp = *LARpp_j;
141 }

◆ P3() [1/2]

static void Coefficients_27_39 P3 ( (LARpp_j_1, LARpp_j, LARp)  ,
register word LARpp_j_1,
register word LARpp_j,
register word LARp 
)
static

Definition at line 95 of file short_term.c.

References GSM_ADD(), and SASR.

99 {
100  register int i;
101 
102  for (i = 1; i <= 8; i++, LARp++, LARpp_j_1++, LARpp_j++) {
103  *LARp = GSM_ADD( SASR( *LARpp_j_1, 2 ), SASR( *LARpp_j, 2 ));
104  *LARp = GSM_ADD( *LARp, SASR( *LARpp_j_1, 1));
105  }
106 }
static word GSM_ADD(longword a, longword b)
#define SASR(x, by)

◆ P3() [2/2]

void Gsm_Short_Term_Analysis_Filter P3 ( (S, LARc, s)  ,
struct gsm_state S,
word LARc,
word s 
)

Definition at line 364 of file short_term.c.

References FILTER, gsm_state::j, gsm_state::LARpp, and gsm_state::u.

371 {
372  word * LARpp_j = S->LARpp[ S->j ];
373  word * LARpp_j_1 = S->LARpp[ S->j ^= 1 ];
374 
375  word LARp[8];
376 
377 #undef FILTER
378 #if defined(FAST) && defined(USE_FLOAT_MUL)
379 # define FILTER (* (S->fast \
380  ? Fast_Short_term_analysis_filtering \
381  : Short_term_analysis_filtering ))
382 
383 #else
384 # define FILTER Short_term_analysis_filtering
385 #endif
386 
387  Decoding_of_the_coded_Log_Area_Ratios( LARc, LARpp_j );
388 
389  Coefficients_0_12( LARpp_j_1, LARpp_j, LARp );
390  LARp_to_rp( LARp );
391  FILTER( S->u, LARp, 13, s);
392 
393  Coefficients_13_26( LARpp_j_1, LARpp_j, LARp);
394  LARp_to_rp( LARp );
395  FILTER( S->u, LARp, 14, s + 13);
396 
397  Coefficients_27_39( LARpp_j_1, LARpp_j, LARp);
398  LARp_to_rp( LARp );
399  FILTER( S->u, LARp, 13, s + 27);
400 
401  Coefficients_40_159( LARpp_j, LARp);
402  LARp_to_rp( LARp );
403  FILTER( S->u, LARp, 120, s + 40);
404 
405 }
#define FILTER
#define LARc
short word

◆ P4() [1/2]

static void Short_term_analysis_filtering P4 ( (u0, rp0, k_n, s)  ,
register word u0,
register word rp0,
register int  k_n,
register word s 
)
static

Definition at line 190 of file short_term.c.

References di, MAX_WORD, and MIN_WORD.

206 {
207  register word * u_top = u0 + 8;
208  register word * s_top = s + k_n;
209 
210  while (s < s_top) {
211  register word *u, *rp ;
212  register longword di, u_out;
213  di = u_out = *s;
214  for (rp=rp0, u=u0; u<u_top;) {
215  register longword ui, rpi;
216  ui = *u;
217  *u++ = (word)u_out;
218  rpi = *rp++;
219  u_out = ui + (((rpi*di)+0x4000)>>15);
220  di = di + (((rpi*ui)+0x4000)>>15);
221  /* make the common case fastest: */
222  if ((u_out == (word)u_out) && (di == (word)di)) continue;
223  /* otherwise do slower fixup (saturation) */
224  if (u_out>MAX_WORD) u_out=MAX_WORD;
225  else if (u_out<MIN_WORD) u_out=MIN_WORD;
226  if (di>MAX_WORD) di=MAX_WORD;
227  else if (di<MIN_WORD) di=MIN_WORD;
228  }
229  *s++ = (word)di;
230  }
231 }
#define MAX_WORD
static float di[4]
Definition: tdd.c:58
#define MIN_WORD
long longword
short word

◆ P4() [2/2]

void Gsm_Short_Term_Synthesis_Filter P4 ( (S, LARcr, wt, s)  ,
struct gsm_state S,
word LARcr,
word wt,
word s 
)

Definition at line 407 of file short_term.c.

References FILTER, gsm_state::j, and gsm_state::LARpp.

415 {
416  word * LARpp_j = S->LARpp[ S->j ];
417  word * LARpp_j_1 = S->LARpp[ S->j ^=1 ];
418 
419  word LARp[8];
420 
421 #undef FILTER
422 #if defined(FAST) && defined(USE_FLOAT_MUL)
423 
424 # define FILTER (* (S->fast \
425  ? Fast_Short_term_synthesis_filtering \
426  : Short_term_synthesis_filtering ))
427 #else
428 # define FILTER Short_term_synthesis_filtering
429 #endif
430 
431  Decoding_of_the_coded_Log_Area_Ratios( LARcr, LARpp_j );
432 
433  Coefficients_0_12( LARpp_j_1, LARpp_j, LARp );
434  LARp_to_rp( LARp );
435  FILTER( S, LARp, 13, wt, s );
436 
437  Coefficients_13_26( LARpp_j_1, LARpp_j, LARp);
438  LARp_to_rp( LARp );
439  FILTER( S, LARp, 14, wt + 13, s + 13 );
440 
441  Coefficients_27_39( LARpp_j_1, LARpp_j, LARp);
442  LARp_to_rp( LARp );
443  FILTER( S, LARp, 13, wt + 27, s + 27 );
444 
445  Coefficients_40_159( LARpp_j, LARp );
446  LARp_to_rp( LARp );
447  FILTER(S, LARp, 120, wt + 40, s + 40);
448 }
#define FILTER
short word

◆ P5()

static void Short_term_synthesis_filtering P5 ( (S, rrp, k, wt, sr)  ,
struct gsm_state S,
register word rrp,
register int  k,
register word wt,
register word sr 
)
static

Definition at line 281 of file short_term.c.

References MAX_WORD, MIN_WORD, S, and gsm_state::v.

288 {
289  register word * v = S->v;
290  register int i;
291  register longword sri;
292 
293  while (k--) {
294  sri = *wt++;
295  for (i = 8; i--;) {
296  register longword tmp1, tmp2;
297 
298  /* sri = GSM_SUB( sri, gsm_mult_r( rrp[i], v[i] ) );
299  */
300  tmp1 = rrp[i];
301  tmp2 = v[i];
302 
303  tmp2 = (( tmp1 * tmp2 + 16384) >> 15) ;
304  /* saturation done below */
305  sri -= tmp2;
306  if (sri != (word)sri) {
307  sri = (sri<0)? MIN_WORD:MAX_WORD;
308  }
309  /* v[i+1] = GSM_ADD( v[i], gsm_mult_r( rrp[i], sri ) );
310  */
311 
312  tmp1 = (( tmp1 * sri + 16384) >> 15) ;
313  /* saturation done below */
314  tmp1 += v[i];
315  if (tmp1 != (word)tmp1) {
316  tmp1 = (tmp1<0)? MIN_WORD:MAX_WORD;
317  }
318  v[i+1] = (word)tmp1;
319  }
320  *sr++ = v[0] = (word)sri;
321  }
322 }
#define MAX_WORD
#define MIN_WORD
long longword
short word