summaryrefslogtreecommitdiff
path: root/libavcodec/adpcm_data.c (plain)
blob: 52271be26e187aef0a15ef51f3d794e5d56e9a62
1/*
2 * Copyright (c) 2001-2003 The FFmpeg project
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/**
22 * @file
23 * ADPCM tables
24 */
25
26#include <stdint.h>
27
28/* ff_adpcm_step_table[] and ff_adpcm_index_table[] are from the ADPCM
29 reference source */
30static const int8_t adpcm_index_table2[4] = {
31 -1, 2,
32 -1, 2,
33};
34
35static const int8_t adpcm_index_table3[8] = {
36 -1, -1, 1, 2,
37 -1, -1, 1, 2,
38};
39
40const int8_t ff_adpcm_index_table[16] = {
41 -1, -1, -1, -1, 2, 4, 6, 8,
42 -1, -1, -1, -1, 2, 4, 6, 8,
43};
44
45static const int8_t adpcm_index_table5[32] = {
46 -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16,
47 -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16,
48};
49
50const int8_t * const ff_adpcm_index_tables[4] = {
51 &adpcm_index_table2[0],
52 &adpcm_index_table3[0],
53 &ff_adpcm_index_table[0],
54 &adpcm_index_table5[0],
55};
56
57/**
58 * This is the step table. Note that many programs use slight deviations from
59 * this table, but such deviations are negligible:
60 */
61const int16_t ff_adpcm_step_table[89] = {
62 7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
63 19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
64 50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
65 130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
66 337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
67 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
68 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
69 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
70 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
71};
72
73const int16_t ff_adpcm_oki_step_table[49] = {
74 16, 17, 19, 21, 23, 25, 28, 31, 34, 37,
75 41, 45, 50, 55, 60, 66, 73, 80, 88, 97,
76 107, 118, 130, 143, 157, 173, 190, 209, 230, 253,
77 279, 307, 337, 371, 408, 449, 494, 544, 598, 658,
78 724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552
79};
80
81/* These are for MS-ADPCM */
82/* ff_adpcm_AdaptationTable[], ff_adpcm_AdaptCoeff1[], and
83 ff_adpcm_AdaptCoeff2[] are from libsndfile */
84const int16_t ff_adpcm_AdaptationTable[] = {
85 230, 230, 230, 230, 307, 409, 512, 614,
86 768, 614, 512, 409, 307, 230, 230, 230
87};
88
89/** Divided by 4 to fit in 8-bit integers */
90const uint8_t ff_adpcm_AdaptCoeff1[] = {
91 64, 128, 0, 48, 60, 115, 98
92};
93
94/** Divided by 4 to fit in 8-bit integers */
95const int8_t ff_adpcm_AdaptCoeff2[] = {
96 0, -64, 0, 16, 0, -52, -58
97};
98
99const int16_t ff_adpcm_yamaha_indexscale[] = {
100 230, 230, 230, 230, 307, 409, 512, 614,
101 230, 230, 230, 230, 307, 409, 512, 614
102};
103
104const int8_t ff_adpcm_yamaha_difflookup[] = {
105 1, 3, 5, 7, 9, 11, 13, 15,
106 -1, -3, -5, -7, -9, -11, -13, -15
107};
108
109const int16_t ff_adpcm_afc_coeffs[2][16] = {
110 { 0, 2048, 0, 1024, 4096, 3584, 3072, 4608, 4200, 4800, 5120, 2048, 1024, 64512, 64512, 63488 },
111 { 0, 0, 2048, 1024, 63488, 64000, 64512, 62976, 63288, 63236, 62464, 63488, 64512, 1024, 0, 0 }
112};
113
114const int16_t ff_adpcm_mtaf_stepsize[32][16] = {
115 { 1, 5, 9, 13, 16, 20, 24, 28,
116 -1, -5, -9, -13, -16, -20, -24, -28, },
117 { 2, 6, 11, 15, 20, 24, 29, 33,
118 -2, -6, -11, -15, -20, -24, -29, -33, },
119 { 2, 7, 13, 18, 23, 28, 34, 39,
120 -2, -7, -13, -18, -23, -28, -34, -39, },
121 { 3, 9, 15, 21, 28, 34, 40, 46,
122 -3, -9, -15, -21, -28, -34, -40, -46, },
123 { 3, 11, 18, 26, 33, 41, 48, 56,
124 -3, -11, -18, -26, -33, -41, -48, -56, },
125 { 4, 13, 22, 31, 40, 49, 58, 67,
126 -4, -13, -22, -31, -40, -49, -58, -67, },
127 { 5, 16, 26, 37, 48, 59, 69, 80,
128 -5, -16, -26, -37, -48, -59, -69, -80, },
129 { 6, 19, 31, 44, 57, 70, 82, 95,
130 -6, -19, -31, -44, -57, -70, -82, -95, },
131 { 7, 22, 38, 53, 68, 83, 99, 114,
132 -7, -22, -38, -53, -68, -83, -99, -114, },
133 { 9, 27, 45, 63, 81, 99, 117, 135,
134 -9, -27, -45, -63, -81, -99, -117, -135, },
135 { 10, 32, 53, 75, 96, 118, 139, 161,
136 -10, -32, -53, -75, -96, -118, -139, -161, },
137 { 12, 38, 64, 90, 115, 141, 167, 193,
138 -12, -38, -64, -90, -115, -141, -167, -193, },
139 { 15, 45, 76, 106, 137, 167, 198, 228,
140 -15, -45, -76, -106, -137, -167, -198, -228, },
141 { 18, 54, 91, 127, 164, 200, 237, 273,
142 -18, -54, -91, -127, -164, -200, -237, -273, },
143 { 21, 65, 108, 152, 195, 239, 282, 326,
144 -21, -65, -108, -152, -195, -239, -282, -326, },
145 { 25, 77, 129, 181, 232, 284, 336, 388,
146 -25, -77, -129, -181, -232, -284, -336, -388, },
147 { 30, 92, 153, 215, 276, 338, 399, 461,
148 -30, -92, -153, -215, -276, -338, -399, -461, },
149 { 36, 109, 183, 256, 329, 402, 476, 549,
150 -36, -109, -183, -256, -329, -402, -476, -549, },
151 { 43, 130, 218, 305, 392, 479, 567, 654,
152 -43, -130, -218, -305, -392, -479, -567, -654, },
153 { 52, 156, 260, 364, 468, 572, 676, 780,
154 -52, -156, -260, -364, -468, -572, -676, -780, },
155 { 62, 186, 310, 434, 558, 682, 806, 930,
156 -62, -186, -310, -434, -558, -682, -806, -930, },
157 { 73, 221, 368, 516, 663, 811, 958, 1106,
158 -73, -221, -368, -516, -663, -811, -958, -1106, },
159 { 87, 263, 439, 615, 790, 966, 1142, 1318,
160 -87, -263, -439, -615, -790, -966, -1142, -1318, },
161 { 104, 314, 523, 733, 942, 1152, 1361, 1571,
162 -104, -314, -523, -733, -942, -1152, -1361, -1571, },
163 { 124, 374, 623, 873, 1122, 1372, 1621, 1871,
164 -124, -374, -623, -873, -1122, -1372, -1621, -1871, },
165 { 148, 445, 743, 1040, 1337, 1634, 1932, 2229,
166 -148, -445, -743, -1040, -1337, -1634, -1932, -2229, },
167 { 177, 531, 885, 1239, 1593, 1947, 2301, 2655,
168 -177, -531, -885, -1239, -1593, -1947, -2301, -2655, },
169 { 210, 632, 1053, 1475, 1896, 2318, 2739, 3161,
170 -210, -632, -1053, -1475, -1896, -2318, -2739, -3161, },
171 { 251, 753, 1255, 1757, 2260, 2762, 3264, 3766,
172 -251, -753, -1255, -1757, -2260, -2762, -3264, -3766, },
173 { 299, 897, 1495, 2093, 2692, 3290, 3888, 4486,
174 -299, -897, -1495, -2093, -2692, -3290, -3888, -4486, },
175 { 356, 1068, 1781, 2493, 3206, 3918, 4631, 5343,
176 -356, -1068, -1781, -2493, -3206, -3918, -4631, -5343, },
177 { 424, 1273, 2121, 2970, 3819, 4668, 5516, 6365,
178 -424, -1273, -2121, -2970, -3819, -4668, -5516, -6365, },
179};
180