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

Go to the source code of this file.

Macros

#define STEP(k)   (longword)wt[k] * dp[k - lambda]
 
#define STEP(BP)
 

Functions

static void Calculation_of_the_LTP_parameters P4 ((d, dp, bc_out, Nc_out), register word *d, register word *dp, word *bc_out, word *Nc_out)
 
void Gsm_Long_Term_Synthesis_Filtering P5 ((S, Ncr, bcr, erp, drp), struct gsm_state *S, word Ncr, word bcr, register word *erp, register word *drp)
 
static void Long_term_analysis_filtering P6 ((bc, Nc, dp, d, dpp, e), word bc, word Nc, register word *dp, register word *d, register word *dpp, register word *e)
 
void Gsm_Long_Term_Predictor P7 ((S, d, dp, e, dpp, Nc, bc), struct gsm_state *S, word *d, word *dp, word *e, word *dpp, word *Nc, word *bc)
 

Macro Definition Documentation

◆ STEP [1/2]

#define STEP (   k)    (longword)wt[k] * dp[k - lambda]

Referenced by P4(), and P6().

◆ STEP [2/2]

#define STEP (   BP)
Value:
for (k = 0; k <= 39; k++) { \
dpp[k] = (word)GSM_MULT_R( BP, dp[k - Nc]); \
e[k] = GSM_SUB( d[k], dpp[k] ); \
}
static struct test_val d
static word GSM_SUB(longword a, longword b)
#define GSM_MULT_R(a, b)
#define Nc
short word

Function Documentation

◆ P4()

static void Calculation_of_the_LTP_parameters P4 ( (d, dp, bc_out, Nc_out)  ,
register word d,
register word dp,
word bc_out,
word Nc_out 
)
static

Definition at line 158 of file long_term.c.

References a, b, bc, c, dmax, GSM_ABS, gsm_DLB, gsm_state::ltp_cut, Nc, P5(), S, SASR, and STEP.

164 {
165  register int k;
166 #ifndef K6OPT
167  register int lambda;
168 #endif
169  word Nc, bc;
170  word wt[40];
171 
172  longword L_max, L_power;
173  word R, S, dmax, scal;
174  register word temp;
175 
176  /* Search of the optimum scaling of d[0..39].
177  */
178  dmax = 0;
179 
180  for (k = 0; k <= 39; k++) {
181  temp = d[k];
182  temp = GSM_ABS( temp );
183  if (temp > dmax) dmax = temp;
184  }
185 
186  temp = 0;
187  if (dmax == 0) scal = 0;
188  else {
189  assert(dmax > 0);
190  temp = gsm_norm( (longword)dmax << 16 );
191  }
192 
193  if (temp > 6) scal = 0;
194  else scal = 6 - temp;
195 
196  assert(scal >= 0);
197 
198  /* Initialization of a working array wt
199  */
200 
201  for (k = 0; k <= 39; k++) wt[k] = SASR( d[k], scal );
202 
203  /* Search for the maximum cross-correlation and coding of the LTP lag
204  */
205 # ifdef K6OPT
206  L_max = k6maxcc(wt,dp,&Nc);
207 # else
208  L_max = 0;
209  Nc = 40; /* index for the maximum cross-correlation */
210 
211  for (lambda = 40; lambda <= 120; lambda++) {
212 
213 # undef STEP
214 # define STEP(k) (longword)wt[k] * dp[k - lambda]
215 
216  register longword L_result;
217 
218  L_result = STEP(0) ; L_result += STEP(1) ;
219  L_result += STEP(2) ; L_result += STEP(3) ;
220  L_result += STEP(4) ; L_result += STEP(5) ;
221  L_result += STEP(6) ; L_result += STEP(7) ;
222  L_result += STEP(8) ; L_result += STEP(9) ;
223  L_result += STEP(10) ; L_result += STEP(11) ;
224  L_result += STEP(12) ; L_result += STEP(13) ;
225  L_result += STEP(14) ; L_result += STEP(15) ;
226  L_result += STEP(16) ; L_result += STEP(17) ;
227  L_result += STEP(18) ; L_result += STEP(19) ;
228  L_result += STEP(20) ; L_result += STEP(21) ;
229  L_result += STEP(22) ; L_result += STEP(23) ;
230  L_result += STEP(24) ; L_result += STEP(25) ;
231  L_result += STEP(26) ; L_result += STEP(27) ;
232  L_result += STEP(28) ; L_result += STEP(29) ;
233  L_result += STEP(30) ; L_result += STEP(31) ;
234  L_result += STEP(32) ; L_result += STEP(33) ;
235  L_result += STEP(34) ; L_result += STEP(35) ;
236  L_result += STEP(36) ; L_result += STEP(37) ;
237  L_result += STEP(38) ; L_result += STEP(39) ;
238 
239  if (L_result > L_max) {
240 
241  Nc = lambda;
242  L_max = L_result;
243  }
244  }
245 # endif
246  *Nc_out = Nc;
247 
248  L_max <<= 1;
249 
250  /* Rescaling of L_max
251  */
252  assert(scal <= 100 && scal >= -100);
253  L_max = L_max >> (6 - scal); /* sub(6, scal) */
254 
255  assert( Nc <= 120 && Nc >= 40);
256 
257  /* Compute the power of the reconstructed short term residual
258  * signal dp[..]
259  */
260  L_power = 0;
261  for (k = 0; k <= 39; k++) {
262 
263  register longword L_temp;
264 
265  L_temp = SASR( dp[k - Nc], 3 );
266  L_power += L_temp * L_temp;
267  }
268  L_power <<= 1; /* from L_MULT */
269 
270  /* Normalization of L_max and L_power
271  */
272 
273  if (L_max <= 0) {
274  *bc_out = 0;
275  return;
276  }
277  if (L_max >= L_power) {
278  *bc_out = 3;
279  return;
280  }
281 
282  temp = gsm_norm( L_power );
283 
284  R = (word)SASR( L_max << temp, 16 );
285  S = (word)SASR( L_power << temp, 16 );
286 
287  /* Coding of the LTP gain
288  */
289 
290  /* Table 4.3a must be used to obtain the level DLB[i] for the
291  * quantization of the LTP gain b to get the coded version bc.
292  */
293  for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;
294  *bc_out = bc;
295 }
#define bc
static struct test_val d
#define S(e)
word gsm_DLB[4]
Definition: table.c:39
#define SASR(x, by)
#define dmax(a, b)
Definition: f2c.h:200
#define Nc
#define GSM_ABS(a)
#define STEP(k)
long longword
short word

