Browse code

AMR-WB decoder, written as part of Google Summer of Code 2010 by Marcelo Galvão Póvoa <marspeoplester gmail com>, mentored by Robert Swain <robert dot swain gmail com>.

Originally committed as revision 26051 to svn://svn.ffmpeg.org/ffmpeg/trunk

Ronald S. Bultje authored on 2010/12/18 12:03:18
Showing 7 changed files
... ...
@@ -65,6 +65,7 @@ version <next>:
65 65
 - RTP depacketization of QCELP
66 66
 - FLAC parser added
67 67
 - gradfun filter added
68
+- AMR-WB decoder
68 69
 
69 70
 
70 71
 version 0.6:
... ...
@@ -1194,6 +1194,7 @@ aac_latm_decoder_select="aac_decoder aac_latm_parser"
1194 1194
 ac3_decoder_select="mdct ac3_parser"
1195 1195
 alac_encoder_select="lpc"
1196 1196
 amrnb_decoder_select="lsp"
1197
+amrwb_decoder_select="lsp"
1197 1198
 atrac1_decoder_select="mdct"
1198 1199
 atrac3_decoder_select="mdct"
1199 1200
 binkaudio_dct_decoder_select="mdct rdft dct"
... ...
@@ -574,8 +574,7 @@ following image formats are supported:
574 574
 @item ADPCM Yamaha           @tab  X  @tab  X
575 575
 @item AMR-NB                 @tab  E  @tab  X
576 576
     @tab encoding supported through external library libopencore-amrnb
577
-@item AMR-WB                 @tab     @tab  E
578
-    @tab decoding supported through external library libopencore-amrwb
577
+@item AMR-WB                 @tab     @tab  X
579 578
 @item Apple lossless audio   @tab  X  @tab  X
580 579
     @tab QuickTime fourcc 'alac'
581 580
 @item Atrac 1                @tab     @tab  X
... ...
@@ -62,6 +62,10 @@ OBJS-$(CONFIG_AMRNB_DECODER)           += amrnbdec.o celp_filters.o   \
62 62
                                           celp_math.o acelp_filters.o \
63 63
                                           acelp_vectors.o             \
64 64
                                           acelp_pitch_delay.o
65
+OBJS-$(CONFIG_AMRWB_DECODER)           += amrwbdec.o celp_filters.o   \
66
+                                          celp_math.o acelp_filters.o \
67
+                                          acelp_vectors.o             \
68
+                                          acelp_pitch_delay.o lsp.o
65 69
 OBJS-$(CONFIG_AMV_DECODER)             += sp5xdec.o mjpegdec.o mjpeg.o
66 70
 OBJS-$(CONFIG_ANM_DECODER)             += anm.o
67 71
 OBJS-$(CONFIG_ANSI_DECODER)            += ansi.o cga_data.o
... ...
@@ -225,6 +225,7 @@ void avcodec_register_all(void)
225 225
     REGISTER_ENCDEC  (ALAC, alac);
226 226
     REGISTER_DECODER (ALS, als);
227 227
     REGISTER_DECODER (AMRNB, amrnb);
228
+    REGISTER_DECODER (AMRWB, amrwb);
228 229
     REGISTER_DECODER (APE, ape);
229 230
     REGISTER_DECODER (ATRAC1, atrac1);
230 231
     REGISTER_DECODER (ATRAC3, atrac3);
