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 int detl;
155 
156 /* quantization table 31 long to make quantl look-up easier,
157 last entry is for mil=30 case when wd is max */
158 const int quant26bt_pos[31] = {
159  61, 60, 59, 58, 57, 56, 55, 54,
160  53, 52, 51, 50, 49, 48, 47, 46,
161  45, 44, 43, 42, 41, 40, 39, 38,
162  37, 36, 35, 34, 33, 32, 32
163 };
164 
165 /* quantization table 31 long to make quantl look-up easier,
166 last entry is for mil=30 case when wd is max */
167 const int quant26bt_neg[31] = {
168  63, 62, 31, 30, 29, 28, 27, 26,
169  25, 24, 23, 22, 21, 20, 19, 18,
170  17, 16, 15, 14, 13, 12, 11, 10,
171  9, 8, 7, 6, 5, 4, 4
172 };
173 
174 
175 int deth;
176 int sh; /* this comes from adaptive predictor */
177 int eh;
178 
179 const int qq2_code2_table[4] = {
180  -7408, -1616, 7408, 1616
181 };
182 
183 const int wh_code_table[4] = {
184  798, -214, 798, -214
185 };
186 
187 
188 int dh, ih;
189 int nbh, szh;
190 int sph, ph, yh, rh;
191 
192 int delay_dhx[6];
193 
194 int delay_bph[6];
195 
196 int ah1, ah2;
197 int ph1, ph2;
198 int rh1, rh2;
199 
200 /* variables for decoder here */
201 int ilr, rl;
203 
204 int dec_del_bpl[6];
205 
207 
212 int dl;
214 
215 /* variables used in filtez */
216 int dec_del_bph[6];
217 
218 int dec_del_dhx[6];
219 
221 /* variables used in filtep */
225 
226 int dec_sh;
227 
229 
230 /* G722 encode function two ints in, one 8 bit output */
231 
232 /* put input samples in xin1 = first value, xin2 = second value */
233 /* returns il and ih stored together */
234 
235 int
236 abs (int n)
237 {
238  int m;
239 
240  if (n >= 0)
241  m = n;
242  else
243  m = -n;
244  return m;
245 }
246 
247 int
248 encode (int xin1, int xin2)
249 {
250  int i;
251  const int *h_ptr;
252  int *tqmf_ptr, *tqmf_ptr1;
253  long int xa, xb;
254  int decis;
255 
256 /* transmit quadrature mirror filters implemented here */
257  h_ptr = h;
258  tqmf_ptr = tqmf;
259  xa = (long) (*tqmf_ptr++) * (*h_ptr++);
260  xb = (long) (*tqmf_ptr++) * (*h_ptr++);
261 /* main multiply accumulate loop for samples and coefficients */
262  for (i = 0; i < 10; i++)
263  {
264  xa += (long) (*tqmf_ptr++) * (*h_ptr++);
265  xb += (long) (*tqmf_ptr++) * (*h_ptr++);
266  }
267 /* final mult/accumulate */
268  xa += (long) (*tqmf_ptr++) * (*h_ptr++);
269  xb += (long) (*tqmf_ptr) * (*h_ptr++);
270 
271 /* update delay line tqmf */
272  tqmf_ptr1 = tqmf_ptr - 2;
273  for (i = 0; i < 22; i++)
274  *tqmf_ptr-- = *tqmf_ptr1--;
275  *tqmf_ptr-- = xin1;
276  *tqmf_ptr = xin2;
277 
278 /* scale outputs */
279  xl = (xa + xb) >> 15;
280  xh = (xa - xb) >> 15;
281 
282 /* end of quadrature mirror filter code */
283 
284 /* starting with lower sub band encoder */
285 
286 /* filtez - compute predictor output section - zero section */
288 
289 /* filtep - compute predictor output signal (pole section) */
290  spl = filtep (rlt1, al1, rlt2, al2);
291 
292 /* compute the predictor output value in the lower sub_band encoder */
293  sl = szl + spl;
294  el = xl - sl;
295 
296 /* quantl: quantize the difference signal */
297  il = quantl (el, detl);
298 
299 /* computes quantized difference signal */
300 /* for invqbl, truncate by 2 lsbs, so mode = 3 */
301  dlt = ((long) detl * qq4_code4_table[il >> 2]) >> 15;
302 
303 /* logscl: updates logarithmic quant. scale factor in low sub band */
304  nbl = logscl (il, nbl);
305 
306 /* scalel: compute the quantizer scale factor in the lower sub band */
307 /* calling parameters nbl and 8 (constant such that scalel can be scaleh) */
308  detl = scalel (nbl, 8);
309 
310 /* parrec - simple addition to compute recontructed signal for adaptive pred */
311  plt = dlt + szl;
312 
313 /* upzero: update zero section predictor coefficients (sixth order)*/
314 /* calling parameters: dlt, dlt1, dlt2, ..., dlt6 from dlt */
315 /* bpli (linear_buffer in which all six values are delayed */
316 /* return params: updated bpli, delayed dltx */
318 
319 /* uppol2- update second predictor coefficient apl2 and delay it as al2 */
320 /* calling parameters: al1, al2, plt, plt1, plt2 */
321  al2 = uppol2 (al1, al2, plt, plt1, plt2);
322 
323 /* uppol1 :update first predictor coefficient apl1 and delay it as al1 */
324 /* calling parameters: al1, apl2, plt, plt1 */
325  al1 = uppol1 (al1, al2, plt, plt1);
326 
327 /* recons : compute recontructed signal for adaptive predictor */
328  rlt = sl + dlt;
329 
330 /* done with lower sub_band encoder; now implement delays for next time*/
331  rlt2 = rlt1;
332  rlt1 = rlt;
333  plt2 = plt1;
334  plt1 = plt;
335 
336 /* high band encode */
337 
339 
340  sph = filtep (rh1, ah1, rh2, ah2);
341 
342 /* predic: sh = sph + szh */
343  sh = sph + szh;
344 /* subtra: eh = xh - sh */
345  eh = xh - sh;
346 
347 /* quanth - quantization of difference signal for higher sub-band */
348 /* quanth: in-place for speed params: eh, deth (has init. value) */
349  if (eh >= 0)
350  {
351  ih = 3; /* 2,3 are pos codes */
352  }
353  else
354  {
355  ih = 1; /* 0,1 are neg codes */
356  }
357  decis = (564L * (long) deth) >> 12L;
358  if (abs (eh) > decis)
359  ih--; /* mih = 2 case */
360 
361 /* compute the quantized difference signal, higher sub-band*/
362  dh = ((long) deth * qq2_code2_table[ih]) >> 15L;
363 
364 /* logsch: update logarithmic quantizer scale factor in hi sub-band*/
365  nbh = logsch (ih, nbh);
366 
367 /* note : scalel and scaleh use same code, different parameters */
368  deth = scalel (nbh, 10);
369 
370 /* parrec - add pole predictor output to quantized diff. signal */
371  ph = dh + szh;
372 
373 /* upzero: update zero section predictor coefficients (sixth order) */
374 /* calling parameters: dh, dhi, bphi */
375 /* return params: updated bphi, delayed dhx */
377 
378 /* uppol2: update second predictor coef aph2 and delay as ah2 */
379 /* calling params: ah1, ah2, ph, ph1, ph2 */
380  ah2 = uppol2 (ah1, ah2, ph, ph1, ph2);
381 
382 /* uppol1: update first predictor coef. aph2 and delay it as ah1 */
383  ah1 = uppol1 (ah1, ah2, ph, ph1);
384 
385 /* recons for higher sub-band */
386  yh = sh + dh;
387 
388 /* done with higher sub-band encoder, now Delay for next time */
389  rh2 = rh1;
390  rh1 = yh;
391  ph2 = ph1;
392  ph1 = ph;
393 
394 /* multiplex ih and il to get signals together */
395  return (il | (ih << 6));
396 }
397 
398 /* decode function, result in xout1 and xout2 */
399 
400 void
402 {
403  int i;
404  long int xa1, xa2; /* qmf accumulators */
405  const int *h_ptr;
406  int *ac_ptr, *ac_ptr1, *ad_ptr, *ad_ptr1;
407 
408 /* split transmitted word from input into ilr and ih */
409  ilr = input & 0x3f;
410  ih = input >> 6;
411 
412 /* LOWER SUB_BAND DECODER */
413 
414 /* filtez: compute predictor output for zero section */
416 
417 /* filtep: compute predictor output signal for pole section */
419 
420  dec_sl = dec_spl + dec_szl;
421 
422 /* compute quantized difference signal for adaptive predic */
423  dec_dlt = ((long) dec_detl * qq4_code4_table[ilr >> 2]) >> 15;
424 
425 /* compute quantized difference signal for decoder output */
426  dl = ((long) dec_detl * qq6_code6_table[il]) >> 15;
427 
428  rl = dl + dec_sl;
429 
430 /* logscl: quantizer scale factor adaptation in the lower sub-band */
431  dec_nbl = logscl (ilr, dec_nbl);
432 
433 /* scalel: computes quantizer scale factor in the lower sub band */
434  dec_detl = scalel (dec_nbl, 8);
435 
436 /* parrec - add pole predictor output to quantized diff. signal */
437 /* for partially reconstructed signal */
438  dec_plt = dec_dlt + dec_szl;
439 
440 /* upzero: update zero section predictor coefficients */
442 
443 /* uppol2: update second predictor coefficient apl2 and delay it as al2 */
445 
446 /* uppol1: update first predictor coef. (pole setion) */
448 
449 /* recons : compute recontructed signal for adaptive predictor */
450  dec_rlt = dec_sl + dec_dlt;
451 
452 /* done with lower sub band decoder, implement delays for next time */
453  dec_rlt2 = dec_rlt1;
454  dec_rlt1 = dec_rlt;
455  dec_plt2 = dec_plt1;
456  dec_plt1 = dec_plt;
457 
458 /* HIGH SUB-BAND DECODER */
459 
460 /* filtez: compute predictor output for zero section */
462 
463 /* filtep: compute predictor output signal for pole section */
465 
466 /* predic:compute the predictor output value in the higher sub_band decoder */
467  dec_sh = dec_sph + dec_szh;
468 
469 /* in-place compute the quantized difference signal */
470  dec_dh = ((long) dec_deth * qq2_code2_table[ih]) >> 15L;
471 
472 /* logsch: update logarithmic quantizer scale factor in hi sub band */
473  dec_nbh = logsch (ih, dec_nbh);
474 
475 /* scalel: compute the quantizer scale factor in the higher sub band */
476  dec_deth = scalel (dec_nbh, 10);
477 
478 /* parrec: compute partially recontructed signal */
479  dec_ph = dec_dh + dec_szh;
480 
481 /* upzero: update zero section predictor coefficients */
483 
484 /* uppol2: update second predictor coefficient aph2 and delay it as ah2 */
486 
487 /* uppol1: update first predictor coef. (pole setion) */
489 
490 /* recons : compute recontructed signal for adaptive predictor */
491  rh = dec_sh + dec_dh;
492 
493 /* done with high band decode, implementing delays for next time here */
494  dec_rh2 = dec_rh1;
495  dec_rh1 = rh;
496  dec_ph2 = dec_ph1;
497  dec_ph1 = dec_ph;
498 
499 /* end of higher sub_band decoder */
500 
501 /* end with receive quadrature mirror filters */
502  xd = rl - rh;
503  xs = rl + rh;
504 
505 /* receive quadrature mirror filters implemented here */
506  h_ptr = h;
507  ac_ptr = accumc;
508  ad_ptr = accumd;
509  xa1 = (long) xd *(*h_ptr++);
510  xa2 = (long) xs *(*h_ptr++);
511 /* main multiply accumulate loop for samples and coefficients */
512  for (i = 0; i < 10; i++)
513  {
514  xa1 += (long) (*ac_ptr++) * (*h_ptr++);
515  xa2 += (long) (*ad_ptr++) * (*h_ptr++);
516  }
517 /* final mult/accumulate */
518  xa1 += (long) (*ac_ptr) * (*h_ptr++);
519  xa2 += (long) (*ad_ptr) * (*h_ptr++);
520 
521 /* scale by 2^14 */
522  xout1 = xa1 >> 14;
523  xout2 = xa2 >> 14;
524 
525 /* update delay lines */
526  ac_ptr1 = ac_ptr - 1;
527  ad_ptr1 = ad_ptr - 1;
528  for (i = 0; i < 10; i++)
529  {
530  *ac_ptr-- = *ac_ptr1--;
531  *ad_ptr-- = *ad_ptr1--;
532  }
533  *ac_ptr = xd;
534  *ad_ptr = xs;
535 }
536 
537 /* clear all storage locations */
538 
539 void
541 {
542  int i;
543 
544  detl = dec_detl = 32; /* reset to min scale factor */
545  deth = dec_deth = 8;
546  nbl = al1 = al2 = plt1 = plt2 = rlt1 = rlt2 = 0;
547  nbh = ah1 = ah2 = ph1 = ph2 = rh1 = rh2 = 0;
550 
551  for (i = 0; i < 6; i++)
552  {
553  delay_dltx[i] = 0;
554  delay_dhx[i] = 0;
555  dec_del_dltx[i] = 0;
556  dec_del_dhx[i] = 0;
557  }
558 
559  for (i = 0; i < 6; i++)
560  {
561  delay_bpl[i] = 0;
562  delay_bph[i] = 0;
563  dec_del_bpl[i] = 0;
564  dec_del_bph[i] = 0;
565  }
566 
567  for (i = 0; i < 24; i++)
568  tqmf[i] = 0; // i<23
569 
570  for (i = 0; i < 11; i++)
571  {
572  accumc[i] = 0;
573  accumd[i] = 0;
574  }
575 }
576 
577 /* filtez - compute predictor output signal (zero section) */
578 /* input: bpl1-6 and dlt1-6, output: szl */
579 
580 int
581 filtez (int *bpl, int *dlt)
582 {
583  int i;
584  long int zl;
585  zl = (long) (*bpl++) * (*dlt++);
586  for (i = 1; i < 6; i++)
587  zl += (long) (*bpl++) * (*dlt++);
588 
589  return ((int) (zl >> 14)); /* x2 here */
590 }
591 
592 /* filtep - compute predictor output signal (pole section) */
593 /* input rlt1-2 and al1-2, output spl */
594 
595 int
596 filtep (int rlt1, int al1, int rlt2, int al2)
597 {
598  long int pl, pl2;
599  pl = 2 * rlt1;
600  pl = (long) al1 *pl;
601  pl2 = 2 * rlt2;
602  pl += (long) al2 *pl2;
603  return ((int) (pl >> 15));
604 }
605 
606 /* quantl - quantize the difference signal in the lower sub-band */
607 int
608 quantl (int el, int detl)
609 {
610  int ril, mil;
611  long int wd, decis;
612 
613 /* abs of difference signal */
614  wd = abs (el);
615 /* determine mil based on decision levels and detl gain */
616  for (mil = 0; mil < 30; mil++)
617  {
618  decis = (decis_levl[mil] * (long) detl) >> 15L;
619  if (wd <= decis)
620  break;
621  }
622 /* if mil=30 then wd is less than all decision levels */
623  if (el >= 0)
624  ril = quant26bt_pos[mil];
625  else
626  ril = quant26bt_neg[mil];
627  return (ril);
628 }
629 
630 /* logscl - update log quantizer scale factor in lower sub-band */
631 /* note that nbl is passed and returned */
632 
633 int
634 logscl (int il, int nbl)
635 {
636  long int wd;
637  wd = ((long) nbl * 127L) >> 7L; /* leak factor 127/128 */
638  nbl = (int) wd + wl_code_table[il >> 2];
639  if (nbl < 0)
640  nbl = 0;
641  if (nbl > 18432)
642  nbl = 18432;
643  return (nbl);
644 }
645 
646 /* scalel: compute quantizer scale factor in lower or upper sub-band*/
647 
648 int
649 scalel (int nbl, int shift_constant)
650 {
651  int wd1, wd2, wd3;
652  wd1 = (nbl >> 6) & 31;
653  wd2 = nbl >> 11;
654  wd3 = ilb_table[wd1] >> (shift_constant + 1 - wd2);
655  return (wd3 << 3);
656 }
657 
658 /* upzero - inputs: dlt, dlti[0-5], bli[0-5], outputs: updated bli[0-5] */
659 /* also implements delay of bli and update of dlti from dlt */
660 
661 void
662 upzero (int dlt, int *dlti, int *bli)
663 {
664  int i, wd2, wd3;
665 /*if dlt is zero, then no sum into bli */
666  if (dlt == 0)
667  {
668  for (i = 0; i < 6; i++)
669  {
670  bli[i] = (int) ((255L * bli[i]) >> 8L); /* leak factor of 255/256 */
671  }
672  }
673  else
674  {
675  for (i = 0; i < 6; i++)
676  {
677  if ((long) dlt * dlti[i] >= 0)
678  wd2 = 128;
679  else
680  wd2 = -128;
681  wd3 = (int) ((255L * bli[i]) >> 8L); /* leak factor of 255/256 */
682  bli[i] = wd2 + wd3;
683  }
684  }
685 /* implement delay line for dlt */
686  dlti[5] = dlti[4];
687  dlti[4] = dlti[3];
688  dlti[3] = dlti[2];
689  dlti[2] = dlti[1];
690  dlti[1] = dlti[0];
691  dlti[0] = dlt;
692 }
693 
694 /* uppol2 - update second predictor coefficient (pole section) */
695 /* inputs: al1, al2, plt, plt1, plt2. outputs: apl2 */
696 
697 int
698 uppol2 (int al1, int al2, int plt, int plt1, int plt2)
699 {
700  long int wd2, wd4;
701  int apl2;
702  wd2 = 4L * (long) al1;
703  if ((long) plt * plt1 >= 0L)
704  wd2 = -wd2; /* check same sign */
705  wd2 = wd2 >> 7; /* gain of 1/128 */
706  if ((long) plt * plt2 >= 0L)
707  {
708  wd4 = wd2 + 128; /* same sign case */
709  }
710  else
711  {
712  wd4 = wd2 - 128;
713  }
714  apl2 = wd4 + (127L * (long) al2 >> 7L); /* leak factor of 127/128 */
715 
716 /* apl2 is limited to +-.75 */
717  if (apl2 > 12288)
718  apl2 = 12288;
719  if (apl2 < -12288)
720  apl2 = -12288;
721  return (apl2);
722 }
723 
724 /* uppol1 - update first predictor coefficient (pole section) */
725 /* inputs: al1, apl2, plt, plt1. outputs: apl1 */
726 
727 int
728 uppol1 (int al1, int apl2, int plt, int plt1)
729 {
730  long int wd2;
731  int wd3, apl1;
732  wd2 = ((long) al1 * 255L) >> 8L; /* leak factor of 255/256 */
733  if ((long) plt * plt1 >= 0L)
734  {
735  apl1 = (int) wd2 + 192; /* same sign case */
736  }
737  else
738  {
739  apl1 = (int) wd2 - 192;
740  }
741 /* note: wd3= .9375-.75 is always positive */
742  wd3 = 15360 - apl2; /* limit value */
743  if (apl1 > wd3)
744  apl1 = wd3;
745  if (apl1 < -wd3)
746  apl1 = -wd3;
747  return (apl1);
748 }
749 
750 /* logsch - update log quantizer scale factor in higher sub-band */
751 /* note that nbh is passed and returned */
752 
753 int
754 logsch (int ih, int nbh)
755 {
756  int wd;
757  wd = ((long) nbh * 127L) >> 7L; /* leak factor 127/128 */
758  nbh = wd + wh_code_table[ih];
759  if (nbh < 0)
760  nbh = 0;
761  if (nbh > 22528)
762  nbh = 22528;
763  return (nbh);
764 }
765 
766 /*
767 +--------------------------------------------------------------------------+
768 | * Test Vectors (added for CHStone) |
769 | test_data : input data |
770 | test_compressed : expected output data for "encode" |
771 | test_result : expected output data for "decode" |
772 +--------------------------------------------------------------------------+
773 */
774 
775 #define SIZE 100
776 #define IN_END 100
777 
778 const int test_data[SIZE] = {
779  0x44, 0x44, 0x44, 0x44, 0x44,
780  0x44, 0x44, 0x44, 0x44, 0x44,
781  0x44, 0x44, 0x44, 0x44, 0x44,
782  0x44, 0x44, 0x43, 0x43, 0x43,
783  0x43, 0x43, 0x43, 0x43, 0x42,
784  0x42, 0x42, 0x42, 0x42, 0x42,
785  0x41, 0x41, 0x41, 0x41, 0x41,
786  0x40, 0x40, 0x40, 0x40, 0x40,
787  0x40, 0x40, 0x40, 0x3f, 0x3f,
788  0x3f, 0x3f, 0x3f, 0x3e, 0x3e,
789  0x3e, 0x3e, 0x3e, 0x3e, 0x3d,
790  0x3d, 0x3d, 0x3d, 0x3d, 0x3d,
791  0x3c, 0x3c, 0x3c, 0x3c, 0x3c,
792  0x3c, 0x3c, 0x3c, 0x3c, 0x3b,
793  0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
794  0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
795  0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
796  0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
797  0x3b, 0x3b, 0x3c, 0x3c, 0x3c,
798  0x3c, 0x3c, 0x3c, 0x3c, 0x3c
799 };
801 const int test_compressed[SIZE] = {
802  0xfd, 0xde, 0x77, 0xba, 0xf2,
803  0x90, 0x20, 0xa0, 0xec, 0xed,
804  0xef, 0xf1, 0xf3, 0xf4, 0xf5,
805  0xf5, 0xf5, 0xf5, 0xf6, 0xf6,
806  0xf6, 0xf7, 0xf8, 0xf7, 0xf8,
807  0xf7, 0xf9, 0xf8, 0xf7, 0xf9,
808  0xf8, 0xf8, 0xf6, 0xf8, 0xf8,
809  0xf7, 0xf9, 0xf9, 0xf9, 0xf8,
810  0xf7, 0xfa, 0xf8, 0xf8, 0xf7,
811  0xfb, 0xfa, 0xf9, 0xf8, 0xf8
812 };
813 const int test_result[SIZE] = {
814  0, 0xffffffff, 0xffffffff, 0, 0,
815  0xffffffff, 0, 0, 0xffffffff, 0xffffffff,
816  0, 0, 0x1, 0x1, 0,
817  0xfffffffe, 0xffffffff, 0xfffffffe, 0, 0xfffffffc,
818  0x1, 0x1, 0x1, 0xfffffffb, 0x2,
819  0x2, 0x3, 0xb, 0x14, 0x14,
820  0x16, 0x18, 0x20, 0x21, 0x26,
821  0x27, 0x2e, 0x2f, 0x33, 0x32,
822  0x35, 0x33, 0x36, 0x34, 0x37,
823  0x34, 0x37, 0x35, 0x38, 0x36,
824  0x39, 0x38, 0x3b, 0x3a, 0x3f,
825  0x3f, 0x40, 0x3a, 0x3d, 0x3e,
826  0x41, 0x3c, 0x3e, 0x3f, 0x42,
827  0x3e, 0x3b, 0x37, 0x3b, 0x3e,
828  0x41, 0x3b, 0x3b, 0x3a, 0x3b,
829  0x36, 0x39, 0x3b, 0x3f, 0x3c,
830  0x3b, 0x37, 0x3b, 0x3d, 0x41,
831  0x3d, 0x3e, 0x3c, 0x3e, 0x3b,
832  0x3a, 0x37, 0x3b, 0x3e, 0x41,
833  0x3c, 0x3b, 0x39, 0x3a, 0x36
834 };
835 
836 void
838 {
839  int i, j;
840 
841 /* reset, initialize required memory */
842  reset ();
843 
844  j = 10;
845 
846  for (i = 0; i < IN_END; i += 2)
847  {
848  compressed[i / 2] = encode (test_data[i], test_data[i + 1]);
849  }
850  for (i = 0; i < IN_END; i += 2)
851  {
852  decode (compressed[i / 2]);
853  result[i] = xout1;
854  result[i + 1] = xout2;
855  }
856 }
857 
858 int
860 {
861  int i;
862  int main_result;
863 
864  main_result = 0;
865  adpcm_main ();
866  for (i = 0; i < IN_END / 2; i++)
867  {
868  if (compressed[i] != test_compressed[i])
869  {
870  main_result += 1;
871  }
872  }
873  for (i = 0; i < IN_END; i++)
874  {
875  if (result[i] != test_result[i])
876  {
877  main_result += 1;
878  }
879  }
880  printf ("%d\n", main_result);
881  return main_result;
882  }
#define IN_END
Definition: adpcm.c:776
int szh
Definition: adpcm.c:189
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
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
#define SIZE
Definition: adpcm.c:775
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
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