FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
metasound.c
Go to the documentation of this file.
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 
28 #define BITSTREAM_READER_LE
30 #include "libavutil/float_dsp.h"
31 #include "avcodec.h"
32 #include "get_bits.h"
33 #include "fft.h"
34 #include "internal.h"
35 #include "lsp.h"
36 #include "sinewin.h"
37 
38 #include "twinvq.h"
39 #include "metasound_data.h"
40 
41 static void add_peak(float period, int width, const float *shape,
42  float ppc_gain, float *speech, int len)
43 {
44  int i, j, center;
45  const float *shape_end = shape + len;
46 
47  // First peak centered around zero
48  for (i = 0; i < width / 2; i++)
49  speech[i] += ppc_gain * *shape++;
50 
51  for (i = 1; i < ROUNDED_DIV(len, width); i++) {
52  center = (int)(i * period + 0.5);
53  for (j = -width / 2; j < (width + 1) / 2; j++)
54  speech[j + center] += ppc_gain * *shape++;
55  }
56 
57  // For the last block, be careful not to go beyond the end of the buffer
58  center = (int)(i * period + 0.5);
59  for (j = -width / 2; j < (width + 1) / 2 && shape < shape_end; j++)
60  speech[j + center] += ppc_gain * *shape++;
61 }
62 
63 static void decode_ppc(TwinVQContext *tctx, int period_coef, int g_coef,
64  const float *shape, float *speech)
65 {
66  const TwinVQModeTab *mtab = tctx->mtab;
67  int isampf = tctx->avctx->sample_rate / 1000;
68  int ibps = tctx->avctx->bit_rate / (1000 * tctx->avctx->channels);
69  int width;
70 
71  float ratio = (float)mtab->size / isampf;
72  float min_period, max_period, period_range, period;
73  float some_mult;
74 
75  float pgain_base, pgain_step, ppc_gain;
76 
77  if (tctx->avctx->channels == 1) {
78  min_period = log2(ratio * 0.2);
79  max_period = min_period + log2(6);
80  } else {
81  min_period = (int)(ratio * 0.2 * 400 + 0.5) / 400.0;
82  max_period = (int)(ratio * 0.2 * 400 * 6 + 0.5) / 400.0;
83  }
84  period_range = max_period - min_period;
85  period = min_period + period_coef * period_range /
86  ((1 << mtab->ppc_period_bit) - 1);
87  if (tctx->avctx->channels == 1)
88  period = powf(2.0, period);
89  else
90  period = (int)(period * 400 + 0.5) / 400.0;
91 
92  switch (isampf) {
93  case 8: some_mult = 2.0; break;
94  case 11: some_mult = 3.0; break;
95  case 16: some_mult = 3.0; break;
96  case 22: some_mult = ibps == 32 ? 2.0 : 4.0; break;
97  case 44: some_mult = 8.0; break;
98  default: some_mult = 4.0;
99  }
100 
101  width = (int)(some_mult / (mtab->size / period) * mtab->ppc_shape_len);
102  if (isampf == 22 && ibps == 32)
103  width = (int)((2.0 / period + 1) * width + 0.5);
104 
105  pgain_base = tctx->avctx->channels == 2 ? 25000.0 : 20000.0;
106  pgain_step = pgain_base / ((1 << mtab->pgain_bit) - 1);
107  ppc_gain = 1.0 / 8192 *
108  twinvq_mulawinv(pgain_step * g_coef + pgain_step / 2,
109  pgain_base, TWINVQ_PGAIN_MU);
110 
111  add_peak(period, width, shape, ppc_gain, speech, mtab->ppc_shape_len);
112 }
113 
114 static void dec_bark_env(TwinVQContext *tctx, const uint8_t *in, int use_hist,
115  int ch, float *out, float gain,
116  enum TwinVQFrameType ftype)
117 {
118  const TwinVQModeTab *mtab = tctx->mtab;
119  int i, j;
120  float *hist = tctx->bark_hist[ftype][ch];
121  float val = ((const float []) { 0.4, 0.35, 0.28 })[ftype];
122  int bark_n_coef = mtab->fmode[ftype].bark_n_coef;
123  int fw_cb_len = mtab->fmode[ftype].bark_env_size / bark_n_coef;
124  int idx = 0;
125 
126  if (tctx->avctx->channels == 1)
127  val = 0.5;
128  for (i = 0; i < fw_cb_len; i++)
129  for (j = 0; j < bark_n_coef; j++, idx++) {
130  float tmp2 = mtab->fmode[ftype].bark_cb[fw_cb_len * in[j] + i] *
131  (1.0 / 2048);
132  float st;
133 
134  if (tctx->avctx->channels == 1)
135  st = use_hist ?
136  tmp2 + val * hist[idx] + 1.0 : tmp2 + 1.0;
137  else
138  st = use_hist ? (1.0 - val) * tmp2 + val * hist[idx] + 1.0
139  : tmp2 + 1.0;
140 
141  hist[idx] = tmp2;
142  if (st < 0.1)
143  st = 0.1;
144 
145  twinvq_memset_float(out, st * gain,
146  mtab->fmode[ftype].bark_tab[idx]);
147  out += mtab->fmode[ftype].bark_tab[idx];
148  }
149 }
150 
151 static void read_cb_data(TwinVQContext *tctx, GetBitContext *gb,
152  uint8_t *dst, enum TwinVQFrameType ftype)
153 {
154  int i;
155 
156  for (i = 0; i < tctx->n_div[ftype]; i++) {
157  int bs_second_part = (i >= tctx->bits_main_spec_change[ftype]);
158 
159  *dst++ = get_bits(gb, tctx->bits_main_spec[0][ftype][bs_second_part]);
160  *dst++ = get_bits(gb, tctx->bits_main_spec[1][ftype][bs_second_part]);
161  }
162 }
163 
165  const uint8_t *buf, int buf_size)
166 {
168  const TwinVQModeTab *mtab = tctx->mtab;
169  int channels = tctx->avctx->channels;
170  int sub;
171  GetBitContext gb;
172  int i, j, k;
173 
174  init_get_bits(&gb, buf, buf_size * 8);
175 
176  for (tctx->cur_frame = 0; tctx->cur_frame < tctx->frames_per_packet;
177  tctx->cur_frame++) {
178  bits = tctx->bits + tctx->cur_frame;
179 
181 
182  if (bits->window_type > 8) {
183  av_log(avctx, AV_LOG_ERROR, "Invalid window type, broken sample?\n");
184  return AVERROR_INVALIDDATA;
185  }
186 
188 
189  sub = mtab->fmode[bits->ftype].sub;
190 
191  if (bits->ftype != TWINVQ_FT_SHORT && !tctx->is_6kbps)
192  get_bits(&gb, 2);
193 
194  read_cb_data(tctx, &gb, bits->main_coeffs, bits->ftype);
195 
196  for (i = 0; i < channels; i++)
197  for (j = 0; j < sub; j++)
198  for (k = 0; k < mtab->fmode[bits->ftype].bark_n_coef; k++)
199  bits->bark1[i][j][k] =
200  get_bits(&gb, mtab->fmode[bits->ftype].bark_n_bit);
201 
202  for (i = 0; i < channels; i++)
203  for (j = 0; j < sub; j++)
204  bits->bark_use_hist[i][j] = get_bits1(&gb);
205 
206  if (bits->ftype == TWINVQ_FT_LONG) {
207  for (i = 0; i < channels; i++)
208  bits->gain_bits[i] = get_bits(&gb, TWINVQ_GAIN_BITS);
209  } else {
210  for (i = 0; i < channels; i++) {
211  bits->gain_bits[i] = get_bits(&gb, TWINVQ_GAIN_BITS);
212  for (j = 0; j < sub; j++)
213  bits->sub_gain_bits[i * sub + j] =
215  }
216  }
217 
218  for (i = 0; i < channels; i++) {
219  bits->lpc_hist_idx[i] = get_bits(&gb, mtab->lsp_bit0);
220  bits->lpc_idx1[i] = get_bits(&gb, mtab->lsp_bit1);
221 
222  for (j = 0; j < mtab->lsp_split; j++)
223  bits->lpc_idx2[i][j] = get_bits(&gb, mtab->lsp_bit2);
224  }
225 
226  if (bits->ftype == TWINVQ_FT_LONG) {
227  read_cb_data(tctx, &gb, bits->ppc_coeffs, 3);
228  for (i = 0; i < channels; i++) {
229  bits->p_coef[i] = get_bits(&gb, mtab->ppc_period_bit);
230  bits->g_coef[i] = get_bits(&gb, mtab->pgain_bit);
231  }
232  }
233 
234  // subframes are aligned to nibbles
235  if (get_bits_count(&gb) & 3)
236  skip_bits(&gb, 4 - (get_bits_count(&gb) & 3));
237  }
238 
239  return (get_bits_count(&gb) + 7) / 8;
240 }
241 
242 typedef struct MetasoundProps {
243  uint32_t tag;
244  int bit_rate;
245  int channels;
248 
249 static const MetasoundProps codec_props[] = {
250  { MKTAG('V','X','0','3'), 6, 1, 8000 },
251  { MKTAG('V','X','0','4'), 12, 2, 8000 },
252 
253  { MKTAG('V','O','X','i'), 8, 1, 8000 },
254  { MKTAG('V','O','X','j'), 10, 1, 11025 },
255  { MKTAG('V','O','X','k'), 16, 1, 16000 },
256  { MKTAG('V','O','X','L'), 24, 1, 22050 },
257  { MKTAG('V','O','X','q'), 32, 1, 44100 },
258  { MKTAG('V','O','X','r'), 40, 1, 44100 },
259  { MKTAG('V','O','X','s'), 48, 1, 44100 },
260  { MKTAG('V','O','X','t'), 16, 2, 8000 },
261  { MKTAG('V','O','X','u'), 20, 2, 11025 },
262  { MKTAG('V','O','X','v'), 32, 2, 16000 },
263  { MKTAG('V','O','X','w'), 48, 2, 22050 },
264  { MKTAG('V','O','X','x'), 64, 2, 44100 },
265  { MKTAG('V','O','X','y'), 80, 2, 44100 },
266  { MKTAG('V','O','X','z'), 96, 2, 44100 },
267 
268  { 0, 0, 0, 0 }
269 };
270 
272 {
273  int isampf, ibps;
274  TwinVQContext *tctx = avctx->priv_data;
275  uint32_t tag;
276  const MetasoundProps *props = codec_props;
277 
278  if (!avctx->extradata || avctx->extradata_size < 16) {
279  av_log(avctx, AV_LOG_ERROR, "Missing or incomplete extradata\n");
280  return AVERROR_INVALIDDATA;
281  }
282 
283  tag = AV_RL32(avctx->extradata + 12);
284 
285  for (;;) {
286  if (!props->tag) {
287  av_log(avctx, AV_LOG_ERROR, "Could not find tag %08"PRIX32"\n", tag);
288  return AVERROR_INVALIDDATA;
289  }
290  if (props->tag == tag) {
291  avctx->sample_rate = props->sample_rate;
292  avctx->channels = props->channels;
293  avctx->bit_rate = props->bit_rate * 1000;
294  isampf = avctx->sample_rate / 1000;
295  break;
296  }
297  props++;
298  }
299 
300  if (avctx->channels <= 0 || avctx->channels > TWINVQ_CHANNELS_MAX) {
301  av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels: %i\n",
302  avctx->channels);
303  return AVERROR_INVALIDDATA;
304  }
305  avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO
307 
308  ibps = avctx->bit_rate / (1000 * avctx->channels);
309 
310  switch ((avctx->channels << 16) + (isampf << 8) + ibps) {
311  case (1 << 16) + ( 8 << 8) + 6:
312  tctx->mtab = &ff_metasound_mode0806;
313  break;
314  case (2 << 16) + ( 8 << 8) + 6:
315  tctx->mtab = &ff_metasound_mode0806s;
316  break;
317  case (1 << 16) + ( 8 << 8) + 8:
318  tctx->mtab = &ff_metasound_mode0808;
319  break;
320  case (2 << 16) + ( 8 << 8) + 8:
321  tctx->mtab = &ff_metasound_mode0808s;
322  break;
323  case (1 << 16) + (11 << 8) + 10:
324  tctx->mtab = &ff_metasound_mode1110;
325  break;
326  case (2 << 16) + (11 << 8) + 10:
327  tctx->mtab = &ff_metasound_mode1110s;
328  break;
329  case (1 << 16) + (16 << 8) + 16:
330  tctx->mtab = &ff_metasound_mode1616;
331  break;
332  case (2 << 16) + (16 << 8) + 16:
333  tctx->mtab = &ff_metasound_mode1616s;
334  break;
335  case (1 << 16) + (22 << 8) + 24:
336  tctx->mtab = &ff_metasound_mode2224;
337  break;
338  case (2 << 16) + (22 << 8) + 24:
339  tctx->mtab = &ff_metasound_mode2224s;
340  break;
341  case (1 << 16) + (44 << 8) + 32:
342  tctx->mtab = &ff_metasound_mode4432;
343  break;
344  case (2 << 16) + (44 << 8) + 32:
345  tctx->mtab = &ff_metasound_mode4432s;
346  break;
347  case (1 << 16) + (44 << 8) + 40:
348  tctx->mtab = &ff_metasound_mode4440;
349  break;
350  case (2 << 16) + (44 << 8) + 40:
351  tctx->mtab = &ff_metasound_mode4440s;
352  break;
353  case (1 << 16) + (44 << 8) + 48:
354  tctx->mtab = &ff_metasound_mode4448;
355  break;
356  case (2 << 16) + (44 << 8) + 48:
357  tctx->mtab = &ff_metasound_mode4448s;
358  break;
359  default:
360  av_log(avctx, AV_LOG_ERROR,
361  "This version does not support %d kHz - %d kbit/s/ch mode.\n",
362  isampf, ibps);
363  return AVERROR(ENOSYS);
364  }
365 
368  tctx->dec_bark_env = dec_bark_env;
369  tctx->decode_ppc = decode_ppc;
370  tctx->frame_size = avctx->bit_rate * tctx->mtab->size
371  / avctx->sample_rate;
372  tctx->is_6kbps = ibps == 6;
373 
374  return ff_twinvq_decode_init(avctx);
375 }
376 
378  .name = "metasound",
379  .long_name = NULL_IF_CONFIG_SMALL("Voxware MetaSound"),
380  .type = AVMEDIA_TYPE_AUDIO,
381  .id = AV_CODEC_ID_METASOUND,
382  .priv_data_size = sizeof(TwinVQContext),
384  .close = ff_twinvq_decode_close,
386  .capabilities = AV_CODEC_CAP_DR1,
387  .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
389 };
#define TWINVQ_PGAIN_MU
Definition: twinvq.h:54
float, planar
Definition: samplefmt.h:70
const char const char void * val
Definition: avisynth_c.h:634
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
uint8_t bark_n_bit
number of bits of the BSE coefs
Definition: twinvq.h:75
int window_type
Definition: twinvq.h:87
uint8_t ppc_coeffs[TWINVQ_PPC_SHAPE_LEN_MAX]
Definition: twinvq.h:91
int bits_main_spec_change[4]
Definition: twinvq.h:155
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:260
const TwinVQModeTab * mtab
Definition: twinvq.h:142
TwinVQFrameData bits[TWINVQ_MAX_FRAMES_PER_PACKET]
Definition: twinvq.h:170
int p_coef[TWINVQ_CHANNELS_MAX]
Definition: twinvq.h:103
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
uint8_t bark_n_coef
number of BSE CB coefficients to read
Definition: twinvq.h:74
static const MetasoundProps codec_props[]
Definition: metasound.c:249
uint16_t size
frame size in samples
Definition: twinvq.h:114
uint8_t lsp_bit0
Definition: twinvq.h:119
#define AV_CH_LAYOUT_STEREO
uint8_t bark_use_hist[TWINVQ_CHANNELS_MAX][TWINVQ_SUBBLOCKS_MAX]
Definition: twinvq.h:97
AVCodec.
Definition: avcodec.h:3472
uint8_t lpc_idx1[TWINVQ_CHANNELS_MAX]
Definition: twinvq.h:99
enum TwinVQFrameType ff_twinvq_wtype_to_ftype_table[]
Definition: twinvq.c:470
uint8_t sub_gain_bits[TWINVQ_CHANNELS_MAX *TWINVQ_SUBBLOCKS_MAX]
Definition: twinvq.h:94
const TwinVQModeTab ff_metasound_mode1110
#define log2(x)
Definition: libm.h:122
const TwinVQModeTab ff_metasound_mode0808s
Short frame (divided in n sub-blocks)
Definition: twinvq.h:40
static int metasound_read_bitstream(AVCodecContext *avctx, TwinVQContext *tctx, const uint8_t *buf, int buf_size)
Definition: metasound.c:164
uint8_t lpc_idx2[TWINVQ_CHANNELS_MAX][TWINVQ_LSP_SPLIT_MAX]
Definition: twinvq.h:100
uint8_t bits
Definition: crc.c:295
uint8_t
#define av_cold
Definition: attributes.h:74
int g_coef[TWINVQ_CHANNELS_MAX]
Definition: twinvq.h:104
uint8_t ppc_period_bit
number of the bits for the PPC period value
Definition: twinvq.h:127
av_cold int ff_twinvq_decode_close(AVCodecContext *avctx)
Definition: twinvq.c:751
uint8_t gain_bits[TWINVQ_CHANNELS_MAX]
Definition: twinvq.h:93
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1617
#define TWINVQ_GAIN_BITS
Definition: twinvq.h:50
TwinVQFrameType
Definition: twinvq.h:39
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:212
#define TWINVQ_WINDOW_TYPE_BITS
Definition: twinvq.h:53
uint32_t tag
Definition: movenc.c:1334
Parameters and tables that are different for every combination of bitrate/sample rate.
Definition: twinvq.h:111
uint8_t lpc_hist_idx[TWINVQ_CHANNELS_MAX]
Definition: twinvq.h:101
bitstream reader API header.
int cur_frame
Definition: twinvq.h:169
Long frame (single sub-block + PPC)
Definition: twinvq.h:42
#define av_log(a,...)
uint8_t bark_env_size
number of distinct bark scale envelope values
Definition: twinvq.h:71
const TwinVQModeTab ff_metasound_mode0806
#define ROUNDED_DIV(a, b)
Definition: common.h:55
static float twinvq_mulawinv(float y, float clip, float mu)
Definition: twinvq.h:192
int frame_size
Definition: twinvq.h:169
static void decode_ppc(TwinVQContext *tctx, int period_coef, int g_coef, const float *shape, float *speech)
Definition: metasound.c:63
uint8_t main_coeffs[1024]
Definition: twinvq.h:90
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
const TwinVQModeTab ff_metasound_mode4432
const TwinVQModeTab ff_metasound_mode1616
const char * name
Name of the codec implementation.
Definition: avcodec.h:3479
int(* read_bitstream)(AVCodecContext *avctx, struct TwinVQContext *tctx, const uint8_t *buf, int buf_size)
Definition: twinvq.h:174
Libavcodec external API header.
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:2323
#define powf(x, y)
Definition: libm.h:48
void(* decode_ppc)(struct TwinVQContext *tctx, int period_coef, int g_coef, const float *shape, float *speech)
Definition: twinvq.h:179
void(* dec_bark_env)(struct TwinVQContext *tctx, const uint8_t *in, int use_hist, int ch, float *out, float gain, enum TwinVQFrameType ftype)
Definition: twinvq.h:176
const TwinVQModeTab ff_metasound_mode4440s
int bit_rate
the average bitrate
Definition: avcodec.h:1567
audio channel layout utility functions
uint8_t sub
Number subblocks in each frame.
Definition: twinvq.h:67
static void dec_bark_env(TwinVQContext *tctx, const uint8_t *in, int use_hist, int ch, float *out, float gain, enum TwinVQFrameType ftype)
Definition: metasound.c:114
const TwinVQModeTab ff_metasound_mode1616s
uint8_t bits_main_spec[2][4][2]
bits for the main codebook
Definition: twinvq.h:154
static void twinvq_memset_float(float *buf, float val, int size)
Definition: twinvq.h:186
const TwinVQModeTab ff_metasound_mode2224s
int ff_twinvq_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: twinvq.c:476
int is_6kbps
Definition: twinvq.h:144
const TwinVQModeTab ff_metasound_mode4448s
int n_div[4]
Definition: twinvq.h:156
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:59
float bark_hist[3][2][40]
BSE coefficients of last frame.
Definition: twinvq.h:148
static void read_cb_data(TwinVQContext *tctx, GetBitContext *gb, uint8_t *dst, enum TwinVQFrameType ftype)
Definition: metasound.c:151
int sample_rate
samples per second
Definition: avcodec.h:2262
main external API structure.
Definition: avcodec.h:1502
const uint16_t * bark_tab
Definition: twinvq.h:68
enum TwinVQFrameType ftype
Definition: twinvq.h:88
int frames_per_packet
Definition: twinvq.h:169
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
const TwinVQModeTab ff_metasound_mode0808
const int16_t * bark_cb
codebook for the bark scale envelope (BSE)
Definition: twinvq.h:73
void * buf
Definition: avisynth_c.h:553
int extradata_size
Definition: avcodec.h:1618
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:304
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:297
struct TwinVQFrameMode fmode[3]
frame type-dependant parameters
Definition: twinvq.h:112
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:410
static void add_peak(float period, int width, const float *shape, float ppc_gain, float *speech, int len)
Definition: metasound.c:41
uint32_t tag
Definition: metasound.c:243
uint8_t pgain_bit
bits for PPC gain
Definition: twinvq.h:131
const TwinVQModeTab ff_metasound_mode1110s
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
Definition: ccaption_dec.c:523
uint8_t lsp_bit1
Definition: twinvq.h:120
enum TwinVQCodec codec
Definition: twinvq.h:172
common internal api header.
if(ret< 0)
Definition: vf_mcdeint.c:280
uint8_t ppc_shape_len
size of PPC shape CB
Definition: twinvq.h:130
#define TWINVQ_SUB_GAIN_BITS
Definition: twinvq.h:52
void * priv_data
Definition: avcodec.h:1544
int len
int channels
number of audio channels
Definition: avcodec.h:2263
const TwinVQModeTab ff_metasound_mode0806s
const TwinVQModeTab ff_metasound_mode4432s
const TwinVQModeTab ff_metasound_mode2224
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
const TwinVQModeTab ff_metasound_mode4448
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:701
static av_cold int metasound_decode_init(AVCodecContext *avctx)
Definition: metasound.c:271
const TwinVQModeTab ff_metasound_mode4440
#define TWINVQ_CHANNELS_MAX
Definition: twinvq.h:57
#define AV_CH_LAYOUT_MONO
#define MKTAG(a, b, c, d)
Definition: common.h:330
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:87
AVCodec ff_metasound_decoder
Definition: metasound.c:377
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:857
AVCodecContext * avctx
Definition: twinvq.h:138
uint8_t lsp_bit2
Definition: twinvq.h:121
uint8_t lsp_split
number of CB entries for the LSP decoding
Definition: twinvq.h:123
uint8_t bark1[TWINVQ_CHANNELS_MAX][TWINVQ_SUBBLOCKS_MAX][TWINVQ_BARK_N_COEF_MAX]
Definition: twinvq.h:96
av_cold int ff_twinvq_decode_init(AVCodecContext *avctx)
Definition: twinvq.c:770
static int width