1 #include "aliases.h" 2 /* 3 * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische 4 * Universitaet Berlin. See the accompanying file "COPYRIGHT" for 5 * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. 6 */ 7 8 /*$Header: /cvsroot/sox/sox/libgsm/private.h,v 1.3 2008/03/21 13:34:21 robs Exp $*/ 9 10 #ifndef PRIVATE_H 11 #define PRIVATE_H 12 13 typedef short word; /* 16 bit signed int */ 14 typedef long longword; /* 32 bit signed int */ 15 16 typedef unsigned short uword; /* unsigned word */ 17 typedef unsigned long ulongword; /* unsigned longword */ 18 19 struct gsm_state { 20 21 word dp0[ 280 ]; 22 23 word z1; /* preprocessing.c, Offset_com. */ 24 longword L_z2; /* Offset_com. */ 25 int mp; /* Preemphasis */ 26 27 word u[8]; /* short_term_aly_filter.c */ 28 word LARpp[2][8]; /* */ 29 word j; /* */ 30 31 word ltp_cut; /* long_term.c, LTP crosscorr. */ 32 word nrp; /* 40 */ /* long_term.c, synthesis */ 33 word v[9]; /* short_term.c, synthesis */ 34 word msr; /* decoder.c, Postprocessing */ 35 36 char verbose; /* only used if !NDEBUG */ 37 char fast; /* only used if FAST */ 38 39 char wav_fmt; /* only used if WAV49 defined */ 40 unsigned char frame_index; /* odd/even chaining */ 41 unsigned char frame_chain; /* half-byte to carry forward */ 42 }; 43 44 45 #define MIN_WORD (-32767 - 1) 46 #define MAX_WORD 32767 47 48 #define MIN_LONGWORD (-2147483647 - 1) 49 #define MAX_LONGWORD 2147483647 50 51 #ifdef SASR /* flag: >> is a signed arithmetic shift right */ 52 #undef SASR 53 #define SASR(x, by) ((x) >> (by)) 54 #else 55 #define SASR(x, by) ((x) >= 0 ? (x) >> (by) : (~(-((x) + 1) >> (by)))) 56 #endif /* SASR */ 57 58 /* 59 * Prototypes from add.c 60 */ 61 extern word gsm_mult (word a, word b); 62 extern longword gsm_L_mult (word a, word b); 63 extern word gsm_mult_r (word a, word b); 64 65 extern word gsm_div (word num, word denum); 66 67 extern word gsm_add ( word a, word b ); 68 extern longword gsm_L_add ( longword a, longword b ); 69 70 extern word gsm_sub (word a, word b); 71 extern longword gsm_L_sub (longword a, longword b); 72 73 extern word gsm_abs (word a); 74 75 extern word gsm_norm ( longword a ); 76 77 extern longword gsm_L_asl (longword a, int n); 78 extern word gsm_asl (word a, int n); 79 80 extern longword gsm_L_asr (longword a, int n); 81 extern word gsm_asr (word a, int n); 82 83 /* 84 * Inlined functions from add.h 85 */ 86 87 /* 88 * #define GSM_MULT_R(a, b) (* word a, word b, !(a == b == MIN_WORD) *) \ 89 * (0x0FFFF & SASR(((longword)(a) * (longword)(b) + 16384), 15)) 90 */ 91 #define GSM_MULT_R(a, b) /* word a, word b, !(a == b == MIN_WORD) */ \ 92 (SASR( ((longword)(a) * (longword)(b) + 16384), 15 )) 93 94 # define GSM_MULT(a,b) /* word a, word b, !(a == b == MIN_WORD) */ \ 95 (SASR( ((longword)(a) * (longword)(b)), 15 )) 96 97 # define GSM_L_MULT(a, b) /* word a, word b */ \ 98 (((longword)(a) * (longword)(b)) << 1) 99 100 # define GSM_L_ADD(a, b) \ 101 ( (a) < 0 ? ( (b) >= 0 ? (a) + (b) \ 102 : (utmp = (ulongword)-((a) + 1) + (ulongword)-((b) + 1)) \ 103 >= MAX_LONGWORD ? MIN_LONGWORD : -(longword)utmp-2 ) \ 104 : ((b) <= 0 ? (a) + (b) \ 105 : (utmp = (ulongword)(a) + (ulongword)(b)) >= MAX_LONGWORD \ 106 ? MAX_LONGWORD : (longword)utmp)) 107 108 /* 109 * # define GSM_ADD(a, b) \ 110 * ((ltmp = (longword)(a) + (longword)(b)) >= MAX_WORD \ 111 * ? MAX_WORD : ltmp <= MIN_WORD ? MIN_WORD : ltmp) 112 */ 113 /* Nonportable, but faster: */ 114 115 #define GSM_ADD(a, b) \ 116 ((ulongword)((ltmp = (longword)(a) + (longword)(b)) - MIN_WORD) > \ 117 MAX_WORD - MIN_WORD ? (ltmp > 0 ? MAX_WORD : MIN_WORD) : ltmp) 118 119 # define GSM_SUB(a, b) \ 120 ((ltmp = (longword)(a) - (longword)(b)) >= MAX_WORD \ 121 ? MAX_WORD : ltmp <= MIN_WORD ? MIN_WORD : ltmp) 122 123 # define GSM_ABS(a) ((a) < 0 ? ((a) == MIN_WORD ? MAX_WORD : -(a)) : (a)) 124 125 /* Use these if necessary: 126 127 # define GSM_MULT_R(a, b) gsm_mult_r(a, b) 128 # define GSM_MULT(a, b) gsm_mult(a, b) 129 # define GSM_L_MULT(a, b) gsm_L_mult(a, b) 130 131 # define GSM_L_ADD(a, b) gsm_L_add(a, b) 132 # define GSM_ADD(a, b) gsm_add(a, b) 133 # define GSM_SUB(a, b) gsm_sub(a, b) 134 135 # define GSM_ABS(a) gsm_abs(a) 136 137 */ 138 139 /* 140 * More prototypes from implementations.. 141 */ 142 extern void Gsm_Coder ( 143 struct gsm_state * S, 144 word * s, /* [0..159] samples IN */ 145 word * LARc, /* [0..7] LAR coefficients OUT */ 146 word * Nc, /* [0..3] LTP lag OUT */ 147 word * bc, /* [0..3] coded LTP gain OUT */ 148 word * Mc, /* [0..3] RPE grid selection OUT */ 149 word * xmaxc,/* [0..3] Coded maximum amplitude OUT */ 150 word * xMc /* [13*4] normalized RPE samples OUT */); 151 152 extern void Gsm_Long_Term_Predictor ( /* 4x for 160 samples */ 153 struct gsm_state * S, 154 word * d, /* [0..39] residual signal IN */ 155 word * dp, /* [-120..-1] d' IN */ 156 word * e, /* [0..40] OUT */ 157 word * dpp, /* [0..40] OUT */ 158 word * Nc, /* correlation lag OUT */ 159 word * bc /* gain factor OUT */); 160 161 extern void Gsm_LPC_Analysis ( 162 struct gsm_state * S, 163 word * s, /* 0..159 signals IN/OUT */ 164 word * LARc); /* 0..7 LARc's OUT */ 165 166 extern void Gsm_Preprocess ( 167 struct gsm_state * S, 168 word * s, word * so); 169 170 extern void Gsm_Encoding ( 171 struct gsm_state * S, 172 word * e, 173 word * ep, 174 word * xmaxc, 175 word * Mc, 176 word * xMc); 177 178 extern void Gsm_Short_Term_Analysis_Filter ( 179 struct gsm_state * S, 180 word * LARc, /* coded log area ratio [0..7] IN */ 181 word * d /* st res. signal [0..159] IN/OUT */); 182 183 extern void Gsm_Decoder ( 184 struct gsm_state * S, 185 word * LARcr, /* [0..7] IN */ 186 word * Ncr, /* [0..3] IN */ 187 word * bcr, /* [0..3] IN */ 188 word * Mcr, /* [0..3] IN */ 189 word * xmaxcr, /* [0..3] IN */ 190 word * xMcr, /* [0..13*4] IN */ 191 word * s); /* [0..159] OUT */ 192 193 extern void Gsm_Decoding ( 194 struct gsm_state * S, 195 word xmaxcr, 196 word Mcr, 197 word * xMcr, /* [0..12] IN */ 198 word * erp); /* [0..39] OUT */ 199 200 extern void Gsm_Long_Term_Synthesis_Filtering ( 201 struct gsm_state* S, 202 word Ncr, 203 word bcr, 204 word * erp, /* [0..39] IN */ 205 word * drp); /* [-120..-1] IN, [0..40] OUT */ 206 207 void Gsm_RPE_Decoding ( 208 struct gsm_state *S, 209 word xmaxcr, 210 word Mcr, 211 word * xMcr, /* [0..12], 3 bits IN */ 212 word * erp); /* [0..39] OUT */ 213 214 void Gsm_RPE_Encoding ( 215 struct gsm_state * S, 216 word * e, /* -5..-1][0..39][40..44 IN/OUT */ 217 word * xmaxc, /* OUT */ 218 word * Mc, /* OUT */ 219 word * xMc); /* [0..12] OUT */ 220 221 extern void Gsm_Short_Term_Synthesis_Filter ( 222 struct gsm_state * S, 223 word * LARcr, /* log area ratios [0..7] IN */ 224 word * drp, /* received d [0...39] IN */ 225 word * s); /* signal s [0..159] OUT */ 226 227 extern void Gsm_Update_of_reconstructed_short_time_residual_signal ( 228 word * dpp, /* [0...39] IN */ 229 word * ep, /* [0...39] IN */ 230 word * dp); /* [-120...-1] IN/OUT */ 231 232 /* 233 * Tables from table.c 234 */ 235 #ifndef GSM_TABLE_C 236 237 extern word gsm_A[8], gsm_B[8], gsm_MIC[8], gsm_MAC[8]; 238 extern word gsm_INVA[8]; 239 extern word gsm_DLB[4], gsm_QLB[4]; 240 extern word gsm_H[11]; 241 extern word gsm_NRFAC[8]; 242 extern word gsm_FAC[8]; 243 244 #endif /* GSM_TABLE_C */ 245 246 /* 247 * Debugging 248 */ 249 #ifdef NDEBUG 250 251 # define gsm_debug_words(a, b, c, d) /* nil */ 252 # define gsm_debug_longwords(a, b, c, d) /* nil */ 253 # define gsm_debug_word(a, b) /* nil */ 254 # define gsm_debug_longword(a, b) /* nil */ 255 256 #else /* !NDEBUG => DEBUG */ 257 258 extern void gsm_debug_words (char * name, int, int, word *); 259 extern void gsm_debug_longwords (char * name, int, int, longword *); 260 extern void gsm_debug_longword (char * name, longword); 261 extern void gsm_debug_word (char * name, word); 262 263 #endif /* !NDEBUG */ 264 265 #endif /* PRIVATE_H */ 266