ld8a.h 25 KB

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