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 <math.h>
25 #include <stdint.h>
26
27 #define BITSTREAM_READER_LE
36
39
41 float ppc_gain,
float *speech,
int len)
42 {
43 int i, j, center;
44 const float *shape_end = shape +
len;
45
46 // First peak centered around zero
47 for (i = 0; i < width / 2; i++)
48 speech[i] += ppc_gain * *shape++;
49
51 center = (int)(i * period + 0.5);
52 for (j = -width / 2; j < (width + 1) / 2; j++)
53 speech[j + center] += ppc_gain * *shape++;
54 }
55
56 // For the last block, be careful not to go beyond the end of the buffer
57 center = (int)(i * period + 0.5);
58 for (j = -width / 2; j < (width + 1) / 2 && shape < shape_end; j++)
59 speech[j + center] += ppc_gain * *shape++;
60 }
61
63 const float *shape, float *speech)
64 {
69
70 float ratio = (float)mtab->
size / isampf;
71 float min_period, max_period, period_range, period;
72 float some_mult;
73
74 float pgain_base, pgain_step, ppc_gain;
75
77 min_period =
log2(ratio * 0.2);
78 max_period = min_period +
log2(6);
79 } else {
80 min_period = (int)(ratio * 0.2 * 400 + 0.5) / 400.0;
81 max_period = (int)(ratio * 0.2 * 400 * 6 + 0.5) / 400.0;
82 }
83 period_range = max_period - min_period;
84 period = min_period + period_coef * period_range /
87 period =
powf(2.0, period);
88 else
89 period = (int)(period * 400 + 0.5) / 400.0;
90
91 switch (isampf) {
92 case 8: some_mult = 2.0; break;
93 case 11: some_mult = 3.0; break;
94 case 16: some_mult = 3.0; break;
95 case 22: some_mult = ibps == 32 ? 2.0 : 4.0; break;
96 case 44: some_mult = 8.0; break;
97 default: some_mult = 4.0;
98 }
99
101 if (isampf == 22 && ibps == 32)
102 width = (int)((2.0 / period + 1) * width + 0.5);
103
105 pgain_step = pgain_base / ((1 << mtab->
pgain_bit) - 1);
106 ppc_gain = 1.0 / 8192 *
109
111 }
112
114 int ch,
float *
out,
float gain,
116 {
118 int i, j;
119 float *hist = tctx->
bark_hist[ftype][ch];
120 float val = ((
const float []) { 0.4, 0.35, 0.28 })[ftype];
123 int idx = 0;
124
126 val = 0.5;
127 for (i = 0; i < fw_cb_len; i++)
128 for (j = 0; j < bark_n_coef; j++, idx++) {
129 float tmp2 = mtab->
fmode[ftype].
bark_cb[fw_cb_len * in[j] + i] *
130 (1.0 / 2048);
131 float st;
132
134 st = use_hist ?
135 tmp2 + val * hist[idx] + 1.0 : tmp2 + 1.0;
136 else
137 st = use_hist ? (1.0 -
val) * tmp2 + val * hist[idx] + 1.0
138 : tmp2 + 1.0;
139
140 hist[idx] = tmp2;
141 if (st < 0.1)
142 st = 0.1;
143
147 }
148 }
149
152 {
153 int i;
154
155 for (i = 0; i < tctx->
n_div[ftype]; i++) {
157
160 }
161 }
162
165 {
169 int sub;
171 int i, j, k;
172
174
176
180 }
181
183
185
188
190
191 for (i = 0; i < channels; i++)
192 for (j = 0; j < sub; j++)
194 bits->
bark1[i][j][k] =
196
197 for (i = 0; i < channels; i++)
198 for (j = 0; j < sub; j++)
200
202 for (i = 0; i < channels; i++)
204 } else {
205 for (i = 0; i < channels; i++) {
207 for (j = 0; j < sub; j++)
210 }
211 }
212
213 for (i = 0; i < channels; i++) {
216
219 }
220
223 for (i = 0; i < channels; i++) {
226 }
227 }
228
230 }
231
238
240 {
MKTAG(
'V',
'X',
'0',
'3'), 6, 1, 8000 },
241 {
MKTAG(
'V',
'X',
'0',
'4'), 12, 2, 8000 },
242
243 {
MKTAG(
'V',
'O',
'X',
'i'), 8, 1, 8000 },
244 {
MKTAG(
'V',
'O',
'X',
'j'), 10, 1, 11025 },
245 {
MKTAG(
'V',
'O',
'X',
'k'), 16, 1, 16000 },
246 {
MKTAG(
'V',
'O',
'X',
'L'), 24, 1, 22050 },
247 {
MKTAG(
'V',
'O',
'X',
'q'), 32, 1, 44100 },
248 {
MKTAG(
'V',
'O',
'X',
'r'), 40, 1, 44100 },
249 {
MKTAG(
'V',
'O',
'X',
's'), 48, 1, 44100 },
250 {
MKTAG(
'V',
'O',
'X',
't'), 16, 2, 8000 },
251 {
MKTAG(
'V',
'O',
'X',
'u'), 20, 2, 11025 },
252 {
MKTAG(
'V',
'O',
'X',
'v'), 32, 2, 16000 },
253 {
MKTAG(
'V',
'O',
'X',
'w'), 48, 2, 22050 },
254 {
MKTAG(
'V',
'O',
'X',
'x'), 64, 2, 44100 },
255 {
MKTAG(
'V',
'O',
'X',
'y'), 80, 2, 44100 },
256 {
MKTAG(
'V',
'O',
'X',
'z'), 96, 2, 44100 },
257
258 { 0, 0, 0, 0 }
259 };
260
262 {
263 int isampf, ibps;
267
271 }
272
274
275 for (;;) {
279 }
280 if (props->
tag == tag) {
285 break;
286 }
287 props++;
288 }
289
294 }
297
299
300 switch ((avctx->
channels << 16) + (isampf << 8) + ibps) {
301 case (1 << 16) + ( 8 << 8) + 8:
303 break;
304 case (1 << 16) + (16 << 8) + 16:
306 break;
307 case (1 << 16) + (44 << 8) + 32:
309 break;
310 case (2 << 16) + (44 << 8) + 48:
312 break;
313 default:
315 "This version does not support %d kHz - %d kbit/s/ch mode.\n",
316 isampf, isampf);
318 }
319
322
327
329 }
330
343 };