📄 rom_enc.h
字号:
/*
* ===================================================================
* TS 26.104
* REL-5 V5.4.0 2004-03
* REL-6 V6.1.0 2004-03
* 3GPP AMR Floating-point Speech Codec
* ===================================================================
*
*/
/*
* rom_enc.h
*
*
* Project:
* AMR Floating-Point Codec
*
* Contains:
* This file contains all the tables needed by AMR encoder functions.
*
*/
#ifndef _ROM_ENC_H_
#define _ROM_ENC_H_
#include "typedef.h"
#include "sp_enc.h"
#define M 10 /* Order of LP filter */
#define MP1 (M+1) /* Order of LP filter + 1 */
#define L_WINDOW 240 /* Window size in LP analysis */
#define L_NEXT 40 /* Overhead in LP analysis */
#define LTPG_MEM_SIZE 5 /* number of stored past LTP coding gains + 1 */
#define N_FRAME 7 /* old pitch gains in average calculation */
#define DTX_HIST_SIZE 8 /* DTX history size */
#define L_TOTAL 320 /* Total size of speech buffer. */
#define L_FRAME 160 /* Frame size */
#define L_FRAME_BY2 80 /* Frame size divided by 2 */
#define L_SUBFR 40 /* Subframe size */
#define L_CODE 40 /* codevector length */
#define PIT_MAX 143 /* Maximum pitch lag */
#define PIT_MIN 20 /* Minimum pitch lag */
#define PIT_MIN_MR122 18 /* Minimum pitch lag (MR122 mode) */
#define L_INTERPOL (10+1)/* Length of filter for interpolation */
#define NPRED 4 /* number of prediction taps */
#define SHARPMIN 0 /* Minimum value of pitch sharpening */
#define MAX_PRM_SIZE 57 /* max. num. of params */
#define L_INTER_SRCH 4 /* Length of filter for CL LTP search interpolation */
#define GP_CLIP 0.95F /* Pitch gain clipping */
#define UP_SAMP_MAX 6
#define NB_TRACK 5 /* number of tracks */
#define NB_TRACK_MR102 4 /* number of tracks mode mr102 */
#define STEP 5 /* codebook step size */
#define STEP_MR102 4 /* codebook step size mode mr102 */
#define NC M/2 /* Order of LP filter divided by 2 */
#define SCALE_LSP_FREQ (Float32)(4000.0/3.141592654)
#define SCALE_FREQ_LSP (Float32)(3.141592654/4000.0)
#define SLOPE1_WGHT_LSF (Float32)((3.347-1.8)/(450.0-0.0))
#define SLOPE2_WGHT_LSF (Float32)((1.8-1.0)/(1500.0-450.0))
#define FRAME_LEN 160 /* Length (samples) of the input frame */
#define COMPLEN 9 /* Number of sub-bands used by VAD */
#define INV_COMPLEN 3641 /* 1.0/COMPLEN*2^15 */
#define LOOKAHEAD 40 /* length of the lookahead used by speech coder */
#define UNITY 512 /* Scaling used with SNR calculation */
#define UNIRSHFT 6 /* = log2(MAX_16/UNITY) */
#define TONE_THR 0.65F /* Threshold for tone detection */
/* Constants for background spectrum update */
#define ALPHA_UP1 (Float32)(1.0 - 0.95) /* Normal update, upwards: */
#define ALPHA_DOWN1 (Float32)(1.0 - 0.936) /* Normal update, downwards */
#define ALPHA_UP2 (Float32)(1.0 - 0.985) /* Forced update, upwards */
#define ALPHA_DOWN2 (Float32)(1.0 - 0.943) /* Forced update, downwards */
#define ALPHA3 (Float32)(1.0 - 0.95) /* Update downwards */
#define ALPHA4 (Float32)(1.0 - 0.9) /* For stationary estimation */
#define ALPHA5 (Float32)(1.0 - 0.5) /* For stationary estimation */
/* Constants for VAD threshold */
#define VAD_THR_HIGH 1260 /* Highest threshold */
#define VAD_THR_LOW 720 /* Lowest threshold */
#define VAD_P1 0 /* Noise level for highest threshold */
#define VAD_P2 6300 /* Noise level for lowest threshold */
#define VAD_SLOPE (float)(VAD_THR_LOW-VAD_THR_HIGH)/(float)(VAD_P2-VAD_P1)
/* Parameters for background spectrum recovery function */
#define STAT_COUNT 20 /* threshold of stationary detection counter */
#define STAT_COUNT_BY_2 10 /* threshold of stationary detection counter */
#define CAD_MIN_STAT_COUNT 5 /* threshold of stationary detection counter */
#define STAT_THR_LEVEL 184 /* Threshold level for stationarity detection */
#define STAT_THR 1000 /* Threshold for stationarity detection */
/* Limits for background noise estimate */
#define NOISE_MIN 40 /* minimum */
#define NOISE_MAX 16000 /* maximum */
#define NOISE_INIT 150 /* initial */
/* Constants for VAD hangover addition */
#define HANG_NOISE_THR 100
#define BURST_LEN_HIGH_NOISE 4
#define HANG_LEN_HIGH_NOISE 7
#define BURST_LEN_LOW_NOISE 5
#define HANG_LEN_LOW_NOISE 4
/* Thresholds for signal power */
#define VAD_POW_LOW (Word32)15000/2 /* If input power is lower, */
/* VAD is set to 0 */
#define POW_PITCH_THR (Word32)343040/2 /* If input power is lower, pitch */
/* detection is ignored */
#define POW_COMPLEX_THR (Word32)15000/2/* If input power is lower, complex */
/* flags value for previous frame is un-set */
/*
* VAD Constants
*/
/* Constants for the filter bank */
#define LEVEL_SHIFT 0 /* scaling */
#define COEFF3 (Float32)13363/32768 /* coefficient for the 3rd order filter */
#define COEFF5_1 (Float32)21955/32768 /* 1st coefficient the for 5th order filter */
#define COEFF5_2 (Float32)6390/32768 /* 2nd coefficient the for 5th order filter */
/* Constants for pitch detection */
#define LTHRESH 4
#define NTHRESH 4
/* Constants for complex signal VAD */
#define CVAD_THRESH_ADAPT_HIGH 0.6F /* threshold for adapt stopping high */
#define CVAD_THRESH_ADAPT_LOW 0.5F /* threshold for adapt stopping low */
#define CVAD_THRESH_IN_NOISE 0.65F * 32768.0F /* threshold going into speech on
a short term basis */
#define CVAD_THRESH_HANG 0.70F /* threshold */
#define CVAD_HANG_LIMIT (Word16)(100) /* 2 second estimation time */
#define CVAD_HANG_LENGTH (Word16)(250) /* 5 second hangover */
#define CVAD_LOWPOW_RESET 0.40F /* init in low power segment */
#define CVAD_MIN_CORR 0.40F /* lowest adaptation value */
#define CVAD_BURST 20 /* speech burst length for speech reset */
#define CVAD_ADAPT_SLOW 1.0F - 0.98F /* threshold for slow adaption */
#define CVAD_ADAPT_FAST 1.0F - 0.92F /* threshold for fast adaption */
#define CVAD_ADAPT_REALLY_FAST 1.0F - 0.80F /* threshold for really fast adaption */
/* track table for algebraic code book search (MR475, MR515) */
static Word8 trackTable[4 * 5] =
{
/* subframe 1; track to code; -1 do not code this position */ 0,
1,
0,
1,
- 1,
/* subframe 2 */ 0,
- 1,
1,
0,
1,
/* subframe 3 */ 0,
1,
0,
- 1,
1,
/* subframe 4 */ 0,
1,
- 1,
0,
1
};
static const Float32 gamma1[M] =
{
0.9400024414063F,
0.8836059570313F,
0.8305969238281F,
0.78076171875F,
0.7339172363281F,
0.6898803710938F,
0.6484985351563F,
0.6095886230469F,
0.5730285644531F,
0.5386352539063F
};
/*
* gamma1 for the 12k2 coder
*/
static const Float32 gamma1_12k2[M] =
{
0.8999938964844F,
0.8099975585938F,
0.72900390625F,
0.6560974121094F,
0.5904846191406F,
0.5314331054688F,
0.478271484375F,
0.4304504394531F,
0.3873901367188F,
0.3486633300781F
};
static const Float32 gamma2[M] =
{
0.6000061035156F,
0.3600158691406F,
0.2160034179688F,
0.1296081542969F,
0.0777587890625F,
0.04666137695313F,
0.02798461914063F,
0.01678466796875F,
0.01007080078125F,
0.00604248046875F
};
/* 1/6 resolution interpolation filter (-3 dB at 3600 Hz)
* Note: the 1/3 resolution filter is simply a subsampled
* version of the 1/6 resolution filter, i.e. it uses
* every second coefficient:
*
* inter_6(1/3)[k] = inter_6(1/3)[2*k], 0 <= k <= 3*L_INTER10
*/
static Float32 b60[UP_SAMP_MAX*(L_INTERPOL-1)+1] =
{
0.898529F,
0.865051F,
0.769257F,
0.624054F,
0.448639F,
0.265289F,
0.0959167F,
- 0.0412598F,
- 0.134338F,
- 0.178986F,
- 0.178528F,
- 0.142609F,
- 0.0849304F,
- 0.0205078F,
0.0369568F,
0.0773926F,
0.0955200F,
0.0912781F,
0.0689392F,
0.0357056F,
0.000000F,
- 0.0305481F,
- 0.0504150F,
- 0.0570068F,
- 0.0508423F,
- 0.0350037F,
- 0.0141602F,
0.00665283F,
0.0230713F,
0.0323486F,
0.0335388F,
0.0275879F,
0.0167847F,
0.00411987F,
- 0.00747681F,
- 0.0156860F,
- 0.0193481F,
- 0.0183716F,
- 0.0137634F,
- 0.00704956F,
0.000000F,
0.00582886F,
0.00939941F,
0.0103760F,
0.00903320F,
0.00604248F,
0.00238037F,
- 0.00109863F,
- 0.00366211F,
- 0.00497437F,
- 0.00503540F,
- 0.00402832F,
- 0.00241089F,
- 0.000579834F,
0.00103760F,
0.00222778F,
0.00277710F,
0.00271606F,
0.00213623F,
0.00115967F,
0.000000F
};
/* same in fixed-point */
static const Word32 inter6[61] =
{
29443,
28346,
25207,
20449,
14701,
8693,
3143,
- 1352,
- 4402,
- 5865,
- 5850,
- 4673,
- 2783,
- 672,
1211,
2536,
3130,
2991,
2259,
1170,
0,
- 1001,
- 1652,
- 1868,
- 1666,
- 1147,
- 464,
218,
756,
1060,
1099,
904,
550,
135,
- 245,
- 514,
- 634,
- 602,
- 451,
- 231,
0,
191,
308,
340,
296,
198,
78,
- 36,
- 120,
- 163,
- 165,
- 132,
- 79,
- 19,
34,
73,
91,
89,
70,
38,
0
};
static const Word16 startPos1[2] =
{
1,
3
};
static const Word16 startPos2[4] =
{
0,
1,
2,
4
};
static const Word16 startPos[2 * 4 * 2] =
{
0,
2,
0,
3,
0,
2,
0,
3,
1,
3,
2,
4,
1,
4,
1,
4
};
/* Scalar quantization tables of the pitch gain and the codebook gain. */
#define NB_QUA_PITCH 16
static const Float32 qua_gain_pitch[NB_QUA_PITCH] =
{
0.0F,
0.20001220703125F,
0.400146484375F,
0.5F,
0.5999755859375F,
0.70001220703125F,
0.75F,
0.79998779296875F,
0.8499755859375F,
0.9000244140625F,
0.95001220703125F,
1.0F,
1.04998779296875F,
1.0999755859375F,
1.1500244140625F,
1.20001220703125F
};
static const Float32 qua_gain_pitch_MR122[NB_QUA_PITCH] =
{
0.0F,
0.199951171875F,
0.400146484375F,
0.5F,
0.599853515625F,
0.699951171875F,
0.75F,
0.7998046875F,
0.849853515625F,
0.89990234375F,
0.949951171875F,
1.0F,
1.0498046875F,
1.099853515625F,
1.14990234375F,
1.199951171875F
};
#define NB_QUA_CODE 32
static const Float32 gain_factor[NB_QUA_CODE] =
{
/* gain factor (g_fac) */
0.0776367F,
0.100586F,
0.130859F,
0.170410F,
0.204590F,
0.235352F,
0.270508F,
0.311035F,
0.357910F,
0.411133F,
0.473145F,
0.543945F,
0.625488F,
0.719238F,
0.827148F,
0.951172F,
1.09424F,
1.25830F,
1.44678F,
1.66406F,
1.91357F,
2.20068F,
2.53076F,
2.91016F,
3.34717F,
3.84912F,
4.42627F,
5.09033F,
6.10840F,
7.94092F,
10.3232F,
13.4204F
};
static const Word8 gray[8] =
{
0,
1,
3,
2,
6,
4,
5,
7
};
/*
* grid[0] = 1.0;
* grid[61] = -1.0;
* for (i = 1; i < 61; i++)
* grid[i] = (Float32)cos((6.283185307*i)/(2.0*60));
*/
static const Float32 grid[61] =
{
1.00000F,
0.998630F,
0.994522F,
0.987688F,
0.978148F,
0.965926F,
0.951057F,
0.933580F,
0.913545F,
0.891007F,
0.866025F,
0.838671F,
0.809017F,
0.777146F,
0.743145F,
0.707107F,
0.669131F,
0.629320F,
0.587785F,
0.544639F,
0.500000F,
0.453990F,
0.406737F,
0.358368F,
0.309017F,
0.258819F,
0.207912F,
0.156434F,
0.104528F,
0.0523360F,
4.48966e-011F,
- 0.0523360F,
- 0.104528F,
- 0.156434F,
- 0.207912F,
- 0.258819F,
- 0.309017F,
- 0.358368F,
- 0.406737F,
- 0.453990F,
- 0.500000F,
- 0.544639F,
- 0.587785F,
- 0.629320F,
- 0.669131F,
- 0.707107F,
- 0.743145F,
- 0.777146F,
- 0.809017F,
- 0.838671F,
- 0.866025F,
- 0.891007F,
- 0.913545F,
- 0.933580F,
- 0.951057F,
- 0.965926F,
- 0.978148F,
- 0.987688F,
- 0.994522F,
- 0.998630F,
- 1.00000F
};
/*
* 1/6 resolution interpolation filter (-3 dB at 3600 Hz)
* Note: The IS641 (7.4) 1/3 resolution filter is simply a subsampled
* version of the 1/6 resolution filter, i.e. it uses
* every second coefficient:
*
* b24[k](1/3) = b24[2*k](1/6), 0 <= k <= 3*L_INTER_SRCH
*/
static const Float32 b24[UP_SAMP_MAX*L_INTER_SRCH+1] =
{
0.900848F,
0.864136F,
0.760071F,
0.605408F,
0.424072F,
0.242462F,
0.0840759F,
- 0.0343933F,
- 0.105560F,
- 0.131348F,
- 0.121124F,
- 0.0884705F,
- 0.0476379F,
- 0.0102539F,
0.0162964F,
0.0296021F,
0.0312195F,
0.0251160F,
0.0157471F,
0.00671387F,
0.000000F,
- 0.00399780F,
- 0.00592041F,
- 0.00656128F,
0.000000F
};
/*
* Exponential Window coefficients used to weight the autocorrelation
* coefficients for 60 Hz bandwidth expansion of high pitched voice
* before Levinson-Durbin recursion to compute the LPC coefficients.
*
* lagwindow[i] = exp( -0.5*(2*pi*F0*(i+1)/Fs)^2 ); i = 0,...,9
* F0 = 60 Hz, Fs = 8000 Hz
*/
static Float32 lag_wind[M] =
{
0.99889028F,
0.99556851F,
0.99005681F,
0.98239160F,
0.97262347F,
0.96081644F,
0.94704735F,
0.93140495F,
0.91398895F,
0.89490914F
};
/* initialization table for lsp history in DTX */
static const Float32 lsp_init_data[M] =
{
0.9595F,
0.8413F,
0.6549F,
0.4154F,
0.1423F,
- 0.1423F,
- 0.4154F,
- 0.6549F,
- 0.8413F,
- 0.9595F
};
#define PAST_RQ_INIT_SIZE 8
/* initalization table for MA predictor in dtx mode */
static const Float32 past_rq_init[80] =
{
-62.9883F, -77.6367F, -107.178F, -154.785F, -160.156F, -188.721F, -173.584F, -122.559F,
-65.4297F, -47.1191F, -0.488281F, 30.5176F, 29.7852F, -9.52148F, -2.19727F, 25.6348F,
31.4941F, 69.0918F, 90.8203F, 140.381F, -67.627F, -79.1016F, -48.0957F, -118.896F,
-108.643F, -88.3789F, -71.2891F, -6.5918F, 43.2129F, 132.568F, 83.4961F, 126.221F,
125.977F, 31.7383F, 6.5918F, -25.3906F, -29.2969F, -34.1797F, -18.0664F, -13.6719F,
-137.695F, -230.225F, -371.094F, -235.596F, -198.73F, -128.418F, -78.6133F, -0.488281F,
38.8184F, 160.4F, -76.1719F, -69.3359F, -94.2383F, -145.752F, -120.361F, -128.418F,
-102.051F, -55.9082F, 25.6348F, 109.619F, -135.986F, -212.402F, -262.451F, -224.365F,
-231.934F, -183.594F, -173.096F, -77.1484F, 15.1367F, 118.652F, -76.6602F, -46.6309F,
-49.5605F, -80.5664F, -39.0625F, -25.1465F, -12.4512F, 31.9824F, 82.5195F, 125.732F
};
/* LSF means ->normalize frequency domain */
static const Float32 mean_lsf_3[10] =
{
377.441F,
554.688F,
922.363F,
1339.84F,
1702.15F,
2046.39F,
2452.88F,
2741.46F,
3116.70F,
3348.14F,
};
static const Float32 mean_lsf_5[10] =
{
337.891F,
507.080F,
834.961F,
1247.07F,
1646.00F,
1982.91F,
2407.96F,
2708.01F,
3104.00F,
3344.97F,
};
/* LSF prediction factors (not in MR122) */
static const Float32 pred_fac[10] =
{
0.291626F,
0.328644F,
0.383636F,
0.405640F,
0.438873F,
0.355560F,
0.323120F,
0.298065F,
0.262238F,
0.197876F
};
/* codebooks from IS641 */
#define DICO1_SIZE_3 256
#define DICO2_SIZE_3 512
#define DICO3_SIZE_3 512
static const Float32 dico1_lsf_3[] =
{
1.46484F,
20.0195F,
-31.9824F,
37.5977F,
-13.6719F,
-179.443F,
44.6777F,
-15.8691F,
-64.6973F,
2.19727F,
-51.2695F,
-88.1348F,
27.5879F,
175.293F,
443.604F,
246.582F,
296.387F,
384.033F,
209.229F,
325.439F,
555.664F,
201.904F,
382.813F,
471.924F,
175.049F,
485.596F,
538.574F,
204.590F,
286.133F,
445.068F,
176.025F,
244.141F,
525.879F,
69.8242F,
116.211F,
368.408F,
-60.3027F,
-129.639F,
56.1523F,
35.8887F,
-20.0195F,
138.916F,
6.34766F,
-43.2129F,
-230.469F,
-6.59180F,
-66.6504F,
168.945F,
-40.0391F,
-64.4531F,
-44.6777F,
54.6875F,
192.871F,
253.662F,
219.482F,
230.957F,
146.729F,
118.408F,
188.232F,
280.762F,
127.930F,
165.283F,
220.459F,
-34.1797F,
91.5527F,
189.941F,
100.098F,
165.039F,
104.736F,
73.4863F,
129.395F,
246.338F,
175.537F,
157.715F,
9.27734F,
55.1758F,
89.5996F,
9.76563F,
35.4004F,
-10.9863F,
-123.291F,
70.8008F,
29.5410F,
-29.5410F,
73.7305F,
31.0059F,
40.5273F,
-30.2734F,
-93.5059F,
-233.398F,
-87.4023F,
-111.084F,
-238.525F,
174.561F,
214.355F,
218.262F,
238.770F,
225.342F,
51.5137F,
116.455F,
66.4063F,
15.6250F,
45.8984F,
-19.0430F,
4.15039F,
-34.9121F,
-15.8691F,
9.27734F,
156.982F,
143.066F,
151.611F,
-32.7148F,
-104.004F,
-158.936F,
84.7168F,
133.057F,
688.477F,
290.039F,
665.527F,
596.191F,
34.6680F,
-19.5313F,
423.584F,
69.0918F,
31.7383F,
112.549F,
-63.9648F,
-97.4121F,
-279.541F,
-100.342F,
37.8418F,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -