LD8A.H 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. /*
  2. ITU-T G.729A Speech Coder ANSI-C Source Code
  3. Version 1.1 Last modified: September 1996
  4. Copyright (c) 1996,
  5. AT&T, France Telecom, NTT, Universite de Sherbrooke
  6. All rights reserved.
  7. */
  8. /*---------------------------------------------------------------*
  9. * LD8A.H *
  10. * ~~~~~~ *
  11. * Function prototypes and constants use for G.729A 8kb/s coder. *
  12. * *
  13. *---------------------------------------------------------------*/
  14. /*--------------------------------------------------------------------------*
  15. * Codec constant parameters (coder, decoder, and postfilter) *
  16. *--------------------------------------------------------------------------*/
  17. #define L_TOTAL 240 /* Total size of speech buffer. */
  18. #define L_WINDOW 240 /* Window size in LP analysis. */
  19. #define L_NEXT 40 /* Lookahead in LP analysis. */
  20. #define L_FRAME 80 /* Frame size. */
  21. #define L_SUBFR 40 /* Subframe size. */
  22. #define M 10 /* Order of LP filter. */
  23. #define MP1 (M+1) /* Order of LP filter + 1 */
  24. #define PIT_MIN 20 /* Minimum pitch lag. */
  25. #define PIT_MAX 143 /* Maximum pitch lag. */
  26. #define L_INTERPOL (10+1) /* Length of filter for interpolation. */
  27. #define GAMMA1 24576 /* Bandwitdh factor = 0.75 in Q15 */
  28. #define PRM_SIZE 11 /* Size of vector of analysis parameters. */
  29. #define SERIAL_SIZE (80+2) /* bfi+ number of speech bits */
  30. #define SHARPMAX 13017 /* Maximum value of pitch sharpening 0.8 Q14 */
  31. #define SHARPMIN 3277 /* Minimum value of pitch sharpening 0.2 Q14 */
  32. /*-------------------------------*
  33. * Mathematic functions. *
  34. *-------------------------------*/
  35. Word32 Inv_sqrt( /* (o) Q30 : output value (range: 0<=val<1) */
  36. Word32 L_x /* (i) Q0 : input value (range: 0<=val<=7fffffff) */
  37. );
  38. void Log2(
  39. Word32 L_x, /* (i) Q0 : input value */
  40. Word16 *exponent, /* (o) Q0 : Integer part of Log2. (range: 0<=val<=30) */
  41. Word16 *fraction /* (o) Q15: Fractionnal part of Log2. (range: 0<=val<1) */
  42. );
  43. Word32 Pow2( /* (o) Q0 : result (range: 0<=val<=0x7fffffff) */
  44. Word16 exponent, /* (i) Q0 : Integer part. (range: 0<=val<=30) */
  45. Word16 fraction /* (i) Q15 : Fractionnal part. (range: 0.0<=val<1.0) */
  46. );
  47. /*-------------------------------*
  48. * Pre and post-process. *
  49. *-------------------------------*/
  50. void Init_Pre_Process(void);
  51. void Init_Post_Process(void);
  52. void Pre_Process(
  53. Word16 signal[], /* Input/output signal */
  54. Word16 lg /* Length of signal */
  55. );
  56. void Post_Process(
  57. Word16 signal[], /* Input/output signal */
  58. Word16 lg /* Length of signal */
  59. );
  60. /*----------------------------------*
  61. * Main coder and decoder functions *
  62. *----------------------------------*/
  63. void Init_Coder_ld8a(void);
  64. void Coder_ld8a(
  65. Word16 ana[] /* output : Analysis parameters */
  66. );
  67. void Init_Decod_ld8a(void);
  68. void Decod_ld8a(
  69. Word16 parm[], /* (i) : vector of synthesis parameters
  70. parm[0] = bad frame indicator (bfi) */
  71. Word16 synth[], /* (o) : synthesis speech */
  72. Word16 A_t[], /* (o) : decoded LP filter in 2 subframes */
  73. Word16 *T2 /* (o) : decoded pitch lag in 2 subframes */
  74. );
  75. /*-------------------------------*
  76. * LPC analysis and filtering. *
  77. *-------------------------------*/
  78. void Autocorr(
  79. Word16 x[], /* (i) : Input signal */
  80. Word16 m, /* (i) : LPC order */
  81. Word16 r_h[], /* (o) : Autocorrelations (msb) */
  82. Word16 r_l[] /* (o) : Autocorrelations (lsb) */
  83. );
  84. void Lag_window(
  85. Word16 m, /* (i) : LPC order */
  86. Word16 r_h[], /* (i/o) : Autocorrelations (msb) */
  87. Word16 r_l[] /* (i/o) : Autocorrelations (lsb) */
  88. );
  89. void Levinson(
  90. Word16 Rh[], /* (i) : Rh[m+1] Vector of autocorrelations (msb) */
  91. Word16 Rl[], /* (i) : Rl[m+1] Vector of autocorrelations (lsb) */
  92. Word16 A[], /* (o) Q12 : A[m] LPC coefficients (m = 10) */
  93. Word16 rc[] /* (o) Q15 : rc[M] Relection coefficients. */
  94. );
  95. void Az_lsp(
  96. Word16 a[], /* (i) Q12 : predictor coefficients */
  97. Word16 lsp[], /* (o) Q15 : line spectral pairs */
  98. Word16 old_lsp[] /* (i) : old lsp[] (in case not found 10 roots) */
  99. );
  100. void Lsp_Az(
  101. Word16 lsp[], /* (i) Q15 : line spectral frequencies */
  102. Word16 a[] /* (o) Q12 : predictor coefficients (order = 10) */
  103. );
  104. void Lsf_lsp(
  105. Word16 lsf[], /* (i) Q15 : lsf[m] normalized (range: 0.0<=val<=0.5) */
  106. Word16 lsp[], /* (o) Q15 : lsp[m] (range: -1<=val<1) */
  107. Word16 m /* (i) : LPC order */
  108. );
  109. void Lsp_lsf(
  110. Word16 lsp[], /* (i) Q15 : lsp[m] (range: -1<=val<1) */
  111. Word16 lsf[], /* (o) Q15 : lsf[m] normalized (range: 0.0<=val<=0.5) */
  112. Word16 m /* (i) : LPC order */
  113. );
  114. void Int_qlpc(
  115. Word16 lsp_old[], /* input : LSP vector of past frame */
  116. Word16 lsp_new[], /* input : LSP vector of present frame */
  117. Word16 Az[] /* output: interpolated Az() for the 2 subframes */
  118. );
  119. void Weight_Az(
  120. Word16 a[], /* (i) Q12 : a[m+1] LPC coefficients */
  121. Word16 gamma, /* (i) Q15 : Spectral expansion factor. */
  122. Word16 m, /* (i) : LPC order. */
  123. Word16 ap[] /* (o) Q12 : Spectral expanded LPC coefficients */
  124. );
  125. void Residu(
  126. Word16 a[], /* (i) Q12 : prediction coefficients */
  127. Word16 x[], /* (i) : speech (values x[-m..-1] are needed (m=10) */
  128. Word16 y[], /* (o) : residual signal */
  129. Word16 lg /* (i) : size of filtering */
  130. );
  131. void Syn_filt(
  132. Word16 a[], /* (i) Q12 : a[m+1] prediction coefficients (m=10) */
  133. Word16 x[], /* (i) : input signal */
  134. Word16 y[], /* (o) : output signal */
  135. Word16 lg, /* (i) : size of filtering */
  136. Word16 mem[], /* (i/o) : memory associated with this filtering. */
  137. Word16 update /* (i) : 0=no update, 1=update of memory. */
  138. );
  139. void Convolve(
  140. Word16 x[], /* (i) : input vector */
  141. Word16 h[], /* (i) Q12 : impulse response */
  142. Word16 y[], /* (o) : output vector */
  143. Word16 L /* (i) : vector size */
  144. );
  145. /*--------------------------------------------------------------------------*
  146. * LTP constant parameters *
  147. *--------------------------------------------------------------------------*/
  148. #define UP_SAMP 3
  149. #define L_INTER10 10
  150. #define FIR_SIZE_SYN (UP_SAMP*L_INTER10+1)
  151. /*-----------------------*
  152. * Pitch functions. *
  153. *-----------------------*/
  154. Word16 Pitch_ol_fast( /* output: open loop pitch lag */
  155. Word16 signal[], /* input : signal used to compute the open loop pitch */
  156. /* signal[-pit_max] to signal[-1] should be known */
  157. Word16 pit_max, /* input : maximum pitch lag */
  158. Word16 L_frame /* input : length of frame to compute pitch */
  159. );
  160. Word16 Pitch_fr3_fast(/* (o) : pitch period. */
  161. Word16 exc[], /* (i) : excitation buffer */
  162. Word16 xn[], /* (i) : target vector */
  163. Word16 h[], /* (i) Q12 : impulse response of filters. */
  164. Word16 L_subfr, /* (i) : Length of subframe */
  165. Word16 t0_min, /* (i) : minimum value in the searched range. */
  166. Word16 t0_max, /* (i) : maximum value in the searched range. */
  167. Word16 i_subfr, /* (i) : indicator for first subframe. */
  168. Word16 *pit_frac /* (o) : chosen fraction. */
  169. );
  170. Word16 G_pitch( /* (o) Q14 : Gain of pitch lag saturated to 1.2 */
  171. Word16 xn[], /* (i) : Pitch target. */
  172. Word16 y1[], /* (i) : Filtered adaptive codebook. */
  173. Word16 g_coeff[], /* (i) : Correlations need for gain quantization. */
  174. Word16 L_subfr /* (i) : Length of subframe. */
  175. );
  176. Word16 Enc_lag3( /* output: Return index of encoding */
  177. Word16 T0, /* input : Pitch delay */
  178. Word16 T0_frac, /* input : Fractional pitch delay */
  179. Word16 *T0_min, /* in/out: Minimum search delay */
  180. Word16 *T0_max, /* in/out: Maximum search delay */
  181. Word16 pit_min, /* input : Minimum pitch delay */
  182. Word16 pit_max, /* input : Maximum pitch delay */
  183. Word16 pit_flag /* input : Flag for 1st subframe */
  184. );
  185. void Dec_lag3( /* output: return integer pitch lag */
  186. Word16 index, /* input : received pitch index */
  187. Word16 pit_min, /* input : minimum pitch lag */
  188. Word16 pit_max, /* input : maximum pitch lag */
  189. Word16 i_subfr, /* input : subframe flag */
  190. Word16 *T0, /* output: integer part of pitch lag */
  191. Word16 *T0_frac /* output: fractional part of pitch lag */
  192. );
  193. Word16 Interpol_3( /* (o) : interpolated value */
  194. Word16 *x, /* (i) : input vector */
  195. Word16 frac /* (i) : fraction */
  196. );
  197. void Pred_lt_3(
  198. Word16 exc[], /* in/out: excitation buffer */
  199. Word16 T0, /* input : integer pitch lag */
  200. Word16 frac, /* input : fraction of lag */
  201. Word16 L_subfr /* input : subframe size */
  202. );
  203. Word16 Parity_Pitch( /* output: parity bit (XOR of 6 MSB bits) */
  204. Word16 pitch_index /* input : index for which parity to compute */
  205. );
  206. Word16 Check_Parity_Pitch( /* output: 0 = no error, 1= error */
  207. Word16 pitch_index, /* input : index of parameter */
  208. Word16 parity /* input : parity bit */
  209. );
  210. void Cor_h_X(
  211. Word16 h[], /* (i) Q12 :Impulse response of filters */
  212. Word16 X[], /* (i) :Target vector */
  213. Word16 D[] /* (o) :Correlations between h[] and D[] */
  214. /* Normalized to 13 bits */
  215. );
  216. /*-----------------------*
  217. * Innovative codebook. *
  218. *-----------------------*/
  219. #define DIM_RR 616 /* size of correlation matrix */
  220. #define NB_POS 8 /* Number of positions for each pulse */
  221. #define STEP 5 /* Step betweem position of the same pulse. */
  222. #define MSIZE 64 /* Size of vectors for cross-correlation between 2 pulses*/
  223. /* The following constants are Q15 fractions.
  224. These fractions is used to keep maximum precision on "alp" sum */
  225. #define _1_2 (Word16)(16384)
  226. #define _1_4 (Word16)( 8192)
  227. #define _1_8 (Word16)( 4096)
  228. #define _1_16 (Word16)( 2048)
  229. Word16 ACELP_Code_A( /* (o) :index of pulses positions */
  230. Word16 x[], /* (i) :Target vector */
  231. Word16 h[], /* (i) Q12 :Inpulse response of filters */
  232. Word16 T0, /* (i) :Pitch lag */
  233. Word16 pitch_sharp, /* (i) Q14 :Last quantized pitch gain */
  234. Word16 code[], /* (o) Q13 :Innovative codebook */
  235. Word16 y[], /* (o) Q12 :Filtered innovative codebook */
  236. Word16 *sign /* (o) :Signs of 4 pulses */
  237. );
  238. void Decod_ACELP(
  239. Word16 sign, /* (i) : signs of 4 pulses. */
  240. Word16 index, /* (i) : Positions of the 4 pulses. */
  241. Word16 cod[] /* (o) Q13 : algebraic (fixed) codebook excitation */
  242. );
  243. /*--------------------------------------------------------------------------*
  244. * LSP constant parameters *
  245. *--------------------------------------------------------------------------*/
  246. #define NC 5 /* NC = M/2 */
  247. #define MA_NP 4 /* MA prediction order for LSP */
  248. #define MODE 2 /* number of modes for MA prediction */
  249. #define NC0_B 7 /* number of first stage bits */
  250. #define NC1_B 5 /* number of second stage bits */
  251. #define NC0 (1<<NC0_B)
  252. #define NC1 (1<<NC1_B)
  253. #define L_LIMIT 40 /* Q13:0.005 */
  254. #define M_LIMIT 25681 /* Q13:3.135 */
  255. #define GAP1 10 /* Q13 */
  256. #define GAP2 5 /* Q13 */
  257. #define GAP3 321 /* Q13 */
  258. #define GRID_POINTS 50
  259. #define PI04 ((Word16)1029) /* Q13 pi*0.04 */
  260. #define PI92 ((Word16)23677) /* Q13 pi*0.92 */
  261. #define CONST10 ((Word16)10*(1<<11)) /* Q11 10.0 */
  262. #define CONST12 ((Word16)19661) /* Q14 1.2 */
  263. /*-------------------------------*
  264. * LSP VQ functions. *
  265. *-------------------------------*/
  266. void Lsf_lsp2(
  267. Word16 lsf[], /* (i) Q13 : lsf[m] (range: 0.0<=val<PI) */
  268. Word16 lsp[], /* (o) Q15 : lsp[m] (range: -1<=val<1) */
  269. Word16 m /* (i) : LPC order */
  270. );
  271. void Lsp_lsf2(
  272. Word16 lsp[], /* (i) Q15 : lsp[m] (range: -1<=val<1) */
  273. Word16 lsf[], /* (o) Q13 : lsf[m] (range: 0.0<=val<PI) */
  274. Word16 m /* (i) : LPC order */
  275. );
  276. void Qua_lsp(
  277. Word16 lsp[], /* (i) Q15 : Unquantized LSP */
  278. Word16 lsp_q[], /* (o) Q15 : Quantized LSP */
  279. Word16 ana[] /* (o) : indexes */
  280. );
  281. void Get_wegt(
  282. Word16 flsp[], /* Q13 */
  283. Word16 wegt[] /* Q11 -> normalized */
  284. );
  285. void Lsp_encw_reset(
  286. void
  287. );
  288. void Lsp_qua_cs(
  289. Word16 flsp_in[M], /* Q13 */
  290. Word16 lspq_out[M], /* Q13 */
  291. Word16 *code
  292. );
  293. void Lsp_expand_1(
  294. Word16 buf[], /* Q13 */
  295. Word16 gap /* Q13 */
  296. );
  297. void Lsp_expand_2(
  298. Word16 buf[], /* Q13 */
  299. Word16 gap /* Q13 */
  300. );
  301. void Lsp_expand_1_2(
  302. Word16 buf[], /* Q13 */
  303. Word16 gap /* Q13 */
  304. );
  305. void Lsp_get_quant(
  306. Word16 lspcb1[][M], /* Q13 */
  307. Word16 lspcb2[][M], /* Q13 */
  308. Word16 code0,
  309. Word16 code1,
  310. Word16 code2,
  311. Word16 fg[][M], /* Q15 */
  312. Word16 freq_prev[][M], /* Q13 */
  313. Word16 lspq[], /* Q13 */
  314. Word16 fg_sum[] /* Q15 */
  315. );
  316. void Lsp_get_tdist(
  317. Word16 wegt[], /* normalized */
  318. Word16 buf[], /* Q13 */
  319. Word32 *L_tdist, /* Q27 */
  320. Word16 rbuf[], /* Q13 */
  321. Word16 fg_sum[] /* Q15 */
  322. );
  323. void Lsp_last_select(
  324. Word32 L_tdist[], /* Q27 */
  325. Word16 *mode_index
  326. );
  327. void Lsp_pre_select(
  328. Word16 rbuf[], /* Q13 */
  329. Word16 lspcb1[][M], /* Q13 */
  330. Word16 *cand
  331. );
  332. void Lsp_select_1(
  333. Word16 rbuf[], /* Q13 */
  334. Word16 lspcb1[], /* Q13 */
  335. Word16 wegt[], /* normalized */
  336. Word16 lspcb2[][M], /* Q13 */
  337. Word16 *index
  338. );
  339. void Lsp_select_2(
  340. Word16 rbuf[], /* Q13 */
  341. Word16 lspcb1[], /* Q13 */
  342. Word16 wegt[], /* normalized */
  343. Word16 lspcb2[][M], /* Q13 */
  344. Word16 *index
  345. );
  346. void Lsp_stability(
  347. Word16 buf[] /* Q13 */
  348. );
  349. void Relspwed(
  350. Word16 lsp[], /* Q13 */
  351. Word16 wegt[], /* normalized */
  352. Word16 lspq[], /* Q13 */
  353. Word16 lspcb1[][M], /* Q13 */
  354. Word16 lspcb2[][M], /* Q13 */
  355. Word16 fg[MODE][MA_NP][M], /* Q15 */
  356. Word16 freq_prev[MA_NP][M], /* Q13 */
  357. Word16 fg_sum[MODE][M], /* Q15 */
  358. Word16 fg_sum_inv[MODE][M], /* Q12 */
  359. Word16 code_ana[]
  360. );
  361. void D_lsp(
  362. Word16 prm[], /* (i) : indexes of the selected LSP */
  363. Word16 lsp_q[], /* (o) Q15 : Quantized LSP parameters */
  364. Word16 erase /* (i) : frame erase information */
  365. );
  366. void Lsp_decw_reset(
  367. void
  368. );
  369. void Lsp_iqua_cs(
  370. Word16 prm[], /* input : codes of the selected LSP*/
  371. Word16 lsp_q[], /* output: Quantized LSP parameters*/
  372. Word16 erase /* input : frame erase information */
  373. );
  374. void Lsp_prev_compose(
  375. Word16 lsp_ele[], /* Q13 */
  376. Word16 lsp[], /* Q13 */
  377. Word16 fg[][M], /* Q15 */
  378. Word16 freq_prev[][M], /* Q13 */
  379. Word16 fg_sum[] /* Q15 */
  380. );
  381. void Lsp_prev_extract(
  382. Word16 lsp[M], /* Q13 */
  383. Word16 lsp_ele[M], /* Q13 */
  384. Word16 fg[MA_NP][M], /* Q15 */
  385. Word16 freq_prev[MA_NP][M], /* Q13 */
  386. Word16 fg_sum_inv[M] /* Q12 */
  387. );
  388. void Lsp_prev_update(
  389. Word16 lsp_ele[M], /* Q13 */
  390. Word16 freq_prev[MA_NP][M] /* Q13 */
  391. );
  392. /*-------------------------------*
  393. * gain VQ constants. *
  394. *-------------------------------*/
  395. #define NCODE1_B 3 /* number of Codebook-bit */
  396. #define NCODE2_B 4 /* number of Codebook-bit */
  397. #define NCODE1 (1<<NCODE1_B) /* Codebook 1 size */
  398. #define NCODE2 (1<<NCODE2_B) /* Codebook 2 size */
  399. #define NCAN1 4 /* Pre-selecting order for #1 */
  400. #define NCAN2 8 /* Pre-selecting order for #2 */
  401. #define INV_COEF -17103 /* Q19 */
  402. /*--------------------------------------------------------------------------*
  403. * gain VQ functions. *
  404. *--------------------------------------------------------------------------*/
  405. Word16 Qua_gain(
  406. Word16 code[], /* (i) Q13 : Innovative vector. */
  407. Word16 g_coeff[], /* (i) : Correlations <xn y1> -2<y1 y1> */
  408. /* <y2,y2>, -2<xn,y2>, 2<y1,y2> */
  409. Word16 exp_coeff[],/* (i) : Q-Format g_coeff[] */
  410. Word16 L_subfr, /* (i) : Subframe length. */
  411. Word16 *gain_pit, /* (o) Q14 : Pitch gain. */
  412. Word16 *gain_cod, /* (o) Q1 : Code gain. */
  413. Word16 tameflag /* (i) : flag set to 1 if taming is needed */
  414. );
  415. void Dec_gain(
  416. Word16 index, /* (i) : Index of quantization. */
  417. Word16 code[], /* (i) Q13 : Innovative vector. */
  418. Word16 L_subfr, /* (i) : Subframe length. */
  419. Word16 bfi, /* (i) : Bad frame indicator */
  420. Word16 *gain_pit, /* (o) Q14 : Pitch gain. */
  421. Word16 *gain_cod /* (o) Q1 : Code gain. */
  422. );
  423. void Gain_predict(
  424. Word16 past_qua_en[],/* (i) Q10 :Past quantized energies */
  425. Word16 code[], /* (i) Q13 : Innovative vector. */
  426. Word16 L_subfr, /* (i) : Subframe length. */
  427. Word16 *gcode0, /* (o) Qxx : Predicted codebook gain */
  428. Word16 *exp_gcode0 /* (o) : Q-Format(gcode0) */
  429. );
  430. void Gain_update(
  431. Word16 past_qua_en[],/* (i) Q10 :Past quantized energies */
  432. Word32 L_gbk12 /* (i) Q13 : gbk1[indice1][1]+gbk2[indice2][1] */
  433. );
  434. void Gain_update_erasure(
  435. Word16 past_qua_en[]/* (i) Q10 :Past quantized energies */
  436. );
  437. void Corr_xy2(
  438. Word16 xn[], /* (i) Q0 :Target vector. */
  439. Word16 y1[], /* (i) Q0 :Adaptive codebook. */
  440. Word16 y2[], /* (i) Q12 :Filtered innovative vector. */
  441. Word16 g_coeff[], /* (o) Q[exp]:Correlations between xn,y1,y2 */
  442. Word16 exp_g_coeff[] /* (o) :Q-format of g_coeff[] */
  443. );
  444. /*-----------------------*
  445. * Bitstream function *
  446. *-----------------------*/
  447. void prm2bits_ld8k(Word16 prm[], Word16 bits[]);
  448. void bits2prm_ld8k(Word16 bits[], Word16 prm[]);
  449. #define BIT_0 (short)0x007f /* definition of zero-bit in bit-stream */
  450. #define BIT_1 (short)0x0081 /* definition of one-bit in bit-stream */
  451. #define SYNC_WORD (short)0x6b21 /* definition of frame erasure flag */
  452. #define SIZE_WORD (short)80 /* number of speech bits */
  453. /*-----------------------------------*
  454. * Post-filter functions. *
  455. *-----------------------------------*/
  456. #define L_H 22 /* size of truncated impulse response of A(z/g1)/A(z/g2) */
  457. #define GAMMAP 16384 /* 0.5 (Q15) */
  458. #define INV_GAMMAP 21845 /* 1/(1+GAMMAP) (Q15) */
  459. #define GAMMAP_2 10923 /* GAMMAP/(1+GAMMAP) (Q15) */
  460. #define GAMMA2_PST 18022 /* Formant postfilt factor (numerator) 0.55 Q15 */
  461. #define GAMMA1_PST 22938 /* Formant postfilt factor (denominator) 0.70 Q15 */
  462. #define MU 26214 /* Factor for tilt compensation filter 0.8 Q15 */
  463. #define AGC_FAC 29491 /* Factor for automatic gain control 0.9 Q15 */
  464. #define AGC_FAC1 (Word16)(32767 - AGC_FAC) /* 1-AGC_FAC in Q15 */
  465. void Init_Post_Filter(void);
  466. void Post_Filter(
  467. Word16 *syn, /* in/out: synthesis speech (postfiltered is output) */
  468. Word16 *Az_4, /* input : interpolated LPC parameters in all subframes */
  469. Word16 *T /* input : decoded pitch lags in all subframes */
  470. );
  471. void pit_pst_filt(
  472. Word16 *signal, /* (i) : input signal */
  473. Word16 *scal_sig, /* (i) : input signal (scaled, divided by 4) */
  474. Word16 t0_min, /* (i) : minimum value in the searched range */
  475. Word16 t0_max, /* (i) : maximum value in the searched range */
  476. Word16 L_subfr, /* (i) : size of filtering */
  477. Word16 *signal_pst /* (o) : harmonically postfiltered signal */
  478. );
  479. void preemphasis(
  480. Word16 *signal, /* (i/o) : input signal overwritten by the output */
  481. Word16 g, /* (i) Q15 : preemphasis coefficient */
  482. Word16 L /* (i) : size of filtering */
  483. );
  484. void agc(
  485. Word16 *sig_in, /* (i) : postfilter input signal */
  486. Word16 *sig_out, /* (i/o) : postfilter output signal */
  487. Word16 l_trm /* (i) : subframe size */
  488. );
  489. /*--------------------------------------------------------------------------*
  490. * Constants and prototypes for taming procedure. *
  491. *--------------------------------------------------------------------------*/
  492. #define GPCLIP 15564 /* Maximum pitch gain if taming is needed Q14*/
  493. #define GPCLIP2 481 /* Maximum pitch gain if taming is needed Q9 */
  494. #define GP0999 16383 /* Maximum pitch gain if taming is needed */
  495. #define L_THRESH_ERR 983040000L /* Error threshold taming 16384. * 60000. */
  496. void Init_exc_err(void);
  497. void update_exc_err(Word16 gain_pit, Word16 t0);
  498. Word16 test_err(Word16 t0, Word16 t0_frac);
  499. /*--------------------------------------------------------------------------*
  500. * Prototypes for auxiliary functions. *
  501. *--------------------------------------------------------------------------*/
  502. void Copy(
  503. Word16 x[], /* (i) : input vector */
  504. Word16 y[], /* (o) : output vector */
  505. Word16 L /* (i) : vector length */
  506. );
  507. void Set_zero(
  508. Word16 x[], /* (o) : vector to clear */
  509. Word16 L /* (i) : length of vector */
  510. );
  511. Word16 Random(void);