FFmpeg
Functions | Variables
twinvqdec.c File Reference
#include <math.h>
#include <stdint.h>
#include "libavutil/channel_layout.h"
#include "avcodec.h"
#include "codec_internal.h"
#include "get_bits.h"
#include "twinvq.h"
#include "twinvq_data.h"

Go to the source code of this file.

Functions

static int very_broken_op (int a, int b)
 Evaluate a * b / 400 rounded to the nearest integer. More...
 
static void add_peak (int period, int width, const float *shape, float ppc_gain, float *speech, int len)
 Sum to data a periodic peak of a given period, width and shape. More...
 
static void decode_ppc (TwinVQContext *tctx, int period_coef, int g_coef, const float *shape, float *speech)
 
static void dec_bark_env (TwinVQContext *tctx, const uint8_t *in, int use_hist, int ch, float *out, float gain, enum TwinVQFrameType ftype)
 
static void read_cb_data (TwinVQContext *tctx, GetBitContext *gb, uint8_t *dst, enum TwinVQFrameType ftype)
 
static int twinvq_read_bitstream (AVCodecContext *avctx, TwinVQContext *tctx, const uint8_t *buf, int buf_size)
 
static av_cold int twinvq_decode_init (AVCodecContext *avctx)
 

Variables

static const TwinVQModeTab mode_08_08
 
static const TwinVQModeTab mode_11_08
 
static const TwinVQModeTab mode_11_10
 
static const TwinVQModeTab mode_16_16
 
static const TwinVQModeTab mode_22_20
 
static const TwinVQModeTab mode_22_24
 
static const TwinVQModeTab mode_22_32
 
static const TwinVQModeTab mode_44_40
 
static const TwinVQModeTab mode_44_48
 
const FFCodec ff_twinvq_decoder
 

Function Documentation

◆ very_broken_op()

static int very_broken_op ( int  a,
int  b 
)
static

Evaluate a * b / 400 rounded to the nearest integer.

When, for example, a * b == 200 and the nearest integer is ill-defined, use a table to emulate the following broken float-based implementation used by the binary decoder:

static int very_broken_op(int a, int b)
{
static float test; // Ugh, force gcc to do the division first...
test = a / 400.0;
return b * test + 0.5;
}
Note
if this function is replaced by just ROUNDED_DIV(a * b, 400.0), the stddev between the original file (before encoding with Yamaha encoder) and the decoded output increases, which leads one to believe that the encoder expects exactly this broken calculation.

Definition at line 133 of file twinvqdec.c.

Referenced by add_peak().

◆ add_peak()

static void add_peak ( int  period,
int  width,
const float shape,
float  ppc_gain,
float speech,
int  len 
)
static

Sum to data a periodic peak of a given period, width and shape.

Parameters
periodthe period of the peak divided by 400.0

Definition at line 154 of file twinvqdec.c.

Referenced by decode_ppc().

◆ decode_ppc()

static void decode_ppc ( TwinVQContext tctx,
int  period_coef,
int  g_coef,
const float shape,
float speech 
)
static

Definition at line 178 of file twinvqdec.c.

Referenced by twinvq_decode_init().

◆ dec_bark_env()

static void dec_bark_env ( TwinVQContext tctx,
const uint8_t *  in,
int  use_hist,
int  ch,
float out,
float  gain,
enum TwinVQFrameType  ftype 
)
static

Definition at line 210 of file twinvqdec.c.

Referenced by twinvq_decode_init().

◆ read_cb_data()

static void read_cb_data ( TwinVQContext tctx,
GetBitContext gb,
uint8_t *  dst,
enum TwinVQFrameType  ftype 
)
static

Definition at line 238 of file twinvqdec.c.

Referenced by twinvq_read_bitstream().

◆ twinvq_read_bitstream()

static int twinvq_read_bitstream ( AVCodecContext avctx,
TwinVQContext tctx,
const uint8_t *  buf,
int  buf_size 
)
static

Definition at line 251 of file twinvqdec.c.

Referenced by twinvq_decode_init().

◆ twinvq_decode_init()

static av_cold int twinvq_decode_init ( AVCodecContext avctx)
static

Definition at line 319 of file twinvqdec.c.

Variable Documentation

◆ mode_08_08

const TwinVQModeTab mode_08_08
static
Initial value:
= {
{
{ 8, bark_tab_s08_64, 10, tab.fcb08s, 1, 5, tab.cb0808s0, tab.cb0808s1, 18 },
{ 2, bark_tab_m08_256, 20, tab.fcb08m, 2, 5, tab.cb0808m0, tab.cb0808m1, 16 },
{ 1, bark_tab_l08_512, 30, tab.fcb08l, 3, 6, tab.cb0808l0, tab.cb0808l1, 17 }
},
512, 12, ff_metasound_lsp8, 1, 5, 3, 3, tab.shape08, 8, 28, 20, 6, 40
}

Definition at line 32 of file twinvqdec.c.

Referenced by twinvq_decode_init().

◆ mode_11_08

const TwinVQModeTab mode_11_08
static
Initial value:
= {
{
{ 8, bark_tab_s11_64, 10, tab.fcb11s, 1, 5, tab.cb1108s0, tab.cb1108s1, 29 },
{ 2, bark_tab_m11_256, 20, tab.fcb11m, 2, 5, tab.cb1108m0, tab.cb1108m1, 24 },
{ 1, bark_tab_l11_512, 30, tab.fcb11l, 3, 6, tab.cb1108l0, tab.cb1108l1, 27 }
},
512, 16, ff_metasound_lsp11, 1, 6, 4, 3, tab.shape11, 9, 36, 30, 7, 90
}

Definition at line 41 of file twinvqdec.c.

Referenced by twinvq_decode_init().

◆ mode_11_10

const TwinVQModeTab mode_11_10
static
Initial value:
= {
{
{ 8, bark_tab_s11_64, 10, tab.fcb11s, 1, 5, tab.cb1110s0, tab.cb1110s1, 21 },
{ 2, bark_tab_m11_256, 20, tab.fcb11m, 2, 5, tab.cb1110m0, tab.cb1110m1, 18 },
{ 1, bark_tab_l11_512, 30, tab.fcb11l, 3, 6, tab.cb1110l0, tab.cb1110l1, 20 }
},
512, 16, ff_metasound_lsp11, 1, 6, 4, 3, tab.shape11, 9, 36, 30, 7, 90
}

Definition at line 50 of file twinvqdec.c.

Referenced by twinvq_decode_init().

◆ mode_16_16

const TwinVQModeTab mode_16_16
static
Initial value:
= {
{
{ 8, bark_tab_s16_128, 10, tab.fcb16s, 1, 5, tab.cb1616s0, tab.cb1616s1, 16 },
{ 2, bark_tab_m16_512, 20, tab.fcb16m, 2, 5, tab.cb1616m0, tab.cb1616m1, 15 },
{ 1, bark_tab_l16_1024, 30, tab.fcb16l, 3, 6, tab.cb1616l0, tab.cb1616l1, 16 }
},
1024, 16, ff_metasound_lsp16, 1, 6, 4, 3, tab.shape16, 9, 56, 60, 7, 180
}

Definition at line 59 of file twinvqdec.c.

Referenced by twinvq_decode_init().

◆ mode_22_20

const TwinVQModeTab mode_22_20
static
Initial value:
= {
{
{ 8, bark_tab_s22_128, 10, tab.fcb22s_1, 1, 6, tab.cb2220s0, tab.cb2220s1, 18 },
{ 2, bark_tab_m22_512, 20, tab.fcb22m_1, 2, 6, tab.cb2220m0, tab.cb2220m1, 17 },
{ 1, bark_tab_l22_1024, 32, tab.fcb22l_1, 4, 6, tab.cb2220l0, tab.cb2220l1, 18 }
},
1024, 16, ff_metasound_lsp22, 1, 6, 4, 3, tab.shape22_1, 9, 56, 36, 7, 144
}

Definition at line 68 of file twinvqdec.c.

Referenced by twinvq_decode_init().

◆ mode_22_24

const TwinVQModeTab mode_22_24
static
Initial value:
= {
{
{ 8, bark_tab_s22_128, 10, tab.fcb22s_1, 1, 6, tab.cb2224s0, tab.cb2224s1, 15 },
{ 2, bark_tab_m22_512, 20, tab.fcb22m_1, 2, 6, tab.cb2224m0, tab.cb2224m1, 14 },
{ 1, bark_tab_l22_1024, 32, tab.fcb22l_1, 4, 6, tab.cb2224l0, tab.cb2224l1, 15 }
},
1024, 16, ff_metasound_lsp22, 1, 6, 4, 3, tab.shape22_1, 9, 56, 36, 7, 144
}

Definition at line 77 of file twinvqdec.c.

Referenced by twinvq_decode_init().

◆ mode_22_32

const TwinVQModeTab mode_22_32
static
Initial value:
= {
{
{ 4, bark_tab_s22_128, 10, tab.fcb22s_2, 1, 6, tab.cb2232s0, tab.cb2232s1, 11 },
{ 2, bark_tab_m22_256, 20, tab.fcb22m_2, 2, 6, tab.cb2232m0, tab.cb2232m1, 11 },
{ 1, bark_tab_l22_512, 32, tab.fcb22l_2, 4, 6, tab.cb2232l0, tab.cb2232l1, 12 }
},
512, 16, tab.lsp22_2, 1, 6, 4, 4, tab.shape22_2, 9, 56, 36, 7, 72
}

Definition at line 86 of file twinvqdec.c.

Referenced by twinvq_decode_init().

◆ mode_44_40

const TwinVQModeTab mode_44_40
static
Initial value:
= {
{
{ 16, bark_tab_s44_128, 10, tab.fcb44s, 1, 6, tab.cb4440s0, tab.cb4440s1, 18 },
{ 4, bark_tab_m44_512, 20, tab.fcb44m, 2, 6, tab.cb4440m0, tab.cb4440m1, 17 },
{ 1, bark_tab_l44_2048, 40, tab.fcb44l, 4, 6, tab.cb4440l0, tab.cb4440l1, 17 }
},
2048, 20, ff_metasound_lsp44, 1, 6, 4, 4, tab.shape44, 9, 84, 54, 7, 432
}

Definition at line 95 of file twinvqdec.c.

Referenced by twinvq_decode_init().

◆ mode_44_48

const TwinVQModeTab mode_44_48
static
Initial value:
= {
{
{ 16, bark_tab_s44_128, 10, tab.fcb44s, 1, 6, tab.cb4448s0, tab.cb4448s1, 15 },
{ 4, bark_tab_m44_512, 20, tab.fcb44m, 2, 6, tab.cb4448m0, tab.cb4448m1, 14 },
{ 1, bark_tab_l44_2048, 40, tab.fcb44l, 4, 6, tab.cb4448l0, tab.cb4448l1, 14 }
},
2048, 20, ff_metasound_lsp44, 1, 6, 4, 4, tab.shape44, 9, 84, 54, 7, 432
}

Definition at line 104 of file twinvqdec.c.

Referenced by twinvq_decode_init().

◆ ff_twinvq_decoder

const FFCodec ff_twinvq_decoder
Initial value:
= {
.p.name = "twinvq",
CODEC_LONG_NAME("VQF TwinVQ"),
.p.type = AVMEDIA_TYPE_AUDIO,
.priv_data_size = sizeof(TwinVQContext),
.p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
}

Definition at line 416 of file twinvqdec.c.

AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:66
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
bark_tab_m22_256
static const uint16_t bark_tab_m22_256[]
Definition: twinvq_data.h:95
twinvq_decode_init
static av_cold int twinvq_decode_init(AVCodecContext *avctx)
Definition: twinvqdec.c:319
bark_tab_m22_512
#define bark_tab_m22_512
Definition: metasound_data.h:13814
b
#define b
Definition: input.c:41
test
Definition: idctdsp.c:34
bark_tab_s44_128
static const uint16_t bark_tab_s44_128[]
Definition: metasound_data.h:13821
ff_metasound_lsp11
const float ff_metasound_lsp11[]
Definition: metasound_twinvq_data.h:93
bark_tab_l08_512
static const uint16_t bark_tab_l08_512[]
Definition: twinvq_data.h:41
very_broken_op
static int very_broken_op(int a, int b)
Evaluate a * b / 400 rounded to the nearest integer.
Definition: twinvqdec.c:133
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:306
ff_metasound_lsp8
const float ff_metasound_lsp8[]
Definition: metasound_twinvq_data.h:27
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:365
bark_tab_m16_512
static const uint16_t bark_tab_m16_512[]
Definition: metasound_data.h:13756
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
ff_twinvq_decode_close
av_cold int ff_twinvq_decode_close(AVCodecContext *avctx)
Definition: twinvq.c:744
ff_twinvq_decode_frame
int ff_twinvq_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Definition: twinvq.c:479
AV_CODEC_CAP_CHANNEL_CONF
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
Definition: codec.h:103
tab
static const uint8_t tab[16]
Definition: rka.c:668
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
ff_metasound_lsp44
const float ff_metasound_lsp44[]
Definition: metasound_twinvq_data.h:606
bark_tab_m11_256
static const uint16_t bark_tab_m11_256[]
Definition: metasound_data.h:13728
bark_tab_m08_256
static const uint16_t bark_tab_m08_256[]
Definition: twinvq_data.h:80
bark_tab_s11_64
static const uint16_t bark_tab_s11_64[]
Definition: metasound_data.h:13724
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
ff_metasound_lsp22
const float ff_metasound_lsp22[]
Definition: metasound_twinvq_data.h:439
bark_tab_l11_512
static const uint16_t bark_tab_l11_512[]
Definition: metasound_data.h:13718
test
static int test(void)
Definition: dnn-layer-dense.c:28
bark_tab_l22_512
static const uint16_t bark_tab_l22_512[]
Definition: twinvq_data.h:66
bark_tab_l44_2048
static const uint16_t bark_tab_l44_2048[]
Definition: metasound_data.h:13808
ff_metasound_lsp16
const float ff_metasound_lsp16[]
Definition: metasound_twinvq_data.h:260
TwinVQContext
Definition: twinvq.h:137
bark_tab_s22_128
#define bark_tab_s22_128
Definition: metasound_data.h:13820
bark_tab_l16_1024
static const uint16_t bark_tab_l16_1024[]
Definition: metasound_data.h:13751
AV_CODEC_ID_TWINVQ
@ AV_CODEC_ID_TWINVQ
Definition: codec_id.h:481
bark_tab_s16_128
static const uint16_t bark_tab_s16_128[]
Definition: metasound_data.h:13761
bark_tab_s08_64
static const uint16_t bark_tab_s08_64[]
Definition: twinvq_data.h:110
bark_tab_l22_1024
static const uint16_t bark_tab_l22_1024[]
Definition: metasound_data.h:13783
bark_tab_m44_512
static const uint16_t bark_tab_m44_512[]
Definition: metasound_data.h:13815