FFmpeg  2.1.1
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 <math.h>
25 #include <stdint.h>
26 
27 #define BITSTREAM_READER_LE
28 #include "libavutil/channel_layout.h"
29 #include "libavutil/float_dsp.h"
30 #include "avcodec.h"
31 #include "get_bits.h"
32 #include "fft.h"
33 #include "internal.h"
34 #include "lsp.h"
35 #include "sinewin.h"
36 
37 #include "twinvq.h"
38 #include "metasound_data.h"
39 
40 static void add_peak(float period, int width, const float *shape,
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 
50  for (i = 1; i < ROUNDED_DIV(len, width); i++) {
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 
62 static void decode_ppc(TwinVQContext *tctx, int period_coef, int g_coef,
63  const float *shape, float *speech)
64 {
65  const TwinVQModeTab *mtab = tctx->mtab;
66  int isampf = tctx->avctx->sample_rate / 1000;
67  int ibps = tctx->avctx->bit_rate / (1000 * tctx->avctx->channels);
68  int width;
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 
76  if (tctx->avctx->channels == 1) {
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 /
85  ((1 << mtab->ppc_period_bit) - 1);
86  if (tctx->avctx->channels == 1)
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 
100  width = (int)(some_mult / (mtab->size / period) * mtab->ppc_shape_len);
101  if (isampf == 22 && ibps == 32)
102  width = (int)((2.0 / period + 1) * width + 0.5);
103 
104  pgain_base = tctx->avctx->channels == 2 ? 25000.0 : 20000.0;
105  pgain_step = pgain_base / ((1 << mtab->pgain_bit) - 1);
106  ppc_gain = 1.0 / 8192 *
107  twinvq_mulawinv(pgain_step * g_coef + pgain_step / 2,
108  pgain_base, TWINVQ_PGAIN_MU);
109 
110  add_peak(period, width, shape, ppc_gain, speech, mtab->ppc_shape_len);
111 }
112 
113 static void dec_bark_env(TwinVQContext *tctx, const uint8_t *in, int use_hist,
114  int ch, float *out, float gain,
115  enum TwinVQFrameType ftype)
116 {
117  const TwinVQModeTab *mtab = tctx->mtab;
118  int i, j;
119  float *hist = tctx->bark_hist[ftype][ch];
120  float val = ((const float []) { 0.4, 0.35, 0.28 })[ftype];
121  int bark_n_coef = mtab->fmode[ftype].bark_n_coef;
122  int fw_cb_len = mtab->fmode[ftype].bark_env_size / bark_n_coef;
123  int idx = 0;
124 
125  if (tctx->avctx->channels == 1)
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 
133  if (tctx->avctx->channels == 1)
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 
144  twinvq_memset_float(out, st * gain,
145  mtab->fmode[ftype].bark_tab[idx]);
146  out += mtab->fmode[ftype].bark_tab[idx];
147  }
148 }
149 
150 static void read_cb_data(TwinVQContext *tctx, GetBitContext *gb,
151  uint8_t *dst, enum TwinVQFrameType ftype)
152 {
153  int i;
154 
155  for (i = 0; i < tctx->n_div[ftype]; i++) {
156  int bs_second_part = (i >= tctx->bits_main_spec_change[ftype]);
157 
158  *dst++ = get_bits(gb, tctx->bits_main_spec[0][ftype][bs_second_part]);
159  *dst++ = get_bits(gb, tctx->bits_main_spec[1][ftype][bs_second_part]);
160  }
161 }
162 
164  const uint8_t *buf, int buf_size)
165 {
166  TwinVQFrameData *bits = &tctx->bits;
167  const TwinVQModeTab *mtab = tctx->mtab;
168  int channels = tctx->avctx->channels;
169  int sub;
170  GetBitContext gb;
171  int i, j, k;
172 
173  init_get_bits(&gb, buf, buf_size * 8);
174 
176 
177  if (bits->window_type > 8) {
178  av_log(avctx, AV_LOG_ERROR, "Invalid window type, broken sample?\n");
179  return AVERROR_INVALIDDATA;
180  }
181 
183 
184  sub = mtab->fmode[bits->ftype].sub;
185 
186  if (bits->ftype != TWINVQ_FT_SHORT)
187  get_bits(&gb, 2);
188 
189  read_cb_data(tctx, &gb, bits->main_coeffs, bits->ftype);
190 
191  for (i = 0; i < channels; i++)
192  for (j = 0; j < sub; j++)
193  for (k = 0; k < mtab->fmode[bits->ftype].bark_n_coef; k++)
194  bits->bark1[i][j][k] =
195  get_bits(&gb, mtab->fmode[bits->ftype].bark_n_bit);
196 
197  for (i = 0; i < channels; i++)
198  for (j = 0; j < sub; j++)
199  bits->bark_use_hist[i][j] = get_bits1(&gb);
200 
201  if (bits->ftype == TWINVQ_FT_LONG) {
202  for (i = 0; i < channels; i++)
203  bits->gain_bits[i] = get_bits(&gb, TWINVQ_GAIN_BITS);
204  } else {
205  for (i = 0; i < channels; i++) {
206  bits->gain_bits[i] = get_bits(&gb, TWINVQ_GAIN_BITS);
207  for (j = 0; j < sub; j++)
208  bits->sub_gain_bits[i * sub + j] =
210  }
211  }
212 
213  for (i = 0; i < channels; i++) {
214  bits->lpc_hist_idx[i] = get_bits(&gb, mtab->lsp_bit0);
215  bits->lpc_idx1[i] = get_bits(&gb, mtab->lsp_bit1);
216 
217  for (j = 0; j < mtab->lsp_split; j++)
218  bits->lpc_idx2[i][j] = get_bits(&gb, mtab->lsp_bit2);
219  }
220 
221  if (bits->ftype == TWINVQ_FT_LONG) {
222  read_cb_data(tctx, &gb, bits->ppc_coeffs, 3);
223  for (i = 0; i < channels; i++) {
224  bits->p_coef[i] = get_bits(&gb, mtab->ppc_period_bit);
225  bits->g_coef[i] = get_bits(&gb, mtab->pgain_bit);
226  }
227  }
228 
229  return (get_bits_count(&gb) + 7) / 8;
230 }
231 
232 typedef struct MetasoundProps {
233  uint32_t tag;
234  int bit_rate;
235  int channels;
238 
239 static const MetasoundProps codec_props[] = {
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;
264  TwinVQContext *tctx = avctx->priv_data;
265  uint32_t tag;
266  const MetasoundProps *props = codec_props;
267 
268  if (!avctx->extradata || avctx->extradata_size < 16) {
269  av_log(avctx, AV_LOG_ERROR, "Missing or incomplete extradata\n");
270  return AVERROR_INVALIDDATA;
271  }
272 
273  tag = AV_RL32(avctx->extradata + 12);
274 
275  for (;;) {
276  if (!props->tag) {
277  av_log(avctx, AV_LOG_ERROR, "Could not find tag %08X\n", tag);
278  return AVERROR_INVALIDDATA;
279  }
280  if (props->tag == tag) {
281  avctx->sample_rate = props->sample_rate;
282  avctx->channels = props->channels;
283  avctx->bit_rate = props->bit_rate * 1000;
284  isampf = avctx->sample_rate / 1000;
285  break;
286  }
287  props++;
288  }
289 
290  if (avctx->channels <= 0 || avctx->channels > TWINVQ_CHANNELS_MAX) {
291  av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels: %i\n",
292  avctx->channels);
293  return AVERROR_INVALIDDATA;
294  }
295  avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO
297 
298  ibps = avctx->bit_rate / (1000 * avctx->channels);
299 
300  switch ((avctx->channels << 16) + (isampf << 8) + ibps) {
301  case (1 << 16) + ( 8 << 8) + 8:
302  tctx->mtab = &ff_metasound_mode0808;
303  break;
304  case (1 << 16) + (16 << 8) + 16:
305  tctx->mtab = &ff_metasound_mode1616;
306  break;
307  case (1 << 16) + (44 << 8) + 32:
308  tctx->mtab = &ff_metasound_mode4432;
309  break;
310  case (2 << 16) + (44 << 8) + 48:
311  tctx->mtab = &ff_metasound_mode4448s;
312  break;
313  default:
314  av_log(avctx, AV_LOG_ERROR,
315  "This version does not support %d kHz - %d kbit/s/ch mode.\n",
316  isampf, isampf);
317  return AVERROR(ENOSYS);
318  }
319 
320  avctx->block_align = (avctx->bit_rate * tctx->mtab->size
321  / avctx->sample_rate + 7) / 8;
322 
325  tctx->dec_bark_env = dec_bark_env;
326  tctx->decode_ppc = decode_ppc;
327 
328  return ff_twinvq_decode_init(avctx);
329 }
330 
332  .name = "metasound",
333  .long_name = NULL_IF_CONFIG_SMALL("Voxware MetaSound"),
334  .type = AVMEDIA_TYPE_AUDIO,
335  .id = AV_CODEC_ID_METASOUND,
336  .priv_data_size = sizeof(TwinVQContext),
340  .capabilities = CODEC_CAP_DR1,
341  .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
343 };
#define TWINVQ_PGAIN_MU
Definition: twinvq.h:54
const char const char void * val
Definition: avisynth_c.h:671
uint8_t bark_n_bit
number of bits of the BSE coefs
Definition: twinvq.h:73
int window_type
Definition: twinvq.h:85
uint8_t ppc_coeffs[TWINVQ_PPC_SHAPE_LEN_MAX]
Definition: twinvq.h:89
int bits_main_spec_change[4]
Definition: twinvq.h:151
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:255
const TwinVQModeTab * mtab
Definition: twinvq.h:140
int p_coef[TWINVQ_CHANNELS_MAX]
Definition: twinvq.h:101
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:72
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
static const MetasoundProps codec_props[]
Definition: metasound.c:239
uint16_t size
frame size in samples
Definition: twinvq.h:112
uint8_t lsp_bit0
Definition: twinvq.h:117
#define AV_CH_LAYOUT_STEREO
uint8_t bark_use_hist[TWINVQ_CHANNELS_MAX][TWINVQ_SUBBLOCKS_MAX]
Definition: twinvq.h:95
AVCodec.
Definition: avcodec.h:2922
#define av_cold
Definition: avcodec.h:653
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
Definition: avcodec.h:1910
uint8_t lpc_idx1[TWINVQ_CHANNELS_MAX]
Definition: twinvq.h:97
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1254
enum TwinVQFrameType ff_twinvq_wtype_to_ftype_table[]
Definition: twinvq.c:467
uint8_t sub_gain_bits[TWINVQ_CHANNELS_MAX *TWINVQ_SUBBLOCKS_MAX]
Definition: twinvq.h:92
#define log2(x)
Definition: libm.h:122
if((e=av_dict_get(options,"", NULL, AV_DICT_IGNORE_SUFFIX)))
Definition: avfilter.c:965
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:163
uint8_t lpc_idx2[TWINVQ_CHANNELS_MAX][TWINVQ_LSP_SPLIT_MAX]
Definition: twinvq.h:98
uint8_t bits
Definition: crc.c:260
uint8_t
int g_coef[TWINVQ_CHANNELS_MAX]
Definition: twinvq.h:102
uint8_t ppc_period_bit
number of the bits for the PPC period value
Definition: twinvq.h:125
av_cold int ff_twinvq_decode_close(AVCodecContext *avctx)
Definition: twinvq.c:739
uint8_t gain_bits[TWINVQ_CHANNELS_MAX]
Definition: twinvq.h:91
const char * name
Name of the codec implementation.
Definition: avcodec.h:2929
#define TWINVQ_GAIN_BITS
Definition: twinvq.h:50
TwinVQFrameType
Definition: twinvq.h:39
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:742
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:207
#define TWINVQ_WINDOW_TYPE_BITS
Definition: twinvq.h:53
uint32_t tag
Definition: movenc.c:961
Parameters and tables that are different for every combination of bitrate/sample rate.
Definition: twinvq.h:109
uint8_t lpc_hist_idx[TWINVQ_CHANNELS_MAX]
Definition: twinvq.h:99
bitstream reader API header.
Long frame (single sub-block + PPC)
Definition: twinvq.h:42
uint8_t bark_env_size
number of distinct bark scale envelope values
Definition: twinvq.h:69
static float twinvq_mulawinv(float y, float clip, float mu)
Definition: twinvq.h:187
static void decode_ppc(TwinVQContext *tctx, int period_coef, int g_coef, const float *shape, float *speech)
Definition: metasound.c:62
uint8_t main_coeffs[1024]
Definition: twinvq.h:88
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: avcodec.h:4147
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){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));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=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);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);ff_audio_convert_init_arm(ac);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_dlog(ac->avr,"%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
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:151
const TwinVQModeTab ff_metasound_mode4432
const TwinVQModeTab ff_metasound_mode1616
int(* read_bitstream)(AVCodecContext *avctx, struct TwinVQContext *tctx, const uint8_t *buf, int buf_size)
Definition: twinvq.h:169
Libavcodec external API header.
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:1934
#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:174
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:171
int bit_rate
the average bitrate
Definition: avcodec.h:1204
uint8_t sub
Number subblocks in each frame.
Definition: twinvq.h:65
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:113
uint8_t bits_main_spec[2][4][2]
bits for the main codebook
Definition: twinvq.h:150
static void twinvq_memset_float(float *buf, float val, int size)
Definition: twinvq.h:181
TwinVQFrameData bits
Definition: twinvq.h:165
int ff_twinvq_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: twinvq.c:473
const TwinVQModeTab ff_metasound_mode4448s
int n_div[4]
Definition: twinvq.h:152
AVSampleFormat
Audio Sample Formats.
Definition: samplefmt.h:49
static int width
Definition: utils.c:158
float bark_hist[3][2][40]
BSE coefficients of last frame.
Definition: twinvq.h:144
static void read_cb_data(TwinVQContext *tctx, GetBitContext *gb, uint8_t *dst, enum TwinVQFrameType ftype)
Definition: metasound.c:150
int sample_rate
samples per second
Definition: avcodec.h:1873
main external API structure.
Definition: avcodec.h:1146
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:538
const uint16_t * bark_tab
Definition: twinvq.h:66
enum TwinVQFrameType ftype
Definition: twinvq.h:86
const TwinVQModeTab ff_metasound_mode0808
const int16_t * bark_cb
codebook for the bark scale envelope (BSE)
Definition: twinvq.h:71
void * buf
Definition: avisynth_c.h:594
int extradata_size
Definition: avcodec.h:1255
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:299
#define MKTAG(a, b, c, d)
struct TwinVQFrameMode fmode[3]
frame type-dependant parameters
Definition: twinvq.h:110
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:405
static void add_peak(float period, int width, const float *shape, float ppc_gain, float *speech, int len)
Definition: metasound.c:40
uint32_t tag
Definition: metasound.c:233
uint8_t pgain_bit
bits for PPC gain
Definition: twinvq.h:129
#define ROUNDED_DIV(a, b)
Definition: avcodec.h:914
void * priv_data
Definition: avcodec.h:1182
uint8_t lsp_bit1
Definition: twinvq.h:118
enum TwinVQCodec codec
Definition: twinvq.h:167
common internal api header.
uint8_t ppc_shape_len
size of PPC shape CB
Definition: twinvq.h:128
#define TWINVQ_SUB_GAIN_BITS
Definition: twinvq.h:52
#define AVERROR_INVALIDDATA
#define AV_RL32(x)
Definition: intreadwrite.h:275
int len
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){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));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=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);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);ff_audio_convert_init_arm(ac);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_dlog(ac->avr,"%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
int channels
number of audio channels
Definition: avcodec.h:1874
#define AVERROR(e)
float, planar
Definition: samplefmt.h:60
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:700
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: crystalhd.c:868
static av_cold int metasound_decode_init(AVCodecContext *avctx)
Definition: metasound.c:261
#define TWINVQ_CHANNELS_MAX
Definition: twinvq.h:57
#define AV_CH_LAYOUT_MONO
AVCodec ff_metasound_decoder
Definition: metasound.c:331
AVCodecContext * avctx
Definition: twinvq.h:136
uint8_t lsp_bit2
Definition: twinvq.h:119
uint8_t lsp_split
number of CB entries for the LSP decoding
Definition: twinvq.h:121
uint8_t bark1[TWINVQ_CHANNELS_MAX][TWINVQ_SUBBLOCKS_MAX][TWINVQ_BARK_N_COEF_MAX]
Definition: twinvq.h:94
av_cold int ff_twinvq_decode_init(AVCodecContext *avctx)
Definition: twinvq.c:757