-
Notifications
You must be signed in to change notification settings - Fork 1
/
rom_dec.h
13261 lines (13210 loc) · 184 KB
/
rom_dec.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* ===================================================================
* TS 26.104
* REL-5 V5.4.0 2004-03
* REL-6 V6.1.0 2004-03
* REL-15 V15.1.0 2018-07
* 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,