◆ P5()

void Gsm_Long_Term_Synthesis_Filtering P5 ( (S, Ncr, bcr, erp, drp)  ,
struct gsm_state S,
word  Ncr,
word  bcr,
register word erp,
register word drp 
)

Definition at line 912 of file long_term.c.

References GSM_ADD(), GSM_MULT_R, gsm_QLB, MIN_WORD, and gsm_state::nrp.

Referenced by P4().

925 {
926  register int k;
927  word brp, drpp, Nr;
928 
929  /* Check the limits of Nr.
930  */
931  Nr = Ncr < 40 || Ncr > 120 ? S->nrp : Ncr;
932  S->nrp = Nr;
933  assert(Nr >= 40 && Nr <= 120);
934 
935  /* Decoding of the LTP gain bcr
936  */
937  brp = gsm_QLB[ bcr ];
938 
939  /* Computation of the reconstructed short term residual
940  * signal drp[0..39]
941  */
942  assert(brp != MIN_WORD);
943 
944  for (k = 0; k <= 39; k++) {
945  drpp = (word)GSM_MULT_R( brp, drp[ k - Nr ] );
946  drp[k] = GSM_ADD( erp[k], drpp );
947  }
948 
949  /*
950  * Update of the reconstructed short term residual signal
951  * drp[ -1..-120 ]
952  */
953 
954  for (k = 0; k <= 119; k++) drp[ -120 + k ] = drp[ -80 + k ];
955 }
static word GSM_ADD(longword a, longword b)
word gsm_QLB[4]
Definition: table.c:45
#define GSM_MULT_R(a, b)
#define MIN_WORD
short word

◆ P6()

static void Long_term_analysis_filtering P6 ( (bc, Nc, dp, d, dpp, e)  ,
word  bc,
word  Nc,
register word dp,
register word d,
register word dpp,
register word e 
)
static

Definition at line 842 of file long_term.c.

References STEP.

856 {
857  register int k;
858 
859 # undef STEP
860 # define STEP(BP) \
861  for (k = 0; k <= 39; k++) { \
862  dpp[k] = (word)GSM_MULT_R( BP, dp[k - Nc]); \
863  e[k] = GSM_SUB( d[k], dpp[k] ); \
864  }
865 
866  switch (bc) {
867  case 0: STEP( 3277 ); break;
868  case 1: STEP( 11469 ); break;
869  case 2: STEP( 21299 ); break;
870  case 3: STEP( 32767 ); break;
871  }
872 }
#define bc
#define STEP(k)

◆ P7()

void Gsm_Long_Term_Predictor P7 ( (S, d, dp, e, dpp, Nc, bc ,
struct gsm_state S,
word d,
word dp,
word e,
word dpp,
word Nc,
word bc 
)

Definition at line 874 of file long_term.c.

References gsm_state::fast, and gsm_state::ltp_cut.

886 {
887  assert( d ); assert( dp ); assert( e );
888  assert( dpp); assert( Nc ); assert( bc );
889 
890 #if defined(FAST) && defined(USE_FLOAT_MUL)
891  if (S->fast)
892 #if defined (LTP_CUT)
893  if (S->ltp_cut)
894  Cut_Fast_Calculation_of_the_LTP_parameters(S,
895  d, dp, bc, Nc);
896  else
897 #endif /* LTP_CUT */
898  Fast_Calculation_of_the_LTP_parameters(d, dp, bc, Nc );
899  else
900 #endif /* FAST & USE_FLOAT_MUL */
901 #ifdef LTP_CUT
902  if (S->ltp_cut)
903  Cut_Calculation_of_the_LTP_parameters(S, d, dp, bc, Nc);
904  else
905 #endif
906  Calculation_of_the_LTP_parameters(d, dp, bc, Nc);
907 
908  Long_term_analysis_filtering( *bc, *Nc, dp, d, dpp, e );
909 }
#define bc
static struct test_val d
#define Nc