1 /*
2 * Voxware MetaSound decoder
3 * Copyright (c) 2013 Konstantin Shishkov
4 * based on TwinVQ decoder
5 * Copyright (c) 2009 Vitor Sessak
6 *
7 * This file is part of FFmpeg.
8 *
9 * FFmpeg is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * FFmpeg is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with FFmpeg; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 #include <inttypes.h>
25 #include <math.h>
26 #include <stdint.h>
27
30
31 #define BITSTREAM_READER_LE
38
41
43 float ppc_gain,
float *speech,
int len)
44 {
46 const float *shape_end = shape +
len;
47
48 // First peak centered around zero
50 speech[
i] += ppc_gain * *shape++;
51
55 speech[j + center] += ppc_gain * *shape++;
56 }
57
58 // For the last block, be careful not to go beyond the end of the buffer
60 for (j = -
width / 2; j < (
width + 1) / 2 && shape < shape_end; j++)
61 speech[j + center] += ppc_gain * *shape++;
62 }
63
65 const float *shape, float *speech)
66 {
72
74 float min_period, max_period, period_range,
period;
75 float some_mult;
76
77 float pgain_base, pgain_step, ppc_gain;
78
80 min_period =
log2(ratio * 0.2);
81 max_period = min_period +
log2(6);
82 } else {
83 min_period = (
int)(ratio * 0.2 * 400 + 0.5) / 400.0;
84 max_period = (
int)(ratio * 0.2 * 400 * 6 + 0.5) / 400.0;
85 }
86 period_range = max_period - min_period;
87 period = min_period + period_coef * period_range /
91 else
93
94 switch (isampf) {
95 case 8: some_mult = 2.0; break;
96 case 11: some_mult = 3.0; break;
97 case 16: some_mult = 3.0; break;
98 case 22: some_mult = ibps == 32 ? 2.0 : 4.0; break;
99 case 44: some_mult = 8.0; break;
100 default: some_mult = 4.0;
101 }
102
104 if (isampf == 22 && ibps == 32)
106
107 pgain_base =
channels == 2 ? 25000.0 : 20000.0;
108 pgain_step = pgain_base / ((1 << mtab->
pgain_bit) - 1);
109 ppc_gain = 1.0 / 8192 *
112
114 }
115
117 int ch,
float *
out,
float gain,
119 {
123 float val = ((
const float []) { 0.4, 0.35, 0.28 })[
ftype];
126 int idx = 0;
128
131 for (
i = 0;
i < fw_cb_len;
i++)
132 for (j = 0; j < bark_n_coef; j++, idx++) {
134 (1.0 / 2048);
135 float st;
136
138 st = use_hist ?
139 tmp2 +
val * hist[idx] + 1.0 : tmp2 + 1.0;
140 else
141 st = use_hist ? (1.0 -
val) * tmp2 +
val * hist[idx] + 1.0
142 : tmp2 + 1.0;
143
144 hist[idx] = tmp2;
145 if (st < 0.1)
146 st = 0.1;
147
151 }
152 }
153
156 {
158
161
164 }
165 }
166
168 const uint8_t *buf, int buf_size)
169 {
176
179
183
185
186 if (
bits->window_type > 8) {
189 }
190
192
194
197
199
201 for (j = 0; j <
sub; j++)
203 bits->bark1[
i][j][k] =
205
207 for (j = 0; j <
sub; j++)
209
213 } else {
216 for (j = 0; j <
sub; j++)
219 }
220 }
221
225
228 }
229
235 }
236 }
237
238 // subframes are aligned to nibbles
241 }
242
244 }
245
252
254 {
MKTAG(
'V',
'X',
'0',
'3'), 6, 1, 8000 },
255 {
MKTAG(
'V',
'X',
'0',
'4'), 12, 2, 8000 },
256
257 {
MKTAG(
'V',
'O',
'X',
'i'), 8, 1, 8000 },
258 {
MKTAG(
'V',
'O',
'X',
'j'), 10, 1, 11025 },
259 {
MKTAG(
'V',
'O',
'X',
'k'), 16, 1, 16000 },
260 {
MKTAG(
'V',
'O',
'X',
'L'), 24, 1, 22050 },
261 {
MKTAG(
'V',
'O',
'X',
'q'), 32, 1, 44100 },
262 {
MKTAG(
'V',
'O',
'X',
'r'), 40, 1, 44100 },
263 {
MKTAG(
'V',
'O',
'X',
's'), 48, 1, 44100 },
264 {
MKTAG(
'V',
'O',
'X',
't'), 16, 2, 8000 },
265 {
MKTAG(
'V',
'O',
'X',
'u'), 20, 2, 11025 },
266 {
MKTAG(
'V',
'O',
'X',
'v'), 32, 2, 16000 },
267 {
MKTAG(
'V',
'O',
'X',
'w'), 48, 2, 22050 },
268 {
MKTAG(
'V',
'O',
'X',
'x'), 64, 2, 44100 },
269 {
MKTAG(
'V',
'O',
'X',
'y'), 80, 2, 44100 },
270 {
MKTAG(
'V',
'O',
'X',
'z'), 96, 2, 44100 },
271
272 { 0, 0, 0, 0 }
273 };
274
276 {
277 int isampf, ibps;
282
286 }
287
289
290 for (;;) {
294 }
300 break;
301 }
302 props++;
303 }
304
309 }
312
314
315 switch ((
channels << 16) + (isampf << 8) + ibps) {
316 case (1 << 16) + ( 8 << 8) + 6:
318 break;
319 case (2 << 16) + ( 8 << 8) + 6:
321 break;
322 case (1 << 16) + ( 8 << 8) + 8:
324 break;
325 case (2 << 16) + ( 8 << 8) + 8:
327 break;
328 case (1 << 16) + (11 << 8) + 10:
330 break;
331 case (2 << 16) + (11 << 8) + 10:
333 break;
334 case (1 << 16) + (16 << 8) + 16:
336 break;
337 case (2 << 16) + (16 << 8) + 16:
339 break;
340 case (1 << 16) + (22 << 8) + 24:
342 break;
343 case (2 << 16) + (22 << 8) + 24:
345 break;
346 case (1 << 16) + (44 << 8) + 32:
347 case (2 << 16) + (44 << 8) + 32:
349 break;
350 case (1 << 16) + (44 << 8) + 40:
351 case (2 << 16) + (44 << 8) + 40:
353 break;
354 case (1 << 16) + (44 << 8) + 48:
355 case (2 << 16) + (44 << 8) + 48:
357 break;
358 default:
360 "This version does not support %d kHz - %d kbit/s/ch mode.\n",
361 isampf, ibps);
363 }
364
372
374 }
375
377 .
p.
name =
"metasound",
389 };