melp.h
上传用户:luckfish
上传日期:2021-12-16
资源大小:77k
文件大小:5k
源码类别:

语音压缩

开发平台:

Visual C++

  1. /*
  2. 2.4 kbps MELP Proposed Federal Standard speech coder
  3. version 1.2
  4. Copyright (c) 1996, Texas Instruments, Inc.  
  5. Texas Instruments has intellectual property rights on the MELP
  6. algorithm.  The Texas Instruments contact for licensing issues for
  7. commercial and non-government use is William Gordon, Director,
  8. Government Contracts, Texas Instruments Incorporated, Semiconductor
  9. Group (phone 972 480 7442).
  10. */
  11. /*                                                                  */
  12. /*  melp.h: include file for MELP coder                             */
  13. /*                                                                  */
  14. /*  compiler flags */
  15. #define PRINT 1             /* warning message flag */
  16. /*  compiler constants */
  17. #define FRAME 240           /* speech frame size */
  18. #define LPC_ORD 10          /* LPC order */
  19. #define NUM_HARM 10         /* number of Fourier magnitudes */
  20. #define NUM_GAINFR 2        /* number of gains per frame */
  21. #define LPC_FRAME 200       /* LPC window size */
  22. #define PITCHMIN 20         /* minimum pitch lag */
  23. #define PITCHMAX 160        /* maximum pitch lag */
  24. #define NUM_BANDS 5         /* number of frequency bands */
  25. #define LPF_ORD 6           /* lowpass filter order */
  26. #define DC_ORD 4            /* DC removal filter order */
  27. #define BPF_ORD 6           /* bandpass analysis filter order */
  28. #define ENV_ORD 2           /* bandpass envelope filter order */
  29. #define MIX_ORD 32          /* mixed excitation filtering order */
  30. #define DISP_ORD 64         /* pulse dispersion filter order */
  31. #define DEFAULT_PITCH 50.0  /* default pitch value */
  32. #define UV_PITCH 50         /* unvoiced pitch value */
  33. #define VMIN 0.8            /* minimum strongly voiced correlation */
  34. #define VJIT 0.5            /* jitter threshold for correlations */
  35. #define BPTHRESH 0.6        /* bandpass voicing threshold */
  36. #define MAX_JITTER 0.25     /* maximum jitter percentage (as a fraction) */
  37. #define ASE_NUM_BW 0.5      /* adaptive spectral enhancement - numerator */
  38. #define ASE_DEN_BW 0.8      /* adaptive spectral enhancement - denominator */
  39. #define GAINFR (FRAME/NUM_GAINFR)  /* size of gain frame */
  40. #define MIN_GAINFR 120      /* minimum gain analysis window */
  41. #define MINLENGTH 160       /* minimum correlation length */
  42. #define PI 3.141592654
  43. #define TWOPI 6.283185308
  44. #define FSAMP 8000.0        /* sampling frequency */
  45. #define MSVQ_M 8            /* M-best for MSVQ search */
  46. #define MSVQ_MAXCNT 256     /* maximum inner loop counter for MSVQ search */
  47. #define BWMIN (50.0*2/FSAMP) /* minimum LSF separation */
  48. /* Noise suppression/estimation parameters */
  49. /* Up by 3 dB/sec (0.5*22.5 ms frame), down by 12 dB/sec */
  50. #define UPCONST 0.0337435    /* noise estimation up time constant */
  51. #define DOWNCONST -0.135418  /* noise estimation down time constant */
  52. #define NFACT 3.0            /* noise floor boost in dB */
  53. #define MAX_NS_ATT 6.0       /* maximum noise suppression */
  54. #define MAX_NS_SUP 20.0      /* maximum noise level to use in suppression */  
  55. #define MIN_NOISE 10.0       /* minimum value allowed in noise estimation */
  56. #define MAX_NOISE 80.0       /* maximum value allowed in noise estimation */
  57. /* Channel I/O constants */
  58. #define CHWORDSIZE 6         /* number of bits per channel word */
  59. #define ERASE_MASK 0x4000    /* erasure flag mask for channel word */
  60. #define GN_QLO 10.0          /* minimum gain in dB */
  61. #define GN_QUP 77.0          /* maximum gain in dB */
  62. #define GN_QLEV 32           /* number of second gain quantization levels */
  63. #define PIT_BITS 7           /* number of bits for pitch coding */
  64. #define PIT_QLEV 99          /* number of pitch levels */
  65. #define PIT_QLO 1.30103      /* minimum log pitch for quantization */
  66. #define PIT_QUP 2.20412      /* maximum log pitch for quantization */
  67. #define FS_BITS 8            /* number of bits for Fourier magnitudes */
  68. #define FS_LEVELS (1<<FS_BITS) /* number of levels for Fourier magnitudes */
  69. /* Structure definitions */
  70. struct melp_param {         /* MELP parameters */
  71.     float pitch;
  72.     float lsf[LPC_ORD+1];
  73.     float gain[NUM_GAINFR];
  74.     float jitter;
  75.     float bpvc[NUM_BANDS];
  76.     int pitch_index;
  77.     int lsf_index[LPC_ORD];
  78.     int jit_index;
  79.     int bpvc_index;
  80.     int gain_index[NUM_GAINFR];
  81.     unsigned int *chptr;
  82.     int chbit;
  83.     int uv_flag;
  84.     float fs_mag[NUM_HARM];
  85.     int *fsvq_index;
  86.     int *msvq_index;
  87.     int msvq_stages;
  88.     int *msvq_bits;
  89.     int *msvq_levels;
  90. };
  91. /* External function definitions */
  92. #include "dsp_sub.h"
  93. #include "melp_sub.h"
  94. void melp_ana(float sp_in[],struct melp_param *par);
  95. void melp_syn(struct melp_param *par, float sp_out[]);
  96. void melp_ana_init();
  97. void melp_syn_init();
  98. void melp_chn_write(struct melp_param *par);
  99. int melp_chn_read(struct melp_param *par, struct melp_param *prev_par);
  100. void fec_code(struct melp_param *par);
  101. int fec_decode(struct melp_param *par, int erase);