diff --git a/Frameworks/FFMPEG/FFMPEG.xcodeproj/project.pbxproj b/Frameworks/FFMPEG/FFMPEG.xcodeproj/project.pbxproj index 9533fedec..1080c3911 100644 --- a/Frameworks/FFMPEG/FFMPEG.xcodeproj/project.pbxproj +++ b/Frameworks/FFMPEG/FFMPEG.xcodeproj/project.pbxproj @@ -7,6 +7,13 @@ objects = { /* Begin PBXBuildFile section */ + 830C4B5B180C3434007674D6 /* amr.h in Headers */ = {isa = PBXBuildFile; fileRef = 830C4B56180C3434007674D6 /* amr.h */; }; + 830C4B5C180C3434007674D6 /* amrnbdata.h in Headers */ = {isa = PBXBuildFile; fileRef = 830C4B57180C3434007674D6 /* amrnbdata.h */; }; + 830C4B5D180C3434007674D6 /* amrnbdec.c in Sources */ = {isa = PBXBuildFile; fileRef = 830C4B58180C3434007674D6 /* amrnbdec.c */; }; + 830C4B5E180C3434007674D6 /* amrwbdata.h in Headers */ = {isa = PBXBuildFile; fileRef = 830C4B59180C3434007674D6 /* amrwbdata.h */; }; + 830C4B5F180C3434007674D6 /* amrwbdec.c in Sources */ = {isa = PBXBuildFile; fileRef = 830C4B5A180C3434007674D6 /* amrwbdec.c */; }; + 830C4B61180C343C007674D6 /* amr.c in Sources */ = {isa = PBXBuildFile; fileRef = 830C4B60180C343C007674D6 /* amr.c */; }; + 830C4B63180C3580007674D6 /* amrwbdec_mips.h in Headers */ = {isa = PBXBuildFile; fileRef = 830C4B62180C3580007674D6 /* amrwbdec_mips.h */; }; 830F0BD117FC4FB900042E8F /* allcodecs.c in Sources */ = {isa = PBXBuildFile; fileRef = 830F0B8F17FC4FB900042E8F /* allcodecs.c */; }; 830F0BD217FC4FB900042E8F /* avcodec.h in Headers */ = {isa = PBXBuildFile; fileRef = 830F0B9017FC4FB900042E8F /* avcodec.h */; settings = {ATTRIBUTES = (Public, ); }; }; 830F0BD517FC4FB900042E8F /* fft.c in Sources */ = {isa = PBXBuildFile; fileRef = 830F0B9317FC4FB900042E8F /* fft.c */; }; @@ -436,6 +443,13 @@ /* Begin PBXFileReference section */ 089C1667FE841158C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = ""; }; 32DBCF5E0370ADEE00C91783 /* FFMPEG_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FFMPEG_Prefix.pch; sourceTree = ""; }; + 830C4B56180C3434007674D6 /* amr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = amr.h; sourceTree = ""; }; + 830C4B57180C3434007674D6 /* amrnbdata.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = amrnbdata.h; sourceTree = ""; }; + 830C4B58180C3434007674D6 /* amrnbdec.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = amrnbdec.c; sourceTree = ""; }; + 830C4B59180C3434007674D6 /* amrwbdata.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = amrwbdata.h; sourceTree = ""; }; + 830C4B5A180C3434007674D6 /* amrwbdec.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = amrwbdec.c; sourceTree = ""; }; + 830C4B60180C343C007674D6 /* amr.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = amr.c; sourceTree = ""; }; + 830C4B62180C3580007674D6 /* amrwbdec_mips.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = amrwbdec_mips.h; sourceTree = ""; }; 830F0B8F17FC4FB900042E8F /* allcodecs.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = allcodecs.c; sourceTree = ""; }; 830F0B9017FC4FB900042E8F /* avcodec.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = avcodec.h; sourceTree = ""; }; 830F0B9317FC4FB900042E8F /* fft.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = fft.c; sourceTree = ""; }; @@ -943,6 +957,11 @@ 830F0B8E17FC4FB900042E8F /* libavcodec */ = { isa = PBXGroup; children = ( + 830C4B56180C3434007674D6 /* amr.h */, + 830C4B57180C3434007674D6 /* amrnbdata.h */, + 830C4B58180C3434007674D6 /* amrnbdec.c */, + 830C4B59180C3434007674D6 /* amrwbdata.h */, + 830C4B5A180C3434007674D6 /* amrwbdec.c */, 838491161807D1D900E7332D /* tta.c */, 838491171807D1D900E7332D /* ttadata.c */, 838491181807D1D900E7332D /* ttadata.h */, @@ -1195,6 +1214,7 @@ 830F0BAD17FC4FB900042E8F /* libavformat */ = { isa = PBXGroup; children = ( + 830C4B60180C343C007674D6 /* amr.c */, 838491141807D1D200E7332D /* tta.c */, 838491121807D06100E7332D /* spdifdec.c */, 838490FE1807C58500E7332D /* aacdec.c */, @@ -1394,6 +1414,7 @@ 830F0D0417FC80B400042E8F /* mips */ = { isa = PBXGroup; children = ( + 830C4B62180C3580007674D6 /* amrwbdec_mips.h */, 830F0D0517FC80B400042E8F /* lsp_mips.h */, ); path = mips; @@ -1560,6 +1581,7 @@ 830F0C4917FC7CA300042E8F /* asf.h in Headers */, 830F0DCA17FC931700042E8F /* pcm.h in Headers */, 830F0CCC17FC7F1E00042E8F /* celp_filters.h in Headers */, + 830C4B5C180C3434007674D6 /* amrnbdata.h in Headers */, 830F0D5117FC880E00042E8F /* time_.h in Headers */, 830F0BD717FC4FB900042E8F /* get_bits.h in Headers */, 830F0C2417FC527400042E8F /* atomic.h in Headers */, @@ -1572,6 +1594,7 @@ 833C37D118032D4800CBA602 /* dirac_dwt.h in Headers */, 8393B80318052BC200913C76 /* mpegaudiodecheader.h in Headers */, 838490901807BC9400E7332D /* dca.h in Headers */, + 830C4B5E180C3434007674D6 /* amrwbdata.h in Headers */, 830F0D7917FC8C7300042E8F /* mpeg4audio.h in Headers */, 830F0C3A17FC554D00042E8F /* des.h in Headers */, 830F0BF117FC4FB900042E8F /* avi.h in Headers */, @@ -1591,6 +1614,7 @@ 830F0C4A17FC7CA300042E8F /* avio_internal.h in Headers */, 830F0C7017FC7DB100042E8F /* pixdesc.h in Headers */, 833C37C318032CF600CBA602 /* dirac_arith.h in Headers */, + 830C4B63180C3580007674D6 /* amrwbdec_mips.h in Headers */, 830F0CF717FC7F1E00042E8F /* rnd_avg.h in Headers */, 830F0D4117FC848D00042E8F /* sha.h in Headers */, 830F0CEE17FC7F1E00042E8F /* mpeg12data.h in Headers */, @@ -1606,6 +1630,7 @@ 830F0CF117FC7F1E00042E8F /* ratecontrol.h in Headers */, 830F0C1417FC500B00042E8F /* fft-internal.h in Headers */, 830F0D8E17FC8E8B00042E8F /* sbr.h in Headers */, + 830C4B5B180C3434007674D6 /* amr.h in Headers */, 833C37B218032AEF00CBA602 /* diracdsp.h in Headers */, 830F0C3D17FC554D00042E8F /* internal.h in Headers */, 833C37D718032EA500CBA602 /* idct_xvid.h in Headers */, @@ -1760,14 +1785,17 @@ 830F0D5917FC893E00042E8F /* codec_desc.c in Sources */, 830F0DBE17FC922C00042E8F /* h264chroma_init.c in Sources */, 830F0BF217FC4FB900042E8F /* avio.c in Sources */, + 830C4B5F180C3434007674D6 /* amrwbdec.c in Sources */, 838490DC1807C47E00E7332D /* g723_1.c in Sources */, 830F0CE217FC7F1E00042E8F /* frame_thread_encoder.c in Sources */, + 830C4B61180C343C007674D6 /* amr.c in Sources */, 838491151807D1D200E7332D /* tta.c in Sources */, 8393B80118052BC200913C76 /* mpegaudiodec.c in Sources */, 830F0C3817FC554D00042E8F /* buffer.c in Sources */, 8384905C1807AF0100E7332D /* ac3_parser.c in Sources */, 830F0C6B17FC7DB100042E8F /* bprint.c in Sources */, 830F0BE017FC4FB900042E8F /* simple_idct.c in Sources */, + 830C4B5D180C3434007674D6 /* amrnbdec.c in Sources */, 838490991807BC9C00E7332D /* dtsdec.c in Sources */, 830F0D6917FC8A3D00042E8F /* avpicture.c in Sources */, 8393B80518052BC200913C76 /* mpegaudiodsp_data.c in Sources */, diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/config.h b/Frameworks/FFMPEG/ffmpeg-minimal/config.h index 1b3baa64a..651f584e3 100644 --- a/Frameworks/FFMPEG/ffmpeg-minimal/config.h +++ b/Frameworks/FFMPEG/ffmpeg-minimal/config.h @@ -393,8 +393,8 @@ #define CONFIG_ALAC_ENCODER 0 #define CONFIG_ALAC_DECODER 0 #define CONFIG_ALS_DECODER 0 -#define CONFIG_AMRNB_DECODER 0 -#define CONFIG_AMRWB_DECODER 0 +#define CONFIG_AMRNB_DECODER 1 +#define CONFIG_AMRWB_DECODER 1 #define CONFIG_APE_DECODER 1 #define CONFIG_ATRAC1_DECODER 0 #define CONFIG_ATRAC3_DECODER 1 @@ -718,7 +718,7 @@ #define CONFIG_AIFF_MUXER 0 #define CONFIG_AIFF_DEMUXER 0 #define CONFIG_AMR_MUXER 0 -#define CONFIG_AMR_DEMUXER 0 +#define CONFIG_AMR_DEMUXER 1 #define CONFIG_ANM_DEMUXER 0 #define CONFIG_APC_DEMUXER 0 #define CONFIG_APE_DEMUXER 1 diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/amr.h b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/amr.h new file mode 100644 index 000000000..1ac73abe8 --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/amr.h @@ -0,0 +1,70 @@ +/* + * Shared functions between AMR codecs + * + * Copyright (c) 2010 Marcelo Galvao Povoa + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_AMR_H +#define AVCODEC_AMR_H + +#include + +#include "avcodec.h" + +#ifdef AMR_USE_16BIT_TABLES +#define R_TABLE_TYPE uint16_t +#else +#define R_TABLE_TYPE uint8_t +#endif + +/** + * Fill the frame structure variables from bitstream by parsing the + * given reordering table that uses the following format: + * + * Each field (16 bits) in the AMR Frame is stored as: + * - one byte for the number of bits in the field + * - one byte for the field index + * - then, one byte for each bit of the field (from most-significant to least) + * of the position of that bit in the AMR frame. + * + * @param out pointer to the frame struct + * @param size the size in bytes of the frame struct + * @param data input bitstream after the frame header + * @param ord_table the reordering table as above + */ +static inline void ff_amr_bit_reorder(uint16_t *out, int size, + const uint8_t *data, + const R_TABLE_TYPE *ord_table) +{ + int field_size; + + memset(out, 0, size); + while ((field_size = *ord_table++)) { + int field = 0; + int field_offset = *ord_table++; + while (field_size--) { + int bit = *ord_table++; + field <<= 1; + field |= data[bit >> 3] >> (bit & 7) & 1; + } + out[field_offset >> 1] = field; + } +} + +#endif /* AVCODEC_AMR_H */ diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/amrnbdata.h b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/amrnbdata.h new file mode 100644 index 000000000..435fd9924 --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/amrnbdata.h @@ -0,0 +1,1671 @@ +/* + * AMR narrowband data and definitions + * Copyright (c) 2006-2007 Robert Swain + * Copyright (c) 2009 Colin McQuillan + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +/** + * @file + * AMR narrowband data and definitions + */ + +#ifndef AVCODEC_AMRNBDATA_H +#define AVCODEC_AMRNBDATA_H + +#include + +#include "libavutil/common.h" /* offsetof */ + +#define AMR_SUBFRAME_SIZE 40 ///< samples per subframe + +/** Frame type (Table 1a in 3GPP TS 26.101) */ +enum Mode { + MODE_4k75 = 0, ///< 4.75 kbit/s + MODE_5k15, ///< 5.15 kbit/s + MODE_5k9, ///< 5.90 kbit/s + MODE_6k7, ///< 6.70 kbit/s + MODE_7k4, ///< 7.40 kbit/s + MODE_7k95, ///< 7.95 kbit/s + MODE_10k2, ///< 10.2 kbit/s + MODE_12k2, ///< 12.2 kbit/s + MODE_DTX, ///< silent frame + N_MODES, ///< number of modes + NO_DATA = 15 ///< no transmission +}; + +#define LP_FILTER_ORDER 10 ///< linear predictive coding filter order + +/** + * AMRNB unpacked data subframe + */ +typedef struct AMRNBSubframe { + uint16_t p_lag; ///< index to decode the pitch lag + uint16_t p_gain; ///< index to decode the pitch gain + uint16_t fixed_gain; ///< index to decode the fixed gain factor, for MODE_12k2 and MODE_7k95 + uint16_t pulses[10]; ///< pulses: 10 for MODE_12k2, 7 for MODE_10k2, and index and sign for others +} AMRNBSubframe; + +/** + * AMRNB unpacked data frame + */ +typedef struct AMRNBFrame { + uint16_t lsf[5]; ///< lsf parameters: 5 parameters for MODE_12k2, only 3 for other modes + AMRNBSubframe subframe[4]; ///< unpacked data for each subframe +} AMRNBFrame; + +/** The index of a frame parameter */ +#define AMR_BIT(field) (offsetof(AMRNBFrame, field)) +/** The index of a subframe-specific parameter */ +#define AMR_OF(frame_num, variable) AMR_BIT(subframe[frame_num].variable) + +// The following order* tables are used to convert AMR frame parameters to and +// from a bitstream. See 3GPP TS 26.101 for more information. +// Each field in AMRNBFrame is stored as: +// * one byte for the number of bits in the field +// * one byte for the field index +// * then, one byte for each bit of the field (from most-significant to least) +// of the position of that bit in the AMR frame. +static const uint8_t order_MODE_4k75[] = { + 8, AMR_BIT(lsf[0]), 7, 6, 5, 4, 3, 2, 1, 0, + 8, AMR_BIT(lsf[1]), 15, 14, 13, 12, 11, 10, 9, 8, + 7, AMR_BIT(lsf[2]), 51, 35, 34, 50, 33, 49, 32, + 8, AMR_OF(0,p_lag), 23, 22, 21, 20, 19, 18, 43, 42, + 8, AMR_OF(0,p_gain), 54, 55, 40, 41, 24, 25, 26, 27, + 7, AMR_OF(0,pulses[0]), 92, 68, 67, 84, 66, 65, 80, + 2, AMR_OF(0,pulses[1]), 53, 52, + 4, AMR_OF(1,p_lag), 17, 16, 48, 63, + 7, AMR_OF(1,pulses[0]), 91, 64, 79, 83, 78, 77, 95, + 2, AMR_OF(1,pulses[1]), 62, 61, + 4, AMR_OF(2,p_lag), 31, 30, 60, 59, + 8, AMR_OF(2,p_gain), 44, 45, 46, 47, 36, 37, 38, 39, + 7, AMR_OF(2,pulses[0]), 90, 76, 75, 82, 74, 73, 94, + 2, AMR_OF(2,pulses[1]), 58, 57, + 4, AMR_OF(3,p_lag), 29, 28, 56, 71, + 7, AMR_OF(3,pulses[0]), 89, 72, 87, 81, 86, 85, 93, + 2, AMR_OF(3,pulses[1]), 70, 69, + 0 +}; + +static const uint8_t order_MODE_5k15[] = { + 8, AMR_BIT(lsf[0]), 0, 1, 2, 3, 4, 5, 6, 7, + 8, AMR_BIT(lsf[1]), 8, 9, 10, 11, 12, 13, 14, 15, + 7, AMR_BIT(lsf[2]), 70, 51, 43, 71, 50, 60, 49, + 8, AMR_OF(0,p_lag), 23, 22, 21, 20, 19, 47, 54, 59, + 6, AMR_OF(0,p_gain), 48, 42, 35, 29, 30, 31, + 7, AMR_OF(0,pulses[0]), 92, 84, 82, 100, 79, 72, 88, + 2, AMR_OF(0,pulses[1]), 67, 68, + 4, AMR_OF(1,p_lag), 18, 46, 53, 58, + 6, AMR_OF(1,p_gain), 63, 41, 34, 26, 27, 28, + 7, AMR_OF(1,pulses[0]), 91, 83, 81, 99, 78, 87, 103, + 2, AMR_OF(1,pulses[1]), 65, 66, + 4, AMR_OF(2,p_lag), 17, 45, 52, 57, + 6, AMR_OF(2,p_gain), 62, 40, 33, 39, 24, 25, + 7, AMR_OF(2,pulses[0]), 90, 80, 95, 98, 77, 86, 102, + 2, AMR_OF(2,pulses[1]), 75, 64, + 4, AMR_OF(3,p_lag), 16, 44, 56, 69, + 6, AMR_OF(3,p_gain), 61, 55, 32, 36, 37, 38, + 7, AMR_OF(3,pulses[0]), 89, 94, 93, 97, 76, 85, 101, + 2, AMR_OF(3,pulses[1]), 73, 74, + 0 +}; + +static const uint8_t order_MODE_5k9[] = { + 8, AMR_BIT(lsf[0]), 7, 6, 0, 3, 5, 4, 2, 1, + 9, AMR_BIT(lsf[1]), 13, 12, 8, 11, 10, 15, 9, 14, 23, + 9, AMR_BIT(lsf[2]), 71, 56, 60, 70, 59, 57, 58, 69, 76, + 8, AMR_OF(0,p_lag), 16, 18, 22, 20, 30, 38, 44, 42, + 6, AMR_OF(0,p_gain), 75, 48, 52, 40, 34, 26, + 9, AMR_OF(0,pulses[0]), 101, 89, 93, 117, 105, 81, 85, 109, 97, + 2, AMR_OF(0,pulses[1]), 67, 78, + 4, AMR_OF(1,p_lag), 28, 36, 46, 87, + 6, AMR_OF(1,p_gain), 74, 63, 51, 55, 33, 25, + 9, AMR_OF(1,pulses[0]), 100, 88, 92, 116, 104, 80, 84, 108, 96, + 2, AMR_OF(1,pulses[1]), 64, 79, + 8, AMR_OF(2,p_lag), 31, 17, 21, 19, 29, 37, 43, 41, + 6, AMR_OF(2,p_gain), 73, 62, 50, 54, 32, 24, + 9, AMR_OF(2,pulses[0]), 99, 103, 91, 115, 119, 95, 83, 107, 111, + 2, AMR_OF(2,pulses[1]), 66, 77, + 4, AMR_OF(3,p_lag), 27, 35, 45, 86, + 6, AMR_OF(3,p_gain), 72, 61, 49, 53, 47, 39, + 9, AMR_OF(3,pulses[0]), 98, 102, 90, 114, 118, 94, 82, 106, 110, + 2, AMR_OF(3,pulses[1]), 65, 68, + 0 +}; + +static const uint8_t order_MODE_6k7[] = { + 8, AMR_BIT(lsf[0]), 7, 6, 15, 4, 5, 3, 2, 0, + 9, AMR_BIT(lsf[1]), 14, 13, 8, 12, 10, 1, 9, 11, 29, + 9, AMR_BIT(lsf[2]), 57, 58, 50, 56, 60, 59, 49, 71, 70, + 8, AMR_OF(0,p_lag), 17, 19, 23, 21, 31, 24, 32, 52, + 7, AMR_OF(0,p_gain), 36, 82, 69, 46, 42, 48, 77, + 11, AMR_OF(0,pulses[0]), 109, 97, 133, 121, 101, 89, 125, 113, 93, 117, + 105, + 3, AMR_OF(0,pulses[1]), 81, 73, 65, + 4, AMR_OF(1,p_lag), 28, 26, 38, 54, + 7, AMR_OF(1,p_gain), 35, 83, 68, 45, 41, 63, 76, + 11, AMR_OF(1,pulses[0]), 108, 96, 132, 120, 100, 88, 124, 112, 92, 116, + 104, + 3, AMR_OF(1,pulses[1]), 80, 72, 64, + 8, AMR_OF(2,p_lag), 16, 18, 22, 20, 30, 39, 47, 51, + 7, AMR_OF(2,p_gain), 34, 84, 67, 44, 40, 62, 75, + 11, AMR_OF(2,pulses[0]), 107, 111, 131, 135, 99, 103, 123, 127, 91, 115, + 119, + 3, AMR_OF(2,pulses[1]), 95, 87, 79, + 4, AMR_OF(3,p_lag), 27, 25, 37, 53, + 7, AMR_OF(3,p_gain), 33, 85, 66, 43, 55, 61, 74, + 11, AMR_OF(3,pulses[0]), 106, 110, 130, 134, 98, 102, 122, 126, 90, 114, + 118, + 3, AMR_OF(3,pulses[1]), 94, 86, 78, + 0 +}; + +static const uint8_t order_MODE_7k4[] = { + 8, AMR_BIT(lsf[0]), 7, 6, 5, 4, 3, 2, 1, 0, + 9, AMR_BIT(lsf[1]), 15, 14, 13, 12, 11, 10, 9, 8, 23, + 9, AMR_BIT(lsf[2]), 53, 52, 51, 58, 40, 55, 54, 57, 56, + 8, AMR_OF(0,p_lag), 22, 20, 18, 16, 30, 50, 95, 94, + 7, AMR_OF(0,p_gain), 28, 24, 73, 36, 32, 62, 67, + 13, AMR_OF(0,pulses[0]), 127, 123, 135, 131, 143, 139, 151, 103, 102, 101, + 100, 99, 98, + 4, AMR_OF(0,pulses[1]), 83, 75, 79, 71, + 5, AMR_OF(1,p_lag), 44, 42, 49, 93, 92, + 7, AMR_OF(1,p_gain), 27, 39, 72, 35, 47, 61, 66, + 13, AMR_OF(1,pulses[0]), 126, 122, 134, 130, 142, 138, 150, 97, 96, 111, + 110, 109, 108, + 4, AMR_OF(1,pulses[1]), 82, 74, 78, 70, + 8, AMR_OF(2,p_lag), 21, 19, 17, 31, 29, 48, 91, 90, + 7, AMR_OF(2,p_gain), 26, 38, 87, 34, 46, 60, 65, + 13, AMR_OF(2,pulses[0]), 125, 121, 133, 129, 141, 137, 149, 107, 106, 105, + 104, 119, 118, + 4, AMR_OF(2,pulses[1]), 81, 85, 77, 69, + 5, AMR_OF(3,p_lag), 43, 41, 63, 89, 88, + 7, AMR_OF(3,p_gain), 25, 37, 86, 33, 45, 59, 64, + 13, AMR_OF(3,pulses[0]), 124, 120, 132, 128, 140, 136, 148, 117, 116, 115, + 114, 113, 112, + 4, AMR_OF(3,pulses[1]), 80, 84, 76, 68, + 0 +}; + +static const uint8_t order_MODE_7k95[] = { + 9, AMR_BIT(lsf[0]), 67, 68, 1, 2, 3, 4, 5, 6, 7, + 9, AMR_BIT(lsf[1]), 14, 13, 9, 12, 11, 0, 10, 15, 8, + 9, AMR_BIT(lsf[2]), 18, 19, 23, 17, 22, 20, 21, 66, 65, + 8, AMR_OF(0,p_lag), 44, 42, 40, 54, 52, 56, 64, 78, + 4, AMR_OF(0,p_gain), 36, 32, 72, 80, + 5, AMR_OF(0,fixed_gain), 16, 28, 24, 60, 84, + 13, AMR_OF(0,pulses[0]), 135, 109, 144, 156, 120, 97, 148, 121, 101, 122, + 123, 89, 124, + 4, AMR_OF(0,pulses[1]), 125, 126, 127, 112, + 6, AMR_OF(1,p_lag), 50, 48, 62, 70, 76, 74, + 4, AMR_OF(1,p_gain), 35, 47, 87, 95, + 5, AMR_OF(1,fixed_gain), 31, 27, 39, 59, 83, + 13, AMR_OF(1,pulses[0]), 129, 108, 159, 155, 130, 96, 147, 131, 100, 132, + 133, 88, 134, + 4, AMR_OF(1,pulses[1]), 113, 114, 115, 116, + 8, AMR_OF(2,p_lag), 43, 41, 55, 53, 51, 71, 79, 77, + 4, AMR_OF(2,p_gain), 34, 46, 86, 94, + 5, AMR_OF(2,fixed_gain), 30, 26, 38, 58, 82, + 13, AMR_OF(2,pulses[0]), 139, 107, 158, 154, 140, 111, 146, 141, 99, 142, + 143, 103, 128, + 4, AMR_OF(2,pulses[1]), 105, 90, 91, 92, + 6, AMR_OF(3,p_lag), 49, 63, 61, 69, 75, 73, + 4, AMR_OF(3,p_gain), 33, 45, 85, 93, + 5, AMR_OF(3,fixed_gain), 29, 25, 37, 57, 81, + 13, AMR_OF(3,pulses[0]), 149, 106, 157, 153, 150, 110, 145, 151, 98, 136, + 137, 102, 138, + 4, AMR_OF(3,pulses[1]), 117, 118, 119, 104, + 0 +}; + +static const uint8_t order_MODE_10k2[] = { + 8, AMR_BIT(lsf[0]), 0, 1, 2, 3, 4, 5, 6, 7, + 9, AMR_BIT(lsf[1]), 23, 8, 9, 10, 11, 12, 13, 14, 15, + 9, AMR_BIT(lsf[2]), 57, 58, 62, 56, 60, 59, 61, 71, 70, + 8, AMR_OF(0,p_lag), 22, 21, 20, 19, 18, 17, 42, 41, + 7, AMR_OF(0,p_gain), 38, 50, 84, 37, 36, 85, 83, + 1, AMR_OF(0,pulses[0]), 66, + 1, AMR_OF(0,pulses[1]), 67, + 1, AMR_OF(0,pulses[2]), 68, + 1, AMR_OF(0,pulses[3]), 69, + 10, AMR_OF(0,pulses[4]), 145, 144, 156, 153, 154, 163, 161, 192, 206, 195, + 10, AMR_OF(0,pulses[5]), 158, 159, 157, 152, 155, 165, 160, 205, 204, 194, + 7, AMR_OF(0,pulses[6]), 167, 166, 162, 164, 196, 207, 193, + 5, AMR_OF(1,p_lag), 26, 25, 54, 53, 89, + 7, AMR_OF(1,p_gain), 35, 49, 81, 34, 33, 82, 80, + 1, AMR_OF(1,pulses[0]), 78, + 1, AMR_OF(1,pulses[1]), 79, + 1, AMR_OF(1,pulses[2]), 64, + 1, AMR_OF(1,pulses[3]), 65, + 10, AMR_OF(1,pulses[4]), 103, 102, 98, 111, 96, 105, 119, 185, 199, 188, + 10, AMR_OF(1,pulses[5]), 100, 101, 99, 110, 97, 107, 118, 198, 197, 187, + 7, AMR_OF(1,pulses[6]), 109, 108, 104, 106, 189, 184, 186, + 8, AMR_OF(2,p_lag), 16, 31, 30, 29, 28, 27, 40, 55, + 7, AMR_OF(2,p_gain), 32, 48, 94, 47, 46, 95, 93, + 1, AMR_OF(2,pulses[0]), 74, + 1, AMR_OF(2,pulses[1]), 75, + 1, AMR_OF(2,pulses[2]), 76, + 1, AMR_OF(2,pulses[3]), 77, + 10, AMR_OF(2,pulses[4]), 117, 116, 112, 125, 126, 135, 133, 178, 176, 181, + 10, AMR_OF(2,pulses[5]), 114, 115, 113, 124, 127, 121, 132, 191, 190, 180, + 7, AMR_OF(2,pulses[6]), 123, 122, 134, 120, 182, 177, 179, + 5, AMR_OF(3,p_lag), 24, 39, 52, 51, 88, + 7, AMR_OF(3,p_gain), 45, 63, 91, 44, 43, 92, 90, + 1, AMR_OF(3,pulses[0]), 86, + 1, AMR_OF(3,pulses[1]), 87, + 1, AMR_OF(3,pulses[2]), 72, + 1, AMR_OF(3,pulses[3]), 73, + 10, AMR_OF(3,pulses[4]), 131, 130, 142, 139, 140, 149, 147, 171, 169, 174, + 10, AMR_OF(3,pulses[5]), 128, 129, 143, 138, 141, 151, 146, 168, 183, 173, + 7, AMR_OF(3,pulses[6]), 137, 136, 148, 150, 175, 170, 172, + 0 +}; + +static const uint8_t order_MODE_12k2[] = { + 7, AMR_BIT(lsf[0]), 7, 6, 5, 4, 3, 2, 1, + 8, AMR_BIT(lsf[1]), 0, 15, 14, 13, 12, 11, 10, 9, + 9, AMR_BIT(lsf[2]), 23, 22, 21, 20, 19, 18, 17, 16, 8, + 8, AMR_BIT(lsf[3]), 31, 30, 29, 28, 27, 86, 85, 84, + 6, AMR_BIT(lsf[4]), 83, 82, 81, 80, 127, 126, + 9, AMR_OF(0,p_lag), 26, 24, 38, 36, 34, 32, 46, 44, 42, + 4, AMR_OF(0,p_gain), 40, 52, 48, 95, + 5, AMR_OF(0,fixed_gain), 60, 56, 68, 91, 111, + 3, AMR_OF(0,pulses[0]), 191, 176, 177, + 4, AMR_OF(0,pulses[1]), 103, 123, 124, 125, + 3, AMR_OF(0,pulses[2]), 188, 189, 190, + 4, AMR_OF(0,pulses[3]), 99, 120, 121, 122, + 3, AMR_OF(0,pulses[4]), 185, 186, 187, + 4, AMR_OF(0,pulses[5]), 107, 133, 134, 135, + 3, AMR_OF(0,pulses[6]), 198, 199, 184, + 4, AMR_OF(0,pulses[7]), 119, 130, 131, 132, + 3, AMR_OF(0,pulses[8]), 195, 196, 197, + 4, AMR_OF(0,pulses[9]), 115, 143, 128, 129, + 6, AMR_OF(1,p_lag), 64, 78, 76, 74, 72, 245, + 4, AMR_OF(1,p_gain), 55, 51, 63, 94, + 5, AMR_OF(1,fixed_gain), 59, 71, 67, 90, 110, + 3, AMR_OF(1,pulses[0]), 192, 193, 194, + 4, AMR_OF(1,pulses[1]), 102, 140, 141, 142, + 3, AMR_OF(1,pulses[2]), 205, 206, 207, + 4, AMR_OF(1,pulses[3]), 98, 137, 138, 139, + 3, AMR_OF(1,pulses[4]), 202, 203, 204, + 4, AMR_OF(1,pulses[5]), 106, 150, 151, 136, + 3, AMR_OF(1,pulses[6]), 215, 200, 201, + 4, AMR_OF(1,pulses[7]), 118, 147, 148, 149, + 3, AMR_OF(1,pulses[8]), 212, 213, 214, + 4, AMR_OF(1,pulses[9]), 114, 144, 145, 146, + 9, AMR_OF(2,p_lag), 25, 39, 37, 35, 33, 47, 45, 43, 41, + 4, AMR_OF(2,p_gain), 54, 50, 62, 93, + 5, AMR_OF(2,fixed_gain), 58, 70, 66, 89, 109, + 3, AMR_OF(2,pulses[0]), 209, 210, 211, + 4, AMR_OF(2,pulses[1]), 101, 157, 158, 159, + 3, AMR_OF(2,pulses[2]), 222, 223, 208, + 4, AMR_OF(2,pulses[3]), 97, 154, 155, 156, + 3, AMR_OF(2,pulses[4]), 219, 220, 221, + 4, AMR_OF(2,pulses[5]), 105, 167, 152, 153, + 3, AMR_OF(2,pulses[6]), 216, 217, 218, + 4, AMR_OF(2,pulses[7]), 117, 164, 165, 166, + 3, AMR_OF(2,pulses[8]), 229, 230, 231, + 4, AMR_OF(2,pulses[9]), 113, 161, 162, 163, + 6, AMR_OF(3,p_lag), 79, 77, 75, 73, 87, 244, + 4, AMR_OF(3,p_gain), 53, 49, 61, 92, + 5, AMR_OF(3,fixed_gain), 57, 69, 65, 88, 108, + 3, AMR_OF(3,pulses[0]), 226, 227, 228, + 4, AMR_OF(3,pulses[1]), 100, 174, 175, 160, + 3, AMR_OF(3,pulses[2]), 239, 224, 225, + 4, AMR_OF(3,pulses[3]), 96, 171, 172, 173, + 3, AMR_OF(3,pulses[4]), 236, 237, 238, + 4, AMR_OF(3,pulses[5]), 104, 168, 169, 170, + 3, AMR_OF(3,pulses[6]), 233, 234, 235, + 4, AMR_OF(3,pulses[7]), 116, 181, 182, 183, + 3, AMR_OF(3,pulses[8]), 246, 247, 232, + 4, AMR_OF(3,pulses[9]), 112, 178, 179, 180, + 0 +}; + +/** + * position of the bitmapping data for each packet type in + * the AMRNBFrame + */ +static const uint8_t * const amr_unpacking_bitmaps_per_mode[N_MODES] = { + order_MODE_4k75, + order_MODE_5k15, + order_MODE_5k9, + order_MODE_6k7, + order_MODE_7k4, + order_MODE_7k95, + order_MODE_10k2, + order_MODE_12k2, +}; + +/** number of bytes for each mode */ +static const uint8_t frame_sizes_nb[N_MODES] = { + 12, 13, 15, 17, 19, 20, 26, 31, 5 +}; + +/** + * Base-5 representation for values 0-124 + * + * This is useful for decoding pulse positions in 10.2 kbit/s frames. + * Safe values are provided for out of range positions 125-127. + */ +static const uint8_t base_five_table[128][3] = { + {0, 0, 0}, {0, 0, 1}, {0, 0, 2}, {0, 0, 3}, {0, 0, 4}, {0, 1, 0}, {0, 1, 1}, + {0, 1, 2}, {0, 1, 3}, {0, 1, 4}, {0, 2, 0}, {0, 2, 1}, {0, 2, 2}, {0, 2, 3}, + {0, 2, 4}, {0, 3, 0}, {0, 3, 1}, {0, 3, 2}, {0, 3, 3}, {0, 3, 4}, {0, 4, 0}, + {0, 4, 1}, {0, 4, 2}, {0, 4, 3}, {0, 4, 4}, {1, 0, 0}, {1, 0, 1}, {1, 0, 2}, + {1, 0, 3}, {1, 0, 4}, {1, 1, 0}, {1, 1, 1}, {1, 1, 2}, {1, 1, 3}, {1, 1, 4}, + {1, 2, 0}, {1, 2, 1}, {1, 2, 2}, {1, 2, 3}, {1, 2, 4}, {1, 3, 0}, {1, 3, 1}, + {1, 3, 2}, {1, 3, 3}, {1, 3, 4}, {1, 4, 0}, {1, 4, 1}, {1, 4, 2}, {1, 4, 3}, + {1, 4, 4}, {2, 0, 0}, {2, 0, 1}, {2, 0, 2}, {2, 0, 3}, {2, 0, 4}, {2, 1, 0}, + {2, 1, 1}, {2, 1, 2}, {2, 1, 3}, {2, 1, 4}, {2, 2, 0}, {2, 2, 1}, {2, 2, 2}, + {2, 2, 3}, {2, 2, 4}, {2, 3, 0}, {2, 3, 1}, {2, 3, 2}, {2, 3, 3}, {2, 3, 4}, + {2, 4, 0}, {2, 4, 1}, {2, 4, 2}, {2, 4, 3}, {2, 4, 4}, {3, 0, 0}, {3, 0, 1}, + {3, 0, 2}, {3, 0, 3}, {3, 0, 4}, {3, 1, 0}, {3, 1, 1}, {3, 1, 2}, {3, 1, 3}, + {3, 1, 4}, {3, 2, 0}, {3, 2, 1}, {3, 2, 2}, {3, 2, 3}, {3, 2, 4}, {3, 3, 0}, + {3, 3, 1}, {3, 3, 2}, {3, 3, 3}, {3, 3, 4}, {3, 4, 0}, {3, 4, 1}, {3, 4, 2}, + {3, 4, 3}, {3, 4, 4}, {4, 0, 0}, {4, 0, 1}, {4, 0, 2}, {4, 0, 3}, {4, 0, 4}, + {4, 1, 0}, {4, 1, 1}, {4, 1, 2}, {4, 1, 3}, {4, 1, 4}, {4, 2, 0}, {4, 2, 1}, + {4, 2, 2}, {4, 2, 3}, {4, 2, 4}, {4, 3, 0}, {4, 3, 1}, {4, 3, 2}, {4, 3, 3}, + {4, 3, 4}, {4, 4, 0}, {4, 4, 1}, {4, 4, 2}, {4, 4, 3}, {4, 4, 4}, {0, 0, 0}, + {0, 0, 0}, {0, 0, 0} +}; + +/** + * Values for the lsp vector from the 4th subframe of the + * previous subframe values. + * + * @note: Taken from Decoder_amr_reset in Q15 using val/1000 + */ +static const int8_t lsp_sub4_init[LP_FILTER_ORDER] = { + 30, 26, 21, 15, 8, 0, -8, -15, -21, -26 +}; + +/** + * Mean lsp values. + * + * @note: Taken from Decoder_amr_reset in Q15 + */ +static const int16_t lsp_avg_init[LP_FILTER_ORDER] = { + 1384, 2077, 3420, 5108, 6742, 8122, 9863, 11092, 12714, 13701 +}; + +// LSF tables + +// These are stored as integers to save space. The values are taken from +// q_plsf_3.tab and q_plsf_5.tab in 3GPP TS 26.090. + +static const int16_t lsf_3_3_MODE_5k15[128][4] = { +{ 419, 163, -30, -262}, { -455, -789,-1430, -721}, { 1006, 664, 269, 25}, +{ 619, 260, 183, 96}, { -968,-1358, -388, 135}, { -693, 835, 456, 154}, +{ 1105, 703, 569, 363}, { 1625, 1326, 985, 748}, { -220, 219, 76, -208}, +{-1455,-1662, 49, 149}, { -964, -172, -752, -336}, { 625, 209, -250, -66}, +{-1017, -838, -2, 317}, {-2168,-1485, -138, 123}, {-1876,-2099, -521, 85}, +{ -967, -366, -695, -881}, { -921,-1011, -763, -949}, { -124, -256, -352, -660}, +{ 178, 463, 354, 304}, {-1744, -591, -282, 79}, {-2249, 175, 867, 499}, +{ -138, -180, -181, -21}, {-2291,-1241, -460, -520}, { -771, 451, -10, -308}, +{ 271, -65, 4, 214}, { -279, -435, -43, -348}, { -670, 35, -65, -211}, +{ 806, 535, 85, 297}, { 57, 239, 722, 493}, { 225, 661, 840, 547}, +{ -540, -376, 14, 349}, { 469, 721, 331, 162}, { -544, -752, -62, -10}, +{ 398, -88, 724, 701}, { -19, -533, -94, 601}, { 136, -71, -681, -747}, +{ -166, -344, 261, -50}, { 161, -52, 485, 337}, {-1675, 50, 190, -93}, +{-2282, -231, -194, -82}, { -95, -595, -154, 128}, { 894, 501, 588, 457}, +{ -345, 206, 122, 110}, { -631, -227, -569, 3}, { 408, 239, 397, 226}, +{ -197, -2, 128, 491}, { 1281, 904, 292, 215}, { 538, 306, 259, 509}, +{ -677,-1047, 13, 321}, { -679, -588, -358, -212}, { -558, 243, 646, 479}, +{ 486, 342, 634, 532}, { 107, 802, 331, 136}, { -112, -398,-1031, -286}, +{ -326, -705, 288, 272}, { 1299, 1144, 1178, 860}, { -423, 121, -385, -148}, +{ -295, -302, -834, -819}, { 16, -24, -201, -476}, { 555, 91, -245, 294}, +{ -38, -379, -962,-1221}, {-1191,-1518, -273, -395}, { -390,-1013, -645, 573}, +{-1843,-1030, 505, 468}, { 744, 947, 609, 493}, { -689,-1172, -628, -135}, +{-1026, 195, 411, 196}, { 1582, 1147, 575, 337}, {-1239, -777, -648, -142}, +{ 595, 825, 967, 735}, {-1206, -970, -81, -342}, { -745, 13, -72, 375}, +{ 454, 19, 1407, 921}, {-1647, -172, 861, 562}, { 928, 1537, 1063, 740}, +{-2472, -952, 264, 82}, { -502, -965,-1334, 123}, { 867, 1236, 534, 171}, +{-2320, -460, 780, 363}, {-1190, -617, 252, -61}, { -174, 34, 1011, 788}, +{-2333, 247, 423, 153}, { -16, -355, 262, 449}, {-1576,-1073, -544, -371}, +{ -615, -305, 1051, 805}, { 687, 528, 6, -182}, { 935, 875, 1002, 809}, +{ 199, 257, 126, 76}, { -584,-1138, 599, 556}, {-1105,-1391,-1591, -519}, +{ -977,-1325, 108, 347}, { -722, -975, 365, 101}, { -145, 681, 249, -153}, +{ 0, -334, -570, 159}, { 412, 285, -336, -617}, { -953, -966, 887, 689}, +{-1251, 84, -185, -398}, { -592, 433, 1044, 653}, { 85, 329, -40, 361}, +{ -433, -705, 466, 574}, { -154, 654, 592, 290}, { -167, 72, 349, 175}, +{ 674, 297, 977, 720}, { 1235, 1204, 757, 488}, { -400, -269, 538, 372}, +{-1350,-1387,-1194, -91}, { 1262, 876, 775, 700}, { -599, -38, -430, -722}, +{ 1976, 1630, 991, 608}, { 111, 276, -226, -96}, { -947, -388, -11, -7}, +{ -303, -531, -839, 338}, { 1734, 1710, 1405, 1013}, { -516, -855, -645, 210}, +{ -688, -416, 513, 230}, { -822, -637,-1146, -320}, { -952, -658, -694, 183}, +{ -114, -623, 818, 674}, { -191, -204, 731, 635}, { 51, 1221, 883, 576}, +{ -954, -431, 826, 598}, { -342, -755, -900, -407}, {-1126, -354, -206, -512}, +{ -547, -810, -357, -620}, { 66, 515, -73, -410}, { -872, -945,-1444,-1227}, +{ 191, -17, -544, -231}, {-1540, -544, -901, -886} +}; + +static const int16_t lsf_3_1_MODE_7k95[512][3] = { +{ -890,-1550,-2541}, { -819, -970, 175}, { -826,-1234, -762}, +{ -599, -22, 634}, { -811, -987, -902}, { -323, 203, 26}, +{ -383, -235, -781}, { -399, 1262, 906}, { -932,-1399,-1380}, +{ -624, 93, 87}, { -414, -539, -691}, { 37, 633, 510}, +{ -387, -476,-1330}, { 399, 66, 263}, { -407, -49, -335}, +{ -417, 1041, 1865}, { -779,-1089,-1440}, { -746, -858, 832}, +{ -581, -759, -371}, { -673, -506, 2088}, { -560, -634,-1179}, +{ 271, 241, 14}, { -438, -244, -397}, { 463, 1202, 1047}, +{ -606, -797,-1438}, { -51, -323, 481}, { -224, -584, -527}, +{ 494, 881, 682}, { -433, -306,-1002}, { 554, 659, 222}, +{ 171, -160, -353}, { 681, 1798, 1565}, { -852,-1181,-1695}, +{ -336, -666, 114}, { -581, -756, -744}, { -195, 375, 497}, +{ -465, -804,-1098}, { 154, 282, -131}, { -50, -191, -719}, +{ 323, 732, 1542}, { -722, -819,-1404}, { 105, -250, 185}, +{ -178, -502, -742}, { 321, 510, 1111}, { -323, -567, -966}, +{ 127, 484, 338}, { -160, 52, -338}, { 732, 1367, 1554}, +{ -626, -802,-1696}, { -286, -586, 676}, { -695, -343, -370}, +{ -490, 295, 1893}, { -630, -574,-1014}, { -80, 645, -69}, +{ -6, -318, -364}, { 782, 1450, 1038}, { -313, -733,-1395}, +{ 120, 60, 477}, { -264, -585, -123}, { 711, 1245, 633}, +{ -91, -355,-1016}, { 771, 758, 261}, { 253, 81, -474}, +{ 930, 2215, 1720}, { -808,-1099,-1925}, { -560, -782, 169}, +{ -804,-1074, -188}, { -626, -55, 1405}, { -694, -716,-1194}, +{ -660, 354, 329}, { -514, -55, -543}, { 366, 1033, 1182}, +{ -658, -959,-1357}, { -55, -184, 93}, { -605, -286, -662}, +{ 404, 449, 827}, { -286, -350,-1263}, { 628, 306, 227}, +{ -16, 147, -623}, { 186, 923, 2146}, { -674, -890,-1606}, +{ -443, -228, 339}, { -369, -790, -409}, { 231, 86, 1469}, +{ -448, -581,-1061}, { 594, 450, -177}, { -124, -170, -447}, +{ 671, 1159, 1404}, { -476, -667,-1511}, { -77, -138, 716}, +{ -177, -372, -381}, { 451, 934, 915}, { -250, -432, -822}, +{ 272, 828, 446}, { 26, 19, -31}, { 698, 1692, 2168}, +{ -646, -977,-1924}, { -179, -473, 268}, { -379, -745, -691}, +{ 11, 127, 1033}, { -488, -917, -825}, { 61, 323, 135}, +{ 147, -145, -686}, { 685, 786, 1682}, { -506, -848,-1297}, +{ 35, 90, 222}, { -23, -346, -670}, { 455, 591, 1287}, +{ -203, -593,-1086}, { 652, 352, 437}, { 39, 63, -457}, +{ 841, 1265, 2105}, { -520, -882,-1584}, { -328, -711, 1421}, +{ -596, -342, -70}, { 209, 173, 1928}, { -423, -598, -921}, +{ 421, 605, -38}, { -2, -245, -127}, { 896, 1969, 1135}, +{ -379, -518,-1579}, { 173, 118, 753}, { -55, -381, -52}, +{ 985, 1021, 753}, { -2, -291, -891}, { 753, 992, 423}, +{ 264, 131, -196}, { 895, 2274, 2543}, { -635,-1088,-2499}, +{ -529, -982, 526}, { -764, -830, -548}, { -436, 316, 599}, +{ -675, -940, -746}, { -57, 236, -11}, { -201, -81, -798}, +{ 16, 845, 1558}, { -737, -985,-1212}, { -468, 17, 290}, +{ -279, -584, -700}, { 183, 822, 705}, { -265, -492,-1187}, +{ 421, 152, 468}, { -390, 166, -268}, { 39, 1550, 1868}, +{ -635, -966,-1571}, { -453, -492, 910}, { -284,-1027, -75}, +{ -181, -133, 1852}, { -445, -624,-1174}, { 420, 367, -49}, +{ -389, -212, -169}, { 707, 1073, 1208}, { -539, -710,-1449}, +{ 83, -163, 484}, { -236, -543, -355}, { 338, 1175, 814}, +{ -246, -309, -958}, { 606, 760, 60}, { 166, -8, -163}, +{ -306, 1849, 2563}, { -747,-1025,-1783}, { -419, -446, 209}, +{ -718, -566, -534}, { -506, 693, 857}, { -463, -697,-1082}, +{ 325, 431, -206}, { -15, -8, -763}, { 545, 919, 1518}, +{ -611, -783,-1313}, { 256, -55, 208}, { -165, -348, -662}, +{ 321, 680, 930}, { -326, -429, -951}, { 484, 446, 570}, +{ -197, 72, -73}, { 909, 1455, 1741}, { -563, -737,-1974}, +{ -124, -416, 718}, { -478, -404, -314}, { -16, 446, 1636}, +{ -551, -537, -750}, { -58, 638, 214}, { 55, -185, -271}, +{ 1148, 1301, 1212}, { -483, -671,-1264}, { 117, 285, 543}, +{ -204, -391, -111}, { 513, 1538, 854}, { -114, -190, -978}, +{ 877, 595, 464}, { 260, 260, -311}, { 748, 2283, 2216}, +{ -517, -945,-2171}, { -326, -708, 378}, { -812, -691, -232}, +{ -560, 687, 1409}, { -732, -690, -836}, { -359, 645, 386}, +{ -265, 62, -678}, { 145, 1644, 1208}, { -555, -988,-1233}, +{ -78, 14, 114}, { -327, -358, -489}, { 392, 677, 697}, +{ -201, -236,-1140}, { 693, 449, 178}, { -243, 256, -433}, +{ 611, 1385, 2456}, { -612, -901,-1464}, { -307, -17, 499}, +{ -315, -667, -254}, { 256, 428, 1463}, { -486, -422,-1056}, +{ 655, 370, 18}, { -102, -185, -276}, { 755, 1578, 1335}, +{ -488, -603,-1418}, { 182, -93, 870}, { -73, -458, -348}, +{ 835, 862, 957}, { -282, -333, -746}, { 547, 839, 428}, +{ 273, -89, 13}, { 940, 1708, 2576}, { -418,-1084,-1758}, +{ -44, -358, 259}, { -497, -643, -560}, { 99, 557, 961}, +{ -421, -766, -917}, { 295, 326, 184}, { 175, 15, -626}, +{ 532, 878, 1981}, { -443, -768,-1275}, { 221, 156, 268}, +{ 39, -363, -505}, { 695, 772, 1140}, { -162, -459, -912}, +{ 709, 444, 658}, { 25, 303, -312}, { 1268, 1410, 1715}, +{ -297, -766,-1836}, { -263, -108, 1070}, { -406, -13, -129}, +{ 57, 438, 2734}, { -374, -487, -835}, { 304, 696, 164}, +{ 104, -235, 5}, { 1611, 1900, 1399}, { -229, -582,-1325}, +{ 405, 192, 817}, { -87, -438, 111}, { 1028, 1199, 993}, +{ 68, -175, -934}, { 1033, 1117, 451}, { 478, 200, -248}, +{ 2127, 2696, 2042}, { -835,-1323,-2131}, { -799, -692, 466}, +{ -812,-1032, -469}, { -622, 288, 920}, { -701, -841,-1070}, +{ -411, 512, 8}, { -390, -91, -744}, { -30, 1043, 1161}, +{ -822,-1148,-1156}, { -294, -46, 110}, { -411, -374, -678}, +{ 214, 531, 668}, { -406, -420,-1194}, { 487, 232, 303}, +{ -318, 91, -472}, { 123, 1232, 2445}, { -722, -952,-1495}, +{ -738, -675, 1332}, { -543, -606, -211}, { -95, -98, 1508}, +{ -549, -514,-1193}, { 473, 211, 73}, { -288, -112, -389}, +{ 537, 1332, 1258}, { -567, -755,-1545}, { 71, -283, 632}, +{ -170, -481, -493}, { 681, 1002, 817}, { -356, -331, -877}, +{ 419, 706, 346}, { 241, -34, -326}, { 377, 1950, 1883}, +{ -727,-1075,-1625}, { -233, -543, 116}, { -524, -806, -585}, +{ -73, 478, 729}, { -288, -925,-1143}, { 173, 447, -52}, +{ 68, -229, -606}, { 449, 529, 1797}, { -591, -875,-1363}, +{ 183, -144, 324}, { -103, -452, -666}, { 623, 488, 1176}, +{ -238, -511,-1004}, { 326, 552, 458}, { 136, 108, -319}, +{ 626, 1343, 1883}, { -490, -646,-1730}, { -186, -449, 984}, +{ -738, -76, -170}, { -550, 755, 2560}, { -496, -510, -947}, +{ 210, 694, -52}, { 84, -322, -199}, { 1090, 1625, 1224}, +{ -376, -603,-1396}, { 343, 74, 632}, { -175, -502, -32}, +{ 972, 1332, 734}, { 52, -295,-1113}, { 1065, 918, 160}, +{ 393, 107, -397}, { 1214, 2649, 1741}, { -632,-1201,-1891}, +{ -719, -277, 353}, { -651, -880, -122}, { -211, 209, 1338}, +{ -562, -714,-1059}, { -208, 388, 159}, { -320, -61, -551}, +{ 293, 1092, 1443}, { -648, -865,-1253}, { -49, -143, 305}, +{ -401, -227, -585}, { 561, 532, 927}, { -117, -443,-1188}, +{ 507, 436, 292}, { -79, 233, -458}, { 671, 1025, 2396}, +{ -633, -842,-1525}, { -308, -286, 640}, { -373, -621, -407}, +{ 418, 253, 1305}, { -315, -581,-1137}, { 572, 685, -281}, +{ 61, -68, -371}, { 991, 1101, 1498}, { -493, -683,-1362}, +{ -47, 164, 704}, { -256, -314, -268}, { 631, 949, 1052}, +{ -118, -348, -833}, { 68, 1180, 568}, { 152, 117, 34}, +{ 1113, 1902, 2239}, { -601, -959,-1706}, { -143, -489, 480}, +{ -332, -655, -574}, { 54, 353, 1192}, { -462, -652, -796}, +{ 150, 549, 112}, { 195, -111, -515}, { 679, 1108, 1647}, +{ -558, -749,-1217}, { -9, 272, 341}, { -53, -265, -535}, +{ 489, 843, 1298}, { -120, -482,-1032}, { 632, 543, 408}, +{ 179, 306, -526}, { 1124, 1464, 2244}, { -417, -786,-1562}, +{ -224, -384, 1364}, { -377, -459, -25}, { 385, 489, 2174}, +{ -332, -651, -829}, { 544, 553, 61}, { 22, -113, -89}, +{ 1128, 1725, 1524}, { -216, -373,-1653}, { 161, 316, 908}, +{ -165, -222, -67}, { 1362, 1175, 789}, { 73, -252, -767}, +{ 738, 932, 616}, { 362, 246, -126}, { 787, 2654, 3027}, +{ -691,-1106,-2190}, { -565, -588, 524}, { -590, -979, -490}, +{ -263, 397, 982}, { -577, -837, -945}, { -22, 435, -49}, +{ -190, -118, -629}, { -88, 1240, 1513}, { -636,-1051,-1019}, +{ -291, 189, 259}, { -257, -470, -629}, { 145, 945, 894}, +{ -326, -364,-1094}, { 543, 260, 630}, { -202, 189, -209}, +{ 357, 1379, 2091}, { -569,-1075,-1449}, { -714, -239, 919}, +{ -420, -705, -84}, { -109, -114, 2407}, { -413, -529,-1177}, +{ 482, 368, 131}, { -186, -72, -131}, { 861, 1255, 1220}, +{ -611, -658,-1341}, { 227, -121, 631}, { -176, -489, -218}, +{ 745, 1175, 957}, { -321, -148, -936}, { 671, 966, 216}, +{ 340, -3, -143}, { 469, 1848, 2437}, { -729, -961,-1683}, +{ -213, -254, 321}, { -511, -438, -521}, { -126, 725, 903}, +{ -340, -685,-1032}, { 316, 480, 20}, { 23, -89, -551}, +{ 353, 1051, 1789}, { -544, -757,-1364}, { 298, -25, 436}, +{ -100, -392, -519}, { 467, 754, 1078}, { -210, -398,-1078}, +{ 620, 658, 630}, { 33, 147, -178}, { 921, 1687, 1921}, +{ -325, -528,-1978}, { 2, -285, 910}, { -371, -490, -230}, +{ 0, 597, 2010}, { -496, -395, -834}, { 37, 945, 245}, +{ 181, -160, -144}, { 1481, 1373, 1357}, { -355, -601,-1270}, +{ 298, 322, 672}, { -193, -336, 77}, { 1089, 1533, 922}, +{ 177, -39,-1125}, { 996, 781, 536}, { 456, 366, -432}, +{ 1415, 2440, 2279}, { -466, -758,-2325}, { -303, -509, 387}, +{ -727, -557, 66}, { -145, 643, 1248}, { -544, -676, -916}, +{ -225, 862, 588}, { -152, 40, -533}, { 423, 1423, 1558}, +{ -572, -843,-1145}, { -128, 85, 461}, { -238, -257, -584}, +{ 605, 748, 861}, { 24, -202,-1409}, { 797, 487, 303}, +{ -181, 364, -182}, { 616, 1378, 2942}, { -494, -852,-1441}, +{ -292, 61, 812}, { -84, -723, -182}, { 555, 532, 1506}, +{ -365, -493,-1057}, { 822, 588, 11}, { -14, -18, -230}, +{ 1001, 1401, 1451}, { -474, -569,-1292}, { 302, 62, 1062}, +{ -70, -376, -222}, { 982, 974, 1149}, { -196, -234, -795}, +{ 479, 1098, 499}, { 362, 58, 70}, { 1147, 2069, 2857}, +{ -487, -878,-1824}, { 73, -288, 348}, { -358, -500, -508}, +{ 199, 721, 1242}, { -78, -697, -795}, { 361, 536, 196}, +{ 374, 110, -735}, { 847, 1051, 1896}, { -366, -713,-1182}, +{ 315, 320, 429}, { 72, -215, -450}, { 759, 886, 1363}, +{ -30, -428, -834}, { 861, 627, 796}, { 118, 468, -279}, +{ 1355, 1883, 1893}, { -188, -642,-1612}, { 63, -175, 1198}, +{ -418, -211, 51}, { 414, 587, 2601}, { -234, -557, -858}, +{ 424, 889, 222}, { 136, -101, 83}, { 1413, 2278, 1383}, +{ -84, -445,-1389}, { 414, 313, 1045}, { 29, -343, 65}, +{ 1552, 1647, 980}, { 183, -91, -829}, { 1273, 1413, 360}, +{ 553, 272, -107}, { 1587, 3149, 2603} +}; + +static const int16_t lsf_3_1[256][3] = { +{ 6, 82, -131}, { 154, -56, -735}, { 183, -65, -265}, +{ 9, -210, -361}, { 113, 718, 1817}, { 1010, 1214, 1573}, +{ 857, 1333, 2276}, { 827, 1568, 1933}, { 717, 1989, 2206}, +{ 838, 1172, 1823}, { 721, 1000, 2154}, { 286, 476, 1509}, +{ -247, -531, 230}, { 147, -82, 569}, { 26, -177, -944}, +{ -27, -273, 692}, { -164, -264, -183}, { 224, 790, 1039}, +{ 899, 946, 601}, { 485, 771, 1150}, { 524, 677, 903}, +{ -140, 375, 778}, { 410, 676, 429}, { 301, 530, 1009}, +{ 719, 646, 38}, { 226, 367, 40}, { 145, -45, -505}, +{ 290, 121, -121}, { 302, 127, 166}, { -124, -383, -956}, +{ -358, -455, -977}, { 715, 878, 894}, { 978, 923, 211}, +{ 477, 272, 64}, { 188, -78, 17}, { -143, -65, 38}, +{ 643, 586, 621}, { -134, -426, -651}, { 347, 545, 2820}, +{ 1188, 2726, 2442}, { 142, -80, 1735}, { 283, 130, 461}, +{ -262, -399,-1145}, { -411, 155, 430}, { 329, 375, 779}, +{ 53, -226, -139}, { -129, -236, 1682}, { 285, 744, 1327}, +{ 738, 697, 1664}, { 312, 409, 266}, { 325, 720, 135}, +{ 1, 221, 453}, { 8, 203, 145}, { 299, 640, 760}, +{ 29, 468, 638}, { 103, 429, 379}, { 420, 954, 932}, +{ 1326, 1210, 1258}, { 704, 1012, 1152}, { -166, -444, -266}, +{ -316, -130, -376}, { 191, 1151, 1904}, { -240, -543,-1260}, +{ -112, 268, 1207}, { 70, 1062, 1583}, { 278, 1360, 1574}, +{ -258, -272, -768}, { 19, 563, 2240}, { -3, -265, 135}, +{ -295, -591, -388}, { 140, 354, -206}, { -260, -504, -795}, +{ -433, -718,-1319}, { 109, 331, 962}, { -429, -87, 652}, +{ -296, 426, 1019}, { -239, 775, 851}, { 489, 1334, 1073}, +{ -334, -332, 25}, { 543, 1206, 1807}, { 326, 61, 727}, +{ 578, 849, 1405}, { -208, -277, 329}, { -152, 64, 669}, +{ -434, -678, -727}, { -454, -71, 251}, { 605, 480, 254}, +{ -482, 11, 996}, { -289, 395, 486}, { 722, 1049, 1440}, +{ -30, -316, -786}, { -106, -115, -619}, { 861, 1474, 1412}, +{ 1055, 1366, 1184}, { 812, 1237, 925}, { 42, -251, -576}, +{ 342, 141, -454}, { -168, -80, 1359}, { -342, -656,-1763}, +{ 100, 821, 725}, { 990, 747, 800}, { 332, 440, 568}, +{ 663, 379, 852}, { 112, 165, -369}, { 597, 910, 282}, +{ -8, 834, 1281}, { -352, 572, 695}, { 462, 2246, 1806}, +{ 345, 190, 1374}, { 416, 915, 2166}, { 168, -82, 280}, +{ -516, -446, 840}, { 47, 533, 44}, { -362, -711,-1143}, +{ 22, 193, 1472}, { -85, 233, 1813}, { -62, 579, 1504}, +{ 550, 944, 1749}, { 723, 650, 1148}, { 972, 884, 1395}, +{ -425, 643, 0}, { 1000, 952, 1098}, { 249, 1446, 672}, +{ -334, -87, 2172}, { -554, 1882, 2672}, { 140, 1826, 1853}, +{ 920, 1749, 2590}, { 1076, 1933, 2038}, { -137, -443,-1555}, +{ 1269, 1174, 468}, { -493, -122, 1521}, { -451, 1033, 1214}, +{ 482, 1695, 1118}, { 815, 649, 384}, { -446, -692, 107}, +{ -319, -605, -118}, { -207, -505, 525}, { -468, -12, 2736}, +{ 75, 1934, 1305}, { 880, 2358, 2267}, { 1285, 1575, 2004}, +{ -48, -304,-1186}, { -435, -461, -251}, { -366, -404, -547}, +{ -289, -605, -597}, { -538, -810, -165}, { -120, 3, 356}, +{ 639, 1241, 1502}, { 96, 177, 750}, { -435, -585,-1174}, +{ -356, 109, -79}, { -485, 288, 2005}, { 9, 1116, 731}, +{ 880, 2134, 946}, { -265, 1585, 1065}, { 1157, 1210, 843}, +{ -498, -668, 431}, { 374, 321, -229}, { 1440, 2101, 1381}, +{ 449, 461, 1155}, { -105, 39, -384}, { -263, 367, 182}, +{ -371, -660, 773}, { -188, 1151, 971}, { 1333, 1632, 1435}, +{ 774, 1267, 1221}, { -482, -832,-1489}, { -237, -210, 860}, +{ 890, 1615, 1064}, { 472, 1062, 1192}, { 185, 1077, 989}, +{ -568, -992,-1704}, { -449, -902,-2043}, { -142, -377, -458}, +{ -210, -554,-1029}, { -11, 1133, 2265}, { -329, -675, -893}, +{ -250, 657, 1187}, { 519, 1510, 1779}, { 520, 539, 1403}, +{ 527, 1421, 1302}, { -563, -871,-1248}, { -147, -463, 879}, +{ -76, 2334, 2840}, { 563, 2573, 2385}, { 632, 1926, 2920}, +{ 719, 2023, 1840}, { -545, -723, 1108}, { 129, -125, 884}, +{ 1417, 1632, 925}, { -94, 1566, 1751}, { -341, 1533, 1551}, +{ 591, 395, -274}, { -76, 981, 2831}, { 153, 2985, 1844}, +{ 1032, 2565, 2749}, { 1508, 2832, 1879}, { 791, 1199, 538}, +{ -190, -453, 1489}, { -278, -548, 1158}, { -245, 1941, 2044}, +{ 1024, 1560, 1650}, { 512, 253, 466}, { -62, -323, 1151}, +{ -473, -376, 507}, { -433, 1380, 2162}, { 899, 1943, 1445}, +{ 134, 704, 440}, { 460, 525, -28}, { -450, 279, 1338}, +{ 0, 971, 252}, { -445, -627, -991}, { -348, -602,-1424}, +{ 398, 712, 1656}, { -107, 314, -178}, { 93, 2226, 2238}, +{ 518, 849, 656}, { -462, -711, -447}, { 174, -34, 1191}, +{ -119, 42, 1005}, { -372, 274, 758}, { 1036, 2352, 1838}, +{ 675, 1724, 1498}, { 430, 1286, 2133}, { -129, -439, 0}, +{ -373, 800, 2144}, { 6, 1587, 2478}, { 478, 596, 2128}, +{ -428, -736, 1505}, { 385, 178, 980}, { 139, 449, 1225}, +{ -526, -842, -982}, { 145, 1554, 1242}, { 623, 1448, 656}, +{ 349, 1016, 1482}, { 31, -280, 415}, { -316, 724, 1641}, +{ 360, 1058, 556}, { -436, -358, 1201}, { -355, 1123, 1939}, +{ 401, 1584, 2248}, { -527,-1012, 355}, { 233, 238, 2233}, +{ -550, -897, -639}, { -365, -501, 1957}, { 389, 1860, 1621}, +{ 162, 1132, 1264}, { -237, 1174, 1390}, { -640, -411, 116}, +{ -228, 1694, 2298}, { 1639, 2186, 2267}, { 562, 1273, 2658}, +{ 323, 338, 1774}, { 578, 1107, 852}, { 22, 594, 934}, +{ -143, 718, 446} +}; + + +static const int16_t lsf_3_2[512][3] = { +{ 50, 71, -9}, { -338, -698,-1407}, { 102, -138, -820}, +{ -310, -469,-1147}, { 414, 67, -267}, { 1060, 814, 1441}, +{ 1548, 1360, 1272}, { 1754, 1895, 1661}, { 2019, 2133, 1820}, +{ 1808, 2318, 1845}, { 644, -93, 454}, { 858, 329, -136}, +{ 489, -258, -128}, { -198, -745, -41}, { -52, -265, -985}, +{ 346, 137, 479}, {-1741, -748, -684}, {-1163,-1725, -367}, +{ -895,-1145, -784}, { -488, -946, -968}, { -85, -390, -725}, +{ 215, -340, -171}, { 1020, 916, 1969}, { 564, 179, 746}, +{ 662, 977, 1734}, { 887, 622, 914}, { 939, 856, 1165}, +{ 309, 688, 803}, { 917, 161, 570}, { 118, -20, -283}, +{ -816, -42, 204}, {-1228, -325, -462}, { -963, -202, -143}, +{ -988, -484, -361}, { -702, -978, -477}, { -302, -790,-1188}, +{ -100, -786,-1088}, {-1054, -947,-1684}, { -202, -843, -782}, +{-1039,-1378, -901}, { -624, -110, -85}, { 356, 213, -10}, +{ -493, 364, 774}, { 425, 822, 479}, { -83, 557, 520}, +{ -992,-1560, -572}, { -603, -741, -26}, { -502, -638, -903}, +{ 209, 306, 147}, { -316, -593, -596}, { -85, -211, -225}, +{ -918, -529, 117}, { 233, -439, -738}, { 1101, 751, 633}, +{ 1457, 1716, 1511}, { 1765, 1457, 910}, { 1122, 1156, 849}, +{ 1354, 868, 470}, { -871,-1150,-1796}, { -871, -861, -992}, +{ -118, 155, 212}, {-1051, -849, -606}, {-1117,-1849,-2750}, +{-1019,-1427,-1869}, { 370, -184, -414}, { 959, 493, 104}, +{ 958, 1039, 543}, { 154, 653, 201}, { 1249, 507, 150}, +{ 663, 503, 230}, { 623, 777, 675}, { 659, 88, -110}, +{ 843, 244, 224}, { 382, 541, 302}, { 724, 433, 666}, +{ 1166, 734, 341}, { -138, 20, -397}, {-1183, -424, -46}, +{ -321, -352, -124}, { 1333, 1021, 1080}, { 262, 366, 723}, +{ 922, 283, -551}, { 31, -636, -611}, { -689, -697, -415}, +{ -952, -779, -201}, {-1329, -598, -359}, { -953,-1285, 166}, +{ 493, 305, 221}, { 846, 703, 610}, { 840, 936, 774}, +{ -723,-1324,-1261}, { -357,-1025,-1388}, {-1096,-1376, -365}, +{-1416,-1881, -608}, {-1798,-1727, -674}, { -545,-1173, -703}, +{ 678, 786, 148}, { -123, 696, 1288}, { 644, 350, -10}, +{ 414, 614, 15}, { 137, 344, -211}, { -814,-1512, -819}, +{ -391, -930, -588}, { 47, -591, -898}, { -909,-1097, -163}, +{-1272,-1167, -157}, {-1464,-1525, -389}, {-1274,-1188, -624}, +{ 671, 213, 454}, { 124, -274, -525}, { -729, -496, -152}, +{-1344, 122, 135}, {-2905, -589, -394}, {-1728, 441, -50}, +{ 1476, 904, 787}, { 316, 236, -440}, { -347, 217, 413}, +{ -911, -917, 121}, { -455, -932, 202}, { -92, -465, -375}, +{ 488, 390, 474}, { 876, 729, 316}, {-1815,-1312, -669}, +{ 87, 962, 432}, { 563, -249,-1058}, { 250, 285, 1105}, +{ 1141, 427, 696}, {-1038,-1664,-1582}, { -948, 346, 160}, +{ -309, -272, -858}, { 670, 624, 1250}, { -944, -408, -666}, +{ -606, -320, -384}, { -492, 230, 65}, { 334, -50, -16}, +{ -16, -690,-1397}, { 1791, 1716, 1399}, { 2478, 2063, 1404}, +{ 1245, 1471, 1426}, { -382,-1037, -2}, { 173, -398, 1145}, +{ 1491, 2024, 1801}, { 772, 1274, 1506}, { 1429, 1735, 2001}, +{ 1079, 1218, 1273}, {-1154,-1851,-1329}, { -808,-1133,-1096}, +{ -451,-1033,-1722}, { 65, 578, -84}, {-1476,-2434,-1778}, +{ -765,-1366, -494}, { -218, -594, -931}, { 337, -236, 562}, +{ 2357, 2662, 1938}, { 1489, 1276, 874}, { 189, 358, 374}, +{-1519,-2281,-2346}, { -967,-1271,-2095}, { -628,-1188,-1542}, +{ 1661, 1043, 546}, { 565, 1061, 732}, { -64, -836, -434}, +{ -436, -96, 203}, { 1078, 1216, 1636}, { 907, 1534, 986}, +{ 326, 965, 845}, { 142, -84, 197}, { 470, 2379, 1570}, +{ 1133, 470, 1214}, { 395, 1376, 1200}, { 1125, 1042, 348}, +{ -543,-1234, -376}, { -215, -181, 481}, {-1947,-1621, -210}, +{ -750,-1185, 390}, { 29, -399, 27}, { 820, 1236, 755}, +{ 695, 979, 409}, { -174, 1197, 1035}, { 912, 1356, 1846}, +{ -992,-1437, 484}, {-1485,-1700, 208}, { -412, 1204, 1432}, +{ -271, 896, 1144}, { -416, 1777, 1434}, {-1696,-2644, -204}, +{-1789,-1551, 1033}, {-1656,-1559, 1303}, {-1253,-1589, 1081}, +{ -669,-1095, -66}, { -682, 320, -345}, { 659, 305, 1069}, +{-1292, -804, -19}, {-1635,-1291, 29}, {-1683, -497, 71}, +{ -287, -7, -100}, { -494, -962, -237}, { 852, 1881, 1740}, +{-1217,-1387, 227}, { -660, 302, 373}, { 96, 1087, 1257}, +{-1074,-1669, 160}, { 485, 2076, 1798}, { -934, -220, 552}, +{ -596, -612, 237}, { 336, 1720, 879}, { 643, 629, 434}, +{ 1267, 522, 1633}, { 15, 244, -441}, { 1475, 717, 184}, +{ 1819, 1590, 1709}, { 988, 261, 937}, { 2093, 2345, 1520}, +{ 2139, 1858, 1606}, { -577, -579,-1203}, { -956, 135, -488}, +{ -464, 51, -338}, { -629, -348, -723}, { 1146, 2073, 1442}, +{ 2192, 1466, 911}, {-1444,-1572,-2278}, { 1400, 710, 1297}, +{ 1335, 633, 928}, { 1434, 2194, 2594}, { 2422, 2204, 1881}, +{ 982, 2242, 1854}, { 380, 792, 1145}, { -63, -539, 414}, +{ -252, -964, -314}, {-1261, -683, -780}, { -831, -526,-1005}, +{-1666,-1135, -424}, {-1611, -452, -299}, { 1268, 1048, 642}, +{ 1147, 853, 856}, { -675, -336, 139}, { 2268, 1343, 1418}, +{ 29, 768, 797}, {-1224, 423, 564}, {-1318,-1082, 245}, +{-1302, -812, 573}, {-1298,-1617, 646}, { -968, 834, 723}, +{ 993, 1652, 2027}, { -191, -817, 432}, { 662, 60, 198}, +{ 626, 997, 1330}, { 1648, 1963, 1289}, {-1597, -93, -45}, +{-1088, 37, -84}, { 1653, 2607, 2337}, { 1065, 2040, 2377}, +{ 1139, 2326, 2118}, { 859, 357, 1510}, { 664, 1227, 1099}, +{ 479, 1360, 912}, { 1897, 1754, 2019}, { 1168, 1909, 1784}, +{ 399, 34, 256}, { -593, -304,-1053}, { 547, 1694, 1407}, +{ 647, -99, -341}, { 1492, 1647, 1190}, { 38, -644, -212}, +{ 395, 846, 222}, { -704, -765, -716}, { -724,-1964,-2804}, +{ -150, 291, -82}, { 1233, 1459, 1007}, { -140, -155, 153}, +{ 439, 297, 1568}, {-1529, -410, -636}, { 1536, 455, -237}, +{-1328, -139, -260}, { 531, 554, 868}, { 269, 1264, 606}, +{ -233, 883, 463}, { 742, 600, -120}, { -73, 421, 212}, +{ -439, -58, 804}, {-1286,-1241, 728}, { 294, -490, 50}, +{ -591, -905,-1254}, { 42, -687, 147}, { -25, 273, 596}, +{ -311, 1213, 601}, { -754, 849, 584}, { 429, 607, 587}, +{ -602, -166, 461}, { -796, -823, 777}, { 1380, 910, 1755}, +{ 119, 1417, 972}, { -219, -880,-1596}, {-1049,-1010, 438}, +{ -713,-1379, 78}, { 0, -447,-1179}, {-1136,-1319,-1573}, +{ 2248, 1767, 1309}, { 946, 1583, 1432}, { 1150, 482, 436}, +{ -469,-1108, 618}, { -447, -966, 1088}, {-1252,-1515, -114}, +{-1104,-2008, -579}, { 210, 613, 497}, {-1975,-1437, 642}, +{-1269, -856, 1011}, {-1646,-1185, 1063}, {-1555, -672, 1204}, +{-1692,-1114, 623}, { -979,-1326,-1277}, { 539, -147, 894}, +{-1354, -897, -434}, { 888, 475, 428}, { 153, -384, 338}, +{-1492, -511, 359}, { -974,-1115, -470}, { 105, -550, 677}, +{ -937,-1145, 877}, { 380, -260, 210}, { 1685, 924, 1256}, +{ 1775, 1190, 1095}, { 1419, 631, 533}, { 627, 299, -347}, +{ -411, -534, 647}, { -650, 29, -595}, { -378,-1367, 1563}, +{ 1402, 1121, 1465}, { 1089, 1410, 648}, {-2096,-1090, -6}, +{ 311, -194, -869}, { -639, -831, 416}, {-1162,-1224, 1349}, +{-1247, -941, 1813}, {-2193,-1987, 453}, { -619,-1367, -956}, +{-1606,-1972,-1507}, {-1175,-1057,-1104}, { -377, 601, 201}, +{ 1876, 825, 374}, { -430,-1323, 29}, {-1397,-1249,-1331}, +{-1007,-1504, 960}, {-1401,-2009, 197}, {-1379,-1949, -236}, +{-1077, 123, 422}, { 615, 1269, 546}, { -306, 1526, 904}, +{ 1194, 1788, 1177}, { -626, -884,-1526}, { 199, 766, 1504}, +{-1065, 862, 197}, {-1034,-1773, -887}, { -800, 145, 599}, +{-1134, -519, 626}, {-1205,-1926, 500}, { -910,-1041,-1395}, +{-1476,-1567, -969}, { -523, 842, 34}, { 1794, 646, 862}, +{-1207,-1888,-1002}, { -78, -9, -672}, { 1044, 759, 80}, +{ -600, 1139, 1019}, { 57, 2000, 1422}, { -833, 1414, 1121}, +{-1202, 1630, 1260}, { -461, 1420, 1244}, { 1537, 975, 253}, +{ -283, 324, -359}, { 599, -195, 106}, { 588, 62, -587}, +{ -757, 645, 205}, { 51, 1201, 758}, {-1209, 673, -390}, +{ -624, 1581, 941}, { -151, 1023, 735}, { 2820, 1301, 690}, +{ -302, 524, -99}, { -900,-1588,-1189}, { 1084, 251, 238}, +{ 2014, 1792, 1010}, { 1245, 1633, 1741}, {-1227,-1540,-1208}, +{ -621, 456, -109}, { 40, -65, 788}, { -805, -699,-1350}, +{ -583, 904, 832}, { -801, 532, 594}, { 1972, 1408, 1351}, +{-1177,-1880,-2114}, { -773, 568, 948}, {-1015, 1079, 1260}, +{-1111, 482, -130}, { 1778, 1044, 780}, {-1491, 245, 912}, +{ -316,-1141, -917}, { -536,-1442,-2346}, { -785,-1546,-1988}, +{-2003, 257, 909}, {-1849, -633,-1209}, {-1538,-1918,-1054}, +{ 1606, 2239, 1576}, { -567,-1500,-1544}, {-1279, 195, 1369}, +{ -817, 293, 1219}, { -525, 630, 1197}, {-1698,-2425,-1840}, +{ -303, 731, 747}, {-1169, -251, 269}, { -950, -75, 1684}, +{-1182, -453, 1005}, {-1599, 585, 378}, {-2075, -571, -427}, +{ -529,-1159,-1171}, { -283, -205, -564}, { -796, 1246, 717}, +{ 2277, 927, 539}, { -454, 559, 440}, { -717, 1460, 1615}, +{-1030, 1052, 1610}, {-1169, -138, 847}, { 226, 39, -612}, +{-1251, -106, -729}, { -651, 968, 1302}, { -714, -636, 1727}, +{ 353, 1069, 410}, { -798, -156, 1099}, { -574, 918, 446}, +{-1310, 1012, 466}, { 1408, 1591, 765}, { 1429, 1380, 1757}, +{ 1949, 1956, 2378}, { 1578, 2047, 2148}, { 916, 98, -7}, +{ 1893, 1418, 2141}, { 348, 1405, 1579}, { 152, 1134, 1801}, +{ -267, 154, 1395}, {-1166, 469, 1054}, {-1142, -405,-1073}, +{-1341,-2264,-1581}, { -364, 869, 1706}, {-1162, 549, 1550}, +{-1225,-1932,-1666}, {-1485,-1977,-2055}, {-1727, -906, -98}, +{-1897, 233, 1492}, { 892, 108, -331}, {-1728,-1170,-1700}, +{-1060, 1980, 1790}, {-1070,-1741,-1909}, { -11, 1539, 1317}, +{-1600, 94, 497}, { 421, 443, -197}, {-1578, -349, -994}, +{ -599, -539, 1140}, { -965,-1419, -129}, {-1341, 175, -447}, +{ -375, 1311, 2055}, { -371, -650, -307}, {-1073, 605, 365}, +{-2057, -113, 430}, { 652, 914, 967}, {-1012,-1586,-2323}, +{ 1505, 1248, 559}, { 262, -486, -401}, {-1727, 1342, 1546}, +{ 50, 56, 432}, { -330, 119, -604}, {-1517,-1080, -810}, +{ 946, 1127, 1055}, {-1400,-1703,-1712}, {-1270, -704,-1317}, +{ 807, 1821, 1143}, { 2760, 1606, 2171}, { 1120, 409, -150}, +{ -147, 404, 959}, { 2439, 1911, 2189}, { -906, -141, -866}, +{ -904, -142, -458}, { -557, -708,-1679}, { -830,-1431,-1583}, +{-1842,-1346,-1086}, {-1604, -272, 915}, {-1196, 772, 1056}, +{ -638,-1234,-1897}, { -500, -81, -822}, {-1289,-1613, -735}, +{ -117, 785, 168}, {-1090, 1133, 922}, {-1096, -746, 1384}, +{ 287, -547,-1063}, {-1376,-2201,-1204}, {-2176,-1570,-1757}, +{-1511,-2241, -771}, {-1737, 1099, 830}, {-1588, 724, 1243}, +{-1542, 693, 805}, {-1690, -240, 1665}, {-1700, -4, -668}, +{ 2149, 816, 1042}, { -818,-1841, 22}, { -764, -507, 449}, +{-1151, -617, 289}, { -843,-1596, -240}, { 498, -234, -657}, +{ -752, 480, 1678}, { -319, -481, 193}, { -811, 171, -119}, +{-2128, -202, -848}, { 1717, 1140, 1700} +}; + +static const int16_t lsf_3_3[512][4] = { +{ 67, -17, 66, -12}, {-1690, -581, -104, -272}, {-1076,-1186,-1845, -376}, +{-1140, -926, -420, -58}, { -259, -656,-1134, -553}, { 1788, 1227, 455, 129}, +{ 462, 441, -240, -528}, { 840, 514, 130, -75}, { 1114, 623, 153, 216}, +{ 1068, 564, -6, -276}, { 1119, 727, 190, -68}, { 704, 306, 119, -264}, +{ 329, 61, -100, 156}, { 364, 123, 183, -208}, { -171, -123, 220, -65}, +{ -306, -62, 402, 17}, { -660, -938, -266, 0}, { 385, 235, 276, 285}, +{ 320, 268, -336, -200}, { -724, 17, -84, 381}, { -544, 429, 494, 519}, +{ -117, 288, 304, 329}, { 643, 157, 701, 508}, { 1200, 625, 796, 608}, +{ 998, 421, 492, 632}, { 1204, 780, 446, 132}, { 1257, 844, 547, 449}, +{ 829, 658, 541, 470}, { 1132, 1258, 918, 639}, { 547, 51, 423, 279}, +{ 9, 392, 83, 94}, { 542, 543, 229, -147}, { -198, 129, 194, -185}, +{ -863,-1321, -302, 30}, { -597, -629, -19, 114}, { -900,-1081, 466, 353}, +{-1483,-1573, 15, -143}, {-1708,-2059, -751, 196}, {-1876,-2067, -642, -258}, +{-2335,-1470, -450, -564}, { -584, -186, -872, -414}, {-1805, -988,-1125,-1310}, +{ -726,-1129, 28, 169}, {-1039, -864, -718, -246}, { 484, 36, -233, -49}, +{ 265, 67, 289, 467}, { 178, 543, 810, 540}, { 84, 282, 672, 703}, +{ -975, -777, 129, 287}, { -938, -227, 955, 595}, {-1617, -289, 836, 649}, +{-1847, -215, 1106, 718}, {-2034,-1085, 650, 440}, {-2101, -529, 907, 575}, +{-2011, -336, 670, 204}, {-2389, -692, 360, 137}, {-2156,-2204, -9, 280}, +{ -266, 119, 39, 193}, { 78, -59, -120, 226}, { -975, -858, -781,-1095}, +{ -619, -413, -451, -842}, {-1216,-1321, -813, -883}, {-1376,-1615, -394, -428}, +{ -737,-1113, -549, -790}, { -880, -975, -967, -642}, { -985, -886,-1273,-1361}, +{ -473, -804,-1401,-1407}, { 160, -265, -919, -275}, { -248, -250, -718, -380}, +{ 97, -103, -375, -229}, { -415, -193, -135, -555}, { 628, 361, 119, 216}, +{ 579, 364, 391, 209}, { 634, 522, -154, -148}, { 526, 389, 170, 33}, +{ 105, 267, 64, 380}, {-1503,-1000, -30, -369}, {-1070, 58, 647, 223}, +{-1520, -291, 621, 307}, {-1531, 156, 762, 404}, {-2029, 141, 734, 499}, +{-1849, -650, 306, 512}, { -187, -104, -59, 438}, { 134, -230, 156, -186}, +{ -61, -260, -16, 10}, { -569, -3, -421, -297}, {-1725, -521, -346, 178}, +{-1362, -59, -44, 157}, {-2146, -461, -470, -349}, {-2170, -1, -369, -121}, +{-1579, -373, -900,-1015}, {-1117, -591, -613, -784}, { -561, 122, -75, -449}, +{ -4, -171, -123, -372}, { 192, 168, -76, -132}, { 252, -107, 340, 210}, +{ 392, 509, 272, 181}, { -109, 145, 218, 119}, { -416, -263, 485, 265}, +{ -181, -8, -286, 226}, { -244, -218, 69, -290}, { -158, 191, -1, -64}, +{ -592, -90, 213, -96}, { 255, 435, 178, -80}, { -369, -18, -33, -80}, +{ -42, 415, 140, -222}, { 1143, 651, 649, 329}, { 767, 556, 249, 235}, +{ 948, 413, 442, 279}, { 141, 339, 356, 557}, { -470, -170, 99, 237}, +{ -569, -800, 352, 565}, { 282, 473, 470, 332}, { -199, -690,-1284, -917}, +{ -193, -426, -800,-1122}, { -26, -371, -490, -193}, { 637, 595, 519, 330}, +{ 408, -115, 79, 12}, { 477, 87, -103, -376}, { -666, -347, -277, -291}, +{ -510, -481, 169, 297}, { -829, -738, -205, -171}, { -320, -540, 328, 283}, +{ -859, -958, 442, -2}, { 556, 686, 130, 56}, { 1383, 1012, 755, 427}, +{ 612, 741, 628, 553}, { -339, -796, 134, 277}, { -633,-1085, -2, -246}, +{ -880,-1035,-1607,-1064}, { -994, -474,-1138, -488}, { -414, -795, 73, -206}, +{ -8, -139, 439, 204}, { -176, -578, 23, 131}, { -269, -757, -191, 245}, +{ -109, -338, 112, 316}, { 120, -406, -118, 611}, { -180, -186, -645, 115}, +{ -173, 34, -518, -489}, { -151, 61, -583, -844}, { 220, -138, -681,-1020}, +{ 391, -17, -598, -321}, { 157, -295, 129, 155}, { -926, -875, -987, 285}, +{ 241, -83, -125, -125}, { 620, 597, 432, 92}, { 393, 78, 409, 61}, +{ -393, -739, -413, -748}, { 83, 54, 361, 27}, {-1084, 130, -337, -694}, +{-1565, 297, 318, -19}, {-1873, 36, 51, -317}, {-2323, -246, 231, -84}, +{-2306, -783, 40, -179}, {-2233, -930, -474, -462}, { -754, -86, -288, -626}, +{-2411, -455, -63, 171}, {-1099,-1094, -26, -143}, {-1193, -455, -406, -381}, +{ -605, -210, -96, -51}, { -580, -476, -276, -15}, {-1195, -634,-1203, -881}, +{ -378, -221, -669, -952}, { 594, 178, -403, -676}, { 763, 327, 601, 290}, +{ 172, 300, 203, 157}, { -56, -336, 356, 24}, { -228, -296, -259, -29}, +{ -186, 263, 416, 14}, { -353, 373, -12, -216}, { 257, 96, 174, 57}, +{-1526, -616, -954, -499}, { -497, -152, -333, 125}, { 105, 200, 179, -97}, +{ -331, -224, 765, 697}, { 760, 256, 301, 59}, { 455, -85, 204, 288}, +{ -514, 240, 251, -109}, { 256, 417, -34, -413}, { 101, 430, 384, 156}, +{ -31, -10, 206, 426}, { 589, 145, 143, 71}, { 808, 906, 333, 349}, +{ 986, 938, 589, 331}, { 1300, 824, 187, 509}, { 1062, 653, 379, 466}, +{ 1462, 937, 401, 274}, { 787, 861, 265, 2}, { 609, 553, 28, 305}, +{ 926, 340, 106, 386}, { 241, -267, -147, 225}, { -178, -534, 347, 502}, +{ -643, -381, 397, 30}, { -651, -733, -435, 398}, { -407, -726, -484, -248}, +{ -789, -914, -438, -476}, { -498, -390, 75, -295}, { -964, -590, -606, 150}, +{ -121, -49, -155, -78}, { 935, 550, 389, 38}, { -321, 127, 424, 315}, +{ -285, -113, 283, 259}, { 658, 203, 322, 486}, { 903, 505, 748, 417}, +{ 611, 423, 555, 512}, { 239, -83, -578, -19}, { -339, -731, 349, 13}, +{ -934,-1399, -114, -360}, { 107, 692, 182, 90}, {-1243,-1538,-1551, -725}, +{ -568, -903,-1363, -525}, { -517, -853, -861,-1004}, { -168, -690, -835, 63}, +{ -137, -556, -547, 144}, { -286, -817, 485, 319}, { -147, -408, 526, 246}, +{ -347, -434, 297, -28}, { -290, -471,-1110,-1285}, { -460, -359, -988, -794}, +{ 1347, 1299, 690, 523}, { 1216, 1068, 1094, 757}, { 825, 1140, 752, 494}, +{ 1252, 1365, 1195, 898}, { 521, 1053, 532, 432}, { -334, -216, -313, -263}, +{ -160, 52, -472, -155}, { 127, 136, -380, 44}, { 851, 410, -162, -489}, +{ 123, -255, -796, -667}, { 1090, 917, 789, 493}, { 1397, 1197, 558, 202}, +{ -51, -118, -342, -701}, { 83, 108, -42, -441}, { 61, 95, 287, 256}, +{ -27, 89, 524, 531}, { 351, 227, 592, 545}, { 697, 155, -164, 307}, +{ 638, 274, -489, -50}, { 754, 240, -166, -124}, { -116, -579,-1212, -63}, +{ 190, -295,-1040,-1296}, { 147, -376, -177, -113}, { 841, 1241, 1051, 668}, +{ 2, 293, 551, 304}, {-1096, -953, -248, 376}, { -750, -965, 87, 516}, +{ -275, -516, 689, 391}, { -379, -643, 876, 594}, { -390,-1013, -645, 573}, +{ -107, -568, -689, -826}, {-1025, -27, -328, -203}, { 861, 749, 548, 233}, +{-1660,-1043, 451, 108}, { -660, -620, 430, 236}, { 21, -396,-1158, -631}, +{ 1372, 1298, 967, 577}, { 1125, 1125, 589, 454}, { -323, -865, -467, 153}, +{ -468, -699, -804, -509}, { -392, -718, -204, -35}, { -603,-1093, -567, -162}, +{ -505,-1004, -102, 350}, { 219, 224, 423, 252}, { 395, 591, 608, 363}, +{ -746, -96, 373, 172}, { 171, 295, 714, 339}, { 233, 77, 107, 277}, +{ 157, 153, -499, -356}, { 1547, 1073, 576, 494}, { -292, -339, -504, -592}, +{ -903, -72, -619, -481}, {-1594,-1117, -567, -254}, { -793, -507, -564, -291}, +{ -492, -532, 502, 560}, { -382, 427, 600, 230}, { -227, 477, 251, 75}, +{ 285, 842, 813, 476}, {-1310,-1333, 186, 377}, { -587, -917, 643, 381}, +{-1186, -553, 411, 82}, {-1127, -820, -174, -540}, { -604, 119, 543, 205}, +{ -380, 657, 909, 567}, { 112, -298, -374, 114}, { -857, -251, 56, 159}, +{ 401, 345, -34, -140}, { -111, -607, 41, 614}, { 355, -114, -77, 474}, +{ 578, 56, 1450, 924}, { 1098, 1420, 741, 400}, { 246, 22, 588, 313}, +{ -121, 327, 831, 472}, {-1138, -608, 856, 552}, {-1241,-1072, 638, 600}, +{ -358, 254, -333, -303}, { -646, 739, 358, 74}, { 1226, 1671, 1221, 849}, +{ 2241, 1624, 983, 636}, { 1841, 1477, 749, 384}, { 350, 263, 87, 128}, +{-1902, -941, -144, -64}, {-1734, -255, 288, -31}, {-2644,-1238, 366, 235}, +{-1643,-1092,-1344, -304}, { -541,-1075,-1116, 123}, {-1178, -252, -816, -180}, +{-1016, 533, 565, 233}, { -487, -430, -188, 334}, { 867, 1236, 534, 171}, +{-1590,-1607, 635, 630}, {-2196, 310, 924, 412}, {-2358, -328, 956, 529}, +{-2639, -377, 630, 278}, {-2602, 317, 799, 299}, {-2406, 133, 340, 31}, +{-2156,-1468, 131, 125}, {-1184, -490, -139, 46}, { -744, 447, 891, 564}, +{ 67, -451, 646, 604}, { -553, -429, -876, 396}, { 162, -66, 1305, 915}, +{ 479, 579, 1088, 794}, { 450, 278, 566, 324}, {-1057, -154, 148, -177}, +{-2545, 168, 1070, 592}, {-2351, -42, 819, 345}, {-2344, -707, 721, 250}, +{-2175,-1497, -309, 122}, { -78, -73, 120, 173}, { -4, 262, -263, -261}, +{ -431, -64, -405, -732}, {-2609, 116, -83, -193}, {-1525, -944, -477, -725}, +{ -508, 307, 170, 172}, { 832, 417, 832, 686}, { -225, 177, 894, 818}, +{ -482, -389, 1279, 1039}, { -383, 201, -350, 40}, { 730, 635, 226, 526}, +{ 503, 462, 338, 398}, { 535, 714, 40, -282}, { 1482, 1471, 1085, 731}, +{ 1561, 1072, 909, 693}, { 1419, 1282, 889, 879}, { 1153, 728, 1186, 840}, +{ -226, 1130, 949, 689}, { -494, -986,-1556, -128}, { -568, -721, -713, -26}, +{ 317, 524, 70, 135}, { -405, -865,-1766, -652}, { -174, -801, 885, 773}, +{ -153, -91, 1099, 751}, { -506,-1149, 853, 646}, { 241, 782, 519, 539}, +{ 1853, 1700, 1101, 684}, {-1249,-1486, -464, 188}, { -893,-1409,-1312, -341}, +{ -135, 438, -175, 18}, { 1111, 976, 319, 208}, {-1430,-1768, 83, 458}, +{ -530,-1000, 307, 129}, { -840, -15, -29, -356}, { -911, -924,-1147, -242}, +{ -119, -528, 127, -133}, { -761, -765, 190, -83}, { -315, 895, 522, 231}, +{ -222, 102, -63, -428}, { 316, 699, 379, 70}, { 25, 716, 314, -108}, +{ 507, 874, 566, 238}, { 108, 941, 519, 195}, { 425, -60, -427, 257}, +{ 139, -103, -630, 446}, { 334, 370, 412, 48}, { -172, -690, -283, 557}, +{ 187, -286, 158, 483}, { 140, 270, -344, -631}, { 924, 579, -116, 132}, +{ 142, 466, -68, -64}, { 230, -145, -302, -542}, { -803, -912, 1018, 737}, +{ -773, 1015, 630, 297}, {-2596, 95, 445, 336}, {-2122, 491, 510, 191}, +{-1253, 161, -2, -324}, {-1450, -633, -712, -105}, { -842, -254, -411, 100}, +{ -640, -290, 1010, 763}, { -650, 313, 1169, 730}, { 140, 505, 1030, 766}, +{ 772, 287, 1067, 823}, { 495, 749, 305, 323}, { -164, 462, 78, 399}, +{ -342, -874, 69, 597}, { -16, 620, 621, 337}, { -138, -444, -265, 218}, +{ 84, -450, 953, 666}, { -222, -803, 541, 604}, { -921,-1376, 244, 116}, +{ -841, -723, 630, 588}, { 140, 663, 294, 368}, { 935, 1046, 881, 759}, +{ 1746, 1464, 916, 628}, { 436, 963, 281, 1}, { -119, 74, 542, 213}, +{ 1, -567, 301, 241}, { 260, 435, 222, 396}, { 936, 957, 1108, 703}, +{ 510, 506, 808, 478}, { 601, 694, 960, 620}, { 972, 741, 980, 600}, +{ 834, 717, 767, 684}, { 643, 972, 935, 638}, { 501, 661, 720, 851}, +{ -105, -632, -303, -117}, { -429, 130, 789, 442}, { -522, -188, 704, 373}, +{ -759, 42, 814, 523}, { -531,-1137, 373, 578}, { -682,-1203, -455, 285}, +{-1163,-1577,-1098, 44}, { 81, -82, 712, 363}, { 477, 246, 954, 622}, +{ 1604, 1622, 1277, 891}, { 1409, 859, 924, 892}, { 774, 1041, 947, 1142}, +{ 40, -546, -75, 288}, { -616, -106, -697, -26}, { -169, -160, -891, -739}, +{ -279, -384,-1029, -350}, { 1781, 1308, 1046, 816}, { 1580, 1533, 1472, 1178}, +{ 1505, 1076, 1216, 899}, { 890, 904, 564, 654}, { 920, 692, 1021, 856}, +{ -493, 132, 177, 505}, { 71, 195, -28, 97}, { 456, 351, -164, 88}, +{ 439, 278, -40, 350}, { 1395, 949, 234, -95}, { -805, -472, 38, -163}, +{ 367, -98, 489, 523}, { 1025, 1178, 1212, 906}, { 319, 1314, 814, 461}, +{ -123, -543, -804, 447}, { -748, -324, -897,-1127}, { -737, -501, -789, -713}, +{ 715, 777, 1239, 922}, { 1949, 1939, 1368, 865}, { 730, 880, 758, 388}, +{ -871, 454, 17, -251}, { -381, -810,-1583, 239}, { -521, -966, -792, 259}, +{ -890,-1358, -770, -73}, { 166, 349, -212, 323}, { -840, -301, 473, 435}, +{ -679, -464, 728, 351}, { -156, -199, 667, 432}, { 29, -252, 415, 480}, +{ -731, -379, 145, 559}, { -528, -631,-1158, -159}, { 445, 273, 123, 639}, +{ 373, -126, 800, 568}, { 84, -162, 720, 712}, { -830, -536, -185, 222}, +{ 408, 452, 501, 771}, { -897,-1355, -67, 442}, { -792,-1406, 566, 602}, +{ 167, -326, 509, 330}, { -95, -626, -730, -344}, { 1668, 1217, 779, 455}, +{ 1316, 828, 584, 719}, { 404, -31, 1013, 789}, { 89, 107, 891, 549}, +{ 871, 1581, 917, 671}, { 866, 1479, 1289, 854}, { 391, 1068, 1122, 812}, +{ 78, -562, 345, 563}, { 429, -103, 417, 787}, { -122, -437, 411, 788}, +{ -913, -417, 602, 754}, { -226, -16, 151, 760}, { -700, 118, -104, -14}, +{-1128, 48, 284, 393}, { -390, -419, -639, -116}, { -910, 306, 316, -13}, +{ 1207, 984, 821, 669}, {-1195, -693, 140, -213}, { -884, -416, -199, -558}, +{ -616, 245, -404, -664}, { 262, 56, -617, -724}, { -85, -491, -320, -656}, +{ -570, -831, -129, -528}, {-1506, -63, -367, -385}, { -358, -321, 4, 51}, +{ -366, -214, 319, 511}, { 146, 671, -17, -291}, { -110, 464, -139, -496}, +{ -202, 220, -312, -631}, { -660, -73, -655, -820}, { -662, -653,-1288, -857}, +{ -430, -953, -959, -264}, { -49, -468, -72, -381}, { -350, -563, -193, -407}, +{ 55, -408, -803, 11}, { -309, 649, 188, -198}, { -512, 461, -79, -458}, +{-1318, -263, -134, -523}, {-1657, -435, -495, -765}, { 57, -347, -414, 434}, +{-1141, -242, -664, -857}, { 34, -68, -707, -338} +}; + +static const int16_t lsf_5_1[128][4] = { +{ -451,-1065, -529,-1305}, { -450, -756, -497, -863}, { -384, -619, -413, -669}, +{ -317, -538, -331, -556}, { -414, -508, -424, -378}, { -274, -324, -434, -614}, +{ -226, -500, -232, -514}, { -263, -377, -298, -410}, { -151, -710, -174, -818}, +{ -149, -412, -156, -429}, { -288, -462, -186, -203}, { -170, -302, -191, -321}, +{ -131, -147, -297, -395}, { -228, -214, -245, -192}, { -67, -316, -71, -327}, +{ -104, -205, -94, -183}, { -143, -38, -193, -95}, { 16, -76, -124, -248}, +{ 23, -237, 24, -244}, { 18, -136, 44, -111}, { -33, -24, -25, 0}, +{ 149, 19, 23, -143}, { 158, -169, 174, -181}, { 133, -55, 165, -26}, +{ 111, 84, 98, 75}, { 87, 183, -115, -11}, { -8, 130, 11, 170}, +{ 254, 77, 205, 17}, { 183, 112, 262, 194}, { 202, 287, 95, 189}, +{ -42, -105, 234, 179}, { 39, 186, 163, 345}, { 332, 199, 299, 161}, +{ -54, 285, -78, 281}, { -133, 141, -182, 111}, { 249, 341, 271, 364}, +{ 93, 403, 75, 391}, { 92, 510, -138, 220}, { -185, -29, -34, 361}, +{ -115, 320, 3, 554}, { 99, 286, 218, 591}, { -245, 406, -268, 453}, +{ 0, 580, 25, 606}, { 275, 532, 148, 450}, { -73, 739, -285, 518}, +{ -288, 94, -203, 674}, { -140, -74, 205, 714}, { -114, 299, 176, 923}, +{ 182, 557, 240, 705}, { -16, 513, 485, 593}, { 293, 384, 451, 617}, +{ -38, 50, 563, 529}, { 303, 209, 459, 363}, { 433, 452, 450, 454}, +{ 367, 606, 477, 741}, { 432, 353, 368, 267}, { 361, 716, 273, 583}, +{ 453, 166, 510, 172}, { 201, 629, 274, 191}, { 568, 639, 302, 298}, +{ 634, 387, 643, 350}, { 587, 560, 612, 565}, { 600, 788, 487, 672}, +{ 512, 1015, 321, 333}, { 357, 854, -125, 413}, { 474, 712, 17, -151}, +{ 564, 285, 270, -241}, { 971, 889, 489, 220}, { 510, 896, 549, 924}, +{ 327, 825, 290, 911}, { 540, 1108, 158, 805}, { 199, 957, 511, 730}, +{ 100, 874, 13, 791}, { 435, 632, 676, 972}, { 249, 900, 467, 1218}, +{ 781, 1074, 585, 785}, { -23, 669, 267, 1043}, { 619, 1084, 615, 1145}, +{ 622, 905, 916, 1049}, { 80, 331, 584, 1075}, { 89, 639, 988, 961}, +{ 770, 720, 798, 699}, { 492, 447, 899, 627}, { 271, 1188, 725, 1333}, +{ 87, 603, 832, 1603}, { 616, 1127, 890, 1505}, { 1000, 1156, 866, 1009}, +{ 995, 827, 1149, 858}, { 817, 1450, 773, 1320}, { 500, 1389, 312, 1153}, +{ -20, 1084, 64, 1283}, { 2, 1172, 399, 1869}, { 514, 1706, 502, 1636}, +{ 886, 1522, 416, 600}, { 1131, 1350, 1275, 1390}, { 889, 1795, 914, 1766}, +{ 227, 1183, 1250, 1826}, { 505, 1854, 919, 2353}, { -199, 431, 152, 1735}, +{ -213, -28, 392, 1334}, { -153, -52, 978, 1151}, { -323, -400, 813, 1703}, +{ -136, 84, 1449, 2015}, { -331, -143, -137, 1192}, { -256, 534, -157, 1031}, +{ -307, -439, 542, 731}, { -329, -420, -97, 616}, { -362, -168, -322, 366}, +{ -247, -110, -211, 89}, { -196, -309, 20, 59}, { -364, -463, -286, 89}, +{ -336, 175, -432, 141}, { -379, -190, -434, -196}, { -79, 150, -278, -227}, +{ -280, 166, -555, -422}, { -155, 541, -366, 54}, { -29, -83, -301, -774}, +{ 186, 628, -397, -264}, { 242, 293, -197, -585}, { 124, 410, 53, -133}, +{ 10, 340, -570,-1065}, { 65, -446, 68, -493}, { 383, 937, -357, -711}, +{ -359, -250, -677,-1068}, { 292, -26, 363, 6}, { 607, 1313, -127, -10}, +{ 1513, 1886, 713, 972}, { 1469, 2181, 1443, 2016} +}; + +static const int16_t lsf_5_2[256][4] = { +{-1631,-1600,-1796,-2290}, {-1027,-1770,-1100,-2025}, {-1277,-1388,-1367,-1534}, +{ -947,-1461, -972,-1524}, { -999,-1222,-1020,-1172}, { -815, -987, -992,-1371}, +{-1216,-1006,-1289,-1094}, { -744,-1268, -755,-1293}, { -862, -923, -905, -984}, +{ -678,-1051, -685,-1050}, {-1087, -985,-1062, -679}, { -989, -641,-1127, -976}, +{ -762, -654, -890, -806}, { -833,-1091, -706, -629}, { -621, -806, -640, -812}, +{ -775, -634, -779, -543}, { -996, -565,-1075, -580}, { -546, -611, -572, -619}, +{ -760, -290, -879, -526}, { -823, -462, -795, -253}, { -553, -415, -589, -439}, +{ -533, -340, -692, -935}, { -505, -772, -702,-1131}, { -263, -306, -971, -483}, +{ -445, -74, -555, -548}, { -614, -129, -693, -234}, { -396, -246, -475, -250}, +{ -265, -404, -376, -514}, { -417, -510, -300, -313}, { -334, -664, -463, -814}, +{ -386, -704, -337, -615}, { -234, -201, -233, -239}, { -167, -567, -203, -619}, +{ -147, -415, -115, -352}, { -166, -750, -171, -761}, { -270, -879, -264, -903}, +{ -367, -744, 43, -475}, { 14, -653, 43, -670}, { 11, -448, -59, -521}, +{ -126, -119, -155, -613}, { -42, -863, -27, -931}, { 136, -483, 183, -468}, +{ 55, -298, 55, -304}, { 313, -609, 313, -720}, { 322, -167, 100, -541}, +{ -3, -119, -111, -187}, { 233, -236, 260, -234}, { 26, -165, 134, -45}, +{ -40, -549, 360, -203}, { 378, -388, 450, -383}, { 275, 20, 182, -103}, +{ 246, -111, 431, 37}, { 462, -146, 487, -157}, { -284, -59, 503, -184}, +{ 24, 53, -3, 54}, { 122, 259, 333, 66}, { 484, 104, 436, 68}, +{ 195, 116, 190, 206}, { 269, -9, 482, 352}, { 382, 285, 399, 277}, +{ 452, 256, 69, 186}, { 13, 297, -13, 259}, { -95, 30, 56, 394}, +{ 196, 425, 205, 456}, { 281, 577, 15, 191}, { 375, 290, 407, 576}, +{ -56, 227, 544, 405}, { 0, 549, -92, 528}, { -229, 351, -245, 338}, +{ -362, 435, 167, 527}, { -75, 302, 91, 824}, { 129, 599, 496, 679}, +{ 186, 749, 153, 737}, { -281, 600, -348, 615}, { -236, 769, 41, 881}, +{ 38, 890, -220, 841}, { -357, 883, -393, 903}, { -634, 474, -444, 850}, +{ -175, 678, -493, 242}, { -519, 785, -714, 582}, { -541, 366, -543, 434}, +{ -597, 500, -765, 222}, { -702, 917, -743, 962}, { -869, 501, -899, 548}, +{ -379, 200, -435, 157}, { -819, 214, -861, 157}, { -614, 40, -632, 94}, +{ -883, -54, -741, 516}, { -501, 298, -614, -171}, { -870, -161, -865, -23}, +{ -818, 93,-1015, -267}, { -662, -359, -549, 2}, { -442, -121, -377, 0}, +{ -227, 33, -414, -126}, { -129, 212, -934, 34}, {-1082, -282,-1119, -268}, +{ -710, -825, -420, -191}, {-1076, -928, -917, -93}, { -628, -358, 97, 7}, +{ -206, -393, -101, 24}, { -203, 38, -168, 83}, { -599, -423, -279, 426}, +{ -700, 118, -75, 206}, { -981, -673, -680, 417}, { -367, 37, -279, 474}, +{ -129, -318, 319, 296}, { -626, -39, 343, 602}, { -696, -39, -303, 940}, +{ 104, 233, -380, 137}, { -36, 269, -75, -214}, { 120, 43, -529, -477}, +{ 459, 164, -202, -229}, { -49, -167, 609, 792}, { 98, -220, 915, 148}, +{ 293, 283, 869, 91}, { 575, 394, 326, -78}, { 717, 67, 365, -323}, +{ 616, -36, 731, 27}, { 619, 238, 632, 273}, { 448, 99, 801, 476}, +{ 869, 273, 685, 64}, { 789, 72, 1021, 217}, { 793, 459, 734, 360}, +{ 646, 480, 360, 322}, { 429, 464, 638, 430}, { 756, 363, 1000, 404}, +{ 683, 528, 602, 615}, { 655, 413, 946, 687}, { 937, 602, 904, 604}, +{ 555, 737, 786, 662}, { 467, 654, 362, 589}, { 929, 710, 498, 478}, +{ 415, 420, 693, 883}, { 813, 683, 781, 925}, { 913, 939, 726, 732}, +{ 491, 853, 531, 948}, { 734, 963, 315, 808}, { 761, 755, 1144, 760}, +{ 655, 1076, 826, 1057}, { 1091, 838, 1003, 808}, { 1047, 1133, 659, 1101}, +{ 992, 1050, 1074, 1075}, { 971, 694, 1226, 1054}, { 571, 841, 884, 1404}, +{ 1379, 1096, 1080, 861}, { 1231, 735, 1284, 760}, { 1272, 991, 1367, 1053}, +{ 1257, 700, 1050, 534}, { 988, 453, 1264, 599}, { 1140, 679, 1621, 815}, +{ 1384, 521, 1317, 393}, { 1564, 805, 1448, 686}, { 1068, 648, 875, 307}, +{ 1083, 361, 1047, 317}, { 1417, 964, 675, 571}, { 1152, 79, 1114, -47}, +{ 1530, 311, 1721, 314}, { 1166, 689, 514, -94}, { 349, 282, 1412, 328}, +{ 1025, 487, -65, 57}, { 805, 970, 36, 62}, { 769, -263, 791, -346}, +{ 637, 699, -137, 620}, { 534, 541, -735, 194}, { 711, 300, -268, -863}, +{ 926, 769, -708, -428}, { 506, 174, -892, -630}, { 435, 547,-1435, -258}, +{ 621, 471,-1018,-1368}, { -393, 521, -920, -686}, { -25, 20, -982,-1156}, +{ 340, 9,-1558,-1135}, { -352, 48,-1579, -402}, { -887, 6,-1156, -888}, +{ -548, -352,-1643,-1168}, { -159, 610,-2024, -963}, { -225, 193,-1656,-1960}, +{ -245, -493, -964,-1680}, { -936, -635,-1299,-1744}, {-1388, -604,-1540, -835}, +{-1397, -135,-1588, -290}, {-1670, -712,-2011,-1632}, {-1663, -27,-2258, -811}, +{-1157, 184,-1265, 189}, {-1367, 586,-2011, 201}, { -790, 712,-1210, 3}, +{-1033, 808,-1251, 830}, { -111, 635,-1636, 447}, { -463, -949, -445, -928}, +{ -504,-1162, -501,-1211}, { 144, -351, -372,-1052}, { -283,-1059, -279,-1123}, +{ -575,-1438, -587,-1614}, { -935, -984, 229, 690}, { -921, -719, -403, 1362}, +{ -685, -465, 874, 397}, { -509, -46, 317, 1334}, { -485, 456, 813, 439}, +{ -411, 339, 898, 1067}, { -425, 46, 1441, 497}, { -909, -800, 1465, 1046}, +{ -254, -321, 1430, 1165}, { 68, 350, 1034, 666}, { 370, 11, 1311, 790}, +{ 143, 232, 1041, 1562}, { -114, 663, 1616, 1078}, { 454, 579, 1275, 1040}, +{ -76, 909, 752, 1067}, { 153, 512, 348, 1214}, { 614, 385, 1843, 808}, +{ 269, 1034, 203, 1086}, { 652, 1017, 1783, 1130}, { 429, 1327, 387, 1384}, +{ -49, 1183, -72, 1215}, { -416, 1001, 544, 1749}, { -352, 1223, -502, 1199}, +{ -589, 569, -227, 1630}, { -142, 1578, -230, 1715}, { -714, 1288, -838, 1398}, +{ 1131, 1357, -208, 1232}, { 437, 965, -929, 818}, { 811, 1410, 859, 1507}, +{ 164, 1212, 1387, 1793}, { 484, 1874, 456, 2063}, { 996, 1170, 1326, 1402}, +{ 1316, 1360, 1135, 1262}, { 1234, 1618, 1361, 1768}, { 1421, 1227, 1584, 1347}, +{ 854, 672, 1685, 1566}, { 1139, 1270, 2016, 1825}, { 1773, 1581, 1532, 1460}, +{ 1487, 946, 1659, 1021}, { 1744, 1212, 1392, 977}, { 1772, 1161, 1826, 1164}, +{ 1718, 1429, 1973, 1591}, { 1185, 864, 2132, 1061}, { 1799, 814, 1838, 757}, +{ 2104, 1315, 2054, 1258}, { 2113, 915, 2331, 930}, { 1467, 1147, 2590, 1439}, +{ 2245, 1744, 2090, 1620}, { 2358, 1454, 2666, 1506}, { 1876, 1837, 2070, 1975}, +{ 1739, 1577, 682, 1289}, { 1584, 2045, 1454, 2098}, { 2498, 2004, 2711, 2066}, +{ 726, 1588, 2756, 2336}, { 228, 847, 2456, 1659}, { 36, 301, 1942, 1957}, +{ -446, -96, 2154, 1396}, { 1533, 1101, 14, 608}, { -923, -732, 1383, 1982}, +{ 1345, 952, -680, 321}, { 1281, 1268,-1594, 365}, { 941, 946,-1737, -822}, +{ 2374, 2787, 1821, 2788} +}; + +static const int16_t lsf_5_3[256][4] = { +{-1812,-2275,-1879,-2537}, {-1640,-1848,-1695,-2004}, {-1220,-1912,-1221,-2106}, +{-1559,-1588,-1573,-1556}, {-1195,-1615,-1224,-1727}, {-1359,-1151,-1616,-1948}, +{-1274,-1391,-1305,-1403}, {-1607,-1179,-1676,-1311}, {-1443,-1478,-1367, -898}, +{-1256,-1059,-1331,-1134}, { -982,-1133,-1149,-1504}, {-1080,-1308,-1020,-1183}, +{ -980,-1486, -967,-1495}, { -988, -922,-1047,-1077}, { -838,-1179, -858,-1222}, +{-1131,-1041,-1064, -767}, { -872,-1157, -701, -880}, { -706, -906, -774,-1016}, +{ -578,-1080, -801,-1478}, { -591,-1111, -592,-1146}, { -713,-1388, -640,-1376}, +{ -597,-1059, -416, -903}, { -686, -832, -661, -708}, { -444, -868, -490, -921}, +{ -374, -776, -619,-1170}, { -585, -549, -769, -795}, { -435, -659, -530, -741}, +{ -498, -837, -357, -597}, { -279, -871, -243, -887}, { -282, -665, -280, -667}, +{ -165, -560, -394, -903}, { -362, -410, -448, -583}, { -409, -574, -313, -357}, +{ -637, -548, -570, -436}, { -896, -504, -382, -757}, { -58, -481, -165, -618}, +{ -191, -374, -234, -382}, { -222, -683, -25, -480}, { -418, -359, -730, -353}, +{ -324, -157, -432, -322}, { -394, -303, -284, -104}, { -601, -289, -556, -196}, +{ -588, -150, -659, -608}, { -473, -24, -68, -448}, { -474, -8, -506, -45}, +{ -748, -184, -844, -252}, { -901, -91, -584, -97}, { -652, 138, -764, -131}, +{ -678, -12, -670, 165}, { -259, -3, -840, -107}, { -909, 37, -992, 44}, +{ -854, -415, -839, 13}, {-1001, -271,-1026, -309}, { -798, -478, -832, -488}, +{ -943, 168,-1112, -387}, {-1185, -101,-1183, -40}, { -941, -316,-1030, -770}, +{-1044, -625,-1081, -538}, {-1224, -299,-1312, -436}, {-1197, -663,-1167, -161}, +{-1216, -690,-1237, -831}, {-1432, -720,-1403, -493}, { -898, -740, -922, -801}, +{-1102, -402,-1579, -964}, {-1061, -638,-1269,-1438}, {-1499, -934,-1502, -895}, +{-1598, -564,-1723, -717}, { -606, -597,-1166,-1085}, {-1369, -468,-1946,-1493}, +{-1838, -953,-1932, -931}, {-1499, -188,-1635, -421}, {-1457, -338,-1448, -22}, +{-1942, -422,-2006, -249}, { -496, -114,-1910, -755}, {-1289, 174,-1451, -109}, +{ -482, -257,-1221, -508}, {-1617, 151,-1694, 208}, { -654, 107,-1651, 29}, +{-1141, 279,-1215, 306}, {-1228, -506, -730, -175}, {-1236, -101, -969, 551}, +{ -870, 278, -823, 315}, { -563, 376,-1051, 228}, { -507, 280, -599, 281}, +{ -758, 253, -305, 379}, { -755, -134, -611, 660}, { -824, 536, -817, 646}, +{ -413, 49, -341, 177}, { -453, 526, -482, 589}, { -71, 339, -657, 264}, +{ -244, 295, -237, 315}, { -387, 569, -506, -9}, { -377, 14, -160, 661}, +{ -216, 40, -308, -46}, { 95, 214, -242, 167}, { -86, 192, -56, 27}, +{ -76, 31, 36, 309}, { -106, -182, -113, 74}, { -441, -22, 23, 139}, +{ 81, -11, 44, 15}, { -87, -137, -118, -207}, { -158, -58, 272, -92}, +{ -156, -441, 8, -136}, { 128, -221, 101, -218}, { 40, -197, -76, -456}, +{ 9, -445, 33, -423}, { 226, 60, 73, -222}, { 156, -399, 280, -318}, +{ 245, -341, 166, -499}, { 339, -190, 327, -219}, { 325, -137, -89, -596}, +{ 100, -627, 144, -677}, { 487, 28, 252, -391}, { 214, -41, 282, -28}, +{ 99, -286, 331, 49}, { 459, -388, 565, -369}, { 436, 28, 336, -9}, +{ 397, -167, 618, 34}, { 596, -17, 561, -140}, { 299, 79, 522, 125}, +{ 203, 2, 244, 288}, { 255, 211, 175, 82}, { 596, 187, 517, 108}, +{ 381, 255, 365, 297}, { 497, 352, 327, -82}, { 25, 210, 371, 245}, +{ 261, 3, 545, 449}, { 140, 294, 44, 295}, { 212, 347, 244, 494}, +{ 331, 528, 201, 307}, { 349, 411, 613, 284}, { 614, 413, 464, 322}, +{ 624, 397, 97, 200}, { -160, 384, 149, 362}, { 495, 525, 269, 585}, +{ 33, 491, -121, 433}, { 427, 611, 498, 516}, { 171, 443, 497, 666}, +{ 440, 275, 566, 575}, { 146, 639, 155, 670}, { -33, 173, 212, 696}, +{ -166, 601, -191, 695}, { -489, 503, 175, 742}, { 214, 476, 372, 1083}, +{ 578, 530, 586, 777}, { 425, 874, 315, 841}, { 374, 848, -165, 565}, +{ 35, 991, -39, 1062}, { 329, 712, 786, 840}, { 645, 795, 661, 676}, +{ 571, 918, 632, 1079}, { 673, 817, 318, 388}, { 874, 1012, 564, 848}, +{ 880, 620, 557, 479}, { 671, 453, 692, 468}, { 840, 642, 844, 645}, +{ 506, 428, 897, 567}, { 837, 387, 962, 499}, { 691, 561, 939, 926}, +{ 783, 296, 790, 268}, { 1028, 530, 874, 329}, { 548, 143, 675, 291}, +{ 503, 66, 1041, 359}, { 786, 97, 805, 33}, { 837, 470, 511, 49}, +{ 1092, 327, 1174, 323}, { 3, 242, 872, 474}, { 689, 429, 1329, 678}, +{ 1042, 620, 1109, 664}, { 321, 193, 889, 950}, { 1153, 874, 893, 635}, +{ 877, 862, 948, 913}, { 1293, 665, 1320, 639}, { 997, 793, 1402, 1030}, +{ 1176, 1012, 1110, 959}, { 1410, 925, 1403, 915}, { 543, 862, 1116, 1222}, +{ 835, 1190, 835, 1190}, { 959, 1148, 1147, 1376}, { 1300, 1193, 1415, 1231}, +{ 1335, 1341, 746, 1092}, { 1711, 1283, 1389, 1073}, { 1334, 1566, 1153, 1475}, +{ 1645, 1137, 1825, 1220}, { 1056, 1382, 1521, 1730}, { 1632, 1545, 1620, 1542}, +{ 855, 1596, 865, 1667}, { 693, 885, 1716, 1519}, { 1167, 1296, 2209, 1760}, +{ 1952, 1493, 2020, 1482}, { 1534, 1866, 1694, 2008}, { 1566, 748, 1761, 825}, +{ 294, 1392, 1084, 2058}, { 621, 1315, 365, 1287}, { 198, 1028, 488, 1408}, +{ 249, 403, 1014, 1561}, { 324, 363, 1645, 1044}, { 193, 367, 2034, 1859}, +{ -251, 579, 750, 994}, { -243, 30, 1325, 879}, { -28, -169, 624, 917}, +{ -453, 159, 186, 1370}, { -614, 6, 537, 392}, { -94, -291, 781, 229}, +{ -128, -298, 245, 491}, { -701, -648, 972, 789}, { -501, -640, 178, 255}, +{ -365, -390, -255, 317}, { -958, -294, -191, 228}, { -775, -447, 157, -237}, +{ -657, -720, -407, 92}, { -117, -611, 334, -230}, { -679,-1084, -144, -317}, +{ -901, -861, -738, -360}, { -85, -727, -90, -787}, { 100, -22, -391, -263}, +{ -56, -73, -337, -754}, { 5, -189, -706, -624}, { 89, -344, -135,-1113}, +{ -353, -237, -684,-1135}, { -275,-1102, -269,-1203}, { 152, 145, -722,-1232}, +{ 49, 80,-1248, -776}, { -248, 391, -732, -547}, { 469, 218, -255, -864}, +{ 69, 366, -166, -485}, { -688, 191,-1212,-1196}, { -170, -169,-1308,-1631}, +{ 321, 470,-1419,-1243}, { -64, 272,-1361, -248}, { 492, 565, -721, -609}, +{ 195, 485, -573, -133}, { 427, 202, -171, -118}, { 199, 575, 2, -31}, +{ 694, 755,-1366, -39}, { 552, 557, -489, 271}, { 680, 537, 13, -453}, +{ 855, 954, -133, -52}, { -81, 738,-1169, 637}, { 1055, 1059, -95, 676}, +{ 1259, 1081, 489, 305}, { -449, 954, -534, 996}, { -969, 866,-1058, 1059}, +{-1294, 618,-1416, 617}, { -458, 1366, -159, 1821}, { -774, -528, -14, 1110}, +{-1202, -901, -772, 433}, {-1256,-1255,-1011, -302}, { -602, -585, -759,-1618}, +{ -760,-1549, -840,-1921}, { -816, -539,-1769,-2235}, { -227, -36,-2034,-1831}, +{-2107,-1126,-2471,-1816}, {-1470, 252,-2701, -415}, { -571, -467, 1509, 1554}, +{ 2180, 1975, 2326, 2020} +}; + +static const int16_t lsf_5_4[256][4] = { +{-1857,-1681,-1857,-1755}, {-2056,-1150,-2134,-1654}, {-1619,-1099,-1704,-1131}, +{-1345,-1608,-1359,-1638}, {-1338,-1293,-1325,-1265}, {-1664,-1649,-1487, -851}, +{-1346,-1832,-1413,-2188}, {-1282, -681,-1785,-1649}, { -966,-1082,-1183,-1676}, +{-1054,-1073,-1142,-1158}, {-1207, -744,-1274, -997}, { -934,-1383, -927,-1416}, +{-1010,-1305, -783, -955}, {-1049, -900, -993, -817}, { -737, -823, -972,-1189}, +{ -738,-1094, -738,-1154}, { -784, -801, -810, -786}, { -892, -520,-1000, -818}, +{ -644, -965, -577, -882}, { -541, -694, -671, -917}, { -595, -642, -646, -615}, +{ -956, -621, -925, -515}, { -727, -483, -815, -485}, { -840, -578, -440, -713}, +{ -578, -325, -657, -670}, { -386, -570, -441, -666}, { -514, -787, -392, -529}, +{ -522, -453, -487, -423}, { -616, -585, -617, -157}, { -662, -268, -680, -348}, +{ -322, -323, -632, -444}, { -304, -430, -332, -458}, { -277, -468, -659, -793}, +{ -319, -636, -227, -554}, { -373, -347, -334, -210}, { -456, -192, -530, -242}, +{ -216, -198, -366, -370}, { -338, -161, -409, -748}, { -107, -380, -294, -643}, +{ -223, -665, -234, -741}, { -141, -496, -130, -510}, { -139, -327, -172, -305}, +{ -306, -580, -164, -263}, { -262, -172, -67, -402}, { 31, -366, -10, -436}, +{ -86, -527, 71, -377}, { -22, -609, -12, -678}, { -67, -319, 63, -191}, +{ 35, -181, -39, -242}, { 126, -167, -140, -544}, { 155, -297, 174, -297}, +{ 38, -8, 117, -380}, { 197, -452, 240, -522}, { 223, -103, 110, -187}, +{ 87, -155, 169, -47}, { 157, 26, -83, -100}, { 128, 80, 209, -62}, +{ 6, 7, 22, 5}, { 318, -20, 248, -45}, { -200, -63, 156, -69}, +{ 250, -183, 369, -126}, { -113, -76, -142, -122}, { -64, -254, -31, 35}, +{ -177, -71, -7, 171}, { 93, 27, 108, 212}, { -330, -209, -123, -70}, +{ -279, 95, -96, 20}, { -188, -61, -314, 87}, { -300, -78, -354, -134}, +{ 11, 122, -140, 122}, { -275, 152, -293, 140}, { -82, 138, -321, -111}, +{ -480, -156, -359, 76}, { -254, -40, -635, -96}, { -522, 79, -507, 8}, +{ -268, 303, -539, 68}, { -446, 61, -522, 306}, { 111, 189, -435, 122}, +{ -379, 166, -571, -398}, { -632, -74, -747, -95}, { -455, 194, -952, 83}, +{ -798, 192, -755, 192}, { -781, -162, -619, 234}, { -663, -297, -488, -109}, +{ -964, -132, -838, -68}, { -843, 58,-1112, -86}, { -805, -299, -944, -253}, +{ -778, -50, -965, -549}, { -352, -98, -992, -343}, {-1117, -315,-1117, -307}, +{-1155, -374, -637, -230}, {-1166, -43,-1299, -100}, { -925, -393,-1274, -600}, +{ -689, -130,-1479, -312}, {-1321, -254,-1464, -442}, {-1292, -613,-1261, -503}, +{-1501, -368,-1322, 26}, {-1432, -66,-1743, -161}, {-1644, -467,-1760, -548}, +{-1393, -568,-1556, -871}, {-1495,-1034,-1387, -571}, {-1917, -528,-1783, -123}, +{-1897, -231,-2054, -323}, {-2052, -906,-1976, -567}, {-1917, -620,-2047, -989}, +{-1077, -370,-2031, -704}, {-2355, -749,-2740,-1089}, {-1909, 159,-2012, 248}, +{ -626, -123,-2339, -962}, { -669, -408,-1379,-1174}, { -452, -364,-1044, -735}, +{ -132, 183,-1620, -752}, { -547, -307, -777,-1261}, { -98, 41, -880,-1091}, +{ -257, 97,-1602,-1833}, { 31, -26, -644, -561}, { -180, -546, -385,-1095}, +{ -410, -802, -414, -827}, { -457, -970, -490,-1109}, { -215, -916, -144, -937}, +{ -493,-1269, -517,-1507}, { 181, 101, -332, -889}, { -836, -937, -559, -429}, +{ -629, -547, -183, -337}, { -545, -82, -250, -286}, { 5, -132, -348, -252}, +{ -293, -472, -158, 100}, { -29, 197, -236, -424}, { -861, -213, -140, -7}, +{ -427, -443, 187, -97}, { -684, -736, -293, 258}, { -368, -152, -150, 392}, +{ -609, 175, -142, 299}, { -138, 152, -119, 329}, { -486, -52, 293, 198}, +{ -183, 117, 175, 331}, { -58, -274, 231, 300}, { -288, 330, -305, 372}, +{ -111, 409, -9, 423}, { 83, 256, 67, 367}, { -19, 248, 91, 113}, +{ -35, 406, -191, 154}, { 238, 296, 5, 197}, { 141, 221, 313, 198}, +{ 211, 421, 244, 334}, { 88, 426, -243, 454}, { 202, 552, -5, 403}, +{ 291, 185, 219, 301}, { 251, 138, 128, 69}, { 197, 288, -140, -61}, +{ 188, 361, 197, 598}, { 442, 273, 290, 143}, { 472, 482, 157, 370}, +{ 415, 321, 372, 385}, { 402, 552, 155, 24}, { 550, 263, -11, 21}, +{ 360, 227, 147, -254}, { 424, 97, 366, -13}, { 375, 141, 449, 232}, +{ 396, 507, 474, 272}, { 701, 324, 362, -47}, { 587, 148, 543, 69}, +{ 400, -51, 561, 59}, { 220, -10, 352, 147}, { 206, 211, 653, 185}, +{ 563, 297, 565, 284}, { 594, 121, 766, 192}, { 398, 118, 642, 434}, +{ 233, 264, 481, 467}, { 129, -165, 699, 239}, { 90, 26, 342, 474}, +{ -55, 27, 388, 94}, { -172, 0, 725, 379}, { -60, 337, 370, 465}, +{ 95, 319, 806, 595}, { 78, 260, 497, 851}, { 210, 560, 458, 574}, +{ -464, 202, 497, 625}, { -202, 152, 48, 712}, { -20, 566, 100, 715}, +{ 455, 468, 411, 605}, { 319, 646, 195, 615}, { 401, 538, 680, 739}, +{ 201, 667, 434, 954}, { 454, 425, 646, 491}, { 606, 681, 416, 508}, +{ 497, 822, 426, 815}, { 660, 647, 628, 716}, { 697, 466, 618, 457}, +{ 685, 460, 365, 309}, { 721, 567, 836, 601}, { 609, 300, 825, 459}, +{ 943, 687, 681, 533}, { 915, 598, 591, 243}, { 876, 451, 874, 420}, +{ 786, 317, 732, 220}, { 922, 317, 1108, 367}, { 531, 466, 1028, 649}, +{ 1053, 615, 1034, 553}, { 829, 602, 1021, 799}, { 927, 803, 878, 763}, +{ 799, 496, 1373, 773}, { 585, 770, 803, 930}, { 1099, 793, 1222, 862}, +{ 1209, 895, 1025, 727}, { 772, 845, 1172, 1115}, { 867, 1021, 830, 1013}, +{ 841, 910, 506, 703}, { 1239, 1077, 620, 819}, { 1196, 1083, 1155, 1081}, +{ 1142, 907, 1547, 1121}, { 1309, 648, 1343, 612}, { 1484, 988, 1479, 937}, +{ 985, 1328, 955, 1341}, { 429, 910, 841, 1338}, { 564, 1179, 412, 1156}, +{ 1427, 1320, 1434, 1330}, { 640, 760, 1726, 1410}, { 190, 555, 1073, 1005}, +{ 426, 257, 839, 980}, { 235, 231, 1520, 1167}, { 109, 293, 1014, 1569}, +{ 305, 142, 1148, 539}, { -291, -108, 1213, 972}, { 22, -216, 667, 828}, +{ -482, 438, 453, 1431}, { -581, -422, 789, 387}, { -358, -454, 174, 780}, +{ -36, -372, 390, -134}, { -629, 160, -306, 751}, {-1258, -331, 177, 522}, +{ -248, 574, -251, 639}, { -531, 407, -596, 394}, { -419, 789, -617, 801}, +{ -986, 399, -857, 727}, { -7, 518, -703, 310}, {-1143, -24,-1002, 287}, +{ -960, 363,-1299, 312}, {-1534, 245,-1557, 305}, { 28, 153, -859, -175}, +{ -33, 332,-1398, -154}, { 212, 410, -593, -197}, {-1092, -704, -904, -65}, +{ 282, 367, -918, -686}, { 345, 93, -258, -357}, { 696, 644, -693, -28}, +{ 448, 493, -273, 193}, { 527, 546, -243, -513}, { 384, -136, 273, -353}, +{ 512, -142, 537, -198}, { 941, 750, 83, 248}, { 578, 861, -56, 592}, +{ 842, 44, 892, 24}, { 33, 890, -16, 982}, { 831, 1398, 1535, 1898}, +{ 1716, 1376, 1948, 1465} +}; + +static const int16_t lsf_5_5[64][4] = { +{-1002, -929,-1096,-1203}, { -641, -931, -604, -961}, { -779, -673, -835, -788}, +{ -416, -664, -458, -766}, { -652, -521, -662, -495}, {-1023, -509,-1023, -428}, +{ -444, -552, -368, -449}, { -479, -211,-1054, -903}, { -316, -249, -569, -591}, +{ -569, -275, -541, -191}, { -716, -188, -842, -264}, { -333, -248, -318, -228}, +{ -275, 1, -567, -228}, { -115, -221, -238, -374}, { -197, -507, -222, -579}, +{ -258, -432, -61, -244}, { -345, 2, -338, 39}, { -215, -169, -58, 0}, +{ -56, -6, -203, -131}, { 1, -186, -5, -211}, { 6, -380, 11, -418}, +{ -116, 131, -134, 113}, { 89, -4, 71, -2}, { -19, -192, 262, 24}, +{ 189, 151, -133, -109}, { 186, -153, 166, -219}, { 37, 139, 193, 171}, +{ 337, 124, 158, -61}, { 141, 226, -13, 190}, { 231, 34, 354, 109}, +{ 316, 201, 244, 164}, { 330, -85, 390, -84}, { 254, 327, 257, 335}, +{ 491, 147, 476, 105}, { 54, 77, 437, 370}, { 421, 314, 449, 342}, +{ 329, 126, 673, 292}, { 571, 388, 243, 193}, { 653, 320, 621, 280}, +{ 194, 380, 517, 581}, { 45, 323, 111, 422}, { 489, 395, 734, 534}, +{ 622, 546, 486, 502}, { 318, 572, 189, 550}, { 385, 422, -157, 153}, +{ -125, 382, -197, 386}, { -263, 334, 228, 697}, { -188, 1, 51, 297}, +{ -507, 213, -376, 397}, { -24, 255, -547, 89}, { -502, -94, 387, 179}, +{ -620, 68, -684, 112}, { -642, -350, -260, 172}, { -438, -324, 264, 648}, +{ -964, -4,-1121, 7}, { -134, 134,-1133, -306}, { 143, 96, -420, -497}, +{-1221, -350,-1527, -685}, { -161, 72, 873, 691}, { 732, 283, 921, 353}, +{ 334, 475, 1095, 821}, { 864, 524, 843, 497}, { 714, 711, 788, 750}, +{ 1076, 714, 1204, 753} +}; + +static const float lsf_3_mean[LP_FILTER_ORDER] = { + 377.441, 554.688, 922.363, 1339.84, 1702.15, + 2046.390, 2452.880, 2741.460, 3116.70, 3348.14 +}; + +static const float lsf_5_mean[LP_FILTER_ORDER] = { + 337.891, 507.080, 834.961, 1247.07, 1646.00, + 1982.910, 2407.960, 2708.010, 3104.00, 3344.97 +}; + +/** Prediction factor table for modes other than 12.2kbit/s */ +static const float pred_fac[LP_FILTER_ORDER] = { + 0.291626, 0.328644, 0.383636, 0.405640, 0.438873, + 0.355560, 0.323120, 0.298065, 0.262238, 0.197876, +}; + +// fixed tables + +/** + * number of pulses per mode + */ +static const uint8_t pulses_nb_per_mode[] = {2, 2, 2, 3, 4, 4, 8, 10}; + +/** track start positions for algebraic code book routines */ +static const uint8_t track_position[16] = { + 0, 2, 0, 3, 0, 2, 0, 3, 1, 3, 2, 4, 1, 4, 1, 4 +}; + +/** 3-bit Gray code to binary lookup table */ +static const uint8_t gray_decode[8] = { 0, 5, 15, 10, 25, 30, 20, 35 }; + + +// gain tables + +/** scalar quantized pitch gain table for 7.95 and 12.2 kbps modes */ +static const uint16_t qua_gain_pit[16] = { + 0, 3277, 6556, 8192, 9830, 11469, 12288, 13107, + 13926, 14746, 15565, 16384, 17203, 18022, 18842, 19661 +}; + +/** scalar quantized fixed gain table for 7.95 and 12.2 kbps modes */ +static const uint16_t qua_gain_code[32] = { + 159, 206, 268, 349, 419, 482, 554, 637, + 733, 842, 969, 1114, 1281, 1473, 1694, 1948, + 2241, 2577, 2963, 3408, 3919, 4507, 5183, 5960, + 6855, 7883, 9065, 10425, 12510, 16263, 21142, 27485 +}; + +/** desired mean innovation energy, indexed by active mode */ +static const float energy_mean[8] = { + 33.0, 33.0, 33.0, 28.75, 30.0, 36.0, 33.0, 36.0 +}; + +/** 4-tap moving average prediction coefficients in reverse order */ +static const float energy_pred_fac[4] = { 0.19, 0.34, 0.58, 0.68 }; + +/** gain table for 4.75 kbps mode + * + * first index has even/odd indexes for subframes 0,2/1,3 + * second index is {pitch_gain, fixed_gain_factor} */ +static const uint16_t gains_MODE_4k75[512][2] = { +{ 812, 128}, { 542, 140}, { 2873, 1135}, { 2266, 3402}, { 2067, 563}, +{12677, 647}, { 4132, 1798}, { 5601, 5285}, { 7689, 374}, { 3735, 441}, +{10912, 2638}, {11807, 2494}, {20490, 797}, { 5218, 675}, { 6724, 8354}, +{ 5282, 1696}, { 1488, 428}, { 5882, 452}, { 5332, 4072}, { 3583, 1268}, +{ 2469, 901}, {15894, 1005}, {14982, 3271}, {10331, 4858}, { 3635, 2021}, +{ 2596, 835}, {12360, 4892}, {12206, 1704}, {13432, 1604}, { 9118, 2341}, +{ 3968, 1538}, { 5479, 9936}, { 3795, 417}, { 1359, 414}, { 3640, 1569}, +{ 7995, 3541}, {11405, 645}, { 8552, 635}, { 4056, 1377}, {16608, 6124}, +{11420, 700}, { 2007, 607}, {12415, 1578}, {11119, 4654}, {13680, 1708}, +{11990, 1229}, { 7996, 7297}, {13231, 5715}, { 2428, 1159}, { 2073, 1941}, +{ 6218, 6121}, { 3546, 1804}, { 8925, 1802}, { 8679, 1580}, {13935, 3576}, +{13313, 6237}, { 6142, 1130}, { 5994, 1734}, {14141, 4662}, {11271, 3321}, +{12226, 1551}, {13931, 3015}, { 5081,10464}, { 9444, 6706}, { 1689, 683}, +{ 1436, 1306}, { 7212, 3933}, { 4082, 2713}, { 7793, 704}, {15070, 802}, +{ 6299, 5212}, { 4337, 5357}, { 6676, 541}, { 6062, 626}, {13651, 3700}, +{11498, 2408}, {16156, 716}, {12177, 751}, { 8065,11489}, { 6314, 2256}, +{ 4466, 496}, { 7293, 523}, {10213, 3833}, { 8394, 3037}, { 8403, 966}, +{14228, 1880}, { 8703, 5409}, {16395, 4863}, { 7420, 1979}, { 6089, 1230}, +{ 9371, 4398}, {14558, 3363}, {13559, 2873}, {13163, 1465}, { 5534, 1678}, +{13138,14771}, { 7338, 600}, { 1318, 548}, { 4252, 3539}, {10044, 2364}, +{10587, 622}, {13088, 669}, {14126, 3526}, { 5039, 9784}, {15338, 619}, +{ 3115, 590}, {16442, 3013}, {15542, 4168}, {15537, 1611}, {15405, 1228}, +{16023, 9299}, { 7534, 4976}, { 1990, 1213}, {11447, 1157}, {12512, 5519}, +{ 9475, 2644}, { 7716, 2034}, {13280, 2239}, {16011, 5093}, { 8066, 6761}, +{10083, 1413}, { 5002, 2347}, {12523, 5975}, {15126, 2899}, {18264, 2289}, +{15827, 2527}, {16265,10254}, {14651,11319}, { 1797, 337}, { 3115, 397}, +{ 3510, 2928}, { 4592, 2670}, { 7519, 628}, {11415, 656}, { 5946, 2435}, +{ 6544, 7367}, { 8238, 829}, { 4000, 863}, {10032, 2492}, {16057, 3551}, +{18204, 1054}, { 6103, 1454}, { 5884, 7900}, {18752, 3468}, { 1864, 544}, +{ 9198, 683}, {11623, 4160}, { 4594, 1644}, { 3158, 1157}, {15953, 2560}, +{12349, 3733}, {17420, 5260}, { 6106, 2004}, { 2917, 1742}, {16467, 5257}, +{16787, 1680}, {17205, 1759}, { 4773, 3231}, { 7386, 6035}, {14342,10012}, +{ 4035, 442}, { 4194, 458}, { 9214, 2242}, { 7427, 4217}, {12860, 801}, +{11186, 825}, {12648, 2084}, {12956, 6554}, { 9505, 996}, { 6629, 985}, +{10537, 2502}, {15289, 5006}, {12602, 2055}, {15484, 1653}, {16194, 6921}, +{14231, 5790}, { 2626, 828}, { 5615, 1686}, {13663, 5778}, { 3668, 1554}, +{11313, 2633}, { 9770, 1459}, {14003, 4733}, {15897, 6291}, { 6278, 1870}, +{ 7910, 2285}, {16978, 4571}, {16576, 3849}, {15248, 2311}, {16023, 3244}, +{14459,17808}, {11847, 2763}, { 1981, 1407}, { 1400, 876}, { 4335, 3547}, +{ 4391, 4210}, { 5405, 680}, {17461, 781}, { 6501, 5118}, { 8091, 7677}, +{ 7355, 794}, { 8333, 1182}, {15041, 3160}, {14928, 3039}, {20421, 880}, +{14545, 852}, {12337,14708}, { 6904, 1920}, { 4225, 933}, { 8218, 1087}, +{10659, 4084}, {10082, 4533}, { 2735, 840}, {20657, 1081}, {16711, 5966}, +{15873, 4578}, {10871, 2574}, { 3773, 1166}, {14519, 4044}, {20699, 2627}, +{15219, 2734}, {15274, 2186}, { 6257, 3226}, {13125,19480}, { 7196, 930}, +{ 2462, 1618}, { 4515, 3092}, {13852, 4277}, {10460, 833}, {17339, 810}, +{16891, 2289}, {15546, 8217}, {13603, 1684}, { 3197, 1834}, {15948, 2820}, +{15812, 5327}, {17006, 2438}, {16788, 1326}, {15671, 8156}, {11726, 8556}, +{ 3762, 2053}, { 9563, 1317}, {13561, 6790}, {12227, 1936}, { 8180, 3550}, +{13287, 1778}, {16299, 6599}, {16291, 7758}, { 8521, 2551}, { 7225, 2645}, +{18269, 7489}, {16885, 2248}, {17882, 2884}, {17265, 3328}, { 9417,20162}, +{11042, 8320}, { 1286, 620}, { 1431, 583}, { 5993, 2289}, { 3978, 3626}, +{ 5144, 752}, {13409, 830}, { 5553, 2860}, {11764, 5908}, {10737, 560}, +{ 5446, 564}, {13321, 3008}, {11946, 3683}, {19887, 798}, { 9825, 728}, +{13663, 8748}, { 7391, 3053}, { 2515, 778}, { 6050, 833}, { 6469, 5074}, +{ 8305, 2463}, { 6141, 1865}, {15308, 1262}, {14408, 4547}, {13663, 4515}, +{ 3137, 2983}, { 2479, 1259}, {15088, 4647}, {15382, 2607}, {14492, 2392}, +{12462, 2537}, { 7539, 2949}, {12909,12060}, { 5468, 684}, { 3141, 722}, +{ 5081, 1274}, {12732, 4200}, {15302, 681}, { 7819, 592}, { 6534, 2021}, +{16478, 8737}, {13364, 882}, { 5397, 899}, {14656, 2178}, {14741, 4227}, +{14270, 1298}, {13929, 2029}, {15477, 7482}, {15815, 4572}, { 2521, 2013}, +{ 5062, 1804}, { 5159, 6582}, { 7130, 3597}, {10920, 1611}, {11729, 1708}, +{16903, 3455}, {16268, 6640}, { 9306, 1007}, { 9369, 2106}, {19182, 5037}, +{12441, 4269}, {15919, 1332}, {15357, 3512}, {11898,14141}, {16101, 6854}, +{ 2010, 737}, { 3779, 861}, {11454, 2880}, { 3564, 3540}, { 9057, 1241}, +{12391, 896}, { 8546, 4629}, {11561, 5776}, { 8129, 589}, { 8218, 588}, +{18728, 3755}, {12973, 3149}, {15729, 758}, {16634, 754}, {15222,11138}, +{15871, 2208}, { 4673, 610}, {10218, 678}, {15257, 4146}, { 5729, 3327}, +{ 8377, 1670}, {19862, 2321}, {15450, 5511}, {14054, 5481}, { 5728, 2888}, +{ 7580, 1346}, {14384, 5325}, {16236, 3950}, {15118, 3744}, {15306, 1435}, +{14597, 4070}, {12301,15696}, { 7617, 1699}, { 2170, 884}, { 4459, 4567}, +{18094, 3306}, {12742, 815}, {14926, 907}, {15016, 4281}, {15518, 8368}, +{17994, 1087}, { 2358, 865}, {16281, 3787}, {15679, 4596}, {16356, 1534}, +{16584, 2210}, {16833, 9697}, {15929, 4513}, { 3277, 1085}, { 9643, 2187}, +{11973, 6068}, { 9199, 4462}, { 8955, 1629}, {10289, 3062}, {16481, 5155}, +{15466, 7066}, {13678, 2543}, { 5273, 2277}, {16746, 6213}, {16655, 3408}, +{20304, 3363}, {18688, 1985}, {14172,12867}, {15154,15703}, { 4473, 1020}, +{ 1681, 886}, { 4311, 4301}, { 8952, 3657}, { 5893, 1147}, {11647, 1452}, +{15886, 2227}, { 4582, 6644}, { 6929, 1205}, { 6220, 799}, {12415, 3409}, +{15968, 3877}, {19859, 2109}, { 9689, 2141}, {14742, 8830}, {14480, 2599}, +{ 1817, 1238}, { 7771, 813}, {19079, 4410}, { 5554, 2064}, { 3687, 2844}, +{17435, 2256}, {16697, 4486}, {16199, 5388}, { 8028, 2763}, { 3405, 2119}, +{17426, 5477}, {13698, 2786}, {19879, 2720}, { 9098, 3880}, {18172, 4833}, +{17336,12207}, { 5116, 996}, { 4935, 988}, { 9888, 3081}, { 6014, 5371}, +{15881, 1667}, { 8405, 1183}, {15087, 2366}, {19777, 7002}, {11963, 1562}, +{ 7279, 1128}, {16859, 1532}, {15762, 5381}, {14708, 2065}, {20105, 2155}, +{17158, 8245}, {17911, 6318}, { 5467, 1504}, { 4100, 2574}, {17421, 6810}, +{ 5673, 2888}, {16636, 3382}, { 8975, 1831}, {20159, 4737}, {19550, 7294}, +{ 6658, 2781}, {11472, 3321}, {19397, 5054}, {18878, 4722}, {16439, 2373}, +{20430, 4386}, {11353,26526}, {11593, 3068}, { 2866, 1566}, { 5108, 1070}, +{ 9614, 4915}, { 4939, 3536}, { 7541, 878}, {20717, 851}, { 6938, 4395}, +{16799, 7733}, {10137, 1019}, { 9845, 964}, {15494, 3955}, {15459, 3430}, +{18863, 982}, {20120, 963}, {16876,12887}, {14334, 4200}, { 6599, 1220}, +{ 9222, 814}, {16942, 5134}, { 5661, 4898}, { 5488, 1798}, {20258, 3962}, +{17005, 6178}, {17929, 5929}, { 9365, 3420}, { 7474, 1971}, {19537, 5177}, +{19003, 3006}, {16454, 3788}, {16070, 2367}, { 8664, 2743}, { 9445,26358}, +{10856, 1287}, { 3555, 1009}, { 5606, 3622}, {19453, 5512}, {12453, 797}, +{20634, 911}, {15427, 3066}, {17037,10275}, {18883, 2633}, { 3913, 1268}, +{19519, 3371}, {18052, 5230}, {19291, 1678}, {19508, 3172}, {18072,10754}, +{16625, 6845}, { 3134, 2298}, {10869, 2437}, {15580, 6913}, {12597, 3381}, +{11116, 3297}, {16762, 2424}, {18853, 6715}, {17171, 9887}, {12743, 2605}, +{ 8937, 3140}, {19033, 7764}, {18347, 3880}, {20475, 3682}, {19602, 3380}, +{13044,19373}, {10526,23124} +}; + +/** gain table for 6.70, 7.40 and 10.2 kbps modes + * + * second index is {pitch_gain, fixed_gain_factor} */ +static const uint16_t gains_high[128][2] = { +{ 577, 662}, { 806, 1836}, { 3109, 1052}, { 4181, 1387}, { 2373, 1425}, +{ 3248, 1985}, { 1827, 2320}, { 941, 3314}, { 2351, 2977}, { 3616, 2420}, +{ 3451, 3096}, { 2955, 4301}, { 1848, 4500}, { 3884, 5416}, { 1187, 7210}, +{ 3083, 9000}, { 7384, 883}, { 5962, 1506}, { 5155, 2134}, { 7944, 2009}, +{ 6507, 2250}, { 7670, 2752}, { 5952, 3016}, { 4898, 3764}, { 6989, 3588}, +{ 8174, 3978}, { 6064, 4404}, { 7709, 5087}, { 5523, 6021}, { 7769, 7126}, +{ 6060, 7938}, { 5594,11487}, {10581, 1356}, { 9049, 1597}, { 9794, 2035}, +{ 8946, 2415}, {10296, 2584}, { 9407, 2734}, { 8700, 3218}, { 9757, 3395}, +{10177, 3892}, { 9170, 4528}, {10152, 5004}, { 9114, 5735}, {10500, 6266}, +{10110, 7631}, { 8844, 8727}, { 8956,12496}, {12924, 976}, {11435, 1755}, +{12138, 2328}, {11388, 2368}, {10700, 3064}, {12332, 2861}, {11722, 3327}, +{11270, 3700}, {10861, 4413}, {12082, 4533}, {11283, 5205}, {11960, 6305}, +{11167, 7534}, {12128, 8329}, {10969,10777}, {10300,17376}, {13899, 1681}, +{12580, 2045}, {13265, 2439}, {14033, 2989}, {13452, 3098}, {12396, 3658}, +{13510, 3780}, {12880, 4272}, {13533, 4861}, {12667, 5457}, {13854, 6106}, +{13031, 6483}, {13557, 7721}, {12957, 9311}, {13714,11551}, {12591,15206}, +{15113, 1540}, {15072, 2333}, {14527, 2511}, {14692, 3199}, {15382, 3560}, +{14133, 3960}, {15102, 4236}, {14332, 4824}, {14846, 5451}, {15306, 6083}, +{14329, 6888}, {15060, 7689}, {14406, 9426}, {15387, 9741}, {14824,14271}, +{13600,24939}, {16396, 1969}, {16817, 2832}, {15713, 2843}, {16104, 3336}, +{16384, 3963}, {16940, 4579}, {15711, 4599}, {16222, 5448}, {16832, 6382}, +{15745, 7141}, {16326, 7469}, {16611, 8624}, {17028,10418}, {15905,11817}, +{16878,14690}, {16515,20870}, {18142, 2083}, {19401, 3178}, {17508, 3426}, +{20054, 4027}, {18069, 4249}, {18952, 5066}, {17711, 5402}, {19835, 6192}, +{17950, 7014}, {21318, 7877}, {17910, 9289}, {19144, 9290}, {20517,11381}, +{18075,14485}, {19999,17882}, {18842,32764} +}; + +/** gain table for 5.15 and 5.90 kbps modes + * + * second index is {pitch_gain, fixed_gain_factor} */ +static const uint16_t gains_low[64][2] = { +{10813,28753}, {20480, 2785}, {18841, 6594}, { 6225, 7413}, {17203,10444}, +{21626, 1269}, {21135, 4423}, {11304, 1556}, {19005,12820}, {17367, 2498}, +{17858, 4833}, { 9994, 2498}, {17530, 7864}, {14254, 1884}, {15892, 3153}, +{ 6717, 1802}, {18186,20193}, {18022, 3031}, {16711, 5857}, { 8847, 4014}, +{15892, 8970}, {18022, 1392}, {16711, 4096}, { 8192, 655}, {15237,13926}, +{14254, 3112}, {14090, 4669}, { 5406, 2703}, {13434, 6553}, {12451, 901}, +{12451, 2662}, { 3768, 655}, {14745,23511}, {19169, 2457}, {20152, 5079}, +{ 6881, 4096}, {20480, 8560}, {19660, 737}, {19005, 4259}, { 7864, 2088}, +{11468,12288}, {15892, 1474}, {15728, 4628}, { 9175, 1433}, {16056, 7004}, +{14827, 737}, {15073, 2252}, { 5079, 1228}, {13271,17326}, {16547, 2334}, +{15073, 5816}, { 3932, 3686}, {14254, 8601}, {16875, 778}, {15073, 3809}, +{ 6062, 614}, { 9338, 9256}, {13271, 1761}, {13271, 3522}, { 2457, 1966}, +{11468, 5529}, {10485, 737}, {11632, 3194}, { 1474, 778} +}; + + +// pre-processing tables + +/** impulse response filter tables converted to float from Q15 int32_t + * used for anti-sparseness processing */ +static const float ir_filter_strong_MODE_7k95[AMR_SUBFRAME_SIZE] = { + 0.817169, 0.024445, 0.076447, -0.020844, -0.042175, 0.017761, 0.018433, +-0.038879, 0.107147, -0.179871, 0.138367, -0.015228, -0.059204, 0.091888, +-0.154358, 0.171326, -0.060730, -0.032379, -0.044525, 0.135559, -0.021362, +-0.162811, 0.140656, 0.013794, -0.017975, -0.102295, 0.090118, 0.038666, +-0.036987, -0.079041, 0.052826, 0.112000, -0.136566, -0.029755, 0.134003, +-0.077423, 0.028961, -0.041595, -0.029877, 0.174988, +}; + +static const float ir_filter_strong[AMR_SUBFRAME_SIZE] = { + 0.448303, 0.351501, 0.038696, -0.084259, -0.173065, 0.229309, -0.001068, +-0.085663, -0.092773, 0.147186, 0.090088, -0.257080, 0.115509, 0.044403, + 0.066498, -0.263580, 0.245697, -0.064178, -0.044373, 0.023712, 0.033813, +-0.072784, 0.068787, -0.011078, -0.020569, -0.064178, 0.184509, -0.173370, + 0.032715, 0.095306, -0.154358, 0.162109, -0.071075, -0.113770, 0.211304, +-0.118683, 0.020599, -0.054169, 0.000885, 0.309601, +}; + +static const float ir_filter_medium[AMR_SUBFRAME_SIZE] = { + 0.923889, 0.116913, -0.123169, 0.090698, -0.031982, -0.030579, 0.075592, +-0.092865, 0.085907, -0.068085, 0.053497, -0.049164, 0.052307, -0.054169, + 0.047089, -0.030762, 0.013092, -0.005157, 0.014404, -0.038574, 0.066406, +-0.082581, 0.076996, -0.049469, 0.010498, 0.025208, -0.046661, 0.052612, +-0.050568, 0.051910, -0.062958, 0.080688, -0.093384, 0.088409, -0.060364, + 0.016998, 0.023804, -0.041779, 0.025696, 0.019989, +}; + +static const float * const ir_filters_lookup[2] = { + ir_filter_strong, ir_filter_medium +}; +static const float * const ir_filters_lookup_MODE_7k95[2] = { + ir_filter_strong_MODE_7k95, ir_filter_medium +}; + +// High-pass coefficients + +static const float highpass_zeros[2] = { -2.0, 1.0 }; +static const float highpass_poles[2] = { -1.933105469, 0.935913085 }; +static const float highpass_gain = 0.939819335; + +#endif /* AVCODEC_AMRNBDATA_H */ diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/amrnbdec.c b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/amrnbdec.c new file mode 100644 index 000000000..e2b30d787 --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/amrnbdec.c @@ -0,0 +1,1095 @@ +/* + * AMR narrowband decoder + * Copyright (c) 2006-2007 Robert Swain + * Copyright (c) 2009 Colin McQuillan + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +/** + * @file + * AMR narrowband decoder + * + * This decoder uses floats for simplicity and so is not bit-exact. One + * difference is that differences in phase can accumulate. The test sequences + * in 3GPP TS 26.074 can still be useful. + * + * - Comparing this file's output to the output of the ref decoder gives a + * PSNR of 30 to 80. Plotting the output samples shows a difference in + * phase in some areas. + * + * - Comparing both decoders against their input, this decoder gives a similar + * PSNR. If the test sequence homing frames are removed (this decoder does + * not detect them), the PSNR is at least as good as the reference on 140 + * out of 169 tests. + */ + + +#include +#include + +#include "libavutil/channel_layout.h" +#include "libavutil/float_dsp.h" +#include "libavutil/internal.h" +#include "avcodec.h" +#include "libavutil/common.h" +#include "libavutil/avassert.h" +#include "celp_math.h" +#include "celp_filters.h" +#include "acelp_filters.h" +#include "acelp_vectors.h" +#include "acelp_pitch_delay.h" +#include "lsp.h" +#include "amr.h" +#include "internal.h" + +#include "amrnbdata.h" + +#define AMR_BLOCK_SIZE 160 ///< samples per frame +#define AMR_SAMPLE_BOUND 32768.0 ///< threshold for synthesis overflow + +/** + * Scale from constructed speech to [-1,1] + * + * AMR is designed to produce 16-bit PCM samples (3GPP TS 26.090 4.2) but + * upscales by two (section 6.2.2). + * + * Fundamentally, this scale is determined by energy_mean through + * the fixed vector contribution to the excitation vector. + */ +#define AMR_SAMPLE_SCALE (2.0 / 32768.0) + +/** Prediction factor for 12.2kbit/s mode */ +#define PRED_FAC_MODE_12k2 0.65 + +#define LSF_R_FAC (8000.0 / 32768.0) ///< LSF residual tables to Hertz +#define MIN_LSF_SPACING (50.0488 / 8000.0) ///< Ensures stability of LPC filter +#define PITCH_LAG_MIN_MODE_12k2 18 ///< Lower bound on decoded lag search in 12.2kbit/s mode + +/** Initial energy in dB. Also used for bad frames (unimplemented). */ +#define MIN_ENERGY -14.0 + +/** Maximum sharpening factor + * + * The specification says 0.8, which should be 13107, but the reference C code + * uses 13017 instead. (Amusingly the same applies to SHARP_MAX in g729dec.c.) + */ +#define SHARP_MAX 0.79449462890625 + +/** Number of impulse response coefficients used for tilt factor */ +#define AMR_TILT_RESPONSE 22 +/** Tilt factor = 1st reflection coefficient * gamma_t */ +#define AMR_TILT_GAMMA_T 0.8 +/** Adaptive gain control factor used in post-filter */ +#define AMR_AGC_ALPHA 0.9 + +typedef struct AMRContext { + AMRNBFrame frame; ///< decoded AMR parameters (lsf coefficients, codebook indexes, etc) + uint8_t bad_frame_indicator; ///< bad frame ? 1 : 0 + enum Mode cur_frame_mode; + + int16_t prev_lsf_r[LP_FILTER_ORDER]; ///< residual LSF vector from previous subframe + double lsp[4][LP_FILTER_ORDER]; ///< lsp vectors from current frame + double prev_lsp_sub4[LP_FILTER_ORDER]; ///< lsp vector for the 4th subframe of the previous frame + + float lsf_q[4][LP_FILTER_ORDER]; ///< Interpolated LSF vector for fixed gain smoothing + float lsf_avg[LP_FILTER_ORDER]; ///< vector of averaged lsf vector + + float lpc[4][LP_FILTER_ORDER]; ///< lpc coefficient vectors for 4 subframes + + uint8_t pitch_lag_int; ///< integer part of pitch lag from current subframe + + float excitation_buf[PITCH_DELAY_MAX + LP_FILTER_ORDER + 1 + AMR_SUBFRAME_SIZE]; ///< current excitation and all necessary excitation history + float *excitation; ///< pointer to the current excitation vector in excitation_buf + + float pitch_vector[AMR_SUBFRAME_SIZE]; ///< adaptive code book (pitch) vector + float fixed_vector[AMR_SUBFRAME_SIZE]; ///< algebraic codebook (fixed) vector (must be kept zero between frames) + + float prediction_error[4]; ///< quantified prediction errors {20log10(^gamma_gc)} for previous four subframes + float pitch_gain[5]; ///< quantified pitch gains for the current and previous four subframes + float fixed_gain[5]; ///< quantified fixed gains for the current and previous four subframes + + float beta; ///< previous pitch_gain, bounded by [0.0,SHARP_MAX] + uint8_t diff_count; ///< the number of subframes for which diff has been above 0.65 + uint8_t hang_count; ///< the number of subframes since a hangover period started + + float prev_sparse_fixed_gain; ///< previous fixed gain; used by anti-sparseness processing to determine "onset" + uint8_t prev_ir_filter_nr; ///< previous impulse response filter "impNr": 0 - strong, 1 - medium, 2 - none + uint8_t ir_filter_onset; ///< flag for impulse response filter strength + + float postfilter_mem[10]; ///< previous intermediate values in the formant filter + float tilt_mem; ///< previous input to tilt compensation filter + float postfilter_agc; ///< previous factor used for adaptive gain control + float high_pass_mem[2]; ///< previous intermediate values in the high-pass filter + + float samples_in[LP_FILTER_ORDER + AMR_SUBFRAME_SIZE]; ///< floating point samples + + ACELPFContext acelpf_ctx; ///< context for filters for ACELP-based codecs + ACELPVContext acelpv_ctx; ///< context for vector operations for ACELP-based codecs + CELPFContext celpf_ctx; ///< context for filters for CELP-based codecs + CELPMContext celpm_ctx; ///< context for fixed point math operations + +} AMRContext; + +/** Double version of ff_weighted_vector_sumf() */ +static void weighted_vector_sumd(double *out, const double *in_a, + const double *in_b, double weight_coeff_a, + double weight_coeff_b, int length) +{ + int i; + + for (i = 0; i < length; i++) + out[i] = weight_coeff_a * in_a[i] + + weight_coeff_b * in_b[i]; +} + +static av_cold int amrnb_decode_init(AVCodecContext *avctx) +{ + AMRContext *p = avctx->priv_data; + int i; + + if (avctx->channels > 1) { + avpriv_report_missing_feature(avctx, "multi-channel AMR"); + return AVERROR_PATCHWELCOME; + } + + avctx->channels = 1; + avctx->channel_layout = AV_CH_LAYOUT_MONO; + if (!avctx->sample_rate) + avctx->sample_rate = 8000; + avctx->sample_fmt = AV_SAMPLE_FMT_FLT; + + // p->excitation always points to the same position in p->excitation_buf + p->excitation = &p->excitation_buf[PITCH_DELAY_MAX + LP_FILTER_ORDER + 1]; + + for (i = 0; i < LP_FILTER_ORDER; i++) { + p->prev_lsp_sub4[i] = lsp_sub4_init[i] * 1000 / (float)(1 << 15); + p->lsf_avg[i] = p->lsf_q[3][i] = lsp_avg_init[i] / (float)(1 << 15); + } + + for (i = 0; i < 4; i++) + p->prediction_error[i] = MIN_ENERGY; + + ff_acelp_filter_init(&p->acelpf_ctx); + ff_acelp_vectors_init(&p->acelpv_ctx); + ff_celp_filter_init(&p->celpf_ctx); + ff_celp_math_init(&p->celpm_ctx); + + return 0; +} + + +/** + * Unpack an RFC4867 speech frame into the AMR frame mode and parameters. + * + * The order of speech bits is specified by 3GPP TS 26.101. + * + * @param p the context + * @param buf pointer to the input buffer + * @param buf_size size of the input buffer + * + * @return the frame mode + */ +static enum Mode unpack_bitstream(AMRContext *p, const uint8_t *buf, + int buf_size) +{ + enum Mode mode; + + // Decode the first octet. + mode = buf[0] >> 3 & 0x0F; // frame type + p->bad_frame_indicator = (buf[0] & 0x4) != 0x4; // quality bit + + if (mode >= N_MODES || buf_size < frame_sizes_nb[mode] + 1) { + return NO_DATA; + } + + if (mode < MODE_DTX) + ff_amr_bit_reorder((uint16_t *) &p->frame, sizeof(AMRNBFrame), buf + 1, + amr_unpacking_bitmaps_per_mode[mode]); + + return mode; +} + + +/// @name AMR pitch LPC coefficient decoding functions +/// @{ + +/** + * Interpolate the LSF vector (used for fixed gain smoothing). + * The interpolation is done over all four subframes even in MODE_12k2. + * + * @param[in] ctx The Context + * @param[in,out] lsf_q LSFs in [0,1] for each subframe + * @param[in] lsf_new New LSFs in [0,1] for subframe 4 + */ +static void interpolate_lsf(ACELPVContext *ctx, float lsf_q[4][LP_FILTER_ORDER], float *lsf_new) +{ + int i; + + for (i = 0; i < 4; i++) + ctx->weighted_vector_sumf(lsf_q[i], lsf_q[3], lsf_new, + 0.25 * (3 - i), 0.25 * (i + 1), + LP_FILTER_ORDER); +} + +/** + * Decode a set of 5 split-matrix quantized lsf indexes into an lsp vector. + * + * @param p the context + * @param lsp output LSP vector + * @param lsf_no_r LSF vector without the residual vector added + * @param lsf_quantizer pointers to LSF dictionary tables + * @param quantizer_offset offset in tables + * @param sign for the 3 dictionary table + * @param update store data for computing the next frame's LSFs + */ +static void lsf2lsp_for_mode12k2(AMRContext *p, double lsp[LP_FILTER_ORDER], + const float lsf_no_r[LP_FILTER_ORDER], + const int16_t *lsf_quantizer[5], + const int quantizer_offset, + const int sign, const int update) +{ + int16_t lsf_r[LP_FILTER_ORDER]; // residual LSF vector + float lsf_q[LP_FILTER_ORDER]; // quantified LSF vector + int i; + + for (i = 0; i < LP_FILTER_ORDER >> 1; i++) + memcpy(&lsf_r[i << 1], &lsf_quantizer[i][quantizer_offset], + 2 * sizeof(*lsf_r)); + + if (sign) { + lsf_r[4] *= -1; + lsf_r[5] *= -1; + } + + if (update) + memcpy(p->prev_lsf_r, lsf_r, LP_FILTER_ORDER * sizeof(*lsf_r)); + + for (i = 0; i < LP_FILTER_ORDER; i++) + lsf_q[i] = lsf_r[i] * (LSF_R_FAC / 8000.0) + lsf_no_r[i] * (1.0 / 8000.0); + + ff_set_min_dist_lsf(lsf_q, MIN_LSF_SPACING, LP_FILTER_ORDER); + + if (update) + interpolate_lsf(&p->acelpv_ctx, p->lsf_q, lsf_q); + + ff_acelp_lsf2lspd(lsp, lsf_q, LP_FILTER_ORDER); +} + +/** + * Decode a set of 5 split-matrix quantized lsf indexes into 2 lsp vectors. + * + * @param p pointer to the AMRContext + */ +static void lsf2lsp_5(AMRContext *p) +{ + const uint16_t *lsf_param = p->frame.lsf; + float lsf_no_r[LP_FILTER_ORDER]; // LSFs without the residual vector + const int16_t *lsf_quantizer[5]; + int i; + + lsf_quantizer[0] = lsf_5_1[lsf_param[0]]; + lsf_quantizer[1] = lsf_5_2[lsf_param[1]]; + lsf_quantizer[2] = lsf_5_3[lsf_param[2] >> 1]; + lsf_quantizer[3] = lsf_5_4[lsf_param[3]]; + lsf_quantizer[4] = lsf_5_5[lsf_param[4]]; + + for (i = 0; i < LP_FILTER_ORDER; i++) + lsf_no_r[i] = p->prev_lsf_r[i] * LSF_R_FAC * PRED_FAC_MODE_12k2 + lsf_5_mean[i]; + + lsf2lsp_for_mode12k2(p, p->lsp[1], lsf_no_r, lsf_quantizer, 0, lsf_param[2] & 1, 0); + lsf2lsp_for_mode12k2(p, p->lsp[3], lsf_no_r, lsf_quantizer, 2, lsf_param[2] & 1, 1); + + // interpolate LSP vectors at subframes 1 and 3 + weighted_vector_sumd(p->lsp[0], p->prev_lsp_sub4, p->lsp[1], 0.5, 0.5, LP_FILTER_ORDER); + weighted_vector_sumd(p->lsp[2], p->lsp[1] , p->lsp[3], 0.5, 0.5, LP_FILTER_ORDER); +} + +/** + * Decode a set of 3 split-matrix quantized lsf indexes into an lsp vector. + * + * @param p pointer to the AMRContext + */ +static void lsf2lsp_3(AMRContext *p) +{ + const uint16_t *lsf_param = p->frame.lsf; + int16_t lsf_r[LP_FILTER_ORDER]; // residual LSF vector + float lsf_q[LP_FILTER_ORDER]; // quantified LSF vector + const int16_t *lsf_quantizer; + int i, j; + + lsf_quantizer = (p->cur_frame_mode == MODE_7k95 ? lsf_3_1_MODE_7k95 : lsf_3_1)[lsf_param[0]]; + memcpy(lsf_r, lsf_quantizer, 3 * sizeof(*lsf_r)); + + lsf_quantizer = lsf_3_2[lsf_param[1] << (p->cur_frame_mode <= MODE_5k15)]; + memcpy(lsf_r + 3, lsf_quantizer, 3 * sizeof(*lsf_r)); + + lsf_quantizer = (p->cur_frame_mode <= MODE_5k15 ? lsf_3_3_MODE_5k15 : lsf_3_3)[lsf_param[2]]; + memcpy(lsf_r + 6, lsf_quantizer, 4 * sizeof(*lsf_r)); + + // calculate mean-removed LSF vector and add mean + for (i = 0; i < LP_FILTER_ORDER; i++) + lsf_q[i] = (lsf_r[i] + p->prev_lsf_r[i] * pred_fac[i]) * (LSF_R_FAC / 8000.0) + lsf_3_mean[i] * (1.0 / 8000.0); + + ff_set_min_dist_lsf(lsf_q, MIN_LSF_SPACING, LP_FILTER_ORDER); + + // store data for computing the next frame's LSFs + interpolate_lsf(&p->acelpv_ctx, p->lsf_q, lsf_q); + memcpy(p->prev_lsf_r, lsf_r, LP_FILTER_ORDER * sizeof(*lsf_r)); + + ff_acelp_lsf2lspd(p->lsp[3], lsf_q, LP_FILTER_ORDER); + + // interpolate LSP vectors at subframes 1, 2 and 3 + for (i = 1; i <= 3; i++) + for(j = 0; j < LP_FILTER_ORDER; j++) + p->lsp[i-1][j] = p->prev_lsp_sub4[j] + + (p->lsp[3][j] - p->prev_lsp_sub4[j]) * 0.25 * i; +} + +/// @} + + +/// @name AMR pitch vector decoding functions +/// @{ + +/** + * Like ff_decode_pitch_lag(), but with 1/6 resolution + */ +static void decode_pitch_lag_1_6(int *lag_int, int *lag_frac, int pitch_index, + const int prev_lag_int, const int subframe) +{ + if (subframe == 0 || subframe == 2) { + if (pitch_index < 463) { + *lag_int = (pitch_index + 107) * 10923 >> 16; + *lag_frac = pitch_index - *lag_int * 6 + 105; + } else { + *lag_int = pitch_index - 368; + *lag_frac = 0; + } + } else { + *lag_int = ((pitch_index + 5) * 10923 >> 16) - 1; + *lag_frac = pitch_index - *lag_int * 6 - 3; + *lag_int += av_clip(prev_lag_int - 5, PITCH_LAG_MIN_MODE_12k2, + PITCH_DELAY_MAX - 9); + } +} + +static void decode_pitch_vector(AMRContext *p, + const AMRNBSubframe *amr_subframe, + const int subframe) +{ + int pitch_lag_int, pitch_lag_frac; + enum Mode mode = p->cur_frame_mode; + + if (p->cur_frame_mode == MODE_12k2) { + decode_pitch_lag_1_6(&pitch_lag_int, &pitch_lag_frac, + amr_subframe->p_lag, p->pitch_lag_int, + subframe); + } else + ff_decode_pitch_lag(&pitch_lag_int, &pitch_lag_frac, + amr_subframe->p_lag, + p->pitch_lag_int, subframe, + mode != MODE_4k75 && mode != MODE_5k15, + mode <= MODE_6k7 ? 4 : (mode == MODE_7k95 ? 5 : 6)); + + p->pitch_lag_int = pitch_lag_int; // store previous lag in a uint8_t + + pitch_lag_frac <<= (p->cur_frame_mode != MODE_12k2); + + pitch_lag_int += pitch_lag_frac > 0; + + /* Calculate the pitch vector by interpolating the past excitation at the + pitch lag using a b60 hamming windowed sinc function. */ + p->acelpf_ctx.acelp_interpolatef(p->excitation, + p->excitation + 1 - pitch_lag_int, + ff_b60_sinc, 6, + pitch_lag_frac + 6 - 6*(pitch_lag_frac > 0), + 10, AMR_SUBFRAME_SIZE); + + memcpy(p->pitch_vector, p->excitation, AMR_SUBFRAME_SIZE * sizeof(float)); +} + +/// @} + + +/// @name AMR algebraic code book (fixed) vector decoding functions +/// @{ + +/** + * Decode a 10-bit algebraic codebook index from a 10.2 kbit/s frame. + */ +static void decode_10bit_pulse(int code, int pulse_position[8], + int i1, int i2, int i3) +{ + // coded using 7+3 bits with the 3 LSBs being, individually, the LSB of 1 of + // the 3 pulses and the upper 7 bits being coded in base 5 + const uint8_t *positions = base_five_table[code >> 3]; + pulse_position[i1] = (positions[2] << 1) + ( code & 1); + pulse_position[i2] = (positions[1] << 1) + ((code >> 1) & 1); + pulse_position[i3] = (positions[0] << 1) + ((code >> 2) & 1); +} + +/** + * Decode the algebraic codebook index to pulse positions and signs and + * construct the algebraic codebook vector for MODE_10k2. + * + * @param fixed_index positions of the eight pulses + * @param fixed_sparse pointer to the algebraic codebook vector + */ +static void decode_8_pulses_31bits(const int16_t *fixed_index, + AMRFixed *fixed_sparse) +{ + int pulse_position[8]; + int i, temp; + + decode_10bit_pulse(fixed_index[4], pulse_position, 0, 4, 1); + decode_10bit_pulse(fixed_index[5], pulse_position, 2, 6, 5); + + // coded using 5+2 bits with the 2 LSBs being, individually, the LSB of 1 of + // the 2 pulses and the upper 5 bits being coded in base 5 + temp = ((fixed_index[6] >> 2) * 25 + 12) >> 5; + pulse_position[3] = temp % 5; + pulse_position[7] = temp / 5; + if (pulse_position[7] & 1) + pulse_position[3] = 4 - pulse_position[3]; + pulse_position[3] = (pulse_position[3] << 1) + ( fixed_index[6] & 1); + pulse_position[7] = (pulse_position[7] << 1) + ((fixed_index[6] >> 1) & 1); + + fixed_sparse->n = 8; + for (i = 0; i < 4; i++) { + const int pos1 = (pulse_position[i] << 2) + i; + const int pos2 = (pulse_position[i + 4] << 2) + i; + const float sign = fixed_index[i] ? -1.0 : 1.0; + fixed_sparse->x[i ] = pos1; + fixed_sparse->x[i + 4] = pos2; + fixed_sparse->y[i ] = sign; + fixed_sparse->y[i + 4] = pos2 < pos1 ? -sign : sign; + } +} + +/** + * Decode the algebraic codebook index to pulse positions and signs, + * then construct the algebraic codebook vector. + * + * nb of pulses | bits encoding pulses + * For MODE_4k75 or MODE_5k15, 2 | 1-3, 4-6, 7 + * MODE_5k9, 2 | 1, 2-4, 5-6, 7-9 + * MODE_6k7, 3 | 1-3, 4, 5-7, 8, 9-11 + * MODE_7k4 or MODE_7k95, 4 | 1-3, 4-6, 7-9, 10, 11-13 + * + * @param fixed_sparse pointer to the algebraic codebook vector + * @param pulses algebraic codebook indexes + * @param mode mode of the current frame + * @param subframe current subframe number + */ +static void decode_fixed_sparse(AMRFixed *fixed_sparse, const uint16_t *pulses, + const enum Mode mode, const int subframe) +{ + av_assert1(MODE_4k75 <= (signed)mode && mode <= MODE_12k2); + + if (mode == MODE_12k2) { + ff_decode_10_pulses_35bits((const int16_t *) pulses, fixed_sparse, gray_decode, 5, 3); + } else if (mode == MODE_10k2) { + decode_8_pulses_31bits((const int16_t *) pulses, fixed_sparse); + } else { + int *pulse_position = fixed_sparse->x; + int i, pulse_subset; + const int fixed_index = pulses[0]; + + if (mode <= MODE_5k15) { + pulse_subset = ((fixed_index >> 3) & 8) + (subframe << 1); + pulse_position[0] = ( fixed_index & 7) * 5 + track_position[pulse_subset]; + pulse_position[1] = ((fixed_index >> 3) & 7) * 5 + track_position[pulse_subset + 1]; + fixed_sparse->n = 2; + } else if (mode == MODE_5k9) { + pulse_subset = ((fixed_index & 1) << 1) + 1; + pulse_position[0] = ((fixed_index >> 1) & 7) * 5 + pulse_subset; + pulse_subset = (fixed_index >> 4) & 3; + pulse_position[1] = ((fixed_index >> 6) & 7) * 5 + pulse_subset + (pulse_subset == 3 ? 1 : 0); + fixed_sparse->n = pulse_position[0] == pulse_position[1] ? 1 : 2; + } else if (mode == MODE_6k7) { + pulse_position[0] = (fixed_index & 7) * 5; + pulse_subset = (fixed_index >> 2) & 2; + pulse_position[1] = ((fixed_index >> 4) & 7) * 5 + pulse_subset + 1; + pulse_subset = (fixed_index >> 6) & 2; + pulse_position[2] = ((fixed_index >> 8) & 7) * 5 + pulse_subset + 2; + fixed_sparse->n = 3; + } else { // mode <= MODE_7k95 + pulse_position[0] = gray_decode[ fixed_index & 7]; + pulse_position[1] = gray_decode[(fixed_index >> 3) & 7] + 1; + pulse_position[2] = gray_decode[(fixed_index >> 6) & 7] + 2; + pulse_subset = (fixed_index >> 9) & 1; + pulse_position[3] = gray_decode[(fixed_index >> 10) & 7] + pulse_subset + 3; + fixed_sparse->n = 4; + } + for (i = 0; i < fixed_sparse->n; i++) + fixed_sparse->y[i] = (pulses[1] >> i) & 1 ? 1.0 : -1.0; + } +} + +/** + * Apply pitch lag to obtain the sharpened fixed vector (section 6.1.2) + * + * @param p the context + * @param subframe unpacked amr subframe + * @param mode mode of the current frame + * @param fixed_sparse sparse respresentation of the fixed vector + */ +static void pitch_sharpening(AMRContext *p, int subframe, enum Mode mode, + AMRFixed *fixed_sparse) +{ + // The spec suggests the current pitch gain is always used, but in other + // modes the pitch and codebook gains are joinly quantized (sec 5.8.2) + // so the codebook gain cannot depend on the quantized pitch gain. + if (mode == MODE_12k2) + p->beta = FFMIN(p->pitch_gain[4], 1.0); + + fixed_sparse->pitch_lag = p->pitch_lag_int; + fixed_sparse->pitch_fac = p->beta; + + // Save pitch sharpening factor for the next subframe + // MODE_4k75 only updates on the 2nd and 4th subframes - this follows from + // the fact that the gains for two subframes are jointly quantized. + if (mode != MODE_4k75 || subframe & 1) + p->beta = av_clipf(p->pitch_gain[4], 0.0, SHARP_MAX); +} +/// @} + + +/// @name AMR gain decoding functions +/// @{ + +/** + * fixed gain smoothing + * Note that where the spec specifies the "spectrum in the q domain" + * in section 6.1.4, in fact frequencies should be used. + * + * @param p the context + * @param lsf LSFs for the current subframe, in the range [0,1] + * @param lsf_avg averaged LSFs + * @param mode mode of the current frame + * + * @return fixed gain smoothed + */ +static float fixed_gain_smooth(AMRContext *p , const float *lsf, + const float *lsf_avg, const enum Mode mode) +{ + float diff = 0.0; + int i; + + for (i = 0; i < LP_FILTER_ORDER; i++) + diff += fabs(lsf_avg[i] - lsf[i]) / lsf_avg[i]; + + // If diff is large for ten subframes, disable smoothing for a 40-subframe + // hangover period. + p->diff_count++; + if (diff <= 0.65) + p->diff_count = 0; + + if (p->diff_count > 10) { + p->hang_count = 0; + p->diff_count--; // don't let diff_count overflow + } + + if (p->hang_count < 40) { + p->hang_count++; + } else if (mode < MODE_7k4 || mode == MODE_10k2) { + const float smoothing_factor = av_clipf(4.0 * diff - 1.6, 0.0, 1.0); + const float fixed_gain_mean = (p->fixed_gain[0] + p->fixed_gain[1] + + p->fixed_gain[2] + p->fixed_gain[3] + + p->fixed_gain[4]) * 0.2; + return smoothing_factor * p->fixed_gain[4] + + (1.0 - smoothing_factor) * fixed_gain_mean; + } + return p->fixed_gain[4]; +} + +/** + * Decode pitch gain and fixed gain factor (part of section 6.1.3). + * + * @param p the context + * @param amr_subframe unpacked amr subframe + * @param mode mode of the current frame + * @param subframe current subframe number + * @param fixed_gain_factor decoded gain correction factor + */ +static void decode_gains(AMRContext *p, const AMRNBSubframe *amr_subframe, + const enum Mode mode, const int subframe, + float *fixed_gain_factor) +{ + if (mode == MODE_12k2 || mode == MODE_7k95) { + p->pitch_gain[4] = qua_gain_pit [amr_subframe->p_gain ] + * (1.0 / 16384.0); + *fixed_gain_factor = qua_gain_code[amr_subframe->fixed_gain] + * (1.0 / 2048.0); + } else { + const uint16_t *gains; + + if (mode >= MODE_6k7) { + gains = gains_high[amr_subframe->p_gain]; + } else if (mode >= MODE_5k15) { + gains = gains_low [amr_subframe->p_gain]; + } else { + // gain index is only coded in subframes 0,2 for MODE_4k75 + gains = gains_MODE_4k75[(p->frame.subframe[subframe & 2].p_gain << 1) + (subframe & 1)]; + } + + p->pitch_gain[4] = gains[0] * (1.0 / 16384.0); + *fixed_gain_factor = gains[1] * (1.0 / 4096.0); + } +} + +/// @} + + +/// @name AMR preprocessing functions +/// @{ + +/** + * Circularly convolve a sparse fixed vector with a phase dispersion impulse + * response filter (D.6.2 of G.729 and 6.1.5 of AMR). + * + * @param out vector with filter applied + * @param in source vector + * @param filter phase filter coefficients + * + * out[n] = sum(i,0,len-1){ in[i] * filter[(len + n - i)%len] } + */ +static void apply_ir_filter(float *out, const AMRFixed *in, + const float *filter) +{ + float filter1[AMR_SUBFRAME_SIZE], ///< filters at pitch lag*1 and *2 + filter2[AMR_SUBFRAME_SIZE]; + int lag = in->pitch_lag; + float fac = in->pitch_fac; + int i; + + if (lag < AMR_SUBFRAME_SIZE) { + ff_celp_circ_addf(filter1, filter, filter, lag, fac, + AMR_SUBFRAME_SIZE); + + if (lag < AMR_SUBFRAME_SIZE >> 1) + ff_celp_circ_addf(filter2, filter, filter1, lag, fac, + AMR_SUBFRAME_SIZE); + } + + memset(out, 0, sizeof(float) * AMR_SUBFRAME_SIZE); + for (i = 0; i < in->n; i++) { + int x = in->x[i]; + float y = in->y[i]; + const float *filterp; + + if (x >= AMR_SUBFRAME_SIZE - lag) { + filterp = filter; + } else if (x >= AMR_SUBFRAME_SIZE - (lag << 1)) { + filterp = filter1; + } else + filterp = filter2; + + ff_celp_circ_addf(out, out, filterp, x, y, AMR_SUBFRAME_SIZE); + } +} + +/** + * Reduce fixed vector sparseness by smoothing with one of three IR filters. + * Also know as "adaptive phase dispersion". + * + * This implements 3GPP TS 26.090 section 6.1(5). + * + * @param p the context + * @param fixed_sparse algebraic codebook vector + * @param fixed_vector unfiltered fixed vector + * @param fixed_gain smoothed gain + * @param out space for modified vector if necessary + */ +static const float *anti_sparseness(AMRContext *p, AMRFixed *fixed_sparse, + const float *fixed_vector, + float fixed_gain, float *out) +{ + int ir_filter_nr; + + if (p->pitch_gain[4] < 0.6) { + ir_filter_nr = 0; // strong filtering + } else if (p->pitch_gain[4] < 0.9) { + ir_filter_nr = 1; // medium filtering + } else + ir_filter_nr = 2; // no filtering + + // detect 'onset' + if (fixed_gain > 2.0 * p->prev_sparse_fixed_gain) { + p->ir_filter_onset = 2; + } else if (p->ir_filter_onset) + p->ir_filter_onset--; + + if (!p->ir_filter_onset) { + int i, count = 0; + + for (i = 0; i < 5; i++) + if (p->pitch_gain[i] < 0.6) + count++; + if (count > 2) + ir_filter_nr = 0; + + if (ir_filter_nr > p->prev_ir_filter_nr + 1) + ir_filter_nr--; + } else if (ir_filter_nr < 2) + ir_filter_nr++; + + // Disable filtering for very low level of fixed_gain. + // Note this step is not specified in the technical description but is in + // the reference source in the function Ph_disp. + if (fixed_gain < 5.0) + ir_filter_nr = 2; + + if (p->cur_frame_mode != MODE_7k4 && p->cur_frame_mode < MODE_10k2 + && ir_filter_nr < 2) { + apply_ir_filter(out, fixed_sparse, + (p->cur_frame_mode == MODE_7k95 ? + ir_filters_lookup_MODE_7k95 : + ir_filters_lookup)[ir_filter_nr]); + fixed_vector = out; + } + + // update ir filter strength history + p->prev_ir_filter_nr = ir_filter_nr; + p->prev_sparse_fixed_gain = fixed_gain; + + return fixed_vector; +} + +/// @} + + +/// @name AMR synthesis functions +/// @{ + +/** + * Conduct 10th order linear predictive coding synthesis. + * + * @param p pointer to the AMRContext + * @param lpc pointer to the LPC coefficients + * @param fixed_gain fixed codebook gain for synthesis + * @param fixed_vector algebraic codebook vector + * @param samples pointer to the output speech samples + * @param overflow 16-bit overflow flag + */ +static int synthesis(AMRContext *p, float *lpc, + float fixed_gain, const float *fixed_vector, + float *samples, uint8_t overflow) +{ + int i; + float excitation[AMR_SUBFRAME_SIZE]; + + // if an overflow has been detected, the pitch vector is scaled down by a + // factor of 4 + if (overflow) + for (i = 0; i < AMR_SUBFRAME_SIZE; i++) + p->pitch_vector[i] *= 0.25; + + p->acelpv_ctx.weighted_vector_sumf(excitation, p->pitch_vector, fixed_vector, + p->pitch_gain[4], fixed_gain, AMR_SUBFRAME_SIZE); + + // emphasize pitch vector contribution + if (p->pitch_gain[4] > 0.5 && !overflow) { + float energy = p->celpm_ctx.dot_productf(excitation, excitation, + AMR_SUBFRAME_SIZE); + float pitch_factor = + p->pitch_gain[4] * + (p->cur_frame_mode == MODE_12k2 ? + 0.25 * FFMIN(p->pitch_gain[4], 1.0) : + 0.5 * FFMIN(p->pitch_gain[4], SHARP_MAX)); + + for (i = 0; i < AMR_SUBFRAME_SIZE; i++) + excitation[i] += pitch_factor * p->pitch_vector[i]; + + ff_scale_vector_to_given_sum_of_squares(excitation, excitation, energy, + AMR_SUBFRAME_SIZE); + } + + p->celpf_ctx.celp_lp_synthesis_filterf(samples, lpc, excitation, + AMR_SUBFRAME_SIZE, + LP_FILTER_ORDER); + + // detect overflow + for (i = 0; i < AMR_SUBFRAME_SIZE; i++) + if (fabsf(samples[i]) > AMR_SAMPLE_BOUND) { + return 1; + } + + return 0; +} + +/// @} + + +/// @name AMR update functions +/// @{ + +/** + * Update buffers and history at the end of decoding a subframe. + * + * @param p pointer to the AMRContext + */ +static void update_state(AMRContext *p) +{ + memcpy(p->prev_lsp_sub4, p->lsp[3], LP_FILTER_ORDER * sizeof(p->lsp[3][0])); + + memmove(&p->excitation_buf[0], &p->excitation_buf[AMR_SUBFRAME_SIZE], + (PITCH_DELAY_MAX + LP_FILTER_ORDER + 1) * sizeof(float)); + + memmove(&p->pitch_gain[0], &p->pitch_gain[1], 4 * sizeof(float)); + memmove(&p->fixed_gain[0], &p->fixed_gain[1], 4 * sizeof(float)); + + memmove(&p->samples_in[0], &p->samples_in[AMR_SUBFRAME_SIZE], + LP_FILTER_ORDER * sizeof(float)); +} + +/// @} + + +/// @name AMR Postprocessing functions +/// @{ + +/** + * Get the tilt factor of a formant filter from its transfer function + * + * @param p The Context + * @param lpc_n LP_FILTER_ORDER coefficients of the numerator + * @param lpc_d LP_FILTER_ORDER coefficients of the denominator + */ +static float tilt_factor(AMRContext *p, float *lpc_n, float *lpc_d) +{ + float rh0, rh1; // autocorrelation at lag 0 and 1 + + // LP_FILTER_ORDER prior zeros are needed for ff_celp_lp_synthesis_filterf + float impulse_buffer[LP_FILTER_ORDER + AMR_TILT_RESPONSE] = { 0 }; + float *hf = impulse_buffer + LP_FILTER_ORDER; // start of impulse response + + hf[0] = 1.0; + memcpy(hf + 1, lpc_n, sizeof(float) * LP_FILTER_ORDER); + p->celpf_ctx.celp_lp_synthesis_filterf(hf, lpc_d, hf, + AMR_TILT_RESPONSE, + LP_FILTER_ORDER); + + rh0 = p->celpm_ctx.dot_productf(hf, hf, AMR_TILT_RESPONSE); + rh1 = p->celpm_ctx.dot_productf(hf, hf + 1, AMR_TILT_RESPONSE - 1); + + // The spec only specifies this check for 12.2 and 10.2 kbit/s + // modes. But in the ref source the tilt is always non-negative. + return rh1 >= 0.0 ? rh1 / rh0 * AMR_TILT_GAMMA_T : 0.0; +} + +/** + * Perform adaptive post-filtering to enhance the quality of the speech. + * See section 6.2.1. + * + * @param p pointer to the AMRContext + * @param lpc interpolated LP coefficients for this subframe + * @param buf_out output of the filter + */ +static void postfilter(AMRContext *p, float *lpc, float *buf_out) +{ + int i; + float *samples = p->samples_in + LP_FILTER_ORDER; // Start of input + + float speech_gain = p->celpm_ctx.dot_productf(samples, samples, + AMR_SUBFRAME_SIZE); + + float pole_out[AMR_SUBFRAME_SIZE + LP_FILTER_ORDER]; // Output of pole filter + const float *gamma_n, *gamma_d; // Formant filter factor table + float lpc_n[LP_FILTER_ORDER], lpc_d[LP_FILTER_ORDER]; // Transfer function coefficients + + if (p->cur_frame_mode == MODE_12k2 || p->cur_frame_mode == MODE_10k2) { + gamma_n = ff_pow_0_7; + gamma_d = ff_pow_0_75; + } else { + gamma_n = ff_pow_0_55; + gamma_d = ff_pow_0_7; + } + + for (i = 0; i < LP_FILTER_ORDER; i++) { + lpc_n[i] = lpc[i] * gamma_n[i]; + lpc_d[i] = lpc[i] * gamma_d[i]; + } + + memcpy(pole_out, p->postfilter_mem, sizeof(float) * LP_FILTER_ORDER); + p->celpf_ctx.celp_lp_synthesis_filterf(pole_out + LP_FILTER_ORDER, lpc_d, samples, + AMR_SUBFRAME_SIZE, LP_FILTER_ORDER); + memcpy(p->postfilter_mem, pole_out + AMR_SUBFRAME_SIZE, + sizeof(float) * LP_FILTER_ORDER); + + p->celpf_ctx.celp_lp_zero_synthesis_filterf(buf_out, lpc_n, + pole_out + LP_FILTER_ORDER, + AMR_SUBFRAME_SIZE, LP_FILTER_ORDER); + + ff_tilt_compensation(&p->tilt_mem, tilt_factor(p, lpc_n, lpc_d), buf_out, + AMR_SUBFRAME_SIZE); + + ff_adaptive_gain_control(buf_out, buf_out, speech_gain, AMR_SUBFRAME_SIZE, + AMR_AGC_ALPHA, &p->postfilter_agc); +} + +/// @} + +static int amrnb_decode_frame(AVCodecContext *avctx, void *data, + int *got_frame_ptr, AVPacket *avpkt) +{ + + AMRContext *p = avctx->priv_data; // pointer to private data + AVFrame *frame = data; + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + float *buf_out; // pointer to the output data buffer + int i, subframe, ret; + float fixed_gain_factor; + AMRFixed fixed_sparse = {0}; // fixed vector up to anti-sparseness processing + float spare_vector[AMR_SUBFRAME_SIZE]; // extra stack space to hold result from anti-sparseness processing + float synth_fixed_gain; // the fixed gain that synthesis should use + const float *synth_fixed_vector; // pointer to the fixed vector that synthesis should use + + /* get output buffer */ + frame->nb_samples = AMR_BLOCK_SIZE; + if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) + return ret; + buf_out = (float *)frame->data[0]; + + p->cur_frame_mode = unpack_bitstream(p, buf, buf_size); + if (p->cur_frame_mode == NO_DATA) { + av_log(avctx, AV_LOG_ERROR, "Corrupt bitstream\n"); + return AVERROR_INVALIDDATA; + } + if (p->cur_frame_mode == MODE_DTX) { + avpriv_report_missing_feature(avctx, "dtx mode"); + av_log(avctx, AV_LOG_INFO, "Note: libopencore_amrnb supports dtx\n"); + return AVERROR_PATCHWELCOME; + } + + if (p->cur_frame_mode == MODE_12k2) { + lsf2lsp_5(p); + } else + lsf2lsp_3(p); + + for (i = 0; i < 4; i++) + ff_acelp_lspd2lpc(p->lsp[i], p->lpc[i], 5); + + for (subframe = 0; subframe < 4; subframe++) { + const AMRNBSubframe *amr_subframe = &p->frame.subframe[subframe]; + + decode_pitch_vector(p, amr_subframe, subframe); + + decode_fixed_sparse(&fixed_sparse, amr_subframe->pulses, + p->cur_frame_mode, subframe); + + // The fixed gain (section 6.1.3) depends on the fixed vector + // (section 6.1.2), but the fixed vector calculation uses + // pitch sharpening based on the on the pitch gain (section 6.1.3). + // So the correct order is: pitch gain, pitch sharpening, fixed gain. + decode_gains(p, amr_subframe, p->cur_frame_mode, subframe, + &fixed_gain_factor); + + pitch_sharpening(p, subframe, p->cur_frame_mode, &fixed_sparse); + + if (fixed_sparse.pitch_lag == 0) { + av_log(avctx, AV_LOG_ERROR, "The file is corrupted, pitch_lag = 0 is not allowed\n"); + return AVERROR_INVALIDDATA; + } + ff_set_fixed_vector(p->fixed_vector, &fixed_sparse, 1.0, + AMR_SUBFRAME_SIZE); + + p->fixed_gain[4] = + ff_amr_set_fixed_gain(fixed_gain_factor, + p->celpm_ctx.dot_productf(p->fixed_vector, + p->fixed_vector, + AMR_SUBFRAME_SIZE) / + AMR_SUBFRAME_SIZE, + p->prediction_error, + energy_mean[p->cur_frame_mode], energy_pred_fac); + + // The excitation feedback is calculated without any processing such + // as fixed gain smoothing. This isn't mentioned in the specification. + for (i = 0; i < AMR_SUBFRAME_SIZE; i++) + p->excitation[i] *= p->pitch_gain[4]; + ff_set_fixed_vector(p->excitation, &fixed_sparse, p->fixed_gain[4], + AMR_SUBFRAME_SIZE); + + // In the ref decoder, excitation is stored with no fractional bits. + // This step prevents buzz in silent periods. The ref encoder can + // emit long sequences with pitch factor greater than one. This + // creates unwanted feedback if the excitation vector is nonzero. + // (e.g. test sequence T19_795.COD in 3GPP TS 26.074) + for (i = 0; i < AMR_SUBFRAME_SIZE; i++) + p->excitation[i] = truncf(p->excitation[i]); + + // Smooth fixed gain. + // The specification is ambiguous, but in the reference source, the + // smoothed value is NOT fed back into later fixed gain smoothing. + synth_fixed_gain = fixed_gain_smooth(p, p->lsf_q[subframe], + p->lsf_avg, p->cur_frame_mode); + + synth_fixed_vector = anti_sparseness(p, &fixed_sparse, p->fixed_vector, + synth_fixed_gain, spare_vector); + + if (synthesis(p, p->lpc[subframe], synth_fixed_gain, + synth_fixed_vector, &p->samples_in[LP_FILTER_ORDER], 0)) + // overflow detected -> rerun synthesis scaling pitch vector down + // by a factor of 4, skipping pitch vector contribution emphasis + // and adaptive gain control + synthesis(p, p->lpc[subframe], synth_fixed_gain, + synth_fixed_vector, &p->samples_in[LP_FILTER_ORDER], 1); + + postfilter(p, p->lpc[subframe], buf_out + subframe * AMR_SUBFRAME_SIZE); + + // update buffers and history + ff_clear_fixed_vector(p->fixed_vector, &fixed_sparse, AMR_SUBFRAME_SIZE); + update_state(p); + } + + p->acelpf_ctx.acelp_apply_order_2_transfer_function(buf_out, + buf_out, highpass_zeros, + highpass_poles, + highpass_gain * AMR_SAMPLE_SCALE, + p->high_pass_mem, AMR_BLOCK_SIZE); + + /* Update averaged lsf vector (used for fixed gain smoothing). + * + * Note that lsf_avg should not incorporate the current frame's LSFs + * for fixed_gain_smooth. + * The specification has an incorrect formula: the reference decoder uses + * qbar(n-1) rather than qbar(n) in section 6.1(4) equation 71. */ + p->acelpv_ctx.weighted_vector_sumf(p->lsf_avg, p->lsf_avg, p->lsf_q[3], + 0.84, 0.16, LP_FILTER_ORDER); + + *got_frame_ptr = 1; + + /* return the amount of bytes consumed if everything was OK */ + return frame_sizes_nb[p->cur_frame_mode] + 1; // +7 for rounding and +8 for TOC +} + + +AVCodec ff_amrnb_decoder = { + .name = "amrnb", + .long_name = NULL_IF_CONFIG_SMALL("AMR-NB (Adaptive Multi-Rate NarrowBand)"), + .type = AVMEDIA_TYPE_AUDIO, + .id = AV_CODEC_ID_AMR_NB, + .priv_data_size = sizeof(AMRContext), + .init = amrnb_decode_init, + .decode = amrnb_decode_frame, + .capabilities = CODEC_CAP_DR1, + .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLT, + AV_SAMPLE_FMT_NONE }, +}; diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/amrwbdata.h b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/amrwbdata.h new file mode 100644 index 000000000..8390582b0 --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/amrwbdata.h @@ -0,0 +1,1890 @@ +/* + * AMR wideband data and definitions + * Copyright (c) 2010 Marcelo Galvao Povoa + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * AMR wideband data and definitions + */ + +#ifndef AVCODEC_AMRWBDATA_H +#define AVCODEC_AMRWBDATA_H + +#include +#include + +#define LP_ORDER 16 ///< linear predictive coding filter order +#define LP_ORDER_16k 20 ///< lpc filter order at 16kHz +#define HB_FIR_SIZE 30 ///< amount of past data needed by HB filters +#define UPS_FIR_SIZE 12 ///< upsampling filter size +#define UPS_MEM_SIZE (2 * UPS_FIR_SIZE) + +#define MIN_ISF_SPACING (128.0 / 32768.0) ///< minimum isf gap +#define PRED_FACTOR (1.0 / 3.0) +#define MIN_ENERGY -14.0 ///< initial innnovation energy (dB) +#define ENERGY_MEAN 30.0 ///< mean innovation energy (dB) in all modes +#define PREEMPH_FAC 0.68 ///< factor used to de-emphasize synthesis + +#define AMRWB_SFR_SIZE 64 ///< samples per subframe at 12.8 kHz +#define AMRWB_SFR_SIZE_16k 80 ///< samples per subframe at 16 kHz +#define AMRWB_P_DELAY_MAX 231 ///< maximum pitch delay value +#define AMRWB_P_DELAY_MIN 34 + +/* Relative mode ordering is sensitive */ +enum Mode { + MODE_6k60 = 0, ///< 6.60 kbit/s + MODE_8k85, ///< 8.85 kbit/s + MODE_12k65, ///< 12.65 kbit/s + MODE_14k25, ///< 14.25 kbit/s + MODE_15k85, ///< 15.85 kbit/s + MODE_18k25, ///< 18.25 kbit/s + MODE_19k85, ///< 19.85 kbit/s + MODE_23k05, ///< 23.05 kbit/s + MODE_23k85, ///< 23.85 kbit/s + MODE_SID, ///< comfort noise frame + /* 10-13: Future use */ + SP_LOST = 14, ///< speech lost + NO_DATA ///< no transmission +}; + +/* All decoded parameters in these structs must be 2 bytes long + * because of the direct indexing at the frame parsing */ +typedef struct AMRWBSubFrame { + uint16_t adap; ///< adaptive codebook index + uint16_t ltp; ///< ltp-filtering flag + uint16_t vq_gain; ///< VQ adaptive and innovative gains + uint16_t hb_gain; ///< high-band energy index (mode 23k85 only) + uint16_t pul_ih[4]; ///< MSBs part of codebook index (high modes only) + uint16_t pul_il[4]; ///< LSBs part of codebook index +} AMRWBSubFrame; + +typedef struct AMRWBFrame { + uint16_t vad; ///< voice activity detection flag + uint16_t isp_id[7]; ///< index of ISP subvectors + AMRWBSubFrame subframe[4]; ///< data for subframes +} AMRWBFrame; + +/** The index of a frame parameter */ +#define AMR_BIT(field) (offsetof(AMRWBFrame, field)) +/** The index of a subframe-specific parameter */ +#define AMR_OF(frame_num, variable) AMR_BIT(subframe[frame_num].variable) + +//As defined in 3GPP TS 26.201 V9.0.0 +//Tables for bit parsing in Core Frame speech frames +//The reordered bits are in order of decreasing importance and +//may be contiguously separated in Class A, B and C bits. + +// Each field in AMRWBFrame is stored as: +// * one byte for the number of bits in the field +// * one byte for the field index +// * then, one byte for each bit of the field (from most-significant to least) +// of the position of that bit in the AMR frame. +static const uint16_t order_MODE_6k60[] = { + 1, AMR_BIT(vad), 7, + 8, AMR_BIT(isp_id[0]), 24, 33, 39, 12, 6, 5, 4, 13, + 8, AMR_BIT(isp_id[1]), 65, 79, 64, 78, 51, 61, 71, 70, + 7, AMR_BIT(isp_id[2]), 52, 55, 44, 54, 53, 43, 42, + 7, AMR_BIT(isp_id[3]), 60, 59, 58, 57, 56, 75, 74, + 6, AMR_BIT(isp_id[4]), 73, 72, 86, 87, 85, 84, + 8, AMR_OF(0, adap), 11, 10, 9, 8, 28, 27, 49, 69, + 6, AMR_OF(0, pul_il[0]), 83, 91, 99, 107, 115, 123, + 6, AMR_OF(0, pul_il[1]), 82, 103, 111, 119, 127, 135, + 6, AMR_OF(0, vq_gain), 38, 23, 34, 19, 3, 15, + 5, AMR_OF(1, adap), 32, 41, 63, 67, 77, + 6, AMR_OF(1, pul_il[0]), 81, 90, 98, 106, 114, 122, + 6, AMR_OF(1, pul_il[1]), 80, 102, 110, 118, 126, 134, + 6, AMR_OF(1, vq_gain), 26, 22, 36, 18, 2, 14, + 5, AMR_OF(2, adap), 45, 40, 50, 48, 68, + 6, AMR_OF(2, pul_il[0]), 95, 89, 97, 105, 113, 121, + 6, AMR_OF(2, pul_il[1]), 94, 101, 109, 117, 125, 133, + 6, AMR_OF(2, vq_gain), 37, 21, 35, 17, 1, 31, + 5, AMR_OF(3, adap), 47, 46, 62, 66, 76, + 6, AMR_OF(3, pul_il[0]), 93, 88, 96, 104, 112, 120, + 6, AMR_OF(3, pul_il[1]), 92, 100, 108, 116, 124, 132, + 6, AMR_OF(3, vq_gain), 25, 20, 29, 16, 0, 30, + 0 +}; + +static const uint16_t order_MODE_8k85[] = { + 1, AMR_BIT(vad), 7, + 8, AMR_BIT(isp_id[0]), 47, 32, 2, 6, 3, 5, 4, 60, + 8, AMR_BIT(isp_id[1]), 69, 50, 67, 41, 51, 49, 59, 53, + 6, AMR_BIT(isp_id[2]), 40, 55, 43, 54, 42, 62, + 7, AMR_BIT(isp_id[3]), 63, 48, 52, 61, 77, 78, 72, + 7, AMR_BIT(isp_id[4]), 85, 56, 86, 68, 74, 73, 81, + 5, AMR_BIT(isp_id[5]), 82, 95, 80, 94, 91, + 5, AMR_BIT(isp_id[6]), 90, 89, 88, 103, 87, + 8, AMR_OF(0, adap), 1, 0, 15, 35, 33, 58, 64, 84, + 5, AMR_OF(0, pul_il[0]), 102, 118, 134, 150, 166, + 5, AMR_OF(0, pul_il[1]), 101, 114, 130, 146, 162, + 5, AMR_OF(0, pul_il[2]), 100, 126, 142, 158, 174, + 5, AMR_OF(0, pul_il[3]), 99, 122, 138, 154, 170, + 6, AMR_OF(0, vq_gain), 11, 39, 19, 31, 27, 23, + 5, AMR_OF(1, adap), 46, 71, 66, 76, 93, + 5, AMR_OF(1, pul_il[0]), 98, 117, 133, 149, 165, + 5, AMR_OF(1, pul_il[1]), 97, 113, 129, 145, 161, + 5, AMR_OF(1, pul_il[2]), 96, 125, 141, 157, 173, + 5, AMR_OF(1, pul_il[3]), 111, 121, 137, 153, 169, + 6, AMR_OF(1, vq_gain), 10, 38, 18, 30, 26, 22, + 8, AMR_OF(2, adap), 14, 13, 12, 34, 45, 57, 79, 83, + 5, AMR_OF(2, pul_il[0]), 110, 116, 132, 148, 164, + 5, AMR_OF(2, pul_il[1]), 109, 112, 128, 144, 160, + 5, AMR_OF(2, pul_il[2]), 108, 124, 140, 156, 172, + 5, AMR_OF(2, pul_il[3]), 107, 120, 136, 152, 168, + 6, AMR_OF(2, vq_gain), 9, 37, 17, 29, 25, 21, + 5, AMR_OF(3, adap), 44, 70, 65, 75, 92, + 5, AMR_OF(3, pul_il[0]), 106, 115, 131, 147, 163, + 5, AMR_OF(3, pul_il[1]), 105, 127, 143, 159, 175, + 5, AMR_OF(3, pul_il[2]), 104, 123, 139, 155, 171, + 5, AMR_OF(3, pul_il[3]), 119, 135, 151, 167, 183, + 6, AMR_OF(3, vq_gain), 8, 36, 16, 28, 24, 20, + 0 +}; + +static const uint16_t order_MODE_12k65[] = { + 1, AMR_BIT(vad), 7, + 8, AMR_BIT(isp_id[0]), 55, 40, 14, 6, 15, 5, 0, 68, + 8, AMR_BIT(isp_id[1]), 77, 58, 75, 49, 59, 57, 67, 61, + 6, AMR_BIT(isp_id[2]), 48, 63, 51, 62, 50, 70, + 7, AMR_BIT(isp_id[3]), 71, 56, 60, 69, 85, 86, 80, + 7, AMR_BIT(isp_id[4]), 93, 64, 94, 76, 82, 81, 89, + 5, AMR_BIT(isp_id[5]), 90, 103, 88, 102, 99, + 5, AMR_BIT(isp_id[6]), 98, 97, 96, 111, 95, + 9, AMR_OF(0, adap), 13, 12, 11, 10, 9, 41, 66, 72, + 92, + 1, AMR_OF(0, ltp), 110, + 9, AMR_OF(0, pul_il[0]), 106, 122, 154, 186, 218, 134, 166, 198, + 230, + 9, AMR_OF(0, pul_il[1]), 105, 130, 162, 194, 226, 142, 174, 206, + 238, + 9, AMR_OF(0, pul_il[2]), 104, 138, 170, 202, 234, 150, 182, 214, + 246, + 9, AMR_OF(0, pul_il[3]), 119, 146, 178, 210, 242, 158, 190, 222, + 254, + 7, AMR_OF(0, vq_gain), 4, 19, 45, 27, 39, 33, 31, + 6, AMR_OF(1, adap), 35, 54, 79, 74, 84, 101, + 1, AMR_OF(1, ltp), 109, + 9, AMR_OF(1, pul_il[0]), 118, 121, 153, 185, 217, 133, 165, 197, + 229, + 9, AMR_OF(1, pul_il[1]), 117, 129, 161, 193, 225, 141, 173, 205, + 237, + 9, AMR_OF(1, pul_il[2]), 116, 137, 169, 201, 233, 149, 181, 213, + 245, + 9, AMR_OF(1, pul_il[3]), 115, 145, 177, 209, 241, 157, 189, 221, + 253, + 7, AMR_OF(1, vq_gain), 3, 18, 44, 26, 38, 32, 30, + 9, AMR_OF(2, adap), 8, 23, 22, 21, 20, 52, 65, 87, + 91, + 1, AMR_OF(2, ltp), 108, + 9, AMR_OF(2, pul_il[0]), 114, 120, 152, 184, 216, 132, 164, 196, + 228, + 9, AMR_OF(2, pul_il[1]), 113, 128, 160, 192, 224, 140, 172, 204, + 236, + 9, AMR_OF(2, pul_il[2]), 112, 136, 168, 200, 232, 148, 180, 212, + 244, + 9, AMR_OF(2, pul_il[3]), 127, 144, 176, 208, 240, 156, 188, 220, + 252, + 7, AMR_OF(2, vq_gain), 2, 17, 43, 25, 37, 47, 29, + 6, AMR_OF(3, adap), 34, 53, 78, 73, 83, 100, + 1, AMR_OF(3, ltp), 107, + 9, AMR_OF(3, pul_il[0]), 126, 135, 167, 199, 231, 131, 163, 195, + 227, + 9, AMR_OF(3, pul_il[1]), 125, 143, 175, 207, 239, 139, 171, 203, + 235, + 9, AMR_OF(3, pul_il[2]), 124, 151, 183, 215, 247, 147, 179, 211, + 243, + 9, AMR_OF(3, pul_il[3]), 123, 159, 191, 223, 255, 155, 187, 219, + 251, + 7, AMR_OF(3, vq_gain), 1, 16, 42, 24, 36, 46, 28, + 0 +}; + +static const uint16_t order_MODE_14k25[] = { + 1, AMR_BIT(vad), 7, + 8, AMR_BIT(isp_id[0]), 55, 40, 14, 6, 15, 5, 0, 68, + 8, AMR_BIT(isp_id[1]), 77, 58, 75, 49, 59, 57, 67, 61, + 6, AMR_BIT(isp_id[2]), 48, 63, 51, 62, 50, 70, + 7, AMR_BIT(isp_id[3]), 71, 56, 60, 69, 85, 86, 80, + 7, AMR_BIT(isp_id[4]), 93, 64, 94, 76, 82, 81, 89, + 5, AMR_BIT(isp_id[5]), 90, 103, 88, 102, 99, + 5, AMR_BIT(isp_id[6]), 98, 97, 96, 111, 95, + 9, AMR_OF(0, adap), 13, 12, 11, 10, 9, 41, 66, 72, + 92, + 1, AMR_OF(0, ltp), 110, + 13, AMR_OF(0, pul_il[0]), 114, 186, 210, 234, 258, 106, 126, 162, + 170, 198, 222, 246, 270, + 13, AMR_OF(0, pul_il[1]), 122, 194, 218, 242, 266, 118, 134, 174, + 182, 206, 230, 254, 278, + 9, AMR_OF(0, pul_il[2]), 130, 138, 146, 154, 178, 202, 226, 250, + 274, + 9, AMR_OF(0, pul_il[3]), 142, 150, 158, 166, 190, 214, 238, 262, + 286, + 7, AMR_OF(0, vq_gain), 4, 19, 45, 27, 39, 33, 31, + 6, AMR_OF(1, adap), 35, 54, 79, 74, 84, 101, + 1, AMR_OF(1, ltp), 109, + 13, AMR_OF(1, pul_il[0]), 113, 185, 209, 233, 257, 105, 125, 161, + 169, 197, 221, 245, 269, + 13, AMR_OF(1, pul_il[1]), 121, 193, 217, 241, 265, 117, 133, 173, + 181, 205, 229, 253, 277, + 9, AMR_OF(1, pul_il[2]), 129, 137, 145, 153, 177, 201, 225, 249, + 273, + 9, AMR_OF(1, pul_il[3]), 141, 149, 157, 165, 189, 213, 237, 261, + 285, + 7, AMR_OF(1, vq_gain), 3, 18, 44, 26, 38, 32, 30, + 9, AMR_OF(2, adap), 8, 23, 22, 21, 20, 52, 65, 87, + 91, + 1, AMR_OF(2, ltp), 108, + 13, AMR_OF(2, pul_il[0]), 112, 184, 208, 232, 256, 104, 124, 160, + 168, 196, 220, 244, 268, + 13, AMR_OF(2, pul_il[1]), 120, 192, 216, 240, 264, 116, 132, 172, + 180, 204, 228, 252, 276, + 9, AMR_OF(2, pul_il[2]), 128, 136, 144, 152, 176, 200, 224, 248, + 272, + 9, AMR_OF(2, pul_il[3]), 140, 148, 156, 164, 188, 212, 236, 260, + 284, + 7, AMR_OF(2, vq_gain), 2, 17, 43, 25, 37, 47, 29, + 6, AMR_OF(3, adap), 34, 53, 78, 73, 83, 100, + 1, AMR_OF(3, ltp), 107, + 13, AMR_OF(3, pul_il[0]), 127, 199, 223, 247, 271, 119, 123, 175, + 183, 195, 219, 243, 267, + 13, AMR_OF(3, pul_il[1]), 135, 207, 231, 255, 279, 115, 131, 171, + 179, 203, 227, 251, 275, + 9, AMR_OF(3, pul_il[2]), 143, 151, 159, 167, 191, 215, 239, 263, + 287, + 9, AMR_OF(3, pul_il[3]), 139, 147, 155, 163, 187, 211, 235, 259, + 283, + 7, AMR_OF(3, vq_gain), 1, 16, 42, 24, 36, 46, 28, + 0 +}; + +static const uint16_t order_MODE_15k85[] = { + 1, AMR_BIT(vad), 7, + 8, AMR_BIT(isp_id[0]), 55, 40, 14, 6, 15, 5, 0, 68, + 8, AMR_BIT(isp_id[1]), 77, 58, 75, 49, 59, 57, 67, 61, + 6, AMR_BIT(isp_id[2]), 48, 63, 51, 62, 50, 70, + 7, AMR_BIT(isp_id[3]), 71, 56, 60, 69, 85, 86, 80, + 7, AMR_BIT(isp_id[4]), 93, 64, 94, 76, 82, 81, 89, + 5, AMR_BIT(isp_id[5]), 90, 103, 88, 102, 99, + 5, AMR_BIT(isp_id[6]), 98, 97, 96, 111, 95, + 9, AMR_OF(0, adap), 13, 12, 11, 10, 9, 41, 66, 72, + 92, + 1, AMR_OF(0, ltp), 110, + 13, AMR_OF(0, pul_il[0]), 122, 154, 170, 218, 266, 138, 106, 182, + 230, 278, 178, 226, 274, + 13, AMR_OF(0, pul_il[1]), 134, 166, 190, 238, 286, 150, 118, 186, + 234, 282, 198, 246, 294, + 13, AMR_OF(0, pul_il[2]), 130, 162, 194, 242, 290, 146, 114, 206, + 254, 302, 202, 250, 298, + 13, AMR_OF(0, pul_il[3]), 142, 174, 214, 262, 310, 158, 126, 210, + 258, 306, 222, 270, 318, + 7, AMR_OF(0, vq_gain), 4, 19, 45, 27, 39, 33, 31, + 6, AMR_OF(1, adap), 35, 54, 79, 74, 84, 101, + 1, AMR_OF(1, ltp), 109, + 13, AMR_OF(1, pul_il[0]), 121, 153, 169, 217, 265, 137, 105, 181, + 229, 277, 177, 225, 273, + 13, AMR_OF(1, pul_il[1]), 133, 165, 189, 237, 285, 149, 117, 185, + 233, 281, 197, 245, 293, + 13, AMR_OF(1, pul_il[2]), 129, 161, 193, 241, 289, 145, 113, 205, + 253, 301, 201, 249, 297, + 13, AMR_OF(1, pul_il[3]), 141, 173, 213, 261, 309, 157, 125, 209, + 257, 305, 221, 269, 317, + 7, AMR_OF(1, vq_gain), 3, 18, 44, 26, 38, 32, 30, + 9, AMR_OF(2, adap), 8, 23, 22, 21, 20, 52, 65, 87, + 91, + 1, AMR_OF(2, ltp), 108, + 13, AMR_OF(2, pul_il[0]), 120, 152, 168, 216, 264, 136, 104, 180, + 228, 276, 176, 224, 272, + 13, AMR_OF(2, pul_il[1]), 132, 164, 188, 236, 284, 148, 116, 184, + 232, 280, 196, 244, 292, + 13, AMR_OF(2, pul_il[2]), 128, 160, 192, 240, 288, 144, 112, 204, + 252, 300, 200, 248, 296, + 13, AMR_OF(2, pul_il[3]), 140, 172, 212, 260, 308, 156, 124, 208, + 256, 304, 220, 268, 316, + 7, AMR_OF(2, vq_gain), 2, 17, 43, 25, 37, 47, 29, + 6, AMR_OF(3, adap), 34, 53, 78, 73, 83, 100, + 1, AMR_OF(3, ltp), 107, + 13, AMR_OF(3, pul_il[0]), 135, 167, 183, 231, 279, 151, 119, 179, + 227, 275, 191, 239, 287, + 13, AMR_OF(3, pul_il[1]), 131, 163, 187, 235, 283, 147, 115, 199, + 247, 295, 195, 243, 291, + 13, AMR_OF(3, pul_il[2]), 143, 175, 207, 255, 303, 159, 127, 203, + 251, 299, 215, 263, 311, + 13, AMR_OF(3, pul_il[3]), 139, 171, 211, 259, 307, 155, 123, 223, + 271, 319, 219, 267, 315, + 7, AMR_OF(3, vq_gain), 1, 16, 42, 24, 36, 46, 28, + 0 +}; + +static const uint16_t order_MODE_18k25[] = { + 1, AMR_BIT(vad), 7, + 8, AMR_BIT(isp_id[0]), 55, 40, 14, 6, 15, 5, 0, 68, + 8, AMR_BIT(isp_id[1]), 77, 58, 75, 49, 59, 57, 67, 61, + 6, AMR_BIT(isp_id[2]), 48, 63, 51, 62, 50, 70, + 7, AMR_BIT(isp_id[3]), 71, 56, 60, 69, 85, 86, 80, + 7, AMR_BIT(isp_id[4]), 93, 64, 94, 76, 82, 81, 89, + 5, AMR_BIT(isp_id[5]), 90, 103, 88, 102, 99, + 5, AMR_BIT(isp_id[6]), 98, 97, 96, 111, 95, + 9, AMR_OF(0, adap), 13, 12, 11, 10, 9, 41, 66, 72, + 92, + 1, AMR_OF(0, ltp), 110, + 2, AMR_OF(0, pul_ih[0]), 124, 115, + 2, AMR_OF(0, pul_ih[1]), 150, 117, + 2, AMR_OF(0, pul_ih[2]), 129, 114, + 2, AMR_OF(0, pul_ih[3]), 121, 131, + 14, AMR_OF(0, pul_il[0]), 161, 257, 343, 199, 177, 303, 204, 173, + 168, 260, 277, 307, 338, 128, + 14, AMR_OF(0, pul_il[1]), 194, 286, 347, 222, 214, 316, 236, 152, + 166, 242, 284, 308, 344, 142, + 14, AMR_OF(0, pul_il[2]), 169, 273, 353, 202, 189, 311, 240, 200, + 171, 261, 309, 296, 345, 130, + 14, AMR_OF(0, pul_il[3]), 198, 275, 349, 187, 163, 282, 193, 195, + 175, 234, 265, 289, 328, 119, + 7, AMR_OF(0, vq_gain), 4, 19, 45, 27, 39, 33, 31, + 6, AMR_OF(1, adap), 35, 54, 79, 74, 84, 101, + 1, AMR_OF(1, ltp), 109, + 2, AMR_OF(1, pul_ih[0]), 139, 104, + 2, AMR_OF(1, pul_ih[1]), 135, 118, + 2, AMR_OF(1, pul_ih[2]), 112, 127, + 2, AMR_OF(1, pul_ih[3]), 140, 141, + 14, AMR_OF(1, pul_il[0]), 179, 276, 340, 225, 223, 321, 235, 190, + 182, 271, 310, 315, 352, 125, + 14, AMR_OF(1, pul_il[1]), 153, 264, 329, 232, 209, 323, 231, 165, + 191, 279, 290, 312, 367, 134, + 14, AMR_OF(1, pul_il[2]), 167, 269, 341, 205, 197, 298, 224, 160, + 170, 259, 280, 317, 357, 148, + 14, AMR_OF(1, pul_il[3]), 203, 272, 342, 227, 192, 299, 233, 172, + 183, 256, 283, 326, 355, 106, + 7, AMR_OF(1, vq_gain), 3, 18, 44, 26, 38, 32, 30, + 9, AMR_OF(2, adap), 8, 23, 22, 21, 20, 52, 65, 87, + 91, + 1, AMR_OF(2, ltp), 108, + 2, AMR_OF(2, pul_ih[0]), 144, 120, + 2, AMR_OF(2, pul_ih[1]), 157, 123, + 2, AMR_OF(2, pul_ih[2]), 145, 138, + 2, AMR_OF(2, pul_ih[3]), 132, 154, + 14, AMR_OF(2, pul_il[0]), 241, 319, 365, 252, 253, 331, 254, 230, + 220, 263, 285, 314, 364, 156, + 14, AMR_OF(2, pul_il[1]), 247, 291, 339, 249, 250, 332, 267, 196, + 207, 268, 304, 324, 356, 158, + 14, AMR_OF(2, pul_il[2]), 210, 300, 348, 243, 237, 333, 246, 206, + 219, 266, 318, 335, 363, 159, + 14, AMR_OF(2, pul_il[3]), 239, 306, 366, 221, 226, 297, 251, 184, + 178, 258, 292, 305, 346, 116, + 7, AMR_OF(2, vq_gain), 2, 17, 43, 25, 37, 47, 29, + 6, AMR_OF(3, adap), 34, 53, 78, 73, 83, 100, + 1, AMR_OF(3, ltp), 107, + 2, AMR_OF(3, pul_ih[0]), 143, 126, + 2, AMR_OF(3, pul_ih[1]), 137, 122, + 2, AMR_OF(3, pul_ih[2]), 149, 105, + 2, AMR_OF(3, pul_ih[3]), 133, 136, + 14, AMR_OF(3, pul_il[0]), 162, 287, 337, 244, 229, 322, 218, 180, + 186, 262, 274, 288, 351, 146, + 14, AMR_OF(3, pul_il[1]), 212, 294, 358, 248, 228, 334, 215, 174, + 176, 270, 293, 301, 354, 147, + 14, AMR_OF(3, pul_il[2]), 185, 327, 336, 211, 213, 313, 245, 181, + 188, 255, 281, 325, 350, 151, + 14, AMR_OF(3, pul_il[3]), 201, 295, 359, 216, 208, 320, 238, 164, + 155, 217, 278, 302, 330, 113, + 7, AMR_OF(3, vq_gain), 1, 16, 42, 24, 36, 46, 28, + 0 +}; + +static const uint16_t order_MODE_19k85[] = { + 1, AMR_BIT(vad), 7, + 8, AMR_BIT(isp_id[0]), 55, 40, 14, 6, 15, 5, 0, 68, + 8, AMR_BIT(isp_id[1]), 77, 58, 75, 49, 59, 57, 67, 61, + 6, AMR_BIT(isp_id[2]), 48, 63, 51, 62, 50, 70, + 7, AMR_BIT(isp_id[3]), 71, 56, 60, 69, 85, 86, 80, + 7, AMR_BIT(isp_id[4]), 93, 64, 94, 76, 82, 81, 89, + 5, AMR_BIT(isp_id[5]), 90, 103, 88, 102, 99, + 5, AMR_BIT(isp_id[6]), 98, 97, 96, 111, 95, + 9, AMR_OF(0, adap), 13, 12, 11, 10, 9, 41, 66, 72, + 92, + 1, AMR_OF(0, ltp), 110, + 10, AMR_OF(0, pul_ih[0]), 134, 153, 263, 342, 399, 154, 106, 177, + 317, 265, + 10, AMR_OF(0, pul_ih[1]), 128, 167, 270, 351, 385, 160, 105, 213, + 329, 259, + 2, AMR_OF(0, pul_ih[2]), 123, 147, + 2, AMR_OF(0, pul_ih[3]), 131, 143, + 10, AMR_OF(0, pul_il[0]), 346, 118, 170, 201, 296, 368, 250, 284, + 341, 391, + 10, AMR_OF(0, pul_il[1]), 345, 104, 166, 196, 281, 374, 242, 269, + 327, 390, + 14, AMR_OF(0, pul_il[2]), 141, 171, 291, 364, 229, 210, 308, 228, + 206, 200, 258, 295, 313, 361, + 14, AMR_OF(0, pul_il[3]), 144, 188, 282, 366, 217, 216, 309, 218, + 193, 182, 245, 287, 300, 367, + 7, AMR_OF(0, vq_gain), 4, 19, 45, 27, 39, 33, 31, + 6, AMR_OF(1, adap), 35, 54, 79, 74, 84, 101, + 1, AMR_OF(1, ltp), 109, + 10, AMR_OF(1, pul_ih[0]), 139, 169, 267, 348, 389, 163, 116, 189, + 343, 268, + 10, AMR_OF(1, pul_ih[1]), 120, 161, 249, 339, 397, 152, 114, 230, + 334, 303, + 2, AMR_OF(1, pul_ih[2]), 125, 138, + 2, AMR_OF(1, pul_ih[3]), 112, 129, + 10, AMR_OF(1, pul_il[0]), 349, 122, 162, 203, 288, 372, 278, 274, + 312, 377, + 10, AMR_OF(1, pul_il[1]), 357, 126, 165, 214, 298, 362, 252, 260, + 321, 378, + 14, AMR_OF(1, pul_il[2]), 150, 199, 266, 355, 211, 180, 285, 241, + 195, 198, 243, 275, 323, 375, + 14, AMR_OF(1, pul_il[3]), 142, 191, 256, 353, 208, 220, 314, 237, + 190, 212, 255, 304, 318, 371, + 7, AMR_OF(1, vq_gain), 3, 18, 44, 26, 38, 32, 30, + 9, AMR_OF(2, adap), 8, 23, 22, 21, 20, 52, 65, 87, + 91, + 1, AMR_OF(2, ltp), 108, + 10, AMR_OF(2, pul_ih[0]), 159, 168, 302, 356, 395, 178, 132, 185, + 330, 286, + 10, AMR_OF(2, pul_ih[1]), 158, 181, 292, 358, 396, 176, 133, 235, + 331, 276, + 2, AMR_OF(2, pul_ih[2]), 130, 157, + 2, AMR_OF(2, pul_ih[3]), 124, 136, + 10, AMR_OF(2, pul_il[0]), 354, 121, 194, 246, 322, 379, 272, 273, + 332, 398, + 10, AMR_OF(2, pul_il[1]), 359, 140, 186, 236, 333, 376, 290, 301, + 338, 387, + 14, AMR_OF(2, pul_il[2]), 155, 227, 319, 369, 253, 254, 350, 248, + 224, 239, 240, 293, 315, 383, + 14, AMR_OF(2, pul_il[3]), 156, 209, 297, 373, 225, 215, 326, 247, + 197, 184, 232, 289, 310, 365, + 7, AMR_OF(2, vq_gain), 2, 17, 43, 25, 37, 47, 29, + 6, AMR_OF(3, adap), 34, 53, 78, 73, 83, 100, + 1, AMR_OF(3, ltp), 107, + 10, AMR_OF(3, pul_ih[0]), 148, 164, 264, 340, 388, 183, 117, 205, + 336, 261, + 10, AMR_OF(3, pul_ih[1]), 146, 174, 257, 335, 384, 173, 113, 187, + 320, 279, + 2, AMR_OF(3, pul_ih[2]), 127, 151, + 2, AMR_OF(3, pul_ih[3]), 119, 137, + 10, AMR_OF(3, pul_il[0]), 352, 135, 172, 238, 306, 381, 262, 271, + 328, 382, + 10, AMR_OF(3, pul_il[1]), 347, 115, 179, 219, 305, 380, 277, 294, + 337, 386, + 14, AMR_OF(3, pul_il[2]), 145, 192, 307, 370, 234, 223, 324, 244, + 202, 204, 251, 299, 325, 360, + 14, AMR_OF(3, pul_il[3]), 149, 221, 311, 363, 226, 222, 316, 231, + 207, 175, 233, 280, 283, 344, + 7, AMR_OF(3, vq_gain), 1, 16, 42, 24, 36, 46, 28, + 0 +}; + +static const uint16_t order_MODE_23k05[] = { + 1, AMR_BIT(vad), 7, + 8, AMR_BIT(isp_id[0]), 55, 40, 14, 6, 15, 5, 0, 68, + 8, AMR_BIT(isp_id[1]), 77, 58, 75, 49, 59, 57, 67, 61, + 6, AMR_BIT(isp_id[2]), 48, 63, 51, 62, 50, 70, + 7, AMR_BIT(isp_id[3]), 71, 56, 60, 69, 85, 86, 80, + 7, AMR_BIT(isp_id[4]), 93, 64, 94, 76, 82, 81, 89, + 5, AMR_BIT(isp_id[5]), 90, 103, 88, 102, 99, + 5, AMR_BIT(isp_id[6]), 98, 97, 96, 111, 95, + 9, AMR_OF(0, adap), 13, 12, 11, 10, 9, 41, 66, 72, + 92, + 1, AMR_OF(0, ltp), 110, + 11, AMR_OF(0, pul_ih[0]), 118, 129, 131, 153, 170, 282, 298, 210, + 191, 357, 317, + 11, AMR_OF(0, pul_ih[1]), 126, 146, 135, 165, 187, 273, 345, 295, + 172, 338, 340, + 11, AMR_OF(0, pul_ih[2]), 119, 137, 141, 167, 208, 304, 366, 256, + 177, 339, 328, + 11, AMR_OF(0, pul_ih[3]), 116, 130, 120, 166, 190, 252, 311, 239, + 173, 343, 318, + 11, AMR_OF(0, pul_il[0]), 245, 180, 342, 424, 259, 277, 266, 380, + 398, 423, 440, + 11, AMR_OF(0, pul_il[1]), 218, 207, 367, 434, 201, 240, 275, 363, + 399, 419, 452, + 11, AMR_OF(0, pul_il[2]), 274, 188, 348, 425, 242, 204, 262, 365, + 402, 431, 463, + 11, AMR_OF(0, pul_il[3]), 221, 183, 337, 439, 243, 216, 251, 354, + 390, 411, 462, + 7, AMR_OF(0, vq_gain), 4, 19, 45, 27, 39, 33, 31, + 6, AMR_OF(1, adap), 35, 54, 79, 74, 84, 101, + 1, AMR_OF(1, ltp), 109, + 11, AMR_OF(1, pul_ih[0]), 115, 140, 142, 161, 230, 291, 351, 235, + 181, 293, 310, + 11, AMR_OF(1, pul_ih[1]), 104, 138, 132, 162, 211, 315, 347, 233, + 176, 320, 329, + 11, AMR_OF(1, pul_ih[2]), 106, 134, 125, 154, 205, 267, 306, 220, + 185, 330, 297, + 11, AMR_OF(1, pul_ih[3]), 105, 148, 122, 152, 215, 302, 350, 254, + 178, 319, 313, + 11, AMR_OF(1, pul_il[0]), 269, 189, 382, 432, 272, 228, 263, 383, + 406, 422, 453, + 11, AMR_OF(1, pul_il[1]), 286, 206, 377, 446, 226, 222, 265, 368, + 404, 416, 454, + 11, AMR_OF(1, pul_il[2]), 247, 195, 358, 445, 224, 236, 309, 341, + 375, 408, 449, + 11, AMR_OF(1, pul_il[3]), 225, 192, 359, 436, 250, 258, 290, 389, + 400, 420, 448, + 7, AMR_OF(1, vq_gain), 3, 18, 44, 26, 38, 32, 30, + 9, AMR_OF(2, adap), 8, 23, 22, 21, 20, 52, 65, 87, + 91, + 1, AMR_OF(2, ltp), 108, + 11, AMR_OF(2, pul_ih[0]), 139, 144, 145, 169, 234, 327, 395, 299, + 244, 356, 379, + 11, AMR_OF(2, pul_ih[1]), 127, 156, 158, 171, 231, 308, 397, 355, + 261, 371, 335, + 11, AMR_OF(2, pul_ih[2]), 123, 155, 157, 193, 241, 362, 384, 323, + 238, 392, 361, + 11, AMR_OF(2, pul_ih[3]), 114, 147, 121, 175, 196, 333, 373, 303, + 184, 353, 322, + 11, AMR_OF(2, pul_il[0]), 271, 203, 385, 442, 307, 276, 334, 405, + 412, 427, 459, + 11, AMR_OF(2, pul_il[1]), 278, 200, 388, 447, 292, 288, 296, 403, + 415, 429, 460, + 11, AMR_OF(2, pul_il[2]), 312, 214, 393, 433, 279, 301, 314, 391, + 410, 426, 450, + 11, AMR_OF(2, pul_il[3]), 280, 186, 376, 437, 268, 260, 255, 364, + 414, 417, 441, + 7, AMR_OF(2, vq_gain), 2, 17, 43, 25, 37, 47, 29, + 6, AMR_OF(3, adap), 34, 53, 78, 73, 83, 100, + 1, AMR_OF(3, ltp), 107, + 11, AMR_OF(3, pul_ih[0]), 112, 159, 143, 164, 213, 281, 332, 284, + 168, 344, 325, + 11, AMR_OF(3, pul_ih[1]), 113, 150, 149, 179, 199, 316, 324, 285, + 237, 360, 336, + 11, AMR_OF(3, pul_ih[2]), 124, 136, 151, 174, 209, 326, 349, 248, + 198, 374, 331, + 11, AMR_OF(3, pul_ih[3]), 117, 128, 133, 163, 202, 300, 372, 305, + 194, 387, 321, + 11, AMR_OF(3, pul_il[0]), 249, 182, 352, 428, 253, 264, 289, 413, + 407, 418, 461, + 11, AMR_OF(3, pul_il[1]), 287, 212, 369, 444, 223, 246, 217, 346, + 394, 401, 451, + 11, AMR_OF(3, pul_il[2]), 219, 197, 378, 435, 229, 257, 283, 396, + 409, 430, 455, + 11, AMR_OF(3, pul_il[3]), 232, 160, 370, 438, 227, 270, 294, 381, + 386, 421, 443, + 7, AMR_OF(3, vq_gain), 1, 16, 42, 24, 36, 46, 28, + 0 +}; + +static const uint16_t order_MODE_23k85[] = { + 1, AMR_BIT(vad), 7, + 8, AMR_BIT(isp_id[0]), 55, 40, 14, 6, 15, 5, 0, 68, + 8, AMR_BIT(isp_id[1]), 93, 58, 91, 49, 59, 57, 67, 61, + 6, AMR_BIT(isp_id[2]), 48, 63, 51, 62, 50, 70, + 7, AMR_BIT(isp_id[3]), 71, 56, 60, 69, 101, 102, 96, + 7, AMR_BIT(isp_id[4]), 109, 64, 110, 92, 98, 97, 105, + 5, AMR_BIT(isp_id[5]), 106, 119, 104, 118, 115, + 5, AMR_BIT(isp_id[6]), 114, 113, 112, 127, 111, + 9, AMR_OF(0, adap), 13, 12, 11, 10, 9, 41, 66, 88, + 108, + 1, AMR_OF(0, ltp), 126, + 11, AMR_OF(0, pul_ih[0]), 134, 145, 147, 169, 186, 298, 314, 226, + 207, 373, 333, + 11, AMR_OF(0, pul_ih[1]), 142, 162, 151, 181, 203, 289, 361, 311, + 188, 354, 356, + 11, AMR_OF(0, pul_ih[2]), 135, 153, 157, 183, 224, 320, 382, 272, + 193, 355, 344, + 11, AMR_OF(0, pul_ih[3]), 132, 146, 136, 182, 206, 268, 327, 255, + 189, 359, 334, + 11, AMR_OF(0, pul_il[0]), 261, 196, 358, 440, 275, 293, 282, 396, + 414, 439, 456, + 11, AMR_OF(0, pul_il[1]), 234, 223, 383, 450, 217, 256, 291, 379, + 415, 435, 468, + 11, AMR_OF(0, pul_il[2]), 290, 204, 364, 441, 258, 220, 278, 381, + 418, 447, 479, + 11, AMR_OF(0, pul_il[3]), 237, 199, 353, 455, 259, 232, 267, 370, + 406, 427, 478, + 7, AMR_OF(0, vq_gain), 4, 19, 45, 27, 39, 33, 31, + 4, AMR_OF(0, hb_gain), 79, 78, 77, 76, + 6, AMR_OF(1, adap), 35, 54, 95, 90, 100, 117, + 1, AMR_OF(1, ltp), 125, + 11, AMR_OF(1, pul_ih[0]), 131, 156, 158, 177, 246, 307, 367, 251, + 197, 309, 326, + 11, AMR_OF(1, pul_ih[1]), 120, 154, 148, 178, 227, 331, 363, 249, + 192, 336, 345, + 11, AMR_OF(1, pul_ih[2]), 122, 150, 141, 170, 221, 283, 322, 236, + 201, 346, 313, + 11, AMR_OF(1, pul_ih[3]), 121, 164, 138, 168, 231, 318, 366, 270, + 194, 335, 329, + 11, AMR_OF(1, pul_il[0]), 285, 205, 398, 448, 288, 244, 279, 399, + 422, 438, 469, + 11, AMR_OF(1, pul_il[1]), 302, 222, 393, 462, 242, 238, 281, 384, + 420, 432, 470, + 11, AMR_OF(1, pul_il[2]), 263, 211, 374, 461, 240, 252, 325, 357, + 391, 424, 465, + 11, AMR_OF(1, pul_il[3]), 241, 208, 375, 452, 266, 274, 306, 405, + 416, 436, 464, + 7, AMR_OF(1, vq_gain), 3, 18, 44, 26, 38, 32, 30, + 4, AMR_OF(1, hb_gain), 75, 74, 73, 72, + 9, AMR_OF(2, adap), 8, 23, 22, 21, 20, 52, 65, 103, + 107, + 1, AMR_OF(2, ltp), 124, + 11, AMR_OF(2, pul_ih[0]), 155, 160, 161, 185, 250, 343, 411, 315, + 260, 372, 395, + 11, AMR_OF(2, pul_ih[1]), 143, 172, 174, 187, 247, 324, 413, 371, + 277, 387, 351, + 11, AMR_OF(2, pul_ih[2]), 139, 171, 173, 209, 257, 378, 400, 339, + 254, 408, 377, + 11, AMR_OF(2, pul_ih[3]), 130, 163, 137, 191, 212, 349, 389, 319, + 200, 369, 338, + 11, AMR_OF(2, pul_il[0]), 287, 219, 401, 458, 323, 292, 350, 421, + 428, 443, 475, + 11, AMR_OF(2, pul_il[1]), 294, 216, 404, 463, 308, 304, 312, 419, + 431, 445, 476, + 11, AMR_OF(2, pul_il[2]), 328, 230, 409, 449, 295, 317, 330, 407, + 426, 442, 466, + 11, AMR_OF(2, pul_il[3]), 296, 202, 392, 453, 284, 276, 271, 380, + 430, 433, 457, + 7, AMR_OF(2, vq_gain), 2, 17, 43, 25, 37, 47, 29, + 4, AMR_OF(2, hb_gain), 87, 86, 85, 84, + 6, AMR_OF(3, adap), 34, 53, 94, 89, 99, 116, + 1, AMR_OF(3, ltp), 123, + 11, AMR_OF(3, pul_ih[0]), 128, 175, 159, 180, 229, 297, 348, 300, + 184, 360, 341, + 11, AMR_OF(3, pul_ih[1]), 129, 166, 165, 195, 215, 332, 340, 301, + 253, 376, 352, + 11, AMR_OF(3, pul_ih[2]), 140, 152, 167, 190, 225, 342, 365, 264, + 214, 390, 347, + 11, AMR_OF(3, pul_ih[3]), 133, 144, 149, 179, 218, 316, 388, 321, + 210, 403, 337, + 11, AMR_OF(3, pul_il[0]), 265, 198, 368, 444, 269, 280, 305, 429, + 423, 434, 477, + 11, AMR_OF(3, pul_il[1]), 303, 228, 385, 460, 239, 262, 233, 362, + 410, 417, 467, + 11, AMR_OF(3, pul_il[2]), 235, 213, 394, 451, 245, 273, 299, 412, + 425, 446, 471, + 11, AMR_OF(3, pul_il[3]), 248, 176, 386, 454, 243, 286, 310, 397, + 402, 437, 459, + 7, AMR_OF(3, vq_gain), 1, 16, 42, 24, 36, 46, 28, + 4, AMR_OF(3, hb_gain), 83, 82, 81, 80, + 0 +}; + +/** Reordering array addresses for each mode */ +static const uint16_t* amr_bit_orderings_by_mode[] = { + order_MODE_6k60, + order_MODE_8k85, + order_MODE_12k65, + order_MODE_14k25, + order_MODE_15k85, + order_MODE_18k25, + order_MODE_19k85, + order_MODE_23k05, + order_MODE_23k85 +}; + +// Extracted from 3GPP TS 26.173 V9.0.0 (qpisf_2s.tab) +// The *_36b tables are used in 6k60 mode +// Stored in fixed-point to save some space +/** Indexed tables for retrieval of quantized ISF vectors in Q15 */ +static const int16_t dico1_isf[256][9] = { + { 579, 1081, 1035, 390, 3, -263, -198, -82, 38}, + { 18, -68, -12, 313, 761, 405, 249, 111, -76}, + { 740, 1263, 1292, 1006, 997, 1019, 1017, 976, 923}, + { -91, 827, 948, 648, 613, 535, 522, 490, 421}, + { 41, -44, -281, -472, 652, 534, 193, 135, -90}, + { 41, -121, -356, -60, 663, 307, 61, -48, -344}, + { 557, 946, 1049, 867, 846, 990, 1112, 1262, 1241}, + { -118, -204, 328, 512, 870, 793, 610, 402, 186}, + { 156, 293, 74, -338, -475, -897, -594, -161, -497}, + { 226, 131, -138, 307, 169, -271, -164, -387, -624}, + { 62, -32, -61, -252, -541, -828, -1027, -523, -662}, + { 102, -61, 141, 112, -270, -251, -541, 25, -150}, + { 6, -132, -356, -686, -96, -322, -522, -31, -326}, + { -36, -209, -521, -229, 307, -132, -5, -99, -384}, + { 60, -51, -237, -668, -973, -407, -708, -75, -172}, + { 26, -138, -266, 111, -302, 43, -278, -356, -359}, + { 570, 822, 496, -154, -312, -92, 137, 279, 371}, + { -146, 368, 409, 68, 6, 77, 167, 202, 162}, + { 633, 898, 996, 756, 662, 683, 783, 909, 996}, + { -103, 294, 607, 415, 483, 462, 480, 431, 408}, + { -120, -338, -612, -524, 584, 331, 92, 433, 276}, + { -178, -293, -154, -41, 269, 100, -9, 213, 160}, + { 830, 736, 278, 820, 1254, 686, 712, 1039, 473}, + { -218, -304, 463, 454, 397, 273, 202, 286, 273}, + { -232, 7, 6, -388, -472, -427, -378, -167, -100}, + { -294, -183, 134, -47, 101, -88, -84, -117, -3}, + { 57, 17, -202, -634, -989, -1119, -533, 176, -36}, + { 120, -28, 23, 111, -319, 318, -22, -77, 266}, + { -271, -464, -434, -658, -640, -385, -385, -99, -69}, + { -198, -259, -266, -44, -39, -139, -137, 171, 66}, + { 9, -145, -377, -846, -1000, -111, -325, 342, 135}, + { -81, -286, -380, 192, -57, 307, 76, -24, -140}, + { 677, 702, 247, 56, 249, 141, -105, -236, -99}, + { 36, -39, -69, 348, 198, -93, 322, 91, -72}, + { 503, 885, 1508, 1307, 1282, 1172, 1119, 1209, 1061}, + { 416, 719, 989, 1227, 1001, 1052, 954, 741, 1044}, + { -127, -376, -657, 139, 623, 223, 501, 306, 220}, + { -113, -384, -796, 504, 438, 85, 213, -83, -194}, + { 585, 1132, 1233, 1091, 1247, 1433, 1512, 1448, 1314}, + { -174, -422, 7, 1155, 1089, 1182, 1003, 945, 806}, + { 8, -126, -317, -103, -351, -695, -98, -268, -537}, + { 33, -103, -290, 167, -39, -407, 44, -208, -375}, + { 104, -23, -64, -291, -637, -851, -1084, -61, -112}, + { -75, -306, -434, 218, -148, -354, -680, -133, -216}, + { -121, -377, -718, -97, -130, -361, -156, -379, -599}, + { -56, -254, -586, 235, 157, -214, 11, -260, -149}, + { -124, -267, -397, -580, -593, -527, -805, -385, 346}, + { -193, -440, -708, -351, -141, -255, -499, -147, -185}, + { 448, 660, 494, 208, 509, 461, 338, 291, 149}, + { -223, 88, 335, 159, 212, 191, 286, 308, 205}, + { -31, 469, 803, 659, 619, 658, 843, 987, 1113}, + { -171, -242, 514, 362, 295, 524, 552, 694, 585}, + { -64, -308, -448, -21, 284, 786, 446, 289, 92}, + { -218, -390, -7, 169, 206, 330, 352, 408, 358}, + { -36, 702, 959, 859, 861, 1115, 1269, 1357, 1305}, + { -133, -341, -65, 678, 417, 440, 486, 518, 780}, + { 33, -44, -191, -344, -461, -755, -201, 217, -31}, + { -353, -547, -44, 123, -61, -68, -79, 29, 60}, + { 73, -57, -406, -766, -1243, -1203, 240, 400, 165}, + { -73, -282, -601, -213, -171, -375, 332, 35, -103}, + { -29, -207, -553, -476, -638, -908, 172, -22, -135}, + { -192, -239, -164, -103, -111, -47, 153, 125, 110}, + { -1, -203, -570, -1030, -1424, -535, 155, 1, 147}, + { -333, -653, -865, -197, -158, -21, -44, 95, 108}, + { 389, 588, 490, 33, -237, -524, -628, -136, -260}, + { 40, -177, -462, 453, 862, 380, 131, -130, -405}, + { 842, 1678, 1841, 1549, 1474, 1256, 1082, 905, 742}, + { 370, 1216, 1768, 1633, 1212, 636, 22, -330, 71}, + { -76, -281, -741, -742, 898, 619, 277, 71, -222}, + { -32, -265, -556, -25, 994, 682, 305, 126, -165}, + { 73, 738, 893, 968, 993, 1768, 2273, 1840, 1391}, + { -69, -349, -585, 234, 1158, 903, 626, 510, 251}, + { -1, -99, -272, -210, -603, -351, -540, -811, -383}, + { -16, -230, -504, 410, 149, -205, -343, -651, -639}, + { 103, -9, -227, -205, -562, -781, -1079, -1208, -156}, + { 143, 63, -135, -67, -317, -602, -784, -1154, -640}, + { -144, -391, -674, -622, -200, -254, -660, -947, -395}, + { -40, -250, -625, 27, 543, 94, -131, -386, -673}, + { -123, -371, -757, -451, -564, -614, -415, -711, -35}, + { -116, -309, -593, -268, 239, -33, -338, -650, -135}, + { 94, 251, 554, 57, -312, -423, -154, -57, 235}, + { -268, -71, 381, 114, -44, -87, 125, 173, 133}, + { 1513, 1714, 1238, 534, 276, 315, 461, 459, 508}, + { -131, -19, 1149, 670, 486, 356, 309, 369, 296}, + { -223, -501, -899, -722, -70, 6, 131, 310, 394}, + { -99, -303, -517, 249, 64, -53, 135, -11, 453}, + { -147, -399, -730, -401, 817, 738, 802, 749, 575}, + { -154, -435, -739, 800, 593, 366, 529, 318, 326}, + { -224, 45, -39, -387, -515, -518, -608, -384, -321}, + { -315, -377, 143, -101, -113, -377, -177, -144, -12}, + { 117, 40, -239, -651, -1051, -581, -737, -990, -328}, + { 26, -50, -157, -23, -453, -283, -531, -546, 192}, + { -252, -501, -743, -589, -627, -499, -328, -118, -72}, + { -324, -494, -244, -306, -144, -177, -262, -135, -78}, + { -36, -234, -519, -961, -1290, -314, -479, -371, -45}, + { -95, -292, -535, -8, -300, 112, -164, -277, 198}, + { -99, -128, 880, 836, 579, 351, 23, -95, -217}, + { -27, -258, 124, 1011, 597, 425, 144, 7, -73}, + { 421, 1293, 1640, 1623, 1742, 1617, 1499, 1284, 1006}, + { -95, 752, 1680, 1569, 1618, 1436, 1200, 980, 712}, + { -69, -300, -683, -435, 1132, 899, 504, 332, 109}, + { -74, -323, -637, 563, 1074, 608, 371, 105, -49}, + { -78, 831, 1194, 1110, 1378, 1481, 1492, 1365, 1217}, + { -259, -121, 1440, 1334, 1628, 1490, 1438, 1223, 933}, + { -82, -306, -613, -222, -378, -675, -545, -671, -845}, + { 53, -124, -347, 422, 52, -125, -270, -529, 9}, + { 79, -89, -320, -662, -999, -1199, -1243, -676, -297}, + { -68, -273, -611, 137, -146, -397, -627, -845, -220}, + { -112, -346, -797, -826, 234, -132, -188, -278, -522}, + { -159, -405, -734, -419, 293, 74, -167, -167, 184}, + { -153, -437, -833, -1080, -336, -472, -561, -340, -253}, + { -169, -423, -820, -904, -131, -19, -346, -604, 31}, + { 33, -31, 312, 62, -148, 49, -59, 564, 486}, + { -306, -333, 194, -44, 67, 72, 147, 205, 243}, + { -207, -49, 1360, 983, 969, 991, 1014, 1110, 973}, + { -211, -172, 883, 627, 711, 674, 705, 798, 746}, + { -88, -325, -763, -974, 687, 908, 514, 382, 172}, + { -292, -612, -805, 63, 131, 270, 259, 352, 348}, + { -235, -84, 955, 818, 1120, 1289, 1559, 1480, 1285}, + { -180, -461, -614, 657, 691, 745, 854, 783, 713}, + { -97, -309, -477, -614, -777, -734, -768, -526, -472}, + { -344, -476, -35, -169, 49, -77, -150, -240, -141}, + { -52, -268, -639, -919, -1278, -1113, -342, -333, -151}, + { -68, -242, -585, -73, -209, -478, -159, -429, 133}, + { -197, -499, -1005, -1268, -272, -224, -105, -67, 17}, + { -363, -618, -414, -116, -62, 20, 10, 116, 108}, + { -195, -475, -906, -1260, -891, -441, -277, -142, -28}, + { -226, -519, -950, -700, -275, -266, -116, -105, 82}, + { 404, 511, 520, 327, 17, -194, -333, -536, -586}, + { -114, -130, 276, 237, 204, 342, 135, -16, -111}, + { 670, 1208, 1168, 860, 742, 601, 528, 403, 309}, + { 397, 621, 966, 752, 579, 398, 400, 329, 252}, + { 191, 180, -137, -467, 272, 106, -95, 17, -192}, + { -80, -290, -626, 194, 598, 196, 21, -281, 77}, + { 510, 864, 1108, 807, 939, 902, 925, 717, 481}, + { 137, 367, 534, 764, 670, 382, 296, 153, 84}, + { 303, 497, 144, -85, -125, -539, -482, -464, -764}, + { 233, 347, 68, -147, 169, -210, -242, -226, -482}, + { 307, 422, 154, -175, -386, -722, -724, -904, -1015}, + { 309, 308, 160, -60, -470, -420, -598, -791, -219}, + { 68, 121, -137, -560, -146, -446, -515, -494, -729}, + { 130, 53, -227, 46, 474, 32, -161, -192, -490}, + { 213, 164, -71, -465, -876, -161, -456, -587, -48}, + { 218, 117, 39, 177, -194, -88, -226, -418, 50}, + { 210, 547, 569, 279, 121, -44, -50, 10, -84}, + { 58, 140, 182, -5, 267, 117, 106, 211, 198}, + { 539, 835, 913, 719, 617, 544, 591, 565, 642}, + { 153, 559, 872, 460, 222, 108, 188, 180, 183}, + { 158, 119, 284, -153, -271, 229, 87, 110, -57}, + { -183, 82, 118, 21, 13, 40, 118, 191, 185}, + { 162, 889, 654, 108, -34, 244, 488, 561, 532}, + { 163, 56, 609, 341, 50, 329, 68, 266, 218}, + { 100, 206, 18, -304, -107, -436, -487, -65, -306}, + { -86, 154, 134, -30, -45, -73, -104, -80, -96}, + { 245, 330, 10, -440, -849, -1082, 79, 40, -265}, + { 196, 372, 272, -181, -493, -389, 275, 80, -59}, + { 2, -12, -246, -505, -100, -436, 21, -187, -431}, + { -221, -48, 36, -271, -186, -147, -109, 26, 71}, + { 213, 140, 72, -351, -620, -84, -363, 69, 46}, + { 91, 167, -3, -95, -99, -105, -48, 114, 147}, + { 259, 249, 172, 607, 406, 52, 59, -189, -320}, + { 115, -85, -54, 574, 128, 226, -59, -253, 130}, + { -62, 1033, 1308, 1035, 1127, 1098, 1029, 961, 823}, + { 39, 364, 757, 940, 728, 660, 659, 583, 770}, + { -115, -338, -760, -471, 394, 37, 441, 178, 6}, + { -57, -305, -525, 796, 453, 188, -4, -114, 248}, + { 71, 444, 797, 731, 1096, 1157, 1222, 1029, 811}, + { 135, 359, 551, 425, 749, 815, 874, 704, 502}, + { 132, 247, 0, -206, -449, -750, -258, -514, -633}, + { 248, 249, 91, 121, -195, -499, -90, -282, -435}, + { 78, 20, -277, -623, -983, -1224, -415, -458, -639}, + { 347, 509, 208, -179, -464, -728, -76, -237, -486}, + { -103, -343, -756, -713, -265, -609, -191, -398, -636}, + { -121, -383, -749, 567, 252, -36, -354, -417, -50}, + { 204, 100, -149, -650, -1081, -47, -7, -263, 111}, + { -46, -180, -267, -324, -562, -394, -692, 398, 292}, + { 482, 670, 683, 624, 442, 165, 116, 36, -149}, + { 108, 247, 291, 247, 355, 122, 109, 224, 296}, + { -14, 945, 990, 801, 755, 815, 847, 913, 892}, + { 292, 349, 725, 482, 388, 329, 429, 620, 667}, + { -34, 197, 213, -127, 84, 494, 620, 575, 375}, + { 126, 207, 172, 167, 362, 202, 296, 395, 455}, + { -6, 250, 539, 467, 636, 801, 1149, 1287, 1118}, + { 27, 240, 369, 280, 440, 411, 634, 892, 953}, + { 159, 170, -58, -395, -797, -690, 77, -211, -334}, + { -5, -28, -13, -74, -335, -603, 300, 88, -205}, + { 82, -33, -364, -698, -1203, -1153, 110, -146, -289}, + { 113, 1, -243, -588, -994, -496, 414, 160, 42}, + { -56, -247, -440, -693, -996, -479, 11, -178, -357}, + { -151, -353, -327, -211, -340, 141, 65, 425, 453}, + { 34, -169, -455, -932, -1215, 138, 499, 256, 324}, + { 68, 139, -15, -547, -478, 17, 306, 502, 481}, + { -32, -134, 445, 129, -143, -244, -503, -507, -599}, + { 61, -140, -345, 496, 458, -2, 20, -227, -514}, + { 394, 1765, 1666, 1339, 1117, 806, 642, 479, 380}, + { 215, 519, 920, 1053, 1090, 791, 528, 290, 155}, + { -54, -233, -647, -602, 639, 294, -2, -167, -442}, + { -78, -315, -791, -113, 820, 403, 158, -116, -356}, + { 529, 1851, 2003, 1228, 622, -41, -416, 344, 819}, + { -105, -379, -236, 1224, 893, 749, 568, 356, 214}, + { -17, -199, -144, 50, -283, -247, -578, -846, -1087}, + { 69, -11, -381, -206, 209, -284, -387, -416, -716}, + { 39, -5, -145, -374, -682, -909, -1074, -1169, -1066}, + { 287, 226, 67, -221, -662, -171, -421, -642, -707}, + { -132, -348, -538, -448, -20, -4, -354, -748, -933}, + { 4, -75, -289, -598, 317, 52, -208, -297, -559}, + { -88, -264, -358, -589, -631, -248, -523, -822, -1071}, + { 70, -8, 54, -314, -515, 92, -146, -274, -493}, + { 199, 62, 391, 158, -141, 71, -219, -203, -207}, + { 152, 40, 329, 162, -29, 48, -149, 108, 127}, + { 635, 1058, 883, 492, 372, 312, 317, 274, 241}, + { 267, 722, 1256, 882, 625, 248, 8, -81, -60}, + { -58, -138, -291, -600, -12, -2, -39, 147, 117}, + { -107, -345, -513, 459, 76, 92, -272, 388, 262}, + { 362, 516, 203, -409, -716, -831, -331, 185, 209}, + { -117, -391, -298, 671, 292, 538, 257, 166, -38}, + { -102, -319, -194, -283, -573, -262, -579, -219, -444}, + { -235, 78, 11, -168, -101, -229, -263, -321, -123}, + { 70, 50, -170, -599, -996, -588, -263, -516, -455}, + { 394, 363, 229, -136, -538, 21, -183, -348, -201}, + { -124, -368, -640, -879, -847, -209, -409, -494, -515}, + { -127, -341, -541, -425, -510, -10, -252, -473, -291}, + { 84, -69, -201, -676, -868, 103, -311, -132, -320}, + { 5, -173, -188, -297, -628, 197, -57, 7, -11}, + { 49, -160, 56, 558, 111, 33, -311, -440, -463}, + { -1, -246, -307, 862, 453, 139, -170, -355, -232}, + { 279, 966, 1642, 1478, 1463, 1123, 795, 525, 339}, + { -197, -38, 1702, 1331, 1252, 950, 692, 504, 426}, + { -108, -344, -861, -1172, 444, 354, 88, -46, -220}, + { -53, -321, -494, 1113, 744, 364, 198, -34, -75}, + { 457, 955, 1177, 1214, 1427, 1457, 1345, 917, 539}, + { -69, 199, 897, 1140, 1343, 1183, 977, 742, 522}, + { 122, 44, -269, 27, -155, -562, -307, -590, -773}, + { 154, 42, -160, 252, -129, -305, -471, -733, -371}, + { 135, 185, -82, -416, -722, -913, -504, -743, -880}, + { 149, 214, -84, -329, -680, -835, -426, -661, -81}, + { -128, -380, -735, -998, -337, 17, -182, -467, -697}, + { -84, -290, -510, -592, 13, 440, 154, -38, -279}, + { 70, -61, -246, -727, -1047, -80, -381, -535, -704}, + { 178, -2, -146, -670, -938, 482, 138, 63, 65}, + { -11, 15, 772, 443, 142, -20, -209, -126, -161}, + { -32, -249, 95, 552, 124, 30, -343, 82, -86}, + { 148, 751, 1515, 1105, 867, 606, 474, 448, 399}, + { -163, -257, 899, 1097, 906, 751, 502, 390, 294}, + { -51, -258, -447, -806, -368, 763, 464, 364, 183}, + { -166, -374, -367, 87, 35, 399, 418, 856, 833}, + { -205, -310, 588, 778, 785, 1065, 1118, 1245, 1157}, + { -173, -312, 107, 345, 400, 790, 870, 1113, 1001}, + { -7, -120, -387, -410, -614, -943, -226, -384, -491}, + { -203, -288, -51, -331, -90, -178, -408, -573, -338}, + { 56, -29, -273, -627, -1041, -798, -247, -467, 148}, + { 66, -2, -205, -205, -575, -349, -57, -352, -58}, + { -45, -225, -471, -924, -497, 77, -32, 44, -135}, + { -277, -491, -497, -502, -424, -202, -137, 77, 96}, + { 26, -179, -469, -1008, -1260, 262, -35, -132, -259}, + { -66, -232, -447, -533, -789, -191, -100, -267, 364} +}; + +static const int16_t dico2_isf[256][7] = { + { 1357, 1313, 1136, 784, 438, 181, 145}, + { 636, 648, 667, 568, 442, 217, 362}, + { 427, 440, 674, 524, 332, 117, -417}, + { 121, 295, 468, 465, 230, 44, -221}, + { -147, -240, 149, 80, 390, 278, 106}, + { -418, -556, 552, 511, 235, 144, -95}, + { 43, 193, 274, 150, 67, 34, -273}, + { -43, -126, 171, 416, 282, 63, -354}, + { -372, -86, -344, -108, -94, -182, -89}, + { -600, -840, -200, 465, 258, -11, -253}, + { -48, 329, 97, -290, -543, -795, -354}, + { -570, -117, 187, 10, -133, -416, -76}, + { -618, -129, -247, -371, 45, -76, 277}, + { -1022, -1079, 126, 474, 254, 127, 52}, + { -281, 76, -167, -361, -283, -551, -283}, + { -119, -52, -1, 134, -32, -204, -415}, + { 1064, 827, 637, 684, 464, 209, 12}, + { 482, 416, 449, 371, 335, 294, 194}, + { 719, 576, 365, 135, 113, 91, -199}, + { 298, 176, 493, 366, 194, 163, 36}, + { -35, -236, -259, -36, -4, 99, 152}, + { -98, -306, -27, 228, 90, 111, -86}, + { 91, 13, -211, -258, -106, 86, -64}, + { 73, -35, -57, -31, 162, 35, -192}, + { -109, -335, -629, -66, -61, -128, 322}, + { -495, -669, -728, 193, 31, -220, 122}, + { 324, 95, -89, -91, -409, -710, -154}, + { 0, -234, 92, 33, -343, -609, -220}, + { -343, -408, -476, -655, -153, 82, 222}, + { -490, -745, -255, 49, -48, 135, -127}, + { 119, -67, -328, -390, -272, -545, -56}, + { -57, -130, -10, -7, -164, -47, -22}, + { 984, 1064, 961, 568, 210, -27, 16}, + { 811, 691, 754, 514, 224, -35, 166}, + { 662, 704, 618, 386, 57, -211, -257}, + { 510, 359, 418, 393, 91, -144, -18}, + { -193, -31, -27, 223, 89, -143, 24}, + { -112, -98, 471, 319, 185, 3, 175}, + { 252, 146, -47, 272, 48, -211, -234}, + { 146, 69, 203, 364, 68, -52, 51}, + { -259, -478, -697, -349, -758, -501, 63}, + { -501, -769, -289, 79, -311, -497, -106}, + { 251, 53, -235, -469, -895, -884, 145}, + { -416, -551, 140, -133, -523, -775, 44}, + { -326, -423, -713, -497, -86, -431, 99}, + { -757, -772, -160, -76, -46, -32, 379}, + { 85, -35, -200, -401, -663, -1040, -247}, + { -180, -330, -92, -376, 27, -183, -110}, + { 1279, 1086, 781, 502, 324, 164, 157}, + { 682, 466, 449, 277, 146, 28, 409}, + { 635, 472, 390, 107, -232, -538, -139}, + { 196, 396, 332, 213, 209, -29, -81}, + { 150, -95, -312, 76, -77, -320, -50}, + { 46, 9, 47, 175, 139, 30, 384}, + { 218, 206, -24, -250, -96, -276, -183}, + { 26, 119, 38, 14, -4, -133, -52}, + { -477, -614, -987, -715, -631, -813, 200}, + { -744, -1009, -1065, -745, -631, -171, 18}, + { -137, -251, -483, -613, -980, -1203, 12}, + { -605, -767, -562, -686, -1088, -515, 58}, + { -202, -428, -782, -1072, -96, -234, -179}, + { -480, -709, -1070, -897, -131, -92, 321}, + { -145, -193, -512, -729, -572, -765, -210}, + { -331, -585, -525, -631, -281, -208, -303}, + { 1165, 1104, 939, 828, 716, 426, 155}, + { 6, -109, 820, 778, 415, 113, -27}, + { 381, 339, 314, 265, 121, -9, -474}, + { -373, 47, 584, 442, 99, -231, -113}, + { -496, -38, -285, 262, 305, 170, 4}, + { -587, -556, 69, 66, 471, 354, 13}, + { -138, 70, -18, 106, 67, 167, -302}, + { -445, -141, 185, 191, 151, 83, -133}, + { -257, -521, -720, -198, 134, -46, -182}, + { -819, -1168, -777, 512, 359, 95, -113}, + { 137, -2, -74, -138, -401, -114, -371}, + { -242, -466, 204, 223, -31, -212, -192}, + { -532, -637, -466, -686, 256, 277, -139}, + { -1141, -1244, -381, -75, -54, 14, 88}, + { -311, 115, -143, -499, -343, 124, -416}, + { -616, -147, -135, 43, -4, 121, -369}, + { 835, 783, 641, 390, 355, 350, 64}, + { 72, 194, 443, 467, 436, 219, 372}, + { 464, 369, 192, 4, -156, -72, -226}, + { 57, 206, 303, 205, 188, 101, 265}, + { -40, -205, -488, -184, 276, 64, -26}, + { -217, -433, -297, 137, 328, 308, -289}, + { 378, 81, -308, -465, 57, -37, 227}, + { -100, 24, -36, -151, 199, 8, 143}, + { -426, -697, -1059, -133, 388, 161, 321}, + { -644, -1023, -1271, 39, 66, -123, 70}, + { 372, 177, -173, -556, -553, -304, -189}, + { -117, -369, -425, -122, -462, -152, -73}, + { -649, -850, -1189, -767, 497, 360, 222}, + { -798, -1139, -1455, -190, 430, 234, 179}, + { 42, -94, -405, -692, 38, -202, -246}, + { -169, -366, -290, -88, -64, 32, -292}, + { 1010, 923, 938, 710, 465, 230, 342}, + { 217, 300, 1054, 675, 68, -458, -179}, + { 78, 453, 316, 18, -237, -496, -243}, + { 167, 21, 424, 215, -91, -303, -170}, + { -290, -81, -70, -67, 40, 54, -59}, + { -353, -427, -90, 53, 94, 9, 54}, + { -28, 318, 283, 15, -240, -58, 79}, + { -75, -121, 229, 35, 58, 6, -133}, + { -351, -514, -744, -834, -705, -137, 164}, + { -1124, -1388, -1055, -230, -73, 40, 36}, + { -163, -233, -532, -785, -1170, -697, 96}, + { -788, -959, -246, -430, -624, -165, -8}, + { -856, -540, -630, -907, -337, -70, 76}, + { -937, -1042, -659, -733, -208, 199, -26}, + { -523, 78, -98, -501, -869, -890, -81}, + { -624, -703, -45, -348, -25, 87, -186}, + { 1005, 823, 546, 249, 90, -22, 207}, + { 298, 397, 381, 319, 200, 62, 303}, + { 473, 379, 133, -247, -632, -441, 75}, + { 284, 208, 391, 115, -25, 44, 95}, + { -72, 79, -95, -63, -129, -293, 203}, + { -164, -349, 115, 122, 69, -1, 378}, + { 348, 170, 99, 58, -179, -302, 188}, + { -190, -2, 150, 23, -51, -11, 216}, + { -615, -863, -1090, -1427, -802, -48, -6}, + { -961, -1276, -1548, -727, -58, 56, 223}, + { -124, -255, -561, -988, -1277, -148, -82}, + { -480, -660, -891, -1191, -1339, -325, 20}, + { -621, -917, -1296, -1350, 264, 289, 50}, + { -844, -1022, -1345, -1329, -293, 46, 278}, + { -260, -468, -829, -1176, -533, -560, -78}, + { -215, -484, -822, -1233, -791, 15, -138}, + { 1301, 1317, 1262, 1048, 716, 357, -64}, + { 578, 824, 925, 802, 630, 362, 102}, + { 470, 925, 767, 514, 327, 190, -112}, + { 225, 492, 495, 437, 598, 384, -45}, + { 43, 82, -42, 175, 519, 342, -64}, + { -304, -154, 159, 576, 403, 221, 327}, + { 214, 244, 122, -62, 312, 92, -160}, + { 218, 208, 310, 268, 306, 323, -199}, + { -285, -269, -79, -124, -143, -153, 236}, + { -205, -384, -426, 344, 59, -185, -184}, + { -272, 247, 126, -210, -518, -468, 78}, + { -99, -120, 502, 160, -280, -557, 304}, + { -423, -17, -283, -443, 215, 212, -140}, + { -564, -684, -228, 510, 361, 130, 323}, + { -428, 335, 98, -65, 36, -215, -246}, + { -362, 51, 364, -16, -234, 150, -165}, + { 914, 883, 751, 653, 676, 464, -153}, + { 631, 545, 535, 720, 596, 360, -81}, + { 783, 712, 512, 439, 341, 251, -391}, + { 497, 417, 249, 372, 295, 173, -193}, + { 128, -110, -385, 93, 39, 173, -231}, + { 216, -59, -253, 462, 389, 154, 69}, + { 455, 270, -4, -337, -49, 233, -322}, + { 307, 143, 53, 218, 128, 236, -156}, + { -37, -186, -240, -411, -110, 9, 399}, + { -140, -365, -628, 258, 380, 214, 277}, + { 131, 454, 177, -285, -520, 108, -214}, + { 77, -141, 201, -123, -490, -131, 60}, + { -14, -194, -521, -741, 273, 362, -33}, + { -362, -566, -287, -228, 161, 237, 317}, + { -269, 195, -75, -375, -204, 11, 77}, + { -128, -264, -156, -223, -475, 265, 27}, + { 1238, 1147, 916, 689, 432, 210, -280}, + { 800, 664, 879, 726, 411, 160, -164}, + { 454, 686, 536, 275, 147, 46, 111}, + { 303, 486, 512, 355, 241, 181, -69}, + { 79, 92, 29, 147, 233, 52, 17}, + { -171, 289, 131, 439, 271, 3, -10}, + { 413, 241, 144, 174, 155, -2, 14}, + { 58, 217, 247, 219, 149, 175, -18}, + { 228, -8, -240, -206, -513, -191, 202}, + { -96, -272, -454, 33, -300, -575, 46}, + { -10, -108, -246, -347, -770, -535, 9}, + { -326, -430, -61, -321, -704, -299, 201}, + { -1, -280, -603, -419, -185, 18, -36}, + { -516, -522, -379, -291, -181, -97, 27}, + { -159, -313, -525, -224, -510, -831, -197}, + { -292, -459, -59, -310, -562, -143, -351}, + { 1066, 912, 631, 389, 207, 86, -224}, + { 596, 512, 596, 505, 314, 122, -48}, + { 787, 861, 441, -93, -303, 33, -190}, + { 257, 469, 337, 51, 15, 298, -93}, + { 295, 73, -119, 25, 36, 23, 108}, + { -28, -3, -32, 114, 21, 185, 107}, + { 482, 305, 15, -279, -319, 52, 96}, + { 226, 46, 115, 72, -136, 133, -125}, + { 18, -207, -559, -590, -503, -482, 321}, + { -571, -789, -951, -172, -441, -538, 113}, + { 181, 14, -310, -641, -1001, -202, 159}, + { -136, -393, -433, -513, -911, -144, -22}, + { 72, -265, -706, -954, -159, 53, 332}, + { -338, -591, -852, -383, -395, 56, 44}, + { 43, -158, -464, -897, -631, -157, -294}, + { -161, -128, -328, -573, -483, -125, 11}, + { 1017, 906, 1051, 1005, 679, 341, -102}, + { 359, 334, 1567, 1314, 723, 105, 10}, + { -65, 726, 529, 301, 220, 43, -273}, + { -510, 436, 719, 566, 358, 179, 114}, + { -560, 298, 133, -120, 342, 225, 14}, + { -899, -101, 217, 617, 400, 146, -58}, + { -41, 352, 82, -196, 39, 121, -167}, + { -212, 59, 447, 284, 423, 250, -169}, + { -371, -484, -596, 30, -41, 249, 22}, + { -372, -650, -794, 477, 445, 216, -79}, + { -352, 275, 17, -443, -929, 92, 19}, + { -699, -696, 431, 264, -49, -310, 182}, + { -978, -217, -430, -400, 101, 261, 72}, + { -929, -889, -357, -13, 463, 378, 236}, + { -826, 56, 30, -299, -360, -128, -51}, + { -878, -299, -111, 75, 65, 36, 3}, + { 817, 368, -25, 354, 697, 591, -173}, + { 309, 212, 222, 751, 484, 140, -56}, + { 593, 379, 70, -8, 258, 180, 110}, + { 165, -46, 255, 297, 219, 273, 105}, + { 160, -70, -358, -181, 379, 330, 319}, + { -238, -369, -198, 740, 580, 319, -143}, + { 201, 109, -202, -456, 328, 276, -141}, + { 203, 170, 111, 42, 207, 360, 188}, + { -345, -399, -513, -233, 650, 422, 81}, + { -635, -961, -1220, 463, 539, 204, 209}, + { 202, -25, -194, -498, -787, 193, -143}, + { -449, -538, 195, -106, -331, 68, 62}, + { -228, -477, -840, -576, 317, 128, 283}, + { -671, -937, -807, -114, 391, 335, -62}, + { 246, 2, -314, -679, -303, 180, -88}, + { -107, -272, 90, -198, -28, 290, -112}, + { 885, 1149, 1021, 712, 496, 281, -83}, + { 269, 492, 787, 643, 347, 70, 124}, + { 336, 636, 499, 92, -229, -179, 191}, + { 26, 402, 564, 340, 149, -11, 135}, + { -440, 561, 470, 204, -72, -186, 140}, + { -720, 14, 355, 229, 68, -133, 465}, + { 110, 310, 103, 12, 106, 29, 158}, + { -178, 113, 161, 142, 121, 115, 27}, + { -651, -414, -645, -152, -164, -13, -429}, + { -639, -944, -681, -104, -81, 52, -189}, + { -663, -164, -316, -683, -954, -205, -83}, + { -609, -669, -172, -517, -694, 283, -80}, + { -646, -152, -383, -678, -246, -40, -143}, + { -747, -796, -745, -390, -98, 43, 275}, + { -599, -199, -398, -433, -436, -538, 31}, + { -1107, -568, -376, -265, -126, -21, 1}, + { 847, 573, 308, 392, 305, 101, 55}, + { 273, 293, 201, 267, 346, 201, 123}, + { 727, 480, 226, 2, -65, -138, 164}, + { 273, 208, 173, 292, 12, 253, 174}, + { 340, 207, 180, 88, 116, 46, 475}, + { -460, -166, -30, 13, 110, 173, 396}, + { 137, 88, 43, -137, -94, 34, 284}, + { 96, -14, 226, 40, 63, 70, 130}, + { -467, -735, -1012, -1174, -307, 305, -67}, + { -612, -920, -1146, -567, -8, 92, -25}, + { -182, -271, -492, -754, -857, 287, -75}, + { -494, -787, -689, -683, -709, 137, -326}, + { -288, -550, -903, -1105, 334, 321, -62}, + { -354, -653, -834, -445, 1, 377, -152}, + { -162, -306, -608, -937, -297, 247, -192}, + { -234, -477, -244, -488, -266, 342, -332} +}; + +static const int16_t dico21_isf[64][3] = { + { 329, 409, 249}, { -33, 505, 160}, + { -29, -14, 582}, { -262, 127, 354}, + { 145, 237, 175}, { -152, 245, 122}, + { 27, 42, 340}, { -84, -93, 311}, + { 285, 222, -156}, { 47, -43, -504}, + { 234, 121, 385}, { 104, -317, 45}, + { 176, 195, 8}, { 104, -59, -94}, + { 177, 53, 192}, { -34, -127, 152}, + { 570, 277, -34}, { -67, -329, -639}, + { -157, -272, 462}, { -177, -462, 198}, + { 322, 179, 115}, { -386, 171, 19}, + { 19, -12, 195}, { -120, -252, 201}, + { 304, 36, -336}, { -128, -221, -380}, + { 171, -185, 296}, { -242, -312, 23}, + { 198, 39, 16}, { -3, -177, -111}, + { 111, -93, 76}, { -92, -223, 4}, + { 177, 406, -44}, { -168, 380, -149}, + { -4, 273, 331}, { -420, 513, 277}, + { 21, 247, 47}, { -58, 131, -2}, + { -3, 134, 180}, { -145, 40, 175}, + { 189, 74, -145}, { -27, -45, -325}, + { 370, -114, -21}, { -83, -415, -173}, + { 77, 95, -51}, { -40, -30, -67}, + { 71, 88, 86}, { -35, -98, 14}, + { 69, 197, -334}, { -196, 79, -231}, + { -348, -137, 218}, { -352, -89, -85}, + { 47, 201, -130}, { -165, 37, -15}, + { -43, 3, 86}, { -161, -108, 79}, + { 83, 21, -237}, { -81, -149, -238}, + { 150, -186, -251}, { -186, -249, -162}, + { -19, 66, -139}, { -26, -50, -181}, + { 24, 11, 0}, { -130, -105, -98} +}; + +static const int16_t dico22_isf[128][3] = { + { -127, 310, 42}, { -242, 197, 5}, + { -151, 84, -17}, { -214, 127, -149}, + { -247, -131, 159}, { -268, -267, -95}, + { -217, 1, -79}, { -271, -80, -185}, + { -45, 436, 159}, { 165, 199, 391}, + { -33, 81, 187}, { -66, -42, 355}, + { -298, -57, 343}, { -108, -537, 226}, + { -144, -23, 193}, { 176, -402, 87}, + { 53, 296, 25}, { -84, 253, -104}, + { -58, 105, -126}, { -169, 174, -314}, + { -48, 44, -294}, { -164, -417, -242}, + { -139, 3, -194}, { -155, -207, -211}, + { 119, 322, 213}, { 333, 50, 380}, + { 237, 247, -2}, { 466, -16, 201}, + { 238, -255, -107}, { 67, -440, -149}, + { 122, -88, -139}, { 88, -247, -73}, + { -41, 231, 167}, { -62, 155, 16}, + { -65, 16, 77}, { -68, -2, -63}, + { -151, -300, 160}, { -18, -333, 54}, + { -56, -94, 5}, { 2, -190, 14}, + { 92, 148, 209}, { 108, 9, 272}, + { 108, 35, 110}, { 142, -85, 145}, + { 47, -157, 279}, { 3, -320, 246}, + { 43, -72, 68}, { 86, -217, 135}, + { 36, 140, 79}, { 56, 175, -49}, + { 26, 45, 3}, { 73, 55, -101}, + { 109, -183, -242}, { -4, -283, -242}, + { 48, -68, -48}, { -6, -153, -122}, + { 161, 196, 96}, { 232, 80, 190}, + { 165, 97, 11}, { 258, -31, 71}, + { 267, -77, -91}, { 311, -209, 87}, + { 152, -14, -22}, { 150, -149, 9}, + { -324, 557, 187}, { -384, 307, 46}, + { -251, 27, 77}, { -365, 77, -52}, + { -482, -84, 160}, { -424, -515, -64}, + { -294, -120, -4}, { -476, -116, -109}, + { -97, 318, 365}, { 106, 627, 445}, + { -190, 120, 287}, { -146, 65, 619}, + { -427, 242, 363}, { -361, -371, 432}, + { -347, 102, 168}, { -629, 195, -14}, + { -65, 476, -47}, { -297, 320, -168}, + { -55, 356, -264}, { -391, 82, -286}, + { -51, -31, -556}, { -178, -399, -586}, + { -205, -49, -360}, { -343, -238, -337}, + { 220, 457, 58}, { 561, 467, 259}, + { 340, 270, -168}, { 450, 77, -280}, + { 60, 167, -413}, { 133, -252, -492}, + { 216, 157, -290}, { 282, 0, -495}, + { -226, 293, 183}, { -157, 135, 122}, + { -158, -59, 39}, { -133, -118, -97}, + { -332, -309, 113}, { -160, -425, -6}, + { -149, -211, 24}, { -80, -277, -90}, + { -11, 125, 338}, { 130, -71, 465}, + { 5, -45, 184}, { 237, -95, 253}, + { -139, -197, 297}, { -19, -300, 511}, + { -63, -152, 139}, { 250, -289, 336}, + { 124, 339, -150}, { 34, 176, -208}, + { 171, 166, -116}, { 94, 38, -229}, + { 75, -65, -339}, { -78, -205, -385}, + { 0, -30, -163}, { -56, -110, -242}, + { 321, 244, 194}, { 505, 238, -1}, + { 317, 116, 65}, { 309, 88, -74}, + { 452, -51, -50}, { 334, -217, -290}, + { 211, 41, -152}, { 238, -55, -260} +}; + +static const int16_t dico23_isf[128][3] = { + { -10, 151, 359}, { 136, 298, 223}, + { 255, -104, 290}, { 423, 6, 183}, + { -270, -269, -98}, { -52, -82, 13}, + { -82, -274, -97}, { 90, -246, -72}, + { -299, -70, 421}, { -88, 365, 430}, + { 187, -318, 381}, { 380, 37, 488}, + { -373, -316, 79}, { -308, -101, 5}, + { -135, -451, 8}, { 72, -421, -154}, + { 180, 170, -121}, { 62, 177, -40}, + { 326, 80, -105}, { 248, 263, -5}, + { -168, -181, -221}, { -2, -23, -158}, + { -14, -149, -121}, { 119, -91, -147}, + { 119, 332, -153}, { 49, 303, 34}, + { 442, -55, -69}, { 217, 454, 58}, + { -359, -187, -375}, { -42, 50, -274}, + { -8, -267, -249}, { 85, -86, -346}, + { -77, -40, 345}, { 89, 134, 219}, + { 156, -80, 160}, { 108, 40, 116}, + { -158, -206, 29}, { 5, -32, 175}, + { -65, -158, 146}, { 55, -78, 73}, + { -114, -222, 353}, { -47, 81, 211}, + { 49, -151, 268}, { 105, 4, 302}, + { -263, -132, 183}, { -151, -28, 201}, + { -177, -307, 166}, { 101, -221, 130}, + { 74, 58, -98}, { 32, 44, 13}, + { 194, 30, -142}, { 170, 96, 8}, + { -136, -119, -91}, { -65, 8, -55}, + { 3, -188, 12}, { 45, -63, -49}, + { 149, -21, -19}, { 24, 144, 95}, + { 254, -22, 60}, { 161, 196, 96}, + { -158, -61, 48}, { -70, 33, 82}, + { -23, -321, 58}, { 155, -147, 5}, + { -364, 328, 77}, { -21, 453, 173}, + { -108, 82, 630}, { 367, 263, 208}, + { -300, -62, -176}, { -205, 143, -158}, + { -169, -410, -264}, { 257, -269, -100}, + { -636, 289, -2}, { -292, 627, 173}, + { -382, -363, 387}, { 248, 524, 447}, + { -521, -111, -107}, { -395, 118, -274}, + { -343, -680, -125}, { -172, -447, -663}, + { 75, 148, -367}, { -79, 263, -94}, + { 249, 148, -286}, { 380, 271, -162}, + { -142, -4, -186}, { -57, 111, -125}, + { -35, -108, -254}, { 100, 29, -242}, + { -80, 303, -264}, { -78, 464, -57}, + { 248, -22, -494}, { 661, 662, 44}, + { -193, -40, -330}, { -178, 145, -337}, + { -90, -199, -400}, { -40, -23, -498}, + { -192, 114, 315}, { -41, 244, 190}, + { 88, -97, 485}, { 241, 80, 212}, + { -246, 40, 87}, { -156, 147, 134}, + { -2, -334, 239}, { 308, -203, 110}, + { -459, 251, 422}, { -218, 310, 228}, + { -86, -346, 654}, { 184, 175, 425}, + { -481, -63, 169}, { -349, 117, 188}, + { -125, -560, 310}, { 158, -416, 94}, + { 46, 171, -192}, { -63, 157, 14}, + { 256, -35, -271}, { 322, 123, 53}, + { -214, 4, -76}, { -156, 86, -18}, + { 128, -197, -232}, { 265, -90, -98}, + { -308, 332, -145}, { -131, 308, 58}, + { 509, 59, -339}, { 562, 196, -14}, + { -378, 100, -47}, { -234, 202, 1}, + { 104, -270, -493}, { 319, -210, -325} +}; + +static const int16_t dico24_isf[32][3] = { + { -79, -89, -4}, { -171, 77, -211}, + { 160, -193, 98}, { 120, -103, 323}, + { 32, -22, -129}, { 72, 78, -268}, + { 182, -76, -66}, { 309, 99, -145}, + { -229, -157, -84}, { -383, 98, -71}, + { -90, -352, 12}, { -284, -178, 178}, + { -65, -125, -166}, { -87, -175, -351}, + { 42, -198, -48}, { 154, -140, -243}, + { -77, 18, 108}, { -39, 355, 91}, + { 87, 8, 155}, { -4, 158, 239}, + { 128, 95, -54}, { 7, 246, -124}, + { 258, 15, 89}, { 206, 216, 98}, + { -201, 9, 18}, { -312, 233, 204}, + { -39, -174, 155}, { -144, -9, 284}, + { -57, 70, -69}, { -157, 187, 18}, + { 54, -30, 23}, { 24, 135, 55} +}; + +static const int16_t dico25_isf[32][4] = { + { 169, 142, -119, 115}, { 206, -20, 94, 226}, + { -106, 313, -21, 16}, { -62, 161, 71, 255}, + { -89, 101, -185, 125}, { 72, -30, -201, 344}, + { -258, 33, -8, 81}, { -104, -154, 72, 296}, + { 144, -68, -268, -25}, { 81, -78, -87, 106}, + { 22, 155, -186, -119}, { -46, -28, 27, 91}, + { -114, -37, -175, -33}, { -94, -222, -189, 122}, + { -132, -119, -191, -270}, { -172, -173, 18, -43}, + { 279, 135, -42, -128}, { 187, -86, 229, -138}, + { 159, 240, 140, 46}, { 69, 25, 227, 77}, + { 21, 115, 13, 8}, { 68, -248, 126, 81}, + { -150, 137, 207, -9}, { -154, -133, 289, 67}, + { 143, -37, -86, -326}, { 180, -32, 19, -23}, + { 26, 168, 116, -233}, { -32, -26, 118, -78}, + { 3, -8, -45, -115}, { 57, -215, -54, -83}, + { -209, 112, -22, -167}, { -91, -151, 168, -262} +}; + +static const int16_t dico21_isf_36b[128][5] = { + { -52, -96, 212, 315, -73}, { 82, -204, 363, 136, -197}, + { -126, -331, 183, 218, 143}, { -49, -41, 557, 230, 72}, + { 2, -73, 163, 377, 221}, { 133, 111, 278, 215, -110}, + { -102, -20, 284, 113, 273}, { 84, 319, 290, 18, 85}, + { -25, -5, 125, 132, -204}, { -38, -5, 286, -9, -356}, + { -140, -256, 92, 117, -189}, { -144, 191, 313, 51, -98}, + { 167, -10, 44, 247, 36}, { 381, 197, 238, 74, 6}, + { 38, -408, 29, -3, -85}, { 92, 266, 157, -25, -200}, + { 161, -121, 70, 84, -140}, { -16, -86, 112, -94, -189}, + { -269, -270, 351, 107, -24}, { -68, -67, 492, -103, -155}, + { -53, -131, 62, 122, 10}, { 135, 84, 283, -55, -120}, + { -12, -219, 331, -81, 167}, { 220, -136, 147, -172, -42}, + { 140, -95, -109, -88, -194}, { 0, -2, -4, -33, -381}, + { -66, -217, 152, -186, -402}, { 244, 108, 156, -140, -395}, + { 113, -136, -196, 110, -24}, { 214, 118, 11, -64, -131}, + { -110, -286, -6, -332, 16}, { 94, 97, 79, -291, -205}, + { -5, -39, -20, 252, -96}, { 76, 174, 101, 163, 61}, + { -69, -239, -55, 399, 6}, { -115, 319, 164, 275, 196}, + { -15, 36, -47, 331, 121}, { 226, 209, 271, 325, 184}, + { 13, -80, -218, 471, 353}, { 288, 378, 16, -51, 251}, + { 174, 116, 52, 149, -279}, { 235, 276, 39, 120, -48}, + { 0, -108, -108, 241, -339}, { -93, 534, 45, 33, -87}, + { 194, 149, -71, 405, -44}, { 409, 370, 81, -186, -154}, + { 25, -102, -448, 124, -173}, { 22, 408, -110, -310, -214}, + { -26, 23, -83, 114, 14}, { -110, 164, 52, 223, -82}, + { 37, -25, -263, 306, -15}, { -466, 415, 292, 165, -18}, + { 29, -19, -171, 155, 182}, { 179, 144, -27, 231, 258}, + { -103, -247, -396, 238, 113}, { 375, -154, -109, -4, 156}, + { 98, 85, -292, -5, -124}, { 116, 139, -116, -98, -294}, + { -14, -83, -278, -117, -378}, { 106, 33, -106, -344, -484}, + { 119, 17, -412, 138, 166}, { 384, 101, -204, 88, -156}, + { -121, -284, -300, -1, -166}, { 280, 33, -152, -313, -81}, + { -37, 22, 229, 153, 37}, { -60, -83, 236, -8, -41}, + { -169, -228, 126, -20, 363}, { -235, 17, 364, -156, 156}, + { -25, -30, 72, 144, 156}, { 153, -26, 256, 97, 144}, + { -21, -37, 48, -65, 250}, { 63, 77, 273, -128, 124}, + { -129, -26, 40, 9, -115}, { -6, 82, 38, -90, -182}, + { -336, -13, 28, 158, 91}, { -30, 241, 137, -170, -17}, + { 146, 14, -11, 33, 61}, { 192, 197, 54, -84, 85}, + { 23, -200, -78, -29, 140}, { 122, 237, 106, -341, 136}, + { -57, -142, -85, -16, -74}, { -59, -90, -8, -187, -20}, + { -211, -267, 216, -179, -110}, { -50, -7, 220, -267, -70}, + { -57, -42, -17, -15, 71}, { 32, 21, 63, -137, 33}, + { -137, -175, 104, -68, 97}, { -67, -43, 133, -301, 221}, + { -116, -200, -81, -92, -272}, { -64, -41, -54, -244, -220}, + { -287, -242, -50, -87, -89}, { -245, 236, 102, -166, -295}, + { 66, 24, -162, -71, 95}, { 66, 136, -90, -220, -36}, + { -98, -161, -222, -188, 29}, { -18, 18, -19, -415, 9}, + { 49, 61, 100, 39, -56}, { -111, 82, 135, -31, 52}, + { -90, -153, -93, 189, 182}, { -214, 295, 119, -74, 284}, + { 2, 137, 37, 47, 182}, { 92, 117, 184, -53, 373}, + { -21, -14, -35, 136, 391}, { 146, 129, -164, -28, 333}, + { 92, 80, -84, 100, -134}, { -8, 217, -32, 3, -47}, + { -151, 251, -215, 142, 92}, { -224, 310, -172, -275, 98}, + { 159, 155, -177, 112, 53}, { 205, 27, 8, -240, 192}, + { 169, 120, -319, -201, 106}, { 11, 36, -86, -237, 455}, + { -109, -154, -163, 174, -55}, { -38, 32, -101, -78, -59}, + { -205, -321, -97, 69, 79}, { -310, 44, 18, -185, 34}, + { -115, -20, -148, -39, 203}, { -29, 154, -30, -158, 166}, + { -45, -131, -317, -24, 363}, { -165, -205, -112, -222, 265}, + { -32, -44, -150, 54, -193}, { -6, -38, -255, -169, -115}, + { -266, 87, -189, -36, -169}, { -60, -87, -266, -436, -170}, + { -68, -81, -278, 24, 38}, { -23, -19, -155, -256, 141}, + { -61, -226, -565, -175, 71}, { 9, -29, -237, -515, 263} +}; + +static const int16_t dico22_isf_36b[128][4] = { + { -298, -6, 95, 31}, { -213, -87, -122, 261}, + { 4, -49, 208, 14}, { -129, -110, 30, 118}, + { -214, 258, 110, -235}, { -41, -18, -126, 120}, + { 103, 65, 127, -37}, { 126, -36, -24, 25}, + { -138, -67, -278, -186}, { -164, -194, -201, 78}, + { -211, -87, -51, -221}, { -174, -79, -94, -39}, + { 23, -6, -157, -240}, { 22, -110, -153, -68}, + { 148, -5, -2, -149}, { -1, -135, -39, -179}, + { 68, 360, -117, -15}, { 137, 47, -278, 146}, + { 136, 260, 135, 65}, { 61, 116, -45, 97}, + { 231, 379, 87, -120}, { 338, 177, -272, 3}, + { 266, 156, 28, -69}, { 260, 84, -85, 86}, + { -266, 154, -256, -182}, { -17, -65, -304, -6}, + { -40, 175, -151, -180}, { -27, 27, -87, -63}, + { 121, 114, -166, -469}, { 159, -66, -323, -231}, + { 214, 152, -141, -212}, { 137, 36, -184, -51}, + { -282, -237, 40, 10}, { -48, -235, -37, 251}, + { -54, -323, 136, 29}, { -88, -174, 213, 198}, + { -390, 99, -63, -375}, { 107, -169, -164, 424}, + { 69, -111, 141, -167}, { 74, -129, 65, 144}, + { -353, -207, -205, -109}, { -160, -386, -355, 98}, + { -176, -493, -20, -143}, { -252, -432, -2, 216}, + { -90, -174, -168, -411}, { 13, -284, -229, -160}, + { -87, -279, 34, -251}, { -75, -263, -58, -42}, + { 420, 53, -211, -358}, { 384, -35, -374, 396}, + { 68, -228, 323, -2}, { 167, -307, 192, 194}, + { 459, 329, -5, -332}, { 375, 79, -7, 313}, + { 282, -124, 200, -92}, { 271, -162, -70, 180}, + { -157, -298, -514, -309}, { 58, -163, -546, 18}, + { 124, -364, 167, -238}, { 83, -411, -117, 96}, + { 140, -112, -388, -624}, { 259, -133, -317, 41}, + { 163, -130, -64, -334}, { 226, -165, -124, -110}, + { -466, -61, 6, 229}, { -153, 205, -145, 242}, + { -159, 48, 195, 148}, { -58, 28, 31, 279}, + { -303, 185, 279, -4}, { -61, 197, 59, 86}, + { -114, 123, 168, -52}, { 35, 36, 100, 126}, + { -407, 102, -77, -40}, { -338, -1, -342, 156}, + { -179, 105, -34, -97}, { -185, 84, -35, 108}, + { -133, 107, -91, -357}, { -180, 54, -229, 24}, + { -44, 47, 47, -182}, { -66, 13, 45, 4}, + { -339, 251, 64, 226}, { -42, 101, -350, 275}, + { -99, 398, 142, 121}, { 111, 12, -102, 260}, + { 0, 505, 260, -94}, { 161, 285, -96, 224}, + { -4, 206, 314, 33}, { 167, 139, 88, 204}, + { -235, 316, -60, -25}, { -8, -150, -312, 201}, + { -36, 292, 61, -104}, { -40, 174, -162, 42}, + { -21, 402, -29, -351}, { 21, 152, -360, -93}, + { 57, 191, 212, -196}, { 76, 158, -21, -69}, + { -328, -185, 331, 119}, { -53, 285, 56, 337}, + { -107, -24, 405, 29}, { -18, 137, 272, 277}, + { -255, 22, 173, -191}, { 295, 322, 325, 302}, + { 21, -27, 332, -178}, { 119, 13, 271, 129}, + { -455, -180, 116, -191}, { -227, 62, -148, 524}, + { -176, -287, 282, -157}, { -243, 13, 199, 430}, + { -59, -49, 115, -365}, { 72, -172, -137, 93}, + { -138, -126, 141, -84}, { 5, -124, 38, -20}, + { -258, 311, 601, 213}, { 94, 130, -61, 502}, + { -1, -157, 485, 313}, { 146, -74, 158, 345}, + { 276, 135, 280, -57}, { 490, 252, 99, 43}, + { 267, -74, 429, 105}, { 278, -23, 119, 94}, + { -542, 488, 257, -115}, { -84, -244, -438, 478}, + { -113, -545, 387, 101}, { -95, -306, 111, 498}, + { 95, 166, 22, -301}, { 420, -15, -58, -78}, + { 270, 29, 122, -282}, { 160, -240, 50, -38} +}; + +static const int16_t dico23_isf_36b[64][7] = { + { 81, -18, 68, -27, -122, -280, -4}, + { 45, -177, 209, -30, -136, -74, 131}, + { -44, 101, -75, -88, -48, -137, -54}, + { -245, -28, 63, -18, -112, -103, 58}, + { -79, -6, 220, -65, 114, -35, -50}, + { 109, -65, 143, -114, 129, 76, 125}, + { 166, 90, -61, -242, 186, -74, -43}, + { -46, -92, 49, -227, 24, -155, 39}, + { 67, 85, 99, -42, 53, -184, -281}, + { 142, -122, 0, 21, -142, -15, -17}, + { 223, 92, -21, -48, -82, -14, -167}, + { 51, -37, -243, -30, -90, 18, -56}, + { 54, 105, 74, 86, 69, 13, -101}, + { 196, 72, -89, 43, 65, 19, 39}, + { 121, 34, 131, -82, 25, 213, -156}, + { 101, -102, -136, -21, 57, 214, 22}, + { 36, -124, 205, 204, 58, -156, -83}, + { 83, -117, 137, 137, 85, 116, 44}, + { -92, -148, -68, 11, -102, -197, -220}, + { -76, -185, -58, 132, -26, -183, 85}, + { -7, -31, -2, 23, 205, -151, 10}, + { -27, -37, -5, -18, 292, 131, 1}, + { 117, -168, 9, -93, 80, -59, -125}, + { -182, -244, 98, -24, 135, -22, 94}, + { 221, 97, 106, 42, 43, -160, 83}, + { 25, -64, -21, 6, 14, -15, 154}, + { 126, 15, -140, 150, -10, -207, -114}, + { 79, -63, -211, -70, -28, -217, 165}, + { 46, 38, -22, 281, 132, -62, 109}, + { 112, 54, -112, -93, 208, 27, 296}, + { 115, 10, -147, 41, 216, 42, -276}, + { 50, -115, -254, 167, 117, -2, 61}, + { 17, 144, 34, -72, -186, -150, 272}, + { -29, -66, -89, -95, -149, 129, 251}, + { 122, 0, -50, -234, -91, 36, 26}, + { -105, -102, -88, -121, -236, -7, -11}, + { -204, 109, 5, -191, 105, -15, 163}, + { -80, 32, -24, -209, 41, 294, 70}, + { -106, -94, -204, -118, 120, -50, -37}, + { -82, -241, 46, -131, -29, 150, -55}, + { 33, 155, 120, -89, -8, 7, 62}, + { 213, 82, 61, 18, -161, 144, 152}, + { 30, 131, 65, -87, -255, -17, -107}, + { -8, 85, -64, 51, -162, 223, -53}, + { -134, 261, 69, -56, 218, 72, -111}, + { 2, 155, -113, -87, 49, 85, -28}, + { -163, 42, -1, -196, 7, 39, -245}, + { 14, -137, -79, 11, -160, 202, -293}, + { -94, 33, 208, 100, 56, -44, 326}, + { -78, -41, 232, 13, -142, 227, 80}, + { -16, -87, 201, 33, -133, 15, -183}, + { -58, -192, -47, 184, -128, 133, 99}, + { -205, 11, -155, 78, 52, 72, 141}, + { -246, 26, 99, 151, 59, 115, -64}, + { -79, -47, -16, -14, 6, 47, -43}, + { -72, -178, -27, 162, 112, 43, -174}, + { -175, 238, 186, 71, -54, -188, -76}, + { -225, 233, 39, -39, -158, 122, 44}, + { -26, 43, 84, 130, -93, -51, 22}, + { 3, 92, -150, 136, -182, -57, 97}, + { -131, 179, -78, 80, 91, -165, 90}, + { -2, 148, 15, 130, 65, 175, 117}, + { -138, 114, -137, 132, 3, -10, -186}, + { 140, -4, -37, 254, -62, 92, -109} +}; + +/** Means of ISF vectors in Q15 */ +static const int16_t isf_mean[LP_ORDER] = { + 738, 1326, 2336, 3578, 4596, 5662, 6711, 7730, + 8750, 9753, 10705, 11728, 12833, 13971, 15043, 4037 +}; + +/** Initialization tables for the processed ISF vector in Q15 */ +static const int16_t isf_init[LP_ORDER] = { + 1024, 2048, 3072, 4096, 5120, 6144, 7168, 8192, + 9216, 10240, 11264, 12288, 13312, 14336, 15360, 3840 +}; + +/** ISF/ISP interpolation coefficients for each subframe */ +static const float isfp_inter[4] = { 0.45, 0.8, 0.96, 1.0 }; + +/** Coefficients for FIR interpolation of excitation vector + * at pitch lag resulting the adaptive codebook vector */ +static const float ac_inter[65] = { + 9.400024e-01, + 8.563843e-01, 6.322632e-01, 3.375854e-01, 5.908203e-02, + -1.310425e-01, -1.994019e-01, -1.585693e-01, -5.633545e-02, + 4.760742e-02, 1.067505e-01, 1.036987e-01, 5.206299e-02, + -1.519775e-02, -6.372070e-02, -7.366943e-02, -4.650879e-02, + -9.765625e-04, 3.820801e-02, 5.316162e-02, 4.003906e-02, + 9.338379e-03, -2.166748e-02, -3.778076e-02, -3.320312e-02, + -1.300049e-02, 1.068115e-02, 2.587891e-02, 2.630615e-02, + 1.379395e-02, -3.662109e-03, -1.678467e-02, -1.983643e-02, + -1.275635e-02, -5.493164e-04, 1.007080e-02, 1.409912e-02, + 1.068115e-02, 2.624512e-03, -5.371094e-03, -9.338379e-03, + -8.117676e-03, -3.173828e-03, 2.319336e-03, 5.615234e-03, + 5.554199e-03, 2.868652e-03, -6.103516e-04, -2.990723e-03, + -3.356934e-03, -2.014160e-03, -1.220703e-04, 1.342773e-03, + 1.708984e-03, 1.159668e-03, 2.441406e-04, -4.272461e-04, + -6.103516e-04, -4.272461e-04, -1.220703e-04, 6.103516e-05, + 1.220703e-04, 6.103516e-05, 0.000000e+00, 0.000000e+00 +}; + +/** [i][j] is the number of pulses present in track j at mode i */ +static const uint8_t pulses_nb_per_mode_tr[][4] = { + {1, 1, 0, 0}, {1, 1, 1, 1}, {2, 2, 2, 2}, + {3, 3, 2, 2}, {3, 3, 3, 3}, {4, 4, 4, 4}, + {5, 5, 4, 4}, {6, 6, 6, 6}, {6, 6, 6, 6} +}; + +/** Tables for decoding quantized gains { pitch (Q14), fixed factor (Q11) } */ +static const int16_t qua_gain_6b[64][2] = { + { 1566, 1332}, { 1577, 3557}, + { 3071, 6490}, { 4193, 10163}, + { 4496, 2534}, { 5019, 4488}, + { 5586, 15614}, { 5725, 1422}, + { 6453, 580}, { 6724, 6831}, + { 7657, 3527}, { 8072, 2099}, + { 8232, 5319}, { 8827, 8775}, + { 9740, 2868}, { 9856, 1465}, + { 10087, 12488}, { 10241, 4453}, + { 10859, 6618}, { 11321, 3587}, + { 11417, 1800}, { 11643, 2428}, + { 11718, 988}, { 12312, 5093}, + { 12523, 8413}, { 12574, 26214}, + { 12601, 3396}, { 13172, 1623}, + { 13285, 2423}, { 13418, 6087}, + { 13459, 12810}, { 13656, 3607}, + { 14111, 4521}, { 14144, 1229}, + { 14425, 1871}, { 14431, 7234}, + { 14445, 2834}, { 14628, 10036}, + { 14860, 17496}, { 15161, 3629}, + { 15209, 5819}, { 15299, 2256}, + { 15518, 4722}, { 15663, 1060}, + { 15759, 7972}, { 15939, 11964}, + { 16020, 2996}, { 16086, 1707}, + { 16521, 4254}, { 16576, 6224}, + { 16894, 2380}, { 16906, 681}, + { 17213, 8406}, { 17610, 3418}, + { 17895, 5269}, { 18168, 11748}, + { 18230, 1575}, { 18607, 32767}, + { 18728, 21684}, { 19137, 2543}, + { 19422, 6577}, { 19446, 4097}, + { 19450, 9056}, { 20371, 14885} +}; + +static const int16_t qua_gain_7b[128][2] = { + { 204, 441}, { 464, 1977}, + { 869, 1077}, { 1072, 3062}, + { 1281, 4759}, { 1647, 1539}, + { 1845, 7020}, { 1853, 634}, + { 1995, 2336}, { 2351, 15400}, + { 2661, 1165}, { 2702, 3900}, + { 2710, 10133}, { 3195, 1752}, + { 3498, 2624}, { 3663, 849}, + { 3984, 5697}, { 4214, 3399}, + { 4415, 1304}, { 4695, 2056}, + { 5376, 4558}, { 5386, 676}, + { 5518, 23554}, { 5567, 7794}, + { 5644, 3061}, { 5672, 1513}, + { 5957, 2338}, { 6533, 1060}, + { 6804, 5998}, { 6820, 1767}, + { 6937, 3837}, { 7277, 414}, + { 7305, 2665}, { 7466, 11304}, + { 7942, 794}, { 8007, 1982}, + { 8007, 1366}, { 8326, 3105}, + { 8336, 4810}, { 8708, 7954}, + { 8989, 2279}, { 9031, 1055}, + { 9247, 3568}, { 9283, 1631}, + { 9654, 6311}, { 9811, 2605}, + { 10120, 683}, { 10143, 4179}, + { 10245, 1946}, { 10335, 1218}, + { 10468, 9960}, { 10651, 3000}, + { 10951, 1530}, { 10969, 5290}, + { 11203, 2305}, { 11325, 3562}, + { 11771, 6754}, { 11839, 1849}, + { 11941, 4495}, { 11954, 1298}, + { 11975, 15223}, { 11977, 883}, + { 11986, 2842}, { 12438, 2141}, + { 12593, 3665}, { 12636, 8367}, + { 12658, 1594}, { 12886, 2628}, + { 12984, 4942}, { 13146, 1115}, + { 13224, 524}, { 13341, 3163}, + { 13399, 1923}, { 13549, 5961}, + { 13606, 1401}, { 13655, 2399}, + { 13782, 3909}, { 13868, 10923}, + { 14226, 1723}, { 14232, 2939}, + { 14278, 7528}, { 14439, 4598}, + { 14451, 984}, { 14458, 2265}, + { 14792, 1403}, { 14818, 3445}, + { 14899, 5709}, { 15017, 15362}, + { 15048, 1946}, { 15069, 2655}, + { 15405, 9591}, { 15405, 4079}, + { 15570, 7183}, { 15687, 2286}, + { 15691, 1624}, { 15699, 3068}, + { 15772, 5149}, { 15868, 1205}, + { 15970, 696}, { 16249, 3584}, + { 16338, 1917}, { 16424, 2560}, + { 16483, 4438}, { 16529, 6410}, + { 16620, 11966}, { 16839, 8780}, + { 17030, 3050}, { 17033, 18325}, + { 17092, 1568}, { 17123, 5197}, + { 17351, 2113}, { 17374, 980}, + { 17566, 26214}, { 17609, 3912}, + { 17639, 32767}, { 18151, 7871}, + { 18197, 2516}, { 18202, 5649}, + { 18679, 3283}, { 18930, 1370}, + { 19271, 13757}, { 19317, 4120}, + { 19460, 1973}, { 19654, 10018}, + { 19764, 6792}, { 19912, 5135}, + { 20040, 2841}, { 21234, 19833} +}; + +/** 4-tap moving average prediction coefficients in reverse order */ +static const float energy_pred_fac[4] = { 0.2, 0.3, 0.4, 0.5 }; + +/** impulse response filter tables converted to float from Q15 + * used for anti-sparseness processing */ +static const float ir_filter_str[64] = { + 6.159058e-01, 2.958069e-01, 9.979248e-02, -1.048889e-01, + 8.740234e-02, -1.599121e-01, 4.849243e-02, -4.141235e-02, + 1.831055e-02, 1.188049e-01, -4.568481e-02, -2.130127e-02, + 3.671265e-02, -1.601868e-01, 3.659058e-02, 1.639099e-01, + -4.541016e-02, -2.151489e-02, -8.810425e-02, 6.030273e-02, + 2.740479e-02, 2.200317e-02, -1.182861e-01, 1.289978e-01, + -1.560059e-01, 1.953125e-01, -3.149414e-02, -1.441956e-01, + 1.249084e-01, -1.328125e-01, 9.780884e-02, 6.500244e-02, + -6.091309e-02, -5.599976e-02, 8.081055e-02, -5.450439e-02, + -1.239014e-02, 1.748657e-02, 7.580566e-02, -1.101074e-01, + 9.579468e-02, -4.159546e-02, -7.830811e-02, 1.162109e-01, + -1.950073e-02, -6.259155e-02, -1.651001e-02, 7.250977e-02, + 1.199951e-01, -1.911011e-01, 4.370117e-02, -1.098938e-01, + 1.492004e-01, 1.129150e-02, 1.730347e-02, -3.549194e-02, + -8.709717e-02, 5.841064e-02, 1.190186e-03, -7.379150e-02, + 1.054077e-01, 9.078979e-02, -1.227112e-01, 1.047058e-01 +}; + +static const float ir_filter_mid[64] = { + 7.354126e-01, 3.192139e-01, -1.606140e-01, -2.328491e-02, + 6.250000e-02, -2.828979e-02, 5.349731e-02, -1.014099e-01, + 6.750488e-02, 1.989746e-02, -6.549072e-02, 7.589722e-02, + -1.080017e-01, 1.253967e-01, -6.430054e-02, -1.141357e-02, + -1.910400e-02, 1.303101e-01, -1.673889e-01, 6.820679e-02, + 5.670166e-02, -8.450317e-02, 2.270508e-02, 3.479004e-02, + -2.328491e-02, -4.928589e-02, 1.239014e-01, -1.395874e-01, + 9.100342e-02, -3.549194e-02, 2.230835e-02, -3.350830e-02, + 2.450562e-02, 5.096436e-03, -2.178955e-02, 1.849365e-02, + -1.708984e-02, 1.950073e-02, 1.312256e-03, -5.389404e-02, + 9.851074e-02, -8.489990e-02, 2.029419e-02, 2.328491e-02, + 7.110596e-03, -6.109619e-02, 3.939819e-02, 5.709839e-02, + -1.058960e-01, 3.149414e-02, 8.270264e-02, -1.232910e-01, + 1.105957e-01, -1.286011e-01, 1.614990e-01, -1.303101e-01, + 4.769897e-02, 3.295898e-03, -1.770020e-02, 5.010986e-02, + -7.501221e-02, 2.920532e-02, 1.660156e-02, 7.751465e-02 +}; + +static const float * const ir_filters_lookup[2] = { + ir_filter_str, ir_filter_mid +}; + +/** High-pass filters coefficients for 31 Hz and 400 Hz cutoff */ +static const float hpf_zeros[2] = { -2.0, 1.0 }; +static const float hpf_31_poles[2] = { -1.978881836, 0.979125977 }; +static const float hpf_31_gain = 0.989501953; + +static const float hpf_400_poles[2] = { -1.787109375, 0.864257812 }; +static const float hpf_400_gain = 0.893554687; + +/** Interpolation coefficients for 5/4 signal upsampling + * Table from the reference source was reordered for efficiency */ +static const float upsample_fir[4][24] = { + { -6.103516e-05, 7.324219e-04, -2.014160e-03, 4.150391e-03, + -7.263184e-03, 1.165771e-02, -1.776123e-02, 2.624512e-02, + -3.869629e-02, 5.877686e-02, -9.863281e-02, 2.314453e-01, + 9.348755e-01, -1.523438e-01, 7.861328e-02, -4.937744e-02, + 3.308105e-02, -2.252197e-02, 1.507568e-02, -9.765625e-03, + 5.859375e-03, -3.173828e-03, 1.403809e-03, -3.662109e-04 }, + { -2.441406e-04, 1.464844e-03, -3.784180e-03, 7.568359e-03, + -1.300049e-02, 2.062988e-02, -3.112793e-02, 4.589844e-02, + -6.781006e-02, 1.042480e-01, -1.815186e-01, 5.016479e-01, + 7.548828e-01, -2.094727e-01, 1.148071e-01, -7.348633e-02, + 4.956055e-02, -3.369141e-02, 2.246094e-02, -1.434326e-02, + 8.483887e-03, -4.455566e-03, 1.831055e-03, -4.272461e-04 }, + { -4.272461e-04, 1.831055e-03, -4.455566e-03, 8.483887e-03, + -1.434326e-02, 2.246094e-02, -3.369141e-02, 4.956055e-02, + -7.348633e-02, 1.148071e-01, -2.094727e-01, 7.548828e-01, + 5.016479e-01, -1.815186e-01, 1.042480e-01, -6.781006e-02, + 4.589844e-02, -3.112793e-02, 2.062988e-02, -1.300049e-02, + 7.568359e-03, -3.784180e-03, 1.464844e-03, -2.441406e-04 }, + { -3.662109e-04, 1.403809e-03, -3.173828e-03, 5.859375e-03, + -9.765625e-03, 1.507568e-02, -2.252197e-02, 3.308105e-02, + -4.937744e-02, 7.861328e-02, -1.523438e-01, 9.348755e-01, + 2.314453e-01, -9.863281e-02, 5.877686e-02, -3.869629e-02, + 2.624512e-02, -1.776123e-02, 1.165771e-02, -7.263184e-03, + 4.150391e-03, -2.014160e-03, 7.324219e-04, -6.103516e-05 } +}; + +/** High band quantized gains for 23k85 in Q14 */ +static const uint16_t qua_hb_gain[16] = { + 3624, 4673, 5597, 6479, 7425, 8378, 9324, 10264, + 11210, 12206, 13391, 14844, 16770, 19655, 24289, 32728 +}; + +/** High-band post-processing FIR filters coefficients from Q15 */ +static const float bpf_6_7_coef[31] = { // band pass, 6kHz and 7kHz cutoffs + -2.441406e-04, 3.585815e-04, 2.441406e-04, + -2.059937e-04, -2.815248e-03, 8.560180e-03, + -1.084137e-02, 0.000000e+00, 2.897645e-02, + -6.774902e-02, 9.421540e-02, -8.380128e-02, + 2.706910e-02, 5.924987e-02, -1.373367e-01, + 1.687469e-01, + -1.373367e-01, 5.924987e-02, 2.706910e-02, + -8.380128e-02, 9.421540e-02, -6.774902e-02, + 2.897645e-02, 0.000000e+00, -1.084137e-02, + 8.560180e-03, -2.815248e-03, -2.059937e-04, + 2.441406e-04, 3.585815e-04, -2.441406e-04 +}; + +static const float lpf_7_coef[31] = { // low pass, 7kHz cutoff + -6.408691e-04, 1.434326e-03, -2.716064e-03, + 4.455566e-03, -6.195068e-03, 6.988525e-03, + -5.401611e-03, 0.000000e+00, 1.022339e-02, + -2.560425e-02, 4.531860e-02, -6.747437e-02, + 8.944702e-02, -1.080933e-01, 1.206360e-01, + 8.753052e-01, + 1.206360e-01, -1.080933e-01, 8.944702e-02, + -6.747437e-02, 4.531860e-02, -2.560425e-02, + 1.022339e-02, 0.000000e+00, -5.401611e-03, + 6.988525e-03, -6.195068e-03, 4.455566e-03, + -2.716064e-03, 1.434326e-03, -6.408691e-04 +}; + +/** Core frame sizes in each mode */ +static const uint16_t cf_sizes_wb[] = { + 132, 177, 253, 285, 317, 365, 397, 461, 477, + 40 /// SID/comfort noise frame +}; + +#endif /* AVCODEC_AMRWBDATA_H */ diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/amrwbdec.c b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/amrwbdec.c new file mode 100644 index 000000000..35c9cf6a2 --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/amrwbdec.c @@ -0,0 +1,1281 @@ +/* + * AMR wideband decoder + * Copyright (c) 2010 Marcelo Galvao Povoa + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A particular PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * AMR wideband decoder + */ + +#include "libavutil/channel_layout.h" +#include "libavutil/common.h" +#include "libavutil/float_dsp.h" +#include "libavutil/lfg.h" +#include "libavutil/internal.h" + +#include "avcodec.h" +#include "lsp.h" +#include "celp_filters.h" +#include "celp_math.h" +#include "acelp_filters.h" +#include "acelp_vectors.h" +#include "acelp_pitch_delay.h" +#include "internal.h" + +#define AMR_USE_16BIT_TABLES +#include "amr.h" + +#include "amrwbdata.h" +#include "mips/amrwbdec_mips.h" + +typedef struct { + AMRWBFrame frame; ///< AMRWB parameters decoded from bitstream + enum Mode fr_cur_mode; ///< mode index of current frame + uint8_t fr_quality; ///< frame quality index (FQI) + float isf_cur[LP_ORDER]; ///< working ISF vector from current frame + float isf_q_past[LP_ORDER]; ///< quantized ISF vector of the previous frame + float isf_past_final[LP_ORDER]; ///< final processed ISF vector of the previous frame + double isp[4][LP_ORDER]; ///< ISP vectors from current frame + double isp_sub4_past[LP_ORDER]; ///< ISP vector for the 4th subframe of the previous frame + + float lp_coef[4][LP_ORDER]; ///< Linear Prediction Coefficients from ISP vector + + uint8_t base_pitch_lag; ///< integer part of pitch lag for the next relative subframe + uint8_t pitch_lag_int; ///< integer part of pitch lag of the previous subframe + + float excitation_buf[AMRWB_P_DELAY_MAX + LP_ORDER + 2 + AMRWB_SFR_SIZE]; ///< current excitation and all necessary excitation history + float *excitation; ///< points to current excitation in excitation_buf[] + + float pitch_vector[AMRWB_SFR_SIZE]; ///< adaptive codebook (pitch) vector for current subframe + float fixed_vector[AMRWB_SFR_SIZE]; ///< algebraic codebook (fixed) vector for current subframe + + float prediction_error[4]; ///< quantified prediction errors {20log10(^gamma_gc)} for previous four subframes + float pitch_gain[6]; ///< quantified pitch gains for the current and previous five subframes + float fixed_gain[2]; ///< quantified fixed gains for the current and previous subframes + + float tilt_coef; ///< {beta_1} related to the voicing of the previous subframe + + float prev_sparse_fixed_gain; ///< previous fixed gain; used by anti-sparseness to determine "onset" + uint8_t prev_ir_filter_nr; ///< previous impulse response filter "impNr": 0 - strong, 1 - medium, 2 - none + float prev_tr_gain; ///< previous initial gain used by noise enhancer for threshold + + float samples_az[LP_ORDER + AMRWB_SFR_SIZE]; ///< low-band samples and memory from synthesis at 12.8kHz + float samples_up[UPS_MEM_SIZE + AMRWB_SFR_SIZE]; ///< low-band samples and memory processed for upsampling + float samples_hb[LP_ORDER_16k + AMRWB_SFR_SIZE_16k]; ///< high-band samples and memory from synthesis at 16kHz + + float hpf_31_mem[2], hpf_400_mem[2]; ///< previous values in the high pass filters + float demph_mem[1]; ///< previous value in the de-emphasis filter + float bpf_6_7_mem[HB_FIR_SIZE]; ///< previous values in the high-band band pass filter + float lpf_7_mem[HB_FIR_SIZE]; ///< previous values in the high-band low pass filter + + AVLFG prng; ///< random number generator for white noise excitation + uint8_t first_frame; ///< flag active during decoding of the first frame + ACELPFContext acelpf_ctx; ///< context for filters for ACELP-based codecs + ACELPVContext acelpv_ctx; ///< context for vector operations for ACELP-based codecs + CELPFContext celpf_ctx; ///< context for filters for CELP-based codecs + CELPMContext celpm_ctx; ///< context for fixed point math operations + +} AMRWBContext; + +static av_cold int amrwb_decode_init(AVCodecContext *avctx) +{ + AMRWBContext *ctx = avctx->priv_data; + int i; + + if (avctx->channels > 1) { + avpriv_report_missing_feature(avctx, "multi-channel AMR"); + return AVERROR_PATCHWELCOME; + } + + avctx->channels = 1; + avctx->channel_layout = AV_CH_LAYOUT_MONO; + if (!avctx->sample_rate) + avctx->sample_rate = 16000; + avctx->sample_fmt = AV_SAMPLE_FMT_FLT; + + av_lfg_init(&ctx->prng, 1); + + ctx->excitation = &ctx->excitation_buf[AMRWB_P_DELAY_MAX + LP_ORDER + 1]; + ctx->first_frame = 1; + + for (i = 0; i < LP_ORDER; i++) + ctx->isf_past_final[i] = isf_init[i] * (1.0f / (1 << 15)); + + for (i = 0; i < 4; i++) + ctx->prediction_error[i] = MIN_ENERGY; + + ff_acelp_filter_init(&ctx->acelpf_ctx); + ff_acelp_vectors_init(&ctx->acelpv_ctx); + ff_celp_filter_init(&ctx->celpf_ctx); + ff_celp_math_init(&ctx->celpm_ctx); + + return 0; +} + +/** + * Decode the frame header in the "MIME/storage" format. This format + * is simpler and does not carry the auxiliary frame information. + * + * @param[in] ctx The Context + * @param[in] buf Pointer to the input buffer + * + * @return The decoded header length in bytes + */ +static int decode_mime_header(AMRWBContext *ctx, const uint8_t *buf) +{ + /* Decode frame header (1st octet) */ + ctx->fr_cur_mode = buf[0] >> 3 & 0x0F; + ctx->fr_quality = (buf[0] & 0x4) == 0x4; + + return 1; +} + +/** + * Decode quantized ISF vectors using 36-bit indexes (6K60 mode only). + * + * @param[in] ind Array of 5 indexes + * @param[out] isf_q Buffer for isf_q[LP_ORDER] + * + */ +static void decode_isf_indices_36b(uint16_t *ind, float *isf_q) +{ + int i; + + for (i = 0; i < 9; i++) + isf_q[i] = dico1_isf[ind[0]][i] * (1.0f / (1 << 15)); + + for (i = 0; i < 7; i++) + isf_q[i + 9] = dico2_isf[ind[1]][i] * (1.0f / (1 << 15)); + + for (i = 0; i < 5; i++) + isf_q[i] += dico21_isf_36b[ind[2]][i] * (1.0f / (1 << 15)); + + for (i = 0; i < 4; i++) + isf_q[i + 5] += dico22_isf_36b[ind[3]][i] * (1.0f / (1 << 15)); + + for (i = 0; i < 7; i++) + isf_q[i + 9] += dico23_isf_36b[ind[4]][i] * (1.0f / (1 << 15)); +} + +/** + * Decode quantized ISF vectors using 46-bit indexes (except 6K60 mode). + * + * @param[in] ind Array of 7 indexes + * @param[out] isf_q Buffer for isf_q[LP_ORDER] + * + */ +static void decode_isf_indices_46b(uint16_t *ind, float *isf_q) +{ + int i; + + for (i = 0; i < 9; i++) + isf_q[i] = dico1_isf[ind[0]][i] * (1.0f / (1 << 15)); + + for (i = 0; i < 7; i++) + isf_q[i + 9] = dico2_isf[ind[1]][i] * (1.0f / (1 << 15)); + + for (i = 0; i < 3; i++) + isf_q[i] += dico21_isf[ind[2]][i] * (1.0f / (1 << 15)); + + for (i = 0; i < 3; i++) + isf_q[i + 3] += dico22_isf[ind[3]][i] * (1.0f / (1 << 15)); + + for (i = 0; i < 3; i++) + isf_q[i + 6] += dico23_isf[ind[4]][i] * (1.0f / (1 << 15)); + + for (i = 0; i < 3; i++) + isf_q[i + 9] += dico24_isf[ind[5]][i] * (1.0f / (1 << 15)); + + for (i = 0; i < 4; i++) + isf_q[i + 12] += dico25_isf[ind[6]][i] * (1.0f / (1 << 15)); +} + +/** + * Apply mean and past ISF values using the prediction factor. + * Updates past ISF vector. + * + * @param[in,out] isf_q Current quantized ISF + * @param[in,out] isf_past Past quantized ISF + * + */ +static void isf_add_mean_and_past(float *isf_q, float *isf_past) +{ + int i; + float tmp; + + for (i = 0; i < LP_ORDER; i++) { + tmp = isf_q[i]; + isf_q[i] += isf_mean[i] * (1.0f / (1 << 15)); + isf_q[i] += PRED_FACTOR * isf_past[i]; + isf_past[i] = tmp; + } +} + +/** + * Interpolate the fourth ISP vector from current and past frames + * to obtain an ISP vector for each subframe. + * + * @param[in,out] isp_q ISPs for each subframe + * @param[in] isp4_past Past ISP for subframe 4 + */ +static void interpolate_isp(double isp_q[4][LP_ORDER], const double *isp4_past) +{ + int i, k; + + for (k = 0; k < 3; k++) { + float c = isfp_inter[k]; + for (i = 0; i < LP_ORDER; i++) + isp_q[k][i] = (1.0 - c) * isp4_past[i] + c * isp_q[3][i]; + } +} + +/** + * Decode an adaptive codebook index into pitch lag (except 6k60, 8k85 modes). + * Calculate integer lag and fractional lag always using 1/4 resolution. + * In 1st and 3rd subframes the index is relative to last subframe integer lag. + * + * @param[out] lag_int Decoded integer pitch lag + * @param[out] lag_frac Decoded fractional pitch lag + * @param[in] pitch_index Adaptive codebook pitch index + * @param[in,out] base_lag_int Base integer lag used in relative subframes + * @param[in] subframe Current subframe index (0 to 3) + */ +static void decode_pitch_lag_high(int *lag_int, int *lag_frac, int pitch_index, + uint8_t *base_lag_int, int subframe) +{ + if (subframe == 0 || subframe == 2) { + if (pitch_index < 376) { + *lag_int = (pitch_index + 137) >> 2; + *lag_frac = pitch_index - (*lag_int << 2) + 136; + } else if (pitch_index < 440) { + *lag_int = (pitch_index + 257 - 376) >> 1; + *lag_frac = (pitch_index - (*lag_int << 1) + 256 - 376) << 1; + /* the actual resolution is 1/2 but expressed as 1/4 */ + } else { + *lag_int = pitch_index - 280; + *lag_frac = 0; + } + /* minimum lag for next subframe */ + *base_lag_int = av_clip(*lag_int - 8 - (*lag_frac < 0), + AMRWB_P_DELAY_MIN, AMRWB_P_DELAY_MAX - 15); + // XXX: the spec states clearly that *base_lag_int should be + // the nearest integer to *lag_int (minus 8), but the ref code + // actually always uses its floor, I'm following the latter + } else { + *lag_int = (pitch_index + 1) >> 2; + *lag_frac = pitch_index - (*lag_int << 2); + *lag_int += *base_lag_int; + } +} + +/** + * Decode an adaptive codebook index into pitch lag for 8k85 and 6k60 modes. + * The description is analogous to decode_pitch_lag_high, but in 6k60 the + * relative index is used for all subframes except the first. + */ +static void decode_pitch_lag_low(int *lag_int, int *lag_frac, int pitch_index, + uint8_t *base_lag_int, int subframe, enum Mode mode) +{ + if (subframe == 0 || (subframe == 2 && mode != MODE_6k60)) { + if (pitch_index < 116) { + *lag_int = (pitch_index + 69) >> 1; + *lag_frac = (pitch_index - (*lag_int << 1) + 68) << 1; + } else { + *lag_int = pitch_index - 24; + *lag_frac = 0; + } + // XXX: same problem as before + *base_lag_int = av_clip(*lag_int - 8 - (*lag_frac < 0), + AMRWB_P_DELAY_MIN, AMRWB_P_DELAY_MAX - 15); + } else { + *lag_int = (pitch_index + 1) >> 1; + *lag_frac = (pitch_index - (*lag_int << 1)) << 1; + *lag_int += *base_lag_int; + } +} + +/** + * Find the pitch vector by interpolating the past excitation at the + * pitch delay, which is obtained in this function. + * + * @param[in,out] ctx The context + * @param[in] amr_subframe Current subframe data + * @param[in] subframe Current subframe index (0 to 3) + */ +static void decode_pitch_vector(AMRWBContext *ctx, + const AMRWBSubFrame *amr_subframe, + const int subframe) +{ + int pitch_lag_int, pitch_lag_frac; + int i; + float *exc = ctx->excitation; + enum Mode mode = ctx->fr_cur_mode; + + if (mode <= MODE_8k85) { + decode_pitch_lag_low(&pitch_lag_int, &pitch_lag_frac, amr_subframe->adap, + &ctx->base_pitch_lag, subframe, mode); + } else + decode_pitch_lag_high(&pitch_lag_int, &pitch_lag_frac, amr_subframe->adap, + &ctx->base_pitch_lag, subframe); + + ctx->pitch_lag_int = pitch_lag_int; + pitch_lag_int += pitch_lag_frac > 0; + + /* Calculate the pitch vector by interpolating the past excitation at the + pitch lag using a hamming windowed sinc function */ + ctx->acelpf_ctx.acelp_interpolatef(exc, + exc + 1 - pitch_lag_int, + ac_inter, 4, + pitch_lag_frac + (pitch_lag_frac > 0 ? 0 : 4), + LP_ORDER, AMRWB_SFR_SIZE + 1); + + /* Check which pitch signal path should be used + * 6k60 and 8k85 modes have the ltp flag set to 0 */ + if (amr_subframe->ltp) { + memcpy(ctx->pitch_vector, exc, AMRWB_SFR_SIZE * sizeof(float)); + } else { + for (i = 0; i < AMRWB_SFR_SIZE; i++) + ctx->pitch_vector[i] = 0.18 * exc[i - 1] + 0.64 * exc[i] + + 0.18 * exc[i + 1]; + memcpy(exc, ctx->pitch_vector, AMRWB_SFR_SIZE * sizeof(float)); + } +} + +/** Get x bits in the index interval [lsb,lsb+len-1] inclusive */ +#define BIT_STR(x,lsb,len) (((x) >> (lsb)) & ((1 << (len)) - 1)) + +/** Get the bit at specified position */ +#define BIT_POS(x, p) (((x) >> (p)) & 1) + +/** + * The next six functions decode_[i]p_track decode exactly i pulses + * positions and amplitudes (-1 or 1) in a subframe track using + * an encoded pulse indexing (TS 26.190 section 5.8.2). + * + * The results are given in out[], in which a negative number means + * amplitude -1 and vice versa (i.e., ampl(x) = x / abs(x) ). + * + * @param[out] out Output buffer (writes i elements) + * @param[in] code Pulse index (no. of bits varies, see below) + * @param[in] m (log2) Number of potential positions + * @param[in] off Offset for decoded positions + */ +static inline void decode_1p_track(int *out, int code, int m, int off) +{ + int pos = BIT_STR(code, 0, m) + off; ///code: m+1 bits + + out[0] = BIT_POS(code, m) ? -pos : pos; +} + +static inline void decode_2p_track(int *out, int code, int m, int off) ///code: 2m+1 bits +{ + int pos0 = BIT_STR(code, m, m) + off; + int pos1 = BIT_STR(code, 0, m) + off; + + out[0] = BIT_POS(code, 2*m) ? -pos0 : pos0; + out[1] = BIT_POS(code, 2*m) ? -pos1 : pos1; + out[1] = pos0 > pos1 ? -out[1] : out[1]; +} + +static void decode_3p_track(int *out, int code, int m, int off) ///code: 3m+1 bits +{ + int half_2p = BIT_POS(code, 2*m - 1) << (m - 1); + + decode_2p_track(out, BIT_STR(code, 0, 2*m - 1), + m - 1, off + half_2p); + decode_1p_track(out + 2, BIT_STR(code, 2*m, m + 1), m, off); +} + +static void decode_4p_track(int *out, int code, int m, int off) ///code: 4m bits +{ + int half_4p, subhalf_2p; + int b_offset = 1 << (m - 1); + + switch (BIT_STR(code, 4*m - 2, 2)) { /* case ID (2 bits) */ + case 0: /* 0 pulses in A, 4 pulses in B or vice versa */ + half_4p = BIT_POS(code, 4*m - 3) << (m - 1); // which has 4 pulses + subhalf_2p = BIT_POS(code, 2*m - 3) << (m - 2); + + decode_2p_track(out, BIT_STR(code, 0, 2*m - 3), + m - 2, off + half_4p + subhalf_2p); + decode_2p_track(out + 2, BIT_STR(code, 2*m - 2, 2*m - 1), + m - 1, off + half_4p); + break; + case 1: /* 1 pulse in A, 3 pulses in B */ + decode_1p_track(out, BIT_STR(code, 3*m - 2, m), + m - 1, off); + decode_3p_track(out + 1, BIT_STR(code, 0, 3*m - 2), + m - 1, off + b_offset); + break; + case 2: /* 2 pulses in each half */ + decode_2p_track(out, BIT_STR(code, 2*m - 1, 2*m - 1), + m - 1, off); + decode_2p_track(out + 2, BIT_STR(code, 0, 2*m - 1), + m - 1, off + b_offset); + break; + case 3: /* 3 pulses in A, 1 pulse in B */ + decode_3p_track(out, BIT_STR(code, m, 3*m - 2), + m - 1, off); + decode_1p_track(out + 3, BIT_STR(code, 0, m), + m - 1, off + b_offset); + break; + } +} + +static void decode_5p_track(int *out, int code, int m, int off) ///code: 5m bits +{ + int half_3p = BIT_POS(code, 5*m - 1) << (m - 1); + + decode_3p_track(out, BIT_STR(code, 2*m + 1, 3*m - 2), + m - 1, off + half_3p); + + decode_2p_track(out + 3, BIT_STR(code, 0, 2*m + 1), m, off); +} + +static void decode_6p_track(int *out, int code, int m, int off) ///code: 6m-2 bits +{ + int b_offset = 1 << (m - 1); + /* which half has more pulses in cases 0 to 2 */ + int half_more = BIT_POS(code, 6*m - 5) << (m - 1); + int half_other = b_offset - half_more; + + switch (BIT_STR(code, 6*m - 4, 2)) { /* case ID (2 bits) */ + case 0: /* 0 pulses in A, 6 pulses in B or vice versa */ + decode_1p_track(out, BIT_STR(code, 0, m), + m - 1, off + half_more); + decode_5p_track(out + 1, BIT_STR(code, m, 5*m - 5), + m - 1, off + half_more); + break; + case 1: /* 1 pulse in A, 5 pulses in B or vice versa */ + decode_1p_track(out, BIT_STR(code, 0, m), + m - 1, off + half_other); + decode_5p_track(out + 1, BIT_STR(code, m, 5*m - 5), + m - 1, off + half_more); + break; + case 2: /* 2 pulses in A, 4 pulses in B or vice versa */ + decode_2p_track(out, BIT_STR(code, 0, 2*m - 1), + m - 1, off + half_other); + decode_4p_track(out + 2, BIT_STR(code, 2*m - 1, 4*m - 4), + m - 1, off + half_more); + break; + case 3: /* 3 pulses in A, 3 pulses in B */ + decode_3p_track(out, BIT_STR(code, 3*m - 2, 3*m - 2), + m - 1, off); + decode_3p_track(out + 3, BIT_STR(code, 0, 3*m - 2), + m - 1, off + b_offset); + break; + } +} + +/** + * Decode the algebraic codebook index to pulse positions and signs, + * then construct the algebraic codebook vector. + * + * @param[out] fixed_vector Buffer for the fixed codebook excitation + * @param[in] pulse_hi MSBs part of the pulse index array (higher modes only) + * @param[in] pulse_lo LSBs part of the pulse index array + * @param[in] mode Mode of the current frame + */ +static void decode_fixed_vector(float *fixed_vector, const uint16_t *pulse_hi, + const uint16_t *pulse_lo, const enum Mode mode) +{ + /* sig_pos stores for each track the decoded pulse position indexes + * (1-based) multiplied by its corresponding amplitude (+1 or -1) */ + int sig_pos[4][6]; + int spacing = (mode == MODE_6k60) ? 2 : 4; + int i, j; + + switch (mode) { + case MODE_6k60: + for (i = 0; i < 2; i++) + decode_1p_track(sig_pos[i], pulse_lo[i], 5, 1); + break; + case MODE_8k85: + for (i = 0; i < 4; i++) + decode_1p_track(sig_pos[i], pulse_lo[i], 4, 1); + break; + case MODE_12k65: + for (i = 0; i < 4; i++) + decode_2p_track(sig_pos[i], pulse_lo[i], 4, 1); + break; + case MODE_14k25: + for (i = 0; i < 2; i++) + decode_3p_track(sig_pos[i], pulse_lo[i], 4, 1); + for (i = 2; i < 4; i++) + decode_2p_track(sig_pos[i], pulse_lo[i], 4, 1); + break; + case MODE_15k85: + for (i = 0; i < 4; i++) + decode_3p_track(sig_pos[i], pulse_lo[i], 4, 1); + break; + case MODE_18k25: + for (i = 0; i < 4; i++) + decode_4p_track(sig_pos[i], (int) pulse_lo[i] + + ((int) pulse_hi[i] << 14), 4, 1); + break; + case MODE_19k85: + for (i = 0; i < 2; i++) + decode_5p_track(sig_pos[i], (int) pulse_lo[i] + + ((int) pulse_hi[i] << 10), 4, 1); + for (i = 2; i < 4; i++) + decode_4p_track(sig_pos[i], (int) pulse_lo[i] + + ((int) pulse_hi[i] << 14), 4, 1); + break; + case MODE_23k05: + case MODE_23k85: + for (i = 0; i < 4; i++) + decode_6p_track(sig_pos[i], (int) pulse_lo[i] + + ((int) pulse_hi[i] << 11), 4, 1); + break; + default: break; + } + + memset(fixed_vector, 0, sizeof(float) * AMRWB_SFR_SIZE); + + for (i = 0; i < 4; i++) + for (j = 0; j < pulses_nb_per_mode_tr[mode][i]; j++) { + int pos = (FFABS(sig_pos[i][j]) - 1) * spacing + i; + + fixed_vector[pos] += sig_pos[i][j] < 0 ? -1.0 : 1.0; + } +} + +/** + * Decode pitch gain and fixed gain correction factor. + * + * @param[in] vq_gain Vector-quantized index for gains + * @param[in] mode Mode of the current frame + * @param[out] fixed_gain_factor Decoded fixed gain correction factor + * @param[out] pitch_gain Decoded pitch gain + */ +static void decode_gains(const uint8_t vq_gain, const enum Mode mode, + float *fixed_gain_factor, float *pitch_gain) +{ + const int16_t *gains = (mode <= MODE_8k85 ? qua_gain_6b[vq_gain] : + qua_gain_7b[vq_gain]); + + *pitch_gain = gains[0] * (1.0f / (1 << 14)); + *fixed_gain_factor = gains[1] * (1.0f / (1 << 11)); +} + +/** + * Apply pitch sharpening filters to the fixed codebook vector. + * + * @param[in] ctx The context + * @param[in,out] fixed_vector Fixed codebook excitation + */ +// XXX: Spec states this procedure should be applied when the pitch +// lag is less than 64, but this checking seems absent in reference and AMR-NB +static void pitch_sharpening(AMRWBContext *ctx, float *fixed_vector) +{ + int i; + + /* Tilt part */ + for (i = AMRWB_SFR_SIZE - 1; i != 0; i--) + fixed_vector[i] -= fixed_vector[i - 1] * ctx->tilt_coef; + + /* Periodicity enhancement part */ + for (i = ctx->pitch_lag_int; i < AMRWB_SFR_SIZE; i++) + fixed_vector[i] += fixed_vector[i - ctx->pitch_lag_int] * 0.85; +} + +/** + * Calculate the voicing factor (-1.0 = unvoiced to 1.0 = voiced). + * + * @param[in] p_vector, f_vector Pitch and fixed excitation vectors + * @param[in] p_gain, f_gain Pitch and fixed gains + * @param[in] ctx The context + */ +// XXX: There is something wrong with the precision here! The magnitudes +// of the energies are not correct. Please check the reference code carefully +static float voice_factor(float *p_vector, float p_gain, + float *f_vector, float f_gain, + CELPMContext *ctx) +{ + double p_ener = (double) ctx->dot_productf(p_vector, p_vector, + AMRWB_SFR_SIZE) * + p_gain * p_gain; + double f_ener = (double) ctx->dot_productf(f_vector, f_vector, + AMRWB_SFR_SIZE) * + f_gain * f_gain; + + return (p_ener - f_ener) / (p_ener + f_ener); +} + +/** + * Reduce fixed vector sparseness by smoothing with one of three IR filters, + * also known as "adaptive phase dispersion". + * + * @param[in] ctx The context + * @param[in,out] fixed_vector Unfiltered fixed vector + * @param[out] buf Space for modified vector if necessary + * + * @return The potentially overwritten filtered fixed vector address + */ +static float *anti_sparseness(AMRWBContext *ctx, + float *fixed_vector, float *buf) +{ + int ir_filter_nr; + + if (ctx->fr_cur_mode > MODE_8k85) // no filtering in higher modes + return fixed_vector; + + if (ctx->pitch_gain[0] < 0.6) { + ir_filter_nr = 0; // strong filtering + } else if (ctx->pitch_gain[0] < 0.9) { + ir_filter_nr = 1; // medium filtering + } else + ir_filter_nr = 2; // no filtering + + /* detect 'onset' */ + if (ctx->fixed_gain[0] > 3.0 * ctx->fixed_gain[1]) { + if (ir_filter_nr < 2) + ir_filter_nr++; + } else { + int i, count = 0; + + for (i = 0; i < 6; i++) + if (ctx->pitch_gain[i] < 0.6) + count++; + + if (count > 2) + ir_filter_nr = 0; + + if (ir_filter_nr > ctx->prev_ir_filter_nr + 1) + ir_filter_nr--; + } + + /* update ir filter strength history */ + ctx->prev_ir_filter_nr = ir_filter_nr; + + ir_filter_nr += (ctx->fr_cur_mode == MODE_8k85); + + if (ir_filter_nr < 2) { + int i; + const float *coef = ir_filters_lookup[ir_filter_nr]; + + /* Circular convolution code in the reference + * decoder was modified to avoid using one + * extra array. The filtered vector is given by: + * + * c2(n) = sum(i,0,len-1){ c(i) * coef( (n - i + len) % len ) } + */ + + memset(buf, 0, sizeof(float) * AMRWB_SFR_SIZE); + for (i = 0; i < AMRWB_SFR_SIZE; i++) + if (fixed_vector[i]) + ff_celp_circ_addf(buf, buf, coef, i, fixed_vector[i], + AMRWB_SFR_SIZE); + fixed_vector = buf; + } + + return fixed_vector; +} + +/** + * Calculate a stability factor {teta} based on distance between + * current and past isf. A value of 1 shows maximum signal stability. + */ +static float stability_factor(const float *isf, const float *isf_past) +{ + int i; + float acc = 0.0; + + for (i = 0; i < LP_ORDER - 1; i++) + acc += (isf[i] - isf_past[i]) * (isf[i] - isf_past[i]); + + // XXX: This part is not so clear from the reference code + // the result is more accurate changing the "/ 256" to "* 512" + return FFMAX(0.0, 1.25 - acc * 0.8 * 512); +} + +/** + * Apply a non-linear fixed gain smoothing in order to reduce + * fluctuation in the energy of excitation. + * + * @param[in] fixed_gain Unsmoothed fixed gain + * @param[in,out] prev_tr_gain Previous threshold gain (updated) + * @param[in] voice_fac Frame voicing factor + * @param[in] stab_fac Frame stability factor + * + * @return The smoothed gain + */ +static float noise_enhancer(float fixed_gain, float *prev_tr_gain, + float voice_fac, float stab_fac) +{ + float sm_fac = 0.5 * (1 - voice_fac) * stab_fac; + float g0; + + // XXX: the following fixed-point constants used to in(de)crement + // gain by 1.5dB were taken from the reference code, maybe it could + // be simpler + if (fixed_gain < *prev_tr_gain) { + g0 = FFMIN(*prev_tr_gain, fixed_gain + fixed_gain * + (6226 * (1.0f / (1 << 15)))); // +1.5 dB + } else + g0 = FFMAX(*prev_tr_gain, fixed_gain * + (27536 * (1.0f / (1 << 15)))); // -1.5 dB + + *prev_tr_gain = g0; // update next frame threshold + + return sm_fac * g0 + (1 - sm_fac) * fixed_gain; +} + +/** + * Filter the fixed_vector to emphasize the higher frequencies. + * + * @param[in,out] fixed_vector Fixed codebook vector + * @param[in] voice_fac Frame voicing factor + */ +static void pitch_enhancer(float *fixed_vector, float voice_fac) +{ + int i; + float cpe = 0.125 * (1 + voice_fac); + float last = fixed_vector[0]; // holds c(i - 1) + + fixed_vector[0] -= cpe * fixed_vector[1]; + + for (i = 1; i < AMRWB_SFR_SIZE - 1; i++) { + float cur = fixed_vector[i]; + + fixed_vector[i] -= cpe * (last + fixed_vector[i + 1]); + last = cur; + } + + fixed_vector[AMRWB_SFR_SIZE - 1] -= cpe * last; +} + +/** + * Conduct 16th order linear predictive coding synthesis from excitation. + * + * @param[in] ctx Pointer to the AMRWBContext + * @param[in] lpc Pointer to the LPC coefficients + * @param[out] excitation Buffer for synthesis final excitation + * @param[in] fixed_gain Fixed codebook gain for synthesis + * @param[in] fixed_vector Algebraic codebook vector + * @param[in,out] samples Pointer to the output samples and memory + */ +static void synthesis(AMRWBContext *ctx, float *lpc, float *excitation, + float fixed_gain, const float *fixed_vector, + float *samples) +{ + ctx->acelpv_ctx.weighted_vector_sumf(excitation, ctx->pitch_vector, fixed_vector, + ctx->pitch_gain[0], fixed_gain, AMRWB_SFR_SIZE); + + /* emphasize pitch vector contribution in low bitrate modes */ + if (ctx->pitch_gain[0] > 0.5 && ctx->fr_cur_mode <= MODE_8k85) { + int i; + float energy = ctx->celpm_ctx.dot_productf(excitation, excitation, + AMRWB_SFR_SIZE); + + // XXX: Weird part in both ref code and spec. A unknown parameter + // {beta} seems to be identical to the current pitch gain + float pitch_factor = 0.25 * ctx->pitch_gain[0] * ctx->pitch_gain[0]; + + for (i = 0; i < AMRWB_SFR_SIZE; i++) + excitation[i] += pitch_factor * ctx->pitch_vector[i]; + + ff_scale_vector_to_given_sum_of_squares(excitation, excitation, + energy, AMRWB_SFR_SIZE); + } + + ctx->celpf_ctx.celp_lp_synthesis_filterf(samples, lpc, excitation, + AMRWB_SFR_SIZE, LP_ORDER); +} + +/** + * Apply to synthesis a de-emphasis filter of the form: + * H(z) = 1 / (1 - m * z^-1) + * + * @param[out] out Output buffer + * @param[in] in Input samples array with in[-1] + * @param[in] m Filter coefficient + * @param[in,out] mem State from last filtering + */ +static void de_emphasis(float *out, float *in, float m, float mem[1]) +{ + int i; + + out[0] = in[0] + m * mem[0]; + + for (i = 1; i < AMRWB_SFR_SIZE; i++) + out[i] = in[i] + out[i - 1] * m; + + mem[0] = out[AMRWB_SFR_SIZE - 1]; +} + +/** + * Upsample a signal by 5/4 ratio (from 12.8kHz to 16kHz) using + * a FIR interpolation filter. Uses past data from before *in address. + * + * @param[out] out Buffer for interpolated signal + * @param[in] in Current signal data (length 0.8*o_size) + * @param[in] o_size Output signal length + * @param[in] ctx The context + */ +static void upsample_5_4(float *out, const float *in, int o_size, CELPMContext *ctx) +{ + const float *in0 = in - UPS_FIR_SIZE + 1; + int i, j, k; + int int_part = 0, frac_part; + + i = 0; + for (j = 0; j < o_size / 5; j++) { + out[i] = in[int_part]; + frac_part = 4; + i++; + + for (k = 1; k < 5; k++) { + out[i] = ctx->dot_productf(in0 + int_part, + upsample_fir[4 - frac_part], + UPS_MEM_SIZE); + int_part++; + frac_part--; + i++; + } + } +} + +/** + * Calculate the high-band gain based on encoded index (23k85 mode) or + * on the low-band speech signal and the Voice Activity Detection flag. + * + * @param[in] ctx The context + * @param[in] synth LB speech synthesis at 12.8k + * @param[in] hb_idx Gain index for mode 23k85 only + * @param[in] vad VAD flag for the frame + */ +static float find_hb_gain(AMRWBContext *ctx, const float *synth, + uint16_t hb_idx, uint8_t vad) +{ + int wsp = (vad > 0); + float tilt; + + if (ctx->fr_cur_mode == MODE_23k85) + return qua_hb_gain[hb_idx] * (1.0f / (1 << 14)); + + tilt = ctx->celpm_ctx.dot_productf(synth, synth + 1, AMRWB_SFR_SIZE - 1) / + ctx->celpm_ctx.dot_productf(synth, synth, AMRWB_SFR_SIZE); + + /* return gain bounded by [0.1, 1.0] */ + return av_clipf((1.0 - FFMAX(0.0, tilt)) * (1.25 - 0.25 * wsp), 0.1, 1.0); +} + +/** + * Generate the high-band excitation with the same energy from the lower + * one and scaled by the given gain. + * + * @param[in] ctx The context + * @param[out] hb_exc Buffer for the excitation + * @param[in] synth_exc Low-band excitation used for synthesis + * @param[in] hb_gain Wanted excitation gain + */ +static void scaled_hb_excitation(AMRWBContext *ctx, float *hb_exc, + const float *synth_exc, float hb_gain) +{ + int i; + float energy = ctx->celpm_ctx.dot_productf(synth_exc, synth_exc, + AMRWB_SFR_SIZE); + + /* Generate a white-noise excitation */ + for (i = 0; i < AMRWB_SFR_SIZE_16k; i++) + hb_exc[i] = 32768.0 - (uint16_t) av_lfg_get(&ctx->prng); + + ff_scale_vector_to_given_sum_of_squares(hb_exc, hb_exc, + energy * hb_gain * hb_gain, + AMRWB_SFR_SIZE_16k); +} + +/** + * Calculate the auto-correlation for the ISF difference vector. + */ +static float auto_correlation(float *diff_isf, float mean, int lag) +{ + int i; + float sum = 0.0; + + for (i = 7; i < LP_ORDER - 2; i++) { + float prod = (diff_isf[i] - mean) * (diff_isf[i - lag] - mean); + sum += prod * prod; + } + return sum; +} + +/** + * Extrapolate a ISF vector to the 16kHz range (20th order LP) + * used at mode 6k60 LP filter for the high frequency band. + * + * @param[out] isf Buffer for extrapolated isf; contains LP_ORDER + * values on input + */ +static void extrapolate_isf(float isf[LP_ORDER_16k]) +{ + float diff_isf[LP_ORDER - 2], diff_mean; + float corr_lag[3]; + float est, scale; + int i, j, i_max_corr; + + isf[LP_ORDER_16k - 1] = isf[LP_ORDER - 1]; + + /* Calculate the difference vector */ + for (i = 0; i < LP_ORDER - 2; i++) + diff_isf[i] = isf[i + 1] - isf[i]; + + diff_mean = 0.0; + for (i = 2; i < LP_ORDER - 2; i++) + diff_mean += diff_isf[i] * (1.0f / (LP_ORDER - 4)); + + /* Find which is the maximum autocorrelation */ + i_max_corr = 0; + for (i = 0; i < 3; i++) { + corr_lag[i] = auto_correlation(diff_isf, diff_mean, i + 2); + + if (corr_lag[i] > corr_lag[i_max_corr]) + i_max_corr = i; + } + i_max_corr++; + + for (i = LP_ORDER - 1; i < LP_ORDER_16k - 1; i++) + isf[i] = isf[i - 1] + isf[i - 1 - i_max_corr] + - isf[i - 2 - i_max_corr]; + + /* Calculate an estimate for ISF(18) and scale ISF based on the error */ + est = 7965 + (isf[2] - isf[3] - isf[4]) / 6.0; + scale = 0.5 * (FFMIN(est, 7600) - isf[LP_ORDER - 2]) / + (isf[LP_ORDER_16k - 2] - isf[LP_ORDER - 2]); + + for (i = LP_ORDER - 1, j = 0; i < LP_ORDER_16k - 1; i++, j++) + diff_isf[j] = scale * (isf[i] - isf[i - 1]); + + /* Stability insurance */ + for (i = 1; i < LP_ORDER_16k - LP_ORDER; i++) + if (diff_isf[i] + diff_isf[i - 1] < 5.0) { + if (diff_isf[i] > diff_isf[i - 1]) { + diff_isf[i - 1] = 5.0 - diff_isf[i]; + } else + diff_isf[i] = 5.0 - diff_isf[i - 1]; + } + + for (i = LP_ORDER - 1, j = 0; i < LP_ORDER_16k - 1; i++, j++) + isf[i] = isf[i - 1] + diff_isf[j] * (1.0f / (1 << 15)); + + /* Scale the ISF vector for 16000 Hz */ + for (i = 0; i < LP_ORDER_16k - 1; i++) + isf[i] *= 0.8; +} + +/** + * Spectral expand the LP coefficients using the equation: + * y[i] = x[i] * (gamma ** i) + * + * @param[out] out Output buffer (may use input array) + * @param[in] lpc LP coefficients array + * @param[in] gamma Weighting factor + * @param[in] size LP array size + */ +static void lpc_weighting(float *out, const float *lpc, float gamma, int size) +{ + int i; + float fac = gamma; + + for (i = 0; i < size; i++) { + out[i] = lpc[i] * fac; + fac *= gamma; + } +} + +/** + * Conduct 20th order linear predictive coding synthesis for the high + * frequency band excitation at 16kHz. + * + * @param[in] ctx The context + * @param[in] subframe Current subframe index (0 to 3) + * @param[in,out] samples Pointer to the output speech samples + * @param[in] exc Generated white-noise scaled excitation + * @param[in] isf Current frame isf vector + * @param[in] isf_past Past frame final isf vector + */ +static void hb_synthesis(AMRWBContext *ctx, int subframe, float *samples, + const float *exc, const float *isf, const float *isf_past) +{ + float hb_lpc[LP_ORDER_16k]; + enum Mode mode = ctx->fr_cur_mode; + + if (mode == MODE_6k60) { + float e_isf[LP_ORDER_16k]; // ISF vector for extrapolation + double e_isp[LP_ORDER_16k]; + + ctx->acelpv_ctx.weighted_vector_sumf(e_isf, isf_past, isf, isfp_inter[subframe], + 1.0 - isfp_inter[subframe], LP_ORDER); + + extrapolate_isf(e_isf); + + e_isf[LP_ORDER_16k - 1] *= 2.0; + ff_acelp_lsf2lspd(e_isp, e_isf, LP_ORDER_16k); + ff_amrwb_lsp2lpc(e_isp, hb_lpc, LP_ORDER_16k); + + lpc_weighting(hb_lpc, hb_lpc, 0.9, LP_ORDER_16k); + } else { + lpc_weighting(hb_lpc, ctx->lp_coef[subframe], 0.6, LP_ORDER); + } + + ctx->celpf_ctx.celp_lp_synthesis_filterf(samples, hb_lpc, exc, AMRWB_SFR_SIZE_16k, + (mode == MODE_6k60) ? LP_ORDER_16k : LP_ORDER); +} + +/** + * Apply a 15th order filter to high-band samples. + * The filter characteristic depends on the given coefficients. + * + * @param[out] out Buffer for filtered output + * @param[in] fir_coef Filter coefficients + * @param[in,out] mem State from last filtering (updated) + * @param[in] in Input speech data (high-band) + * + * @remark It is safe to pass the same array in in and out parameters + */ + +#ifndef hb_fir_filter +static void hb_fir_filter(float *out, const float fir_coef[HB_FIR_SIZE + 1], + float mem[HB_FIR_SIZE], const float *in) +{ + int i, j; + float data[AMRWB_SFR_SIZE_16k + HB_FIR_SIZE]; // past and current samples + + memcpy(data, mem, HB_FIR_SIZE * sizeof(float)); + memcpy(data + HB_FIR_SIZE, in, AMRWB_SFR_SIZE_16k * sizeof(float)); + + for (i = 0; i < AMRWB_SFR_SIZE_16k; i++) { + out[i] = 0.0; + for (j = 0; j <= HB_FIR_SIZE; j++) + out[i] += data[i + j] * fir_coef[j]; + } + + memcpy(mem, data + AMRWB_SFR_SIZE_16k, HB_FIR_SIZE * sizeof(float)); +} +#endif /* hb_fir_filter */ + +/** + * Update context state before the next subframe. + */ +static void update_sub_state(AMRWBContext *ctx) +{ + memmove(&ctx->excitation_buf[0], &ctx->excitation_buf[AMRWB_SFR_SIZE], + (AMRWB_P_DELAY_MAX + LP_ORDER + 1) * sizeof(float)); + + memmove(&ctx->pitch_gain[1], &ctx->pitch_gain[0], 5 * sizeof(float)); + memmove(&ctx->fixed_gain[1], &ctx->fixed_gain[0], 1 * sizeof(float)); + + memmove(&ctx->samples_az[0], &ctx->samples_az[AMRWB_SFR_SIZE], + LP_ORDER * sizeof(float)); + memmove(&ctx->samples_up[0], &ctx->samples_up[AMRWB_SFR_SIZE], + UPS_MEM_SIZE * sizeof(float)); + memmove(&ctx->samples_hb[0], &ctx->samples_hb[AMRWB_SFR_SIZE_16k], + LP_ORDER_16k * sizeof(float)); +} + +static int amrwb_decode_frame(AVCodecContext *avctx, void *data, + int *got_frame_ptr, AVPacket *avpkt) +{ + AMRWBContext *ctx = avctx->priv_data; + AVFrame *frame = data; + AMRWBFrame *cf = &ctx->frame; + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + int expected_fr_size, header_size; + float *buf_out; + float spare_vector[AMRWB_SFR_SIZE]; // extra stack space to hold result from anti-sparseness processing + float fixed_gain_factor; // fixed gain correction factor (gamma) + float *synth_fixed_vector; // pointer to the fixed vector that synthesis should use + float synth_fixed_gain; // the fixed gain that synthesis should use + float voice_fac, stab_fac; // parameters used for gain smoothing + float synth_exc[AMRWB_SFR_SIZE]; // post-processed excitation for synthesis + float hb_exc[AMRWB_SFR_SIZE_16k]; // excitation for the high frequency band + float hb_samples[AMRWB_SFR_SIZE_16k]; // filtered high-band samples from synthesis + float hb_gain; + int sub, i, ret; + + /* get output buffer */ + frame->nb_samples = 4 * AMRWB_SFR_SIZE_16k; + if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) + return ret; + buf_out = (float *)frame->data[0]; + + header_size = decode_mime_header(ctx, buf); + if (ctx->fr_cur_mode > MODE_SID) { + av_log(avctx, AV_LOG_ERROR, + "Invalid mode %d\n", ctx->fr_cur_mode); + return AVERROR_INVALIDDATA; + } + expected_fr_size = ((cf_sizes_wb[ctx->fr_cur_mode] + 7) >> 3) + 1; + + if (buf_size < expected_fr_size) { + av_log(avctx, AV_LOG_ERROR, + "Frame too small (%d bytes). Truncated file?\n", buf_size); + *got_frame_ptr = 0; + return AVERROR_INVALIDDATA; + } + + if (!ctx->fr_quality || ctx->fr_cur_mode > MODE_SID) + av_log(avctx, AV_LOG_ERROR, "Encountered a bad or corrupted frame\n"); + + if (ctx->fr_cur_mode == MODE_SID) { /* Comfort noise frame */ + avpriv_request_sample(avctx, "SID mode"); + return AVERROR_PATCHWELCOME; + } + + ff_amr_bit_reorder((uint16_t *) &ctx->frame, sizeof(AMRWBFrame), + buf + header_size, amr_bit_orderings_by_mode[ctx->fr_cur_mode]); + + /* Decode the quantized ISF vector */ + if (ctx->fr_cur_mode == MODE_6k60) { + decode_isf_indices_36b(cf->isp_id, ctx->isf_cur); + } else { + decode_isf_indices_46b(cf->isp_id, ctx->isf_cur); + } + + isf_add_mean_and_past(ctx->isf_cur, ctx->isf_q_past); + ff_set_min_dist_lsf(ctx->isf_cur, MIN_ISF_SPACING, LP_ORDER - 1); + + stab_fac = stability_factor(ctx->isf_cur, ctx->isf_past_final); + + ctx->isf_cur[LP_ORDER - 1] *= 2.0; + ff_acelp_lsf2lspd(ctx->isp[3], ctx->isf_cur, LP_ORDER); + + /* Generate a ISP vector for each subframe */ + if (ctx->first_frame) { + ctx->first_frame = 0; + memcpy(ctx->isp_sub4_past, ctx->isp[3], LP_ORDER * sizeof(double)); + } + interpolate_isp(ctx->isp, ctx->isp_sub4_past); + + for (sub = 0; sub < 4; sub++) + ff_amrwb_lsp2lpc(ctx->isp[sub], ctx->lp_coef[sub], LP_ORDER); + + for (sub = 0; sub < 4; sub++) { + const AMRWBSubFrame *cur_subframe = &cf->subframe[sub]; + float *sub_buf = buf_out + sub * AMRWB_SFR_SIZE_16k; + + /* Decode adaptive codebook (pitch vector) */ + decode_pitch_vector(ctx, cur_subframe, sub); + /* Decode innovative codebook (fixed vector) */ + decode_fixed_vector(ctx->fixed_vector, cur_subframe->pul_ih, + cur_subframe->pul_il, ctx->fr_cur_mode); + + pitch_sharpening(ctx, ctx->fixed_vector); + + decode_gains(cur_subframe->vq_gain, ctx->fr_cur_mode, + &fixed_gain_factor, &ctx->pitch_gain[0]); + + ctx->fixed_gain[0] = + ff_amr_set_fixed_gain(fixed_gain_factor, + ctx->celpm_ctx.dot_productf(ctx->fixed_vector, + ctx->fixed_vector, + AMRWB_SFR_SIZE) / + AMRWB_SFR_SIZE, + ctx->prediction_error, + ENERGY_MEAN, energy_pred_fac); + + /* Calculate voice factor and store tilt for next subframe */ + voice_fac = voice_factor(ctx->pitch_vector, ctx->pitch_gain[0], + ctx->fixed_vector, ctx->fixed_gain[0], + &ctx->celpm_ctx); + ctx->tilt_coef = voice_fac * 0.25 + 0.25; + + /* Construct current excitation */ + for (i = 0; i < AMRWB_SFR_SIZE; i++) { + ctx->excitation[i] *= ctx->pitch_gain[0]; + ctx->excitation[i] += ctx->fixed_gain[0] * ctx->fixed_vector[i]; + ctx->excitation[i] = truncf(ctx->excitation[i]); + } + + /* Post-processing of excitation elements */ + synth_fixed_gain = noise_enhancer(ctx->fixed_gain[0], &ctx->prev_tr_gain, + voice_fac, stab_fac); + + synth_fixed_vector = anti_sparseness(ctx, ctx->fixed_vector, + spare_vector); + + pitch_enhancer(synth_fixed_vector, voice_fac); + + synthesis(ctx, ctx->lp_coef[sub], synth_exc, synth_fixed_gain, + synth_fixed_vector, &ctx->samples_az[LP_ORDER]); + + /* Synthesis speech post-processing */ + de_emphasis(&ctx->samples_up[UPS_MEM_SIZE], + &ctx->samples_az[LP_ORDER], PREEMPH_FAC, ctx->demph_mem); + + ctx->acelpf_ctx.acelp_apply_order_2_transfer_function(&ctx->samples_up[UPS_MEM_SIZE], + &ctx->samples_up[UPS_MEM_SIZE], hpf_zeros, hpf_31_poles, + hpf_31_gain, ctx->hpf_31_mem, AMRWB_SFR_SIZE); + + upsample_5_4(sub_buf, &ctx->samples_up[UPS_FIR_SIZE], + AMRWB_SFR_SIZE_16k, &ctx->celpm_ctx); + + /* High frequency band (6.4 - 7.0 kHz) generation part */ + ctx->acelpf_ctx.acelp_apply_order_2_transfer_function(hb_samples, + &ctx->samples_up[UPS_MEM_SIZE], hpf_zeros, hpf_400_poles, + hpf_400_gain, ctx->hpf_400_mem, AMRWB_SFR_SIZE); + + hb_gain = find_hb_gain(ctx, hb_samples, + cur_subframe->hb_gain, cf->vad); + + scaled_hb_excitation(ctx, hb_exc, synth_exc, hb_gain); + + hb_synthesis(ctx, sub, &ctx->samples_hb[LP_ORDER_16k], + hb_exc, ctx->isf_cur, ctx->isf_past_final); + + /* High-band post-processing filters */ + hb_fir_filter(hb_samples, bpf_6_7_coef, ctx->bpf_6_7_mem, + &ctx->samples_hb[LP_ORDER_16k]); + + if (ctx->fr_cur_mode == MODE_23k85) + hb_fir_filter(hb_samples, lpf_7_coef, ctx->lpf_7_mem, + hb_samples); + + /* Add the low and high frequency bands */ + for (i = 0; i < AMRWB_SFR_SIZE_16k; i++) + sub_buf[i] = (sub_buf[i] + hb_samples[i]) * (1.0f / (1 << 15)); + + /* Update buffers and history */ + update_sub_state(ctx); + } + + /* update state for next frame */ + memcpy(ctx->isp_sub4_past, ctx->isp[3], LP_ORDER * sizeof(ctx->isp[3][0])); + memcpy(ctx->isf_past_final, ctx->isf_cur, LP_ORDER * sizeof(float)); + + *got_frame_ptr = 1; + + return expected_fr_size; +} + +AVCodec ff_amrwb_decoder = { + .name = "amrwb", + .long_name = NULL_IF_CONFIG_SMALL("AMR-WB (Adaptive Multi-Rate WideBand)"), + .type = AVMEDIA_TYPE_AUDIO, + .id = AV_CODEC_ID_AMR_WB, + .priv_data_size = sizeof(AMRWBContext), + .init = amrwb_decode_init, + .decode = amrwb_decode_frame, + .capabilities = CODEC_CAP_DR1, + .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLT, + AV_SAMPLE_FMT_NONE }, +}; diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/mips/amrwbdec_mips.h b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/mips/amrwbdec_mips.h new file mode 100644 index 000000000..a469918d2 --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavcodec/mips/amrwbdec_mips.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2012 + * MIPS Technologies, Inc., California. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Author: Nedeljko Babic (nbabic@mips.com) + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * Reference: libavcodec/amrwbdec.c + */ +#ifndef AVCODEC_AMRWBDEC_MIPS_H +#define AVCODEC_AMRWBDEC_MIPS_H +#include "config.h" + +#if HAVE_MIPSFPU && HAVE_INLINE_ASM +void hb_fir_filter_mips(float *out, const float fir_coef[], + float mem[], const float *in); +#define hb_fir_filter hb_fir_filter_mips +#endif + +#endif /* AVCODEC_AMRWBDEC_MIPS_H */ diff --git a/Frameworks/FFMPEG/ffmpeg-minimal/libavformat/amr.c b/Frameworks/FFMPEG/ffmpeg-minimal/libavformat/amr.c new file mode 100644 index 000000000..ebbdca92e --- /dev/null +++ b/Frameworks/FFMPEG/ffmpeg-minimal/libavformat/amr.c @@ -0,0 +1,180 @@ +/* + * amr file format + * Copyright (c) 2001 ffmpeg project + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* +Write and read amr data according to RFC3267, http://www.ietf.org/rfc/rfc3267.txt?number=3267 + +Only mono files are supported. + +*/ + +#include "config.h" +#include "libavutil/avassert.h" +#include "libavutil/channel_layout.h" +#include "avformat.h" +#include "internal.h" + +static const char AMR_header[] = "#!AMR\n"; +static const char AMRWB_header[] = "#!AMR-WB\n"; + +#if CONFIG_AMR_MUXER +static int amr_write_header(AVFormatContext *s) +{ + AVIOContext *pb = s->pb; + AVCodecContext *enc = s->streams[0]->codec; + + s->priv_data = NULL; + + if (enc->codec_id == AV_CODEC_ID_AMR_NB) { + avio_write(pb, AMR_header, sizeof(AMR_header) - 1); /* magic number */ + } else if (enc->codec_id == AV_CODEC_ID_AMR_WB) { + avio_write(pb, AMRWB_header, sizeof(AMRWB_header) - 1); /* magic number */ + } else { + return -1; + } + avio_flush(pb); + return 0; +} + +static int amr_write_packet(AVFormatContext *s, AVPacket *pkt) +{ + avio_write(s->pb, pkt->data, pkt->size); + return 0; +} +#endif /* CONFIG_AMR_MUXER */ + +static int amr_probe(AVProbeData *p) +{ + // Only check for "#!AMR" which could be amr-wb, amr-nb. + // This will also trigger multichannel files: "#!AMR_MC1.0\n" and + // "#!AMR-WB_MC1.0\n" (not supported) + + if (!memcmp(p->buf, AMR_header, 5)) + return AVPROBE_SCORE_MAX; + else + return 0; +} + +/* amr input */ +static int amr_read_header(AVFormatContext *s) +{ + AVIOContext *pb = s->pb; + AVStream *st; + uint8_t header[9]; + + avio_read(pb, header, 6); + + st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + if (memcmp(header, AMR_header, 6)) { + avio_read(pb, header + 6, 3); + if (memcmp(header, AMRWB_header, 9)) { + return -1; + } + + st->codec->codec_tag = MKTAG('s', 'a', 'w', 'b'); + st->codec->codec_id = AV_CODEC_ID_AMR_WB; + st->codec->sample_rate = 16000; + } else { + st->codec->codec_tag = MKTAG('s', 'a', 'm', 'r'); + st->codec->codec_id = AV_CODEC_ID_AMR_NB; + st->codec->sample_rate = 8000; + } + st->codec->channels = 1; + st->codec->channel_layout = AV_CH_LAYOUT_MONO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + + return 0; +} + +static int amr_read_packet(AVFormatContext *s, AVPacket *pkt) +{ + AVCodecContext *enc = s->streams[0]->codec; + int read, size = 0, toc, mode; + int64_t pos = avio_tell(s->pb); + + if (url_feof(s->pb)) { + return AVERROR(EIO); + } + + // FIXME this is wrong, this should rather be in a AVParset + toc = avio_r8(s->pb); + mode = (toc >> 3) & 0x0F; + + if (enc->codec_id == AV_CODEC_ID_AMR_NB) { + static const uint8_t packed_size[16] = { + 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 + }; + + size = packed_size[mode] + 1; + } else if (enc->codec_id == AV_CODEC_ID_AMR_WB) { + static const uint8_t packed_size[16] = { + 18, 24, 33, 37, 41, 47, 51, 59, 61, 6, 6, 0, 0, 0, 1, 1 + }; + + size = packed_size[mode]; + } + + if (!size || av_new_packet(pkt, size)) + return AVERROR(EIO); + + /* Both AMR formats have 50 frames per second */ + s->streams[0]->codec->bit_rate = size*8*50; + + pkt->stream_index = 0; + pkt->pos = pos; + pkt->data[0] = toc; + pkt->duration = enc->codec_id == AV_CODEC_ID_AMR_NB ? 160 : 320; + read = avio_read(s->pb, pkt->data + 1, size - 1); + + if (read != size - 1) { + av_free_packet(pkt); + return AVERROR(EIO); + } + + return 0; +} + +#if CONFIG_AMR_DEMUXER +AVInputFormat ff_amr_demuxer = { + .name = "amr", + .long_name = NULL_IF_CONFIG_SMALL("3GPP AMR"), + .read_probe = amr_probe, + .read_header = amr_read_header, + .read_packet = amr_read_packet, + .flags = AVFMT_GENERIC_INDEX, +}; +#endif + +#if CONFIG_AMR_MUXER +AVOutputFormat ff_amr_muxer = { + .name = "amr", + .long_name = NULL_IF_CONFIG_SMALL("3GPP AMR"), + .mime_type = "audio/amr", + .extensions = "amr", + .audio_codec = AV_CODEC_ID_AMR_NB, + .video_codec = AV_CODEC_ID_NONE, + .write_header = amr_write_header, + .write_packet = amr_write_packet, +}; +#endif diff --git a/Info.plist b/Info.plist index 1b9ccfb85..a2e0d1a63 100644 --- a/Info.plist +++ b/Info.plist @@ -22,6 +22,21 @@ CFBundleTypeRole None + + CFBundleTypeExtensions + + amr-wb + amr + + LSTypeIsPackage + + CFBundleTypeRole + Viewer + CFBundleTypeIconFile + song.icns + CFBundleTypeName + AMR Audio File + CFBundleTypeExtensions