123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713 |
- /*
- *****************************************************************************
- *
- * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
- * R99 Version 3.3.0
- * REL-4 Version 4.1.0
- *
- *****************************************************************************
- *
- * File : cod_amr.c
- * Purpose : Main encoder routine operating on a frame basis.
- *
- *****************************************************************************
- */
- #include "cod_amr.h"
- const char cod_amr_id[] = "@(#)$Id $" cod_amr_h;
- /*
- *****************************************************************************
- * INCLUDE FILES
- *****************************************************************************
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include "typedef.h"
- #include "basic_op.h"
- #include "count.h"
- #include "cnst.h"
- #include "copy.h"
- #include "set_zero.h"
- #include "qua_gain.h"
- #include "lpc.h"
- #include "lsp.h"
- #include "pre_big.h"
- #include "ol_ltp.h"
- #include "p_ol_wgh.h"
- #include "spreproc.h"
- #include "cl_ltp.h"
- #include "pred_lt.h"
- #include "spstproc.h"
- #include "cbsearch.h"
- #include "gain_q.h"
- #include "copy.h"
- #include "convolve.h"
- #include "ton_stab.h"
- #include "vad.h"
- #include "dtx_enc.h"
- /*
- *****************************************************************************
- * LOCAL VARIABLES AND TABLES
- *****************************************************************************
- */
- /*
- *****************************************************************************
- * PUBLIC VARIABLES AND TABLES
- *****************************************************************************
- */
- /* Spectral expansion factors */
- static const Word16 gamma1[M] =
- {
- 30802, 28954, 27217, 25584, 24049,
- 22606, 21250, 19975, 18777, 17650
- };
- /* gamma1 differs for the 12k2 coder */
- static const Word16 gamma1_12k2[M] =
- {
- 29491, 26542, 23888, 21499, 19349,
- 17414, 15672, 14105, 12694, 11425
- };
- static const Word16 gamma2[M] =
- {
- 19661, 11797, 7078, 4247, 2548,
- 1529, 917, 550, 330, 198
- };
- /*
- *****************************************************************************
- * PUBLIC PROGRAM CODE
- *****************************************************************************
- */
- /*
- **************************************************************************
- *
- * Function : cod_amr_init
- * Purpose : Allocates memory and initializes state variables
- *
- **************************************************************************
- */
- int cod_amr_init (cod_amrState **state, Flag dtx)
- {
- cod_amrState* s;
- if (state == (cod_amrState **) NULL){
- wfprintf(stderr, "cod_amr_init: invalid parameter\n");
- return -1;
- }
- *state = NULL;
-
- /* allocate memory */
- if ((s= (cod_amrState *) wmalloc(sizeof(cod_amrState))) == NULL){
- wfprintf(stderr, "cod_amr_init: can not malloc state structure\n");
- return -1;
- }
- s->lpcSt = NULL;
- s->lspSt = NULL;
- s->clLtpSt = NULL;
- s->gainQuantSt = NULL;
- s->pitchOLWghtSt = NULL;
- s->tonStabSt = NULL;
- s->vadSt = NULL;
- s->dtx_encSt = NULL;
- s->dtx = dtx;
-
- /* Init sub_ex states */
- if (cl_ltp_init(&s->clLtpSt) ||
- lsp_init(&s->lspSt) ||
- gainQuant_init(&s->gainQuantSt) ||
- p_ol_wgh_init(&s->pitchOLWghtSt) ||
- ton_stab_init(&s->tonStabSt) ||
- #ifndef VAD2
- vad1_init(&s->vadSt) ||
- #else
- vad2_init(&s->vadSt) ||
- #endif
- dtx_enc_init(&s->dtx_encSt) ||
- lpc_init(&s->lpcSt)) {
- cod_amr_exit(&s);
- return -1;
- }
-
- cod_amr_reset(s);
-
- *state = s;
-
- return 0;
- }
-
- /*
- **************************************************************************
- *
- * Function : cod_amr_reset
- * Purpose : Resets state memory
- *
- **************************************************************************
- */
- int cod_amr_reset (cod_amrState *st)
- {
- Word16 i;
-
- if (st == (cod_amrState *) NULL){
- wfprintf(stderr, "cod_amr_reset: invalid parameter\n");
- return -1;
- }
-
- /*-----------------------------------------------------------------------*
- * Initialize pointers to speech vector. *
- *-----------------------------------------------------------------------*/
-
- st->new_speech = st->old_speech + L_TOTAL - L_FRAME; /* New speech */
-
- st->speech = st->new_speech - L_NEXT; /* Present frame */
-
- st->p_window = st->old_speech + L_TOTAL - L_WINDOW; /* For LPC window */
- st->p_window_12k2 = st->p_window - L_NEXT; /* EFR LPC window: no lookahead */
-
- /* Initialize static pointers */
-
- st->wsp = st->old_wsp + PIT_MAX;
- st->exc = st->old_exc + PIT_MAX + L_INTERPOL;
- st->zero = st->ai_zero + MP1;
- st->error = st->mem_err + M;
- st->h1 = &st->hvec[L_SUBFR];
-
- /* Static vectors to zero */
-
- Set_zero(st->old_speech, L_TOTAL);
- Set_zero(st->old_exc, PIT_MAX + L_INTERPOL);
- Set_zero(st->old_wsp, PIT_MAX);
- Set_zero(st->mem_syn, M);
- Set_zero(st->mem_w, M);
- Set_zero(st->mem_w0, M);
- Set_zero(st->mem_err, M);
- Set_zero(st->zero, L_SUBFR);
- Set_zero(st->hvec, L_SUBFR); /* set to zero "h1[-L_SUBFR..-1]" */
- /* OL LTP states */
- for (i = 0; i < 5; i++)
- {
- st->old_lags[i] = 40;
- }
-
- /* Reset lpc states */
- lpc_reset(st->lpcSt);
-
- /* Reset lsp states */
- lsp_reset(st->lspSt);
-
- /* Reset clLtp states */
- cl_ltp_reset(st->clLtpSt);
-
- gainQuant_reset(st->gainQuantSt);
- p_ol_wgh_reset(st->pitchOLWghtSt);
- ton_stab_reset(st->tonStabSt);
- #ifndef VAD2
- vad1_reset(st->vadSt);
- #else
- vad2_reset(st->vadSt);
- #endif
-
- dtx_enc_reset(st->dtx_encSt);
- st->sharp = SHARPMIN;
-
- return 0;
- }
-
- /*
- **************************************************************************
- *
- * Function : cod_amr_exit
- * Purpose : The memory used for state memory is freed
- *
- **************************************************************************
- */
- void cod_amr_exit (cod_amrState **state)
- {
- if (state == NULL || *state == NULL)
- return;
-
- /* dealloc members */
- lpc_exit(&(*state)->lpcSt);
- lsp_exit(&(*state)->lspSt);
- gainQuant_exit(&(*state)->gainQuantSt);
- cl_ltp_exit(&(*state)->clLtpSt);
- p_ol_wgh_exit(&(*state)->pitchOLWghtSt);
- ton_stab_exit(&(*state)->tonStabSt);
- #ifndef VAD2
- vad1_exit(&(*state)->vadSt);
- #else
- vad2_exit(&(*state)->vadSt);
- #endif
- dtx_enc_exit(&(*state)->dtx_encSt);
- /* deallocate memory */
- wfree(*state);
- *state = NULL;
-
- return;
- }
- /***************************************************************************
- * FUNCTION: cod_amr_first
- *
- * PURPOSE: Copes with look-ahead.
- *
- * INPUTS:
- * No input argument are passed to this function. However, before
- * calling this function, 40 new speech data should be copied to the
- * vector new_speech[]. This is a global pointer which is declared in
- * this file (it points to the end of speech buffer minus 200).
- *
- ***************************************************************************/
-
- int cod_amr_first(cod_amrState *st, /* i/o : State struct */
- Word16 new_speech[]) /* i : speech input (L_FRAME) */
- {
- Copy(new_speech,&st->new_speech[-L_NEXT], L_NEXT);
- /* Copy(new_speech,st->new_speech,L_FRAME); */
-
- return 0;
- }
- /***************************************************************************
- * FUNCTION: cod_amr
- *
- * PURPOSE: Main encoder routine.
- *
- * DESCRIPTION: This function is called every 20 ms speech frame,
- * operating on the newly read 160 speech samples. It performs the
- * principle encoding functions to produce the set of encoded parameters
- * which include the LSP, adaptive codebook, and fixed codebook
- * quantization indices (addresses and gains).
- *
- * INPUTS:
- * No input argument are passed to this function. However, before
- * calling this function, 160 new speech data should be copied to the
- * vector new_speech[]. This is a global pointer which is declared in
- * this file (it points to the end of speech buffer minus 160).
- *
- * OUTPUTS:
- *
- * ana[]: vector of analysis parameters.
- * synth[]: Local synthesis speech (for debugging purposes)
- *
- ***************************************************************************/
- int cod_amr(
- cod_amrState *st, /* i/o : State struct */
- enum Mode mode, /* i : AMR mode */
- Word16 new_speech[], /* i : speech input (L_FRAME) */
- Word16 ana[], /* o : Analysis parameters */
- enum Mode *usedMode, /* o : used mode */
- Word16 synth[] /* o : Local synthesis */
- )
- {
- /* LPC coefficients */
- Word16 A_t[(MP1) * 4]; /* A(z) unquantized for the 4 subframes */
- Word16 Aq_t[(MP1) * 4]; /* A(z) quantized for the 4 subframes */
- Word16 *A, *Aq; /* Pointer on A_t and Aq_t */
- Word16 lsp_new[M];
-
- /* Other vectors */
- Word16 xn[L_SUBFR]; /* Target vector for pitch search */
- Word16 xn2[L_SUBFR]; /* Target vector for codebook search */
- Word16 code[L_SUBFR]; /* Fixed codebook excitation */
- Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */
- Word16 y2[L_SUBFR]; /* Filtered fixed codebook excitation */
- Word16 gCoeff[6]; /* Correlations between xn, y1, & y2: */
- Word16 res[L_SUBFR]; /* Short term (LPC) prediction residual */
- Word16 res2[L_SUBFR]; /* Long term (LTP) prediction residual */
- /* Vector and scalars needed for the MR475 */
- Word16 xn_sf0[L_SUBFR]; /* Target vector for pitch search */
- Word16 y2_sf0[L_SUBFR]; /* Filtered codebook innovation */
- Word16 code_sf0[L_SUBFR]; /* Fixed codebook excitation */
- Word16 h1_sf0[L_SUBFR]; /* The impulse response of sf0 */
- Word16 mem_syn_save[M]; /* Filter memory */
- Word16 mem_w0_save[M]; /* Filter memory */
- Word16 mem_err_save[M]; /* Filter memory */
- Word16 sharp_save; /* Sharpening */
- Word16 evenSubfr; /* Even subframe indicator */
- Word16 T0_sf0 = 0; /* Integer pitch lag of sf0 */
- Word16 T0_frac_sf0 = 0; /* Fractional pitch lag of sf0 */
- Word16 i_subfr_sf0 = 0; /* Position in exc[] for sf0 */
- Word16 gain_pit_sf0; /* Quantized pitch gain for sf0 */
- Word16 gain_code_sf0; /* Quantized codebook gain for sf0 */
-
- /* Scalars */
- Word16 i_subfr, subfrNr;
- Word16 T_op[L_FRAME/L_FRAME_BY2];
- Word16 T0, T0_frac;
- Word16 gain_pit, gain_code;
- /* Flags */
- Word16 lsp_flag = 0; /* indicates resonance in LPC filter */
- Word16 gp_limit; /* pitch gain limit value */
- Word16 vad_flag; /* VAD decision flag */
- Word16 compute_sid_flag; /* SID analysis flag */
- Copy(new_speech, st->new_speech, L_FRAME);
- *usedMode = mode; move16 ();
- /* DTX processing */
- if (st->dtx)
- { /* no test() call since this if is only in simulation env */
- /* Find VAD decision */
- #ifdef VAD2
- vad_flag = vad2 (st->new_speech, st->vadSt);
- vad_flag = vad2 (st->new_speech+80, st->vadSt) || vad_flag; logic16();
- #else
- vad_flag = vad1(st->vadSt, st->new_speech);
- #endif
- fwc (); /* function worst case */
- /* NB! usedMode may change here */
- compute_sid_flag = tx_dtx_handler(st->dtx_encSt,
- vad_flag,
- usedMode);
- }
- else
- {
- compute_sid_flag = 0; move16 ();
- }
-
- /*------------------------------------------------------------------------*
- * - Perform LPC analysis: *
- * * autocorrelation + lag windowing *
- * * Levinson-durbin algorithm to find a[] *
- * * convert a[] to lsp[] *
- * * quantize and code the LSPs *
- * * find the interpolated LSPs and convert to a[] for all *
- * subframes (both quantized and unquantized) *
- *------------------------------------------------------------------------*/
-
- /* LP analysis */
- lpc(st->lpcSt, mode, st->p_window, st->p_window_12k2, A_t);
- fwc (); /* function worst case */
- /* From A(z) to lsp. LSP quantization and interpolation */
- lsp(st->lspSt, mode, *usedMode, A_t, Aq_t, lsp_new, &ana);
-
- fwc (); /* function worst case */
- /* Buffer lsp's and energy */
- dtx_buffer(st->dtx_encSt,
- lsp_new,
- st->new_speech);
- /* Check if in DTX mode */
- test();
- if (sub_ex(*usedMode, MRDTX) == 0)
- {
- dtx_enc(st->dtx_encSt,
- compute_sid_flag,
- st->lspSt->qSt,
- st->gainQuantSt->gc_predSt,
- &ana);
-
- Set_zero(st->old_exc, PIT_MAX + L_INTERPOL);
- Set_zero(st->mem_w0, M);
- Set_zero(st->mem_err, M);
- Set_zero(st->zero, L_SUBFR);
- Set_zero(st->hvec, L_SUBFR); /* set to zero "h1[-L_SUBFR..-1]" */
- /* Reset lsp states */
- lsp_reset(st->lspSt);
- Copy(lsp_new, st->lspSt->lsp_old, M);
- Copy(lsp_new, st->lspSt->lsp_old_q, M);
-
- /* Reset clLtp states */
- cl_ltp_reset(st->clLtpSt);
- st->sharp = SHARPMIN; move16 ();
- }
- else
- {
- /* check resonance in the filter */
- lsp_flag = check_lsp(st->tonStabSt, st->lspSt->lsp_old); move16 ();
- }
-
- /*----------------------------------------------------------------------*
- * - Find the weighted input speech w_sp[] for the whole speech frame *
- * - Find the open-loop pitch delay for first 2 subframes *
- * - Set the range for searching closed-loop pitch in 1st subframe *
- * - Find the open-loop pitch delay for last 2 subframes *
- *----------------------------------------------------------------------*/
- #ifdef VAD2
- if (st->dtx)
- { /* no test() call since this if is only in simulation env */
- st->vadSt->L_Rmax = 0; move32 ();
- st->vadSt->L_R0 = 0; move32 ();
- }
- #endif
- for(subfrNr = 0, i_subfr = 0;
- subfrNr < L_FRAME/L_FRAME_BY2;
- subfrNr++, i_subfr += L_FRAME_BY2)
- {
- /* Pre-processing on 80 samples */
- pre_big(mode, gamma1, gamma1_12k2, gamma2, A_t, i_subfr, st->speech,
- st->mem_w, st->wsp);
-
- test (); test ();
- if ((sub_ex(mode, MR475) != 0) && (sub_ex(mode, MR515) != 0))
- {
- /* Find open loop pitch lag for two subframes */
- ol_ltp(st->pitchOLWghtSt, st->vadSt, mode, &st->wsp[i_subfr],
- &T_op[subfrNr], st->old_lags, st->ol_gain_flg, subfrNr,
- st->dtx);
- }
- }
- fwc (); /* function worst case */
- test (); test();
- if ((sub_ex(mode, MR475) == 0) || (sub_ex(mode, MR515) == 0))
- {
- /* Find open loop pitch lag for ONE FRAME ONLY */
- /* search on 160 samples */
-
- ol_ltp(st->pitchOLWghtSt, st->vadSt, mode, &st->wsp[0], &T_op[0],
- st->old_lags, st->ol_gain_flg, 1, st->dtx);
- T_op[1] = T_op[0]; move16 ();
- }
- fwc (); /* function worst case */
-
- #ifdef VAD2
- if (st->dtx)
- { /* no test() call since this if is only in simulation env */
- LTP_flag_update(st->vadSt, mode);
- }
- #endif
- #ifndef VAD2
- /* run VAD pitch detection */
- if (st->dtx)
- { /* no test() call since this if is only in simulation env */
- vad_pitch_detection(st->vadSt, T_op);
- }
- #endif
- fwc (); /* function worst case */
- if (sub_ex(*usedMode, MRDTX) == 0)
- {
- goto the_end;
- }
-
- /*------------------------------------------------------------------------*
- * Loop for every subframe in the analysis frame *
- *------------------------------------------------------------------------*
- * To find the pitch and innovation parameters. The subframe size is *
- * L_SUBFR and the loop is repeated L_FRAME/L_SUBFR times. *
- * - find the weighted LPC coefficients *
- * - find the LPC residual signal res[] *
- * - compute the target signal for pitch search *
- * - compute impulse response of weighted synthesis filter (h1[]) *
- * - find the closed-loop pitch parameters *
- * - encode the pitch dealy *
- * - update the impulse response h1[] by including fixed-gain pitch *
- * - find target vector for codebook search *
- * - codebook search *
- * - encode codebook address *
- * - VQ of pitch and codebook gains *
- * - find synthesis speech *
- * - update states of weighting filter *
- *------------------------------------------------------------------------*/
- A = A_t; /* pointer to interpolated LPC parameters */
- Aq = Aq_t; /* pointer to interpolated quantized LPC parameters */
- evenSubfr = 0; move16 ();
- subfrNr = -1; move16 ();
- for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR)
- {
- subfrNr = add_ex(subfrNr, 1);
- evenSubfr = sub_ex(1, evenSubfr);
- /* Save states for the MR475 mode */
- test(); test();
- if ((evenSubfr != 0) && (sub_ex(*usedMode, MR475) == 0))
- {
- Copy(st->mem_syn, mem_syn_save, M);
- Copy(st->mem_w0, mem_w0_save, M);
- Copy(st->mem_err, mem_err_save, M);
- sharp_save = st->sharp;
- }
-
- /*-----------------------------------------------------------------*
- * - Preprocessing of subframe *
- *-----------------------------------------------------------------*/
- test();
- if (sub_ex(*usedMode, MR475) != 0)
- {
- subframePreProc(*usedMode, gamma1, gamma1_12k2,
- gamma2, A, Aq, &st->speech[i_subfr],
- st->mem_err, st->mem_w0, st->zero,
- st->ai_zero, &st->exc[i_subfr],
- st->h1, xn, res, st->error);
- }
- else
- { /* MR475 */
- subframePreProc(*usedMode, gamma1, gamma1_12k2,
- gamma2, A, Aq, &st->speech[i_subfr],
- st->mem_err, mem_w0_save, st->zero,
- st->ai_zero, &st->exc[i_subfr],
- st->h1, xn, res, st->error);
- /* save impulse response (modified in cbsearch) */
- test ();
- if (evenSubfr != 0)
- {
- Copy (st->h1, h1_sf0, L_SUBFR);
- }
- }
-
- /* copy the LP residual (res2 is modified in the CL LTP search) */
- Copy (res, res2, L_SUBFR);
- fwc (); /* function worst case */
-
- /*-----------------------------------------------------------------*
- * - Closed-loop LTP search *
- *-----------------------------------------------------------------*/
- cl_ltp(st->clLtpSt, st->tonStabSt, *usedMode, i_subfr, T_op, st->h1,
- &st->exc[i_subfr], res2, xn, lsp_flag, xn2, y1,
- &T0, &T0_frac, &gain_pit, gCoeff, &ana,
- &gp_limit);
- /* update LTP lag history */
- move16 (); test(); test ();
- if ((subfrNr == 0) && (st->ol_gain_flg[0] > 0))
- {
- st->old_lags[1] = T0; move16 ();
- }
-
- move16 (); test(); test ();
- if ((sub_ex(subfrNr, 3) == 0) && (st->ol_gain_flg[1] > 0))
- {
- st->old_lags[0] = T0; move16 ();
- }
- fwc (); /* function worst case */
-
- /*-----------------------------------------------------------------*
- * - Inovative codebook search (find index and gain) *
- *-----------------------------------------------------------------*/
- cbsearch(xn2, st->h1, T0, st->sharp, gain_pit, res2,
- code, y2, &ana, *usedMode, subfrNr);
-
- fwc (); /* function worst case */
-
- /*------------------------------------------------------*
- * - Quantization of gains. *
- *------------------------------------------------------*/
- gainQuant(st->gainQuantSt, *usedMode, res, &st->exc[i_subfr], code,
- xn, xn2, y1, y2, gCoeff, evenSubfr, gp_limit,
- &gain_pit_sf0, &gain_code_sf0,
- &gain_pit, &gain_code, &ana);
-
- fwc (); /* function worst case */
- /* update gain history */
- update_gp_clipping(st->tonStabSt, gain_pit);
-
- test();
- if (sub_ex(*usedMode, MR475) != 0)
- {
- /* Subframe Post Porcessing */
- subframePostProc(st->speech, *usedMode, i_subfr, gain_pit,
- gain_code, Aq, synth, xn, code, y1, y2, st->mem_syn,
- st->mem_err, st->mem_w0, st->exc, &st->sharp);
- }
- else
- {
- test();
- if (evenSubfr != 0)
- {
- i_subfr_sf0 = i_subfr; move16 ();
- Copy(xn, xn_sf0, L_SUBFR);
- Copy(y2, y2_sf0, L_SUBFR);
- Copy(code, code_sf0, L_SUBFR);
- T0_sf0 = T0; move16 ();
- T0_frac_sf0 = T0_frac; move16 ();
-
- /* Subframe Post Porcessing */
- subframePostProc(st->speech, *usedMode, i_subfr, gain_pit,
- gain_code, Aq, synth, xn, code, y1, y2,
- mem_syn_save, st->mem_err, mem_w0_save,
- st->exc, &st->sharp);
- st->sharp = sharp_save; move16();
- }
- else
- {
- /* update both subframes for the MR475 */
-
- /* Restore states for the MR475 mode */
- Copy(mem_err_save, st->mem_err, M);
-
- /* re-build excitation for sf 0 */
- Pred_lt_3or6(&st->exc[i_subfr_sf0], T0_sf0, T0_frac_sf0,
- L_SUBFR, 1);
- Convolve(&st->exc[i_subfr_sf0], h1_sf0, y1, L_SUBFR);
-
- Aq -= MP1;
- subframePostProc(st->speech, *usedMode, i_subfr_sf0,
- gain_pit_sf0, gain_code_sf0, Aq,
- synth, xn_sf0, code_sf0, y1, y2_sf0,
- st->mem_syn, st->mem_err, st->mem_w0, st->exc,
- &sharp_save); /* overwrites sharp_save */
- Aq += MP1;
-
- /* re-run pre-processing to get xn right (needed by postproc) */
- /* (this also reconstructs the unsharpened h1 for sf 1) */
- subframePreProc(*usedMode, gamma1, gamma1_12k2,
- gamma2, A, Aq, &st->speech[i_subfr],
- st->mem_err, st->mem_w0, st->zero,
- st->ai_zero, &st->exc[i_subfr],
- st->h1, xn, res, st->error);
-
- /* re-build excitation sf 1 (changed if lag < L_SUBFR) */
- Pred_lt_3or6(&st->exc[i_subfr], T0, T0_frac, L_SUBFR, 1);
- Convolve(&st->exc[i_subfr], st->h1, y1, L_SUBFR);
-
- subframePostProc(st->speech, *usedMode, i_subfr, gain_pit,
- gain_code, Aq, synth, xn, code, y1, y2,
- st->mem_syn, st->mem_err, st->mem_w0,
- st->exc, &st->sharp);
- }
- }
-
- fwc (); /* function worst case */
-
- A += MP1; /* interpolated LPC parameters for next subframe */
- Aq += MP1;
- }
- Copy(&st->old_exc[L_FRAME], &st->old_exc[0], PIT_MAX + L_INTERPOL);
-
- the_end:
-
- /*--------------------------------------------------*
- * Update signal for next frame. *
- *--------------------------------------------------*/
- Copy(&st->old_wsp[L_FRAME], &st->old_wsp[0], PIT_MAX);
-
- Copy(&st->old_speech[L_FRAME], &st->old_speech[0], L_TOTAL - L_FRAME);
- fwc (); /* function worst case */
-
- return 0;
- }
|