28 #define BITSTREAM_READER_LE 
   42                      float ppc_gain, 
float *speech, 
int len)
 
   45     const float *shape_end = shape + 
len;
 
   48     for (i = 0; i < width / 2; i++)
 
   49         speech[i] += ppc_gain * *shape++;
 
   52         center = (int)(i * period + 0.5);
 
   53         for (j = -width / 2; j < (width + 1) / 2; j++)
 
   54             speech[j + center] += ppc_gain * *shape++;
 
   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++;
 
   64                        const float *shape, 
float *speech)
 
   71     float ratio = (float)mtab->
size / isampf;
 
   72     float min_period, max_period, period_range, period;
 
   75     float pgain_base, pgain_step, ppc_gain;
 
   78         min_period = 
log2(ratio * 0.2);
 
   79         max_period = min_period + 
log2(6);
 
   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;
 
   84     period_range = max_period - min_period;
 
   85     period       = min_period + period_coef * period_range /
 
   88         period = 
powf(2.0, period);
 
   90         period = (int)(period * 400 + 0.5) / 400.0;
 
   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;
 
  102     if (isampf == 22 && ibps == 32)
 
  103         width = (int)((2.0 / period + 1) * width + 0.5);
 
  106     pgain_step = pgain_base / ((1 << mtab->
pgain_bit) - 1);
 
  107     ppc_gain   = 1.0 / 8192 *
 
  115                          int ch, 
float *
out, 
float gain,
 
  120     float *hist     = tctx->
