PandA-2024.02
adpcm.c
Go to the documentation of this file.
1 /*
2 +--------------------------------------------------------------------------+
3 | CHStone : a suite of benchmark programs for C-based High-Level Synthesis |
4 | ======================================================================== |
5 | |
6 | * Collected and Modified : Y. Hara, H. Tomiyama, S. Honda, |
7 | H. Takada and K. Ishii |
8 | Nagoya University, Japan |
9 | |
10 | * Remark : |
11 | 1. This source code is modified to unify the formats of the benchmark |
12 | programs in CHStone. |
13 | 2. Test vectors are added for CHStone. |
14 | 3. If "main_result" is 0 at the end of the program, the program is |
15 | correctly executed. |
16 | 4. Please follow the copyright of each benchmark program. |
17 +--------------------------------------------------------------------------+
18 */
19 /*************************************************************************/
20 /* */
21 /* SNU-RT Benchmark Suite for Worst Case Timing Analysis */
22 /* ===================================================== */
23 /* Collected and Modified by S.-S. Lim */
24 /* sslim@archi.snu.ac.kr */
25 /* Real-Time Research Group */
26 /* Seoul National University */
27 /* */
28 /* */
29 /* < Features > - restrictions for our experimental environment */
30 /* */
31 /* 1. Completely structured. */
32 /* - There are no unconditional jumps. */
33 /* - There are no exit from loop bodies. */
34 /* (There are no 'break' or 'return' in loop bodies) */
35 /* 2. No 'switch' statements. */
36 /* 3. No 'do..while' statements. */
37 /* 4. Expressions are restricted. */
38 /* - There are no multiple expressions joined by 'or', */
39 /* 'and' operations. */
40 /* 5. No library calls. */
41 /* - All the functions needed are implemented in the */
42 /* source file. */
43 /* */
44 /* */
45 /*************************************************************************/
46 /* */
47 /* FILE: adpcm.c */
48 /* SOURCE : C Algorithms for Real-Time DSP by P. M. Embree */
49 /* */
50 /* DESCRIPTION : */
51 /* */
52 /* CCITT G.722 ADPCM (Adaptive Differential Pulse Code Modulation) */
53 /* algorithm. */
54 /* 16khz sample rate data is stored in the array test_data[SIZE]. */
55 /* Results are stored in the array compressed[SIZE] and result[SIZE].*/
56 /* Execution time is determined by the constant SIZE (default value */
57 /* is 2000). */
58 /* */
59 /* REMARK : */
60 /* */
61 /* EXECUTION TIME : */
62 /* */
63 /* */
64 /*************************************************************************/
65 #include <stdio.h>
66 
67 int encode (int, int);
68 void decode (int);
69 int filtez (int *bpl, int *dlt);
70 void upzero (int dlt, int *dlti, int *bli);
71 int filtep (int rlt1, int al1, int rlt2, int al2);
72 int quantl (int el, int detl);
73 int logscl (int il, int nbl);
74 int scalel (int nbl, int shift_constant);
75 int uppol2 (int al1, int al2, int plt, int plt1, int plt2);
76 int uppol1 (int al1, int apl2, int plt, int plt1);
77 int logsch (int ih, int nbh);
78 void reset ();
79 
80 /* G722 C code */
81 
82 /* variables for transimit quadrature mirror filter here */
83 int tqmf[24];
84 
85 /* QMF filter coefficients:
86 scaled by a factor of 4 compared to G722 CCITT recomendation */
87 const int h[24] = {
88  12, -44, -44, 212, 48, -624, 128, 1448,
89  -840, -3220, 3804, 15504, 15504, 3804, -3220, -840,
90  1448, 128, -624, 48, 212, -44, -44, 12
91 };
92 
93 int xl, xh;
94 
95 /* variables for receive quadrature mirror filter here */
96 int accumc[11], accumd[11];
97 
98 /* outputs of decode() */
99 int xout1, xout2;
100 
101 int xs, xd;
102 
103 /* variables for encoder (hi and lo) here */
104 
105 int il, szl, spl, sl, el;
106 
107 const int qq4_code4_table[16] = {
108  0, -20456, -12896, -8968, -6288, -4240, -2584, -1200,
109  20456, 12896, 8968, 6288, 4240, 2584, 1200, 0
110 };
111 
112 
113 const int qq6_code6_table[64] = {
114  -136, -136, -136, -136, -24808, -21904, -19008, -16704,
115  -14984, -13512, -12280, -11192, -10232, -9360, -8576, -7856,
116  -7192, -6576, -6000, -5456, -4944, -4464, -4008, -3576,
117  -3168, -2776, -2400, -2032, -1688, -1360, -1040, -728,
118  24808, 21904, 19008, 16704, 14984, 13512, 12280, 11192,
119  10232, 9360, 8576, 7856, 7192, 6576, 6000, 5456,
120  4944, 4464, 4008, 3576, 3168, 2776, 2400, 2032,
121  1688, 1360, 1040, 728, 432, 136, -432, -136
122 };
123 
124 int delay_bpl[6];
125 
126 int delay_dltx[6];
127 
128 const int wl_code_table[16] = {
129  -60, 3042, 1198, 538, 334, 172, 58, -30,
130  3042, 1198, 538, 334, 172, 58, -30, -60
131 };
132 
133 const int ilb_table[32] = {
134  2048, 2093, 2139, 2186, 2233, 2282, 2332, 2383,
135  2435, 2489, 2543, 2599, 2656, 2714, 2774, 2834,
136  2896, 2960, 3025, 3091, 3158, 3228, 3298, 3371,
137  3444, 3520, 3597, 3676, 3756, 3838, 3922, 4008
138 };
139 
140 int nbl; /* delay line */
141 int al1, al2;
142 int plt, plt1, plt2;
143 int dlt;
144 int rlt, rlt1, rlt2;
145 
146 /* decision levels - pre-multiplied by 8, 0 to indicate end */
147 const int decis_levl[30] = {
148  280, 576, 880, 1200, 1520, 1864, 2208, 2584,
149  2960, 3376, 3784, 4240, 4696, 5200, 5712, 6288,
150  6864, 7520, 8184, 8968, 9752, 10712, 11664, 12896,
151  14120, 15840, 17560, 20456, 23352, 32767
152 };
153 
154 #ifdef INITIALIZATIONS
155 int detl=32;
156 #else
157 int detl;
158 #endif
159 
160 /* quantization table 31 long to make quantl look-up easier,
161 last entry is for mil=30 case when wd is max */
162 const int quant26bt_pos[31] = {
163  61, 60, 59, 58, 57, 56, 55, 54,
164  53, 52, 51, 50, 49, 48, 47, 46,
165  45, 44, 43, 42, 41, 40, 39, 38,
166  37, 36, 35, 34, 33, 32, 32
167 };
168 
169 /* quantization table 31 long to make quantl look-up easier,
170 last entry is for mil=30 case when wd is max */
171 const int quant26bt_neg[31] = {
172  63, 62, 31, 30, 29, 28, 27, 26,
173  25, 24, 23, 22, 21, 20, 19, 18,
174  17, 16, 15, 14, 13, 12, 11, 10,
175  9, 8, 7, 6, 5, 4, 4
176 };
177 
178 
179 #ifdef INITIALIZATIONS
180 int deth=8;
181 #else
182 int deth;
183 #endif
184 int sh; /* this comes from adaptive predictor */
185 int eh;
186 
187 const int qq2_code2_table[4] = {
188  -7408, -1616, 7408, 1616
189 };
190 
191 const int wh_code_table[4] = {
192  798, -214, 798, -214
193 };
194 
195 
196 int dh, ih;
197 int nbh, szh;
198 int sph, ph, yh, rh;
199 
200 int delay_dhx[6];
201 
202 int delay_bph[6];
203 
204 int ah1, ah2;
205 int ph1, ph2;
206 int rh1, rh2;
207 
208 /* variables for decoder here */
209 int ilr, rl;
210 #ifdef INITIALIZATIONS
211 int dec_dlt;
212 int dec_deth = 8;
213 int dec_detl = 32;
214 #else
216 #endif
217 
218 int dec_del_bpl[6];
219 
221 
226 int dl;
228 
229 /* variables used in filtez */
230 int dec_del_bph[6];
231 
232 int dec_del_dhx[6];
233 
235 /* variables used in filtep */
239 
240 int dec_sh;
241 
243 
244 /* G722 encode function two ints in, one 8 bit output */
245 
246 /* put input samples in xin1 = first value, xin2 = second value */
247 /* returns il and ih stored together */
248 
249 int
250 abs (int n)
251 {
252  int m;
253 
254  if (n >= 0)
255  m = n;
256  else
257  m = -n;
258  return m;
259 }
260 
261 int
262 __attribute__ ((noinline))
263 encode (int xin1, int xin2)
264 {
265  int i;
266  const int *h_ptr;
267  int *tqmf_ptr, *tqmf_ptr1;
268  long int xa, xb;
269  int decis;
270 
271 /* transmit quadrature mirror filters implemented here */
272  h_ptr = h;
273  tqmf_ptr = tqmf;
274  xa = (long) (*tqmf_ptr++) * (*h_ptr++);
275  xb = (long) (*tqmf_ptr++) * (*h_ptr++);
276 /* main multiply accumulate loop for samples and coefficients */
277  for (i = 0; i < 10; i++)
278  {
279  xa += (long) (*tqmf_ptr++) * (*h_ptr++);
280  xb += (long) (*tqmf_ptr++) * (*h_ptr++);
281  }
282 /* final mult/accumulate */
283  xa += (long) (*tqmf_ptr++) * (*h_ptr++);
284  xb += (long) (*tqmf_ptr) * (*h_ptr++);
285 
286 /* update delay line tqmf */
287  tqmf_ptr1 = tqmf_ptr - 2;
288  for (i = 0; i < 22; i++)
289  *tqmf_ptr-- = *tqmf_ptr1--;
290  *tqmf_ptr-- = xin1;
291  *tqmf_ptr = xin2;
292 
293 /* scale outputs */
294  xl = (xa + xb) >> 15;
295  xh = (xa - xb) >> 15;
296 
297 /* end of quadrature mirror filter code */
298 
299 /* starting with lower sub band encoder */
300 
301 /* filtez - compute predictor output section - zero section */
303 
304 /* filtep - compute predictor output signal (pole section) */
305  spl = filtep (rlt1, al1, rlt2, al2);
306 
307 /* compute the predictor output value in the lower sub_band encoder */
308  sl = szl + spl;
309  el = xl - sl;
310 
311 /* quantl: quantize the difference signal */
312  il = quantl (el, detl);
313 
314 /* computes quantized difference signal */
315 /* for invqbl, truncate by 2 lsbs, so mode = 3 */
316  dlt = ((long) detl * qq4_code4_table[il >> 2]) >> 15;
317 
318 /* logscl: updates logarithmic quant. scale factor in low sub band */
319  nbl = logscl (il, nbl);
320 
321 /* scalel: compute the quantizer scale factor in the lower sub band */
322 /* calling parameters nbl and 8 (constant such that scalel can be scaleh) */
323  detl = scalel (nbl, 8);
324 
325 /* parrec - simple addition to compute recontructed signal for adaptive pred */
326  plt = dlt + szl;
327 
328 /* upzero: update zero section predictor coefficients (sixth order)*/
329 /* calling parameters: dlt, dlt1, dlt2, ..., dlt6 from dlt */
330 /* bpli (linear_buffer in which all six values are delayed */
331 /* return params: updated bpli, delayed dltx */
333 
334 /* uppol2- update second predictor coefficient apl2 and delay it as al2 */
335 /* calling parameters: al1, al2, plt, plt1, plt2 */
336  al2 = uppol2 (al1, al2, plt, plt1, plt2);
337 
338 /* uppol1 :update first predictor coefficient apl1 and delay it as al1 */
339 /* calling parameters: al1, apl2, plt, plt1 */
340  al1 = uppol1 (al1, al2, plt, plt1);
341 
342 /* recons : compute recontructed signal for adaptive predictor */
343  rlt = sl + dlt;
344 
345 /* done with lower sub_band encoder; now implement delays for next time*/
346  rlt2 = rlt1;
347  rlt1 = rlt;
348  plt2 = plt1;
349  plt1 = plt;
350 
351 /* high band encode */
352 
354 
355  sph = filtep (rh1, ah1, rh2, ah2);
356 
357 /* predic: sh = sph + szh */
358  sh = sph + szh;
359 /* subtra: eh = xh - sh */
360  eh = xh - sh;
361 
362 /* quanth - quantization of difference signal for higher sub-band */
363 /* quanth: in-place for speed params: eh, deth (has init. value) */
364  if (eh >= 0)
365  {
366  ih = 3; /* 2,3 are pos codes */
367  }
368  else
369  {
370  ih = 1; /* 0,1 are neg codes */
371  }
372  decis = (564L * (long) deth) >> 12L;
373  if (abs (eh) > decis)
374  ih--; /* mih = 2 case */
375 
376 /* compute the quantized difference signal, higher sub-band*/
377  dh = ((long) deth * qq2_code2_table[ih]) >> 15L;
378 
379 /* logsch: update logarithmic quantizer scale factor in hi sub-band*/
380  nbh = logsch (ih, nbh);
381 
382 /* note : scalel and scaleh use same code, different parameters */
383  deth = scalel (nbh, 10);
384 
385 /* parrec - add pole predictor output to quantized diff. signal */
386  ph = dh + szh;
387 
388 /* upzero: update zero section predictor coefficients (sixth order) */
389 /* calling parameters: dh, dhi, bphi */
390 /* return params: updated bphi, delayed dhx */
392 
393 /* uppol2: update second predictor coef aph2 and delay as ah2 */
394 /* calling params: ah1, ah2, ph, ph1, ph2 */
395  ah2 = uppol2 (ah1, ah2, ph, ph1, ph2);
396 
397 /* uppol1: update first predictor coef. aph2 and delay it as ah1 */
398  ah1 = uppol1 (ah1, ah2, ph, ph1);
399 
400 /* recons for higher sub-band */
401  yh = sh + dh;
402 
403 /* done with higher sub-band encoder, now Delay for next time */
404  rh2 = rh1;
405  rh1 = yh;
406  ph2 = ph1;
407  ph1 = ph;
408 
409 /* multiplex ih and il to get signals together */
410  return (il | (ih << 6));
411 }
412 
413 /* decode function, result in xout1 and xout2 */
414 
415 void
417 {
418  int i;
419  long int xa1, xa2; /* qmf accumulators */
420  const int *h_ptr;
421  int *ac_ptr, *ac_ptr1, *ad_ptr, *ad_ptr1;
422 
423 /* split transmitted word from input into ilr and ih */
424  ilr = input & 0x3f;
425  ih = input >> 6;
426 
427 /* LOWER SUB_BAND DECODER */
428 
429 /* filtez: compute predictor output for zero section */
431 
432 /* filtep: compute predictor output signal for pole section */
434 
435  dec_sl = dec_spl + dec_szl;
436 
437 /* compute quantized difference signal for adaptive predic */
438  dec_dlt = ((long) dec_detl * qq4_code4_table[ilr >> 2]) >> 15;
439 
440 /* compute quantized difference signal for decoder output */
441  dl = ((long) dec_detl * qq6_code6_table[il]) >> 15;
442 
443  rl = dl + dec_sl;
444 
445 /* logscl: quantizer scale factor adaptation in the lower sub-band */
446  dec_nbl = logscl (ilr, dec_nbl);
447 
448 /* scalel: computes quantizer scale factor in the lower sub band */
449  dec_detl = scalel (dec_nbl, 8);
450 
451 /* parrec - add pole predictor output to quantized diff. signal */
452 /* for partially reconstructed signal */
453  dec_plt = dec_dlt + dec_szl;
454 
455 /* upzero: update zero section predictor coefficients */
457 
458 /* uppol2: update second predictor coefficient apl2 and delay it as al2 */
460 
461 /* uppol1: update first predictor coef. (pole setion) */
463 
464 /* recons : compute recontructed signal for adaptive predictor */
465  dec_rlt = dec_sl + dec_dlt;
466 
467 /* done with lower sub band decoder, implement delays for next time */
468  dec_rlt2 = dec_rlt1;
469  dec_rlt1 = dec_rlt;
470  dec_plt2 = dec_plt1;
471  dec_plt1 = dec_plt;
472 
473 /* HIGH SUB-BAND DECODER */
474 
475 /* filtez: compute predictor output for zero section */
477 
478 /* filtep: compute predictor output signal for pole section */
480 
481 /* predic:compute the predictor output value in the higher sub_band decoder */
482  dec_sh = dec_sph + dec_szh;
483 
484 /* in-place compute the quantized difference signal */
485  dec_dh = ((long) dec_deth * qq2_code2_table[ih]) >> 15L;
486 
487 /* logsch: update logarithmic quantizer scale factor in hi sub band */
488  dec_nbh = logsch (ih, dec_nbh);
489 
490 /* scalel: compute the quantizer scale factor in the higher sub band */
491  dec_deth = scalel (dec_nbh, 10);
492 
493 /* parrec: compute partially recontructed signal */
494  dec_ph = dec_dh + dec_szh;
495 
496 /* upzero: update zero section predictor coefficients */
498 
499 /* uppol2: update second predictor coefficient aph2 and delay it as ah2 */
501 
502 /* uppol1: update first predictor coef. (pole setion) */
504 
505 /* recons : compute recontructed signal for adaptive predictor */
506  rh = dec_sh + dec_dh;
507 
508 /* done with high band decode, implementing delays for next time here */
509  dec_rh2 = dec_rh1;
510  dec_rh1 = rh;
511  dec_ph2 = dec_ph1;
512  dec_ph1 = dec_ph;
513 
514 /* end of higher sub_band decoder */
515 
516 /* end with receive quadrature mirror filters */
517  xd = rl - rh;
518  xs = rl + rh;
519 
520 /* receive quadrature mirror filters implemented here */
521  h_ptr = h;
522  ac_ptr = accumc;
523  ad_ptr = accumd;
524  xa1 = (long) xd *(*h_ptr++);
525  xa2 = (long) xs *(*h_ptr++);
526 /* main multiply accumulate loop for samples and coefficients */
527  for (i = 0; i < 10; i++)
528  {
529  xa1 += (long) (*ac_ptr++) * (*h_ptr++);
530  xa2 += (long) (*ad_ptr++) * (*h_ptr++);
531  }
532 /* final mult/accumulate */
533  xa1 += (long) (*ac_ptr) * (*h_ptr++);
534  xa2 += (long) (*ad_ptr) * (*h_ptr++);
535 
536 /* scale by 2^14 */
537  xout1 = xa1 >> 14;
538  xout2 = xa2 >> 14;
539 
540 /* update delay lines */
541  ac_ptr1 = ac_ptr - 1;
542  ad_ptr1 = ad_ptr - 1;
543  for (i = 0; i < 10; i++)
544  {
545  *ac_ptr-- = *ac_ptr1--;
546  *ad_ptr-- = *ad_ptr1--;
547  }
548  *ac_ptr = xd;
549  *ad_ptr = xs;
550 }
551 
552 /* clear all storage locations */
553 
554 void
556 {
557  int i;
558 
559  detl = dec_detl = 32; /* reset to min scale factor */
560  deth = dec_deth = 8;
561  nbl = al1 = al2 = plt1 = plt2 = rlt1 = rlt2 = 0;
562  nbh = ah1 = ah2 = ph1 = ph2 = rh1 = rh2 = 0;
565 
566  for (i = 0; i < 6; i++)
567  {
568  delay_dltx[i] = 0;
569  delay_dhx[i] = 0;
570  dec_del_dltx[i] = 0;
571  dec_del_dhx[i] = 0;
572  }
573 
574  for (i = 0; i < 6; i++)
575  {
576  delay_bpl[i] = 0;
577  delay_bph[i] = 0;
578  dec_del_bpl[i] = 0;
579  dec_del_bph[i] = 0;
580  }
581 
582  for (i = 0; i < 24; i++)
583  tqmf[i] = 0; // i<23
584 
585  for (i = 0; i < 11; i++)
586  {
587  accumc[i] = 0;
588  accumd[i] = 0;
589  }
590 }
591 
592 /* filtez - compute predictor output signal (zero section) */
593 /* input: bpl1-6 and dlt1-6, output: szl */
594 
595 int
596 filtez (int *bpl, int *dlt)
597 {
598  int i;
599  long int zl;
600  zl = (long) (*bpl++) * (*dlt++);
601  for (i = 1; i < 6; i++)
602  zl += (long) (*bpl++) * (*dlt++);
603 
604  return ((int) (zl >> 14)); /* x2 here */
605 }
606 
607 /* filtep - compute predictor output signal (pole section) */
608 /* input rlt1-2 and al1-2, output spl */
609 
610 int
611 filtep (int rlt1, int al1, int rlt2, int al2)
612 {
613  long int pl, pl2;
614  pl = 2 * rlt1;
615  pl = (long) al1 *pl;
616  pl2 = 2 * rlt2;
617  pl += (long) al2 *pl2;
618  return ((int) (pl >> 15));
619 }
620 
621 /* quantl - quantize the difference signal in the lower sub-band */
622 int
623 quantl (int el, int detl)
624 {
625  int ril, mil;
626  long int wd, decis;
627 
628 /* abs of difference signal */
629  wd = abs (el);
630 /* determine mil based on decision levels and detl gain */
631  for (mil = 0; mil < 30; mil++)
632  {
633  decis = (decis_levl[mil] * (long) detl) >> 15L;
634  if (wd <= decis)
635  break;
636  }
637 /* if mil=30 then wd is less than all decision levels */
638  if (el >= 0)
639  ril = quant26bt_pos[mil];
640  else
641  ril = quant26bt_neg[mil];
642  return (ril);
643 }
644 
645 /* logscl - update log quantizer scale factor in lower sub-band */
646 /* note that nbl is passed and returned */
647 
648 int
649 logscl (int il, int nbl)
650 {
651  long int wd;
652  wd = ((long) nbl * 127L) >> 7L; /* leak factor 127/128 */
653  nbl = (int) wd + wl_code_table[il >> 2];
654  if (nbl < 0)
655  nbl = 0;
656  if (nbl > 18432)
657  nbl = 18432;
658  return (nbl);
659 }
660 
661 /* scalel: compute quantizer scale factor in lower or upper sub-band*/
662 
663 int
664 scalel (int nbl, int shift_constant)
665 {
666  int wd1, wd2, wd3;
667  wd1 = (nbl >> 6) & 31;
668  wd2 = nbl >> 11;
669  wd3 = ilb_table[wd1] >> (shift_constant + 1 - wd2);
670  return (wd3 << 3);
671 }
672 
673 /* upzero - inputs: dlt, dlti[0-5], bli[0-5], outputs: updated bli[0-5] */
674 /* also implements delay of bli and update of dlti from dlt */
675 
676 void
677 upzero (int dlt, int *dlti, int *bli)
678 {
679  int i, wd2, wd3;
680 /*if dlt is zero, then no sum into bli */
681  if (dlt == 0)
682  {
683  for (i = 0; i < 6; i++)
684  {
685  bli[i] = (int) ((255L * bli[i]) >> 8L); /* leak factor of 255/256 */
686  }
687  }
688  else
689  {
690  for (i = 0; i < 6; i++)
691  {
692  if ((long) dlt * dlti[i] >= 0)
693  wd2 = 128;
694  else
695  wd2 = -128;
696  wd3 = (int) ((255L * bli[i]) >> 8L); /* leak factor of 255/256 */
697  bli[i] = wd2 + wd3;
698  }
699  }
700 /* implement delay line for dlt */
701  dlti[5] = dlti[4];
702  dlti[4] = dlti[3];
703  dlti[3] = dlti[2];
704  dlti[1] = dlti[0];
705  dlti[0] = dlt;
706 }
707 
708 /* uppol2 - update second predictor coefficient (pole section) */
709 /* inputs: al1, al2, plt, plt1, plt2. outputs: apl2 */
710 
711 int
712 uppol2 (int al1, int al2, int plt, int plt1, int plt2)
713 {
714  long int wd2, wd4;
715  int apl2;
716  wd2 = 4L * (long) al1;
717  if ((long) plt * plt1 >= 0L)
718  wd2 = -wd2; /* check same sign */
719  wd2 = wd2 >> 7; /* gain of 1/128 */
720  if ((long) plt * plt2 >= 0L)
721  {
722  wd4 = wd2 + 128; /* same sign case */
723  }
724  else
725  {
726  wd4 = wd2 - 128;
727  }
728  apl2 = wd4 + (127L * (long) al2 >> 7L); /* leak factor of 127/128 */
729 
730 /* apl2 is limited to +-.75 */
731  if (apl2 > 12288)
732  apl2 = 12288;
733  if (apl2 < -12288)
734  apl2 = -12288;
735  return (apl2);
736 }
737 
738 /* uppol1 - update first predictor coefficient (pole section) */
739 /* inputs: al1, apl2, plt, plt1. outputs: apl1 */
740 
741 int
742 uppol1 (int al1, int apl2, int plt, int plt1)
743 {
744  long int wd2;
745  int wd3, apl1;
746  wd2 = ((long) al1 * 255L) >> 8L; /* leak factor of 255/256 */
747  if ((long) plt * plt1 >= 0L)
748  {
749  apl1 = (int) wd2 + 192; /* same sign case */
750  }
751  else
752  {
753  apl1 = (int) wd2 - 192;
754  }
755 /* note: wd3= .9375-.75 is always positive */
756  wd3 = 15360 - apl2; /* limit value */
757  if (apl1 > wd3)
758  apl1 = wd3;
759  if (apl1 < -wd3)
760  apl1 = -wd3;
761  return (apl1);
762 }
763 
764 /* logsch - update log quantizer scale factor in higher sub-band */
765 /* note that nbh is passed and returned */
766 
767 int
768 logsch (int ih, int nbh)
769 {
770  int wd;
771  wd = ((long) nbh * 127L) >> 7L; /* leak factor 127/128 */
772  nbh = wd + wh_code_table[ih];
773  if (nbh < 0)
774  nbh = 0;
775  if (nbh > 22528)
776  nbh = 22528;
777  return (nbh);
778 }
779 
780 /*
781 +--------------------------------------------------------------------------+
782 | * Test Vectors (added for CHStone) |
783 | test_data : input data |
784 | test_compressed : expected output data for "encode" |
785 | test_result : expected output data for "decode" |
786 +--------------------------------------------------------------------------+
787 */
788 
789 #define SIZE 100
790 #define IN_END 100
791 
792 const int test_data[SIZE] = {
793  0x44, 0x44, 0x44, 0x44, 0x44,
794  0x44, 0x44, 0x44, 0x44, 0x44,
795  0x44, 0x44, 0x44, 0x44, 0x44,
796  0x44, 0x44, 0x43, 0x43, 0x43,
797  0x43, 0x43, 0x43, 0x43, 0x42,
798  0x42, 0x42, 0x42, 0x42, 0x42,
799  0x41, 0x41, 0x41, 0x41, 0x41,
800  0x40, 0x40, 0x40, 0x40, 0x40,
801  0x40, 0x40, 0x40, 0x3f, 0x3f,
802  0x3f, 0x3f, 0x3f, 0x3e, 0x3e,
803  0x3e, 0x3e, 0x3e, 0x3e, 0x3d,
804  0x3d, 0x3d, 0x3d, 0x3d, 0x3d,
805  0x3c, 0x3c, 0x3c, 0x3c, 0x3c,
806  0x3c, 0x3c, 0x3c, 0x3c, 0x3b,
807  0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
808  0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
809  0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
810  0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
811  0x3b, 0x3b, 0x3c, 0x3c, 0x3c,
812  0x3c, 0x3c, 0x3c, 0x3c, 0x3c
813 };
815 const int test_compressed[SIZE] = {
816  253, 222, 119, 186, 244,
817  146, 32, 160, 236, 237,
818  238, 240, 241, 241, 242,
819  243, 244, 243, 244, 245,
820  244, 244, 245, 245, 245,
821  246, 246, 247, 247, 247,
822  247, 248, 246, 247, 249,
823  247, 248, 247, 248, 247,
824  248, 247, 248, 247, 248,
825  248, 246, 248, 247, 248,
826  0, 0, 0, 0, 0,
827  0, 0, 0, 0, 0,
828  0, 0, 0, 0, 0,
829  0, 0, 0, 0, 0,
830  0, 0, 0, 0, 0,
831  0, 0, 0, 0, 0,
832  0, 0, 0, 0, 0,
833  0, 0, 0, 0, 0,
834  0, 0, 0, 0, 0,
835  0, 0, 0, 0, 0
836 };
837 const int test_result[SIZE] = {
838  0, -1, -1, 0, 0,
839  -1, 0, 0, -1, -1,
840  0, 0, 1, 1, 0,
841  -2, -1, -2, 0, -3,
842  1, 0, 0, -4, 1,
843  1, 2, 11, 20, 18,
844  20, 22, 28, 27, 31,
845  31, 34, 31, 34, 34,
846  38, 37, 42, 42, 44,
847  41, 43, 42, 47, 45,
848  47, 44, 45, 43, 46,
849  45, 48, 46, 49, 48,
850  51, 49, 52, 52, 55,
851  53, 56, 55, 58, 57,
852  59, 57, 60, 60, 60,
853  54, 54, 53, 60, 62,
854  62, 54, 55, 56, 59,
855  53, 54, 56, 59, 53,
856  56, 58, 59, 53, 56,
857  58, 60, 54, 55, 57
858 };
859 
860 void
862 {
863  int i, j;
864 
865 /* reset, initialize required memory */
866  reset ();
867 
868  j = 10;
869 
870  for (i = 0; i < IN_END; i += 2)
871  {
872  compressed[i / 2] = encode (test_data[i], test_data[i + 1]);
873  }
874  for (i = 0; i < IN_END; i += 2)
875  {
876  decode (compressed[i / 2]);
877  result[i] = xout1;
878  result[i + 1] = xout2;
879  }
880 }
881 
882 int
884 {
885  int i;
886  int main_result;
887 
888  main_result = 0;
889  adpcm_main ();
890  for (i = 0; i < IN_END / 2; i++)
891  {
892  if (compressed[i] != test_compressed[i])
893  {
894  main_result = 1;
895  }
896  }
897  for (i = 0; i < IN_END; i++)
898  {
899  if (result[i] != test_result[i])
900  {
901  main_result = 1;
902  }
903  }
904  printf ("%d\n", main_result);
905  return main_result;
906  }
int szh
Definition: adpcm.c:189
int __attribute__((noinline))
Definition: adpcm.c:262
int delay_bph[6]
Definition: adpcm.c:194
int scalel(int nbl, int shift_constant)
Definition: adpcm.c:649
int ph
Definition: adpcm.c:190
void decode(int)
Definition: adpcm.c:401
int al2
Definition: adpcm.c:141
int deth
Definition: adpcm.c:175
int dec_del_bph[6]
Definition: adpcm.c:216
const int ilb_table[32]
Definition: adpcm.c:133
int uppol1(int al1, int apl2, int plt, int plt1)
Definition: adpcm.c:728
void upzero(int dlt, int *dlti, int *bli)
Definition: adpcm.c:662
int accumd[11]
Definition: adpcm.c:96
void reset()
Definition: adpcm.c:540
int input[SIZE]
Definition: hash.h:1
int dec_del_bpl[6]
Definition: adpcm.c:204
int plt2
Definition: adpcm.c:142
int dec_spl
Definition: adpcm.c:209
int dec_plt1
Definition: adpcm.c:208
int dec_szh
Definition: adpcm.c:220
int dec_plt
Definition: adpcm.c:208
int dec_del_dltx[6]
Definition: adpcm.c:206
int dec_ah1
Definition: adpcm.c:223
int ph1
Definition: adpcm.c:197
int dec_rlt2
Definition: adpcm.c:210
int dec_nbl
Definition: adpcm.c:213
int main_result
Definition: mips.c:38
int ilr
Definition: adpcm.c:201
int delay_bpl[6]
Definition: adpcm.c:124
const int quant26bt_pos[31]
Definition: adpcm.c:158
int sh
Definition: adpcm.c:176
const int qq4_code4_table[16]
Definition: adpcm.c:107
int filtez(int *bpl, int *dlt)
Definition: adpcm.c:581
int dec_nbh
Definition: adpcm.c:213
int ih
Definition: adpcm.c:188
int main()
Definition: adpcm.c:859
int dec_rh2
Definition: adpcm.c:222
const int qq2_code2_table[4]
Definition: adpcm.c:179
int compressed[SIZE]
Definition: adpcm.c:800
int xout1
Definition: adpcm.c:99
const int test_data[SIZE]
Definition: adpcm.c:778
int dec_ah2
Definition: adpcm.c:223
int dec_rh1
Definition: adpcm.c:222
int dl
Definition: adpcm.c:212
int dec_szl
Definition: adpcm.c:209
int dec_rlt
Definition: adpcm.c:210
int spl
Definition: adpcm.c:105
int dec_al1
Definition: adpcm.c:211
int dec_sph
Definition: adpcm.c:224
int tqmf[24]
Definition: adpcm.c:83
int dec_ph2
Definition: adpcm.c:228
const int test_result[SIZE]
Definition: adpcm.c:813
int xout2
Definition: adpcm.c:99
int uppol2(int al1, int al2, int plt, int plt1, int plt2)
Definition: adpcm.c:698
int dh
Definition: adpcm.c:188
int accumc[11]
Definition: adpcm.c:96
int detl
Definition: adpcm.c:154
int rlt2
Definition: adpcm.c:144
const int h[24]
Definition: adpcm.c:87
int xd
Definition: adpcm.c:101
int dec_rlt1
Definition: adpcm.c:210
int dec_sl
Definition: adpcm.c:209
int il
Definition: adpcm.c:105
int rlt1
Definition: adpcm.c:144
int eh
Definition: adpcm.c:177
int dec_dh
Definition: adpcm.c:213
int result[SIZE]
Definition: adpcm.c:800
#define L
Definition: spmv.h:13
int logscl(int il, int nbl)
Definition: adpcm.c:634
#define IN_END
Definition: adpcm.c:790
int xh
Definition: adpcm.c:93
int sph
Definition: adpcm.c:190
int encode(int, int)
Definition: adpcm.c:248
int xl
Definition: adpcm.c:93
int ah1
Definition: adpcm.c:196
const int test_compressed[SIZE]
Definition: adpcm.c:801
void adpcm_main()
Definition: adpcm.c:837
int plt1
Definition: adpcm.c:142
int ph2
Definition: adpcm.c:197
int el
Definition: adpcm.c:105
int delay_dltx[6]
Definition: adpcm.c:126
int quantl(int el, int detl)
Definition: adpcm.c:608
int rh1
Definition: adpcm.c:198
int dec_detl
Definition: adpcm.c:202
int dec_plt2
Definition: adpcm.c:208
int delay_dhx[6]
Definition: adpcm.c:192
int ah2
Definition: adpcm.c:196
int rl
Definition: adpcm.c:201
int logsch(int ih, int nbh)
Definition: adpcm.c:754
int dlt
Definition: adpcm.c:143
int dec_ph1
Definition: adpcm.c:228
int abs(int n)
Definition: adpcm.c:236
int xs
Definition: adpcm.c:101
int szl
Definition: adpcm.c:105
const int quant26bt_neg[31]
Definition: adpcm.c:167
int yh
Definition: adpcm.c:190
const int decis_levl[30]
Definition: adpcm.c:147
int rh
Definition: adpcm.c:190
int dec_dlt
Definition: adpcm.c:202
int dec_del_dhx[6]
Definition: adpcm.c:218
int rh2
Definition: adpcm.c:198
const int qq6_code6_table[64]
Definition: adpcm.c:113
int dec_deth
Definition: adpcm.c:202
int dec_sh
Definition: adpcm.c:226
int filtep(int rlt1, int al1, int rlt2, int al2)
Definition: adpcm.c:596
int rlt
Definition: adpcm.c:144
int plt
Definition: adpcm.c:142
int al1
Definition: adpcm.c:141
const int wl_code_table[16]
Definition: adpcm.c:128
#define SIZE
Definition: adpcm.c:789
int dec_al2
Definition: adpcm.c:211
int nbh
Definition: adpcm.c:189
int nbl
Definition: adpcm.c:140
int sl
Definition: adpcm.c:105
int dec_ph
Definition: adpcm.c:224
const int wh_code_table[4]
Definition: adpcm.c:183

Generated on Mon Feb 12 2024 13:02:48 for PandA-2024.02 by doxygen 1.8.13