FFmpeg
Loading...
Searching...
No Matches
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.
 
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.
 
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;
}
int a
#define b
Definition input.c:43
Definition idctdsp.c:35
static int very_broken_op(int a, int b)
Evaluate a * b / 400 rounded to the nearest integer.
Definition twinvqdec.c:133
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.

◆ 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.

◆ 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 },
},
512, 12, ff_metasound_lsp8, 1, 5, 3, 3, tab.shape08, 8, 28, 20, 6, 40
}
const float ff_metasound_lsp8[]
int16_t cb0808l1[1088]
int16_t fcb08l[640]
int16_t cb0808l0[1088]
int16_t shape08[1280]
static const uint16_t bark_tab_s08_64[]
static const struct twinvq_data tab
static const uint16_t bark_tab_m08_256[]
Definition twinvq_data.h:80
static const uint16_t bark_tab_l08_512[]
Definition twinvq_data.h:41

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 },
},
512, 16, ff_metasound_lsp11, 1, 6, 4, 3, tab.shape11, 9, 36, 30, 7, 90
}
static const uint16_t bark_tab_s11_64[]
static const uint16_t bark_tab_l11_512[]
static const uint16_t bark_tab_m11_256[]
const float ff_metasound_lsp11[]
int16_t fcb11l[640]
int16_t shape11[1280]
int16_t cb1108l0[1728]
int16_t cb1108l1[1728]

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 },
},
512, 16, ff_metasound_lsp11, 1, 6, 4, 3, tab.shape11, 9, 36, 30, 7, 90
}
int16_t cb1110l1[1280]
int16_t cb1110l0[1280]

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 },
},
1024, 16, ff_metasound_lsp16, 1, 6, 4, 3, tab.shape16, 9, 56, 60, 7, 180
}
static const uint16_t bark_tab_m16_512[]
static const uint16_t bark_tab_s16_128[]
static const uint16_t bark_tab_l16_1024[]
const float ff_metasound_lsp16[]
int16_t shape16[1920]
int16_t cb1616l1[1024]
int16_t cb1616l0[1024]
int16_t fcb16l[640]

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 },
},
1024, 16, ff_metasound_lsp22, 1, 6, 4, 3, tab.shape22_1, 9, 56, 36, 7, 144
}
#define bark_tab_s22_128
static const uint16_t bark_tab_l22_1024[]
#define bark_tab_m22_512
const float ff_metasound_lsp22[]
int16_t cb2220l0[1152]
int16_t cb2220l1[1152]
int16_t shape22_1[1152]
int16_t fcb22l_1[512]

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 },
},
1024, 16, ff_metasound_lsp22, 1, 6, 4, 3, tab.shape22_1, 9, 56, 36, 7, 144
}
int16_t cb2224l1[960]
int16_t cb2224l0[960]

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 },
},
512, 16, tab.lsp22_2, 1, 6, 4, 4, tab.shape22_2, 9, 56, 36, 7, 72
}
int16_t shape22_2[1152]
int16_t fcb22l_2[512]
int16_t cb2232l0[768]
float lsp22_2[1312]
int16_t cb2232l1[768]
static const uint16_t bark_tab_l22_512[]
Definition twinvq_data.h:66
static const uint16_t bark_tab_m22_256[]
Definition twinvq_data.h:95

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 },
},
2048, 20, ff_metasound_lsp44, 1, 6, 4, 4, tab.shape44, 9, 84, 54, 7, 432
}
static const uint16_t bark_tab_m44_512[]
static const uint16_t bark_tab_l44_2048[]
static const uint16_t bark_tab_s44_128[]
const float ff_metasound_lsp44[]
int16_t cb4440l1[1088]
int16_t shape44[1152]
int16_t cb4440l0[1088]
int16_t fcb44l[640]

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 },
},
2048, 20, ff_metasound_lsp44, 1, 6, 4, 4, tab.shape44, 9, 84, 54, 7, 432
}
int16_t cb4448l1[896]
int16_t cb4448l0[896]

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),
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
}
static av_cold void close(AVCodecParserContext *s)
Definition apv_parser.c:197
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
Definition codec.h:94
@ AV_CODEC_ID_TWINVQ
Definition codec_id.h:496
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
int ff_twinvq_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Definition twinvq.c:480
av_cold int ff_twinvq_decode_close(AVCodecContext *avctx)
Definition twinvq.c:745
static av_cold int twinvq_decode_init(AVCodecContext *avctx)
Definition twinvqdec.c:319

Definition at line 416 of file twinvqdec.c.