melp.h
上传用户:csczyc
上传日期:2021-02-19
资源大小:1051k
文件大小:7k
- /*
- 2.4 kbps MELP Proposed Federal Standard speech coder
- Fixed-point C code, version 1.0
- Copyright (c) 1998, Texas Instruments, Inc.
- Texas Instruments has intellectual property rights on the MELP
- algorithm. The Texas Instruments contact for licensing issues for
- commercial and non-government use is William Gordon, Director,
- Government Contracts, Texas Instruments Incorporated, Semiconductor
- Group (phone 972 480 7442).
- The fixed-point version of the voice codec Mixed Excitation Linear
- Prediction (MELP) is based on specifications on the C-language software
- simulation contained in GSM 06.06 which is protected by copyright and
- is the property of the European Telecommunications Standards Institute
- (ETSI). This standard is available from the ETSI publication office
- tel. +33 (0)4 92 94 42 58. ETSI has granted a license to United States
- Department of Defense to use the C-language software simulation contained
- in GSM 06.06 for the purposes of the development of a fixed-point
- version of the voice codec Mixed Excitation Linear Prediction (MELP).
- Requests for authorization to make other use of the GSM 06.06 or
- otherwise distribute or modify them need to be addressed to the ETSI
- Secretariat fax: +33 493 65 47 16.
- */
- /* */
- /* melp.h: include file for MELP coder */
- /* */
- #ifndef _melp_h
- #define _melp_h_
- /* compiler constants */
- #define FRAME 180 /* speech frame size */
- #define LPC_ORD 10 /* LPC order */
- #define NUM_HARM 10 /* number of Fourier magnitudes */
- #define NUM_GAINFR 2 /* number of gains per frame */
- #define LPC_FRAME 200 /* LPC window size */
- #define PITCHMIN 20 /* minimum pitch lag */
- #define PITCHMAX 160 /* maximum pitch lag */
- #define PITCHMAX_X2 (PITCHMAX*2) /* maximum pitch lag times 2 */
- #define NUM_BANDS 5 /* number of frequency bands */
- #define LPF_ORD 6 /* lowpass filter order */
- #define DC_ORD 4 /* DC removal filter order */
- #define BPF_ORD 6 /* bandpass analysis filter order */
- #define ENV_ORD 2 /* bandpass envelope filter order */
- #define MIX_ORD 32 /* mixed excitation filtering order */
- #define DISP_ORD 64 /* pulse dispersion filter order */
- #define DEFAULT_PITCH 50 /* default pitch value */
- #define DEFAULT_PITCH_Q7 6400 /* (DEFAULT_PITCH*(1<<7)) */
- #define UV_PITCH 50 /* unvoiced pitch value */
- #define UV_PITCH_Q7 6400 /* (UV_PITCH*(1<<7)) */
- #define VMIN_Q14 13107 /* (0.8*(1<<14)) minimum strongly voiced correlation */
- #define VJIT_Q14 8192 /* (0.5*(1<<14)) jitter threshold for correlations */
- #define BPTHRESH_Q14 9830 /* (0.6*(1<<14)) bandpass voicing threshold */
- #define MAX_JITTER_Q15 8192 /* (0.25*(1<<15)) maximum jitter (as a fraction) */
- #define ASE_NUM_BW_Q15 16384 /*(0.5*(1<<15)) adaptive spectral enhancement-numer */
- #define ASE_DEN_BW_Q15 26214 /*(0.8*(1<<15)) adaptive spectral enhancement-denom */
- #define GAINFR (FRAME/NUM_GAINFR) /* size of gain frame */
- #define MIN_GAINFR 120 /* minimum gain analysis window */
- #define GAIN_PITCH_Q7 15257 /* ((1.33*GAINFR-0.5)*(1<<7)) pitch input for gain_ana */
- #define MINLENGTH 160 /* minimum correlation length */
- #define PI 3.141592654
- #define TWOPI 6.283185308
- #define FSAMP 8000 /* sampling frequency */
- #define MSVQ_M 8 /* M-best for MSVQ search */
- #define MSVQ_MAXCNT 256 /* maximum inner loop counter for MSVQ search */
- /* Correct value should be 409 but 0 was used during listening test. */
- /* Set to 0 for bit exact results for the test materials */
- #if (1)
- #define BWMIN_Q15 0 /* ((50*2/FSAMP)*(1<<15)) minimum LSF separation */
- #else
- #define BWMIN_Q15 409
- #endif
- /* Noise suppression/estimation parameters */
- /* Up by 3 dB/sec (0.5*22.5 ms frame), down by 12 dB/sec */
- #define UPCONST_Q19 17691 /* (0.0337435*(1<<19)) noise estimation up time const */
- #define DOWNCONST_Q17 -17749 /* (-0.135418*(1<<17)) noise estimation dn time const */
- #define NFACT_Q8 768 /* (3.0*(1<<8)) noise floor boost in dB */
- #define MAX_NS_ATT_Q8 1536 /* (6.0*(1<<8)) maximum noise suppression */
- #define MAX_NS_SUP_Q8 5120 /* (20.0*(1<<8)) max noise level to use in suppression */
- #define MIN_NOISE_Q8 2560 /* (10.0*(1<<8)) min value allowed in noise estimation */
- #define MAX_NOISE_Q8 20480 /* (80.0*(1<<8)) max value allowed in noise estimation */
- /* Channel I/O constants */
- #define CHWORDSIZE 6 /* number of bits per channel word */
- #define ERASE_MASK (UShortword)0x4000 /* erasure flag mask for channel word */
- #define GN_QLO_Q8 2560 /* (10.0*(1<<8)) minimum gain in dB */
- #define GN_QUP_Q8 19712 /* (77.0*(1<<8)) maximum gain in dB */
- #define GN_QLEV_M1 (32-1) /* no. of 2nd gain quantization levels */
- #define GN_QLEV_M1_Q10 31744 /* (GN_QLEV_M1*(1<<10)) GN_QLEV_M1 in Q10 */
- #define PIT_BITS 7 /* number of bits for pitch coding */
- #define PIT_QLEV 99 /* number of pitch levels minus 1 */
- #define PIT_QLEV_M1 (99-1) /* number of pitch levels minus 1 */
- #define PIT_QLEV_M1_Q8 25088 /* (PIT_QLEV_M1*(1<<8)) number of pitch levels minus 1 */
- #define PIT_QLO_Q12 5329 /* (1.30103*(1<<12)) minimum log pitch for quantization */
- #define PIT_QUP_Q12 9028 /* (2.20412*(1<<12)) maximum log pitch for quantization */
- #define FS_BITS 8 /* number of bits for Fourier magnitudes */
- #define FS_LEVELS (1<<FS_BITS) /* number of levels for Fourier magnitudes */
- /* External function definitions */
- //#define COMPLEXITY_COUNT 0
- #include "typedefs.h"
- #include "dsp_sub.h"
- #include "melp_sub.h"
- //#if (COMPLEXITY_COUNT)
- //#include "complex.h"
- //#endif
- /* Structure definitions */
- struct melp_param { /* MELP parameters */
- Shortword pitch; /* Q7 */
- Shortword lsf[LPC_ORD+1]; /* Q15 */
- Shortword gain[NUM_GAINFR]; /* Q8 */
- Shortword jitter; /* Q15 */
- Shortword bpvc[NUM_BANDS]; /* Q14 */
- Shortword pitch_index;
- Shortword lsf_index[LPC_ORD];
- Shortword jit_index;
- Shortword bpvc_index;
- Shortword gain_index[NUM_GAINFR];
- unsigned char *chptr;//Mark ushortword -> unsigned char
- Shortword chbit;
- Shortword uv_flag;
- Shortword fs_mag[NUM_HARM]; /* Q13 */
- Shortword *fsvq_index;
- Shortword *msvq_index;
- Shortword msvq_stages;
- Shortword *msvq_bits;
- Shortword *msvq_levels;
- };
- void melp_ana(Shortword sp_in[],struct melp_param *par);
- void melp_syn(struct melp_param *par, Shortword sp_out[]);
- void melp_ana_init();
- void melp_syn_init();
- void melp_chn_write(struct melp_param *par);
- Shortword melp_chn_read(struct melp_param *par, struct melp_param *prev_par);
- void fec_code(struct melp_param *par);
- Shortword fec_decode(struct melp_param *par, Shortword erase);
- #endif