From 386b7d3366f1359a265da207a9cafa3edf553b64 Mon Sep 17 00:00:00 2001 From: Joshua Bakita Date: Mon, 7 Oct 2019 19:13:39 -0400 Subject: Reorganize and commit all the modified TACLeBench code and run scripts --- all_pairs/source/adpcm_dec/ChangeLog.txt | 32 + all_pairs/source/adpcm_dec/adpcm_dec.c | 719 ++ all_pairs/source/adpcm_dec/timedTest.txt | 100 + all_pairs/source/adpcm_enc/ChangeLog.txt | 34 + all_pairs/source/adpcm_enc/adpcm_enc.c | 758 ++ all_pairs/source/ammunition/ChangeLog.txt | 66 + all_pairs/source/ammunition/README | 86 + all_pairs/source/ammunition/ammunition.c | 1185 ++ all_pairs/source/ammunition/ammunitionTimed.txt | 100 + all_pairs/source/ammunition/ammunition_libc.c | 166 + all_pairs/source/ammunition/ammunition_limits.h | 35 + all_pairs/source/ammunition/ammunition_stdio.h | 8 + all_pairs/source/ammunition/ammunition_stdlib.h | 6 + all_pairs/source/ammunition/ammunition_string.h | 18 + all_pairs/source/ammunition/arithm.c | 1384 ++ all_pairs/source/ammunition/arithm.h | 123 + all_pairs/source/ammunition/bits.c | 313 + all_pairs/source/ammunition/bits.h | 60 + all_pairs/source/ammunition/gmon.out | Bin 0 -> 31048 bytes all_pairs/source/ammunition/timeScript | 8 + all_pairs/source/anagram/ChangeLog.txt | 125 + all_pairs/source/anagram/anagram.c | 670 + all_pairs/source/anagram/anagramTest.txt | 100 + all_pairs/source/anagram/anagram_compare.h | 27 + all_pairs/source/anagram/anagram_ctype.h | 45 + all_pairs/source/anagram/anagram_input.c | 2317 ++++ all_pairs/source/anagram/anagram_stdlib.c | 153 + all_pairs/source/anagram/anagram_stdlib.h | 29 + all_pairs/source/anagram/anagram_strings.h | 27 + all_pairs/source/audiobeam/README | 86 + all_pairs/source/audiobeam/audiobeam.c | 594 + all_pairs/source/audiobeam/audiobeam.h | 50 + all_pairs/source/audiobeam/audiobeaminput.c | 5784 +++++++++ all_pairs/source/audiobeam/audiobeamlibm.c | 423 + all_pairs/source/audiobeam/audiobeamlibm.h | 59 + all_pairs/source/audiobeam/audiobeamlibmalloc.c | 14 + all_pairs/source/audiobeam/audiobeamlibmalloc.h | 27 + all_pairs/source/audiobeam/audiobeamlibmath.h | 69 + all_pairs/source/audiobeam/changeLog.txt | 36 + all_pairs/source/audiobeam/license.txt | 21 + all_pairs/source/cjpeg_transupp/ChangeLog.txt | 36 + all_pairs/source/cjpeg_transupp/README | 417 + all_pairs/source/cjpeg_transupp/cjpeg_transupp.c | 718 ++ all_pairs/source/cjpeg_transupp/jpeglib.h | 757 ++ all_pairs/source/cjpeg_wrbmp/ChangeLog.txt | 104 + all_pairs/source/cjpeg_wrbmp/README | 383 + all_pairs/source/cjpeg_wrbmp/cderror.h | 140 + all_pairs/source/cjpeg_wrbmp/cdjpeg.h | 105 + all_pairs/source/cjpeg_wrbmp/cjpeg_wrbmp.c | 225 + all_pairs/source/cjpeg_wrbmp/input.c | 79 + all_pairs/source/cjpeg_wrbmp/jconfig.h | 65 + all_pairs/source/cjpeg_wrbmp/jerror.h | 203 + all_pairs/source/cjpeg_wrbmp/jmorecfg.h | 95 + all_pairs/source/cjpeg_wrbmp/jpeglib.h | 869 ++ all_pairs/source/cleanupSemaphores.c | 10 + all_pairs/source/dijkstra/ChangeLog.txt | 44 + all_pairs/source/dijkstra/dijkstra.c | 204 + all_pairs/source/dijkstra/input.c | 105 + all_pairs/source/dijkstra/input.h | 8 + all_pairs/source/empty.c | 11 + all_pairs/source/epic/ChangeLog.txt | 56 + all_pairs/source/epic/epic.c | 1141 ++ all_pairs/source/epic/epic.h | 72 + all_pairs/source/extra.h | 197 + all_pairs/source/fmref/Changelog.txt | 5 + all_pairs/source/fmref/fmref.c | 283 + all_pairs/source/fmref/license.txt | 21 + all_pairs/source/fmref/math_private.h | 178 + all_pairs/source/fmref/wcclibm.c | 522 + all_pairs/source/fmref/wcclibm.h | 54 + all_pairs/source/g723_enc/ChangeLog.txt | 34 + all_pairs/source/g723_enc/g723_enc.c | 887 ++ all_pairs/source/g723_enc/license.txt | 23 + all_pairs/source/gsm_dec/COPYRIGHT | 16 + all_pairs/source/gsm_dec/ChangeLog.txt | 87 + all_pairs/source/gsm_dec/add.h | 55 + all_pairs/source/gsm_dec/data.h | 865 ++ all_pairs/source/gsm_dec/gsm.h | 14 + all_pairs/source/gsm_dec/gsm_dec.c | 764 ++ all_pairs/source/gsm_dec/private.h | 44 + all_pairs/source/gsm_enc/COPYRIGHT | 16 + all_pairs/source/gsm_enc/ChangeLog.txt | 8 + all_pairs/source/gsm_enc/data.h | 452 + all_pairs/source/gsm_enc/gsm_enc.c | 2072 +++ all_pairs/source/gsm_enc/private.h | 56 + all_pairs/source/h264_dec/changeLog.txt | 41 + all_pairs/source/h264_dec/copyright.txt | 32 + all_pairs/source/h264_dec/h264_dec.c | 610 + all_pairs/source/h264_dec/h264_dec.h | 29 + all_pairs/source/h264_dec/h264_decinput.c | 801 ++ all_pairs/source/huff_dec/ChangeLog.txt | 20 + all_pairs/source/huff_dec/compress.txt | 1107 ++ all_pairs/source/huff_dec/huff_dec.c | 393 + all_pairs/source/huff_enc/ChangeLog.txt | 27 + all_pairs/source/huff_enc/compress.txt | 1107 ++ all_pairs/source/huff_enc/huff_enc.c | 589 + all_pairs/source/mpeg2/ChangeLog.txt | 35 + all_pairs/source/mpeg2/mpeg2.c | 13218 ++++++++++++++++++++ all_pairs/source/ndes/ChangeLog.txt | 20 + all_pairs/source/ndes/ndes.c | 378 + all_pairs/source/petrinet/ChangeLog.txt | 63 + all_pairs/source/petrinet/petrinet.c | 990 ++ all_pairs/source/rijndael_dec/ChangeLog.txt | 58 + all_pairs/source/rijndael_dec/aes.c | 406 + all_pairs/source/rijndael_dec/aes.h | 165 + all_pairs/source/rijndael_dec/aestab.h | 379 + all_pairs/source/rijndael_dec/input_small_enc.c | 2051 +++ all_pairs/source/rijndael_dec/rijndael_dec.c | 195 + all_pairs/source/rijndael_dec/rijndael_dec_libc.c | 66 + all_pairs/source/rijndael_dec/rijndael_dec_libc.h | 24 + all_pairs/source/rijndael_enc/ChangeLog.txt | 98 + all_pairs/source/rijndael_enc/aes.c | 406 + all_pairs/source/rijndael_enc/aes.h | 165 + all_pairs/source/rijndael_enc/aestab.h | 261 + all_pairs/source/rijndael_enc/input_small.c | 1963 +++ all_pairs/source/rijndael_enc/rijndael_enc.c | 238 + all_pairs/source/rijndael_enc/rijndael_enc_libc.c | 66 + all_pairs/source/rijndael_enc/rijndael_enc_libc.h | 24 + all_pairs/source/statemate/ChangeLog.txt | 60 + all_pairs/source/statemate/statemate.c | 1286 ++ all_pairs/source/susan/ChangeLog.txt | 11 + all_pairs/source/susan/LICENSE | 14 + all_pairs/source/susan/input.c | 7292 +++++++++++ all_pairs/source/susan/math_private.h | 178 + all_pairs/source/susan/susan.c | 2014 +++ all_pairs/source/susan/wccfile.c | 79 + all_pairs/source/susan/wccfile.h | 24 + all_pairs/source/susan/wcclibm.c | 444 + all_pairs/source/susan/wcclibm.h | 53 + all_pairs/source/susan/wccmalloc.c | 51 + all_pairs/source/susan/wccmalloc.h | 10 + 131 files changed, 65898 insertions(+) create mode 100644 all_pairs/source/adpcm_dec/ChangeLog.txt create mode 100644 all_pairs/source/adpcm_dec/adpcm_dec.c create mode 100644 all_pairs/source/adpcm_dec/timedTest.txt create mode 100644 all_pairs/source/adpcm_enc/ChangeLog.txt create mode 100644 all_pairs/source/adpcm_enc/adpcm_enc.c create mode 100644 all_pairs/source/ammunition/ChangeLog.txt create mode 100644 all_pairs/source/ammunition/README create mode 100644 all_pairs/source/ammunition/ammunition.c create mode 100644 all_pairs/source/ammunition/ammunitionTimed.txt create mode 100644 all_pairs/source/ammunition/ammunition_libc.c create mode 100644 all_pairs/source/ammunition/ammunition_limits.h create mode 100644 all_pairs/source/ammunition/ammunition_stdio.h create mode 100644 all_pairs/source/ammunition/ammunition_stdlib.h create mode 100644 all_pairs/source/ammunition/ammunition_string.h create mode 100644 all_pairs/source/ammunition/arithm.c create mode 100644 all_pairs/source/ammunition/arithm.h create mode 100644 all_pairs/source/ammunition/bits.c create mode 100644 all_pairs/source/ammunition/bits.h create mode 100644 all_pairs/source/ammunition/gmon.out create mode 100644 all_pairs/source/ammunition/timeScript create mode 100644 all_pairs/source/anagram/ChangeLog.txt create mode 100644 all_pairs/source/anagram/anagram.c create mode 100644 all_pairs/source/anagram/anagramTest.txt create mode 100644 all_pairs/source/anagram/anagram_compare.h create mode 100644 all_pairs/source/anagram/anagram_ctype.h create mode 100644 all_pairs/source/anagram/anagram_input.c create mode 100644 all_pairs/source/anagram/anagram_stdlib.c create mode 100644 all_pairs/source/anagram/anagram_stdlib.h create mode 100644 all_pairs/source/anagram/anagram_strings.h create mode 100644 all_pairs/source/audiobeam/README create mode 100644 all_pairs/source/audiobeam/audiobeam.c create mode 100644 all_pairs/source/audiobeam/audiobeam.h create mode 100644 all_pairs/source/audiobeam/audiobeaminput.c create mode 100644 all_pairs/source/audiobeam/audiobeamlibm.c create mode 100644 all_pairs/source/audiobeam/audiobeamlibm.h create mode 100644 all_pairs/source/audiobeam/audiobeamlibmalloc.c create mode 100644 all_pairs/source/audiobeam/audiobeamlibmalloc.h create mode 100644 all_pairs/source/audiobeam/audiobeamlibmath.h create mode 100644 all_pairs/source/audiobeam/changeLog.txt create mode 100644 all_pairs/source/audiobeam/license.txt create mode 100644 all_pairs/source/cjpeg_transupp/ChangeLog.txt create mode 100644 all_pairs/source/cjpeg_transupp/README create mode 100644 all_pairs/source/cjpeg_transupp/cjpeg_transupp.c create mode 100644 all_pairs/source/cjpeg_transupp/jpeglib.h create mode 100644 all_pairs/source/cjpeg_wrbmp/ChangeLog.txt create mode 100644 all_pairs/source/cjpeg_wrbmp/README create mode 100644 all_pairs/source/cjpeg_wrbmp/cderror.h create mode 100644 all_pairs/source/cjpeg_wrbmp/cdjpeg.h create mode 100644 all_pairs/source/cjpeg_wrbmp/cjpeg_wrbmp.c create mode 100644 all_pairs/source/cjpeg_wrbmp/input.c create mode 100644 all_pairs/source/cjpeg_wrbmp/jconfig.h create mode 100644 all_pairs/source/cjpeg_wrbmp/jerror.h create mode 100644 all_pairs/source/cjpeg_wrbmp/jmorecfg.h create mode 100644 all_pairs/source/cjpeg_wrbmp/jpeglib.h create mode 100644 all_pairs/source/cleanupSemaphores.c create mode 100644 all_pairs/source/dijkstra/ChangeLog.txt create mode 100644 all_pairs/source/dijkstra/dijkstra.c create mode 100644 all_pairs/source/dijkstra/input.c create mode 100644 all_pairs/source/dijkstra/input.h create mode 100644 all_pairs/source/empty.c create mode 100644 all_pairs/source/epic/ChangeLog.txt create mode 100644 all_pairs/source/epic/epic.c create mode 100644 all_pairs/source/epic/epic.h create mode 100644 all_pairs/source/extra.h create mode 100644 all_pairs/source/fmref/Changelog.txt create mode 100644 all_pairs/source/fmref/fmref.c create mode 100644 all_pairs/source/fmref/license.txt create mode 100644 all_pairs/source/fmref/math_private.h create mode 100644 all_pairs/source/fmref/wcclibm.c create mode 100644 all_pairs/source/fmref/wcclibm.h create mode 100644 all_pairs/source/g723_enc/ChangeLog.txt create mode 100644 all_pairs/source/g723_enc/g723_enc.c create mode 100644 all_pairs/source/g723_enc/license.txt create mode 100644 all_pairs/source/gsm_dec/COPYRIGHT create mode 100644 all_pairs/source/gsm_dec/ChangeLog.txt create mode 100644 all_pairs/source/gsm_dec/add.h create mode 100644 all_pairs/source/gsm_dec/data.h create mode 100644 all_pairs/source/gsm_dec/gsm.h create mode 100644 all_pairs/source/gsm_dec/gsm_dec.c create mode 100644 all_pairs/source/gsm_dec/private.h create mode 100644 all_pairs/source/gsm_enc/COPYRIGHT create mode 100644 all_pairs/source/gsm_enc/ChangeLog.txt create mode 100644 all_pairs/source/gsm_enc/data.h create mode 100644 all_pairs/source/gsm_enc/gsm_enc.c create mode 100644 all_pairs/source/gsm_enc/private.h create mode 100644 all_pairs/source/h264_dec/changeLog.txt create mode 100644 all_pairs/source/h264_dec/copyright.txt create mode 100644 all_pairs/source/h264_dec/h264_dec.c create mode 100644 all_pairs/source/h264_dec/h264_dec.h create mode 100644 all_pairs/source/h264_dec/h264_decinput.c create mode 100644 all_pairs/source/huff_dec/ChangeLog.txt create mode 100644 all_pairs/source/huff_dec/compress.txt create mode 100644 all_pairs/source/huff_dec/huff_dec.c create mode 100644 all_pairs/source/huff_enc/ChangeLog.txt create mode 100644 all_pairs/source/huff_enc/compress.txt create mode 100644 all_pairs/source/huff_enc/huff_enc.c create mode 100644 all_pairs/source/mpeg2/ChangeLog.txt create mode 100644 all_pairs/source/mpeg2/mpeg2.c create mode 100644 all_pairs/source/ndes/ChangeLog.txt create mode 100644 all_pairs/source/ndes/ndes.c create mode 100644 all_pairs/source/petrinet/ChangeLog.txt create mode 100644 all_pairs/source/petrinet/petrinet.c create mode 100644 all_pairs/source/rijndael_dec/ChangeLog.txt create mode 100644 all_pairs/source/rijndael_dec/aes.c create mode 100644 all_pairs/source/rijndael_dec/aes.h create mode 100644 all_pairs/source/rijndael_dec/aestab.h create mode 100644 all_pairs/source/rijndael_dec/input_small_enc.c create mode 100644 all_pairs/source/rijndael_dec/rijndael_dec.c create mode 100644 all_pairs/source/rijndael_dec/rijndael_dec_libc.c create mode 100644 all_pairs/source/rijndael_dec/rijndael_dec_libc.h create mode 100644 all_pairs/source/rijndael_enc/ChangeLog.txt create mode 100644 all_pairs/source/rijndael_enc/aes.c create mode 100644 all_pairs/source/rijndael_enc/aes.h create mode 100644 all_pairs/source/rijndael_enc/aestab.h create mode 100644 all_pairs/source/rijndael_enc/input_small.c create mode 100644 all_pairs/source/rijndael_enc/rijndael_enc.c create mode 100644 all_pairs/source/rijndael_enc/rijndael_enc_libc.c create mode 100644 all_pairs/source/rijndael_enc/rijndael_enc_libc.h create mode 100644 all_pairs/source/statemate/ChangeLog.txt create mode 100644 all_pairs/source/statemate/statemate.c create mode 100644 all_pairs/source/susan/ChangeLog.txt create mode 100644 all_pairs/source/susan/LICENSE create mode 100644 all_pairs/source/susan/input.c create mode 100644 all_pairs/source/susan/math_private.h create mode 100644 all_pairs/source/susan/susan.c create mode 100644 all_pairs/source/susan/wccfile.c create mode 100644 all_pairs/source/susan/wccfile.h create mode 100644 all_pairs/source/susan/wcclibm.c create mode 100644 all_pairs/source/susan/wcclibm.h create mode 100644 all_pairs/source/susan/wccmalloc.c create mode 100644 all_pairs/source/susan/wccmalloc.h (limited to 'all_pairs/source') diff --git a/all_pairs/source/adpcm_dec/ChangeLog.txt b/all_pairs/source/adpcm_dec/ChangeLog.txt new file mode 100644 index 0000000..b9c4f96 --- /dev/null +++ b/all_pairs/source/adpcm_dec/ChangeLog.txt @@ -0,0 +1,32 @@ +File: minver.c +Original provenience: SNU-RT Benchmark Suite for Worst Case Timing Analysis + +2016-02-26: + - Added TACLeBench header to line 1 + - Rename global variable a to minver_a + - Rename global variable b to minver_b + - Rename global variable c to minver_c + - Rename global variable aa to minver_aa + - Rename global variable a_i to minver_a_i + - Rename global variable e to minver_e + - Rename global variable det to minver_det + - Renamed function minver to minver_minver + - Renamed function mmul to minver_mmul + - Renamed function fabs to minver_fabs + - Renamed function main to minver_main + - Created new function main, calling minver_init, minver_main and + returning minver_return + - Reordered functions in source code: initialization- and + return-value-related functions first, followed by algorithm core + functions, followed by main functions + - Applied code formatting with astyle as in the example + +2016-03-09: + - Removed static keyword for global variables + - Renamed global variables, prepended adpcm_dec + + 2016-05-23: + - Check sum added and checked against the expected value + + 2016-05-25: + - Corrected expected value \ No newline at end of file diff --git a/all_pairs/source/adpcm_dec/adpcm_dec.c b/all_pairs/source/adpcm_dec/adpcm_dec.c new file mode 100644 index 0000000..6811e69 --- /dev/null +++ b/all_pairs/source/adpcm_dec/adpcm_dec.c @@ -0,0 +1,719 @@ +/* + + This program is part of the TACLeBench benchmark suite. + Version V 1.x + + Name: adpcm_dec + + Author: Sung-Soo Lim + + Function: + CCITT G.722 ADPCM (Adaptive Differential Pulse Code Modulation) + algorithm. + 16khz sample rate data is stored in the array test_data[SIZE]. + Results are stored in the array compressed[SIZE] and result[SIZE]. + Execution time is determined by the constant SIZE (default value + is 2000). + + Source: SNU-RT Benchmark Suite + + Changes: adpcm benchmark was split into decode and encode benchmark + + License: may be used, modified, and re-distributed freely, but + the SNU-RT Benchmark Suite must be acknowledged + +*/ + +/* + This program is derived from the SNU-RT Benchmark Suite for Worst + Case Timing Analysis by Sung-Soo Lim + + Original source: C Algorithms for Real-Time DSP by P. M. Embree +*/ + +/* + Forward declaration of functions +*/ + +#include "../extra.h" + +void adpcm_dec_decode( int ); +int adpcm_dec_filtez( int *bpl, int *dlt ); +void adpcm_dec_upzero( int dlt, int *dlti, int *bli ); +int adpcm_dec_filtep( int rlt1, int al1, int rlt2, int al2 ); + +int adpcm_dec_logscl( int il, int nbl ); +int adpcm_dec_scalel( int nbl, int shift_constant ); +int adpcm_dec_uppol2( int al1, int al2, int plt, int plt1, int plt2 ); +int adpcm_dec_uppol1( int al1, int apl2, int plt, int plt1 ); + +int adpcm_dec_logsch( int ih, int nbh ); +void adpcm_dec_reset(); +int adpcm_dec_fabs( int n ); +int adpcm_dec_cos( int n ); +int adpcm_dec_sin( int n ); + +void adpcm_dec_init(); +int adpcm_dec_return(); +void adpcm_dec_main(); +//int main( void ); + + +/* + Declaration of macros +*/ +/* common sampling rate for sound cards on IBM/PC */ +#define SAMPLE_RATE 11025 +#define PI 3141 +#define SIZE 3 +#define IN_END 4 + +/* + Declaration of global variables +*/ + +int adpcm_dec_test_data[SIZE * 2], adpcm_dec_result[SIZE * 2]; + +/* Input data for the decoder usually generated by the encoder. */ +int adpcm_dec_compressed[SIZE] = { 0, 253, 32 }; + +/* G722 C code */ + +/* QMF filter coefficients: + scaled by a factor of 4 compared to G722 CCITT recommendation */ +int adpcm_dec_h[24] = { + 12, -44, -44, 212, 48, -624, 128, 1448, + -840, -3220, 3804, 15504, 15504, 3804, -3220, -840, + 1448, 128, -624, 48, 212, -44, -44, 12 +}; + +//int xl,xh; + +/* variables for receive quadrature mirror filter here */ +int adpcm_dec_accumc[11], adpcm_dec_accumd[11]; + +/* outputs of decode() */ +int adpcm_dec_xout1, adpcm_dec_xout2; + +int adpcm_dec_xs, adpcm_dec_xd; + +/* variables for encoder (hi and lo) here */ + +int adpcm_dec_il, adpcm_dec_szl, adpcm_dec_spl, adpcm_dec_sl, adpcm_dec_el; + +int adpcm_dec_qq4_code4_table[16] = { + 0, -20456, -12896, -8968, -6288, -4240, -2584, -1200, + 20456, 12896, 8968, 6288, 4240, 2584, 1200, 0 +}; + + +int adpcm_dec_qq6_code6_table[64] = { + -136, -136, -136, -136, -24808, -21904, -19008, -16704, + -14984, -13512, -12280, -11192, -10232, -9360, -8576, -7856, + -7192, -6576, -6000, -5456, -4944, -4464, -4008, -3576, + -3168, -2776, -2400, -2032, -1688, -1360, -1040, -728, + 24808, 21904, 19008, 16704, 14984, 13512, 12280, 11192, + 10232, 9360, 8576, 7856, 7192, 6576, 6000, 5456, + 4944, 4464, 4008, 3576, 3168, 2776, 2400, 2032, + 1688, 1360, 1040, 728, 432, 136, -432, -136 +}; + + +int adpcm_dec_wl_code_table[16] = { + -60, 3042, 1198, 538, 334, 172, 58, -30, + 3042, 1198, 538, 334, 172, 58, -30, -60 +}; + + +int adpcm_dec_ilb_table[32] = { + 2048, 2093, 2139, 2186, 2233, 2282, 2332, 2383, + 2435, 2489, 2543, 2599, 2656, 2714, 2774, 2834, + 2896, 2960, 3025, 3091, 3158, 3228, 3298, 3371, + 3444, 3520, 3597, 3676, 3756, 3838, 3922, 4008 +}; + +int adpcm_dec_nbl; /* delay line */ +int adpcm_dec_al1, adpcm_dec_al2; +int adpcm_dec_plt, adpcm_dec_plt1, adpcm_dec_plt2; +int adpcm_dec_rs; +int adpcm_dec_dlt; +int adpcm_dec_rlt, adpcm_dec_rlt1, adpcm_dec_rlt2; + + +int adpcm_dec_detl; + + +int adpcm_dec_deth; +int adpcm_dec_sh; /* this comes from adaptive predictor */ +int adpcm_dec_eh; + +int adpcm_dec_qq2_code2_table[4] = { + -7408, -1616, 7408, 1616 +}; + +int adpcm_dec_wh_code_table[4] = { + 798, -214, 798, -214 +}; + + +int adpcm_dec_dh, adpcm_dec_ih; +int adpcm_dec_nbh, adpcm_dec_szh; +int adpcm_dec_sph, adpcm_dec_ph, adpcm_dec_yh, adpcm_dec_rh; + +int adpcm_dec_delay_dhx[6]; + +int adpcm_dec_delay_bph[6]; + +int adpcm_dec_ah1, adpcm_dec_ah2; +int adpcm_dec_ph1, adpcm_dec_ph2; +int adpcm_dec_rh1, adpcm_dec_rh2; + +/* variables for decoder here */ +int adpcm_dec_ilr, adpcm_dec_yl, adpcm_dec_rl; +int adpcm_dec_dec_deth, adpcm_dec_dec_detl, adpcm_dec_dec_dlt; + +int adpcm_dec_dec_del_bpl[6]; + +int adpcm_dec_dec_del_dltx[6]; + +int adpcm_dec_dec_plt, adpcm_dec_dec_plt1, adpcm_dec_dec_plt2; +int adpcm_dec_dec_szl, adpcm_dec_dec_spl, adpcm_dec_dec_sl; +int adpcm_dec_dec_rlt1, adpcm_dec_dec_rlt2, adpcm_dec_dec_rlt; +int adpcm_dec_dec_al1, adpcm_dec_dec_al2; +int adpcm_dec_dl; +int adpcm_dec_dec_nbl, adpcm_dec_dec_yh, adpcm_dec_dec_dh, adpcm_dec_dec_nbh; + +/* variables used in filtez */ +int adpcm_dec_dec_del_bph[6]; + +int adpcm_dec_dec_del_dhx[6]; + +int adpcm_dec_dec_szh; +/* variables used in filtep */ +int adpcm_dec_dec_rh1, adpcm_dec_dec_rh2; +int adpcm_dec_dec_ah1, adpcm_dec_dec_ah2; +int adpcm_dec_dec_ph, adpcm_dec_dec_sph; + +int adpcm_dec_dec_sh, adpcm_dec_dec_rh; + +int adpcm_dec_dec_ph1, adpcm_dec_dec_ph2; + + +/* + Arithmetic math functions +*/ + + +/* MAX: 1 */ +int adpcm_dec_fabs( int n ) +{ + int f; + + + if ( n >= 0 ) + f = n; + else + f = -n; + + return f; +} + + +int adpcm_dec_sin( int rad ) +{ + int diff; + int app = 0; + int inc = 1; + + + /* MAX dependent on rad's value, say 50 */ + _Pragma( "loopbound min 0 max 0" ) + while ( rad > 2 * PI ) + rad -= 2 * PI; + + _Pragma( "loopbound min 0 max 1999" ) + while ( rad < -2 * PI ) + rad += 2 * PI; + + diff = rad; + app = diff; + diff = ( diff * ( -( rad * rad ) ) ) / ( ( 2 * inc ) * ( 2 * inc + 1 ) ); + app = app + diff; + inc++; + + /* REALLY: while(my_fabs(diff) >= 0.00001) { */ + /* MAX: 1000 */ + _Pragma( "loopbound min 849 max 2424" ) + while ( adpcm_dec_fabs( diff ) >= 1 ) { + diff = ( diff * ( -( rad * rad ) ) ) / ( ( 2 * inc ) * ( 2 * inc + 1 ) ); + app = app + diff; + inc++; + } + + return app; +} + + +int adpcm_dec_cos( int rad ) +{ + return ( adpcm_dec_sin( PI / 2 - rad ) ); +} + + +/* + Algorithm core functions +*/ + +/* decode function, result in xout1 and xout2 */ +void adpcm_dec_decode( int input ) +{ + int i; + long int xa1, xa2; /* qmf accumulators */ + int *h_ptr, *ac_ptr, *ac_ptr1, *ad_ptr, *ad_ptr1; + + + /* split transmitted word from input into ilr and ih */ + adpcm_dec_ilr = input & 0x3f; + adpcm_dec_ih = input >> 6; + + /* LOWER SUB_BAND DECODER */ + + /* filtez: compute predictor output for zero section */ + adpcm_dec_dec_szl = adpcm_dec_filtez( adpcm_dec_dec_del_bpl, + adpcm_dec_dec_del_dltx ); + + /* filtep: compute predictor output signal for pole section */ + adpcm_dec_dec_spl = adpcm_dec_filtep( adpcm_dec_dec_rlt1, adpcm_dec_dec_al1, + adpcm_dec_dec_rlt2, adpcm_dec_dec_al2 ); + + adpcm_dec_dec_sl = adpcm_dec_dec_spl + adpcm_dec_dec_szl; + + /* invqxl: compute quantized difference signal for adaptive predic */ + adpcm_dec_dec_dlt = ( ( long )adpcm_dec_dec_detl * + adpcm_dec_qq4_code4_table[adpcm_dec_ilr + >> 2] ) >> 15; + + /* invqxl: compute quantized difference signal for decoder output */ + adpcm_dec_dl = ( ( long )adpcm_dec_dec_detl * + adpcm_dec_qq6_code6_table[adpcm_dec_il] ) >> + 15; + + adpcm_dec_rl = adpcm_dec_dl + adpcm_dec_dec_sl; + + /* logscl: quantizer scale factor adaptation in the lower sub-band */ + adpcm_dec_dec_nbl = adpcm_dec_logscl( adpcm_dec_ilr, adpcm_dec_dec_nbl ); + + /* scalel: computes quantizer scale factor in the lower sub band */ + adpcm_dec_dec_detl = adpcm_dec_scalel( adpcm_dec_dec_nbl, 8 ); + + /* parrec - add pole predictor output to quantized diff. signal */ + /* for partially reconstructed signal */ + adpcm_dec_dec_plt = adpcm_dec_dec_dlt + adpcm_dec_dec_szl; + + /* upzero: update zero section predictor coefficients */ + adpcm_dec_upzero( adpcm_dec_dec_dlt, adpcm_dec_dec_del_dltx, + adpcm_dec_dec_del_bpl ); + + /* uppol2: update second predictor coefficient apl2 and delay it as al2 */ + adpcm_dec_dec_al2 = adpcm_dec_uppol2( adpcm_dec_dec_al1, adpcm_dec_dec_al2, + adpcm_dec_dec_plt, adpcm_dec_dec_plt1, + adpcm_dec_dec_plt2 ); + + /* uppol1: update first predictor coef. (pole setion) */ + adpcm_dec_dec_al1 = adpcm_dec_uppol1( adpcm_dec_dec_al1, adpcm_dec_dec_al2, + adpcm_dec_dec_plt, adpcm_dec_dec_plt1 ); + + /* recons : compute recontructed signal for adaptive predictor */ + adpcm_dec_dec_rlt = adpcm_dec_dec_sl + adpcm_dec_dec_dlt; + + /* done with lower sub band decoder, implement delays for next time */ + adpcm_dec_dec_rlt2 = adpcm_dec_dec_rlt1; + adpcm_dec_dec_rlt1 = adpcm_dec_dec_rlt; + adpcm_dec_dec_plt2 = adpcm_dec_dec_plt1; + adpcm_dec_dec_plt1 = adpcm_dec_dec_plt; + + /* HIGH SUB-BAND DECODER */ + + /* filtez: compute predictor output for zero section */ + adpcm_dec_dec_szh = adpcm_dec_filtez( adpcm_dec_dec_del_bph, + adpcm_dec_dec_del_dhx ); + + /* filtep: compute predictor output signal for pole section */ + adpcm_dec_dec_sph = adpcm_dec_filtep( adpcm_dec_dec_rh1, adpcm_dec_dec_ah1, + adpcm_dec_dec_rh2, adpcm_dec_dec_ah2 ); + + /* predic:compute the predictor output value in the higher sub_band decoder */ + adpcm_dec_dec_sh = adpcm_dec_dec_sph + adpcm_dec_dec_szh; + + /* invqah: in-place compute the quantized difference signal */ + adpcm_dec_dec_dh = ( ( long )adpcm_dec_dec_deth * + adpcm_dec_qq2_code2_table[adpcm_dec_ih] ) >> 15L ; + + /* logsch: update logarithmic quantizer scale factor in hi sub band */ + adpcm_dec_dec_nbh = adpcm_dec_logsch( adpcm_dec_ih, adpcm_dec_dec_nbh ); + + /* scalel: compute the quantizer scale factor in the higher sub band */ + adpcm_dec_dec_deth = adpcm_dec_scalel( adpcm_dec_dec_nbh, 10 ); + + /* parrec: compute partially recontructed signal */ + adpcm_dec_dec_ph = adpcm_dec_dec_dh + adpcm_dec_dec_szh; + + /* upzero: update zero section predictor coefficients */ + adpcm_dec_upzero( adpcm_dec_dec_dh, adpcm_dec_dec_del_dhx, + adpcm_dec_dec_del_bph ); + + /* uppol2: update second predictor coefficient aph2 and delay it as ah2 */ + adpcm_dec_dec_ah2 = adpcm_dec_uppol2( adpcm_dec_dec_ah1, adpcm_dec_dec_ah2, + adpcm_dec_dec_ph, adpcm_dec_dec_ph1, adpcm_dec_dec_ph2 ); + + /* uppol1: update first predictor coef. (pole setion) */ + adpcm_dec_dec_ah1 = adpcm_dec_uppol1( adpcm_dec_dec_ah1, adpcm_dec_dec_ah2, + adpcm_dec_dec_ph, adpcm_dec_dec_ph1 ); + + /* recons : compute recontructed signal for adaptive predictor */ + adpcm_dec_rh = adpcm_dec_dec_sh + adpcm_dec_dec_dh; + + /* done with high band decode, implementing delays for next time here */ + adpcm_dec_dec_rh2 = adpcm_dec_dec_rh1; + adpcm_dec_dec_rh1 = adpcm_dec_rh; + adpcm_dec_dec_ph2 = adpcm_dec_dec_ph1; + adpcm_dec_dec_ph1 = adpcm_dec_dec_ph; + + /* end of higher sub_band decoder */ + + /* end with receive quadrature mirror filters */ + adpcm_dec_xd = adpcm_dec_rl - adpcm_dec_rh; + adpcm_dec_xs = adpcm_dec_rl + adpcm_dec_rh; + + /* receive quadrature mirror filters implemented here */ + h_ptr = adpcm_dec_h; + ac_ptr = adpcm_dec_accumc; + ad_ptr = adpcm_dec_accumd; + xa1 = ( long ) adpcm_dec_xd * ( *h_ptr++ ); + xa2 = ( long ) adpcm_dec_xs * ( *h_ptr++ ); + + /* main multiply accumulate loop for samples and coefficients */ + _Pragma( "loopbound min 10 max 10" ) + for ( i = 0; i < 10; i++ ) { + xa1 += ( long )( *ac_ptr++ ) * ( *h_ptr++ ); + xa2 += ( long )( *ad_ptr++ ) * ( *h_ptr++ ); + } + + /* final mult/accumulate */ + xa1 += ( long )( *ac_ptr ) * ( *h_ptr++ ); + xa2 += ( long )( *ad_ptr ) * ( *h_ptr++ ); + + /* scale by 2^14 */ + adpcm_dec_xout1 = xa1 >> 14; + adpcm_dec_xout2 = xa2 >> 14; + + /* update delay lines */ + ac_ptr1 = ac_ptr - 1; + ad_ptr1 = ad_ptr - 1; + + _Pragma( "loopbound min 10 max 10" ) + for ( i = 0; i < 10; i++ ) { + *ac_ptr-- = *ac_ptr1--; + *ad_ptr-- = *ad_ptr1--; + } + + *ac_ptr = adpcm_dec_xd; + *ad_ptr = adpcm_dec_xs; + + return; +} + + +/* filtez - compute predictor output signal (zero section) */ +/* input: bpl1-6 and dlt1-6, output: szl */ +int adpcm_dec_filtez( int *bpl, int *dlt ) +{ + int i; + long int zl; + + + zl = ( long )( *bpl++ ) * ( *dlt++ ); + + /* MAX: 5 */ + _Pragma( "loopbound min 5 max 5" ) + for ( i = 1; i < 6; i++ ) + zl += ( long )( *bpl++ ) * ( *dlt++ ); + + return ( ( int )( zl >> 14 ) ); /* x2 here */ +} + + +/* filtep - compute predictor output signal (pole section) */ +/* input rlt1-2 and al1-2, output spl */ +int adpcm_dec_filtep( int rlt1, int al1, int rlt2, int al2 ) +{ + long int pl, pl2; + + + pl = 2 * rlt1; + pl = ( long ) al1 * pl; + pl2 = 2 * rlt2; + pl += ( long ) al2 * pl2; + + return ( ( int )( pl >> 15 ) ); +} + + +/* logscl - update log quantizer scale factor in lower sub-band */ +/* note that nbl is passed and returned */ +int adpcm_dec_logscl( int il, int nbl ) +{ + long int wd; + + + wd = ( ( long )nbl * 127L ) >> 7L; /* leak factor 127/128 */ + nbl = ( int )wd + adpcm_dec_wl_code_table[il >> 2]; + + if ( nbl < 0 ) + nbl = 0; + if ( nbl > 18432 ) + nbl = 18432; + + return ( nbl ); +} + + +/* scalel: compute quantizer scale factor in lower or upper sub-band*/ +int adpcm_dec_scalel( int nbl, int shift_constant ) +{ + int wd1, wd2, wd3; + + + wd1 = ( nbl >> 6 ) & 31; + wd2 = nbl >> 11; + wd3 = adpcm_dec_ilb_table[wd1] >> ( shift_constant + 1 - wd2 ); + + return ( wd3 << 3 ); +} + + +/* upzero - inputs: dlt, dlti[0-5], bli[0-5], outputs: updated bli[0-5] */ +/* also implements delay of bli and update of dlti from dlt */ +void adpcm_dec_upzero( int dlt, int *dlti, int *bli ) +{ + int i, wd2, wd3; + + + /*if dlt is zero, then no sum into bli */ + if ( dlt == 0 ) { + _Pragma( "loopbound min 6 max 6" ) + for ( i = 0; i < 6; i++ ) { + bli[i] = ( int )( ( 255L * bli[i] ) >> 8L ); /* leak factor of 255/256 */ + } + + } else { + _Pragma( "loopbound min 6 max 6" ) + for ( i = 0; i < 6; i++ ) { + if ( ( long )dlt * dlti[i] >= 0 ) + wd2 = 128; + else + wd2 = -128; + + wd3 = ( int )( ( 255L * bli[i] ) >> 8L ); /* leak factor of 255/256 */ + bli[i] = wd2 + wd3; + } + + } + + /* implement delay line for dlt */ + dlti[5] = dlti[4]; + dlti[4] = dlti[3]; + dlti[3] = dlti[2]; + dlti[1] = dlti[0]; + dlti[0] = dlt; + + return; +} + + +/* uppol2 - update second predictor coefficient (pole section) */ +/* inputs: al1, al2, plt, plt1, plt2. outputs: apl2 */ +int adpcm_dec_uppol2( int al1, int al2, int plt, int plt1, int plt2 ) +{ + long int wd2, wd4; + int apl2; + + + wd2 = 4L * ( long )al1; + if ( ( long )plt * plt1 >= 0L ) + wd2 = -wd2; /* check same sign */ + wd2 = wd2 >> 7; /* gain of 1/128 */ + + if ( ( long )plt * plt2 >= 0L ) { + wd4 = wd2 + 128; /* same sign case */ + } else + wd4 = wd2 - 128; + apl2 = wd4 + ( 127L * ( long )al2 >> 7L ); /* leak factor of 127/128 */ + + /* apl2 is limited to +-.75 */ + if ( apl2 > 12288 ) + apl2 = 12288; + if ( apl2 < -12288 ) + apl2 = -12288; + + return ( apl2 ); +} + + +/* uppol1 - update first predictor coefficient (pole section) */ +/* inputs: al1, apl2, plt, plt1. outputs: apl1 */ +int adpcm_dec_uppol1( int al1, int apl2, int plt, int plt1 ) +{ + long int wd2; + int wd3, apl1; + + + wd2 = ( ( long )al1 * 255L ) >> 8L; /* leak factor of 255/256 */ + if ( ( long )plt * plt1 >= 0L ) { + apl1 = ( int )wd2 + 192; /* same sign case */ + } else + apl1 = ( int )wd2 - 192; + + /* note: wd3= .9375-.75 is always positive */ + wd3 = 15360 - apl2; /* limit value */ + if ( apl1 > wd3 ) + apl1 = wd3; + if ( apl1 < -wd3 ) + apl1 = -wd3; + + return ( apl1 ); +} + + +/* logsch - update log quantizer scale factor in higher sub-band */ +/* note that nbh is passed and returned */ +int adpcm_dec_logsch( int ih, int nbh ) +{ + int wd; + + + wd = ( ( long )nbh * 127L ) >> 7L; /* leak factor 127/128 */ + nbh = wd + adpcm_dec_wh_code_table[ih]; + + if ( nbh < 0 ) + nbh = 0; + if ( nbh > 22528 ) + nbh = 22528; + + return ( nbh ); +} + +/* + Initialization- and return-value-related functions +*/ + +/* clear all storage locations */ + +void adpcm_dec_reset() +{ + int i; + + + adpcm_dec_detl = adpcm_dec_dec_detl = 32; /* reset to min scale factor */ + adpcm_dec_deth = adpcm_dec_dec_deth = 8; + adpcm_dec_nbl = adpcm_dec_al1 = adpcm_dec_al2 = adpcm_dec_plt1 = adpcm_dec_plt2 + = adpcm_dec_rlt1 = adpcm_dec_rlt2 = 0; + adpcm_dec_nbh = adpcm_dec_ah1 = adpcm_dec_ah2 = adpcm_dec_ph1 = adpcm_dec_ph2 = + adpcm_dec_rh1 = adpcm_dec_rh2 = 0; + adpcm_dec_dec_nbl = adpcm_dec_dec_al1 = adpcm_dec_dec_al2 = adpcm_dec_dec_plt1 = + adpcm_dec_dec_plt2 = adpcm_dec_dec_rlt1 = adpcm_dec_dec_rlt2 = 0; + adpcm_dec_dec_nbh = adpcm_dec_dec_ah1 = adpcm_dec_dec_ah2 = adpcm_dec_dec_ph1 = + adpcm_dec_dec_ph2 = adpcm_dec_dec_rh1 = adpcm_dec_dec_rh2 = 0; + + _Pragma( "loopbound min 6 max 6" ) + for ( i = 0; i < 6; i++ ) { + ////delay_dltx[i] = 0; + adpcm_dec_delay_dhx[i] = 0; + adpcm_dec_dec_del_dltx[i] = 0; + adpcm_dec_dec_del_dhx[i] = 0; + } + + _Pragma( "loopbound min 6 max 6" ) + for ( i = 0; i < 6; i++ ) { + //delay_bpl[i] = 0; + adpcm_dec_delay_bph[i] = 0; + adpcm_dec_dec_del_bpl[i] = 0; + adpcm_dec_dec_del_bph[i] = 0; + } + + _Pragma( "loopbound min 11 max 11" ) + for ( i = 0; i < 11; i++ ) { + adpcm_dec_accumc[i] = 0; + adpcm_dec_accumd[i] = 0; + } + + return; +} + +void adpcm_dec_init() +{ + int i, j, f; + volatile int x = 0; + /* read in amplitude and frequency for test data */ + j = 10; + f = 2000; + + /* reset, initialize required memory */ + adpcm_dec_reset(); + + /* 16 KHz sample rate */ + /* XXmain_0, MAX: 2 */ + /* Since the number of times we loop in adpcm_dec_sin depends on the + argument we add the fact: xxmain_0:[]: */ + _Pragma( "loopbound min 3 max 3" ) + for ( i = 0 ; i < SIZE ; i++ ) { + adpcm_dec_test_data[i] = ( int ) j * adpcm_dec_cos( f * PI * i ); + + /* avoid constant-propagation optimizations */ + adpcm_dec_test_data[i] += x; + } +} + +int adpcm_dec_return() +{ + int i; + int check_sum = 0; + + for (i = 0; i < IN_END; i += 2) + { + check_sum += ( adpcm_dec_result[i] + adpcm_dec_result[i + 1] ); + } + + return check_sum != -2; +} + +/* + Main functions +*/ + +void _Pragma( "entrypoint" ) adpcm_dec_main( void ) +{ + int i; + + _Pragma( "loopbound min 2 max 2" ) + for ( i = 0 ; i < IN_END ; i += 2 ) { + adpcm_dec_decode( adpcm_dec_compressed[i / 2] ); + adpcm_dec_result[i] = adpcm_dec_xout1; + adpcm_dec_result[i + 1] = adpcm_dec_xout2; + } + +} + + +int main(int argc, char **argv) +{ + SET_UP + for (jobsComplete=-1; jobsComplete + + Original name: adpcm_encoder + + Changes: no major functional changes + + License: may be used, modified, and re-distributed freely, but the + SNU-RT Benchmark Suite must be acknowledged + +*/ + + +/* common sampling rate for sound cards on IBM/PC */ + +#include "../extra.h" +#define SAMPLE_RATE 11025 + +#define PI 3141 +#define SIZE 3 +#define IN_END 4 + + +/* + Forward declaration of functions +*/ + +int adpcm_enc_encode( int, int ); +int adpcm_enc_filtez( int *bpl, int *dlt ); +void adpcm_enc_upzero( int dlt, int *dlti, int *bli ); +int adpcm_enc_filtep( int rlt1, int al1, int rlt2, int al2 ); +int adpcm_enc_quantl( int el, int detl ); +int adpcm_enc_logscl( int il, int nbl ); +int adpcm_enc_scalel( int nbl, int shift_constant ); +int adpcm_enc_uppol2( int al1, int al2, int plt, int plt1, int plt2 ); +int adpcm_enc_uppol1( int al1, int apl2, int plt, int plt1 ); +int adpcm_enc_logsch( int ih, int nbh ); +void adpcm_enc_reset(); +int adpcm_enc_fabs( int n ); +int adpcm_enc_cos( int n ); +int adpcm_enc_sin( int n ); +int adpcm_enc_abs( int n ); +void adpcm_enc_init(void); +void adpcm_enc_main(void); +int adpcm_enc_return(void); +//int main(void); + +/* + Forward declaration of global variables +*/ + +int adpcm_enc_test_data[SIZE * 2], adpcm_enc_compressed[SIZE]; + + +/* G722 C code */ + +/* variables for transimit quadrature mirror filter here */ +int adpcm_enc_tqmf[24]; + +/* QMF filter coefficients: +scaled by a factor of 4 compared to G722 CCITT recommendation */ +int adpcm_enc_h[24] = { + 12, -44, -44, 212, 48, -624, 128, 1448, + -840, -3220, 3804, 15504, 15504, 3804, -3220, -840, + 1448, 128, -624, 48, 212, -44, -44, 12 +}; + +int adpcm_enc_xl, adpcm_enc_xh; + +/* variables for encoder (hi and lo) here */ + +int adpcm_enc_il, adpcm_enc_szl, adpcm_enc_spl, adpcm_enc_sl, adpcm_enc_el; + +int adpcm_enc_qq4_code4_table[16] = { + 0, -20456, -12896, -8968, -6288, -4240, -2584, -1200, + 20456, 12896, 8968, 6288, 4240, 2584, 1200, 0 +}; + +int adpcm_enc_qq5_code5_table[32] = { + -280, -280, -23352, -17560, -14120, -11664, -9752, -8184, + -6864, -5712, -4696, -3784, -2960, -2208, -1520, -880, + 23352, 17560, 14120, 11664, 9752, 8184, 6864, 5712, + 4696, 3784, 2960, 2208, 1520, 880, 280, -280 +}; + +int adpcm_enc_qq6_code6_table[64] = { + -136, -136, -136, -136, -24808, -21904, -19008, -16704, +-14984, -13512, -12280, -11192, -10232, -9360, -8576, -7856, + -7192, -6576, -6000, -5456, -4944, -4464, -4008, -3576, + -3168, -2776, -2400, -2032, -1688, -1360, -1040, -728, + 24808, 21904, 19008, 16704, 14984, 13512, 12280, 11192, + 10232, 9360, 8576, 7856, 7192, 6576, 6000, 5456, + 4944, 4464, 4008, 3576, 3168, 2776, 2400, 2032, + 1688, 1360, 1040, 728, 432, 136, -432, -136 +}; + +int adpcm_enc_delay_bpl[6]; + +int adpcm_enc_delay_dltx[6]; + +int adpcm_enc_wl_code_table[16] = { + -60, 3042, 1198, 538, 334, 172, 58, -30, + 3042, 1198, 538, 334, 172, 58, -30, -60 +}; + +int adpcm_enc_ilb_table[32] = { + 2048, 2093, 2139, 2186, 2233, 2282, 2332, 2383, + 2435, 2489, 2543, 2599, 2656, 2714, 2774, 2834, + 2896, 2960, 3025, 3091, 3158, 3228, 3298, 3371, + 3444, 3520, 3597, 3676, 3756, 3838, 3922, 4008 +}; + +int adpcm_enc_nbl; /* delay line */ +int adpcm_enc_al1, adpcm_enc_al2; +int adpcm_enc_plt, adpcm_enc_plt1, adpcm_enc_plt2; +int adpcm_enc_dlt; +int adpcm_enc_rlt, adpcm_enc_rlt1, adpcm_enc_rlt2; + +/* decision levels - pre-multiplied by 8, 0 to indicate end */ +int adpcm_enc_decis_levl[30] = { + 280, 576, 880, 1200, 1520, 1864, 2208, 2584, + 2960, 3376, 3784, 4240, 4696, 5200, 5712, 6288, + 6864, 7520, 8184, 8968, 9752, 10712, 11664, 12896, + 14120, 15840, 17560, 20456, 23352, 32767 +}; + +int adpcm_enc_detl; + +/* quantization table 31 long to make quantl look-up easier, +last entry is for mil=30 case when wd is max */ +int adpcm_enc_quant26bt_pos[31] = { + 61, 60, 59, 58, 57, 56, 55, 54, + 53, 52, 51, 50, 49, 48, 47, 46, + 45, 44, 43, 42, 41, 40, 39, 38, + 37, 36, 35, 34, 33, 32, 32 +}; + +/* quantization table 31 long to make quantl look-up easier, +last entry is for mil=30 case when wd is max */ +int adpcm_enc_quant26bt_neg[31] = { + 63, 62, 31, 30, 29, 28, 27, 26, + 25, 24, 23, 22, 21, 20, 19, 18, + 17, 16, 15, 14, 13, 12, 11, 10, + 9, 8, 7, 6, 5, 4, 4 +}; + + +int adpcm_enc_deth; +int adpcm_enc_sh; /* this comes from adaptive predictor */ +int adpcm_enc_eh; + +int adpcm_enc_qq2_code2_table[4] = { + -7408, -1616, 7408, 1616 +}; + +int adpcm_enc_wh_code_table[4] = { + 798, -214, 798, -214 +}; + + +int adpcm_enc_dh, adpcm_enc_ih; +int adpcm_enc_nbh, adpcm_enc_szh; +int adpcm_enc_sph, adpcm_enc_ph, adpcm_enc_yh; + +int adpcm_enc_delay_dhx[6]; +int adpcm_enc_delay_bph[6]; + +int adpcm_enc_ah1, adpcm_enc_ah2; +int adpcm_enc_ph1, adpcm_enc_ph2; +int adpcm_enc_rh1, adpcm_enc_rh2; + + +/* G722 encode function two ints in, one 8 bit output */ + +/* put input samples in xin1 = first value, xin2 = second value */ +/* returns il and ih stored together */ + + +/* MAX: 1 */ +int adpcm_enc_abs( int n ) +{ + int m; + + + if ( n >= 0 ) + m = n; + else + m = -n; + + return m; +} + + +/* MAX: 1 */ +int adpcm_enc_fabs( int n ) +{ + int f; + + + if ( n >= 0 ) + f = n; + else + f = -n; + + return f; +} + + +int adpcm_enc_sin( int rad ) +{ + int diff; + int app = 0; + int inc = 1; + + + /* MAX dependent on rad's value, say 50 */ + _Pragma("loopbound min 0 max 0") + while ( rad > 2 * PI ) { + rad -= 2 * PI; + } + + /* MAX dependent on rad's value, say 50 */ + _Pragma("loopbound min 0 max 1999") + while ( rad < -2 * PI ) { + rad += 2 * PI; + } + + diff = rad; + app = diff; + diff = (diff * (-(rad*rad))) / ((2 * inc) * (2 * inc + 1)); + app = app + diff; + inc++; + + /* REALLY: while(my_fabs(diff) >= 0.00001) { */ + /* MAX: 1000 */ + _Pragma("loopbound min 849 max 2424") + while ( adpcm_enc_fabs( diff ) >= 1 ) { + diff = (diff * (-(rad*rad))) / ((2 * inc) * (2 * inc + 1)); + app = app + diff; + inc++; + } + + return app; +} + + +int adpcm_enc_cos( int rad ) +{ + return( adpcm_enc_sin( PI / 2 - rad ) ); +} + + +/* MAX: 1 */ +int adpcm_enc_encode( int xin1, int xin2 ) +{ + int i; + int *h_ptr, *tqmf_ptr, *tqmf_ptr1; + long int xa, xb; + int decis; + + + /* transmit quadrature mirror filters implemented here */ + h_ptr = adpcm_enc_h; + tqmf_ptr = adpcm_enc_tqmf; + xa = (long)(*tqmf_ptr++) * (*h_ptr++); + xb = (long)(*tqmf_ptr++) * (*h_ptr++); + + /* main multiply accumulate loop for samples and coefficients */ + /* MAX: 10 */ + _Pragma("loopbound min 10 max 10") + for ( i = 0; i < 10; i++ ) { + xa += (long)(*tqmf_ptr++) * (*h_ptr++); + xb += (long)(*tqmf_ptr++) * (*h_ptr++); + } + + /* final mult/accumulate */ + xa += (long)(*tqmf_ptr++) * (*h_ptr++); + xb += (long)(*tqmf_ptr) * (*h_ptr++); + + /* update delay line tqmf */ + tqmf_ptr1 = tqmf_ptr - 2; + /* MAX: 22 */ + _Pragma("loopbound min 22 max 22") + for ( i = 0; i < 22; i++ ) { + *tqmf_ptr-- = *tqmf_ptr1--; + } + + *tqmf_ptr-- = xin1; + *tqmf_ptr = xin2; + + /* scale outputs */ + adpcm_enc_xl = (xa + xb) >> 15; + adpcm_enc_xh = (xa - xb) >> 15; + + /* end of quadrature mirror filter code */ + + /* starting with lower sub band encoder */ + + /* filtez - compute predictor output section - zero section */ + adpcm_enc_szl = adpcm_enc_filtez( adpcm_enc_delay_bpl, adpcm_enc_delay_dltx ); + + /* filtep - compute predictor output signal (pole section) */ + adpcm_enc_spl = adpcm_enc_filtep( adpcm_enc_rlt1, adpcm_enc_al1, adpcm_enc_rlt2, adpcm_enc_al2 ); + + /* compute the predictor output value in the lower sub_band encoder */ + adpcm_enc_sl = adpcm_enc_szl + adpcm_enc_spl; + adpcm_enc_el = adpcm_enc_xl - adpcm_enc_sl; + + /* quantl: quantize the difference signal */ + adpcm_enc_il = adpcm_enc_quantl( adpcm_enc_el, adpcm_enc_detl ); + + /* invqxl: computes quantized difference signal */ + /* for invqbl, truncate by 2 lsbs, so mode = 3 */ + adpcm_enc_dlt = ( (long) adpcm_enc_detl * adpcm_enc_qq4_code4_table[adpcm_enc_il >> 2] ) >> 15; + + /* logscl: updates logarithmic quant. scale factor in low sub band */ + adpcm_enc_nbl = adpcm_enc_logscl( adpcm_enc_il, adpcm_enc_nbl ); + + /* scalel: compute the quantizer scale factor in the lower sub band */ + /* calling parameters nbl and 8 (constant such that scalel can be scaleh) */ + adpcm_enc_detl = adpcm_enc_scalel( adpcm_enc_nbl, 8 ); + + /* parrec - simple addition to compute recontructed signal for adaptive pred */ + adpcm_enc_plt = adpcm_enc_dlt + adpcm_enc_szl; + + /* upzero: update zero section predictor coefficients (sixth order)*/ + /* calling parameters: dlt, dlt1, dlt2, ..., dlt6 from dlt */ + /* bpli (linear_buffer in which all six values are delayed */ + /* return params: updated bpli, delayed dltx */ + adpcm_enc_upzero( adpcm_enc_dlt, adpcm_enc_delay_dltx, adpcm_enc_delay_bpl ); + + /* uppol2- update second predictor coefficient apl2 and delay it as al2 */ + /* calling parameters: al1, al2, plt, plt1, plt2 */ + adpcm_enc_al2 = adpcm_enc_uppol2( adpcm_enc_al1, adpcm_enc_al2, adpcm_enc_plt, adpcm_enc_plt1, adpcm_enc_plt2 ); + + /* uppol1 :update first predictor coefficient apl1 and delay it as al1 */ + /* calling parameters: al1, apl2, plt, plt1 */ + adpcm_enc_al1 = adpcm_enc_uppol1( adpcm_enc_al1, adpcm_enc_al2, adpcm_enc_plt, adpcm_enc_plt1); + + /* recons : compute recontructed signal for adaptive predictor */ + adpcm_enc_rlt = adpcm_enc_sl + adpcm_enc_dlt; + + /* done with lower sub_band encoder; now implement delays for next time*/ + adpcm_enc_rlt2 = adpcm_enc_rlt1; + adpcm_enc_rlt1 = adpcm_enc_rlt; + adpcm_enc_plt2 = adpcm_enc_plt1; + adpcm_enc_plt1 = adpcm_enc_plt; + + /* high band encode */ + + adpcm_enc_szh = adpcm_enc_filtez( adpcm_enc_delay_bph, adpcm_enc_delay_dhx ); + + adpcm_enc_sph = adpcm_enc_filtep( adpcm_enc_rh1, adpcm_enc_ah1, adpcm_enc_rh2, adpcm_enc_ah2 ); + + /* predic: sh = sph + szh */ + adpcm_enc_sh = adpcm_enc_sph + adpcm_enc_szh; + /* subtra: eh = xh - sh */ + adpcm_enc_eh = adpcm_enc_xh - adpcm_enc_sh; + + /* quanth - quantization of difference signal for higher sub-band */ + /* quanth: in-place for speed params: eh, deth (has init. value) */ + if ( adpcm_enc_eh >= 0 ) + adpcm_enc_ih = 3; /* 2,3 are pos codes */ + else + adpcm_enc_ih = 1; /* 0,1 are neg codes */ + + decis = ( 564L * (long)adpcm_enc_deth ) >> 12L; + if ( adpcm_enc_abs( adpcm_enc_eh ) > decis ) + adpcm_enc_ih--; /* mih = 2 case */ + + /* invqah: compute the quantized difference signal, higher sub-band*/ + adpcm_enc_dh = ( (long)adpcm_enc_deth * adpcm_enc_qq2_code2_table[adpcm_enc_ih] ) >> 15L ; + + /* logsch: update logarithmic quantizer scale factor in hi sub-band*/ + adpcm_enc_nbh = adpcm_enc_logsch( adpcm_enc_ih, adpcm_enc_nbh ); + + /* note : scalel and scaleh use same code, different parameters */ + adpcm_enc_deth = adpcm_enc_scalel( adpcm_enc_nbh, 10 ); + + /* parrec - add pole predictor output to quantized diff. signal */ + adpcm_enc_ph = adpcm_enc_dh + adpcm_enc_szh; + + /* upzero: update zero section predictor coefficients (sixth order) */ + /* calling parameters: dh, dhi, bphi */ + /* return params: updated bphi, delayed dhx */ + adpcm_enc_upzero( adpcm_enc_dh, adpcm_enc_delay_dhx, adpcm_enc_delay_bph ); + + /* uppol2: update second predictor coef aph2 and delay as ah2 */ + /* calling params: ah1, ah2, ph, ph1, ph2 */ + adpcm_enc_ah2 = adpcm_enc_uppol2( adpcm_enc_ah1, adpcm_enc_ah2, adpcm_enc_ph, adpcm_enc_ph1, adpcm_enc_ph2 ); + + /* uppol1: update first predictor coef. aph2 and delay it as ah1 */ + adpcm_enc_ah1 = adpcm_enc_uppol1( adpcm_enc_ah1, adpcm_enc_ah2, adpcm_enc_ph, adpcm_enc_ph1 ); + + /* recons for higher sub-band */ + adpcm_enc_yh = adpcm_enc_sh + adpcm_enc_dh; + + /* done with higher sub-band encoder, now Delay for next time */ + adpcm_enc_rh2 = adpcm_enc_rh1; + adpcm_enc_rh1 = adpcm_enc_yh; + adpcm_enc_ph2 = adpcm_enc_ph1; + adpcm_enc_ph1 = adpcm_enc_ph; + + /* multiplex ih and il to get signals together */ + return( adpcm_enc_il | (adpcm_enc_ih << 6) ); +} + + +/* filtez - compute predictor output signal (zero section) */ +/* input: bpl1-6 and dlt1-6, output: szl */ +int adpcm_enc_filtez( int *bpl, int *dlt ) +{ + int i; + long int zl; + + + zl = (long)(*bpl++) * (*dlt++); + + /* MAX: 5 */ + _Pragma("loopbound min 5 max 5") + for ( i = 1; i < 6; i++ ) { + zl += (long)(*bpl++) * (*dlt++); + } + + return( (int)(zl >> 14) ); /* x2 here */ +} + + +/* filtep - compute predictor output signal (pole section) */ +/* input rlt1-2 and al1-2, output spl */ +int adpcm_enc_filtep( int rlt1, int al1, int rlt2, int al2 ) +{ + long int pl, pl2; + + + pl = 2 * rlt1; + pl = (long) al1 * pl; + pl2 = 2 * rlt2; + pl += (long) al2 * pl2; + + return( (int)(pl >> 15) ); +} + + +/* quantl - quantize the difference signal in the lower sub-band */ +int adpcm_enc_quantl( int el, int detl ) +{ + int ril, mil; + long int wd, decis; + + + /* abs of difference signal */ + wd = adpcm_enc_abs( el ); + + /* determine mil based on decision levels and detl gain */ + /* MAX: 30 */ + _Pragma("loopbound min 1 max 30") + for ( mil = 0; mil < 30; mil++ ) { + decis = (adpcm_enc_decis_levl[mil] * (long)detl) >> 15L; + if ( wd <= decis ) + break; + } + + /* if mil=30 then wd is less than all decision levels */ + if ( el >= 0 ) + ril = adpcm_enc_quant26bt_pos[mil]; + else + ril = adpcm_enc_quant26bt_neg[mil]; + + return( ril ); +} + + +/* invqxl is either invqbl or invqal depending on parameters passed */ +/* returns dlt, code table is pre-multiplied by 8 */ + +/* int invqxl(int il,int detl,int *code_table,int mode) */ +/* { */ +/* long int dlt; */ +/* dlt = (long)detl*code_table[il >> (mode-1)]; */ +/* return((int)(dlt >> 15)); */ +/* } */ + +/* logscl - update log quantizer scale factor in lower sub-band */ +/* note that nbl is passed and returned */ +int adpcm_enc_logscl( int il, int nbl ) +{ + long int wd; + + + wd = ((long)nbl * 127L) >> 7L; /* leak factor 127/128 */ + nbl = (int)wd + adpcm_enc_wl_code_table[il >> 2]; + + if ( nbl < 0 ) + nbl = 0; + if ( nbl > 18432 ) + nbl = 18432; + + return( nbl ); +} + + +/* scalel: compute quantizer scale factor in lower or upper sub-band*/ +int adpcm_enc_scalel( int nbl, int shift_constant ) +{ + int wd1, wd2, wd3; + + + wd1 = (nbl >> 6) & 31; + wd2 = nbl >> 11; + wd3 = adpcm_enc_ilb_table[wd1] >> (shift_constant + 1 - wd2); + + return( wd3 << 3 ); +} + + +/* upzero - inputs: dlt, dlti[0-5], bli[0-5], outputs: updated bli[0-5] */ +/* also implements delay of bli and update of dlti from dlt */ +void adpcm_enc_upzero( int dlt, int *dlti, int *bli ) +{ + int i, wd2, wd3; + + + /*if dlt is zero, then no sum into bli */ + if ( dlt == 0 ) { + _Pragma("loopbound min 6 max 6") + for ( i = 0; i < 6; i++ ) { + bli[i] = (int)((255L * bli[i]) >> 8L); /* leak factor of 255/256 */ + } + + } else { + _Pragma("loopbound min 6 max 6") + for ( i = 0; i < 6; i++ ) { + if ( (long)dlt * dlti[i] >= 0 ) + wd2 = 128; + else + wd2 = -128; + + wd3 = (int)((255L * bli[i]) >> 8L); /* leak factor of 255/256 */ + bli[i] = wd2 + wd3; + } + + } + + /* implement delay line for dlt */ + dlti[5] = dlti[4]; + dlti[4] = dlti[3]; + dlti[3] = dlti[2]; + dlti[1] = dlti[0]; + dlti[0] = dlt; + + return; +} + + +/* uppol2 - update second predictor coefficient (pole section) */ +/* inputs: al1, al2, plt, plt1, plt2. outputs: apl2 */ +int adpcm_enc_uppol2( int al1, int al2, int plt, int plt1, int plt2 ) +{ + long int wd2, wd4; + int apl2; + + + wd2 = 4L * (long)al1; + if ( (long)plt * plt1 >= 0L ) + wd2 = -wd2; /* check same sign */ + wd2 = wd2 >> 7; /* gain of 1/128 */ + + if ( (long)plt * plt2 >= 0L ) { + wd4 = wd2 + 128; /* same sign case */ + } else { + wd4 = wd2 - 128; + } + apl2 = wd4 + (127L*(long)al2 >> 7L); /* leak factor of 127/128 */ + + /* apl2 is limited to +-.75 */ + if ( apl2 > 12288 ) + apl2 = 12288; + if ( apl2 < -12288 ) + apl2 = -12288; + + return( apl2 ); +} + + +/* uppol1 - update first predictor coefficient (pole section) */ +/* inputs: al1, apl2, plt, plt1. outputs: apl1 */ +int adpcm_enc_uppol1( int al1, int apl2, int plt, int plt1 ) +{ + long int wd2; + int wd3, apl1; + + + wd2 = ((long)al1 * 255L) >> 8L; /* leak factor of 255/256 */ + if ( (long)plt * plt1 >= 0L ) { + apl1 = (int)wd2 + 192; /* same sign case */ + } else { + apl1 = (int)wd2 - 192; + } + + /* note: wd3= .9375-.75 is always positive */ + wd3 = 15360 - apl2; /* limit value */ + if ( apl1 > wd3 ) + apl1 = wd3; + if ( apl1 < -wd3 ) + apl1 = -wd3; + + return( apl1 ); +} + + +/* INVQAH: inverse adaptive quantizer for the higher sub-band */ +/* returns dh, code table is pre-multiplied by 8 */ +/* int invqah(int ih,int deth) */ +/* { */ +/* long int rdh; */ +/* rdh = ((long)deth*qq2_code2_table[ih]) >> 15L ; */ +/* return((int)(rdh )); */ +/* } */ + + +/* logsch - update log quantizer scale factor in higher sub-band */ +/* note that nbh is passed and returned */ +int adpcm_enc_logsch( int ih, int nbh ) +{ + int wd; + + + wd = ((long)nbh * 127L) >> 7L; /* leak factor 127/128 */ + nbh = wd + adpcm_enc_wh_code_table[ih]; + + if ( nbh < 0 ) + nbh = 0; + if ( nbh > 22528 ) + nbh = 22528; + + return( nbh ); +} + + +/* + Initialization- and return-value-related functions +*/ + +/* clear all storage locations */ + +void adpcm_enc_reset(void) +{ + int i; + + adpcm_enc_detl = 32; /* reset to min scale factor */ + adpcm_enc_deth = 8; + adpcm_enc_nbl = adpcm_enc_al1 = adpcm_enc_al2 = adpcm_enc_plt1 = adpcm_enc_plt2 = adpcm_enc_rlt1 = adpcm_enc_rlt2 = 0; + adpcm_enc_nbh = adpcm_enc_ah1 = adpcm_enc_ah2 = adpcm_enc_ph1 = adpcm_enc_ph2 = adpcm_enc_rh1 = adpcm_enc_rh2 = 0; + + _Pragma("loopbound min 6 max 6") + for ( i = 0; i < 6; i++) { + adpcm_enc_delay_dltx[i] = 0; + adpcm_enc_delay_dhx[i] = 0; + } + + _Pragma("loopbound min 6 max 6") + for ( i = 0; i < 6; i++ ) { + adpcm_enc_delay_bpl[i] = 0; + adpcm_enc_delay_bph[i] = 0; + } + + _Pragma("loopbound min 23 max 23") + for ( i = 0; i < 23; i++ ) { + adpcm_enc_tqmf[i] = 0; + } + + return; +} + + +void adpcm_enc_init(void) +{ + int i, j, f; + volatile int x = 0; + + /* reset, initialize required memory */ + adpcm_enc_res