231 232
new file mode 100644
... ...
@@ -0,0 +1,1889 @@
0
+/*
1
+ * AMR wideband data and definitions
2
+ * Copyright (c) 2010 Marcelo Galvao Povoa
3
+ *
4
+ * This file is part of FFmpeg.
5
+ *
6
+ * FFmpeg is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * FFmpeg is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with FFmpeg; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+/**
22
+ * @file
23
+ * AMR wideband data and definitions
24
+ */
25
+
26
+#ifndef AVCODEC_AMRWBDATA_H
27
+#define AVCODEC_AMRWBDATA_H
28
+
29
+#include <stdint.h>
30
+
31
+#define LP_ORDER            16                ///< linear predictive coding filter order
32
+#define LP_ORDER_16k        20                ///< lpc filter order at 16kHz
33
+#define HB_FIR_SIZE         30                ///< amount of past data needed by HB filters
34
+#define UPS_FIR_SIZE        12                ///< upsampling filter size
35
+#define UPS_MEM_SIZE        (2 * UPS_FIR_SIZE)
36
+
37
+#define MIN_ISF_SPACING     (128.0 / 32768.0) ///< minimum isf gap
38
+#define PRED_FACTOR         (1.0 / 3.0)
39
+#define MIN_ENERGY         -14.0              ///< initial innnovation energy (dB)
40
+#define ENERGY_MEAN         30.0              ///< mean innovation energy (dB) in all modes
41
+#define PREEMPH_FAC         0.68              ///< factor used to de-emphasize synthesis
42
+
43
+#define AMRWB_SFR_SIZE      64                ///< samples per subframe at 12.8 kHz
44
+#define AMRWB_SFR_SIZE_16k  80                ///< samples per subframe at 16 kHz
45
+#define AMRWB_P_DELAY_MAX   231               ///< maximum pitch delay value
46
+#define AMRWB_P_DELAY_MIN   34
47
+
48
+/* Relative mode ordering is sensitive */
49
+enum Mode {
50
+    MODE_6k60 = 0,                         ///< 6.60 kbit/s
51
+    MODE_8k85,                             ///< 8.85 kbit/s
52
+    MODE_12k65,                            ///< 12.65 kbit/s
53
+    MODE_14k25,                            ///< 14.25 kbit/s
54
+    MODE_15k85,                            ///< 15.85 kbit/s
55
+    MODE_18k25,                            ///< 18.25 kbit/s
56
+    MODE_19k85,                            ///< 19.85 kbit/s
57
+    MODE_23k05,                            ///< 23.05 kbit/s
58
+    MODE_23k85,                            ///< 23.85 kbit/s
59
+    MODE_SID,                              ///< comfort noise frame
60
+    /* 10-13:  Future use */
61
+    SP_LOST = 14,                          ///< speech lost
62
+    NO_DATA                                ///< no transmission
63
+};
64
+
65
+/* All decoded parameters in these structs must be 2 bytes long
66
+ * because of the direct indexing at the frame parsing */
67
+typedef struct {
68
+    uint16_t adap;                         ///< adaptive codebook index
69
+    uint16_t ltp;                          ///< ltp-filtering flag
70
+    uint16_t vq_gain;                      ///< VQ adaptive and innovative gains
71
+    uint16_t hb_gain;                      ///< high-band energy index (mode 23k85 only)
72
+    uint16_t pul_ih[4];                    ///< MSBs part of codebook index (high modes only)
73
+    uint16_t pul_il[4];                    ///< LSBs part of codebook index
74
+} AMRWBSubFrame;
75
+
76
+typedef struct {
77
+    uint16_t vad;                          ///< voice activity detection flag
78
+    uint16_t isp_id[7];                    ///< index of ISP subvectors
79
+    AMRWBSubFrame subframe[4];             ///< data for subframes
80
+} AMRWBFrame;
81
+
82
+/** The index of a frame parameter */
83
+#define AMR_BIT(field)                  (offsetof(AMRWBFrame, field) >> 1)
84
+/** The index of a subframe-specific parameter */
85
+#define AMR_OF(frame_num, variable)     AMR_BIT(subframe[frame_num].variable)
86
+
87
+//As defined in 3GPP TS 26.201 V9.0.0
88
+//Tables for bit parsing in Core Frame speech frames
89
+//The reordered bits are in order of decreasing importance and
90
+//may be contiguously separated in Class A, B and C bits.
91
+
92
+// Each field in AMRWBFrame is stored as:
93
+// * one byte for the number of bits in the field
94
+// * one byte for the field index
95
+// * then, one byte for each bit of the field (from most-significant to least)
96
+//         of the position of that bit in the AMR frame.
97
+static const uint16_t order_MODE_6k60[] = {
98
+     1,         AMR_BIT(vad),   7,
99
+     8,   AMR_BIT(isp_id[0]),  24,  33,  39,  12,   6,   5,   4,  13,
100
+     8,   AMR_BIT(isp_id[1]),  65,  79,  64,  78,  51,  61,  71,  70,
101
+     7,   AMR_BIT(isp_id[2]),  52,  55,  44,  54,  53,  43,  42,
102
+     7,   AMR_BIT(isp_id[3]),  60,  59,  58,  57,  56,  75,  74,
103
+     6,   AMR_BIT(isp_id[4]),  73,  72,  86,  87,  85,  84,
104
+     8,      AMR_OF(0, adap),  11,  10,   9,   8,  28,  27,  49,  69,
105
+     6, AMR_OF(0, pul_il[0]),  83,  91,  99, 107, 115, 123,
106
+     6, AMR_OF(0, pul_il[1]),  82, 103, 111, 119, 127, 135,
107
+     6,   AMR_OF(0, vq_gain),  38,  23,  34,  19,   3,  15,
108
+     5,      AMR_OF(1, adap),  32,  41,  63,  67,  77,
109
+     6, AMR_OF(1, pul_il[0]),  81,  90,  98, 106, 114, 122,
110
+     6, AMR_OF(1, pul_il[1]),  80, 102, 110, 118, 126, 134,
111
+     6,   AMR_OF(1, vq_gain),  26,  22,  36,  18,   2,  14,
112
+     5,      AMR_OF(2, adap),  45,  40,  50,  48,  68,
113
+     6, AMR_OF(2, pul_il[0]),  95,  89,  97, 105, 113, 121,
114
+     6, AMR_OF(2, pul_il[1]),  94, 101, 109, 117, 125, 133,
115
+     6,   AMR_OF(2, vq_gain),  37,  21,  35,  17,   1,  31,
116
+     5,      AMR_OF(3, adap),  47,  46,  62,  66,  76,
117
+     6, AMR_OF(3, pul_il[0]),  93,  88,  96, 104, 112, 120,
118
+     6, AMR_OF(3, pul_il[1]),  92, 100, 108, 116, 124, 132,
119
+     6,   AMR_OF(3, vq_gain),  25,  20,  29,  16,   0,  30,
120
+     0
121
+};
122
+
123
+static const uint16_t order_MODE_8k85[] = {
124
+     1,         AMR_BIT(vad),   7,
125
+     8,   AMR_BIT(isp_id[0]),  47,  32,   2,   6,   3,   5,   4,  60,
126
+     8,   AMR_BIT(isp_id[1]),  69,  50,  67,  41,  51,  49,  59,  53,
127
+     6,   AMR_BIT(isp_id[2]),  40,  55,  43,  54,  42,  62,
128
+     7,   AMR_BIT(isp_id[3]),  63,  48,  52,  61,  77,  78,  72,
129
+     7,   AMR_BIT(isp_id[4]),  85,  56,  86,  68,  74,  73,  81,
130
+     5,   AMR_BIT(isp_id[5]),  82,  95,  80,  94,  91,
131
+     5,   AMR_BIT(isp_id[6]),  90,  89,  88, 103,  87,
132
+     8,      AMR_OF(0, adap),   1,   0,  15,  35,  33,  58,  64,  84,
133
+     5, AMR_OF(0, pul_il[0]), 102, 118, 134, 150, 166,
134
+     5, AMR_OF(0, pul_il[1]), 101, 114, 130, 146, 162,
135
+     5, AMR_OF(0, pul_il[2]), 100, 126, 142, 158, 174,
136
+     5, AMR_OF(0, pul_il[3]),  99, 122, 138, 154, 170,
137
+     6,   AMR_OF(0, vq_gain),  11,  39,  19,  31,  27,  23,
138
+     5,      AMR_OF(1, adap),  46,  71,  66,  76,  93,
139
+     5, AMR_OF(1, pul_il[0]),  98, 117, 133, 149, 165,
140
+     5, AMR_OF(1, pul_il[1]),  97, 113, 129, 145, 161,
141
+     5, AMR_OF(1, pul_il[2]),  96, 125, 141, 157, 173,
142
+     5, AMR_OF(1, pul_il[3]), 111, 121, 137, 153, 169,
143
+     6,   AMR_OF(1, vq_gain),  10,  38,  18,  30,  26,  22,
144
+     8,      AMR_OF(2, adap),  14,  13,  12,  34,  45,  57,  79,  83,
145
+     5, AMR_OF(2, pul_il[0]), 110, 116, 132, 148, 164,
146
+     5, AMR_OF(2, pul_il[1]), 109, 112, 128, 144, 160,
147
+     5, AMR_OF(2, pul_il[2]), 108, 124, 140, 156, 172,
148
+     5, AMR_OF(2, pul_il[3]), 107, 120, 136, 152, 168,
149
+     6,   AMR_OF(2, vq_gain),   9,  37,  17,  29,  25,  21,
150
+     5,      AMR_OF(3, adap),  44,  70,  65,  75,  92,
151
+     5, AMR_OF(3, pul_il[0]), 106, 115, 131, 147, 163,
152
+     5, AMR_OF(3, pul_il[1]), 105, 127, 143, 159, 175,
153
+     5, AMR_OF(3, pul_il[2]), 104, 123, 139, 155, 171,
154
+     5, AMR_OF(3, pul_il[3]), 119, 135, 151, 167, 183,
155
+     6,   AMR_OF(3, vq_gain),   8,  36,  16,  28,  24,  20,
156
+     0
157
+};
158
+
159
+static const uint16_t order_MODE_12k65[] = {
160
+     1,         AMR_BIT(vad),   7,
161
+     8,   AMR_BIT(isp_id[0]),  55,  40,  14,   6,  15,   5,   0,  68,
162
+     8,   AMR_BIT(isp_id[1]),  77,  58,  75,  49,  59,  57,  67,  61,
163
+     6,   AMR_BIT(isp_id[2]),  48,  63,  51,  62,  50,  70,
164
+     7,   AMR_BIT(isp_id[3]),  71,  56,  60,  69,  85,  86,  80,
165
+     7,   AMR_BIT(isp_id[4]),  93,  64,  94,  76,  82,  81,  89,
166
+     5,   AMR_BIT(isp_id[5]),  90, 103,  88, 102,  99,
167
+     5,   AMR_BIT(isp_id[6]),  98,  97,  96, 111,  95,
168
+     9,      AMR_OF(0, adap),  13,  12,  11,  10,   9,  41,  66,  72,
169
+                               92,
170
+     1,       AMR_OF(0, ltp), 110,
171
+     9, AMR_OF(0, pul_il[0]), 106, 122, 154, 186, 218, 134, 166, 198,
172
+                              230,
173
+     9, AMR_OF(0, pul_il[1]), 105, 130, 162, 194, 226, 142, 174, 206,
174
+                              238,
175
+     9, AMR_OF(0, pul_il[2]), 104, 138, 170, 202, 234, 150, 182, 214,
176
+                              246,
177
+     9, AMR_OF(0, pul_il[3]), 119, 146, 178, 210, 242, 158, 190, 222,
178
+                              254,
179
+     7,   AMR_OF(0, vq_gain),   4,  19,  45,  27,  39,  33,  31,
180
+     6,      AMR_OF(1, adap),  35,  54,  79,  74,  84, 101,
181
+     1,       AMR_OF(1, ltp), 109,
182
+     9, AMR_OF(1, pul_il[0]), 118, 121, 153, 185, 217, 133, 165, 197,
183
+                              229,
184
+     9, AMR_OF(1, pul_il[1]), 117, 129, 161, 193, 225, 141, 173, 205,
185
+                              237,
186
+     9, AMR_OF(1, pul_il[2]), 116, 137, 169, 201, 233, 149, 181, 213,
187
+                              245,
188
+     9, AMR_OF(1, pul_il[3]), 115, 145, 177, 209, 241, 157, 189, 221,
189
+                              253,
190
+     7,   AMR_OF(1, vq_gain),   3,  18,  44,  26,  38,  32,  30,
191
+     9,      AMR_OF(2, adap),   8,  23,  22,  21,  20,  52,  65,  87,
192
+                               91,
193
+     1,       AMR_OF(2, ltp), 108,
194
+     9, AMR_OF(2, pul_il[0]), 114, 120, 152, 184, 216, 132, 164, 196,
195
+                              228,
196
+     9, AMR_OF(2, pul_il[1]), 113, 128, 160, 192, 224, 140, 172, 204,
197
+                              236,
198
+     9, AMR_OF(2, pul_il[2]), 112, 136, 168, 200, 232, 148, 180, 212,
199
+                              244,
200
+     9, AMR_OF(2, pul_il[3]), 127, 144, 176, 208, 240, 156, 188, 220,
201
+                              252,
202
+     7,   AMR_OF(2, vq_gain),   2,  17,  43,  25,  37,  47,  29,
203
+     6,      AMR_OF(3, adap),  34,  53,  78,  73,  83, 100,
204
+     1,       AMR_OF(3, ltp), 107,
205
+     9, AMR_OF(3, pul_il[0]), 126, 135, 167, 199, 231, 131, 163, 195,
206
+                              227,
207
+     9, AMR_OF(3, pul_il[1]), 125, 143, 175, 207, 239, 139, 171, 203,
208
+                              235,
209
+     9, AMR_OF(3, pul_il[2]), 124, 151, 183, 215, 247, 147, 179, 211,
210
+                              243,
211
+     9, AMR_OF(3, pul_il[3]), 123, 159, 191, 223, 255, 155, 187, 219,
212
+                              251,
213
+     7,   AMR_OF(3, vq_gain),   1,  16,  42,  24,  36,  46,  28,
214
+     0
215
+};
216
+
217
+static const uint16_t order_MODE_14k25[] = {
218
+     1,         AMR_BIT(vad),   7,
219
+     8,   AMR_BIT(isp_id[0]),  55,  40,  14,   6,  15,   5,   0,  68,
220
+     8,   AMR_BIT(isp_id[1]),  77,  58,  75,  49,  59,  57,  67,  61,
221
+     6,   AMR_BIT(isp_id[2]),  48,  63,  51,  62,  50,  70,
222
+     7,   AMR_BIT(isp_id[3]),  71,  56,  60,  69,  85,  86,  80,
223
+     7,   AMR_BIT(isp_id[4]),  93,  64,  94,  76,  82,  81,  89,
224
+     5,   AMR_BIT(isp_id[5]),  90, 103,  88, 102,  99,
225
+     5,   AMR_BIT(isp_id[6]),  98,  97,  96, 111,  95,
226
+     9,      AMR_OF(0, adap),  13,  12,  11,  10,   9,  41,  66,  72,
227
+                               92,
228
+     1,       AMR_OF(0, ltp), 110,
229
+    13, AMR_OF(0, pul_il[0]), 114, 186, 210, 234, 258, 106, 126, 162,
230
+                              170, 198, 222, 246, 270,
231
+    13, AMR_OF(0, pul_il[1]), 122, 194, 218, 242, 266, 118, 134, 174,
232
+                              182, 206, 230, 254, 278,
233
+     9, AMR_OF(0, pul_il[2]), 130, 138, 146, 154, 178, 202, 226, 250,
234
+                              274,
235
+     9, AMR_OF(0, pul_il[3]), 142, 150, 158, 166, 190, 214, 238, 262,
236
+                              286,
237
+     7,   AMR_OF(0, vq_gain),   4,  19,  45,  27,  39,  33,  31,
238
+     6,      AMR_OF(1, adap),  35,  54,  79,  74,  84, 101,
239
+     1,       AMR_OF(1, ltp), 109,
240
+    13, AMR_OF(1, pul_il[0]), 113, 185, 209, 233, 257, 105, 125, 161,
241
+                              169, 197, 221, 245, 269,
242
+    13, AMR_OF(1, pul_il[1]), 121, 193, 217, 241, 265, 117, 133, 173,
243
+                              181, 205, 229, 253, 277,
244
+     9, AMR_OF(1, pul_il[2]), 129, 137, 145, 153, 177, 201, 225, 249,
245
+                              273,
246
+     9, AMR_OF(1, pul_il[3]), 141, 149, 157, 165, 189, 213, 237, 261,
247
+                              285,
248
+     7,   AMR_OF(1, vq_gain),   3,  18,  44,  26,  38,  32,  30,
249
+     9,      AMR_OF(2, adap),   8,  23,  22,  21,  20,  52,  65,  87,
250
+                               91,
251
+     1,       AMR_OF(2, ltp), 108,
252
+    13, AMR_OF(2, pul_il[0]), 112, 184, 208, 232, 256, 104, 124, 160,
253
+                              168, 196, 220, 244, 268,
254
+    13, AMR_OF(2, pul_il[1]), 120, 192, 216, 240, 264, 116, 132, 172,
255
+                              180, 204, 228, 252, 276,
256
+     9, AMR_OF(2, pul_il[2]), 128, 136, 144, 152, 176, 200, 224, 248,
257
+                              272,
258
+     9, AMR_OF(2, pul_il[3]), 140, 148, 156, 164, 188, 212, 236, 260,
259
+                              284,
260
+     7,   AMR_OF(2, vq_gain),   2,  17,  43,  25,  37,  47,  29,
261
+     6,      AMR_OF(3, adap),  34,  53,  78,  73,  83, 100,
262
+     1,       AMR_OF(3, ltp), 107,
263
+    13, AMR_OF(3, pul_il[0]), 127, 199, 223, 247, 271, 119, 123, 175,
264
+                              183, 195, 219, 243, 267,
265
+    13, AMR_OF(3, pul_il[1]), 135, 207, 231, 255, 279, 115, 131, 171,
266
+                              179, 203, 227, 251, 275,
267
+     9, AMR_OF(3, pul_il[2]), 143, 151, 159, 167, 191, 215, 239, 263,
268
+                              287,
269
+     9, AMR_OF(3, pul_il[3]), 139, 147, 155, 163, 187, 211, 235, 259,
270
+                              283,
271
+     7,   AMR_OF(3, vq_gain),   1,  16,  42,  24,  36,  46,  28,
272
+     0
273
+};
274
+
275
+static const uint16_t order_MODE_15k85[] = {
276
+     1,         AMR_BIT(vad),   7,
277
+     8,   AMR_BIT(isp_id[0]),  55,  40,  14,   6,  15,   5,   0,  68,
278
+     8,   AMR_BIT(isp_id[1]),  77,  58,  75,  49,  59,  57,  67,  61,
279
+     6,   AMR_BIT(isp_id[2]),  48,  63,  51,  62,  50,  70,
280
+     7,   AMR_BIT(isp_id[3]),  71,  56,  60,  69,  85,  86,  80,
281
+     7,   AMR_BIT(isp_id[4]),  93,  64,  94,  76,  82,  81,  89,
282
+     5,   AMR_BIT(isp_id[5]),  90, 103,  88, 102,  99,
283
+     5,   AMR_BIT(isp_id[6]),  98,  97,  96, 111,  95,
284
+     9,      AMR_OF(0, adap),  13,  12,  11,  10,   9,  41,  66,  72,
285
+                               92,
286
+     1,       AMR_OF(0, ltp), 110,
287
+    13, AMR_OF(0, pul_il[0]), 122, 154, 170, 218, 266, 138, 106, 182,
288
+                              230, 278, 178, 226, 274,
289
+    13, AMR_OF(0, pul_il[1]), 134, 166, 190, 238, 286, 150, 118, 186,
290
+                              234, 282, 198, 246, 294,
291
+    13, AMR_OF(0, pul_il[2]), 130, 162, 194, 242, 290, 146, 114, 206,
292
+                              254, 302, 202, 250, 298,
293
+    13, AMR_OF(0, pul_il[3]), 142, 174, 214, 262, 310, 158, 126, 210,
294
+                              258, 306, 222, 270, 318,
295
+     7,   AMR_OF(0, vq_gain),   4,  19,  45,  27,  39,  33,  31,
296
+     6,      AMR_OF(1, adap),  35,  54,  79,  74,  84, 101,
297
+     1,       AMR_OF(1, ltp), 109,
298
+    13, AMR_OF(1, pul_il[0]), 121, 153, 169, 217, 265, 137, 105, 181,
299
+                              229, 277, 177, 225, 273,
300
+    13, AMR_OF(1, pul_il[1]), 133, 165, 189, 237, 285, 149, 117, 185,
301
+                              233, 281, 197, 245, 293,
302
+    13, AMR_OF(1, pul_il[2]), 129, 161, 193, 241, 289, 145, 113, 205,
303
+                              253, 301, 201, 249, 297,
304
+    13, AMR_OF(1, pul_il[3]), 141, 173, 213, 261, 309, 157, 125, 209,
305
+                              257, 305, 221, 269, 317,
306
+     7,   AMR_OF(1, vq_gain),   3,  18,  44,  26,  38,  32,  30,
307
+     9,      AMR_OF(2, adap),   8,  23,  22,  21,  20,  52,  65,  87,
308
+                               91,
309
+     1,       AMR_OF(2, ltp), 108,
310
+    13, AMR_OF(2, pul_il[0]), 120, 152, 168, 216, 264, 136, 104, 180,
311
+                              228, 276, 176, 224, 272,
312
+    13, AMR_OF(2, pul_il[1]), 132, 164, 188, 236, 284, 148, 116, 184,
313
+                              232, 280, 196, 244, 292,
314
+    13, AMR_OF(2, pul_il[2]), 128, 160, 192, 240, 288, 144, 112, 204,
315
+                              252, 300, 200, 248, 296,
316
+    13, AMR_OF(2, pul_il[3]), 140, 172, 212, 260, 308, 156, 124, 208,
317
+                              256, 304, 220, 268, 316,
318
+     7,   AMR_OF(2, vq_gain),   2,  17,  43,  25,  37,  47,  29,
319
+     6,      AMR_OF(3, adap),  34,  53,  78,  73,  83, 100,
320
+     1,       AMR_OF(3, ltp), 107,
321
+    13, AMR_OF(3, pul_il[0]), 135, 167, 183, 231, 279, 151, 119, 179,
322
+                              227, 275, 191, 239, 287,
323
+    13, AMR_OF(3, pul_il[1]), 131, 163, 187, 235, 283, 147, 115, 199,
324
+                              247, 295, 195, 243, 291,
325
+    13, AMR_OF(3, pul_il[2]), 143, 175, 207, 255, 303, 159, 127, 203,
326
+                              251, 299, 215, 263, 311,
327
+    13, AMR_OF(3, pul_il[3]), 139, 171, 211, 259, 307, 155, 123, 223,
328
+                              271, 319, 219, 267, 315,
329
+     7,   AMR_OF(3, vq_gain),   1,  16,  42,  24,  36,  46,  28,
330
+     0
331
+};
332
+
333
+static const uint16_t order_MODE_18k25[] = {
334
+     1,         AMR_BIT(vad),   7,
335
+     8,   AMR_BIT(isp_id[0]),  55,  40,  14,   6,  15,   5,   0,  68,
336
+     8,   AMR_BIT(isp_id[1]),  77,  58,  75,  49,  59,  57,  67,  61,
337
+     6,   AMR_BIT(isp_id[2]),  48,  63,  51,  62,  50,  70,
338
+     7,   AMR_BIT(isp_id[3]),  71,  56,  60,  69,  85,  86,  80,
339
+     7,   AMR_BIT(isp_id[4]),  93,  64,  94,  76,  82,  81,  89,
340
+     5,   AMR_BIT(isp_id[5]),  90, 103,  88, 102,  99,
341
+     5,   AMR_BIT(isp_id[6]),  98,  97,  96, 111,  95,
342
+     9,      AMR_OF(0, adap),  13,  12,  11,  10,   9,  41,  66,  72,
343
+                               92,
344
+     1,       AMR_OF(0, ltp), 110,
345
+     2, AMR_OF(0, pul_ih[0]), 124, 115,
346
+     2, AMR_OF(0, pul_ih[1]), 150, 117,
347
+     2, AMR_OF(0, pul_ih[2]), 129, 114,
348
+     2, AMR_OF(0, pul_ih[3]), 121, 131,
349
+    14, AMR_OF(0, pul_il[0]), 161, 257, 343, 199, 177, 303, 204, 173,
350
+                              168, 260, 277, 307, 338, 128,
351
+    14, AMR_OF(0, pul_il[1]), 194, 286, 347, 222, 214, 316, 236, 152,
352
+                              166, 242, 284, 308, 344, 142,
353
+    14, AMR_OF(0, pul_il[2]), 169, 273, 353, 202, 189, 311, 240, 200,
354
+                              171, 261, 309, 296, 345, 130,
355
+    14, AMR_OF(0, pul_il[3]), 198, 275, 349, 187, 163, 282, 193, 195,
356
+                              175, 234, 265, 289, 328, 119,
357
+     7,   AMR_OF(0, vq_gain),   4,  19,  45,  27,  39,  33,  31,
358
+     6,      AMR_OF(1, adap),  35,  54,  79,  74,  84, 101,
359
+     1,       AMR_OF(1, ltp), 109,
360
+     2, AMR_OF(1, pul_ih[0]), 139, 104,
361
+     2, AMR_OF(1, pul_ih[1]), 135, 118,
362
+     2, AMR_OF(1, pul_ih[2]), 112, 127,
363
+     2, AMR_OF(1, pul_ih[3]), 140, 141,
364
+    14, AMR_OF(1, pul_il[0]), 179, 276, 340, 225, 223, 321, 235, 190,
365
+                              182, 271, 310, 315, 352, 125,
366
+    14, AMR_OF(1, pul_il[1]), 153, 264, 329, 232, 209, 323, 231, 165,
367
+                              191, 279, 290, 312, 367, 134,
368
+    14, AMR_OF(1, pul_il[2]), 167, 269, 341, 205, 197, 298, 224, 160,
369
+                              170, 259, 280, 317, 357, 148,
370
+    14, AMR_OF(1, pul_il[3]), 203, 272, 342, 227, 192, 299, 233, 172,
371
+                              183, 256, 283, 326, 355, 106,
372
+     7,   AMR_OF(1, vq_gain),   3,  18,  44,  26,  38,  32,  30,
373
+     9,      AMR_OF(2, adap),   8,  23,  22,  21,  20,  52,  65,  87,
374
+                               91,
375
+     1,       AMR_OF(2, ltp), 108,
376
+     2, AMR_OF(2, pul_ih[0]), 144, 120,
377
+     2, AMR_OF(2, pul_ih[1]), 157, 123,
378
+     2, AMR_OF(2, pul_ih[2]), 145, 138,
379
+     2, AMR_OF(2, pul_ih[3]), 132, 154,
380
+    14, AMR_OF(2, pul_il[0]), 241, 319, 365, 252, 253, 331, 254, 230,
381
+                              220, 263, 285, 314, 364, 156,
382
+    14, AMR_OF(2, pul_il[1]), 247, 291, 339, 249, 250, 332, 267, 196,
383
+                              207, 268, 304, 324, 356, 158,
384
+    14, AMR_OF(2, pul_il[2]), 210, 300, 348, 243, 237, 333, 246, 206,
385
+                              219, 266, 318, 335, 363, 159,
386
+    14, AMR_OF(2, pul_il[3]), 239, 306, 366, 221, 226, 297, 251, 184,
387
+                              178, 258, 292, 305, 346, 116,
388
+     7,   AMR_OF(2, vq_gain),   2,  17,  43,  25,  37,  47,  29,
389
+     6,      AMR_OF(3, adap),  34,  53,  78,  73,  83, 100,
390
+     1,       AMR_OF(3, ltp), 107,
391
+     2, AMR_OF(3, pul_ih[0]), 143, 126,
392
+     2, AMR_OF(3, pul_ih[1]), 137, 122,
393
+     2, AMR_OF(3, pul_ih[2]), 149, 105,
394
+     2, AMR_OF(3, pul_ih[3]), 133, 136,
395
+    14, AMR_OF(3, pul_il[0]), 162, 287, 337, 244, 229, 322, 218, 180,
396
+                              186, 262, 274, 288, 351, 146,
397
+    14, AMR_OF(3, pul_il[1]), 212, 294, 358, 248, 228, 334, 215, 174,
398
+                              176, 270, 293, 301, 354, 147,
399
+    14, AMR_OF(3, pul_il[2]), 185, 327, 336, 211, 213, 313, 245, 181,
400
+                              188, 255, 281, 325, 350, 151,
401
+    14, AMR_OF(3, pul_il[3]), 201, 295, 359, 216, 208, 320, 238, 164,
402
+                              155, 217, 278, 302, 330, 113,
403
+     7,   AMR_OF(3, vq_gain),   1,  16,  42,  24,  36,  46,  28,
404
+     0
405
+};
406
+
407
+static const uint16_t order_MODE_19k85[] = {
408
+     1,         AMR_BIT(vad),   7,
409
+     8,   AMR_BIT(isp_id[0]),  55,  40,  14,   6,  15,   5,   0,  68,
410
+     8,   AMR_BIT(isp_id[1]),  77,  58,  75,  49,  59,  57,  67,  61,
411
+     6,   AMR_BIT(isp_id[2]),  48,  63,  51,  62,  50,  70,
412
+     7,   AMR_BIT(isp_id[3]),  71,  56,  60,  69,  85,  86,  80,
413
+     7,   AMR_BIT(isp_id[4]),  93,  64,  94,  76,  82,  81,  89,
414
+     5,   AMR_BIT(isp_id[5]),  90, 103,  88, 102,  99,
415
+     5,   AMR_BIT(isp_id[6]),  98,  97,  96, 111,  95,
416
+     9,      AMR_OF(0, adap),  13,  12,  11,  10,   9,  41,  66,  72,
417
+                               92,
418
+     1,       AMR_OF(0, ltp), 110,
419
+    10, AMR_OF(0, pul_ih[0]), 134, 153, 263, 342, 399, 154, 106, 177,
420
+                              317, 265,
421
+    10, AMR_OF(0, pul_ih[1]), 128, 167, 270, 351, 385, 160, 105, 213,
422
+                              329, 259,
423
+     2, AMR_OF(0, pul_ih[2]), 123, 147,
424
+     2, AMR_OF(0, pul_ih[3]), 131, 143,
425
+    10, AMR_OF(0, pul_il[0]), 346, 118, 170, 201, 296, 368, 250, 284,
426
+                              341, 391,
427
+    10, AMR_OF(0, pul_il[1]), 345, 104, 166, 196, 281, 374, 242, 269,
428
+                              327, 390,
429
+    14, AMR_OF(0, pul_il[2]), 141, 171, 291, 364, 229, 210, 308, 228,
430
+                              206, 200, 258, 295, 313, 361,
431
+    14, AMR_OF(0, pul_il[3]), 144, 188, 282, 366, 217, 216, 309, 218,
432
+                              193, 182, 245, 287, 300, 367,
433
+     7,   AMR_OF(0, vq_gain),   4,  19,  45,  27,  39,  33,  31,
434
+     6,      AMR_OF(1, adap),  35,  54,  79,  74,  84, 101,
435
+     1,       AMR_OF(1, ltp), 109,
436
+    10, AMR_OF(1, pul_ih[0]), 139, 169, 267, 348, 389, 163, 116, 189,
437
+                              343, 268,
438
+    10, AMR_OF(1, pul_ih[1]), 120, 161, 249, 339, 397, 152, 114, 230,
439
+                              334, 303,
440
+     2, AMR_OF(1, pul_ih[2]), 125, 138,
441
+     2, AMR_OF(1, pul_ih[3]), 112, 129,
442
+    10, AMR_OF(1, pul_il[0]), 349, 122, 162, 203, 288, 372, 278, 274,
443
+                              312, 377,
444
+    10, AMR_OF(1, pul_il[1]), 357, 126, 165, 214, 298, 362, 252, 260,
445
+                              321, 378,
446
+    14, AMR_OF(1, pul_il[2]), 150, 199, 266, 355, 211, 180, 285, 241,
447
+                              195, 198, 243, 275, 323, 375,
448
+    14, AMR_OF(1, pul_il[3]), 142, 191, 256, 353, 208, 220, 314, 237,
449
+                              190, 212, 255, 304, 318, 371,
450
+     7,   AMR_OF(1, vq_gain),   3,  18,  44,  26,  38,  32,  30,
451
+     9,      AMR_OF(2, adap),   8,  23,  22,  21,  20,  52,  65,  87,
452
+                               91,
453
+     1,       AMR_OF(2, ltp), 108,
454
+    10, AMR_OF(2, pul_ih[0]), 159, 168, 302, 356, 395, 178, 132, 185,
455
+                              330, 286,
456
+    10, AMR_OF(2, pul_ih[1]), 158, 181, 292, 358, 396, 176, 133, 235,
457
+                              331, 276,
458
+     2, AMR_OF(2, pul_ih[2]), 130, 157,
459
+     2, AMR_OF(2, pul_ih[3]), 124, 136,
460
+    10, AMR_OF(2, pul_il[0]), 354, 121, 194, 246, 322, 379, 272, 273,
461
+                              332, 398,
462
+    10, AMR_OF(2, pul_il[1]), 359, 140, 186, 236, 333, 376, 290, 301,
463
+                              338, 387,
464
+    14, AMR_OF(2, pul_il[2]), 155, 227, 319, 369, 253, 254, 350, 248,
465
+                              224, 239, 240, 293, 315, 383,
466
+    14, AMR_OF(2, pul_il[3]), 156, 209, 297, 373, 225, 215, 326, 247,
467
+                              197, 184, 232, 289, 310, 365,
468
+     7,   AMR_OF(2, vq_gain),   2,  17,  43,  25,  37,  47,  29,
469
+     6,      AMR_OF(3, adap),  34,  53,  78,  73,  83, 100,
470
+     1,       AMR_OF(3, ltp), 107,
471
+    10, AMR_OF(3, pul_ih[0]), 148, 164, 264, 340, 388, 183, 117, 205,
472
+                              336, 261,
473
+    10, AMR_OF(3, pul_ih[1]), 146, 174, 257, 335, 384, 173, 113, 187,
474
+                              320, 279,
475
+     2, AMR_OF(3, pul_ih[2]), 127, 151,
476
+     2, AMR_OF(3, pul_ih[3]), 119, 137,
477
+    10, AMR_OF(3, pul_il[0]), 352, 135, 172, 238, 306, 381, 262, 271,
478
+                              328, 382,
479
+    10, AMR_OF(3, pul_il[1]), 347, 115, 179, 219, 305, 380, 277, 294,
480
+                              337, 386,
481
+    14, AMR_OF(3, pul_il[2]), 145, 192, 307, 370, 234, 223, 324, 244,
482
+                              202, 204, 251, 299, 325, 360,
483
+    14, AMR_OF(3, pul_il[3]), 149, 221, 311, 363, 226, 222, 316, 231,
484
+                              207, 175, 233, 280, 283, 344,
485
+     7,   AMR_OF(3, vq_gain),   1,  16,  42,  24,  36,  46,  28,
486
+     0
487
+};
488
+
489
+static const uint16_t order_MODE_23k05[] = {
490
+     1,         AMR_BIT(vad),   7,
491
+     8,   AMR_BIT(isp_id[0]),  55,  40,  14,   6,  15,   5,   0,  68,
492
+     8,   AMR_BIT(isp_id[1]),  77,  58,  75,  49,  59,  57,  67,  61,
493
+     6,   AMR_BIT(isp_id[2]),  48,  63,  51,  62,  50,  70,
494
+     7,   AMR_BIT(isp_id[3]),  71,  56,  60,  69,  85,  86,  80,
495
+     7,   AMR_BIT(isp_id[4]),  93,  64,  94,  76,  82,  81,  89,
496
+     5,   AMR_BIT(isp_id[5]),  90, 103,  88, 102,  99,
497
+     5,   AMR_BIT(isp_id[6]),  98,  97,  96, 111,  95,
498
+     9,      AMR_OF(0, adap),  13,  12,  11,  10,   9,  41,  66,  72,
499
+                               92,
500
+     1,       AMR_OF(0, ltp), 110,
501
+    11, AMR_OF(0, pul_ih[0]), 118, 129, 131, 153, 170, 282, 298, 210,
502
+                              191, 357, 317,
503
+    11, AMR_OF(0, pul_ih[1]), 126, 146, 135, 165, 187, 273, 345, 295,
504
+                              172, 338, 340,
505
+    11, AMR_OF(0, pul_ih[2]), 119, 137, 141, 167, 208, 304, 366, 256,
506
+                              177, 339, 328,
507
+    11, AMR_OF(0, pul_ih[3]), 116, 130, 120, 166, 190, 252, 311, 239,
508
+                              173, 343, 318,
509
+    11, AMR_OF(0, pul_il[0]), 245, 180, 342, 424, 259, 277, 266, 380,
510
+                              398, 423, 440,
511
+    11, AMR_OF(0, pul_il[1]), 218, 207, 367, 434, 201, 240, 275, 363,
512
+                              399, 419, 452,
513
+    11, AMR_OF(0, pul_il[2]), 274, 188, 348, 425, 242, 204, 262, 365,
514
+                              402, 431, 463,
515
+    11, AMR_OF(0, pul_il[3]), 221, 183, 337, 439, 243, 216, 251, 354,
516
+                              390, 411, 462,
517
+     7,   AMR_OF(0, vq_gain),   4,  19,  45,  27,  39,  33,  31,
518
+     6,      AMR_OF(1, adap),  35,  54,  79,  74,  84, 101,
519
+     1,       AMR_OF(1, ltp), 109,
520
+    11, AMR_OF(1, pul_ih[0]), 115, 140, 142, 161, 230, 291, 351, 235,
521
+                              181, 293, 310,
522
+    11, AMR_OF(1, pul_ih[1]), 104, 138, 132, 162, 211, 315, 347, 233,
523
+                              176, 320, 329,
524
+    11, AMR_OF(1, pul_ih[2]), 106, 134, 125, 154, 205, 267, 306, 220,
525
+                              185, 330, 297,
526
+    11, AMR_OF(1, pul_ih[3]), 105, 148, 122, 152, 215, 302, 350, 254,
527
+                              178, 319, 313,
528
+    11, AMR_OF(1, pul_il[0]), 269, 189, 382, 432, 272, 228, 263, 383,
529
+                              406, 422, 453,
530
+    11, AMR_OF(1, pul_il[1]), 286, 206, 377, 446, 226, 222, 265, 368,
531
+                              404, 416, 454,
532
+    11, AMR_OF(1, pul_il[2]), 247, 195, 358, 445, 224, 236, 309, 341,
533
+                              375, 408, 449,
534
+    11, AMR_OF(1, pul_il[3]), 225, 192, 359, 436, 250, 258, 290, 389,
535
+                              400, 420, 448,
536
+     7,   AMR_OF(1, vq_gain),   3,  18,  44,  26,  38,  32,  30,
537
+     9,      AMR_OF(2, adap),   8,  23,  22,  21,  20,  52,  65,  87,
538
+                               91,
539
+     1,       AMR_OF(2, ltp), 108,
540
+    11, AMR_OF(2, pul_ih[0]), 139, 144, 145, 169, 234, 327, 395, 299,
541
+                              244, 356, 379,
542
+    11, AMR_OF(2, pul_ih[1]), 127, 156, 158, 171, 231, 308, 397, 355,
543
+                              261, 371, 335,
544
+    11, AMR_OF(2, pul_ih[2]), 123, 155, 157, 193, 241, 362, 384, 323,
545
+                              238, 392, 361,
546
+    11, AMR_OF(2, pul_ih[3]), 114, 147, 121, 175, 196, 333, 373, 303,
547
+                              184, 353, 322,
548
+    11, AMR_OF(2, pul_il[0]), 271, 203, 385, 442, 307, 276, 334, 405,
549
+                              412, 427, 459,
550
+    11, AMR_OF(2, pul_il[1]), 278, 200, 388, 447, 292, 288, 296, 403,
551
+                              415, 429, 460,
552
+    11, AMR_OF(2, pul_il[2]), 312, 214, 393, 433, 279, 301, 314, 391,
553
+                              410, 426, 450,
554
+    11, AMR_OF(2, pul_il[3]), 280, 186, 376, 437, 268, 260, 255, 364,
555
+                              414, 417, 441,
556
+     7,   AMR_OF(2, vq_gain),   2,  17,  43,  25,  37,  47,  29,
557
+     6,      AMR_OF(3, adap),  34,  53,  78,  73,  83, 100,
558
+     1,       AMR_OF(3, ltp), 107,
559
+    11, AMR_OF(3, pul_ih[0]), 112, 159, 143, 164, 213, 281, 332, 284,
560
+                              168, 344, 325,
561
+    11, AMR_OF(3, pul_ih[1]), 113, 150, 149, 179, 199, 316, 324, 285,
562
+                              237, 360, 336,
563
+    11, AMR_OF(3, pul_ih[2]), 124, 136, 151, 174, 209, 326, 349, 248,
564
+                              198, 374, 331,
565
+    11, AMR_OF(3, pul_ih[3]), 117, 128, 133, 163, 202, 300, 372, 305,
566
+                              194, 387, 321,
567
+    11, AMR_OF(3, pul_il[0]), 249, 182, 352, 428, 253, 264, 289, 413,
568
+                              407, 418, 461,
569
+    11, AMR_OF(3, pul_il[1]), 287, 212, 369, 444, 223, 246, 217, 346,
570
+                              394, 401, 451,
571
+    11, AMR_OF(3, pul_il[2]), 219, 197, 378, 435, 229, 257, 283, 396,
572
+                              409, 430, 455,
573
+    11, AMR_OF(3, pul_il[3]), 232, 160, 370, 438, 227, 270, 294, 381,
574
+                              386, 421, 443,
575
+     7,   AMR_OF(3, vq_gain),   1,  16,  42,  24,  36,  46,  28,
576
+     0
577
+};
578
+
579
+static const uint16_t order_MODE_23k85[] = {
580
+     1,         AMR_BIT(vad),   7,
581
+     8,   AMR_BIT(isp_id[0]),  55,  40,  14,   6,  15,   5,   0,  68,
582
+     8,   AMR_BIT(isp_id[1]),  93,  58,  91,  49,  59,  57,  67,  61,
583
+     6,   AMR_BIT(isp_id[2]),  48,  63,  51,  62,  50,  70,
584
+     7,   AMR_BIT(isp_id[3]),  71,  56,  60,  69, 101, 102,  96,
585
+     7,   AMR_BIT(isp_id[4]), 109,  64, 110,  92,  98,  97, 105,
586
+     5,   AMR_BIT(isp_id[5]), 106, 119, 104, 118, 115,
587
+     5,   AMR_BIT(isp_id[6]), 114, 113, 112, 127, 111,
588
+     9,      AMR_OF(0, adap),  13,  12,  11,  10,   9,  41,  66,  88,
589
+                              108,
590
+     1,       AMR_OF(0, ltp), 126,
591
+    11, AMR_OF(0, pul_ih[0]), 134, 145, 147, 169, 186, 298, 314, 226,
592
+                              207, 373, 333,
593
+    11, AMR_OF(0, pul_ih[1]), 142, 162, 151, 181, 203, 289, 361, 311,
594
+                              188, 354, 356,
595
+    11, AMR_OF(0, pul_ih[2]), 135, 153, 157, 183, 224, 320, 382, 272,
596
+                              193, 355, 344,
597
+    11, AMR_OF(0, pul_ih[3]), 132, 146, 136, 182, 206, 268, 327, 255,
598
+                              189, 359, 334,
599
+    11, AMR_OF(0, pul_il[0]), 261, 196, 358, 440, 275, 293, 282, 396,
600
+                              414, 439, 456,
601
+    11, AMR_OF(0, pul_il[1]), 234, 223, 383, 450, 217, 256, 291, 379,
602
+                              415, 435, 468,
603
+    11, AMR_OF(0, pul_il[2]), 290, 204, 364, 441, 258, 220, 278, 381,
604
+                              418, 447, 479,
605
+    11, AMR_OF(0, pul_il[3]), 237, 199, 353, 455, 259, 232, 267, 370,
606
+                              406, 427, 478,
607
+     7,   AMR_OF(0, vq_gain),   4,  19,  45,  27,  39,  33,  31,
608
+     4,   AMR_OF(0, hb_gain),  79,  78,  77,  76,
609
+     6,      AMR_OF(1, adap),  35,  54,  95,  90, 100, 117,
610
+     1,       AMR_OF(1, ltp), 125,
611
+    11, AMR_OF(1, pul_ih[0]), 131, 156, 158, 177, 246, 307, 367, 251,
612
+                              197, 309, 326,
613
+    11, AMR_OF(1, pul_ih[1]), 120, 154, 148, 178, 227, 331, 363, 249,
614
+                              192, 336, 345,
615
+    11, AMR_OF(1, pul_ih[2]), 122, 150, 141, 170, 221, 283, 322, 236,
616
+                              201, 346, 313,
617
+    11, AMR_OF(1, pul_ih[3]), 121, 164, 138, 168, 231, 318, 366, 270,
618
+                              194, 335, 329,
619
+    11, AMR_OF(1, pul_il[0]), 285, 205, 398, 448, 288, 244, 279, 399,
620
+                              422, 438, 469,
621
+    11, AMR_OF(1, pul_il[1]), 302, 222, 393, 462, 242, 238, 281, 384,
622
+                              420, 432, 470,
623
+    11, AMR_OF(1, pul_il[2]), 263, 211, 374, 461, 240, 252, 325, 357,
624
+                              391, 424, 465,
625
+    11, AMR_OF(1, pul_il[3]), 241, 208, 375, 452, 266, 274, 306, 405,
626
+                              416, 436, 464,
627
+     7,   AMR_OF(1, vq_gain),   3,  18,  44,  26,  38,  32,  30,
628
+     4,   AMR_OF(1, hb_gain),  75,  74,  73,  72,
629
+     9,      AMR_OF(2, adap),   8,  23,  22,  21,  20,  52,  65, 103,
630
+                              107,
631
+     1,       AMR_OF(2, ltp), 124,
632
+    11, AMR_OF(2, pul_ih[0]), 155, 160, 161, 185, 250, 343, 411, 315,
633
+                              260, 372, 395,
634
+    11, AMR_OF(2, pul_ih[1]), 143, 172, 174, 187, 247, 324, 413, 371,
635
+                              277, 387, 351,
636
+    11, AMR_OF(2, pul_ih[2]), 139, 171, 173, 209, 257, 378, 400, 339,
637
+                              254, 408, 377,
638
+    11, AMR_OF(2, pul_ih[3]), 130, 163, 137, 191, 212, 349, 389, 319,
639
+                              200, 369, 338,
640
+    11, AMR_OF(2, pul_il[0]), 287, 219, 401, 458, 323, 292, 350, 421,
641
+                              428, 443, 475,
642
+    11, AMR_OF(2, pul_il[1]), 294, 216, 404, 463, 308, 304, 312, 419,
643
+                              431, 445, 476,
644
+    11, AMR_OF(2, pul_il[2]), 328, 230, 409, 449, 295, 317, 330, 407,
645
+                              426, 442, 466,
646
+    11, AMR_OF(2, pul_il[3]), 296, 202, 392, 453, 284, 276, 271, 380,
647
+                              430, 433, 457,
648
+     7,   AMR_OF(2, vq_gain),   2,  17,  43,  25,  37,  47,  29,
649
+     4,   AMR_OF(2, hb_gain),  87,  86,  85,  84,
650
+     6,      AMR_OF(3, adap),  34,  53,  94,  89,  99, 116,
651
+     1,       AMR_OF(3, ltp), 123,
652
+    11, AMR_OF(3, pul_ih[0]), 128, 175, 159, 180, 229, 297, 348, 300,
653
+                              184, 360, 341,
654
+    11, AMR_OF(3, pul_ih[1]), 129, 166, 165, 195, 215, 332, 340, 301,
655
+                              253, 376, 352,
656
+    11, AMR_OF(3, pul_ih[2]), 140, 152, 167, 190, 225, 342, 365, 264,
657
+                              214, 390, 347,
658
+    11, AMR_OF(3, pul_ih[3]), 133, 144, 149, 179, 218, 316, 388, 321,
659
+                              210, 403, 337,
660
+    11, AMR_OF(3, pul_il[0]), 265, 198, 368, 444, 269, 280, 305, 429,
661
+                              423, 434, 477,
662
+    11, AMR_OF(3, pul_il[1]), 303, 228, 385, 460, 239, 262, 233, 362,
663
+                              410, 417, 467,
664
+    11, AMR_OF(3, pul_il[2]), 235, 213, 394, 451, 245, 273, 299, 412,
665
+                              425, 446, 471,
666
+    11, AMR_OF(3, pul_il[3]), 248, 176, 386, 454, 243, 286, 310, 397,
667
+                              402, 437, 459,
668
+     7,   AMR_OF(3, vq_gain),   1,  16,  42,  24,  36,  46,  28,
669
+     4,   AMR_OF(3, hb_gain),  83,  82,  81,  80,
670
+     0
671
+};
672
+
673
+/** Reordering array addresses for each mode */
674
+static const uint16_t* amr_bit_orderings_by_mode[] = {
675
+    order_MODE_6k60,
676
+    order_MODE_8k85,
677
+    order_MODE_12k65,
678
+    order_MODE_14k25,
679
+    order_MODE_15k85,
680
+    order_MODE_18k25,
681
+    order_MODE_19k85,
682
+    order_MODE_23k05,
683
+    order_MODE_23k85
684
+};
685
+
686
+// Extracted from 3GPP TS 26.173 V9.0.0 (qpisf_2s.tab)
687
+// The *_36b tables are used in 6k60 mode
688
+// Stored in fixed-point to save some space
689
+/** Indexed tables for retrieval of quantized ISF vectors in Q15 */
690
+static const int16_t dico1_isf[256][9] = {
691
+ {  579,  1081,  1035,   390,     3,  -263,  -198,   -82,    38},
692
+ {   18,   -68,   -12,   313,   761,   405,   249,   111,   -76},
693
+ {  740,  1263,  1292,  1006,   997,  1019,  1017,   976,   923},
694
+ {  -91,   827,   948,   648,   613,   535,   522,   490,   421},
695
+ {   41,   -44,  -281,  -472,   652,   534,   193,   135,   -90},
696
+ {   41,  -121,  -356,   -60,   663,   307,    61,   -48,  -344},
697
+ {  557,   946,  1049,   867,   846,   990,  1112,  1262,  1241},
698
+ { -118,  -204,   328,   512,   870,   793,   610,   402,   186},
699
+ {  156,   293,    74,  -338,  -475,  -897,  -594,  -161,  -497},
700
+ {  226,   131,  -138,   307,   169,  -271,  -164,  -387,  -624},
701
+ {   62,   -32,   -61,  -252,  -541,  -828, -1027,  -523,  -662},
702
+ {  102,   -61,   141,   112,  -270,  -251,  -541,    25,  -150},
703
+ {    6,  -132,  -356,  -686,   -96,  -322,  -522,   -31,  -326},
704
+ {  -36,  -209,  -521,  -229,   307,  -132,    -5,   -99,  -384},
705
+ {   60,   -51,  -237,  -668,  -973,  -407,  -708,   -75,  -172},
706
+ {   26,  -138,  -266,   111,  -302,    43,  -278,  -356,  -359},
707
+ {  570,   822,   496,  -154,  -312,   -92,   137,   279,   371},
708
+ { -146,   368,   409,    68,     6,    77,   167,   202,   162},
709
+ {  633,   898,   996,   756,   662,   683,   783,   909,   996},
710
+ { -103,   294,   607,   415,   483,   462,   480,   431,   408},
711
+ { -120,  -338,  -612,  -524,   584,   331,    92,   433,   276},
712
+ { -178,  -293,  -154,   -41,   269,   100,    -9,   213,   160},
713
+ {  830,   736,   278,   820,  1254,   686,   712,  1039,   473},
714
+ { -218,  -304,   463,   454,   397,   273,   202,   286,   273},
715
+ { -232,     7,     6,  -388,  -472,  -427,  -378,  -167,  -100},
716
+ { -294,  -183,   134,   -47,   101,   -88,   -84,  -117,    -3},
717
+ {   57,    17,  -202,  -634,  -989, -1119,  -533,   176,   -36},
718
+ {  120,   -28,    23,   111,  -319,   318,   -22,   -77,   266},
719
+ { -271,  -464,  -434,  -658,  -640,  -385,  -385,   -99,   -69},
720
+ { -198,  -259,  -266,   -44,   -39,  -139,  -137,   171,    66},
721
+ {    9,  -145,  -377,  -846, -1000,  -111,  -325,   342,   135},
722
+ {  -81,  -286,  -380,   192,   -57,   307,    76,   -24,  -140},
723
+ {  677,   702,   247,    56,   249,   141,  -105,  -236,   -99},
724
+ {   36,   -39,   -69,   348,   198,   -93,   322,    91,   -72},
725
+ {  503,   885,  1508,  1307,  1282,  1172,  1119,  1209,  1061},
726
+ {  416,   719,   989,  1227,  1001,  1052,   954,   741,  1044},
727
+ { -127,  -376,  -657,   139,   623,   223,   501,   306,   220},
728
+ { -113,  -384,  -796,   504,   438,    85,   213,   -83,  -194},
729
+ {  585,  1132,  1233,  1091,  1247,  1433,  1512,  1448,  1314},
730
+ { -174,  -422,     7,  1155,  1089,  1182,  1003,   945,   806},
731
+ {    8,  -126,  -317,  -103,  -351,  -695,   -98,  -268,  -537},
732
+ {   33,  -103,  -290,   167,   -39,  -407,    44,  -208,  -375},
733
+ {  104,   -23,   -64,  -291,  -637,  -851, -1084,   -61,  -112},
734
+ {  -75,  -306,  -434,   218,  -148,  -354,  -680,  -133,  -216},
735
+ { -121,  -377,  -718,   -97,  -130,  -361,  -156,  -379,  -599},
736
+ {  -56,  -254,  -586,   235,   157,  -214,    11,  -260,  -149},
737
+ { -124,  -267,  -397,  -580,  -593,  -527,  -805,  -385,   346},
738
+ { -193,  -440,  -708,  -351,  -141,  -255,  -499,  -147,  -185},
739
+ {  448,   660,   494,   208,   509,   461,   338,   291,   149},
740
+ { -223,    88,   335,   159,   212,   191,   286,   308,   205},
741
+ {  -31,   469,   803,   659,   619,   658,   843,   987,  1113},
742
+ { -171,  -242,   514,   362,   295,   524,   552,   694,   585},
743
+ {  -64,  -308,  -448,   -21,   284,   786,   446,   289,    92},
744
+ { -218,  -390,    -7,   169,   206,   330,   352,   408,   358},
745
+ {  -36,   702,   959,   859,   861,  1115,  1269,  1357,  1305},
746
+ { -133,  -341,   -65,   678,   417,   440,   486,   518,   780},
747
+ {   33,   -44,  -191,  -344,  -461,  -755,  -201,   217,   -31},
748
+ { -353,  -547,   -44,   123,   -61,   -68,   -79,    29,    60},
749
+ {   73,   -57,  -406,  -766, -1243, -1203,   240,   400,   165},
750
+ {  -73,  -282,  -601,  -213,  -171,  -375,   332,    35,  -103},
751
+ {  -29,  -207,  -553,  -476,  -638,  -908,   172,   -22,  -135},
752
+ { -192,  -239,  -164,  -103,  -111,   -47,   153,   125,   110},
753
+ {   -1,  -203,  -570, -1030, -1424,  -535,   155,     1,   147},
754
+ { -333,  -653,  -865,  -197,  -158,   -21,   -44,    95,   108},
755
+ {  389,   588,   490,    33,  -237,  -524,  -628,  -136,  -260},
756
+ {   40,  -177,  -462,   453,   862,   380,   131,  -130,  -405},
757
+ {  842,  1678,  1841,  1549,  1474,  1256,  1082,   905,   742},
758
+ {  370,  1216,  1768,  1633,  1212,   636,    22,  -330,    71},
759
+ {  -76,  -281,  -741,  -742,   898,   619,   277,    71,  -222},
760
+ {  -32,  -265,  -556,   -25,   994,   682,   305,   126,  -165},
761
+ {   73,   738,   893,   968,   993,  1768,  2273,  1840,  1391},
762
+ {  -69,  -349,  -585,   234,  1158,   903,   626,   510,   251},
763
+ {   -1,   -99,  -272,  -210,  -603,  -351,  -540,  -811,  -383},
764
+ {  -16,  -230,  -504,   410,   149,  -205,  -343,  -651,  -639},
765
+ {  103,    -9,  -227,  -205,  -562,  -781, -1079, -1208,  -156},
766
+ {  143,    63,  -135,   -67,  -317,  -602,  -784, -1154,  -640},
767
+ { -144,  -391,  -674,  -622,  -200,  -254,  -660,  -947,  -395},
768
+ {  -40,  -250,  -625,    27,   543,    94,  -131,  -386,  -673},
769
+ { -123,  -371,  -757,  -451,  -564,  -614,  -415,  -711,   -35},
770
+ { -116,  -309,  -593,  -268,   239,   -33,  -338,  -650,  -135},
771
+ {   94,   251,   554,    57,  -312,  -423,  -154,   -57,   235},
772
+ { -268,   -71,   381,   114,   -44,   -87,   125,   173,   133},
773
+ { 1513,  1714,  1238,   534,   276,   315,   461,   459,   508},
774
+ { -131,   -19,  1149,   670,   486,   356,   309,   369,   296},
775
+ { -223,  -501,  -899,  -722,   -70,     6,   131,   310,   394},
776
+ {  -99,  -303,  -517,   249,    64,   -53,   135,   -11,   453},
777
+ { -147,  -399,  -730,  -401,   817,   738,   802,   749,   575},
778
+ { -154,  -435,  -739,   800,   593,   366,   529,   318,   326},
779
+ { -224,    45,   -39,  -387,  -515,  -518,  -608,  -384,  -321},
780
+ { -315,  -377,   143,  -101,  -113,  -377,  -177,  -144,   -12},
781
+ {  117,    40,  -239,  -651, -1051,  -581,  -737,  -990,  -328},
782
+ {   26,   -50,  -157,   -23,  -453,  -283,  -531,  -546,   192},
783
+ { -252,  -501,  -743,  -589,  -627,  -499,  -328,  -118,   -72},
784
+ { -324,  -494,  -244,  -306,  -144,  -177,  -262,  -135,   -78},
785
+ {  -36,  -234,  -519,  -961, -1290,  -314,  -479,  -371,   -45},
786
+ {  -95,  -292,  -535,    -8,  -300,   112,  -164,  -277,   198},
787
+ {  -99,  -128,   880,   836,   579,   351,    23,   -95,  -217},
788
+ {  -27,  -258,   124,  1011,   597,   425,   144,     7,   -73},
789
+ {  421,  1293,  1640,  1623,  1742,  1617,  1499,  1284,  1006},
790
+ {  -95,   752,  1680,  1569,  1618,  1436,  1200,   980,   712},
791
+ {  -69,  -300,  -683,  -435,  1132,   899,   504,   332,   109},
792
+ {  -74,  -323,  -637,   563,  1074,   608,   371,   105,   -49},
793
+ {  -78,   831,  1194,  1110,  1378,  1481,  1492,  1365,  1217},
794
+ { -259,  -121,  1440,  1334,  1628,  1490,  1438,  1223,   933},
795
+ {  -82,  -306,  -613,  -222,  -378,  -675,  -545,  -671,  -845},
796
+ {   53,  -124,  -347,   422,    52,  -125,  -270,  -529,     9},
797
+ {   79,   -89,  -320,  -662,  -999, -1199, -1243,  -676,  -297},
798
+ {  -68,  -273,  -611,   137,  -146,  -397,  -627,  -845,  -220},
799
+ { -112,  -346,  -797,  -826,   234,  -132,  -188,  -278,  -522},
800
+ { -159,  -405,  -734,  -419,   293,    74,  -167,  -167,   184},
801
+ { -153,  -437,  -833, -1080,  -336,  -472,  -561,  -340,  -253},
802
+ { -169,  -423,  -820,  -904,  -131,   -19,  -346,  -604,    31},
803
+ {   33,   -31,   312,    62,  -148,    49,   -59,   564,   486},
804
+ { -306,  -333,   194,   -44,    67,    72,   147,   205,   243},
805
+ { -207,   -49,  1360,   983,   969,   991,  1014,  1110,   973},
806
+ { -211,  -172,   883,   627,   711,   674,   705,   798,   746},
807
+ {  -88,  -325,  -763,  -974,   687,   908,   514,   382,   172},
808
+ { -292,  -612,  -805,    63,   131,   270,   259,   352,   348},
809
+ { -235,   -84,   955,   818,  1120,  1289,  1559,  1480,  1285},
810
+ { -180,  -461,  -614,   657,   691,   745,   854,   783,   713},
811
+ {  -97,  -309,  -477,  -614,  -777,  -734,  -768,  -526,  -472},
812
+ { -344,  -476,   -35,  -169,    49,   -77,  -150,  -240,  -141},
813
+ {  -52,  -268,  -639,  -919, -1278, -1113,  -342,  -333,  -151},
814
+ {  -68,  -242,  -585,   -73,  -209,  -478,  -159,  -429,   133},
815
+ { -197,  -499, -1005, -1268,  -272,  -224,  -105,   -67,    17},
816
+ { -363,  -618,  -414,  -116,   -62,    20,    10,   116,   108},
817
+ { -195,  -475,  -906, -1260,  -891,  -441,  -277,  -142,   -28},
818
+ { -226,  -519,  -950,  -700,  -275,  -266,  -116,  -105,    82},
819
+ {  404,   511,   520,   327,    17,  -194,  -333,  -536,  -586},
820
+ { -114,  -130,   276,   237,   204,   342,   135,   -16,  -111},
821
+ {  670,  1208,  1168,   860,   742,   601,   528,   403,   309},
822
+ {  397,   621,   966,   752,   579,   398,   400,   329,   252},
823
+ {  191,   180,  -137,  -467,   272,   106,   -95,    17,  -192},
824
+ {  -80,  -290,  -626,   194,   598,   196,    21,  -281,    77},
825
+ {  510,   864,  1108,   807,   939,   902,   925,   717,   481},
826
+ {  137,   367,   534,   764,   670,   382,   296,   153,    84},
827
+ {  303,   497,   144,   -85,  -125,  -539,  -482,  -464,  -764},
828
+ {  233,   347,    68,  -147,   169,  -210,  -242,  -226,  -482},
829
+ {  307,   422,   154,  -175,  -386,  -722,  -724,  -904, -1015},
830
+ {  309,   308,   160,   -60,  -470,  -420,  -598,  -791,  -219},
831
+ {   68,   121,  -137,  -560,  -146,  -446,  -515,  -494,  -729},
832
+ {  130,    53,  -227,    46,   474,    32,  -161,  -192,  -490},
833
+ {  213,   164,   -71,  -465,  -876,  -161,  -456,  -587,   -48},
834
+ {  218,   117,    39,   177,  -194,   -88,  -226,  -418,    50},
835
+ {  210,   547,   569,   279,   121,   -44,   -50,    10,   -84},
836
+ {   58,   140,   182,    -5,   267,   117,   106,   211,   198},
837
+ {  539,   835,   913,   719,   617,   544,   591,   565,   642},
838
+ {  153,   559,   872,   460,   222,   108,   188,   180,   183},
839
+ {  158,   119,   284,  -153,  -271,   229,    87,   110,   -57},
840
+ { -183,    82,   118,    21,    13,    40,   118,   191,   185},
841
+ {  162,   889,   654,   108,   -34,   244,   488,   561,   532},
842
+ {  163,    56,   609,   341,    50,   329,    68,   266,   218},
843
+ {  100,   206,    18,  -304,  -107,  -436,  -487,   -65,  -306},
844
+ {  -86,   154,   134,   -30,   -45,   -73,  -104,   -80,   -96},
845
+ {  245,   330,    10,  -440,  -849, -1082,    79,    40,  -265},
846
+ {  196,   372,   272,  -181,  -493,  -389,   275,    80,   -59},
847
+ {    2,   -12,  -246,  -505,  -100,  -436,    21,  -187,  -431},
848
+ { -221,   -48,    36,  -271,  -186,  -147,  -109,    26,    71},
849
+ {  213,   140,    72,  -351,  -620,   -84,  -363,    69,    46},
850
+ {   91,   167,    -3,   -95,   -99,  -105,   -48,   114,   147},
851
+ {  259,   249,   172,   607,   406,    52,    59,  -189,  -320},
852
+ {  115,   -85,   -54,   574,   128,   226,   -59,  -253,   130},
853
+ {  -62,  1033,  1308,  1035,  1127,  1098,  1029,   961,   823},
854
+ {   39,   364,   757,   940,   728,   660,   659,   583,   770},
855
+ { -115,  -338,  -760,  -471,   394,    37,   441,   178,     6},
856
+ {  -57,  -305,  -525,   796,   453,   188,    -4,  -114,   248},
857
+ {   71,   444,   797,   731,  1096,  1157,  1222,  1029,   811},
858
+ {  135,   359,   551,   425,   749,   815,   874,   704,   502},
859
+ {  132,   247,     0,  -206,  -449,  -750,  -258,  -514,  -633},
860
+ {  248,   249,    91,   121,  -195,  -499,   -90,  -282,  -435},
861
+ {   78,    20,  -277,  -623,  -983, -1224,  -415,  -458,  -639},
862
+ {  347,   509,   208,  -179,  -464,  -728,   -76,  -237,  -486},
863
+ { -103,  -343,  -756,  -713,  -265,  -609,  -191,  -398,  -636},
864
+ { -121,  -383,  -749,   567,   252,   -36,  -354,  -417,   -50},
865
+ {  204,   100,  -149,  -650, -1081,   -47,    -7,  -263,   111},
866
+ {  -46,  -180,  -267,  -324,  -562,  -394,  -692,   398,   292},
867
+ {  482,   670,   683,   624,   442,   165,   116,    36,  -149},
868
+ {  108,   247,   291,   247,   355,   122,   109,   224,   296},
869
+ {  -14,   945,   990,   801,   755,   815,   847,   913,   892},
870
+ {  292,   349,   725,   482,   388,   329,   429,   620,   667},
871
+ {  -34,   197,   213,  -127,    84,   494,   620,   575,   375},
872
+ {  126,   207,   172,   167,   362,   202,   296,   395,   455},
873
+ {   -6,   250,   539,   467,   636,   801,  1149,  1287,  1118},
874
+ {   27,   240,   369,   280,   440,   411,   634,   892,   953},
875
+ {  159,   170,   -58,  -395,  -797,  -690,    77,  -211,  -334},
876
+ {   -5,   -28,   -13,   -74,  -335,  -603,   300,    88,  -205},
877
+ {   82,   -33,  -364,  -698, -1203, -1153,   110,  -146,  -289},
878
+ {  113,     1,  -243,  -588,  -994,  -496,   414,   160,    42},
879
+ {  -56,  -247,  -440,  -693,  -996,  -479,    11,  -178,  -357},
880
+ { -151,  -353,  -327,  -211,  -340,   141,    65,   425,   453},
881
+ {   34,  -169,  -455,  -932, -1215,   138,   499,   256,   324},
882
+ {   68,   139,   -15,  -547,  -478,    17,   306,   502,   481},
883
+ {  -32,  -134,   445,   129,  -143,  -244,  -503,  -507,  -599},
884
+ {   61,  -140,  -345,   496,   458,    -2,    20,  -227,  -514},
885
+ {  394,  1765,  1666,  1339,  1117,   806,   642,   479,   380},
886
+ {  215,   519,   920,  1053,  1090,   791,   528,   290,   155},
887
+ {  -54,  -233,  -647,  -602,   639,   294,    -2,  -167,  -442},
888
+ {  -78,  -315,  -791,  -113,   820,   403,   158,  -116,  -356},
889
+ {  529,  1851,  2003,  1228,   622,   -41,  -416,   344,   819},
890
+ { -105,  -379,  -236,  1224,   893,   749,   568,   356,   214},
891
+ {  -17,  -199,  -144,    50,  -283,  -247,  -578,  -846, -1087},
892
+ {   69,   -11,  -381,  -206,   209,  -284,  -387,  -416,  -716},
893
+ {   39,    -5,  -145,  -374,  -682,  -909, -1074, -1169, -1066},
894
+ {  287,   226,    67,  -221,  -662,  -171,  -421,  -642,  -707},
895
+ { -132,  -348,  -538,  -448,   -20,    -4,  -354,  -748,  -933},
896
+ {    4,   -75,  -289,  -598,   317,    52,  -208,  -297,  -559},
897
+ {  -88,  -264,  -358,  -589,  -631,  -248,  -523,  -822, -1071},
898
+ {   70,    -8,    54,  -314,  -515,    92,  -146,  -274,  -493},
899
+ {  199,    62,   391,   158,  -141,    71,  -219,  -203,  -207},
900
+ {  152,    40,   329,   162,   -29,    48,  -149,   108,   127},
901
+ {  635,  1058,   883,   492,   372,   312,   317,   274,   241},
902
+ {  267,   722,  1256,   882,   625,   248,     8,   -81,   -60},
903
+ {  -58,  -138,  -291,  -600,   -12,    -2,   -39,   147,   117},
904
+ { -107,  -345,  -513,   459,    76,    92,  -272,   388,   262},
905
+ {  362,   516,   203,  -409,  -716,  -831,  -331,   185,   209},
906
+ { -117,  -391,  -298,   671,   292,   538,   257,   166,   -38},
907
+ { -102,  -319,  -194,  -283,  -573,  -262,  -579,  -219,  -444},
908
+ { -235,    78,    11,  -168,  -101,  -229,  -263,  -321,  -123},
909
+ {   70,    50,  -170,  -599,  -996,  -588,  -263,  -516,  -455},
910
+ {  394,   363,   229,  -136,  -538,    21,  -183,  -348,  -201},
911
+ { -124,  -368,  -640,  -879,  -847,  -209,  -409,  -494,  -515},
912
+ { -127,  -341,  -541,  -425,  -510,   -10,  -252,  -473,  -291},
913
+ {   84,   -69,  -201,  -676,  -868,   103,  -311,  -132,  -320},
914
+ {    5,  -173,  -188,  -297,  -628,   197,   -57,     7,   -11},
915
+ {   49,  -160,    56,   558,   111,    33,  -311,  -440,  -463},
916
+ {   -1,  -246,  -307,   862,   453,   139,  -170,  -355,  -232},
917
+ {  279,   966,  1642,  1478,  1463,  1123,   795,   525,   339},
918
+ { -197,   -38,  1702,  1331,  1252,   950,   692,   504,   426},
919
+ { -108,  -344,  -861, -1172,   444,   354,    88,   -46,  -220},
920
+ {  -53,  -321,  -494,  1113,   744,   364,   198,   -34,   -75},
921
+ {  457,   955,  1177,  1214,  1427,  1457,  1345,   917,   539},
922
+ {  -69,   199,   897,  1140,  1343,  1183,   977,   742,   522},
923
+ {  122,    44,  -269,    27,  -155,  -562,  -307,  -590,  -773},
924
+ {  154,    42,  -160,   252,  -129,  -305,  -471,  -733,  -371},
925
+ {  135,   185,   -82,  -416,  -722,  -913,  -504,  -743,  -880},
926
+ {  149,   214,   -84,  -329,  -680,  -835,  -426,  -661,   -81},
927
+ { -128,  -380,  -735,  -998,  -337,    17,  -182,  -467,  -697},
928
+ {  -84,  -290,  -510,  -592,    13,   440,   154,   -38,  -279},
929
+ {   70,   -61,  -246,  -727, -1047,   -80,  -381,  -535,  -704},
930
+ {  178,    -2,  -146,  -670,  -938,   482,   138,    63,    65},
931
+ {  -11,    15,   772,   443,   142,   -20,  -209,  -126,  -161},
932
+ {  -32,  -249,    95,   552,   124,    30,  -343,    82,   -86},
933
+ {  148,   751,  1515,  1105,   867,   606,   474,   448,   399},
934
+ { -163,  -257,   899,  1097,   906,   751,   502,   390,   294},
935
+ {  -51,  -258,  -447,  -806,  -368,   763,   464,   364,   183},
936
+ { -166,  -374,  -367,    87,    35,   399,   418,   856,   833},
937
+ { -205,  -310,   588,   778,   785,  1065,  1118,  1245,  1157},
938
+ { -173,  -312,   107,   345,   400,   790,   870,  1113,  1001},
939
+ {   -7,  -120,  -387,  -410,  -614,  -943,  -226,  -384,  -491},
940
+ { -203,  -288,   -51,  -331,   -90,  -178,  -408,  -573,  -338},
941
+ {   56,   -29,  -273,  -627, -1041,  -798,  -247,  -467,   148},
942
+ {   66,    -2,  -205,  -205,  -575,  -349,   -57,  -352,   -58},
943
+ {  -45,  -225,  -471,  -924,  -497,    77,   -32,    44,  -135},
944
+ { -277,  -491,  -497,  -502,  -424,  -202,  -137,    77,    96},
945
+ {   26,  -179,  -469, -1008, -1260,   262,   -35,  -132,  -259},
946
+ {  -66,  -232,  -447,  -533,  -789,  -191,  -100,  -267,   364}
947
+};
948
+
949
+static const int16_t dico2_isf[256][7] = {
950
+ {  1357,  1313,  1136,   784,   438,   181,   145},
951
+ {   636,   648,   667,   568,   442,   217,   362},
952
+ {   427,   440,   674,   524,   332,   117,  -417},
953
+ {   121,   295,   468,   465,   230,    44,  -221},
954
+ {  -147,  -240,   149,    80,   390,   278,   106},
955
+ {  -418,  -556,   552,   511,   235,   144,   -95},
956
+ {    43,   193,   274,   150,    67,    34,  -273},
957
+ {   -43,  -126,   171,   416,   282,    63,  -354},
958
+ {  -372,   -86,  -344,  -108,   -94,  -182,   -89},
959
+ {  -600,  -840,  -200,   465,   258,   -11,  -253},
960
+ {   -48,   329,    97,  -290,  -543,  -795,  -354},
961
+ {  -570,  -117,   187,    10,  -133,  -416,   -76},
962
+ {  -618,  -129,  -247,  -371,    45,   -76,   277},
963
+ { -1022, -1079,   126,   474,   254,   127,    52},
964
+ {  -281,    76,  -167,  -361,  -283,  -551,  -283},
965
+ {  -119,   -52,    -1,   134,   -32,  -204,  -415},
966
+ {  1064,   827,   637,   684,   464,   209,    12},
967
+ {   482,   416,   449,   371,   335,   294,   194},
968
+ {   719,   576,   365,   135,   113,    91,  -199},
969
+ {   298,   176,   493,   366,   194,   163,    36},
970
+ {   -35,  -236,  -259,   -36,    -4,    99,   152},
971
+ {   -98,  -306,   -27,   228,    90,   111,   -86},
972
+ {    91,    13,  -211,  -258,  -106,    86,   -64},
973
+ {    73,   -35,   -57,   -31,   162,    35,  -192},
974
+ {  -109,  -335,  -629,   -66,   -61,  -128,   322},
975
+ {  -495,  -669,  -728,   193,    31,  -220,   122},
976
+ {   324,    95,   -89,   -91,  -409,  -710,  -154},
977
+ {     0,  -234,    92,    33,  -343,  -609,  -220},
978
+ {  -343,  -408,  -476,  -655,  -153,    82,   222},
979
+ {  -490,  -745,  -255,    49,   -48,   135,  -127},
980
+ {   119,   -67,  -328,  -390,  -272,  -545,   -56},
981
+ {   -57,  -130,   -10,    -7,  -164,   -47,   -22},
982
+ {   984,  1064,   961,   568,   210,   -27,    16},
983
+ {   811,   691,   754,   514,   224,   -35,   166},
984
+ {   662,   704,   618,   386,    57,  -211,  -257},
985
+ {   510,   359,   418,   393,    91,  -144,   -18},
986
+ {  -193,   -31,   -27,   223,    89,  -143,    24},
987
+ {  -112,   -98,   471,   319,   185,     3,   175},
988
+ {   252,   146,   -47,   272,    48,  -211,  -234},
989
+ {   146,    69,   203,   364,    68,   -52,    51},
990
+ {  -259,  -478,  -697,  -349,  -758,  -501,    63},
991
+ {  -501,  -769,  -289,    79,  -311,  -497,  -106},
992
+ {   251,    53,  -235,  -469,  -895,  -884,   145},
993
+ {  -416,  -551,   140,  -133,  -523,  -775,    44},
994
+ {  -326,  -423,  -713,  -497,   -86,  -431,    99},
995
+ {  -757,  -772,  -160,   -76,   -46,   -32,   379},
996
+ {    85,   -35,  -200,  -401,  -663, -1040,  -247},
997
+ {  -180,  -330,   -92,  -376,    27,  -183,  -110},
998
+ {  1279,  1086,   781,   502,   324,   164,   157},
999
+ {   682,   466,   449,   277,   146,    28,   409},
1000
+ {   635,   472,   390,   107,  -232,  -538,  -139},
1001
+ {   196,   396,   332,   213,   209,   -29,   -81},
1002
+ {   150,   -95,  -312,    76,   -77,  -320,   -50},
1003
+ {    46,     9,    47,   175,   139,    30,   384},
1004
+ {   218,   206,   -24,  -250,   -96,  -276,  -183},
1005
+ {    26,   119,    38,    14,    -4,  -133,   -52},
1006
+ {  -477,  -614,  -987,  -715,  -631,  -813,   200},
1007
+ {  -744, -1009, -1065,  -745,  -631,  -171,    18},
1008
+ {  -137,  -251,  -483,  -613,  -980, -1203,    12},
1009
+ {  -605,  -767,  -562,  -686, -1088,  -515,    58},
1010
+ {  -202,  -428,  -782, -1072,   -96,  -234,  -179},
1011
+ {  -480,  -709, -1070,  -897,  -131,   -92,   321},
1012
+ {  -145,  -193,  -512,  -729,  -572,  -765,  -210},
1013
+ {  -331,  -585,  -525,  -631,  -281,  -208,  -303},
1014
+ {  1165,  1104,   939,   828,   716,   426,   155},
1015
+ {     6,  -109,   820,   778,   415,   113,   -27},
1016
+ {   381,   339,   314,   265,   121,    -9,  -474},
1017
+ {  -373,    47,   584,   442,    99,  -231,  -113},
1018
+ {  -496,   -38,  -285,   262,   305,   170,     4},
1019
+ {  -587,  -556,    69,    66,   471,   354,    13},
1020
+ {  -138,    70,   -18,   106,    67,   167,  -302},
1021
+ {  -445,  -141,   185,   191,   151,    83,  -133},
1022
+ {  -257,  -521,  -720,  -198,   134,   -46,  -182},
1023
+ {  -819, -1168,  -777,   512,   359,    95,  -113},
1024
+ {   137,    -2,   -74,  -138,  -401,  -114,  -371},
1025
+ {  -242,  -466,   204,   223,   -31,  -212,  -192},
1026
+ {  -532,  -637,  -466,  -686,   256,   277,  -139},
1027
+ { -1141, -1244,  -381,   -75,   -54,    14,    88},
1028
+ {  -311,   115,  -143,  -499,  -343,   124,  -416},
1029
+ {  -616,  -147,  -135,    43,    -4,   121,  -369},
1030
+ {   835,   783,   641,   390,   355,   350,    64},
1031
+ {    72,   194,   443,   467,   436,   219,   372},
1032
+ {   464,   369,   192,     4,  -156,   -72,  -226},
1033
+ {    57,   206,   303,   205,   188,   101,   265},
1034
+ {   -40,  -205,  -488,  -184,   276,    64,   -26},
1035
+ {  -217,  -433,  -297,   137,   328,   308,  -289},
1036
+ {   378,    81,  -308,  -465,    57,   -37,   227},
1037
+ {  -100,    24,   -36,  -151,   199,     8,   143},
1038
+ {  -426,  -697, -1059,  -133,   388,   161,   321},
1039
+ {  -644, -1023, -1271,    39,    66,  -123,    70},
1040
+ {   372,   177,  -173,  -556,  -553,  -304,  -189},
1041
+ {  -117,  -369,  -425,  -122,  -462,  -152,   -73},
1042
+ {  -649,  -850, -1189,  -767,   497,   360,   222},
1043
+ {  -798, -1139, -1455,  -190,   430,   234,   179},
1044
+ {    42,   -94,  -405,  -692,    38,  -202,  -246},
1045
+ {  -169,  -366,  -290,   -88,   -64,    32,  -292},
1046
+ {  1010,   923,   938,   710,   465,   230,   342},
1047
+ {   217,   300,  1054,   675,    68,  -458,  -179},
1048
+ {    78,   453,   316,    18,  -237,  -496,  -243},
1049
+ {   167,    21,   424,   215,   -91,  -303,  -170},
1050
+ {  -290,   -81,   -70,   -67,    40,    54,   -59},
1051
+ {  -353,  -427,   -90,    53,    94,     9,    54},
1052
+ {   -28,   318,   283,    15,  -240,   -58,    79},
1053
+ {   -75,  -121,   229,    35,    58,     6,  -133},
1054
+ {  -351,  -514,  -744,  -834,  -705,  -137,   164},
1055
+ { -1124, -1388, -1055,  -230,   -73,    40,    36},
1056
+ {  -163,  -233,  -532,  -785, -1170,  -697,    96},
1057
+ {  -788,  -959,  -246,  -430,  -624,  -165,    -8},
1058
+ {  -856,  -540,  -630,  -907,  -337,   -70,    76},
1059
+ {  -937, -1042,  -659,  -733,  -208,   199,   -26},
1060
+ {  -523,    78,   -98,  -501,  -869,  -890,   -81},
1061
+ {  -624,  -703,   -45,  -348,   -25,    87,  -186},
1062
+ {  1005,   823,   546,   249,    90,   -22,   207},
1063
+ {   298,   397,   381,   319,   200,    62,   303},
1064
+ {   473,   379,   133,  -247,  -632,  -441,    75},
1065
+ {   284,   208,   391,   115,   -25,    44,    95},
1066
+ {   -72,    79,   -95,   -63,  -129,  -293,   203},
1067
+ {  -164,  -349,   115,   122,    69,    -1,   378},
1068
+ {   348,   170,    99,    58,  -179,  -302,   188},
1069
+ {  -190,    -2,   150,    23,   -51,   -11,   216},
1070
+ {  -615,  -863, -1090, -1427,  -802,   -48,    -6},
1071
+ {  -961, -1276, -1548,  -727,   -58,    56,   223},
1072
+ {  -124,  -255,  -561,  -988, -1277,  -148,   -82},
1073
+ {  -480,  -660,  -891, -1191, -1339,  -325,    20},
1074
+ {  -621,  -917, -1296, -1350,   264,   289,    50},
1075
+ {  -844, -1022, -1345, -1329,  -293,    46,   278},
1076
+ {  -260,  -468,  -829, -1176,  -533,  -560,   -78},
1077
+ {  -215,  -484,  -822, -1233,  -791,    15,  -138},
1078
+ {  1301,  1317,  1262,  1048,   716,   357,   -64},
1079
+ {   578,   824,   925,   802,   630,   362,   102},
1080
+ {   470,   925,   767,   514,   327,   190,  -112},
1081
+ {   225,   492,   495,   437,   598,   384,   -45},
1082
+ {    43,    82,   -42,   175,   519,   342,   -64},
1083
+ {  -304,  -154,   159,   576,   403,   221,   327},
1084
+ {   214,   244,   122,   -62,   312,    92,  -160},
1085
+ {   218,   208,   310,   268,   306,   323,  -199},
1086
+ {  -285,  -269,   -79,  -124,  -143,  -153,   236},
1087
+ {  -205,  -384,  -426,   344,    59,  -185,  -184},
1088
+ {  -272,   247,   126,  -210,  -518,  -468,    78},
1089
+ {   -99,  -120,   502,   160,  -280,  -557,   304},
1090
+ {  -423,   -17,  -283,  -443,   215,   212,  -140},
1091
+ {  -564,  -684,  -228,   510,   361,   130,   323},
1092
+ {  -428,   335,    98,   -65,    36,  -215,  -246},
1093
+ {  -362,    51,   364,   -16,  -234,   150,  -165},
1094
+ {   914,   883,   751,   653,   676,   464,  -153},
1095
+ {   631,   545,   535,   720,   596,   360,   -81},
1096
+ {   783,   712,   512,   439,   341,   251,  -391},
1097
+ {   497,   417,   249,   372,   295,   173,  -193},
1098
+ {   128,  -110,  -385,    93,    39,   173,  -231},
1099
+ {   216,   -59,  -253,   462,   389,   154,    69},
1100
+ {   455,   270,    -4,  -337,   -49,   233,  -322},
1101
+ {   307,   143,    53,   218,   128,   236,  -156},
1102
+ {   -37,  -186,  -240,  -411,  -110,     9,   399},
1103
+ {  -140,  -365,  -628,   258,   380,   214,   277},
1104
+ {   131,   454,   177,  -285,  -520,   108,  -214},
1105
+ {    77,  -141,   201,  -123,  -490,  -131,    60},
1106
+ {   -14,  -194,  -521,  -741,   273,   362,   -33},
1107
+ {  -362,  -566,  -287,  -228,   161,   237,   317},
1108
+ {  -269,   195,   -75,  -375,  -204,    11,    77},
1109
+ {  -128,  -264,  -156,  -223,  -475,   265,    27},
1110
+ {  1238,  1147,   916,   689,   432,   210,  -280},
1111
+ {   800,   664,   879,   726,   411,   160,  -164},
1112
+ {   454,   686,   536,   275,   147,    46,   111},
1113
+ {   303,   486,   512,   355,   241,   181,   -69},
1114
+ {    79,    92,    29,   147,   233,    52,    17},
1115
+ {  -171,   289,   131,   439,   271,     3,   -10},
1116
+ {   413,   241,   144,   174,   155,    -2,    14},
1117
+ {    58,   217,   247,   219,   149,   175,   -18},
1118
+ {   228,    -8,  -240,  -206,  -513,  -191,   202},
1119
+ {   -96,  -272,  -454,    33,  -300,  -575,    46},
1120
+ {   -10,  -108,  -246,  -347,  -770,  -535,     9},
1121
+ {  -326,  -430,   -61,  -321,  -704,  -299,   201},
1122
+ {    -1,  -280,  -603,  -419,  -185,    18,   -36},
1123
+ {  -516,  -522,  -379,  -291,  -181,   -97,    27},
1124
+ {  -159,  -313,  -525,  -224,  -510,  -831,  -197},
1125
+ {  -292,  -459,   -59,  -310,  -562,  -143,  -351},
1126
+ {  1066,   912,   631,   389,   207,    86,  -224},
1127
+ {   596,   512,   596,   505,   314,   122,   -48},
1128
+ {   787,   861,   441,   -93,  -303,    33,  -190},
1129
+ {   257,   469,   337,    51,    15,   298,   -93},
1130
+ {   295,    73,  -119,    25,    36,    23,   108},
1131
+ {   -28,    -3,   -32,   114,    21,   185,   107},
1132
+ {   482,   305,    15,  -279,  -319,    52,    96},
1133
+ {   226,    46,   115,    72,  -136,   133,  -125},
1134
+ {    18,  -207,  -559,  -590,  -503,  -482,   321},
1135
+ {  -571,  -789,  -951,  -172,  -441,  -538,   113},
1136
+ {   181,    14,  -310,  -641, -1001,  -202,   159},
1137
+ {  -136,  -393,  -433,  -513,  -911,  -144,   -22},
1138
+ {    72,  -265,  -706,  -954,  -159,    53,   332},
1139
+ {  -338,  -591,  -852,  -383,  -395,    56,    44},
1140
+ {    43,  -158,  -464,  -897,  -631,  -157,  -294},
1141
+ {  -161,  -128,  -328,  -573,  -483,  -125,    11},
1142
+ {  1017,   906,  1051,  1005,   679,   341,  -102},
1143
+ {   359,   334,  1567,  1314,   723,   105,    10},
1144
+ {   -65,   726,   529,   301,   220,    43,  -273},
1145
+ {  -510,   436,   719,   566,   358,   179,   114},
1146
+ {  -560,   298,   133,  -120,   342,   225,    14},
1147
+ {  -899,  -101,   217,   617,   400,   146,   -58},
1148
+ {   -41,   352,    82,  -196,    39,   121,  -167},
1149
+ {  -212,    59,   447,   284,   423,   250,  -169},
1150
+ {  -371,  -484,  -596,    30,   -41,   249,    22},
1151
+ {  -372,  -650,  -794,   477,   445,   216,   -79},
1152
+ {  -352,   275,    17,  -443,  -929,    92,    19},
1153
+ {  -699,  -696,   431,   264,   -49,  -310,   182},
1154
+ {  -978,  -217,  -430,  -400,   101,   261,    72},
1155
+ {  -929,  -889,  -357,   -13,   463,   378,   236},
1156
+ {  -826,    56,    30,  -299,  -360,  -128,   -51},
1157
+ {  -878,  -299,  -111,    75,    65,    36,     3},
1158
+ {   817,   368,   -25,   354,   697,   591,  -173},
1159
+ {   309,   212,   222,   751,   484,   140,   -56},
1160
+ {   593,   379,    70,    -8,   258,   180,   110},
1161
+ {   165,   -46,   255,   297,   219,   273,   105},
1162
+ {   160,   -70,  -358,  -181,   379,   330,   319},
1163
+ {  -238,  -369,  -198,   740,   580,   319,  -143},
1164
+ {   201,   109,  -202,  -456,   328,   276,  -141},
1165
+ {   203,   170,   111,    42,   207,   360,   188},
1166
+ {  -345,  -399,  -513,  -233,   650,   422,    81},
1167
+ {  -635,  -961, -1220,   463,   539,   204,   209},
1168
+ {   202,   -25,  -194,  -498,  -787,   193,  -143},
1169
+ {  -449,  -538,   195,  -106,  -331,    68,    62},
1170
+ {  -228,  -477,  -840,  -576,   317,   128,   283},
1171
+ {  -671,  -937,  -807,  -114,   391,   335,   -62},
1172
+ {   246,     2,  -314,  -679,  -303,   180,   -88},
1173
+ {  -107,  -272,    90,  -198,   -28,   290,  -112},
1174
+ {   885,  1149,  1021,   712,   496,   281,   -83},
1175
+ {   269,   492,   787,   643,   347,    70,   124},
1176
+ {   336,   636,   499,    92,  -229,  -179,   191},
1177
+ {    26,   402,   564,   340,   149,   -11,   135},
1178
+ {  -440,   561,   470,   204,   -72,  -186,   140},
1179
+ {  -720,    14,   355,   229,    68,  -133,   465},
1180
+ {   110,   310,   103,    12,   106,    29,   158},
1181
+ {  -178,   113,   161,   142,   121,   115,    27},
1182
+ {  -651,  -414,  -645,  -152,  -164,   -13,  -429},
1183
+ {  -639,  -944,  -681,  -104,   -81,    52,  -189},
1184
+ {  -663,  -164,  -316,  -683,  -954,  -205,   -83},
1185
+ {  -609,  -669,  -172,  -517,  -694,   283,   -80},
1186
+ {  -646,  -152,  -383,  -678,  -246,   -40,  -143},
1187
+ {  -747,  -796,  -745,  -390,   -98,    43,   275},
1188
+ {  -599,  -199,  -398,  -433,  -436,  -538,    31},
1189
+ { -1107,  -568,  -376,  -265,  -126,   -21,     1},
1190
+ {   847,   573,   308,   392,   305,   101,    55},
1191
+ {   273,   293,   201,   267,   346,   201,   123},
1192
+ {   727,   480,   226,     2,   -65,  -138,   164},
1193
+ {   273,   208,   173,   292,    12,   253,   174},
1194
+ {   340,   207,   180,    88,   116,    46,   475},
1195
+ {  -460,  -166,   -30,    13,   110,   173,   396},
1196
+ {   137,    88,    43,  -137,   -94,    34,   284},
1197
+ {    96,   -14,   226,    40,    63,    70,   130},
1198
+ {  -467,  -735, -1012, -1174,  -307,   305,   -67},
1199
+ {  -612,  -920, -1146,  -567,    -8,    92,   -25},
1200
+ {  -182,  -271,  -492,  -754,  -857,   287,   -75},
1201
+ {  -494,  -787,  -689,  -683,  -709,   137,  -326},
1202
+ {  -288,  -550,  -903, -1105,   334,   321,   -62},
1203
+ {  -354,  -653,  -834,  -445,     1,   377,  -152},
1204
+ {  -162,  -306,  -608,  -937,  -297,   247,  -192},
1205
+ {  -234,  -477,  -244,  -488,  -266,   342,  -332}
1206
+};
1207
+
1208
+static const int16_t dico21_isf[64][3] = {
1209
+ {   329,   409,   249}, {   -33,   505,   160},
1210
+ {   -29,   -14,   582}, {  -262,   127,   354},
1211
+ {   145,   237,   175}, {  -152,   245,   122},
1212
+ {    27,    42,   340}, {   -84,   -93,   311},
1213
+ {   285,   222,  -156}, {    47,   -43,  -504},
1214
+ {   234,   121,   385}, {   104,  -317,    45},
1215
+ {   176,   195,     8}, {   104,   -59,   -94},
1216
+ {   177,    53,   192}, {   -34,  -127,   152},
1217
+ {   570,   277,   -34}, {   -67,  -329,  -639},
1218
+ {  -157,  -272,   462}, {  -177,  -462,   198},
1219
+ {   322,   179,   115}, {  -386,   171,    19},
1220
+ {    19,   -12,   195}, {  -120,  -252,   201},
1221
+ {   304,    36,  -336}, {  -128,  -221,  -380},
1222
+ {   171,  -185,   296}, {  -242,  -312,    23},
1223
+ {   198,    39,    16}, {    -3,  -177,  -111},
1224
+ {   111,   -93,    76}, {   -92,  -223,     4},
1225
+ {   177,   406,   -44}, {  -168,   380,  -149},
1226
+ {    -4,   273,   331}, {  -420,   513,   277},
1227
+ {    21,   247,    47}, {   -58,   131,    -2},
1228
+ {    -3,   134,   180}, {  -145,    40,   175},
1229
+ {   189,    74,  -145}, {   -27,   -45,  -325},
1230
+ {   370,  -114,   -21}, {   -83,  -415,  -173},
1231
+ {    77,    95,   -51}, {   -40,   -30,   -67},
1232
+ {    71,    88,    86}, {   -35,   -98,    14},
1233
+ {    69,   197,  -334}, {  -196,    79,  -231},
1234
+ {  -348,  -137,   218}, {  -352,   -89,   -85},
1235
+ {    47,   201,  -130}, {  -165,    37,   -15},
1236
+ {   -43,     3,    86}, {  -161,  -108,    79},
1237
+ {    83,    21,  -237}, {   -81,  -149,  -238},
1238
+ {   150,  -186,  -251}, {  -186,  -249,  -162},
1239
+ {   -19,    66,  -139}, {   -26,   -50,  -181},
1240
+ {    24,    11,     0}, {  -130,  -105,   -98}
1241
+};
1242
+
1243
+static const int16_t dico22_isf[128][3] = {
1244
+ {  -127,   310,    42}, {  -242,   197,     5},
1245
+ {  -151,    84,   -17}, {  -214,   127,  -149},
1246
+ {  -247,  -131,   159}, {  -268,  -267,   -95},
1247
+ {  -217,     1,   -79}, {  -271,   -80,  -185},
1248
+ {   -45,   436,   159}, {   165,   199,   391},
1249
+ {   -33,    81,   187}, {   -66,   -42,   355},
1250
+ {  -298,   -57,   343}, {  -108,  -537,   226},
1251
+ {  -144,   -23,   193}, {   176,  -402,    87},
1252
+ {    53,   296,    25}, {   -84,   253,  -104},
1253
+ {   -58,   105,  -126}, {  -169,   174,  -314},
1254
+ {   -48,    44,  -294}, {  -164,  -417,  -242},
1255
+ {  -139,     3,  -194}, {  -155,  -207,  -211},
1256
+ {   119,   322,   213}, {   333,    50,   380},
1257
+ {   237,   247,    -2}, {   466,   -16,   201},
1258
+ {   238,  -255,  -107}, {    67,  -440,  -149},
1259
+ {   122,   -88,  -139}, {    88,  -247,   -73},
1260
+ {   -41,   231,   167}, {   -62,   155,    16},
1261
+ {   -65,    16,    77}, {   -68,    -2,   -63},
1262
+ {  -151,  -300,   160}, {   -18,  -333,    54},
1263
+ {   -56,   -94,     5}, {     2,  -190,    14},
1264
+ {    92,   148,   209}, {   108,     9,   272},
1265
+ {   108,    35,   110}, {   142,   -85,   145},
1266
+ {    47,  -157,   279}, {     3,  -320,   246},
1267
+ {    43,   -72,    68}, {    86,  -217,   135},
1268
+ {    36,   140,    79}, {    56,   175,   -49},
1269
+ {    26,    45,     3}, {    73,    55,  -101},
1270
+ {   109,  -183,  -242}, {    -4,  -283,  -242},
1271
+ {    48,   -68,   -48}, {    -6,  -153,  -122},
1272
+ {   161,   196,    96}, {   232,    80,   190},
1273
+ {   165,    97,    11}, {   258,   -31,    71},
1274
+ {   267,   -77,   -91}, {   311,  -209,    87},
1275
+ {   152,   -14,   -22}, {   150,  -149,     9},
1276
+ {  -324,   557,   187}, {  -384,   307,    46},
1277
+ {  -251,    27,    77}, {  -365,    77,   -52},
1278
+ {  -482,   -84,   160}, {  -424,  -515,   -64},
1279
+ {  -294,  -120,    -4}, {  -476,  -116,  -109},
1280
+ {   -97,   318,   365}, {   106,   627,   445},
1281
+ {  -190,   120,   287}, {  -146,    65,   619},
1282
+ {  -427,   242,   363}, {  -361,  -371,   432},
1283
+ {  -347,   102,   168}, {  -629,   195,   -14},
1284
+ {   -65,   476,   -47}, {  -297,   320,  -168},
1285
+ {   -55,   356,  -264}, {  -391,    82,  -286},
1286
+ {   -51,   -31,  -556}, {  -178,  -399,  -586},
1287
+ {  -205,   -49,  -360}, {  -343,  -238,  -337},
1288
+ {   220,   457,    58}, {   561,   467,   259},
1289
+ {   340,   270,  -168}, {   450,    77,  -280},
1290
+ {    60,   167,  -413}, {   133,  -252,  -492},
1291
+ {   216,   157,  -290}, {   282,     0,  -495},
1292
+ {  -226,   293,   183}, {  -157,   135,   122},
1293
+ {  -158,   -59,    39}, {  -133,  -118,   -97},
1294
+ {  -332,  -309,   113}, {  -160,  -425,    -6},
1295
+ {  -149,  -211,    24}, {   -80,  -277,   -90},
1296
+ {   -11,   125,   338}, {   130,   -71,   465},
1297
+ {     5,   -45,   184}, {   237,   -95,   253},
1298
+ {  -139,  -197,   297}, {   -19,  -300,   511},
1299
+ {   -63,  -152,   139}, {   250,  -289,   336},
1300
+ {   124,   339,  -150}, {    34,   176,  -208},
1301
+ {   171,   166,  -116}, {    94,    38,  -229},
1302
+ {    75,   -65,  -339}, {   -78,  -205,  -385},
1303
+ {     0,   -30,  -163}, {   -56,  -110,  -242},
1304
+ {   321,   244,   194}, {   505,   238,    -1},
1305
+ {   317,   116,    65}, {   309,    88,   -74},
1306
+ {   452,   -51,   -50}, {   334,  -217,  -290},
1307
+ {   211,    41,  -152}, {   238,   -55,  -260}
1308
+};
1309
+
1310
+static const int16_t dico23_isf[128][3] = {
1311
+ {   -10,   151,   359}, {   136,   298,   223},
1312
+ {   255,  -104,   290}, {   423,     6,   183},
1313
+ {  -270,  -269,   -98}, {   -52,   -82,    13},
1314
+ {   -82,  -274,   -97}, {    90,  -246,   -72},
1315
+ {  -299,   -70,   421}, {   -88,   365,   430},
1316
+ {   187,  -318,   381}, {   380,    37,   488},
1317
+ {  -373,  -316,    79}, {  -308,  -101,     5},
1318
+ {  -135,  -451,     8}, {    72,  -421,  -154},
1319
+ {   180,   170,  -121}, {    62,   177,   -40},
1320
+ {   326,    80,  -105}, {   248,   263,    -5},
1321
+ {  -168,  -181,  -221}, {    -2,   -23,  -158},
1322
+ {   -14,  -149,  -121}, {   119,   -91,  -147},
1323
+ {   119,   332,  -153}, {    49,   303,    34},
1324
+ {   442,   -55,   -69}, {   217,   454,    58},
1325
+ {  -359,  -187,  -375}, {   -42,    50,  -274},
1326
+ {    -8,  -267,  -249}, {    85,   -86,  -346},
1327
+ {   -77,   -40,   345}, {    89,   134,   219},
1328
+ {   156,   -80,   160}, {   108,    40,   116},
1329
+ {  -158,  -206,    29}, {     5,   -32,   175},
1330
+ {   -65,  -158,   146}, {    55,   -78,    73},
1331
+ {  -114,  -222,   353}, {   -47,    81,   211},
1332
+ {    49,  -151,   268}, {   105,     4,   302},
1333
+ {  -263,  -132,   183}, {  -151,   -28,   201},
1334
+ {  -177,  -307,   166}, {   101,  -221,   130},
1335
+ {    74,    58,   -98}, {    32,    44,    13},
1336
+ {   194,    30,  -142}, {   170,    96,     8},
1337
+ {  -136,  -119,   -91}, {   -65,     8,   -55},
1338
+ {     3,  -188,    12}, {    45,   -63,   -49},
1339
+ {   149,   -21,   -19}, {    24,   144,    95},
1340
+ {   254,   -22,    60}, {   161,   196,    96},
1341
+ {  -158,   -61,    48}, {   -70,    33,    82},
1342
+ {   -23,  -321,    58}, {   155,  -147,     5},
1343
+ {  -364,   328,    77}, {   -21,   453,   173},
1344
+ {  -108,    82,   630}, {   367,   263,   208},
1345
+ {  -300,   -62,  -176}, {  -205,   143,  -158},
1346
+ {  -169,  -410,  -264}, {   257,  -269,  -100},
1347
+ {  -636,   289,    -2}, {  -292,   627,   173},
1348
+ {  -382,  -363,   387}, {   248,   524,   447},
1349
+ {  -521,  -111,  -107}, {  -395,   118,  -274},
1350
+ {  -343,  -680,  -125}, {  -172,  -447,  -663},
1351
+ {    75,   148,  -367}, {   -79,   263,   -94},
1352
+ {   249,   148,  -286}, {   380,   271,  -162},
1353
+ {  -142,    -4,  -186}, {   -57,   111,  -125},
1354
+ {   -35,  -108,  -254}, {   100,    29,  -242},
1355
+ {   -80,   303,  -264}, {   -78,   464,   -57},
1356
+ {   248,   -22,  -494}, {   661,   662,    44},
1357
+ {  -193,   -40,  -330}, {  -178,   145,  -337},
1358
+ {   -90,  -199,  -400}, {   -40,   -23,  -498},
1359
+ {  -192,   114,   315}, {   -41,   244,   190},
1360
+ {    88,   -97,   485}, {   241,    80,   212},
1361
+ {  -246,    40,    87}, {  -156,   147,   134},
1362
+ {    -2,  -334,   239}, {   308,  -203,   110},
1363
+ {  -459,   251,   422}, {  -218,   310,   228},
1364
+ {   -86,  -346,   654}, {   184,   175,   425},
1365
+ {  -481,   -63,   169}, {  -349,   117,   188},
1366
+ {  -125,  -560,   310}, {   158,  -416,    94},
1367
+ {    46,   171,  -192}, {   -63,   157,    14},
1368
+ {   256,   -35,  -271}, {   322,   123,    53},
1369
+ {  -214,     4,   -76}, {  -156,    86,   -18},
1370
+ {   128,  -197,  -232}, {   265,   -90,   -98},
1371
+ {  -308,   332,  -145}, {  -131,   308,    58},
1372
+ {   509,    59,  -339}, {   562,   196,   -14},
1373
+ {  -378,   100,   -47}, {  -234,   202,     1},
1374
+ {   104,  -270,  -493}, {   319,  -210,  -325}
1375
+};
1376
+
1377
+static const int16_t dico24_isf[32][3] = {
1378
+ {   -79,   -89,    -4}, {  -171,    77,  -211},
1379
+ {   160,  -193,    98}, {   120,  -103,   323},
1380
+ {    32,   -22,  -129}, {    72,    78,  -268},
1381
+ {   182,   -76,   -66}, {   309,    99,  -145},
1382
+ {  -229,  -157,   -84}, {  -383,    98,   -71},
1383
+ {   -90,  -352,    12}, {  -284,  -178,   178},
1384
+ {   -65,  -125,  -166}, {   -87,  -175,  -351},
1385
+ {    42,  -198,   -48}, {   154,  -140,  -243},
1386
+ {   -77,    18,   108}, {   -39,   355,    91},
1387
+ {    87,     8,   155}, {    -4,   158,   239},
1388
+ {   128,    95,   -54}, {     7,   246,  -124},
1389
+ {   258,    15,    89}, {   206,   216,    98},
1390
+ {  -201,     9,    18}, {  -312,   233,   204},
1391
+ {   -39,  -174,   155}, {  -144,    -9,   284},
1392
+ {   -57,    70,   -69}, {  -157,   187,    18},
1393
+ {    54,   -30,    23}, {    24,   135,    55}
1394
+};
1395
+
1396
+static const int16_t dico25_isf[32][4] = {
1397
+ {   169,   142,  -119,   115}, {   206,   -20,    94,   226},
1398
+ {  -106,   313,   -21,    16}, {   -62,   161,    71,   255},
1399
+ {   -89,   101,  -185,   125}, {    72,   -30,  -201,   344},
1400
+ {  -258,    33,    -8,    81}, {  -104,  -154,    72,   296},
1401
+ {   144,   -68,  -268,   -25}, {    81,   -78,   -87,   106},
1402
+ {    22,   155,  -186,  -119}, {   -46,   -28,    27,    91},
1403
+ {  -114,   -37,  -175,   -33}, {   -94,  -222,  -189,   122},
1404
+ {  -132,  -119,  -191,  -270}, {  -172,  -173,    18,   -43},
1405
+ {   279,   135,   -42,  -128}, {   187,   -86,   229,  -138},
1406
+ {   159,   240,   140,    46}, {    69,    25,   227,    77},
1407
+ {    21,   115,    13,     8}, {    68,  -248,   126,    81},
1408
+ {  -150,   137,   207,    -9}, {  -154,  -133,   289,    67},
1409
+ {   143,   -37,   -86,  -326}, {   180,   -32,    19,   -23},
1410
+ {    26,   168,   116,  -233}, {   -32,   -26,   118,   -78},
1411
+ {     3,    -8,   -45,  -115}, {    57,  -215,   -54,   -83},
1412
+ {  -209,   112,   -22,  -167}, {   -91,  -151,   168,  -262}
1413
+};
1414
+
1415
+static const int16_t dico21_isf_36b[128][5] = {
1416
+ {   -52,   -96,   212,   315,   -73}, {    82,  -204,   363,   136,  -197},
1417
+ {  -126,  -331,   183,   218,   143}, {   -49,   -41,   557,   230,    72},
1418
+ {     2,   -73,   163,   377,   221}, {   133,   111,   278,   215,  -110},
1419
+ {  -102,   -20,   284,   113,   273}, {    84,   319,   290,    18,    85},
1420
+ {   -25,    -5,   125,   132,  -204}, {   -38,    -5,   286,    -9,  -356},
1421
+ {  -140,  -256,    92,   117,  -189}, {  -144,   191,   313,    51,   -98},
1422
+ {   167,   -10,    44,   247,    36}, {   381,   197,   238,    74,     6},
1423
+ {    38,  -408,    29,    -3,   -85}, {    92,   266,   157,   -25,  -200},
1424
+ {   161,  -121,    70,    84,  -140}, {   -16,   -86,   112,   -94,  -189},
1425
+ {  -269,  -270,   351,   107,   -24}, {   -68,   -67,   492,  -103,  -155},
1426
+ {   -53,  -131,    62,   122,    10}, {   135,    84,   283,   -55,  -120},
1427
+ {   -12,  -219,   331,   -81,   167}, {   220,  -136,   147,  -172,   -42},
1428
+ {   140,   -95,  -109,   -88,  -194}, {     0,    -2,    -4,   -33,  -381},
1429
+ {   -66,  -217,   152,  -186,  -402}, {   244,   108,   156,  -140,  -395},
1430
+ {   113,  -136,  -196,   110,   -24}, {   214,   118,    11,   -64,  -131},
1431
+ {  -110,  -286,    -6,  -332,    16}, {    94,    97,    79,  -291,  -205},
1432
+ {    -5,   -39,   -20,   252,   -96}, {    76,   174,   101,   163,    61},
1433
+ {   -69,  -239,   -55,   399,     6}, {  -115,   319,   164,   275,   196},
1434
+ {   -15,    36,   -47,   331,   121}, {   226,   209,   271,   325,   184},
1435
+ {    13,   -80,  -218,   471,   353}, {   288,   378,    16,   -51,   251},
1436
+ {   174,   116,    52,   149,  -279}, {   235,   276,    39,   120,   -48},
1437
+ {     0,  -108,  -108,   241,  -339}, {   -93,   534,    45,    33,   -87},
1438
+ {   194,   149,   -71,   405,   -44}, {   409,   370,    81,  -186,  -154},
1439
+ {    25,  -102,  -448,   124,  -173}, {    22,   408,  -110,  -310,  -214},
1440
+ {   -26,    23,   -83,   114,    14}, {  -110,   164,    52,   223,   -82},
1441
+ {    37,   -25,  -263,   306,   -15}, {  -466,   415,   292,   165,   -18},
1442
+ {    29,   -19,  -171,   155,   182}, {   179,   144,   -27,   231,   258},
1443
+ {  -103,  -247,  -396,   238,   113}, {   375,  -154,  -109,    -4,   156},
1444
+ {    98,    85,  -292,    -5,  -124}, {   116,   139,  -116,   -98,  -294},
1445
+ {   -14,   -83,  -278,  -117,  -378}, {   106,    33,  -106,  -344,  -484},
1446
+ {   119,    17,  -412,   138,   166}, {   384,   101,  -204,    88,  -156},
1447
+ {  -121,  -284,  -300,    -1,  -166}, {   280,    33,  -152,  -313,   -81},
1448
+ {   -37,    22,   229,   153,    37}, {   -60,   -83,   236,    -8,   -41},
1449
+ {  -169,  -228,   126,   -20,   363}, {  -235,    17,   364,  -156,   156},
1450
+ {   -25,   -30,    72,   144,   156}, {   153,   -26,   256,    97,   144},
1451
+ {   -21,   -37,    48,   -65,   250}, {    63,    77,   273,  -128,   124},
1452
+ {  -129,   -26,    40,     9,  -115}, {    -6,    82,    38,   -90,  -182},
1453
+ {  -336,   -13,    28,   158,    91}, {   -30,   241,   137,  -170,   -17},
1454
+ {   146,    14,   -11,    33,    61}, {   192,   197,    54,   -84,    85},
1455
+ {    23,  -200,   -78,   -29,   140}, {   122,   237,   106,  -341,   136},
1456
+ {   -57,  -142,   -85,   -16,   -74}, {   -59,   -90,    -8,  -187,   -20},
1457
+ {  -211,  -267,   216,  -179,  -110}, {   -50,    -7,   220,  -267,   -70},
1458
+ {   -57,   -42,   -17,   -15,    71}, {    32,    21,    63,  -137,    33},
1459
+ {  -137,  -175,   104,   -68,    97}, {   -67,   -43,   133,  -301,   221},
1460
+ {  -116,  -200,   -81,   -92,  -272}, {   -64,   -41,   -54,  -244,  -220},
1461
+ {  -287,  -242,   -50,   -87,   -89}, {  -245,   236,   102,  -166,  -295},
1462
+ {    66,    24,  -162,   -71,    95}, {    66,   136,   -90,  -220,   -36},
1463
+ {   -98,  -161,  -222,  -188,    29}, {   -18,    18,   -19,  -415,     9},
1464
+ {    49,    61,   100,    39,   -56}, {  -111,    82,   135,   -31,    52},
1465
+ {   -90,  -153,   -93,   189,   182}, {  -214,   295,   119,   -74,   284},
1466
+ {     2,   137,    37,    47,   182}, {    92,   117,   184,   -53,   373},
1467
+ {   -21,   -14,   -35,   136,   391}, {   146,   129,  -164,   -28,   333},
1468
+ {    92,    80,   -84,   100,  -134}, {    -8,   217,   -32,     3,   -47},
1469
+ {  -151,   251,  -215,   142,    92}, {  -224,   310,  -172,  -275,    98},
1470
+ {   159,   155,  -177,   112,    53}, {   205,    27,     8,  -240,   192},
1471
+ {   169,   120,  -319,  -201,   106}, {    11,    36,   -86,  -237,   455},
1472
+ {  -109,  -154,  -163,   174,   -55}, {   -38,    32,  -101,   -78,   -59},
1473
+ {  -205,  -321,   -97,    69,    79}, {  -310,    44,    18,  -185,    34},
1474
+ {  -115,   -20,  -148,   -39,   203}, {   -29,   154,   -30,  -158,   166},
1475
+ {   -45,  -131,  -317,   -24,   363}, {  -165,  -205,  -112,  -222,   265},
1476
+ {   -32,   -44,  -150,    54,  -193}, {    -6,   -38,  -255,  -169,  -115},
1477
+ {  -266,    87,  -189,   -36,  -169}, {   -60,   -87,  -266,  -436,  -170},
1478
+ {   -68,   -81,  -278,    24,    38}, {   -23,   -19,  -155,  -256,   141},
1479
+ {   -61,  -226,  -565,  -175,    71}, {     9,   -29,  -237,  -515,   263}
1480
+};
1481
+
1482
+static const int16_t dico22_isf_36b[128][4] = {
1483
+ {  -298,    -6,    95,    31}, {  -213,   -87,  -122,   261},
1484
+ {     4,   -49,   208,    14}, {  -129,  -110,    30,   118},
1485
+ {  -214,   258,   110,  -235}, {   -41,   -18,  -126,   120},
1486
+ {   103,    65,   127,   -37}, {   126,   -36,   -24,    25},
1487
+ {  -138,   -67,  -278,  -186}, {  -164,  -194,  -201,    78},
1488
+ {  -211,   -87,   -51,  -221}, {  -174,   -79,   -94,   -39},
1489
+ {    23,    -6,  -157,  -240}, {    22,  -110,  -153,   -68},
1490
+ {   148,    -5,    -2,  -149}, {    -1,  -135,   -39,  -179},
1491
+ {    68,   360,  -117,   -15}, {   137,    47,  -278,   146},
1492
+ {   136,   260,   135,    65}, {    61,   116,   -45,    97},
1493
+ {   231,   379,    87,  -120}, {   338,   177,  -272,     3},
1494
+ {   266,   156,    28,   -69}, {   260,    84,   -85,    86},
1495
+ {  -266,   154,  -256,  -182}, {   -17,   -65,  -304,    -6},
1496
+ {   -40,   175,  -151,  -180}, {   -27,    27,   -87,   -63},
1497
+ {   121,   114,  -166,  -469}, {   159,   -66,  -323,  -231},
1498
+ {   214,   152,  -141,  -212}, {   137,    36,  -184,   -51},
1499
+ {  -282,  -237,    40,    10}, {   -48,  -235,   -37,   251},
1500
+ {   -54,  -323,   136,    29}, {   -88,  -174,   213,   198},
1501
+ {  -390,    99,   -63,  -375}, {   107,  -169,  -164,   424},
1502
+ {    69,  -111,   141,  -167}, {    74,  -129,    65,   144},
1503
+ {  -353,  -207,  -205,  -109}, {  -160,  -386,  -355,    98},
1504
+ {  -176,  -493,   -20,  -143}, {  -252,  -432,    -2,   216},
1505
+ {   -90,  -174,  -168,  -411}, {    13,  -284,  -229,  -160},
1506
+ {   -87,  -279,    34,  -251}, {   -75,  -263,   -58,   -42},
1507
+ {   420,    53,  -211,  -358}, {   384,   -35,  -374,   396},
1508
+ {    68,  -228,   323,    -2}, {   167,  -307,   192,   194},
1509
+ {   459,   329,    -5,  -332}, {   375,    79,    -7,   313},
1510
+ {   282,  -124,   200,   -92}, {   271,  -162,   -70,   180},
1511
+ {  -157,  -298,  -514,  -309}, {    58,  -163,  -546,    18},
1512
+ {   124,  -364,   167,  -238}, {    83,  -411,  -117,    96},
1513
+ {   140,  -112,  -388,  -624}, {   259,  -133,  -317,    41},
1514
+ {   163,  -130,   -64,  -334}, {   226,  -165,  -124,  -110},
1515
+ {  -466,   -61,     6,   229}, {  -153,   205,  -145,   242},
1516
+ {  -159,    48,   195,   148}, {   -58,    28,    31,   279},
1517
+ {  -303,   185,   279,    -4}, {   -61,   197,    59,    86},
1518
+ {  -114,   123,   168,   -52}, {    35,    36,   100,   126},
1519
+ {  -407,   102,   -77,   -40}, {  -338,    -1,  -342,   156},
1520
+ {  -179,   105,   -34,   -97}, {  -185,    84,   -35,   108},
1521
+ {  -133,   107,   -91,  -357}, {  -180,    54,  -229,    24},
1522
+ {   -44,    47,    47,  -182}, {   -66,    13,    45,     4},
1523
+ {  -339,   251,    64,   226}, {   -42,   101,  -350,   275},
1524
+ {   -99,   398,   142,   121}, {   111,    12,  -102,   260},
1525
+ {     0,   505,   260,   -94}, {   161,   285,   -96,   224},
1526
+ {    -4,   206,   314,    33}, {   167,   139,    88,   204},
1527
+ {  -235,   316,   -60,   -25}, {    -8,  -150,  -312,   201},
1528
+ {   -36,   292,    61,  -104}, {   -40,   174,  -162,    42},
1529
+ {   -21,   402,   -29,  -351}, {    21,   152,  -360,   -93},
1530
+ {    57,   191,   212,  -196}, {    76,   158,   -21,   -69},
1531
+ {  -328,  -185,   331,   119}, {   -53,   285,    56,   337},
1532
+ {  -107,   -24,   405,    29}, {   -18,   137,   272,   277},
1533
+ {  -255,    22,   173,  -191}, {   295,   322,   325,   302},
1534
+ {    21,   -27,   332,  -178}, {   119,    13,   271,   129},
1535
+ {  -455,  -180,   116,  -191}, {  -227,    62,  -148,   524},
1536
+ {  -176,  -287,   282,  -157}, {  -243,    13,   199,   430},
1537
+ {   -59,   -49,   115,  -365}, {    72,  -172,  -137,    93},
1538
+ {  -138,  -126,   141,   -84}, {     5,  -124,    38,   -20},
1539
+ {  -258,   311,   601,   213}, {    94,   130,   -61,   502},
1540
+ {    -1,  -157,   485,   313}, {   146,   -74,   158,   345},
1541
+ {   276,   135,   280,   -57}, {   490,   252,    99,    43},
1542
+ {   267,   -74,   429,   105}, {   278,   -23,   119,    94},
1543
+ {  -542,   488,   257,  -115}, {   -84,  -244,  -438,   478},
1544
+ {  -113,  -545,   387,   101}, {   -95,  -306,   111,   498},
1545
+ {    95,   166,    22,  -301}, {   420,   -15,   -58,   -78},
1546
+ {   270,    29,   122,  -282}, {   160,  -240,    50,   -38}
1547
+};
1548
+
1549
+static const int16_t dico23_isf_36b[64][7] = {
1550
+ {    81,   -18,    68,   -27,  -122,  -280,    -4},
1551
+ {    45,  -177,   209,   -30,  -136,   -74,   131},
1552
+ {   -44,   101,   -75,   -88,   -48,  -137,   -54},
1553
+ {  -245,   -28,    63,   -18,  -112,  -103,    58},
1554
+ {   -79,    -6,   220,   -65,   114,   -35,   -50},
1555
+ {   109,   -65,   143,  -114,   129,    76,   125},
1556
+ {   166,    90,   -61,  -242,   186,   -74,   -43},
1557
+ {   -46,   -92,    49,  -227,    24,  -155,    39},
1558
+ {    67,    85,    99,   -42,    53,  -184,  -281},
1559
+ {   142,  -122,     0,    21,  -142,   -15,   -17},
1560
+ {   223,    92,   -21,   -48,   -82,   -14,  -167},
1561
+ {    51,   -37,  -243,   -30,   -90,    18,   -56},
1562
+ {    54,   105,    74,    86,    69,    13,  -101},
1563
+ {   196,    72,   -89,    43,    65,    19,    39},
1564
+ {   121,    34,   131,   -82,    25,   213,  -156},
1565
+ {   101,  -102,  -136,   -21,    57,   214,    22},
1566
+ {    36,  -124,   205,   204,    58,  -156,   -83},
1567
+ {    83,  -117,   137,   137,    85,   116,    44},
1568
+ {   -92,  -148,   -68,    11,  -102,  -197,  -220},
1569
+ {   -76,  -185,   -58,   132,   -26,  -183,    85},
1570
+ {    -7,   -31,    -2,    23,   205,  -151,    10},
1571
+ {   -27,   -37,    -5,   -18,   292,   131,     1},
1572
+ {   117,  -168,     9,   -93,    80,   -59,  -125},
1573
+ {  -182,  -244,    98,   -24,   135,   -22,    94},
1574
+ {   221,    97,   106,    42,    43,  -160,    83},
1575
+ {    25,   -64,   -21,     6,    14,   -15,   154},
1576
+ {   126,    15,  -140,   150,   -10,  -207,  -114},
1577
+ {    79,   -63,  -211,   -70,   -28,  -217,   165},
1578
+ {    46,    38,   -22,   281,   132,   -62,   109},
1579
+ {   112,    54,  -112,   -93,   208,    27,   296},
1580
+ {   115,    10,  -147,    41,   216,    42,  -276},
1581
+ {    50,  -115,  -254,   167,   117,    -2,    61},
1582
+ {    17,   144,    34,   -72,  -186,  -150,   272},
1583
+ {   -29,   -66,   -89,   -95,  -149,   129,   251},
1584
+ {   122,     0,   -50,  -234,   -91,    36,    26},
1585
+ {  -105,  -102,   -88,  -121,  -236,    -7,   -11},
1586
+ {  -204,   109,     5,  -191,   105,   -15,   163},
1587
+ {   -80,    32,   -24,  -209,    41,   294,    70},
1588
+ {  -106,   -94,  -204,  -118,   120,   -50,   -37},
1589
+ {   -82,  -241,    46,  -131,   -29,   150,   -55},
1590
+ {    33,   155,   120,   -89,    -8,     7,    62},
1591
+ {   213,    82,    61,    18,  -161,   144,   152},
1592
+ {    30,   131,    65,   -87,  -255,   -17,  -107},
1593
+ {    -8,    85,   -64,    51,  -162,   223,   -53},
1594
+ {  -134,   261,    69,   -56,   218,    72,  -111},
1595
+ {     2,   155,  -113,   -87,    49,    85,   -28},
1596
+ {  -163,    42,    -1,  -196,     7,    39,  -245},
1597
+ {    14,  -137,   -79,    11,  -160,   202,  -293},
1598
+ {   -94,    33,   208,   100,    56,   -44,   326},
1599
+ {   -78,   -41,   232,    13,  -142,   227,    80},
1600
+ {   -16,   -87,   201,    33,  -133,    15,  -183},
1601
+ {   -58,  -192,   -47,   184,  -128,   133,    99},
1602
+ {  -205,    11,  -155,    78,    52,    72,   141},
1603
+ {  -246,    26,    99,   151,    59,   115,   -64},
1604
+ {   -79,   -47,   -16,   -14,     6,    47,   -43},
1605
+ {   -72,  -178,   -27,   162,   112,    43,  -174},
1606
+ {  -175,   238,   186,    71,   -54,  -188,   -76},
1607
+ {  -225,   233,    39,   -39,  -158,   122,    44},
1608
+ {   -26,    43,    84,   130,   -93,   -51,    22},
1609
+ {     3,    92,  -150,   136,  -182,   -57,    97},
1610
+ {  -131,   179,   -78,    80,    91,  -165,    90},
1611
+ {    -2,   148,    15,   130,    65,   175,   117},
1612
+ {  -138,   114,  -137,   132,     3,   -10,  -186},
1613
+ {   140,    -4,   -37,   254,   -62,    92,  -109}
1614
+};
1615
+
1616
+/** Means of ISF vectors in Q15 */
1617
+static const int16_t isf_mean[LP_ORDER] = {
1618
+   738,  1326,  2336,  3578,  4596,  5662,  6711,  7730,
1619
+  8750,  9753, 10705, 11728, 12833, 13971, 15043,  4037
1620
+};
1621
+
1622
+/** Initialization tables for the processed ISF vector in Q15 */
1623
+static const int16_t isf_init[LP_ORDER] = {
1624
+  1024,  2048,  3072,  4096,  5120,  6144,  7168, 8192,
1625
+  9216, 10240, 11264, 12288, 13312, 14336, 15360, 3840
1626
+};
1627
+
1628
+/** ISF/ISP interpolation coefficients for each subframe */
1629
+static const float isfp_inter[4] = { 0.45, 0.8, 0.96, 1.0 };
1630
+
1631
+/** Coefficients for FIR interpolation of excitation vector
1632
+ * at pitch lag resulting the adaptive codebook vector */
1633
+static const float ac_inter[65] = {
1634
+     9.400024e-01,
1635
+     8.563843e-01,  6.322632e-01,  3.375854e-01,  5.908203e-02,
1636
+    -1.310425e-01, -1.994019e-01, -1.585693e-01, -5.633545e-02,
1637
+     4.760742e-02,  1.067505e-01,  1.036987e-01,  5.206299e-02,
1638
+    -1.519775e-02, -6.372070e-02, -7.366943e-02, -4.650879e-02,
1639
+    -9.765625e-04,  3.820801e-02,  5.316162e-02,  4.003906e-02,
1640
+     9.338379e-03, -2.166748e-02, -3.778076e-02, -3.320312e-02,
1641
+    -1.300049e-02,  1.068115e-02,  2.587891e-02,  2.630615e-02,
1642
+     1.379395e-02, -3.662109e-03, -1.678467e-02, -1.983643e-02,
1643
+    -1.275635e-02, -5.493164e-04,  1.007080e-02,  1.409912e-02,
1644
+     1.068115e-02,  2.624512e-03, -5.371094e-03, -9.338379e-03,
1645
+    -8.117676e-03, -3.173828e-03,  2.319336e-03,  5.615234e-03,
1646
+     5.554199e-03,  2.868652e-03, -6.103516e-04, -2.990723e-03,
1647
+    -3.356934e-03, -2.014160e-03, -1.220703e-04,  1.342773e-03,
1648
+     1.708984e-03,  1.159668e-03,  2.441406e-04, -4.272461e-04,
1649
+    -6.103516e-04, -4.272461e-04, -1.220703e-04,  6.103516e-05,
1650
+     1.220703e-04,  6.103516e-05,  0.000000e+00,  0.000000e+00
1651
+};
1652
+
1653
+/** [i][j] is the number of pulses present in track j at mode i */
1654
+static const uint8_t pulses_nb_per_mode_tr[][4] = {
1655
+    {1, 1, 0, 0}, {1, 1, 1, 1}, {2, 2, 2, 2},
1656
+    {3, 3, 2, 2}, {3, 3, 3, 3}, {4, 4, 4, 4},
1657
+    {5, 5, 4, 4}, {6, 6, 6, 6}, {6, 6, 6, 6}
1658
+};
1659
+
1660
+/** Tables for decoding quantized gains { pitch (Q14), fixed factor (Q11) } */
1661
+static const int16_t qua_gain_6b[64][2] = {
1662
+    {  1566,  1332},    {  1577,  3557},
1663
+    {  3071,  6490},    {  4193, 10163},
1664
+    {  4496,  2534},    {  5019,  4488},
1665
+    {  5586, 15614},    {  5725,  1422},
1666
+    {  6453,   580},    {  6724,  6831},
1667
+    {  7657,  3527},    {  8072,  2099},
1668
+    {  8232,  5319},    {  8827,  8775},
1669
+    {  9740,  2868},    {  9856,  1465},
1670
+    { 10087, 12488},    { 10241,  4453},
1671
+    { 10859,  6618},    { 11321,  3587},
1672
+    { 11417,  1800},    { 11643,  2428},
1673
+    { 11718,   988},    { 12312,  5093},
1674
+    { 12523,  8413},    { 12574, 26214},
1675
+    { 12601,  3396},    { 13172,  1623},
1676
+    { 13285,  2423},    { 13418,  6087},
1677
+    { 13459, 12810},    { 13656,  3607},
1678
+    { 14111,  4521},    { 14144,  1229},
1679
+    { 14425,  1871},    { 14431,  7234},
1680
+    { 14445,  2834},    { 14628, 10036},
1681
+    { 14860, 17496},    { 15161,  3629},
1682
+    { 15209,  5819},    { 15299,  2256},
1683
+    { 15518,  4722},    { 15663,  1060},
1684
+    { 15759,  7972},    { 15939, 11964},
1685
+    { 16020,  2996},    { 16086,  1707},
1686
+    { 16521,  4254},    { 16576,  6224},
1687
+    { 16894,  2380},    { 16906,   681},
1688
+    { 17213,  8406},    { 17610,  3418},
1689
+    { 17895,  5269},    { 18168, 11748},
1690
+    { 18230,  1575},    { 18607, 32767},
1691
+    { 18728, 21684},    { 19137,  2543},
1692
+    { 19422,  6577},    { 19446,  4097},
1693
+    { 19450,  9056},    { 20371, 14885}
1694
+};
1695
+
1696
+static const int16_t qua_gain_7b[128][2] = {
1697
+    {   204,   441},    {   464,  1977},
1698
+    {   869,  1077},    {  1072,  3062},
1699
+    {  1281,  4759},    {  1647,  1539},
1700
+    {  1845,  7020},    {  1853,   634},
1701
+    {  1995,  2336},    {  2351, 15400},
1702
+    {  2661,  1165},    {  2702,  3900},
1703
+    {  2710, 10133},    {  3195,  1752},
1704
+    {  3498,  2624},    {  3663,   849},
1705
+    {  3984,  5697},    {  4214,  3399},
1706
+    {  4415,  1304},    {  4695,  2056},
1707
+    {  5376,  4558},    {  5386,   676},
1708
+    {  5518, 23554},    {  5567,  7794},
1709
+    {  5644,  3061},    {  5672,  1513},
1710
+    {  5957,  2338},    {  6533,  1060},
1711
+    {  6804,  5998},    {  6820,  1767},
1712
+    {  6937,  3837},    {  7277,   414},
1713
+    {  7305,  2665},    {  7466, 11304},
1714
+    {  7942,   794},    {  8007,  1982},
1715
+    {  8007,  1366},    {  8326,  3105},
1716
+    {  8336,  4810},    {  8708,  7954},
1717
+    {  8989,  2279},    {  9031,  1055},
1718
+    {  9247,  3568},    {  9283,  1631},
1719
+    {  9654,  6311},    {  9811,  2605},
1720
+    { 10120,   683},    { 10143,  4179},
1721
+    { 10245,  1946},    { 10335,  1218},
1722
+    { 10468,  9960},    { 10651,  3000},
1723
+    { 10951,  1530},    { 10969,  5290},
1724
+    { 11203,  2305},    { 11325,  3562},
1725
+    { 11771,  6754},    { 11839,  1849},
1726
+    { 11941,  4495},    { 11954,  1298},
1727
+    { 11975, 15223},    { 11977,   883},
1728
+    { 11986,  2842},    { 12438,  2141},
1729
+    { 12593,  3665},    { 12636,  8367},
1730
+    { 12658,  1594},    { 12886,  2628},
1731
+    { 12984,  4942},    { 13146,  1115},
1732
+    { 13224,   524},    { 13341,  3163},
1733
+    { 13399,  1923},    { 13549,  5961},
1734
+    { 13606,  1401},    { 13655,  2399},
1735
+    { 13782,  3909},    { 13868, 10923},
1736
+    { 14226,  1723},    { 14232,  2939},
1737
+    { 14278,  7528},    { 14439,  4598},
1738
+    { 14451,   984},    { 14458,  2265},
1739
+    { 14792,  1403},    { 14818,  3445},
1740
+    { 14899,  5709},    { 15017, 15362},
1741
+    { 15048,  1946},    { 15069,  2655},
1742
+    { 15405,  9591},    { 15405,  4079},
1743
+    { 15570,  7183},    { 15687,  2286},
1744
+    { 15691,  1624},    { 15699,  3068},
1745
+    { 15772,  5149},    { 15868,  1205},
1746
+    { 15970,   696},    { 16249,  3584},
1747
+    { 16338,  1917},    { 16424,  2560},
1748
+    { 16483,  4438},    { 16529,  6410},
1749
+    { 16620, 11966},    { 16839,  8780},
1750
+    { 17030,  3050},    { 17033, 18325},
1751
+    { 17092,  1568},    { 17123,  5197},
1752
+    { 17351,  2113},    { 17374,   980},
1753
+    { 17566, 26214},    { 17609,  3912},
1754
+    { 17639, 32767},    { 18151,  7871},
1755
+    { 18197,  2516},    { 18202,  5649},
1756
+    { 18679,  3283},    { 18930,  1370},
1757
+    { 19271, 13757},    { 19317,  4120},
1758
+    { 19460,  1973},    { 19654, 10018},
1759
+    { 19764,  6792},    { 19912,  5135},
1760
+    { 20040,  2841},    { 21234, 19833}
1761
+};
1762
+
1763
+/** 4-tap moving average prediction coefficients in reverse order */
1764
+static const float energy_pred_fac[4] = { 0.2, 0.3, 0.4, 0.5 };
1765
+
1766
+/** impulse response filter tables converted to float from Q15
1767
+ * used for anti-sparseness processing */
1768
+static const float ir_filter_str[64] = {
1769
+     6.159058e-01,  2.958069e-01,  9.979248e-02, -1.048889e-01,
1770
+     8.740234e-02, -1.599121e-01,  4.849243e-02, -4.141235e-02,
1771
+     1.831055e-02,  1.188049e-01, -4.568481e-02, -2.130127e-02,
1772
+     3.671265e-02, -1.601868e-01,  3.659058e-02,  1.639099e-01,
1773
+    -4.541016e-02, -2.151489e-02, -8.810425e-02,  6.030273e-02,
1774
+     2.740479e-02,  2.200317e-02, -1.182861e-01,  1.289978e-01,
1775
+    -1.560059e-01,  1.953125e-01, -3.149414e-02, -1.441956e-01,
1776
+     1.249084e-01, -1.328125e-01,  9.780884e-02,  6.500244e-02,
1777
+    -6.091309e-02, -5.599976e-02,  8.081055e-02, -5.450439e-02,
1778
+    -1.239014e-02,  1.748657e-02,  7.580566e-02, -1.101074e-01,
1779
+     9.579468e-02, -4.159546e-02, -7.830811e-02,  1.162109e-01,
1780
+    -1.950073e-02, -6.259155e-02, -1.651001e-02,  7.250977e-02,
1781
+     1.199951e-01, -1.911011e-01,  4.370117e-02, -1.098938e-01,
1782
+     1.492004e-01,  1.129150e-02,  1.730347e-02, -3.549194e-02,
1783
+    -8.709717e-02,  5.841064e-02,  1.190186e-03, -7.379150e-02,
1784
+     1.054077e-01,  9.078979e-02, -1.227112e-01,  1.047058e-01
1785
+};
1786
+
1787
+static const float ir_filter_mid[64] = {
1788
+     7.354126e-01,  3.192139e-01, -1.606140e-01, -2.328491e-02,
1789
+     6.250000e-02, -2.828979e-02,  5.349731e-02, -1.014099e-01,
1790
+     6.750488e-02,  1.989746e-02, -6.549072e-02,  7.589722e-02,
1791
+    -1.080017e-01,  1.253967e-01, -6.430054e-02, -1.141357e-02,
1792
+    -1.910400e-02,  1.303101e-01, -1.673889e-01,  6.820679e-02,
1793
+     5.670166e-02, -8.450317e-02,  2.270508e-02,  3.479004e-02,
1794
+    -2.328491e-02, -4.928589e-02,  1.239014e-01, -1.395874e-01,
1795
+     9.100342e-02, -3.549194e-02,  2.230835e-02, -3.350830e-02,
1796
+     2.450562e-02,  5.096436e-03, -2.178955e-02,  1.849365e-02,
1797
+    -1.708984e-02,  1.950073e-02,  1.312256e-03, -5.389404e-02,
1798
+     9.851074e-02, -8.489990e-02,  2.029419e-02,  2.328491e-02,
1799
+     7.110596e-03, -6.109619e-02,  3.939819e-02,  5.709839e-02,
1800
+    -1.058960e-01,  3.149414e-02,  8.270264e-02, -1.232910e-01,
1801
+     1.105957e-01, -1.286011e-01,  1.614990e-01, -1.303101e-01,
1802
+     4.769897e-02,  3.295898e-03, -1.770020e-02,  5.010986e-02,
1803
+    -7.501221e-02,  2.920532e-02,  1.660156e-02,  7.751465e-02
1804
+};
1805
+
1806
+static const float *ir_filters_lookup[2] = {
1807
+    ir_filter_str, ir_filter_mid
1808
+};
1809
+
1810
+/** High-pass filters coefficients for 31 Hz and 400 Hz cutoff */
1811
+static const float hpf_zeros[2]     = { -2.0, 1.0 };
1812
+static const float hpf_31_poles[2]  = { -1.978881836, 0.979125977 };
1813
+static const float hpf_31_gain      = 0.989501953;
1814
+
1815
+static const float hpf_400_poles[2] = { -1.787109375, 0.864257812 };
1816
+static const float hpf_400_gain     = 0.893554687;
1817
+
1818
+/** Interpolation coefficients for 5/4 signal upsampling
1819
+ * Table from the reference source was reordered for efficiency */
1820
+static const float upsample_fir[4][24] = {
1821
+    { -6.103516e-05,  7.324219e-04, -2.014160e-03,  4.150391e-03,
1822
+      -7.263184e-03,  1.165771e-02, -1.776123e-02,  2.624512e-02,
1823
+      -3.869629e-02,  5.877686e-02, -9.863281e-02,  2.314453e-01,
1824
+       9.348755e-01, -1.523438e-01,  7.861328e-02, -4.937744e-02,
1825
+       3.308105e-02, -2.252197e-02,  1.507568e-02, -9.765625e-03,
1826
+       5.859375e-03, -3.173828e-03,  1.403809e-03, -3.662109e-04  },
1827
+    { -2.441406e-04,  1.464844e-03, -3.784180e-03,  7.568359e-03,
1828
+      -1.300049e-02,  2.062988e-02, -3.112793e-02,  4.589844e-02,
1829
+      -6.781006e-02,  1.042480e-01, -1.815186e-01,  5.016479e-01,
1830
+       7.548828e-01, -2.094727e-01,  1.148071e-01, -7.348633e-02,
1831
+       4.956055e-02, -3.369141e-02,  2.246094e-02, -1.434326e-02,
1832
+       8.483887e-03, -4.455566e-03,  1.831055e-03, -4.272461e-04  },
1833
+    { -4.272461e-04,  1.831055e-03, -4.455566e-03,  8.483887e-03,
1834
+      -1.434326e-02,  2.246094e-02, -3.369141e-02,  4.956055e-02,
1835
+      -7.348633e-02,  1.148071e-01, -2.094727e-01,  7.548828e-01,
1836
+       5.016479e-01, -1.815186e-01,  1.042480e-01, -6.781006e-02,
1837
+       4.589844e-02, -3.112793e-02,  2.062988e-02, -1.300049e-02,
1838
+       7.568359e-03, -3.784180e-03,  1.464844e-03, -2.441406e-04  },
1839
+    { -3.662109e-04,  1.403809e-03, -3.173828e-03,  5.859375e-03,
1840
+      -9.765625e-03,  1.507568e-02, -2.252197e-02,  3.308105e-02,
1841
+      -4.937744e-02,  7.861328e-02, -1.523438e-01,  9.348755e-01,
1842
+       2.314453e-01, -9.863281e-02,  5.877686e-02, -3.869629e-02,
1843
+       2.624512e-02, -1.776123e-02,  1.165771e-02, -7.263184e-03,
1844
+       4.150391e-03, -2.014160e-03,  7.324219e-04, -6.103516e-05  }
1845
+};
1846
+
1847
+/** High band quantized gains for 23k85 in Q14 */
1848
+static const uint16_t qua_hb_gain[16] = {
1849
+   3624, 4673, 5597, 6479, 7425, 8378, 9324, 10264,
1850
+   11210, 12206, 13391, 14844, 16770, 19655, 24289, 32728
1851
+};
1852
+
1853
+/** High-band post-processing FIR filters coefficients from Q15 */
1854
+static const float bpf_6_7_coef[31] = { // band pass, 6kHz and 7kHz cutoffs
1855
+    -2.441406e-04,  3.585815e-04,  2.441406e-04,
1856
+    -2.059937e-04, -2.815248e-03,  8.560180e-03,
1857
+    -1.084137e-02,  0.000000e+00,  2.897645e-02,
1858
+    -6.774902e-02,  9.421540e-02, -8.380128e-02,
1859
+     2.706910e-02,  5.924987e-02, -1.373367e-01,
1860
+     1.687469e-01,
1861
+    -1.373367e-01,  5.924987e-02,  2.706910e-02,
1862
+    -8.380128e-02,  9.421540e-02, -6.774902e-02,
1863
+     2.897645e-02,  0.000000e+00, -1.084137e-02,
1864
+     8.560180e-03, -2.815248e-03, -2.059937e-04,
1865
+     2.441406e-04,  3.585815e-04, -2.441406e-04
1866
+};
1867
+
1868
+static const float lpf_7_coef[31] = { // low pass, 7kHz cutoff
1869
+    -6.408691e-04,  1.434326e-03, -2.716064e-03,
1870
+     4.455566e-03, -6.195068e-03,  6.988525e-03,
1871
+    -5.401611e-03,  0.000000e+00,  1.022339e-02,
1872
+    -2.560425e-02,  4.531860e-02, -6.747437e-02,
1873
+     8.944702e-02, -1.080933e-01,  1.206360e-01,
1874
+     8.753052e-01,
1875
+     1.206360e-01, -1.080933e-01,  8.944702e-02,
1876
+    -6.747437e-02,  4.531860e-02, -2.560425e-02,
1877
+     1.022339e-02,  0.000000e+00, -5.401611e-03,
1878
+     6.988525e-03, -6.195068e-03,  4.455566e-03,
1879
+    -2.716064e-03,  1.434326e-03, -6.408691e-04
1880
+};
1881
+
1882
+/** Core frame sizes in each mode */
1883
+static const uint16_t cf_sizes_wb[] = {
1884
+    132, 177, 253, 285, 317, 365, 397, 461, 477,
1885
+    40 /// SID/comfort noise frame
1886
+};
1887
+
1888
+#endif
0 1889
new file mode 100644
... ...
@@ -0,0 +1,1237 @@
0
+/*
1
+ * AMR wideband decoder
2
+ * Copyright (c) 2010 Marcelo Galvao Povoa
3
+ *
4
+ * This file is part of FFmpeg.
5
+ *
6
+ * FFmpeg is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * FFmpeg is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A particular PURPOSE.  See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with FFmpeg; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+/**
22
+ * @file
23
+ * AMR wideband decoder
24
+ */
25
+
26
+#include "libavutil/lfg.h"
27
+
28
+#include "avcodec.h"
29
+#include "get_bits.h"
30
+#include "lsp.h"
31
+#include "celp_math.h"
32
+#include "celp_filters.h"
33
+#include "acelp_filters.h"
34
+#include "acelp_vectors.h"
35
+#include "acelp_pitch_delay.h"
36
+
37
+#define AMR_USE_16BIT_TABLES
38
+#include "amr.h"
39
+
40
+#include "amrwbdata.h"
41
+
42
+typedef struct {
43
+    AMRWBFrame                             frame; ///< AMRWB parameters decoded from bitstream
44
+    enum Mode                        fr_cur_mode; ///< mode index of current frame
45
+    uint8_t                           fr_quality; ///< frame quality index (FQI)
46
+    float                      isf_cur[LP_ORDER]; ///< working ISF vector from current frame
47
+    float                   isf_q_past[LP_ORDER]; ///< quantized ISF vector of the previous frame
48
+    float               isf_past_final[LP_ORDER]; ///< final processed ISF vector of the previous frame
49
+    double                      isp[4][LP_ORDER]; ///< ISP vectors from current frame
50
+    double               isp_sub4_past[LP_ORDER]; ///< ISP vector for the 4th subframe of the previous frame
51
+
52
+    float                   lp_coef[4][LP_ORDER]; ///< Linear Prediction Coefficients from ISP vector
53
+
54
+    uint8_t                       base_pitch_lag; ///< integer part of pitch lag for the next relative subframe
55
+    uint8_t                        pitch_lag_int; ///< integer part of pitch lag of the previous subframe
56
+
57
+    float excitation_buf[AMRWB_P_DELAY_MAX + LP_ORDER + 2 + AMRWB_SFR_SIZE]; ///< current excitation and all necessary excitation history
58
+    float                            *excitation; ///< points to current excitation in excitation_buf[]
59
+
60
+    float           pitch_vector[AMRWB_SFR_SIZE]; ///< adaptive codebook (pitch) vector for current subframe
61
+    float           fixed_vector[AMRWB_SFR_SIZE]; ///< algebraic codebook (fixed) vector for current subframe
62
+
63
+    float                    prediction_error[4]; ///< quantified prediction errors {20log10(^gamma_gc)} for previous four subframes
64
+    float                          pitch_gain[6]; ///< quantified pitch gains for the current and previous five subframes
65
+    float                          fixed_gain[2]; ///< quantified fixed gains for the current and previous subframes
66
+
67
+    float                              tilt_coef; ///< {beta_1} related to the voicing of the previous subframe
68
+
69
+    float                 prev_sparse_fixed_gain; ///< previous fixed gain; used by anti-sparseness to determine "onset"
70
+    uint8_t                    prev_ir_filter_nr; ///< previous impulse response filter "impNr": 0 - strong, 1 - medium, 2 - none
71
+    float                           prev_tr_gain; ///< previous initial gain used by noise enhancer for threshold
72
+
73
+    float samples_az[LP_ORDER + AMRWB_SFR_SIZE];         ///< low-band samples and memory from synthesis at 12.8kHz
74
+    float samples_up[UPS_MEM_SIZE + AMRWB_SFR_SIZE];     ///< low-band samples and memory processed for upsampling
75
+    float samples_hb[LP_ORDER_16k + AMRWB_SFR_SIZE_16k]; ///< high-band samples and memory from synthesis at 16kHz
76
+
77
+    float          hpf_31_mem[2], hpf_400_mem[2]; ///< previous values in the high pass filters
78
+    float                           demph_mem[1]; ///< previous value in the de-emphasis filter
79
+    float               bpf_6_7_mem[HB_FIR_SIZE]; ///< previous values in the high-band band pass filter
80
+    float                 lpf_7_mem[HB_FIR_SIZE]; ///< previous values in the high-band low pass filter
81
+
82
+    AVLFG                                   prng; ///< random number generator for white noise excitation
83
+    uint8_t                          first_frame; ///< flag active during decoding of the first frame
84
+} AMRWBContext;
85
+
86
+static av_cold int amrwb_decode_init(AVCodecContext *avctx)
87
+{
88
+    AMRWBContext *ctx = avctx->priv_data;
89
+    int i;
90
+
91
+    avctx->sample_fmt = SAMPLE_FMT_FLT;
92
+
93
+    av_lfg_init(&ctx->prng, 1);
94
+
95
+    ctx->excitation  = &ctx->excitation_buf[AMRWB_P_DELAY_MAX + LP_ORDER + 1];
96
+    ctx->first_frame = 1;
97
+
98
+    for (i = 0; i < LP_ORDER; i++)
99
+        ctx->isf_past_final[i] = isf_init[i] * (1.0f / (1 << 15));
100
+
101
+    for (i = 0; i < 4; i++)
102
+        ctx->prediction_error[i] = MIN_ENERGY;
103
+
104
+    return 0;
105
+}
106
+
107
+/**
108
+ * Decode the frame header in the "MIME/storage" format. This format
109
+ * is simpler and does not carry the auxiliary information of the frame
110
+ *
111
+ * @param[in] ctx                  The Context
112
+ * @param[in] buf                  Pointer to the input buffer
113
+ *
114
+ * @return The decoded header length in bytes
115
+ */
116
+static int decode_mime_header(AMRWBContext *ctx, const uint8_t *buf)
117
+{
118
+    GetBitContext gb;
119
+    init_get_bits(&gb, buf, 8);
120
+
121
+    /* Decode frame header (1st octet) */
122
+    skip_bits(&gb, 1);  // padding bit
123
+    ctx->fr_cur_mode  = get_bits(&gb, 4);
124
+    ctx->fr_quality   = get_bits1(&gb);
125
+    skip_bits(&gb, 2);  // padding bits
126
+
127
+    return 1;
128
+}
129
+
130
+/**
131
+ * Decodes quantized ISF vectors using 36-bit indexes (6K60 mode only)
132
+ *
133
+ * @param[in]  ind                 Array of 5 indexes
134
+ * @param[out] isf_q               Buffer for isf_q[LP_ORDER]
135
+ *
136
+ */
137
+static void decode_isf_indices_36b(uint16_t *ind, float *isf_q)
138
+{
139
+    int i;
140
+
141
+    for (i = 0; i < 9; i++)
142
+        isf_q[i]      = dico1_isf[ind[0]][i]      * (1.0f / (1 << 15));
143
+
144
+    for (i = 0; i < 7; i++)
145
+        isf_q[i + 9]  = dico2_isf[ind[1]][i]      * (1.0f / (1 << 15));
146
+
147
+    for (i = 0; i < 5; i++)
148
+        isf_q[i]     += dico21_isf_36b[ind[2]][i] * (1.0f / (1 << 15));
149
+
150
+    for (i = 0; i < 4; i++)
151
+        isf_q[i + 5] += dico22_isf_36b[ind[3]][i] * (1.0f / (1 << 15));
152
+
153
+    for (i = 0; i < 7; i++)
154
+        isf_q[i + 9] += dico23_isf_36b[ind[4]][i] * (1.0f / (1 << 15));
155
+}
156
+
157
+/**
158
+ * Decodes quantized ISF vectors using 46-bit indexes (except 6K60 mode)
159
+ *
160
+ * @param[in]  ind                 Array of 7 indexes
161
+ * @param[out] isf_q               Buffer for isf_q[LP_ORDER]
162
+ *
163
+ */
164
+static void decode_isf_indices_46b(uint16_t *ind, float *isf_q)
165
+{
166
+    int i;
167
+
168
+    for (i = 0; i < 9; i++)
169
+        isf_q[i]       = dico1_isf[ind[0]][i]  * (1.0f / (1 << 15));
170
+
171
+    for (i = 0; i < 7; i++)
172
+        isf_q[i + 9]   = dico2_isf[ind[1]][i]  * (1.0f / (1 << 15));
173
+
174
+    for (i = 0; i < 3; i++)
175
+        isf_q[i]      += dico21_isf[ind[2]][i] * (1.0f / (1 << 15));
176
+
177
+    for (i = 0; i < 3; i++)
178
+        isf_q[i + 3]  += dico22_isf[ind[3]][i] * (1.0f / (1 << 15));
179
+
180
+    for (i = 0; i < 3; i++)
181
+        isf_q[i + 6]  += dico23_isf[ind[4]][i] * (1.0f / (1 << 15));
182
+
183
+    for (i = 0; i < 3; i++)
184
+        isf_q[i + 9]  += dico24_isf[ind[5]][i] * (1.0f / (1 << 15));
185
+
186
+    for (i = 0; i < 4; i++)
187
+        isf_q[i + 12] += dico25_isf[ind[6]][i] * (1.0f / (1 << 15));
188
+}
189
+
190
+/**
191
+ * Apply mean and past ISF values using the prediction factor
192
+ * Updates past ISF vector
193
+ *
194
+ * @param[in,out] isf_q            Current quantized ISF
195
+ * @param[in,out] isf_past         Past quantized ISF
196
+ *
197
+ */
198
+static void isf_add_mean_and_past(float *isf_q, float *isf_past)
199
+{
200
+    int i;
201
+    float tmp;
202
+
203
+    for (i = 0; i < LP_ORDER; i++) {
204
+        tmp = isf_q[i];
205
+        isf_q[i] += isf_mean[i] * (1.0f / (1 << 15));
206
+        isf_q[i] += PRED_FACTOR * isf_past[i];
207
+        isf_past[i] = tmp;
208
+    }
209
+}
210
+
211
+/**
212
+ * Interpolate the fourth ISP vector from current and past frames
213
+ * to obtain a ISP vector for each subframe
214
+ *
215
+ * @param[in,out] isp_q            ISPs for each subframe
216
+ * @param[in]     isp4_past        Past ISP for subframe 4
217
+ */
218
+static void interpolate_isp(double isp_q[4][LP_ORDER], const double *isp4_past)
219
+{
220
+    int i, k;
221
+
222
+    for (k = 0; k < 3; k++) {
223
+        float c = isfp_inter[k];
224
+        for (i = 0; i < LP_ORDER; i++)
225
+            isp_q[k][i] = (1.0 - c) * isp4_past[i] + c * isp_q[3][i];
226
+    }
227
+}
228
+
229
+/**
230
+ * Decode an adaptive codebook index into pitch lag (except 6k60, 8k85 modes)
231
+ * Calculate integer lag and fractional lag always using 1/4 resolution
232
+ * In 1st and 3rd subframes the index is relative to last subframe integer lag
233
+ *
234
+ * @param[out]    lag_int          Decoded integer pitch lag
235
+ * @param[out]    lag_frac         Decoded fractional pitch lag
236
+ * @param[in]     pitch_index      Adaptive codebook pitch index
237
+ * @param[in,out] base_lag_int     Base integer lag used in relative subframes
238
+ * @param[in]     subframe         Current subframe index (0 to 3)
239
+ */
240
+static void decode_pitch_lag_high(int *lag_int, int *lag_frac, int pitch_index,
241
+                                  uint8_t *base_lag_int, int subframe)
242
+{
243
+    if (subframe == 0 || subframe == 2) {
244
+        if (pitch_index < 376) {
245
+            *lag_int  = (pitch_index + 137) >> 2;
246
+            *lag_frac = pitch_index - (*lag_int << 2) + 136;
247
+        } else if (pitch_index < 440) {
248
+            *lag_int  = (pitch_index + 257 - 376) >> 1;
249
+            *lag_frac = (pitch_index - (*lag_int << 1) + 256 - 376) << 1;
250
+            /* the actual resolution is 1/2 but expressed as 1/4 */
251
+        } else {
252
+            *lag_int  = pitch_index - 280;
253
+            *lag_frac = 0;
254
+        }
255
+        /* minimum lag for next subframe */
256
+        *base_lag_int = av_clip(*lag_int - 8 - (*lag_frac < 0),
257
+                                AMRWB_P_DELAY_MIN, AMRWB_P_DELAY_MAX - 15);
258
+        // XXX: the spec states clearly that *base_lag_int should be
259
+        // the nearest integer to *lag_int (minus 8), but the ref code
260
+        // actually always uses its floor, I'm following the latter
261
+    } else {
262
+        *lag_int  = (pitch_index + 1) >> 2;
263
+        *lag_frac = pitch_index - (*lag_int << 2);
264
+        *lag_int += *base_lag_int;
265
+    }
266
+}
267
+
268
+/**
269
+ * Decode a adaptive codebook index into pitch lag for 8k85 and 6k60 modes
270
+ * Description is analogous to decode_pitch_lag_high, but in 6k60 relative
271
+ * index is used for all subframes except the first
272
+ */
273
+static void decode_pitch_lag_low(int *lag_int, int *lag_frac, int pitch_index,
274
+                                 uint8_t *base_lag_int, int subframe, enum Mode mode)
275
+{
276
+    if (subframe == 0 || (subframe == 2 && mode != MODE_6k60)) {
277
+        if (pitch_index < 116) {
278
+            *lag_int  = (pitch_index + 69) >> 1;
279
+            *lag_frac = (pitch_index - (*lag_int << 1) + 68) << 1;
280
+        } else {
281
+            *lag_int  = pitch_index - 24;
282
+            *lag_frac = 0;
283
+        }
284
+        // XXX: same problem as before
285
+        *base_lag_int = av_clip(*lag_int - 8 - (*lag_frac < 0),
286
+                                AMRWB_P_DELAY_MIN, AMRWB_P_DELAY_MAX - 15);
287
+    } else {
288
+        *lag_int  = (pitch_index + 1) >> 1;
289
+        *lag_frac = (pitch_index - (*lag_int << 1)) << 1;
290
+        *lag_int += *base_lag_int;
291
+    }
292
+}
293
+
294
+/**
295
+ * Find the pitch vector by interpolating the past excitation at the
296
+ * pitch delay, which is obtained in this function
297
+ *
298
+ * @param[in,out] ctx              The context
299
+ * @param[in]     amr_subframe     Current subframe data
300
+ * @param[in]     subframe         Current subframe index (0 to 3)
301
+ */
302
+static void decode_pitch_vector(AMRWBContext *ctx,
303
+                                const AMRWBSubFrame *amr_subframe,
304
+                                const int subframe)
305
+{
306
+    int pitch_lag_int, pitch_lag_frac;
307
+    int i;
308
+    float *exc     = ctx->excitation;
309
+    enum Mode mode = ctx->fr_cur_mode;
310
+
311
+    if (mode <= MODE_8k85) {
312
+        decode_pitch_lag_low(&pitch_lag_int, &pitch_lag_frac, amr_subframe->adap,
313
+                              &ctx->base_pitch_lag, subframe, mode);
314
+    } else
315
+        decode_pitch_lag_high(&pitch_lag_int, &pitch_lag_frac, amr_subframe->adap,
316
+                              &ctx->base_pitch_lag, subframe);
317
+
318
+    ctx->pitch_lag_int = pitch_lag_int;
319
+    pitch_lag_int += pitch_lag_frac > 0;
320
+
321
+    /* Calculate the pitch vector by interpolating the past excitation at the
322
+       pitch lag using a hamming windowed sinc function */
323
+    ff_acelp_interpolatef(exc, exc + 1 - pitch_lag_int,
324
+                          ac_inter, 4,
325
+                          pitch_lag_frac + (pitch_lag_frac > 0 ? 0 : 4),
326
+                          LP_ORDER, AMRWB_SFR_SIZE + 1);
327
+
328
+    /* Check which pitch signal path should be used
329
+     * 6k60 and 8k85 modes have the ltp flag set to 0 */
330
+    if (amr_subframe->ltp) {
331
+        memcpy(ctx->pitch_vector, exc, AMRWB_SFR_SIZE * sizeof(float));
332
+    } else {
333
+        for (i = 0; i < AMRWB_SFR_SIZE; i++)
334
+            ctx->pitch_vector[i] = 0.18 * exc[i - 1] + 0.64 * exc[i] +
335
+                                   0.18 * exc[i + 1];
336
+        memcpy(exc, ctx->pitch_vector, AMRWB_SFR_SIZE * sizeof(float));
337
+    }
338
+}
339
+
340
+/** Get x bits in the index interval [lsb,lsb+len-1] inclusive */
341
+#define BIT_STR(x,lsb,len) (((x) >> (lsb)) & ((1 << (len)) - 1))
342
+
343
+/** Get the bit at specified position */
344
+#define BIT_POS(x, p) (((x) >> (p)) & 1)
345
+
346
+/**
347
+ * The next six functions decode_[i]p_track decode exactly i pulses
348
+ * positions and amplitudes (-1 or 1) in a subframe track using
349
+ * an encoded pulse indexing (TS 26.190 section 5.8.2)
350
+ *
351
+ * The results are given in out[], in which a negative number means
352
+ * amplitude -1 and vice versa (i.e., ampl(x) = x / abs(x) )
353
+ *
354
+ * @param[out] out                 Output buffer (writes i elements)
355
+ * @param[in]  code                Pulse index (no. of bits varies, see below)
356
+ * @param[in]  m                   (log2) Number of potential positions
357
+ * @param[in]  off                 Offset for decoded positions
358
+ */
359
+static inline void decode_1p_track(int *out, int code, int m, int off)
360
+{
361
+    int pos = BIT_STR(code, 0, m) + off; ///code: m+1 bits
362
+
363
+    out[0] = BIT_POS(code, m) ? -pos : pos;
364
+}
365
+
366
+static inline void decode_2p_track(int *out, int code, int m, int off) ///code: 2m+1 bits
367
+{
368
+    int pos0 = BIT_STR(code, m, m) + off;
369
+    int pos1 = BIT_STR(code, 0, m) + off;
370
+
371
+    out[0] = BIT_POS(code, 2*m) ? -pos0 : pos0;
372
+    out[1] = BIT_POS(code, 2*m) ? -pos1 : pos1;
373
+    out[1] = pos0 > pos1 ? -out[1] : out[1];
374
+}
375
+
376
+static void decode_3p_track(int *out, int code, int m, int off) ///code: 3m+1 bits
377
+{
378
+    int half_2p = BIT_POS(code, 2*m - 1) << (m - 1);
379
+
380
+    decode_2p_track(out, BIT_STR(code, 0, 2*m - 1),
381
+                    m - 1, off + half_2p);
382
+    decode_1p_track(out + 2, BIT_STR(code, 2*m, m + 1), m, off);
383
+}
384
+
385
+static void decode_4p_track(int *out, int code, int m, int off) ///code: 4m bits
386
+{
387
+    int half_4p, subhalf_2p;
388
+    int b_offset = 1 << (m - 1);
389
+
390
+    switch (BIT_STR(code, 4*m - 2, 2)) { /* case ID (2 bits) */
391
+    case 0: /* 0 pulses in A, 4 pulses in B or vice versa */
392
+        half_4p = BIT_POS(code, 4*m - 3) << (m - 1); // which has 4 pulses
393
+        subhalf_2p = BIT_POS(code, 2*m - 3) << (m - 2);
394
+
395
+        decode_2p_track(out, BIT_STR(code, 0, 2*m - 3),
396
+                        m - 2, off + half_4p + subhalf_2p);
397
+        decode_2p_track(out + 2, BIT_STR(code, 2*m - 2, 2*m - 1),
398
+                        m - 1, off + half_4p);
399
+        break;
400
+    case 1: /* 1 pulse in A, 3 pulses in B */
401
+        decode_1p_track(out, BIT_STR(code,  3*m - 2, m),
402
+                        m - 1, off);
403
+        decode_3p_track(out + 1, BIT_STR(code, 0, 3*m - 2),
404
+                        m - 1, off + b_offset);
405
+        break;
406
+    case 2: /* 2 pulses in each half */
407
+        decode_2p_track(out, BIT_STR(code, 2*m - 1, 2*m - 1),
408
+                        m - 1, off);
409
+        decode_2p_track(out + 2, BIT_STR(code, 0, 2*m - 1),
410
+                        m - 1, off + b_offset);
411
+        break;
412
+    case 3: /* 3 pulses in A, 1 pulse in B */
413
+        decode_3p_track(out, BIT_STR(code, m, 3*m - 2),
414
+                        m - 1, off);
415
+        decode_1p_track(out + 3, BIT_STR(code, 0, m),
416
+                        m - 1, off + b_offset);
417
+        break;
418
+    }
419
+}
420
+
421
+static void decode_5p_track(int *out, int code, int m, int off) ///code: 5m bits
422
+{
423
+    int half_3p = BIT_POS(code, 5*m - 1) << (m - 1);
424
+
425
+    decode_3p_track(out, BIT_STR(code, 2*m + 1, 3*m - 2),
426
+                    m - 1, off + half_3p);
427
+
428
+    decode_2p_track(out + 3, BIT_STR(code, 0, 2*m + 1), m, off);
429
+}
430
+
431
+static void decode_6p_track(int *out, int code, int m, int off) ///code: 6m-2 bits
432
+{
433
+    int b_offset = 1 << (m - 1);
434
+    /* which half has more pulses in cases 0 to 2 */
435
+    int half_more  = BIT_POS(code, 6*m - 5) << (m - 1);
436
+    int half_other = b_offset - half_more;
437
+
438
+    switch (BIT_STR(code, 6*m - 4, 2)) { /* case ID (2 bits) */
439
+    case 0: /* 0 pulses in A, 6 pulses in B or vice versa */
440
+        decode_1p_track(out, BIT_STR(code, 0, m),
441
+                        m - 1, off + half_more);
442
+        decode_5p_track(out + 1, BIT_STR(code, m, 5*m - 5),
443
+                        m - 1, off + half_more);
444
+        break;
445
+    case 1: /* 1 pulse in A, 5 pulses in B or vice versa */
446
+        decode_1p_track(out, BIT_STR(code, 0, m),
447
+                        m - 1, off + half_other);
448
+        decode_5p_track(out + 1, BIT_STR(code, m, 5*m - 5),
449
+                        m - 1, off + half_more);
450
+        break;
451
+    case 2: /* 2 pulses in A, 4 pulses in B or vice versa */
452
+        decode_2p_track(out, BIT_STR(code, 0, 2*m - 1),
453
+                        m - 1, off + half_other);
454
+        decode_4p_track(out + 2, BIT_STR(code, 2*m - 1, 4*m - 4),
455
+                        m - 1, off + half_more);
456
+        break;
457
+    case 3: /* 3 pulses in A, 3 pulses in B */
458
+        decode_3p_track(out, BIT_STR(code, 3*m - 2, 3*m - 2),
459
+                        m - 1, off);
460
+        decode_3p_track(out + 3, BIT_STR(code, 0, 3*m - 2),
461
+                        m - 1, off + b_offset);
462
+        break;
463
+    }
464
+}
465
+
466
+/**
467
+ * Decode the algebraic codebook index to pulse positions and signs,
468
+ * then construct the algebraic codebook vector
469
+ *
470
+ * @param[out] fixed_vector        Buffer for the fixed codebook excitation
471
+ * @param[in]  pulse_hi            MSBs part of the pulse index array (higher modes only)
472
+ * @param[in]  pulse_lo            LSBs part of the pulse index array
473
+ * @param[in]  mode                Mode of the current frame
474
+ */
475
+static void decode_fixed_vector(float *fixed_vector, const uint16_t *pulse_hi,
476
+                                const uint16_t *pulse_lo, const enum Mode mode)
477
+{
478
+    /* sig_pos stores for each track the decoded pulse position indexes
479
+     * (1-based) multiplied by its corresponding amplitude (+1 or -1) */
480
+    int sig_pos[4][6];
481
+    int spacing = (mode == MODE_6k60) ? 2 : 4;
482
+    int i, j;
483
+
484
+    switch (mode) {
485
+    case MODE_6k60:
486
+        for (i = 0; i < 2; i++)
487
+            decode_1p_track(sig_pos[i], pulse_lo[i], 5, 1);
488
+        break;
489
+    case MODE_8k85:
490
+        for (i = 0; i < 4; i++)
491
+            decode_1p_track(sig_pos[i], pulse_lo[i], 4, 1);
492
+        break;
493
+    case MODE_12k65:
494
+        for (i = 0; i < 4; i++)
495
+            decode_2p_track(sig_pos[i], pulse_lo[i], 4, 1);
496
+        break;
497
+    case MODE_14k25:
498
+        for (i = 0; i < 2; i++)
499
+            decode_3p_track(sig_pos[i], pulse_lo[i], 4, 1);
500
+        for (i = 2; i < 4; i++)
501
+            decode_2p_track(sig_pos[i], pulse_lo[i], 4, 1);
502
+        break;
503
+    case MODE_15k85:
504
+        for (i = 0; i < 4; i++)
505
+            decode_3p_track(sig_pos[i], pulse_lo[i], 4, 1);
506
+        break;
507
+    case MODE_18k25:
508
+        for (i = 0; i < 4; i++)
509
+            decode_4p_track(sig_pos[i], (int) pulse_lo[i] +
510
+                           ((int) pulse_hi[i] << 14), 4, 1);
511
+        break;
512
+    case MODE_19k85:
513
+        for (i = 0; i < 2; i++)
514
+            decode_5p_track(sig_pos[i], (int) pulse_lo[i] +
515
+                           ((int) pulse_hi[i] << 10), 4, 1);
516
+        for (i = 2; i < 4; i++)
517
+            decode_4p_track(sig_pos[i], (int) pulse_lo[i] +
518
+                           ((int) pulse_hi[i] << 14), 4, 1);
519
+        break;
520
+    case MODE_23k05:
521
+    case MODE_23k85:
522
+        for (i = 0; i < 4; i++)
523
+            decode_6p_track(sig_pos[i], (int) pulse_lo[i] +
524
+                           ((int) pulse_hi[i] << 11), 4, 1);
525
+        break;
526
+    }
527
+
528
+    memset(fixed_vector, 0, sizeof(float) * AMRWB_SFR_SIZE);
529
+
530
+    for (i = 0; i < 4; i++)
531
+        for (j = 0; j < pulses_nb_per_mode_tr[mode][i]; j++) {
532
+            int pos = (FFABS(sig_pos[i][j]) - 1) * spacing + i;
533
+
534
+            fixed_vector[pos] += sig_pos[i][j] < 0 ? -1.0 : 1.0;
535
+        }
536
+}
537
+
538
+/**
539
+ * Decode pitch gain and fixed gain correction factor
540
+ *
541
+ * @param[in]  vq_gain             Vector-quantized index for gains
542
+ * @param[in]  mode                Mode of the current frame
543
+ * @param[out] fixed_gain_factor   Decoded fixed gain correction factor
544
+ * @param[out] pitch_gain          Decoded pitch gain
545
+ */
546
+static void decode_gains(const uint8_t vq_gain, const enum Mode mode,
547
+                         float *fixed_gain_factor, float *pitch_gain)
548
+{
549
+    const int16_t *gains = (mode <= MODE_8k85 ? qua_gain_6b[vq_gain] :
550
+                                                qua_gain_7b[vq_gain]);
551
+
552
+    *pitch_gain        = gains[0] * (1.0f / (1 << 14));
553
+    *fixed_gain_factor = gains[1] * (1.0f / (1 << 11));
554
+}
555
+
556
+/**
557
+ * Apply pitch sharpening filters to the fixed codebook vector
558
+ *
559
+ * @param[in]     ctx              The context
560
+ * @param[in,out] fixed_vector     Fixed codebook excitation
561
+ */
562
+// XXX: Spec states this procedure should be applied when the pitch
563
+// lag is less than 64, but this checking seems absent in reference and AMR-NB
564
+static void pitch_sharpening(AMRWBContext *ctx, float *fixed_vector)
565
+{
566
+    int i;
567
+
568
+    /* Tilt part */
569
+    for (i = AMRWB_SFR_SIZE - 1; i != 0; i--)
570
+        fixed_vector[i] -= fixed_vector[i - 1] * ctx->tilt_coef;
571
+
572
+    /* Periodicity enhancement part */
573
+    for (i = ctx->pitch_lag_int; i < AMRWB_SFR_SIZE; i++)
574
+        fixed_vector[i] += fixed_vector[i - ctx->pitch_lag_int] * 0.85;
575
+}
576
+
577
+/**
578
+ * Calculate the voicing factor (-1.0 = unvoiced to 1.0 = voiced)
579
+ *
580
+ * @param[in] p_vector, f_vector   Pitch and fixed excitation vectors
581
+ * @param[in] p_gain, f_gain       Pitch and fixed gains
582
+ */
583
+// XXX: There is something wrong with the precision here! The magnitudes
584
+// of the energies are not correct. Please check the reference code carefully
585
+static float voice_factor(float *p_vector, float p_gain,
586
+                          float *f_vector, float f_gain)
587
+{
588
+    double p_ener = (double) ff_dot_productf(p_vector, p_vector,
589
+                                             AMRWB_SFR_SIZE) * p_gain * p_gain;
590
+    double f_ener = (double) ff_dot_productf(f_vector, f_vector,
591
+                                             AMRWB_SFR_SIZE) * f_gain * f_gain;
592
+
593
+    return (p_ener - f_ener) / (p_ener + f_ener);
594
+}
595
+
596
+/**
597
+ * Reduce fixed vector sparseness by smoothing with one of three IR filters
598
+ * Also known as "adaptive phase dispersion"
599
+ *
600
+ * @param[in]     ctx              The context
601
+ * @param[in,out] fixed_vector     Unfiltered fixed vector
602
+ * @param[out]    buf              Space for modified vector if necessary
603
+ *
604
+ * @return The potentially overwritten filtered fixed vector address
605
+ */
606
+static float *anti_sparseness(AMRWBContext *ctx,
607
+                              float *fixed_vector, float *buf)
608
+{
609
+    int ir_filter_nr;
610
+
611
+    if (ctx->fr_cur_mode > MODE_8k85) // no filtering in higher modes
612
+        return fixed_vector;
613
+
614
+    if (ctx->pitch_gain[0] < 0.6) {
615
+        ir_filter_nr = 0;      // strong filtering
616
+    } else if (ctx->pitch_gain[0] < 0.9) {
617
+        ir_filter_nr = 1;      // medium filtering
618
+    } else
619
+        ir_filter_nr = 2;      // no filtering
620
+
621
+    /* detect 'onset' */
622
+    if (ctx->fixed_gain[0] > 3.0 * ctx->fixed_gain[1]) {
623
+        if (ir_filter_nr < 2)
624
+            ir_filter_nr++;
625
+    } else {
626
+        int i, count = 0;
627
+
628
+        for (i = 0; i < 6; i++)
629
+            if (ctx->pitch_gain[i] < 0.6)
630
+                count++;
631
+
632
+        if (count > 2)
633
+            ir_filter_nr = 0;
634
+
635
+        if (ir_filter_nr > ctx->prev_ir_filter_nr + 1)
636
+            ir_filter_nr--;
637
+    }
638
+
639
+    /* update ir filter strength history */
640
+    ctx->prev_ir_filter_nr = ir_filter_nr;
641
+
642
+    ir_filter_nr += (ctx->fr_cur_mode == MODE_8k85);
643
+
644
+    if (ir_filter_nr < 2) {
645
+        int i;
646
+        const float *coef = ir_filters_lookup[ir_filter_nr];
647
+
648
+        /* Circular convolution code in the reference
649
+         * decoder was modified to avoid using one
650
+         * extra array. The filtered vector is given by:
651
+         *
652
+         * c2(n) = sum(i,0,len-1){ c(i) * coef( (n - i + len) % len ) }
653
+         */
654
+
655
+        memset(buf, 0, sizeof(float) * AMRWB_SFR_SIZE);
656
+        for (i = 0; i < AMRWB_SFR_SIZE; i++)
657
+            if (fixed_vector[i])
658
+                ff_celp_circ_addf(buf, buf, coef, i, fixed_vector[i],
659
+                                  AMRWB_SFR_SIZE);
660
+        fixed_vector = buf;
661
+    }
662
+
663
+    return fixed_vector;
664
+}
665
+
666
+/**
667
+ * Calculate a stability factor {teta} based on distance between
668
+ * current and past isf. A value of 1 shows maximum signal stability
669
+ */
670
+static float stability_factor(const float *isf, const float *isf_past)
671
+{
672
+    int i;
673
+    float acc = 0.0;
674
+
675
+    for (i = 0; i < LP_ORDER - 1; i++)
676
+        acc += (isf[i] - isf_past[i]) * (isf[i] - isf_past[i]);
677
+
678
+    // XXX: This part is not so clear from the reference code
679
+    // the result is more accurate changing the "/ 256" to "* 512"
680
+    return FFMAX(0.0, 1.25 - acc * 0.8 * 512);
681
+}
682
+
683
+/**
684
+ * Apply a non-linear fixed gain smoothing in order to reduce
685
+ * fluctuation in the energy of excitation
686
+ *
687
+ * @param[in]     fixed_gain       Unsmoothed fixed gain
688
+ * @param[in,out] prev_tr_gain     Previous threshold gain (updated)
689
+ * @param[in]     voice_fac        Frame voicing factor
690
+ * @param[in]     stab_fac         Frame stability factor
691
+ *
692
+ * @return The smoothed gain
693
+ */
694
+static float noise_enhancer(float fixed_gain, float *prev_tr_gain,
695
+                            float voice_fac,  float stab_fac)
696
+{
697
+    float sm_fac = 0.5 * (1 - voice_fac) * stab_fac;
698
+    float g0;
699
+
700
+    // XXX: the following fixed-point constants used to in(de)crement
701
+    // gain by 1.5dB were taken from the reference code, maybe it could
702
+    // be simpler
703
+    if (fixed_gain < *prev_tr_gain) {
704
+        g0 = FFMIN(*prev_tr_gain, fixed_gain + fixed_gain *
705
+                     (6226 * (1.0f / (1 << 15)))); // +1.5 dB
706
+    } else
707
+        g0 = FFMAX(*prev_tr_gain, fixed_gain *
708
+                    (27536 * (1.0f / (1 << 15)))); // -1.5 dB
709
+
710
+    *prev_tr_gain = g0; // update next frame threshold
711
+
712
+    return sm_fac * g0 + (1 - sm_fac) * fixed_gain;
713
+}
714
+
715
+/**
716
+ * Filter the fixed_vector to emphasize the higher frequencies
717
+ *
718
+ * @param[in,out] fixed_vector     Fixed codebook vector
719
+ * @param[in]     voice_fac        Frame voicing factor
720
+ */
721
+static void pitch_enhancer(float *fixed_vector, float voice_fac)
722
+{
723
+    int i;
724
+    float cpe  = 0.125 * (1 + voice_fac);
725
+    float last = fixed_vector[0]; // holds c(i - 1)
726
+
727
+    fixed_vector[0] -= cpe * fixed_vector[1];
728
+
729
+    for (i = 1; i < AMRWB_SFR_SIZE - 1; i++) {
730
+        float cur = fixed_vector[i];
731
+
732
+        fixed_vector[i] -= cpe * (last + fixed_vector[i + 1]);
733
+        last = cur;
734
+    }
735
+
736
+    fixed_vector[AMRWB_SFR_SIZE - 1] -= cpe * last;
737
+}
738
+
739
+/**
740
+ * Conduct 16th order linear predictive coding synthesis from excitation
741
+ *
742
+ * @param[in]     ctx              Pointer to the AMRWBContext
743
+ * @param[in]     lpc              Pointer to the LPC coefficients
744
+ * @param[out]    excitation       Buffer for synthesis final excitation
745
+ * @param[in]     fixed_gain       Fixed codebook gain for synthesis
746
+ * @param[in]     fixed_vector     Algebraic codebook vector
747
+ * @param[in,out] samples          Pointer to the output samples and memory
748
+ */
749
+static void synthesis(AMRWBContext *ctx, float *lpc, float *excitation,
750
+                      float fixed_gain, const float *fixed_vector,
751
+                      float *samples)
752
+{
753
+    ff_weighted_vector_sumf(excitation, ctx->pitch_vector, fixed_vector,
754
+                            ctx->pitch_gain[0], fixed_gain, AMRWB_SFR_SIZE);
755
+
756
+    /* emphasize pitch vector contribution in low bitrate modes */
757
+    if (ctx->pitch_gain[0] > 0.5 && ctx->fr_cur_mode <= MODE_8k85) {
758
+        int i;
759
+        float energy = ff_dot_productf(excitation, excitation,
760
+                                       AMRWB_SFR_SIZE);
761
+
762
+        // XXX: Weird part in both ref code and spec. A unknown parameter
763
+        // {beta} seems to be identical to the current pitch gain
764
+        float pitch_factor = 0.25 * ctx->pitch_gain[0] * ctx->pitch_gain[0];
765
+
766
+        for (i = 0; i < AMRWB_SFR_SIZE; i++)
767
+            excitation[i] += pitch_factor * ctx->pitch_vector[i];
768
+
769
+        ff_scale_vector_to_given_sum_of_squares(excitation, excitation,
770
+                                                energy, AMRWB_SFR_SIZE);
771
+    }
772
+
773
+    ff_celp_lp_synthesis_filterf(samples, lpc, excitation,
774
+                                 AMRWB_SFR_SIZE, LP_ORDER);
775
+}
776
+
777
+/**
778
+ * Apply to synthesis a de-emphasis filter of the form:
779
+ * H(z) = 1 / (1 - m * z^-1)
780
+ *
781
+ * @param[out]    out              Output buffer
782
+ * @param[in]     in               Input samples array with in[-1]
783
+ * @param[in]     m                Filter coefficient
784
+ * @param[in,out] mem              State from last filtering
785
+ */
786
+static void de_emphasis(float *out, float *in, float m, float mem[1])
787
+{
788
+    int i;
789
+
790
+    out[0] = in[0] + m * mem[0];
791
+
792
+    for (i = 1; i < AMRWB_SFR_SIZE; i++)
793
+         out[i] = in[i] + out[i - 1] * m;
794
+
795
+    mem[0] = out[AMRWB_SFR_SIZE - 1];
796
+}
797
+
798
+/**
799
+ * Upsample a signal by 5/4 ratio (from 12.8kHz to 16kHz) using
800
+ * a FIR interpolation filter. Uses past data from before *in address
801
+ *
802
+ * @param[out] out                 Buffer for interpolated signal
803
+ * @param[in]  in                  Current signal data (length 0.8*o_size)
804
+ * @param[in]  o_size              Output signal length
805
+ */
806
+static void upsample_5_4(float *out, const float *in, int o_size)
807
+{
808
+    const float *in0 = in - UPS_FIR_SIZE + 1;
809
+    int i, j, k;
810
+    int int_part = 0, frac_part;
811
+
812
+    i = 0;
813
+    for (j = 0; j < o_size / 5; j++) {
814
+        out[i] = in[int_part];
815
+        frac_part = 4;
816
+        i++;
817
+
818
+        for (k = 1; k < 5; k++) {
819
+            out[i] = ff_dot_productf(in0 + int_part, upsample_fir[4 - frac_part],
820
+                                     UPS_MEM_SIZE);
821
+            int_part++;
822
+            frac_part--;
823
+            i++;
824
+        }
825
+    }
826
+}
827
+
828
+/**
829
+ * Calculate the high-band gain based on encoded index (23k85 mode) or
830
+ * on the low-band speech signal and the Voice Activity Detection flag
831
+ *
832
+ * @param[in] ctx                  The context
833
+ * @param[in] synth                LB speech synthesis at 12.8k
834
+ * @param[in] hb_idx               Gain index for mode 23k85 only
835
+ * @param[in] vad                  VAD flag for the frame
836
+ */
837
+static float find_hb_gain(AMRWBContext *ctx, const float *synth,
838
+                          uint16_t hb_idx, uint8_t vad)
839
+{
840
+    int wsp = (vad > 0);
841
+    float tilt;
842
+
843
+    if (ctx->fr_cur_mode == MODE_23k85)
844
+        return qua_hb_gain[hb_idx] * (1.0f / (1 << 14));
845
+
846
+    tilt = ff_dot_productf(synth, synth + 1, AMRWB_SFR_SIZE - 1) /
847
+           ff_dot_productf(synth, synth, AMRWB_SFR_SIZE);
848
+
849
+    /* return gain bounded by [0.1, 1.0] */
850
+    return av_clipf((1.0 - FFMAX(0.0, tilt)) * (1.25 - 0.25 * wsp), 0.1, 1.0);
851
+}
852
+
853
+/**
854
+ * Generate the high-band excitation with the same energy from the lower
855
+ * one and scaled by the given gain
856
+ *
857
+ * @param[in]  ctx                 The context
858
+ * @param[out] hb_exc              Buffer for the excitation
859
+ * @param[in]  synth_exc           Low-band excitation used for synthesis
860
+ * @param[in]  hb_gain             Wanted excitation gain
861
+ */
862
+static void scaled_hb_excitation(AMRWBContext *ctx, float *hb_exc,
863
+                                 const float *synth_exc, float hb_gain)
864
+{
865
+    int i;
866
+    float energy = ff_dot_productf(synth_exc, synth_exc, AMRWB_SFR_SIZE);
867
+
868
+    /* Generate a white-noise excitation */
869
+    for (i = 0; i < AMRWB_SFR_SIZE_16k; i++)
870
+        hb_exc[i] = 32768.0 - (uint16_t) av_lfg_get(&ctx->prng);
871
+
872
+    ff_scale_vector_to_given_sum_of_squares(hb_exc, hb_exc,
873
+                                            energy * hb_gain * hb_gain,
874
+                                            AMRWB_SFR_SIZE_16k);
875
+}
876
+
877
+/**
878
+ * Calculate the auto-correlation for the ISF difference vector
879
+ */
880
+static float auto_correlation(float *diff_isf, float mean, int lag)
881
+{
882
+    int i;
883
+    float sum = 0.0;
884
+
885
+    for (i = 7; i < LP_ORDER - 2; i++) {
886
+        float prod = (diff_isf[i] - mean) * (diff_isf[i - lag] - mean);
887
+        sum += prod * prod;
888
+    }
889
+    return sum;
890
+}
891
+
892
+/**
893
+ * Extrapolate a ISF vector to the 16kHz range (20th order LP)
894
+ * used at mode 6k60 LP filter for the high frequency band
895
+ *
896
+ * @param[out] out                 Buffer for extrapolated isf
897
+ * @param[in]  isf                 Input isf vector
898
+ */
899
+static void extrapolate_isf(float out[LP_ORDER_16k], float isf[LP_ORDER])
900
+{
901
+    float diff_isf[LP_ORDER - 2], diff_mean;
902
+    float *diff_hi = diff_isf - LP_ORDER + 1; // diff array for extrapolated indexes
903
+    float corr_lag[3];
904
+    float est, scale;
905
+    int i, i_max_corr;
906
+
907
+    memcpy(out, isf, (LP_ORDER - 1) * sizeof(float));
908
+    out[LP_ORDER_16k - 1] = isf[LP_ORDER - 1];
909
+
910
+    /* Calculate the difference vector */
911
+    for (i = 0; i < LP_ORDER - 2; i++)
912
+        diff_isf[i] = isf[i + 1] - isf[i];
913
+
914
+    diff_mean = 0.0;
915
+    for (i = 2; i < LP_ORDER - 2; i++)
916
+        diff_mean += diff_isf[i] * (1.0f / (LP_ORDER - 4));
917
+
918
+    /* Find which is the maximum autocorrelation */
919
+    i_max_corr = 0;
920
+    for (i = 0; i < 3; i++) {
921
+        corr_lag[i] = auto_correlation(diff_isf, diff_mean, i + 2);
922
+
923
+        if (corr_lag[i] > corr_lag[i_max_corr])
924
+            i_max_corr = i;
925
+    }
926
+    i_max_corr++;
927
+
928
+    for (i = LP_ORDER - 1; i < LP_ORDER_16k - 1; i++)
929
+        out[i] = isf[i - 1] + isf[i - 1 - i_max_corr]
930
+                            - isf[i - 2 - i_max_corr];
931
+
932
+    /* Calculate an estimate for ISF(18) and scale ISF based on the error */
933
+    est   = 7965 + (out[2] - out[3] - out[4]) / 6.0;
934
+    scale = 0.5 * (FFMIN(est, 7600) - out[LP_ORDER - 2]) /
935
+            (out[LP_ORDER_16k - 2] - out[LP_ORDER - 2]);
936
+
937
+    for (i = LP_ORDER - 1; i < LP_ORDER_16k - 1; i++)
938
+        diff_hi[i] = scale * (out[i] - out[i - 1]);
939
+
940
+    /* Stability insurance */
941
+    for (i = LP_ORDER; i < LP_ORDER_16k - 1; i++)
942
+        if (diff_hi[i] + diff_hi[i - 1] < 5.0) {
943
+            if (diff_hi[i] > diff_hi[i - 1]) {
944
+                diff_hi[i - 1] = 5.0 - diff_hi[i];
945
+            } else
946
+                diff_hi[i] = 5.0 - diff_hi[i - 1];
947
+        }
948
+
949
+    for (i = LP_ORDER - 1; i < LP_ORDER_16k - 1; i++)
950
+        out[i] = out[i - 1] + diff_hi[i] * (1.0f / (1 << 15));
951
+
952
+    /* Scale the ISF vector for 16000 Hz */
953
+    for (i = 0; i < LP_ORDER_16k - 1; i++)
954
+        out[i] *= 0.8;
955
+}
956
+
957
+/**
958
+ * Spectral expand the LP coefficients using the equation:
959
+ *   y[i] = x[i] * (gamma ** i)
960
+ *
961
+ * @param[out] out                 Output buffer (may use input array)
962
+ * @param[in]  lpc                 LP coefficients array
963
+ * @param[in]  gamma               Weighting factor
964
+ * @param[in]  size                LP array size
965
+ */
966
+static void lpc_weighting(float *out, const float *lpc, float gamma, int size)
967
+{
968
+    int i;
969
+    float fac = gamma;
970
+
971
+    for (i = 0; i < size; i++) {
972
+        out[i] = lpc[i] * fac;
973
+        fac   *= gamma;
974
+    }
975
+}
976
+
977
+/**
978
+ * Conduct 20th order linear predictive coding synthesis for the high
979
+ * frequency band excitation at 16kHz
980
+ *
981
+ * @param[in]     ctx              The context
982
+ * @param[in]     subframe         Current subframe index (0 to 3)
983
+ * @param[in,out] samples          Pointer to the output speech samples
984
+ * @param[in]     exc              Generated white-noise scaled excitation
985
+ * @param[in]     isf              Current frame isf vector
986
+ * @param[in]     isf_past         Past frame final isf vector
987
+ */
988
+static void hb_synthesis(AMRWBContext *ctx, int subframe, float *samples,
989
+                         const float *exc, const float *isf, const float *isf_past)
990
+{
991
+    float hb_lpc[LP_ORDER_16k];
992
+    enum Mode mode = ctx->fr_cur_mode;
993
+
994
+    if (mode == MODE_6k60) {
995
+        float e_isf[LP_ORDER_16k]; // ISF vector for extrapolation
996
+        double e_isp[LP_ORDER_16k];
997
+
998
+        ff_weighted_vector_sumf(e_isf, isf_past, isf, isfp_inter[subframe],
999
+                                1.0 - isfp_inter[subframe], LP_ORDER);
1000
+
1001
+        extrapolate_isf(e_isf, e_isf);
1002
+
1003
+        e_isf[LP_ORDER_16k - 1] *= 2.0;
1004
+        ff_acelp_lsf2lspd(e_isp, e_isf, LP_ORDER_16k);
1005
+        ff_amrwb_lsp2lpc(e_isp, hb_lpc, LP_ORDER_16k);
1006
+
1007
+        lpc_weighting(hb_lpc, hb_lpc, 0.9, LP_ORDER_16k);
1008
+    } else {
1009
+        lpc_weighting(hb_lpc, ctx->lp_coef[subframe], 0.6, LP_ORDER);
1010
+    }
1011
+
1012
+    ff_celp_lp_synthesis_filterf(samples, hb_lpc, exc, AMRWB_SFR_SIZE_16k,
1013
+                                 (mode == MODE_6k60) ? LP_ORDER_16k : LP_ORDER);
1014
+}
1015
+
1016
+/**
1017
+ * Apply to high-band samples a 15th order filter
1018
+ * The filter characteristic depends on the given coefficients
1019
+ *
1020
+ * @param[out]    out              Buffer for filtered output
1021
+ * @param[in]     fir_coef         Filter coefficients
1022
+ * @param[in,out] mem              State from last filtering (updated)
1023
+ * @param[in]     in               Input speech data (high-band)
1024
+ *
1025
+ * @remark It is safe to pass the same array in in and out parameters
1026
+ */
1027
+static void hb_fir_filter(float *out, const float fir_coef[HB_FIR_SIZE + 1],
1028
+                          float mem[HB_FIR_SIZE], const float *in)
1029
+{
1030
+    int i, j;
1031
+    float data[AMRWB_SFR_SIZE_16k + HB_FIR_SIZE]; // past and current samples
1032
+
1033
+    memcpy(data, mem, HB_FIR_SIZE * sizeof(float));
1034
+    memcpy(data + HB_FIR_SIZE, in, AMRWB_SFR_SIZE_16k * sizeof(float));
1035
+
1036
+    for (i = 0; i < AMRWB_SFR_SIZE_16k; i++) {
1037
+        out[i] = 0.0;
1038
+        for (j = 0; j <= HB_FIR_SIZE; j++)
1039
+            out[i] += data[i + j] * fir_coef[j];
1040
+    }
1041
+
1042
+    memcpy(mem, data + AMRWB_SFR_SIZE_16k, HB_FIR_SIZE * sizeof(float));
1043
+}
1044
+
1045
+/**
1046
+ * Update context state before the next subframe
1047
+ */
1048
+static void update_sub_state(AMRWBContext *ctx)
1049
+{
1050
+    memmove(&ctx->excitation_buf[0], &ctx->excitation_buf[AMRWB_SFR_SIZE],
1051
+            (AMRWB_P_DELAY_MAX + LP_ORDER + 1) * sizeof(float));
1052
+
1053
+    memmove(&ctx->pitch_gain[1], &ctx->pitch_gain[0], 5 * sizeof(float));
1054
+    memmove(&ctx->fixed_gain[1], &ctx->fixed_gain[0], 1 * sizeof(float));
1055
+
1056
+    memmove(&ctx->samples_az[0], &ctx->samples_az[AMRWB_SFR_SIZE],
1057
+            LP_ORDER * sizeof(float));
1058
+    memmove(&ctx->samples_up[0], &ctx->samples_up[AMRWB_SFR_SIZE],
1059
+            UPS_MEM_SIZE * sizeof(float));
1060
+    memmove(&ctx->samples_hb[0], &ctx->samples_hb[AMRWB_SFR_SIZE_16k],
1061
+            LP_ORDER_16k * sizeof(float));
1062
+}
1063
+
1064
+static int amrwb_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
1065
+                              AVPacket *avpkt)
1066
+{
1067
+    AMRWBContext *ctx  = avctx->priv_data;
1068
+    AMRWBFrame   *cf   = &ctx->frame;
1069
+    const uint8_t *buf = avpkt->data;
1070
+    int buf_size       = avpkt->size;
1071
+    int expected_fr_size, header_size;
1072
+    float *buf_out = data;
1073
+    float spare_vector[AMRWB_SFR_SIZE];      // extra stack space to hold result from anti-sparseness processing
1074
+    float fixed_gain_factor;                 // fixed gain correction factor (gamma)
1075
+    float *synth_fixed_vector;               // pointer to the fixed vector that synthesis should use
1076
+    float synth_fixed_gain;                  // the fixed gain that synthesis should use
1077
+    float voice_fac, stab_fac;               // parameters used for gain smoothing
1078
+    float synth_exc[AMRWB_SFR_SIZE];         // post-processed excitation for synthesis
1079
+    float hb_exc[AMRWB_SFR_SIZE_16k];        // excitation for the high frequency band
1080
+    float hb_samples[AMRWB_SFR_SIZE_16k];    // filtered high-band samples from synthesis
1081
+    float hb_gain;
1082
+    int sub, i;
1083
+
1084
+    header_size      = decode_mime_header(ctx, buf);
1085
+    expected_fr_size = ((cf_sizes_wb[ctx->fr_cur_mode] + 7) >> 3) + 1;
1086
+
1087
+    if (buf_size < expected_fr_size) {
1088
+        av_log(avctx, AV_LOG_ERROR,
1089
+            "Frame too small (%d bytes). Truncated file?\n", buf_size);
1090
+        *data_size = 0;
1091
+        return buf_size;
1092
+    }
1093
+
1094
+    if (!ctx->fr_quality || ctx->fr_cur_mode > MODE_SID)
1095
+        av_log(avctx, AV_LOG_ERROR, "Encountered a bad or corrupted frame\n");
1096
+
1097
+    if (ctx->fr_cur_mode == MODE_SID) /* Comfort noise frame */
1098
+        av_log_missing_feature(avctx, "SID mode", 1);
1099
+
1100
+    if (ctx->fr_cur_mode >= MODE_SID)
1101
+        return -1;
1102
+
1103
+    ff_amr_bit_reorder((uint16_t *) &ctx->frame, sizeof(AMRWBFrame),
1104
+        buf + header_size, amr_bit_orderings_by_mode[ctx->fr_cur_mode]);
1105
+
1106
+    /* Decode the quantized ISF vector */
1107
+    if (ctx->fr_cur_mode == MODE_6k60) {
1108
+        decode_isf_indices_36b(cf->isp_id, ctx->isf_cur);
1109
+    } else {
1110
+        decode_isf_indices_46b(cf->isp_id, ctx->isf_cur);
1111
+    }
1112
+
1113
+    isf_add_mean_and_past(ctx->isf_cur, ctx->isf_q_past);
1114
+    ff_set_min_dist_lsf(ctx->isf_cur, MIN_ISF_SPACING, LP_ORDER - 1);
1115
+
1116
+    stab_fac = stability_factor(ctx->isf_cur, ctx->isf_past_final);
1117
+
1118
+    ctx->isf_cur[LP_ORDER - 1] *= 2.0;
1119
+    ff_acelp_lsf2lspd(ctx->isp[3], ctx->isf_cur, LP_ORDER);
1120
+
1121
+    /* Generate a ISP vector for each subframe */
1122
+    if (ctx->first_frame) {
1123
+        ctx->first_frame = 0;
1124
+        memcpy(ctx->isp_sub4_past, ctx->isp[3], LP_ORDER * sizeof(double));
1125
+    }
1126
+    interpolate_isp(ctx->isp, ctx->isp_sub4_past);
1127
+
1128
+    for (sub = 0; sub < 4; sub++)
1129
+        ff_amrwb_lsp2lpc(ctx->isp[sub], ctx->lp_coef[sub], LP_ORDER);
1130
+
1131
+    for (sub = 0; sub < 4; sub++) {
1132
+        const AMRWBSubFrame *cur_subframe = &cf->subframe[sub];
1133
+        float *sub_buf = buf_out + sub * AMRWB_SFR_SIZE_16k;
1134
+
1135
+        /* Decode adaptive codebook (pitch vector) */
1136
+        decode_pitch_vector(ctx, cur_subframe, sub);
1137
+        /* Decode innovative codebook (fixed vector) */
1138
+        decode_fixed_vector(ctx->fixed_vector, cur_subframe->pul_ih,
1139
+                            cur_subframe->pul_il, ctx->fr_cur_mode);
1140
+
1141
+        pitch_sharpening(ctx, ctx->fixed_vector);
1142
+
1143
+        decode_gains(cur_subframe->vq_gain, ctx->fr_cur_mode,
1144
+                     &fixed_gain_factor, &ctx->pitch_gain[0]);
1145
+
1146
+        ctx->fixed_gain[0] =
1147
+            ff_amr_set_fixed_gain(fixed_gain_factor,
1148
+                       ff_dot_productf(ctx->fixed_vector, ctx->fixed_vector,
1149
+                                       AMRWB_SFR_SIZE) / AMRWB_SFR_SIZE,
1150
+                       ctx->prediction_error,
1151
+                       ENERGY_MEAN, energy_pred_fac);
1152
+
1153
+        /* Calculate voice factor and store tilt for next subframe */
1154
+        voice_fac      = voice_factor(ctx->pitch_vector, ctx->pitch_gain[0],
1155
+                                      ctx->fixed_vector, ctx->fixed_gain[0]);
1156
+        ctx->tilt_coef = voice_fac * 0.25 + 0.25;
1157
+
1158
+        /* Construct current excitation */
1159
+        for (i = 0; i < AMRWB_SFR_SIZE; i++) {
1160
+            ctx->excitation[i] *= ctx->pitch_gain[0];
1161
+            ctx->excitation[i] += ctx->fixed_gain[0] * ctx->fixed_vector[i];
1162
+            ctx->excitation[i] = truncf(ctx->excitation[i]);
1163
+        }
1164
+
1165
+        /* Post-processing of excitation elements */
1166
+        synth_fixed_gain = noise_enhancer(ctx->fixed_gain[0], &ctx->prev_tr_gain,
1167
+                                          voice_fac, stab_fac);
1168
+
1169
+        synth_fixed_vector = anti_sparseness(ctx, ctx->fixed_vector,
1170
+                                             spare_vector);
1171
+
1172
+        pitch_enhancer(synth_fixed_vector, voice_fac);
1173
+
1174
+        synthesis(ctx, ctx->lp_coef[sub], synth_exc, synth_fixed_gain,
1175
+                  synth_fixed_vector, &ctx->samples_az[LP_ORDER]);
1176
+
1177
+        /* Synthesis speech post-processing */
1178
+        de_emphasis(&ctx->samples_up[UPS_MEM_SIZE],
1179
+                    &ctx->samples_az[LP_ORDER], PREEMPH_FAC, ctx->demph_mem);
1180
+
1181
+        ff_acelp_apply_order_2_transfer_function(&ctx->samples_up[UPS_MEM_SIZE],
1182
+            &ctx->samples_up[UPS_MEM_SIZE], hpf_zeros, hpf_31_poles,
1183
+            hpf_31_gain, ctx->hpf_31_mem, AMRWB_SFR_SIZE);
1184
+
1185
+        upsample_5_4(sub_buf, &ctx->samples_up[UPS_FIR_SIZE],
1186
+                     AMRWB_SFR_SIZE_16k);
1187
+
1188
+        /* High frequency band (6.4 - 7.0 kHz) generation part */
1189
+        ff_acelp_apply_order_2_transfer_function(hb_samples,
1190
+            &ctx->samples_up[UPS_MEM_SIZE], hpf_zeros, hpf_400_poles,
1191
+            hpf_400_gain, ctx->hpf_400_mem, AMRWB_SFR_SIZE);
1192
+
1193
+        hb_gain = find_hb_gain(ctx, hb_samples,
1194
+                               cur_subframe->hb_gain, cf->vad);
1195
+
1196
+        scaled_hb_excitation(ctx, hb_exc, synth_exc, hb_gain);
1197
+
1198
+        hb_synthesis(ctx, sub, &ctx->samples_hb[LP_ORDER_16k],
1199
+                     hb_exc, ctx->isf_cur, ctx->isf_past_final);
1200
+
1201
+        /* High-band post-processing filters */
1202
+        hb_fir_filter(hb_samples, bpf_6_7_coef, ctx->bpf_6_7_mem,
1203
+                      &ctx->samples_hb[LP_ORDER_16k]);
1204
+
1205
+        if (ctx->fr_cur_mode == MODE_23k85)
1206
+            hb_fir_filter(hb_samples, lpf_7_coef, ctx->lpf_7_mem,
1207
+                          hb_samples);
1208
+
1209
+        /* Add the low and high frequency bands */
1210
+        for (i = 0; i < AMRWB_SFR_SIZE_16k; i++)
1211
+            sub_buf[i] = (sub_buf[i] + hb_samples[i]) * (1.0f / (1 << 15));
1212
+
1213
+        /* Update buffers and history */
1214
+        update_sub_state(ctx);
1215
+    }
1216
+
1217
+    /* update state for next frame */
1218
+    memcpy(ctx->isp_sub4_past, ctx->isp[3], LP_ORDER * sizeof(ctx->isp[3][0]));
1219
+    memcpy(ctx->isf_past_final, ctx->isf_cur, LP_ORDER * sizeof(float));
1220
+
1221
+    /* report how many samples we got */
1222
+    *data_size = 4 * AMRWB_SFR_SIZE_16k * sizeof(float);
1223
+
1224
+    return expected_fr_size;
1225
+}
1226
+
1227
+AVCodec amrwb_decoder = {
1228
+    .name           = "amrwb",
1229
+    .type           = CODEC_TYPE_AUDIO,
1230
+    .id             = CODEC_ID_AMR_WB,
1231
+    .priv_data_size = sizeof(AMRWBContext),
1232
+    .init           = amrwb_decode_init,
1233
+    .decode         = amrwb_decode_frame,
1234
+    .long_name      = NULL_IF_CONFIG_SMALL("Adaptive Multi-Rate WideBand"),
1235
+    .sample_fmts    = (enum SampleFormat[]){SAMPLE_FMT_FLT,SAMPLE_FMT_NONE},
1236
+};