melp.h
上传用户:cxx_68
上传日期:2021-02-21
资源大小:161k
文件大小:7k
源码类别:

语音压缩

开发平台:

Visual C++

  1. /*
  2. 2.4 kbps MELP Proposed Federal Standard speech coder
  3. Fixed-point C code, version 1.0
  4. Copyright (c) 1998, 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. The fixed-point version of the voice codec Mixed Excitation Linear
  11. Prediction (MELP) is based on specifications on the C-language software
  12. simulation contained in GSM 06.06 which is protected by copyright and
  13. is the property of the European Telecommunications Standards Institute
  14. (ETSI). This standard is available from the ETSI publication office
  15. tel. +33 (0)4 92 94 42 58. ETSI has granted a license to United States
  16. Department of Defense to use the C-language software simulation contained
  17. in GSM 06.06 for the purposes of the development of a fixed-point
  18. version of the voice codec Mixed Excitation Linear Prediction (MELP).
  19. Requests for authorization to make other use of the GSM 06.06 or
  20. otherwise distribute or modify them need to be addressed to the ETSI
  21. Secretariat fax: +33 493 65 47 16.
  22. */
  23. /*                                                                  */
  24. /*  melp.h: include file for MELP coder                             */
  25. /*                                                                  */
  26. #ifndef _melp_h
  27. #define _melp_h_
  28. /*  compiler constants */
  29. #define FRAME 180           /* speech frame size */
  30. #define LPC_ORD 10          /* LPC order */
  31. #define NUM_HARM 10         /* number of Fourier magnitudes */
  32. #define NUM_GAINFR 2        /* number of gains per frame */
  33. #define LPC_FRAME 200       /* LPC window size */
  34. #define PITCHMIN 20         /* minimum pitch lag */
  35. #define PITCHMAX 160        /* maximum pitch lag */
  36. #define PITCHMAX_X2 (PITCHMAX*2)   /* maximum pitch lag times 2 */
  37. #define NUM_BANDS 5         /* number of frequency bands */
  38. #define LPF_ORD 6           /* lowpass filter order */
  39. #define DC_ORD 4            /* DC removal filter order */
  40. #define BPF_ORD 6           /* bandpass analysis filter order */
  41. #define ENV_ORD 2           /* bandpass envelope filter order */
  42. #define MIX_ORD 32          /* mixed excitation filtering order */
  43. #define DISP_ORD 64         /* pulse dispersion filter order */
  44. #define DEFAULT_PITCH 50        /* default pitch value */
  45. #define DEFAULT_PITCH_Q7 6400   /* (DEFAULT_PITCH*(1<<7)) */
  46. #define UV_PITCH 50             /* unvoiced pitch value */
  47. #define UV_PITCH_Q7  6400       /* (UV_PITCH*(1<<7)) */
  48. #define VMIN_Q14 13107 /* (0.8*(1<<14))  minimum strongly voiced correlation */
  49. #define VJIT_Q14 8192  /* (0.5*(1<<14))  jitter threshold for correlations */
  50. #define BPTHRESH_Q14 9830  /* (0.6*(1<<14))  bandpass voicing threshold */
  51. #define MAX_JITTER_Q15 8192  /* (0.25*(1<<15))  maximum jitter (as a fraction) */
  52. #define ASE_NUM_BW_Q15 16384  /*(0.5*(1<<15))  adaptive spectral enhancement-numer */
  53. #define ASE_DEN_BW_Q15 26214  /*(0.8*(1<<15))  adaptive spectral enhancement-denom */
  54. #define GAINFR (FRAME/NUM_GAINFR)  /* size of gain frame */
  55. #define MIN_GAINFR 120      /* minimum gain analysis window */
  56. #define GAIN_PITCH_Q7 15257  /* ((1.33*GAINFR-0.5)*(1<<7))  pitch input for gain_ana */
  57. #define MINLENGTH 160       /* minimum correlation length */
  58. #define PI              3.141592654
  59. #define TWOPI           6.283185308
  60. #define FSAMP 8000          /* sampling frequency */
  61. #define MSVQ_M 8            /* M-best for MSVQ search */
  62. #define MSVQ_MAXCNT 256     /* maximum inner loop counter for MSVQ search */
  63. /* Correct value should be 409 but 0 was used during listening test. */
  64. /* Set to 0 for bit exact results for the test materials */
  65. #if (1)
  66. #define BWMIN_Q15 0  /* ((50*2/FSAMP)*(1<<15))  minimum LSF separation */
  67. #else
  68. #define BWMIN_Q15 409 
  69. #endif
  70. /* Noise suppression/estimation parameters */
  71. /* Up by 3 dB/sec (0.5*22.5 ms frame), down by 12 dB/sec */
  72. #define UPCONST_Q19 17691  /* (0.0337435*(1<<19))  noise estimation up time const */
  73. #define DOWNCONST_Q17 -17749  /* (-0.135418*(1<<17))  noise estimation dn time const */
  74. #define NFACT_Q8 768  /* (3.0*(1<<8))  noise floor boost in dB */
  75. #define MAX_NS_ATT_Q8 1536  /* (6.0*(1<<8))  maximum noise suppression */
  76. #define MAX_NS_SUP_Q8 5120  /* (20.0*(1<<8))  max noise level to use in suppression */  
  77. #define MIN_NOISE_Q8 2560  /* (10.0*(1<<8))  min value allowed in noise estimation */
  78. #define MAX_NOISE_Q8 20480  /* (80.0*(1<<8))  max value allowed in noise estimation */
  79. /* Channel I/O constants */
  80. #define CHWORDSIZE 6         /* number of bits per channel word */
  81. #define ERASE_MASK (UShortword)0x4000  /* erasure flag mask for channel word */
  82. #define GN_QLO_Q8 2560   /* (10.0*(1<<8))  minimum gain in dB */
  83. #define GN_QUP_Q8 19712  /* (77.0*(1<<8))  maximum gain in dB */
  84. #define GN_QLEV_M1 (32-1)             /* no. of 2nd gain quantization levels */
  85. #define GN_QLEV_M1_Q10 31744  /* (GN_QLEV_M1*(1<<10))  GN_QLEV_M1 in Q10 */
  86. #define PIT_BITS 7                    /* number of bits for pitch coding */
  87. #define PIT_QLEV 99                   /* number of pitch levels minus 1 */
  88. #define PIT_QLEV_M1 (99-1)            /* number of pitch levels minus 1 */
  89. #define PIT_QLEV_M1_Q8 25088  /* (PIT_QLEV_M1*(1<<8))  number of pitch levels minus 1 */
  90. #define PIT_QLO_Q12 5329  /* (1.30103*(1<<12))  minimum log pitch for quantization */
  91. #define PIT_QUP_Q12 9028  /* (2.20412*(1<<12))  maximum log pitch for quantization */
  92. #define FS_BITS 8            /* number of bits for Fourier magnitudes */
  93. #define FS_LEVELS (1<<FS_BITS) /* number of levels for Fourier magnitudes */
  94. /* External function definitions */
  95. #define COMPLEXITY_COUNT 0
  96. #include "typedefs.h"
  97. #include "dsp_sub.h"
  98. #include "melp_sub.h"
  99. #if (COMPLEXITY_COUNT)
  100. #include "complex.h"
  101. #endif
  102. /* Structure definitions */
  103. struct melp_param {         /* MELP parameters */
  104.     Shortword pitch;                    /* Q7 */
  105.     Shortword lsf[LPC_ORD+1];           /* Q15 */
  106.     Shortword gain[NUM_GAINFR];         /* Q8 */
  107.     Shortword jitter;                   /* Q15 */
  108.     Shortword bpvc[NUM_BANDS];          /* Q14 */
  109.     Shortword pitch_index;
  110.     Shortword lsf_index[LPC_ORD];
  111.     Shortword jit_index;
  112.     Shortword bpvc_index;
  113.     Shortword gain_index[NUM_GAINFR];
  114.     UShortword *chptr;
  115.     Shortword chbit;
  116.     Shortword uv_flag;
  117.     Shortword fs_mag[NUM_HARM];         /* Q13 */
  118.     Shortword *fsvq_index;
  119.     Shortword *msvq_index;
  120.     Shortword msvq_stages;
  121.     Shortword *msvq_bits;
  122.     Shortword *msvq_levels;
  123. };
  124. void melp_ana(Shortword sp_in[],struct melp_param *par);
  125. void melp_syn(struct melp_param *par, Shortword sp_out[]);
  126. void melp_ana_init();
  127. void melp_syn_init();
  128. void melp_chn_write(struct melp_param *par);
  129. Shortword melp_chn_read(struct melp_param *par, struct melp_param *prev_par);
  130. void fec_code(struct melp_param *par);
  131. Shortword fec_decode(struct melp_param *par, Shortword erase);
  132. #endif