www.pudn.com > SMV_Code.rar > lib_ini.c
/*=========================================================================*/
/* Each of the companies; Ericsson, Lucent, Mindspeed, Motorola, Nokia, */
/* Nortel Networks, and Qualcomm (hereinafter referred to individually as */
/* “Source” or collectively as “Sources”) do hereby state: */
/* */
/* To the extent to which the Source(s) may legally and freely do so, */
/* the Source(s), upon submission of a Contribution, grant(s) a free, */
/* irrevocable, non-exclusive, license to the Third Generation Partnership */
/* Project 2 (3GPP2) and its Organizational Partners: ARIB, CCSA, TIA, */
/* TTA, and TTC, under the Source’s copyright or copyright license rights */
/* in the Contribution, to, in whole or in part, copy, make derivative */
/* works, perform, display and distribute the Contribution and derivative */
/* works thereof consistent with 3GPP2’s and each Organizational Partner’s */
/* policies and procedures, with the right to (i) sublicense the foregoing */
/* rights consistent with 3GPP2’s and each Organizational Partner’s */
/* policies and procedures and (ii) copyright and sell, if applicable) in */
/* 3GPP2's name or each Organizational Partner’s name any 3GPP2 or */
/* transposed Publication even though this Publication may contain the */
/* Contribution or a derivative work thereof. The Contribution shall */
/* disclose any known limitations on the Source’s rights to license as */
/* herein provided. */
/* */
/* When a Contribution is submitted by the Source(s) to assist the */
/* formulating groups of 3GPP2 or any of its Organizational Partners, */
/* it is proposed to the Committee as a basis for discussion and is not */
/* to be construed as a binding proposal on the Source(s). The Source(s) */
/* specifically reserve(s) the right to amend or modify the material */
/* contained in the Contribution. Nothing contained in the Contribution */
/* shall, except as herein expressly provided, be construed as conferring */
/* by implication, estoppel or otherwise, any license or right under */
/* (i) any existing or later issuing patent, whether or not the use of */
/* information in the document necessarily employs an invention of any */
/* existing or later issued patent, (ii) any copyright, (iii) any */
/* trademark, or (iv) any other intellectual property right. */
/* */
/* With respect to the Software necessary for the practice of any or all */
/* Normative portions of the Selectable Mode Vocoder (SMV) as it exists on */
/* the date of submittal of this form, should the SMV be approved as a */
/* Specification or Report by 3GPP2, or as a transposed Standard by any of */
/* the 3GPP2’s Organizational Partners, the Source(s) state(s) that a */
/* worldwide license to reproduce, use and distribute the Software, the */
/* license rights to which are held by the Source(s), will be made */
/* available to applicants under terms and conditions that are reasonable */
/* and non-discriminatory, which may include monetary compensation, */
/* and only to the extent necessary for the practice of any or all of the */
/* Normative portions of the SMV or the field of use of practice of the */
/* SMV Specification, Report, or Standard. The statement contained above */
/* is irrevocable and shall be binding upon the Source(s). In the event */
/* the rights of the Source(s) in and to copyright or copyright license */
/* rights subject to such commitment are assigned or transferred, */
/* the Source(s) shall notify the assignee or transferee of the existence */
/* of such commitments. */
/*=========================================================================*/
/* */
/*-------------------------------------------------------------------*/
/*===================================================================*/
/* LIBRARY: lib_ini.c */
/*-------------------------------------------------------------------*/
/* PURPOSE : General Initialisation Library. */
/*===================================================================*/
/*----------------------------------------------------------------------------*/
/*-------------------------------- INCLUDE -----------------------------------*/
/*----------------------------------------------------------------------------*/
#include "typedef.h"
#include "const.h"
#include "main.h"
#include "mcutil.h"
#include "gputil.h"
#include "ext_var.h"
#include "lib_ini.h"
#include "lib_lpc.h"
#include "lib_qlsf.h"
#include "lib_geq.h"
#include "lib_vad.h"
#include "lib_ppr.h"
#include "lib_cla.h"
#include "lib_snr.h"
#include "lib_pwf.h"
#include "lib_pit.h"
#include "lib_ltp.h"
#include "lib_smo.h"
#include "lib_prc.h"
#include "lib_bit.h"
#include "lib_ppp.h"
#include "lib_gcb.h"
#include "lib_fcs.h"
#include "lib_mus.h"
/*----------------------------------------------------------------------------*/
/*-------------------------------- FUNCTIONS ---------------------------------*/
/*----------------------------------------------------------------------------*/
/*===================================================================*/
/* FUNCTION : INI_allocate_memory (). */
/*-------------------------------------------------------------------*/
/* PURPOSE : This function performs memory allocation. */
/*-------------------------------------------------------------------*/
/* INPUT ARGUMENTS : */
/* _ None. */
/*-------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS : */
/* _ None. */
/*-------------------------------------------------------------------*/
/* INPUT/OUTPUT ARGUMENTS : */
/* _ None. */
/*-------------------------------------------------------------------*/
/* RETURN ARGUMENTS : */
/* _ None. */
/*===================================================================*/
void INI_allocate_memory ( void )
{
/*-------------------------------------------------------------------*/
/* Memory Allocation counter initialisation */
/*-------------------------------------------------------------------*/
#ifdef DRAM_ROM_TEST
ROM_FLOAT64_counter = 0;
RAM_FLOAT64_counter = 0;
SP_RAM_FLOAT64_counter = 0;
ROM_INT16_counter = 0;
RAM_INT16_counter = 0;
SP_RAM_INT16_counter = 0;
SP_RAM_FLOAT64_max = 0;
SP_RAM_INT16_max = 0;
flag_RAM = 1;
#endif
/*-------------------------------------------------------------------*/
/* Memory Allocation for NoiseSupression */
/*-------------------------------------------------------------------*/
#ifdef ENC_CMP
curr_ns_snr = dvector(0, 1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Allocation for Time-Domain Pre Filtering */
/*-------------------------------------------------------------------*/
#ifdef ENC_CMP
pre_flt_buf = dvector (0, PPR_FLT_ORDER-1);
lp_flt_num = dvector (0, LP_FLT_ORDER-1);
lp_flt_buf = dvector (0, LP_FLT_ORDER-1);
/*-------------------------------------------------------------------*/
/* Memory Allocation for Silence Enhancement */
/*-------------------------------------------------------------------*/
zeroed = svector (0, SE_MEM_SIZE-1);
zero_rate = dvector (0, SE_MEM_SIZE-1);
low_rate = dvector (0, SE_MEM_SIZE-1);
high_rate = dvector (0, SE_MEM_SIZE-1);
low_neg = dvector (0, 1);
low_pos = dvector (0, 1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Allocation for Time-Domain Post Filtering */
/*-------------------------------------------------------------------*/
#ifdef DEC_CMP
buff_LTpost = dvector (0, MAX_LAG+L_SF-1);
PF_mem_syn = dvector (0, NP-1);
/*-------------------------------------------------------------------*/
/* Memory Allocation for Time-Domain Post Filtering */
/*-------------------------------------------------------------------*/
pst_flt_buf = dvector (0, PPR_FLT_ORDER-1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Allocation for Linear Prediction Analysis */
/*-------------------------------------------------------------------*/
#ifdef ENC_CMP
refl_mem = dvector (0, NP-1);
lsf_new = dvector (0, NP-1);
lsf_old = dvector (0, NP-1);
lsf_mem = dvector (0, NP-1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Allocation for the LSF quantization */
/*-------------------------------------------------------------------*/
#ifdef ENC_CMP
qes = dmatrix (0, LQMA_40k-1, 0, NP-1);
lsfq_old = dvector (0, NP-1);
#endif
#ifdef DEC_CMP
qes_dec = dmatrix (0, LQMA_40k-1, 0, NP-1);
lsfq_old_dec = dvector (0, NP-1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Allocation for Perceptual Weighting */
/*-------------------------------------------------------------------*/
#ifdef ENC_CMP
wspeech_mem = dvector (0, L_OLPIT-L_FRM-L_LPCLHD-1);
ws_syn_buf = dvector (0, NP-1);
tmp_ws_m = dvector (0, NP-1);
ms_syn_buf = dvector (0, NP-1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Allocation for Signal Classification */
/*-------------------------------------------------------------------*/
#ifdef ENC_CMP
voiced_mem = svector (0, 1);
sig_ppr_mem = dvector (0, L_FRM+MEM_CLASS+L_LPCLHD-1);
Lp_buffer = dvector (0, N_LP-1);
cond_mem = svector (0, 2);
buffer_wtilt = dvector (0, MAX_N_SF-1);
buffer_wmax = dvector (0, MAX_N_SF-1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Allocation for Voice Activity Detection */
/*-------------------------------------------------------------------*/
#ifdef ENC_CMP
lag_buf = svector (0, LTP_BUFF_SIZE-1);
pgain_buf = dvector (0, LTP_BUFF_SIZE-1);
flag_vad_mem = svector (0, FLAG_VAD_MEM_SIZE-1);
pcorr_buf = dvector (0, LTP_BUFF_SIZE-1);
mrc = dvector (0, NP-1);
vad_lsf_mem = dmatrix (0, VAD_MEM_SIZE-1, 0, NP-1);
min_energy_mem = dvector (0, VAD_MIN_MEM_SIZE-1);
mean_lsf = dvector (0, NP-1);
norm_mean_lsf = dvector (0, NP-1);
prev_cml_lsf_diff = dvector (0, VAD_MEM_SIZE-1);
prev_energy = dvector (0, VAD_MEM_SIZE-1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Allocation for Smoothing parameters estimation */
/*-------------------------------------------------------------------*/
#ifdef ENC_CMP
lsf_smooth = dvector (0, NP-1);
ma_lsf = dvector (0, NP-1);
dSP_buf = dvector (0, DSP_BUFF_SIZE-1);;
buffer_smo = dvector (0, HI_LAG2+L_SF-1);
buffer_sum_smo = dvector (0, SMO_BUFF_SIZE-1);
buffer_max_smo = dvector (0, SMO_BUFF_SIZE-1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Allocation for Open Loop Pitch Detection */
/*-------------------------------------------------------------------*/
#ifdef ENC_CMP
ol_lag = svector(0, N_SF_MAX);
lag_enc = svector(0, N_SF_MAX);
#endif
#ifdef DEC_CMP
lag_dec = svector(0, N_SF_MAX);
#endif
#ifdef ENC_CMP
PITmax0 = svector (0, NUM_MAX_SRCH-1);
Rmax0 = dvector (0, NUM_MAX_SRCH-1);
pitch_f_enc_mem = dvector (0, PIT_F_MEM-1);
#endif
#ifdef DEC_CMP
pitch_f_dec_mem = dvector (0, PIT_F_MEM-1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Allocation for Pitch Pre-processing */
/*-------------------------------------------------------------------*/
#ifdef ENC_CMP
targ_mem = dvector (0, MAX_LAG-1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Allocation for Closed Loop Pitch Detection */
/*-------------------------------------------------------------------*/
#ifdef ENC_CMP
NewTg_mem = dvector (0, NP-1);
ext = dvector (0, MAX_LAG+L_SF-1);
lag_f_enc = dvector (0, N_SF_MAX-1);
#endif
#ifdef DEC_CMP
lag_f_dec = dvector (0, N_SF_MAX-1);
ext_dec = dvector (0, MAX_LAG+L_SF-1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Allocation for Short Term Algebraic Analysis */
/*-------------------------------------------------------------------*/
#ifdef ENC_CMP
dyn_track_enc = smatrix(0, 2-1, 0, 16-1);
PHI = dmatrix(0, L_SF4-1, 0, L_SF4-1);
#endif
#ifdef DEC_CMP
dyn_track_dec = smatrix(0, 2-1, 0, 16-1);
#endif
#ifdef DEC_CMP
/* For FEC Only it could be regenerated using GCB_gauss_excit_dec */
qua_unfcod = dmatrix (0, 1, 0, L_FRM-1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Allocation for Gain Vector Quantisation */
/*-------------------------------------------------------------------*/
#ifdef ENC_CMP
/* Can be reduce to one memory */
past_energyq_2d_enc = dvector (0, GVQ_VEC_SIZE_2D-1);
past_energyq_3d_enc = dvector (0, GVQ_VEC_SIZE_3D-1);
past_energyq_4d_enc = dvector (0, GVQ_VEC_SIZE_4D-1);
#endif
#ifdef DEC_CMP
/* Can be reduce to one memory */
past_energyq_2d_dec = dvector (0, GVQ_VEC_SIZE_2D-1);
past_energyq_3d_dec = dvector (0, GVQ_VEC_SIZE_3D-1);
past_energyq_4d_dec = dvector (0, GVQ_VEC_SIZE_4D-1);
/* DECODER Only static */
qua_gainQ = dmatrix (0, 1, 0, N_SF_MAX-1);
gp_buf = dvector (0, GP_BUF_SIZE-1);
Prev_Beta_Pitch = dvector (0, BETA_BUF_SIZE-1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Allocation for Frame Erasure Concealenement */
/*-------------------------------------------------------------------*/
#ifdef DEC_CMP
enrg_buff = dvector(0, ERNG_MEM_SIZE-1);
ext_dec_fec = dvector (0, MAX_LAG+L_SF-1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Allocation for Speech Synthesis */
/*-------------------------------------------------------------------*/
#ifdef ENC_CMP
synth_mem = dvector (0, NP-1);
dif_mem = dvector (0, NP-1);
target_mem = dvector (0, NP-1);
#endif
#ifdef DEC_CMP
synth_mem_dec = dvector (0, NP-1);
sigsyn_dec_mem = dvector (0, NP-1);
#endif
#ifdef DEC_CMP
/*-------------------------------------------------------------------*/
/* Memory Allocation for Bad-Rate Detection */
/*-------------------------------------------------------------------*/
type1en = svector (0, LEN_TYPE1EN-1);
#endif
#ifdef DRAM_ROM_TEST
/*-------------------------------------------------------------------*/
/* Print the estimation of the static RAM */
/*-------------------------------------------------------------------*/
printf ("\n\n\nStatic RAM");
printf ("\nFLOAT64 WORDS:\t%d", RAM_FLOAT64_counter);
printf ("\nINT16 WORDS:\t%d\n", RAM_INT16_counter);
flag_RAM = 2;
#endif
/*-------------------------------------------------------------------*/
return;
/*-------------------------------------------------------------------*/
}
/*----------------------------------------------------------------------------*/
/*===================================================================*/
/* FUNCTION : INI_deallocate_memory (). */
/*-------------------------------------------------------------------*/
/* PURPOSE : This function performs memory deallocation. */
/*-------------------------------------------------------------------*/
/* INPUT ARGUMENTS : */
/* _ None. */
/*-------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS : */
/* _ None. */
/*-------------------------------------------------------------------*/
/* INPUT/OUTPUT ARGUMENTS : */
/* _ None. */
/*-------------------------------------------------------------------*/
/* RETURN ARGUMENTS : */
/* _ None. */
/*===================================================================*/
void INI_deallocate_memory ( void )
{
/*-------------------------------------------------------------------*/
/* Memory Allocation for NoiseSupression */
/*-------------------------------------------------------------------*/
#ifdef DRAM_ROM_TEST
flag_RAM = 1;
#endif
#ifdef ENC_CMP
free_dvector(curr_ns_snr, 0, 1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Deallocation for Time-Domain Pre Filtering */
/*-------------------------------------------------------------------*/
#ifdef ENC_CMP
free_dvector (pre_flt_buf, 0, PPR_FLT_ORDER-1);
free_dvector (lp_flt_num, 0, LP_FLT_ORDER-1);
free_dvector (lp_flt_buf, 0, LP_FLT_ORDER-1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Deallocation for Time-Domain Silence Enhancement */
/*-------------------------------------------------------------------*/
#ifdef ENC_CMP
free_svector (zeroed, 0, SE_MEM_SIZE-1);
free_dvector (zero_rate, 0, SE_MEM_SIZE-1);
free_dvector (low_rate, 0, SE_MEM_SIZE-1);
free_dvector (high_rate, 0, SE_MEM_SIZE-1);
free_dvector (low_neg, 0, 1);
free_dvector (low_pos, 0, 1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Deallocation for Time-Domain Post Filtering */
/*-------------------------------------------------------------------*/
#ifdef DEC_CMP
free_dvector (buff_LTpost, 0, MAX_LAG+L_SF-1);
free_dvector (PF_mem_syn, 0, NP-1);
free_dvector (pst_flt_buf, 0, PPR_FLT_ORDER-1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Deallocation for Linear Prediction Analysis */
/*-------------------------------------------------------------------*/
#ifdef ENC_CMP
free_dvector (refl_mem, 0, NP-1);
free_dvector (lsf_new, 0, NP-1);
free_dvector (lsf_old, 0, NP-1);
free_dvector (lsf_mem, 0, NP-1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Allocation for the LSF quantization */
/*-------------------------------------------------------------------*/
#ifdef ENC_CMP
free_dmatrix (qes, 0, LQMA_40k-1, 0, NP-1);
free_dvector (lsfq_old, 0, NP-1);
#endif
#ifdef DEC_CMP
free_dmatrix (qes_dec, 0, LQMA_40k-1, 0, NP-1);
free_dvector (lsfq_old_dec, 0, NP-1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Deallocation for Perceptual Weighting */
/*-------------------------------------------------------------------*/
#ifdef ENC_CMP
free_dvector (wspeech_mem, 0, L_OLPIT-L_FRM-L_LPCLHD-1);
free_dvector (ws_syn_buf, 0, NP-1);
free_dvector (tmp_ws_m, 0, NP-1);
free_dvector (ms_syn_buf, 0, NP-1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Deallocation for Signal Classification */
/*-------------------------------------------------------------------*/
#ifdef ENC_CMP
free_svector (voiced_mem, 0, 1);
free_dvector (sig_ppr_mem, 0, L_FRM+MEM_CLASS+L_LPCLHD-1);
free_dvector (Lp_buffer, 0, N_LP-1);
free_svector (cond_mem, 0, 2);
free_dvector (buffer_wtilt, 0, MAX_N_SF-1);
free_dvector (buffer_wmax, 0, MAX_N_SF-1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Deallocation for Voice Activity Detection */
/*-------------------------------------------------------------------*/
#ifdef ENC_CMP
free_svector (lag_buf, 0, LTP_BUFF_SIZE-1);
free_dvector (pgain_buf, 0, LTP_BUFF_SIZE-1);
free_svector (flag_vad_mem, 0, FLAG_VAD_MEM_SIZE-1);
free_dvector (pcorr_buf, 0, LTP_BUFF_SIZE-1);
free_dvector (mrc, 0, NP-1);
free_dmatrix (vad_lsf_mem, 0, VAD_MEM_SIZE-1, 0, NP-1);
free_dvector (min_energy_mem, 0, VAD_MIN_MEM_SIZE-1);
free_dvector (mean_lsf, 0, NP-1);
free_dvector (norm_mean_lsf, 0, NP-1);
free_dvector (prev_cml_lsf_diff, 0, VAD_MEM_SIZE-1);
free_dvector (prev_energy, 0, VAD_MEM_SIZE-1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Deallocation for Smoothing parameters estimation */
/*-------------------------------------------------------------------*/
#ifdef ENC_CMP
free_dvector (lsf_smooth, 0, NP-1);
free_dvector (ma_lsf, 0, NP-1);
free_dvector (dSP_buf, 0, DSP_BUFF_SIZE-1);;
free_dvector (buffer_smo, 0, HI_LAG2+L_SF-1);
free_dvector (buffer_sum_smo, 0, SMO_BUFF_SIZE-1);
free_dvector (buffer_max_smo, 0, SMO_BUFF_SIZE-1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Deallocation for Open Loop Pitch Detection */
/*-------------------------------------------------------------------*/
#ifdef ENC_CMP
free_svector (ol_lag, 0, N_SF_MAX);
free_svector (lag_enc, 0, N_SF_MAX);
#endif
#ifdef DEC_CMP
free_svector (lag_dec, 0, N_SF_MAX);
#endif
#ifdef ENC_CMP
free_svector (PITmax0, 0, NUM_MAX_SRCH-1);
free_dvector (Rmax0, 0, NUM_MAX_SRCH-1);
free_dvector (pitch_f_enc_mem, 0, PIT_F_MEM-1);
#endif
#ifdef DEC_CMP
free_dvector (pitch_f_dec_mem, 0, PIT_F_MEM-1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Deallocation for Open Pitch Pre-processing */
/*-------------------------------------------------------------------*/
#ifdef ENC_CMP
free_dvector (targ_mem, 0, MAX_LAG-1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Deallocation for Closed Loop Pitch Detection */
/*-------------------------------------------------------------------*/
#ifdef ENC_CMP
free_dvector (NewTg_mem, 0, NP-1);
free_dvector (ext, 0, MAX_LAG+L_SF-1);
free_dvector (lag_f_enc, 0, N_SF_MAX-1);
#endif
#ifdef DEC_CMP
free_dvector (lag_f_dec, 0, N_SF_MAX-1);
free_dvector (ext_dec, 0, MAX_LAG+L_SF-1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Deallocation for Short Term Algebraic Analysis */
/*-------------------------------------------------------------------*/
#ifdef ENC_CMP
free_smatrix(dyn_track_enc, 0, 2-1, 0, 16-1);
free_dmatrix (PHI, 0, L_SF4-1, 0, L_SF4-1);
#endif
#ifdef DEC_CMP
free_smatrix(dyn_track_dec, 0, 2-1, 0, 16-1);
#endif
#ifdef DEC_CMP
free_dmatrix (qua_unfcod, 0, 1, 0, L_FRM-1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Deallocation for Gain Vector Quantisation */
/*-------------------------------------------------------------------*/
#ifdef ENC_CMP
free_dvector (past_energyq_2d_enc, 0, GVQ_VEC_SIZE_2D-1);
free_dvector (past_energyq_3d_enc, 0, GVQ_VEC_SIZE_3D-1);
free_dvector (past_energyq_4d_enc, 0, GVQ_VEC_SIZE_4D-1);
#endif
#ifdef DEC_CMP
free_dvector (past_energyq_2d_dec, 0, GVQ_VEC_SIZE_2D-1);
free_dvector (past_energyq_3d_dec, 0, GVQ_VEC_SIZE_3D-1);
free_dvector (past_energyq_4d_dec, 0, GVQ_VEC_SIZE_4D-1);
/* DECODER Only static */
free_dmatrix (qua_gainQ, 0, 1, 0, N_SF_MAX-1);
free_dvector (gp_buf, 0, GP_BUF_SIZE-1);
free_dvector (Prev_Beta_Pitch,0, BETA_BUF_SIZE-1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Deallocation for Frame Erasure Concealenement */
/*-------------------------------------------------------------------*/
#ifdef DEC_CMP
free_dvector (enrg_buff, 0, ERNG_MEM_SIZE-1);
free_dvector (ext_dec_fec, 0, MAX_LAG+L_SF-1);
#endif
/*-------------------------------------------------------------------*/
/* Memory Deallocation for Speech Synthesis */
/*-------------------------------------------------------------------*/
#ifdef ENC_CMP
free_dvector (synth_mem, 0, NP-1);
free_dvector (dif_mem, 0, NP-1);
free_dvector (target_mem, 0, NP-1);
#endif
#ifdef DEC_CMP
free_dvector (synth_mem_dec, 0, NP-1);
free_dvector (sigsyn_dec_mem, 0, NP-1);
#endif
#ifdef DEC_CMP
/*-------------------------------------------------------------------*/
/* Memory Allocation for Bad-Rate Detection */
/*-------------------------------------------------------------------*/
free_svector (type1en, 0, LEN_TYPE1EN-1);
#endif
#ifdef DRAM_ROM_TEST
/*-------------------------------------------------------------------*/
/* Check the estimation of RAM and ROM */
/*-------------------------------------------------------------------*/
if ((RAM_FLOAT64_counter != 0) || (RAM_INT16_counter != 0))
{
printf ("\n\n\nError deallocating Static RAM");
printf ("\nFLOAT64 WORDS:\t%d\n", RAM_FLOAT64_counter);
printf ("\nINT16 WORDS:\t%d\n", RAM_INT16_counter);
}
if ((SP_RAM_FLOAT64_counter != 0) || (SP_RAM_INT16_counter != 0))
{
printf ("\n\n\nError deallocating Scratchpad RAM");
printf ("\nFLOAT64 WORDS:\t%d\n", SP_RAM_FLOAT64_counter);
printf ("\nINT16 WORDS:\t%d\n", SP_RAM_INT16_counter);
}
if ((ROM_FLOAT64_counter != 0) || (ROM_INT16_counter != 0))
{
printf ("\n\n\nError deallocating ROM");
printf ("\nFLOAT64 WORDS:\t%d\n", ROM_FLOAT64_counter);
printf ("\nINT16 WORDS:\t%d\n\n\n", ROM_INT16_counter);
}
#endif
/*-------------------------------------------------------------------*/
return;
/*-------------------------------------------------------------------*/
}
/*----------------------------------------------------------------------------*/
#ifdef ENC_CMP
#ifdef DATA
/*===================================================================*/
/* FUNCTION : INI_parameters_setup (). */
/*-------------------------------------------------------------------*/
/* PURPOSE : Performs the encoder parameter initialisation. */
/*-------------------------------------------------------------------*/
/* INPUT ARGUMENTS : */
/* _ (INT32 ) argc: number of input parameters. */
/* _ (char *[]) argv: pointer to the input parameters. */
/*-------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS : */
/* _ (FILE **) fp_speech_in: input speech file. */
/* _ (FILE **) fp_bitstream: input speech file. */
/* _ (FILE **) fp_mode: input speech file. */
/* _ (FILE **) fp_signaling: input speech file. */
/* _ (FILE **) fp_data_in: input data file. */
/* _ (INT16 *) smv_mode: SMV mode. */
/* _ (INT16 *) half_rate_max: HALF-RATE-MAX mode. */
/* _ (INT16 *) data_mode : data transmission mode. */
/*-------------------------------------------------------------------*/
/* INPUT/OUTPUT ARGUMENTS : */
/* _ None. */
/*-------------------------------------------------------------------*/
/* RETURN ARGUMENTS : */
/* _ None. */
/*===================================================================*/
void INI_parameters_setup (INT32 argc, char *argv [], FILE **fp_speech_in,
FILE **fp_bitstream, FILE **fp_mode,
FILE **fp_signaling, INT16 *smv_mode,
INT16 *half_rate_max, FILE **fp_data_in,
INT16 *data_mode)
#else
/*===================================================================*/
/* FUNCTION : INI_parameters_setup (). */
/*-------------------------------------------------------------------*/
/* PURPOSE : Performs the encoder parameter initialisation. */
/*-------------------------------------------------------------------*/
/* INPUT ARGUMENTS : */
/* _ (INT32 ) argc: number of input parameters. */
/* _ (char *[]) argv: pointer to the input parameters. */
/*-------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS : */
/* _ (FILE **) fp_speech_in: input speech file. */
/* _ (FILE **) fp_bitstream: input speech file. */
/* _ (FILE **) fp_mode: input speech file. */
/* _ (FILE **) fp_signaling: input speech file. */
/* _ (INT16 *) smv_mode: SMV mode. */
/* _ (INT16 *) half_rate_max: HALF-RATE-MAX mode. */
/*-------------------------------------------------------------------*/
/* INPUT/OUTPUT ARGUMENTS : */
/* _ None. */
/*-------------------------------------------------------------------*/
/* RETURN ARGUMENTS : */
/* _ None. */
/*===================================================================*/
void INI_parameters_setup (INT32 argc, char *argv [], FILE **fp_speech_in,
FILE **fp_bitstream, FILE **fp_mode,
FILE **fp_signaling, INT16 *smv_mode,
INT16 *half_rate_max)
#endif
{
/*-------------------------------------------------------------------*/
INT16 i, non_switch_cnt;
/*-------------------------------------------------------------------*/
/* Initialisation */
/*-------------------------------------------------------------------*/
*fp_speech_in = NULL;
*fp_bitstream = NULL;
*fp_mode = NULL;
*fp_signaling = NULL;
#ifdef DATA
*fp_data_in = NULL;
*data_mode= 0;
#endif
/*-------------------------------------------------------------------*/
if(argc < 5)
{
#ifdef DATA
printf ("Usage:\n %s -m M [-h] [-f mode_file] [-s signaling_file] [-d data mode] [-D data_in_file] ", argv[0]);
#else
printf ("Usage:\n %s -m M [-h] [-f mode_file] [-s signaling_file] ",
argv[0]);
#endif
printf (" input_speech_file output_bitstream_file\n");
exit(1);
}
else
{
i = 1;
(*smv_mode) = 0;
(*half_rate_max) = 0;
non_switch_cnt = 0;
while (i < argc)
{
if (argv[i][0] != '-')
{
if (non_switch_cnt > 2)
{
#ifdef DATA
printf ("Usage:\n %s -m M [-h] [-f mode_file] [-s signaling_file] [-d data mode] [-D data_in_file] ", argv[0]);
#else
printf ("Usage:\n %s -m M [-h] [-f mode_file] [-s signaling_file] ",
argv[0]);
#endif
printf (" input_speech_file output_bitstream_file\n");
exit (1);
}
if (non_switch_cnt == 0)
{
*fp_speech_in = file_open_rb (argv[i]);
printf("Input speech file : %s\n", argv[i]);
non_switch_cnt++;
}
else
{
*fp_bitstream = file_open_wb (argv[i]);
printf("Output bitstream file : %s\n", argv[i]);
non_switch_cnt++;
}
i++;
}
else
{
switch(argv[i][1])
{
case 'm': i++;
(*smv_mode) = atoi(argv[i]);
if (((*smv_mode) < 0) || ((*smv_mode) > 5))
{
printf("SMV mode = %hd (0, 1, 2, 3, 4 and 5 allowed)\n", (*smv_mode));
exit(0);
}
else
{
printf("SMV MODE: %hd\n", (*smv_mode));
if ((*smv_mode) == 4)
{
(*smv_mode) = 0;
(*half_rate_max) = 1;
}
else if ((*smv_mode) == 5)
{
(*smv_mode) = 1;
(*half_rate_max) = 1;
}
}
i++;
break;
case 'f': i++;
*fp_mode = fopen(argv[i], "r");
if (*fp_mode == NULL)
{
printf("Impossible to open file: %s\n", argv[i]);
exit(0);
}
printf("Mode control file : %s\n", argv[i]);
i++;
break;
case 's': i++;
*fp_signaling = file_open_rb (argv[i]);
printf("Signaling file : %s\n", argv[i]);
i++;
break;
case 'h': i++;
(*half_rate_max) = 1;
break;
#ifdef DATA
case 'D': i++;
*fp_data_in = file_open_rb (argv[i]);
printf("Data file : %s\n", argv[i]);
i++;
break;
case 'd': i++;
*data_mode=atoi(argv[i]);
printf("data_mode = %d\n", *data_mode);
i++;
break;
#endif
default:
#ifdef DATA
printf ("Usage:\n %s -m M [-h] [-f mode_file] [-s signaling_file] [-d data mode] [-D data_in_file] ", argv[0]);
#else
printf ("Usage:\n %s -m M [-h] [-f mode_file] [-s signaling_file] ",
argv[0]);
#endif
printf (" input_speech_file output_bitstream_file\n");
exit (1);
break;
}
}
}
}
/*-------------------------------------------------------------------*/
/* Verify the essential parameters */
/*-------------------------------------------------------------------*/
if (((*fp_speech_in) == NULL) || ((*fp_bitstream) == NULL))
{
#ifdef DATA
printf ("Usage:\n %s -m M [-h] [-f mode_file] [-s signaling_file] [-d data mode] [-D data_in_file] ", argv[0]);
#else
printf ("Usage:\n %s -m M [-h] [-f mode_file] [-s signaling_file] ",
argv[0]);
#endif
printf (" input_speech_file output_bitstream_file\n");
exit (1);
}
/*-------------------------------------------------------------------*/
return;
/*-------------------------------------------------------------------*/
}
#endif
/*----------------------------------------------------------------------------*/
#ifdef ENC_CMP
/*===================================================================*/
/* FUNCTION : INI_pointer_setup_enc (). */
/*-------------------------------------------------------------------*/
/* PURPOSE : Performs the encoder pointers initialisation. */
/* This function should be called just after the */
/* switching between decoder and encoder to preserve */
/* the corruption of the state variables of the decoder */
/* in the full-duplex applications. */
/*-------------------------------------------------------------------*/
/* INPUT ARGUMENTS : */
/* _ None. */
/*-------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS : */
/* _ None. */
/*-------------------------------------------------------------------*/
/* INPUT/OUTPUT ARGUMENTS : */
/* _ None. */
/*-------------------------------------------------------------------*/
/* RETURN ARGUMENTS : */
/* _ None. */
/*===================================================================*/
void INI_pointer_setup_enc (void)
{
/*-------------------------------------------------------------------*/
past_energyq_4d = past_energyq_4d_enc;
past_energyq_3d = past_energyq_3d_enc;
past_energyq_2d = past_energyq_2d_enc;
lag = lag_enc;
pitch_f_mem = pitch_f_enc_mem;
lag_f = lag_f_enc;
track = track_enc;
dyn_track = dyn_track_enc;
MaxIdx = MaxIdx_enc;
/*-------------------------------------------------------------------*/
return;
/*-------------------------------------------------------------------*/
}
#endif
/*----------------------------------------------------------------------------*/
#ifdef DEC_CMP
/*===================================================================*/
/* FUNCTION : INI_pointer_setup_dec (). */
/*-------------------------------------------------------------------*/
/* PURPOSE : Performs the encoder pointers initialisation. */
/* This function should be called just after the */
/* switching between encoder end decoder to preserve */
/* the corruption of the state variables of the encoder */
/* in the full-duplex applications. */
/*-------------------------------------------------------------------*/
/* INPUT ARGUMENTS : */
/* _ None. */
/*-------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS : */
/* _ None. */
/*-------------------------------------------------------------------*/
/* INPUT/OUTPUT ARGUMENTS : */
/* _ None. */
/*-------------------------------------------------------------------*/
/* RETURN ARGUMENTS : */
/* _ None. */
/*===================================================================*/
void INI_pointer_setup_dec (void)
{
/*-------------------------------------------------------------------*/
past_energyq_4d = past_energyq_4d_dec;
past_energyq_3d = past_energyq_3d_dec;
past_energyq_2d = past_energyq_2d_dec;
lag = lag_dec;
pitch_f_mem = pitch_f_dec_mem;
lag_f = lag_f_dec;
track = track_dec;
dyn_track = dyn_track_dec;
MaxIdx = MaxIdx_dec;
/*-------------------------------------------------------------------*/
return;
/*-------------------------------------------------------------------*/
}
#endif
/*----------------------------------------------------------------------------*/
#ifdef ENC_CMP
/*===================================================================*/
/* FUNCTION : INI_reset_encoder (). */
/*-------------------------------------------------------------------*/
/* PURPOSE : Reset the encoder memories. */
/*-------------------------------------------------------------------*/
/* ALGORITHM : */
/*-------------------------------------------------------------------*/
/* INPUT ARGUMENTS : */
/* _ None. */
/*-------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS : */
/* _ None. */
/*-------------------------------------------------------------------*/
/* INPUT/OUTPUT ARGUMENTS : */
/* _ None. */
/*-------------------------------------------------------------------*/
/* RETURN ARGUMENTS : */
/* _ None. */
/*===================================================================*/
void INI_reset_encoder(void)
{
/*-------------------------------------------------------------------*/
INI_pointer_setup_enc ();
/*-------------------------------------------------------------------*/
GEQ_init_lib ();
LPC_init_lib ();
LSF_Q_init_lib ();
GCB_init_lib ();
FCS_init_lib ();
LTP_init_lib ();
SNR_init_lib();
ini_dvector (synth_mem, 0, NP-1, 0.0);
ini_dvector (dif_mem, 0, NP-1, 0.0);
ini_dvector (target_mem, 0, NP-1, 0.0);
/*-------------------------------------------------------------------*/
return;
/*-------------------------------------------------------------------*/
}
/*----------------------------------------------------------------------------*/
/*===================================================================*/
/* FUNCTION : INI_init_encoder (). */
/*-------------------------------------------------------------------*/
/* PURPOSE : Performs the encoder initialisation. */
/*-------------------------------------------------------------------*/
/* ALGORITHM : */
/*-------------------------------------------------------------------*/
/* INPUT ARGUMENTS : */
/* _ None. */
/*-------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS : */
/* _ None. */
/*-------------------------------------------------------------------*/
/* INPUT/OUTPUT ARGUMENTS : */
/* _ None. */
/*-------------------------------------------------------------------*/
/* RETURN ARGUMENTS : */
/* _ None. */
/*===================================================================*/
void INI_init_encoder(void)
{
/*-------------------------------------------------------------------*/
fix_rate = RATE8_5K;
/*-------------------------------------------------------------------*/
INI_pointer_setup_enc ();
/*-------------------------------------------------------------------*/
PPR_silence_enhan_init ();
VAD_init_lib ();
CLA_init_lib ();
PPP_init_lib ();
PIT_init_lib ();
GEQ_init_lib ();
LPC_init_lib ();
PWF_init_lib ();
SMO_init_lib ();
LSF_Q_init_lib ();
SNR_init_lib();
GCB_init_lib ();
FCS_init_lib ();
LTP_init_lib ();
PRC_init_lib ();
MUS_init_lib ();
ini_dvector (synth_mem, 0, NP-1, 0.0);
ini_dvector (dif_mem, 0, NP-1, 0.0);
ini_dvector (target_mem, 0, NP-1, 0.0);
/*-------------------------------------------------------------------*/
return;
/*-------------------------------------------------------------------*/
}
#endif
/*----------------------------------------------------------------------------*/
#ifdef DEC_CMP
/*===================================================================*/
/* FUNCTION : INI_reset_decoder (). */
/*-------------------------------------------------------------------*/
/* PURPOSE : Rest the decoder memories. */
/*-------------------------------------------------------------------*/
/* ALGORITHM : */
/*-------------------------------------------------------------------*/
/* INPUT ARGUMENTS : */
/* _ None. */
/*-------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS : */
/* _ None. */
/*-------------------------------------------------------------------*/
/* INPUT/OUTPUT ARGUMENTS : */
/* _ None. */
/*-------------------------------------------------------------------*/
/* RETURN ARGUMENTS : */
/* _ None. */
/*===================================================================*/
void INI_reset_decoder(void)
{
/*-------------------------------------------------------------------*/
INI_pointer_setup_dec ();
/*-------------------------------------------------------------------*/
GEQ_init_lib ();
PPR_filters_init ();
LPC_init_lib ();
LSF_Q_init_lib ();
GCB_init_lib ();
FCS_init_lib ();
LTP_init_lib ();
SNR_init_lib();
ini_dvector (synth_mem_dec, 0, NP-1, 0.0);
ini_dvector (sigsyn_dec_mem, 0, NP-1, 0.0);
/*-------------------------------------------------------------------*/
return;
/*-------------------------------------------------------------------*/
}
/*----------------------------------------------------------------------------*/
/*===================================================================*/
/* FUNCTION : INI_init_decoder (). */
/*-------------------------------------------------------------------*/
/* PURPOSE : Performs the decoder initialisation. */
/*-------------------------------------------------------------------*/
/* ALGORITHM : */
/*-------------------------------------------------------------------*/
/* INPUT ARGUMENTS : */
/* _ None. */
/*-------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS : */
/* _ None. */
/*-------------------------------------------------------------------*/
/* INPUT/OUTPUT ARGUMENTS : */
/* _ None. */
/*-------------------------------------------------------------------*/
/* RETURN ARGUMENTS : */
/* _ None. */
/*===================================================================*/
void INI_init_decoder(void)
{
/*-------------------------------------------------------------------*/
fix_rate_dec_mem2 = RATE8_5K;
fix_rate_dec_mem = RATE8_5K;
past_bfi = 0;
ppast_bfi = 0;
bfi_caution = 0;
nbfi_count = MAX_BFI_COUNT;
N_bfi = 0;
bfh_oh = 0;
onset_flg_dec = 0;
arrayindex = 0;
type0count = 0;
maxenergy = 32767.0;
ini_svector (type1en, 0, LEN_TYPE1EN-1, 32767);
/*-------------------------------------------------------------------*/
INI_pointer_setup_dec ();
/*-------------------------------------------------------------------*/
GEQ_init_lib ();
PPR_filters_init ();
LPC_init_lib ();
LSF_Q_init_lib ();
CLA_init_lib ();
GCB_init_lib ();
FCS_init_lib ();
LTP_init_lib ();
SNR_init_lib();
ini_dvector (synth_mem_dec, 0, NP-1, 0.0);
ini_dvector (sigsyn_dec_mem, 0, NP-1, 0.0);
/*-------------------------------------------------------------------*/
return;
/*-------------------------------------------------------------------*/
}
#endif
/*----------------------------------------------------------------------------*/
/*============================================================================*/
/*------------------------------------ END -----------------------------------*/
/*============================================================================*/