bark_hist[ftype][ch];
 
  121     float val       = ((
const float []) { 0.4, 0.35, 0.28 })[ftype];
 
  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] *
 
  136                     tmp2 + val * hist[idx] + 1.0 : tmp2 + 1.0;
 
  138                 st = use_hist ? (1.0 - 
val) * tmp2 + val * hist[idx] + 1.0
 
  156     for (i = 0; i < tctx->
n_div[ftype]; i++) {
 
  196         for (i = 0; i < channels; i++)
 
  197             for (j = 0; j < sub; j++)
 
  199                     bits->
bark1[i][j][k] =
 
  202         for (i = 0; i < channels; i++)
 
  203             for (j = 0; j < sub; j++)
 
  207             for (i = 0; i < channels; i++)
 
  210             for (i = 0; i < channels; i++) {
 
  212                 for (j = 0; j < sub; j++)
 
  218         for (i = 0; i < channels; i++) {
 
  228             for (i = 0; i < channels; i++) {
 
  250     { 
MKTAG(
'V',
'X',
'0',
'3'),  6, 1,  8000 },
 
  251     { 
MKTAG(
'V',
'X',
'0',
'4'), 12, 2,  8000 },
 
  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 },
 
  290         if (props->
tag == tag) {
 
  310     switch ((avctx->
channels << 16) + (isampf << 8) + ibps) {
 
  311     case (1 << 16) + ( 8 << 8) +  6:
 
  314     case (2 << 16) + ( 8 << 8) +  6:
 
  317     case (1 << 16) + ( 8 << 8) +  8:
 
  320     case (2 << 16) + ( 8 << 8) +  8:
 
  323     case (1 << 16) + (11 << 8) + 10:
 
  326     case (2 << 16) + (11 << 8) + 10:
 
  329     case (1 << 16) + (16 << 8) + 16:
 
  332     case (2 << 16) + (16 << 8) + 16:
 
  335     case (1 << 16) + (22 << 8) + 24:
 
  338     case (2 << 16) + (22 << 8) + 24:
 
  341     case (1 << 16) + (44 << 8) + 32:
 
  344     case (2 << 16) + (44 << 8) + 32:
 
  347     case (1 << 16) + (44 << 8) + 40:
 
  350     case (2 << 16) + (44 << 8) + 40:
 
  353     case (1 << 16) + (44 << 8) + 48:
 
  356     case (2 << 16) + (44 << 8) + 48:
 
  361                "This version does not support %d kHz - %d kbit/s/ch mode.\n",
 
const char const char void * val
#define AVERROR_INVALIDDATA
Invalid data found when processing input. 
uint8_t bark_n_bit
number of bits of the BSE coefs 
uint8_t ppc_coeffs[TWINVQ_PPC_SHAPE_LEN_MAX]
int bits_main_spec_change[4]
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits. 
const TwinVQModeTab * mtab
TwinVQFrameData bits[TWINVQ_MAX_FRAMES_PER_PACKET]
int p_coef[TWINVQ_CHANNELS_MAX]
static av_cold int init(AVCodecContext *avctx)
uint8_t bark_n_coef
number of BSE CB coefficients to read 
uint16_t size
frame size in samples 
#define AV_CH_LAYOUT_STEREO
uint8_t bark_use_hist[TWINVQ_CHANNELS_MAX][TWINVQ_SUBBLOCKS_MAX]
uint8_t lpc_idx1[TWINVQ_CHANNELS_MAX]
enum TwinVQFrameType ff_twinvq_wtype_to_ftype_table[]
uint8_t sub_gain_bits[TWINVQ_CHANNELS_MAX *TWINVQ_SUBBLOCKS_MAX]
Short frame (divided in n sub-blocks) 
uint8_t lpc_idx2[TWINVQ_CHANNELS_MAX][TWINVQ_LSP_SPLIT_MAX]
int g_coef[TWINVQ_CHANNELS_MAX]
uint8_t ppc_period_bit
number of the bits for the PPC period value 
av_cold int ff_twinvq_decode_close(AVCodecContext *avctx)
uint8_t gain_bits[TWINVQ_CHANNELS_MAX]
uint8_t * extradata
some codecs need / can use extradata like Huffman tables. 
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators. 
static int get_bits_count(const GetBitContext *s)
#define TWINVQ_WINDOW_TYPE_BITS
Parameters and tables that are different for every combination of bitrate/sample rate. 
uint8_t lpc_hist_idx[TWINVQ_CHANNELS_MAX]
bitstream reader API header. 
Long frame (single sub-block + PPC) 
uint8_t bark_env_size
number of distinct bark scale envelope values 
#define ROUNDED_DIV(a, b)
static float twinvq_mulawinv(float y, float clip, float mu)
uint8_t main_coeffs[1024]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered. 
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
const char * name
Name of the codec implementation. 
int(* read_bitstream)(AVCodecContext *avctx, struct TwinVQContext *tctx, const uint8_t *buf, int buf_size)
Libavcodec external API header. 
uint64_t channel_layout
Audio channel layout. 
void(* decode_ppc)(struct TwinVQContext *tctx, int period_coef, int g_coef, const float *shape, float *speech)
void(* dec_bark_env)(struct TwinVQContext *tctx, const uint8_t *in, int use_hist, int ch, float *out, float gain, enum TwinVQFrameType ftype)
int bit_rate
the average bitrate 
audio channel layout utility functions 
uint8_t sub
Number subblocks in each frame. 
uint8_t bits_main_spec[2][4][2]
bits for the main codebook 
static void twinvq_memset_float(float *buf, float val, int size)
int ff_twinvq_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
AVSampleFormat
Audio sample formats. 
float bark_hist[3][2][40]
BSE coefficients of last frame. 
int sample_rate
samples per second 
main external API structure. 
const uint16_t * bark_tab
enum TwinVQFrameType ftype
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 int16_t * bark_cb
codebook for the bark scale envelope (BSE) 
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits(GetBitContext *s, int n)
struct TwinVQFrameMode fmode[3]
frame type-dependant parameters 
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext. 
uint8_t pgain_bit
bits for PPC gain 
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
common internal api header. 
uint8_t ppc_shape_len
size of PPC shape CB 
#define TWINVQ_SUB_GAIN_BITS
int channels
number of audio channels 
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
static enum AVSampleFormat sample_fmts[]
#define TWINVQ_CHANNELS_MAX
#define AV_CH_LAYOUT_MONO
#define MKTAG(a, b, c, d)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
uint8_t lsp_split
number of CB entries for the LSP decoding 
uint8_t bark1[TWINVQ_CHANNELS_MAX][TWINVQ_SUBBLOCKS_MAX][TWINVQ_BARK_N_COEF_MAX]
av_cold int ff_twinvq_decode_init(AVCodecContext *avctx)