📄 rom_dec.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_dec.h
*
*
* Project:
* AMR Floating-Point Codec
*
* Contains:
* This file contains all the tables needed by AMR decoder functions.
*
*/
#ifndef _ROM_DEC_H_
#define _ROM_DEC_H_
/*
* include files
*/
#include"typedef.h"
#include"interf_rom.h"
/*
* definition of constants
*/
#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 */
/* vad */
#define COMPLEN 9 /* Number of sub-bands used by VAD */
#define L_ENERGYHIST 60
#define L_CBGAINHIST 7
#define PHDGAINMEMSIZE 5
#define MIN_ENERGY -14336 /* 14 Q10 */
#define MIN_ENERGY_MR122 -2381 /* 14 / (20*log10(2)) Q10 */
#define PN_INITIAL_SEED 0x70816958L /* Pseudo noise generator seed value */
#define MIN_16 (Word16)-32768
#define MAX_16 (Word16)0x7fff
#define MAX_32 (Word32)0x7fffffffL
#define EXPCONST 5243 /* 0.16 in Q15 */
#define DTX_MAX_EMPTY_THRESH 50
#define DTX_ELAPSED_FRAMES_THRESH (24 + 7 -1)
#define LSF_GAP 205 /* Minimum distance between LSF after quantization; 50 Hz = 205 */
#define LSP_PRED_FAC_MR122 21299 /* MR122 LSP prediction factor (0.65 Q15) */
#define POS_CODE 8191
#define NEG_CODE 8191
#define NMAX 9 /* largest N used in median calculation */
#define MEAN_ENER_MR122 783741L /* 36/(20*log10(2)) (Q17) */
#define SHARPMAX 13017 /* Maximum value of pitch sharpening */
#define FRAMEENERGYLIMIT 17578 /* 150 */
#define LOWERNOISELIMIT 20 /* 5 */
#define UPPERNOISELIMIT 1953 /* 50 */
#define AZ_SIZE (4*M+4) /* Size of array of LP filters in 4 subfr.s */
#define AGC_FAC 29491 /* Factor for automatic gain control 0.9 */
#define PHDGAINMEMSIZE 5
#define PHDTHR1LTP 9830 /* 0.6 in Q14 */
#define PHDTHR2LTP 14746 /* 0.9 in Q14 */
#define ONFACTPLUS1 16384 /* 2.0 in Q13 */
#define ONLENGTH 2
#define DTX_HANG_CONST 7 /* yields eight frames of SP HANGOVER */
/* number of parameters */
#define PRMNO_MR475 17
#define PRMNO_MR515 19
#define PRMNO_MR59 19
#define PRMNO_MR67 19
#define PRMNO_MR74 19
#define PRMNO_MR795 23
#define PRMNO_MR102 39
#define PRMNO_MR122 57
#define PRMNO_MRDTX 5
/*
* tables
*/
/* level adjustment for different modes Q11 */
static const Word16 dtx_log_en_adjust[9] =
{
- 1023,
/* MR475 */ - 878,
/* MR515 */ - 732,
/* MR59 */ - 586,
/* MR67 */ - 440,
/* MR74 */ - 294,
/* MR795 */ - 148,
/* MR102 */ 0,
/* MR122 */ 0,
/* MRDTX */
};
/* attenuation factors for codebook gain */
static const Word32 cdown[7] =
{
32767,
32112,
32112,
32112,
32112,
32112,
22937
};
/* attenuation factors for adaptive codebook gain */
static const Word32 pdown[7] =
{
32767,
32112,
32112,
26214,
9830,
6553,
6553
};
/* algebraic code book gain MA predictor coefficients */
static const Word32 pred[NPRED] =
{
5571,
4751,
2785,
1556
};
/* algebraic code book gain MA predictor coefficients (MR122) */
static const Word32 pred_MR122[NPRED] =
{
44,
37,
22,
12
};
static const Word32 gamma4_gamma3_MR122[M] =
{
22938,
16057,
11240,
7868,
5508,
3856,
2699,
1889,
1322,
925
};
static const Word32 gamma3[M] =
{
18022,
9912,
5451,
2998,
1649,
907,
499,
274,
151,
83
};
static const Word32 gamma4_MR122[M] =
{
24576,
18432,
13824,
10368,
7776,
5832,
4374,
3281,
2461,
1846
};
/* adaptive codebook gain quantization table (MR122, MR795) */
#define NB_QUA_PITCH 16
static const Word32 qua_gain_pitch[NB_QUA_PITCH] =
{
0,
3277,
6556,
8192,
9830,
11469,
12288,
13107,
13926,
14746,
15565,
16384,
17203,
18022,
18842,
19661
};
/* fixed codebook gain quantization table (MR122, MR795) */
#define NB_QUA_CODE 32
static const Word32 qua_gain_code[NB_QUA_CODE * 3] =
{
/* gain factor (g_fac) and quantized energy error (qua_ener_MR122, qua_ener)
* are stored:
*
* qua_ener_MR122 = log2(g_fac) (not the rounded floating point value, but
* the value the original EFR algorithm
* calculates from g_fac [using Log2])
* qua_ener = 20*log10(g_fac); (rounded floating point value)
*
*
* g_fac (Q11),
* qua_ener_MR122 (Q10),
* qua_ener (Q10)
*/ 159,
- 3776,
- 22731,
206,
- 3394,
- 20428,
268,
- 3005,
- 18088,
349,
- 2615,
- 15739,
419,
- 2345,
- 14113,
482,
- 2138,
- 12867,
554,
- 1932,
- 11629,
637,
- 1726,
- 10387,
733,
- 1518,
- 9139,
842,
- 1314,
- 7906,
969,
- 1106,
- 6656,
1114,
- 900,
- 5416,
1281,
- 694,
- 4173,
1473,
- 487,
- 2931,
1694,
- 281,
- 1688,
1948,
- 75,
- 445,
2241,
133,
801,
2577,
339,
2044,
2963,
545,
3285,
3408,
752,
4530,
3919,
958,
5772,
4507,
1165,
7016,
5183,
1371,
8259,
5960,
1577,
9501,
6855,
1784,
10745,
7883,
1991,
11988,
9065,
2197,
13231,
10425,
2404,
14474,
12510,
2673,
16096,
16263,
3060,
18429,
21142,
3448,
20763,
27485,
3836,
23097
};
/* gray coding table */
static const Word8 gray[8] =
{
0,
1,
3,
2,
6,
4,
5,
7
};
/* gray decoding table */
static const Word32 dgray[8] =
{
0,
1,
3,
2,
5,
6,
4,
7
};
/* table[i] = sqrt((i+16)*2^-6) * 2^15, i.e. sqrt(x) scaled Q15 */
static const Word32 sqrt_table[49] =
{
16384,
16888,
17378,
17854,
18318,
18770,
19212,
19644,
20066,
20480,
20886,
21283,
21674,
22058,
22435,
22806,
23170,
23530,
23884,
24232,
24576,
24915,
25249,
25580,
25905,
26227,
26545,
26859,
27170,
27477,
27780,
28081,
28378,
28672,
28963,
29251,
29537,
29819,
30099,
30377,
30652,
30924,
31194,
31462,
31727,
31991,
32252,
32511,
32767
};
static const Word32 inv_sqrt_table[49] =
{
32767,
31790,
30894,
30070,
29309,
28602,
27945,
27330,
26755,
26214,
25705,
25225,
24770,
24339,
23930,
23541,
23170,
22817,
22479,
22155,
21845,
21548,
21263,
20988,
20724,
20470,
20225,
19988,
19760,
19539,
19326,
19119,
18919,
18725,
18536,
18354,
18176,
18004,
17837,
17674,
17515,
17361,
17211,
17064,
16921,
16782,
16646,
16514,
16384
};
/* table used inbase 2 logharithm computation */
static const Word32 log2_table[33] =
{
0,
1455,
2866,
4236,
5568,
6863,
8124,
9352,
10549,
11716,
12855,
13967,
15054,
16117,
17156,
18172,
19167,
20142,
21097,
22033,
22951,
23852,
24735,
25603,
26455,
27291,
28113,
28922,
29716,
30497,
31266,
32023,
32767
};
/* table used in 2 to the power computation */
static const Word32 pow2_table[33] =
{
16384,
16743,
17109,
17484,
17867,
18258,
18658,
19066,
19484,
19911,
20347,
20792,
21247,
21713,
22188,
22674,
23170,
23678,
24196,
24726,
25268,
25821,
26386,
26964,
27554,
28158,
28774,
29405,
30048,
30706,
31379,
32066,
32767
};
/* table of cos(x) */
static const Word32 cos_table[65] =
{
32767,
32729,
32610,
32413,
32138,
31786,
31357,
30853,
30274,
29622,
28899,
28106,
27246,
26320,
25330,
24279,
23170,
22006,
20788,
19520,
18205,
16846,
15447,
14010,
12540,
11039,
9512,
7962,
6393,
4808,
3212,
1608,
0,
- 1608,
- 3212,
- 4808,
- 6393,
- 7962,
- 9512,
- 11039,
- 12540,
- 14010,
- 15447,
- 16846,
- 18205,
- 19520,
- 20788,
- 22006,
- 23170,
- 24279,
- 25330,
- 26320,
- 27246,
- 28106,
- 28899,
- 29622,
- 30274,
- 30853,
- 31357,
- 31786,
- 32138,
- 32413,
- 32610,
- 32729,
- 32768
};
/* slope used to compute y = acos(x) */
static const Word32 acos_slope[64] =
{
- 26887,
- 8812,
- 5323,
- 3813,
- 2979,
- 2444,
- 2081,
- 1811,
- 1608,
- 1450,
- 1322,
- 1219,
- 1132,
- 1059,
- 998,
- 946,
- 901,
- 861,
- 827,
- 797,
- 772,
- 750,
- 730,
- 713,
- 699,
- 687,
- 677,
- 668,
- 662,
- 657,
- 654,
- 652,
- 652,
- 654,
- 657,
- 662,
- 668,
- 677,
- 687,
- 699,
- 713,
- 730,
- 750,
- 772,
- 797,
- 827,
- 861,
- 901,
- 946,
- 998,
- 1059,
- 1132,
- 1219,
- 1322,
- 1450,
- 1608,
- 1811,
- 2081,
- 2444,
- 2979,
- 3813,
- 5323,
- 8812,
- 26887
};
/* All impulse responses are in Q15 */
/* phase dispersion impulse response (MR795) */
static const Word32 ph_imp_low_MR795[] =
{
26777,
801,
2505,
- 683,
- 1382,
582,
604,
- 1274,
3511,
- 5894,
4534,
- 499,
- 1940,
3011,
- 5058,
5614,
- 1990,
- 1061,
- 1459,
4442,
- 700,
- 5335,
4609,
452,
- 589,
- 3352,
2953,
1267,
- 1212,
- 2590,
1731,
3670,
- 4475,
- 975,
4391,
- 2537,
949,
- 1363,
- 979,
5734
};
/* phase dispersion impulse response (MR795) */
static const Word32 ph_imp_mid_MR795[] =
{
30274,
3831,
- 4036,
2972,
- 1048,
- 1002,
2477,
- 3043,
2815,
- 2231,
1753,
- 1611,
1714,
- 1775,
1543,
- 1008,
429,
- 169,
472,
- 1264,
2176,
- 2706,
2523,
- 1621,
344,
826,
- 1529,
1724,
- 1657,
1701,
- 2063,
2644,
- 3060,
2897,
- 1978,
557,
780,
- 1369,
842,
655
};
/* phase dispersion impulse response (MR475 - MR67) */
static const Word32 ph_imp_low[] =
{
14690,
11518,
1268,
- 2761,
- 5671,
7514,
- 35,
- 2807,
- 3040,
4823,
2952,
- 8424,
3785,
1455,
2179,
- 8637,
8051,
- 2103,
- 1454,
777,
1108,
- 2385,
2254,
- 363,
- 674,
- 2103,
6046,
- 5681,
1072,
3123,
- 5058,
5312,
- 2329,
- 3728,
6924,
- 3889,
675,
- 1775,
29,
10145
};
/* phase dispersion impulse response (MR475 - MR67) */
static const Word32 ph_imp_mid[] =
{
30274,
3831,
- 4036,
2972,
- 1048,
- 1002,
2477,
- 3043,
2815,
- 2231,
1753,
- 1611,
1714,
- 1775,
1543,
- 1008,
429,
- 169,
472,
- 1264,
2176,
- 2706,
2523,
- 1621,
344,
826,
- 1529,
1724,
- 1657,
1701,
- 2063,
2644,
- 3060,
2897,
- 1978,
557,
780,
- 1369,
842,
655
};
/* initialization table for the MA predictor in DTX */
#define PAST_RQ_INIT_SIZE 8
/* initalization table for MA predictor in dtx mode */
static const Word32 past_rq_init[80] =
{
- 258,
- 318,
- 439,
- 634,
- 656,
- 773,
- 711,
- 502,
- 268,
- 193,
- 2,
125,
122,
- 39,
- 9,
105,
129,
283,
372,
575,
- 277,
- 324,
- 197,
- 487,
- 445,
- 362,
- 292,
- 27,
177,
543,
342,
517,
516,
130,
27,
- 104,
- 120,
- 140,
- 74,
- 56,
- 564,
- 943,
- 1520,
- 965,
- 814,
- 526,
- 322,
- 2,
159,
657,
- 312,
- 284,
- 386,
- 597,
- 493,
- 526,
- 418,
- 229,
105,
449,
- 557,
- 870,
- 1075,
- 919,
- 950,
- 752,
- 709,
- 316,
62,
486,
- 314,
- 191,
- 203,
- 330,
- 160,
- 103,
- 51,
131,
338,
515
};
#define ALPHA 29491
#define ONE_ALPHA 3277
/* LSF means (not in MR122) */
static const Word32 mean_lsf_3[10] =
{
1546,
2272,
3778,
5488,
6972,
8382,
10047,
11229,
12766,
13714
};
#define ALPHA_122 31128
#define ONE_ALPHA_122 1639
/* LSF means ->normalize frequency domain */
static const Word32 mean_lsf_5[10] =
{
1384,
2077,
3420,
5108,
6742,
8122,
9863,
11092,
12714,
13701
};
/* LSF prediction factors (not in MR122) */
static const Word32 pred_fac[10] =
{
9556,
10769,
12571,
13292,
14381,
11651,
10588,
9767,
8593,
6484
};
#define DICO1_SIZE_3 256
#define DICO2_SIZE_3 512
#define DICO3_SIZE_3 512
/* 1st LSF quantizer (not in MR122 and MR795) */
static const Word32 dico1_lsf_3[] =
{
6,
82,
- 131,
154,
- 56,
- 735,
183,
- 65,
- 265,
9,
- 210,
- 361,
113,
718,
1817,
1010,
1214,
1573,
857,
1333,
2276,
827,
1568,
1933,
717,
1989,
2206,
838,
1172,
1823,
721,
1000,
2154,
286,
476,
1509,
- 247,
- 531,
230,
147,
- 82,
569,
26,
- 177,
- 944,
- 27,
- 273,
692,
- 164,
- 264,
- 183,
224,
790,
1039,
899,
946,
601,
485,
771,
1150,
524,
677,
903,
- 140,
375,
778,
410,
676,
429,
301,
530,
1009,
719,
646,
38,
226,
367,
40,
145,
- 45,
- 505,
290,
121,
- 121,
302,
127,
166,
- 124,
- 383,
- 956,
- 358,
- 455,
- 977,
715,
878,
894,
978,
923,
211,
477,
272,
64,
188,
- 78,
17,
- 143,
- 65,
38,
643,
586,
621,
- 134,
- 426,
- 651,
347,
545,
2820,
1188,
2726,
2442,
142,
- 80,
1735,
283,
130,
461,
- 262,
- 399,
- 1145,
- 411,
155,
430,
329,
375,
779,
53,
- 226,
- 139,
- 129,
- 236,
1682,
285,
744,
1327,
738,
697,
1664,
312,
409,
266,
325,
720,
135,
1,
221,
453,
8,
203,
145,
299,
640,
760,
29,
468,
638,
103,
429,
379,
420,
954,
932,
1326,
1210,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -