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