FFmpeg
Functions | Variables
twinvqdec.c File Reference
#include <math.h>
#include <stdint.h>
#include "libavutil/channel_layout.h"
#include "avcodec.h"
#include "get_bits.h"
#include "internal.h"
#include "twinvq.h"
#include "metasound_data.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
 
AVCodec ff_twinvq_decoder
 

Function Documentation

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:

1 static int very_broken_op(int a, int b)
2 {
3  static float test; // Ugh, force gcc to do the division first...
4 
5  test = a / 400.0;
6  return b * test + 0.5;
7 }
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 134 of file twinvqdec.c.

Referenced by 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 155 of file twinvqdec.c.

Referenced by decode_ppc().

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

Definition at line 179 of file twinvqdec.c.

Referenced by twinvq_decode_init().

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 211 of file twinvqdec.c.

Referenced by twinvq_decode_init().

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

Definition at line 239 of file twinvqdec.c.

Referenced by twinvq_read_bitstream().

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

Definition at line 252 of file twinvqdec.c.

Referenced by twinvq_decode_init().

static av_cold int twinvq_decode_init ( AVCodecContext avctx)
static

Definition at line 320 of file twinvqdec.c.

Variable Documentation

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
}
static const uint16_t bark_tab_m08_256[]
Definition: twinvq_data.h:80
int16_t cb0808l0[1088]
Definition: twinvq_data.h:143
static const uint16_t bark_tab_s08_64[]
Definition: twinvq_data.h:110
int16_t fcb08m[320]
Definition: twinvq_data.h:139
int16_t cb0808m1[1024]
Definition: twinvq_data.h:148
int16_t fcb08l[640]
Definition: twinvq_data.h:138
const float ff_metasound_lsp8[]
int16_t cb0808l1[1088]
Definition: twinvq_data.h:144
int16_t shape08[1280]
Definition: twinvq_data.h:141
int16_t cb0808s1[1152]
Definition: twinvq_data.h:146
int16_t cb0808m0[1024]
Definition: twinvq_data.h:147
static const struct twinvq_data tab
static const uint16_t bark_tab_l08_512[]
Definition: twinvq_data.h:41
int16_t cb0808s0[1152]
Definition: twinvq_data.h:145
int16_t fcb08s[320]
Definition: twinvq_data.h:140

Definition at line 33 of file twinvqdec.c.

Referenced by twinvq_decode_init().

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
}
int16_t cb1108l1[1728]
Definition: twinvq_data.h:151
int16_t cb1108m1[1536]
Definition: twinvq_data.h:153
int16_t fcb11l[640]
Definition: twinvq_data.h:157
static const uint16_t bark_tab_s11_64[]
Definition: twinvq_data.h:114
static const uint16_t bark_tab_l11_512[]
Definition: twinvq_data.h:47
int16_t cb1108l0[1728]
Definition: twinvq_data.h:150
int16_t shape11[1280]
Definition: twinvq_data.h:160
static const uint16_t bark_tab_m11_256[]
Definition: twinvq_data.h:85
const float ff_metasound_lsp11[]
int16_t cb1108s1[1856]
Definition: twinvq_data.h:155
int16_t fcb11m[320]
Definition: twinvq_data.h:158
int16_t cb1108m0[1536]
Definition: twinvq_data.h:152
static const struct twinvq_data tab
int16_t fcb11s[320]
Definition: twinvq_data.h:159
int16_t cb1108s0[1856]
Definition: twinvq_data.h:154

Definition at line 42 of file twinvqdec.c.

Referenced by twinvq_decode_init().

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 cb1110s1[1344]
Definition: twinvq_data.h:167
int16_t cb1110l1[1280]
Definition: twinvq_data.h:163
int16_t cb1110s0[1344]
Definition: twinvq_data.h:166
int16_t fcb11l[640]
Definition: twinvq_data.h:157
static const uint16_t bark_tab_s11_64[]
Definition: twinvq_data.h:114
static const uint16_t bark_tab_l11_512[]
Definition: twinvq_data.h:47
int16_t shape11[1280]
Definition: twinvq_data.h:160
static const uint16_t bark_tab_m11_256[]
Definition: twinvq_data.h:85
int16_t cb1110l0[1280]
Definition: twinvq_data.h:162
int16_t cb1110m0[1152]
Definition: twinvq_data.h:164
const float ff_metasound_lsp11[]
int16_t fcb11m[320]
Definition: twinvq_data.h:158
int16_t cb1110m1[1152]
Definition: twinvq_data.h:165
static const struct twinvq_data tab
int16_t fcb11s[320]
Definition: twinvq_data.h:159

Definition at line 51 of file twinvqdec.c.

Referenced by twinvq_decode_init().

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
}
int16_t cb1616l0[1024]
Definition: twinvq_data.h:174
const float ff_metasound_lsp16[]
int16_t cb1616s0[1024]
Definition: twinvq_data.h:178
int16_t fcb16m[320]
Definition: twinvq_data.h:170
int16_t cb1616l1[1024]
Definition: twinvq_data.h:175
int16_t fcb16l[640]
Definition: twinvq_data.h:169
int16_t cb1616m0[960]
Definition: twinvq_data.h:176
static const uint16_t bark_tab_m16_512[]
Definition: twinvq_data.h:90
int16_t fcb16s[320]
Definition: twinvq_data.h:171
int16_t cb1616s1[1024]
Definition: twinvq_data.h:179
static const uint16_t bark_tab_l16_1024[]
Definition: twinvq_data.h:53
int16_t cb1616m1[960]
Definition: twinvq_data.h:177
static const uint16_t bark_tab_s16_128[]
Definition: twinvq_data.h:118
int16_t shape16[1920]
Definition: twinvq_data.h:172
static const struct twinvq_data tab

Definition at line 60 of file twinvqdec.c.

Referenced by twinvq_decode_init().

const TwinVQModeTab mode_22_20
static
Initial value:
= {
{
},
1024, 16, ff_metasound_lsp22, 1, 6, 4, 3, tab.shape22_1, 9, 56, 36, 7, 144
}
const float ff_metasound_lsp22[]
int16_t cb2220m1[1088]
Definition: twinvq_data.h:184
static const uint16_t bark_tab_s22_128[]
Definition: twinvq_data.h:122
static const uint16_t bark_tab_l22_1024[]
Definition: twinvq_data.h:59
int16_t fcb22m_1[640]
Definition: twinvq_data.h:189
int16_t cb2220l1[1152]
Definition: twinvq_data.h:182
int16_t cb2220s0[1152]
Definition: twinvq_data.h:185
static const uint16_t bark_tab_m22_512[]
Definition: twinvq_data.h:100
int16_t cb2220m0[1088]
Definition: twinvq_data.h:183
int16_t fcb22s_1[640]
Definition: twinvq_data.h:190
int16_t cb2220l0[1152]
Definition: twinvq_data.h:181
int16_t shape22_1[1152]
Definition: twinvq_data.h:191
int16_t fcb22l_1[512]
Definition: twinvq_data.h:188
int16_t cb2220s1[1152]
Definition: twinvq_data.h:186
static const struct twinvq_data tab

Definition at line 69 of file twinvqdec.c.

Referenced by twinvq_decode_init().

const TwinVQModeTab mode_22_24
static
Initial value:
= {
{
},
1024, 16, ff_metasound_lsp22, 1, 6, 4, 3, tab.shape22_1, 9, 56, 36, 7, 144
}
const float ff_metasound_lsp22[]
int16_t cb2224s0[960]
Definition: twinvq_data.h:197
static const uint16_t bark_tab_s22_128[]
Definition: twinvq_data.h:122
static const uint16_t bark_tab_l22_1024[]
Definition: twinvq_data.h:59
int16_t fcb22m_1[640]
Definition: twinvq_data.h:189
int16_t cb2224l0[960]
Definition: twinvq_data.h:193
static const uint16_t bark_tab_m22_512[]
Definition: twinvq_data.h:100
int16_t cb2224s1[960]
Definition: twinvq_data.h:198
int16_t fcb22s_1[640]
Definition: twinvq_data.h:190
int16_t cb2224m0[896]
Definition: twinvq_data.h:195
int16_t shape22_1[1152]
Definition: twinvq_data.h:191
int16_t cb2224l1[960]
Definition: twinvq_data.h:194
int16_t fcb22l_1[512]
Definition: twinvq_data.h:188
int16_t cb2224m1[896]
Definition: twinvq_data.h:196
static const struct twinvq_data tab

Definition at line 78 of file twinvqdec.c.

Referenced by twinvq_decode_init().

const TwinVQModeTab mode_22_32
static
Initial value:
= {
{
},
512, 16, tab.lsp22_2, 1, 6, 4, 4, tab.shape22_2, 9, 56, 36, 7, 72
}
int16_t cb2232m0[704]
Definition: twinvq_data.h:208
int16_t cb2232l0[768]
Definition: twinvq_data.h:206
int16_t cb2232s1[704]
Definition: twinvq_data.h:211
int16_t fcb22l_2[512]
Definition: twinvq_data.h:200
int16_t cb2232m1[704]
Definition: twinvq_data.h:209
static const uint16_t bark_tab_s22_128[]
Definition: twinvq_data.h:122
int16_t shape22_2[1152]
Definition: twinvq_data.h:203
int16_t cb2232l1[768]
Definition: twinvq_data.h:207
static const uint16_t bark_tab_m22_256[]
Definition: twinvq_data.h:95
static const uint16_t bark_tab_l22_512[]
Definition: twinvq_data.h:66
int16_t fcb22m_2[640]
Definition: twinvq_data.h:201
float lsp22_2[1312]
Definition: twinvq_data.h:204
int16_t fcb22s_2[640]
Definition: twinvq_data.h:202
static const struct twinvq_data tab
int16_t cb2232s0[704]
Definition: twinvq_data.h:210

Definition at line 87 of file twinvqdec.c.

Referenced by twinvq_decode_init().

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
}
const float ff_metasound_lsp44[]
static const uint16_t bark_tab_m44_512[]
Definition: twinvq_data.h:105
int16_t fcb44l[640]
Definition: twinvq_data.h:220
int16_t cb4440s1[1152]
Definition: twinvq_data.h:218
int16_t cb4440m1[1088]
Definition: twinvq_data.h:216
int16_t fcb44m[640]
Definition: twinvq_data.h:221
static const uint16_t bark_tab_l44_2048[]
Definition: twinvq_data.h:73
int16_t cb4440l0[1088]
Definition: twinvq_data.h:213
static const uint16_t bark_tab_s44_128[]
Definition: twinvq_data.h:126
int16_t fcb44s[640]
Definition: twinvq_data.h:222
int16_t cb4440s0[1152]
Definition: twinvq_data.h:217
int16_t shape44[1152]
Definition: twinvq_data.h:223
int16_t cb4440m0[1088]
Definition: twinvq_data.h:215
int16_t cb4440l1[1088]
Definition: twinvq_data.h:214
static const struct twinvq_data tab

Definition at line 96 of file twinvqdec.c.

Referenced by twinvq_decode_init().

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
}
const float ff_metasound_lsp44[]
static const uint16_t bark_tab_m44_512[]
Definition: twinvq_data.h:105
int16_t fcb44l[640]
Definition: twinvq_data.h:220
int16_t cb4448l1[896]
Definition: twinvq_data.h:226
int16_t fcb44m[640]
Definition: twinvq_data.h:221
int16_t cb4448m0[896]
Definition: twinvq_data.h:227
static const uint16_t bark_tab_l44_2048[]
Definition: twinvq_data.h:73
static const uint16_t bark_tab_s44_128[]
Definition: twinvq_data.h:126
int16_t cb4448s0[960]
Definition: twinvq_data.h:229
int16_t fcb44s[640]
Definition: twinvq_data.h:222
int16_t shape44[1152]
Definition: twinvq_data.h:223
int16_t cb4448m1[896]
Definition: twinvq_data.h:228
int16_t cb4448s1[960]
Definition: twinvq_data.h:230
static const struct twinvq_data tab
int16_t cb4448l0[896]
Definition: twinvq_data.h:225

Definition at line 105 of file twinvqdec.c.

Referenced by twinvq_decode_init().

AVCodec ff_twinvq_decoder
Initial value:
= {
.name = "twinvq",
.long_name = NULL_IF_CONFIG_SMALL("VQF TwinVQ"),
.priv_data_size = sizeof(TwinVQContext),
}
float, planar
Definition: samplefmt.h:69
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
Definition: codec.h:102
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:71
static av_cold int twinvq_decode_init(AVCodecContext *avctx)
Definition: twinvqdec.c:320
av_cold int ff_twinvq_decode_close(AVCodecContext *avctx)
Definition: twinvq.c:741
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:115
int ff_twinvq_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: twinvq.c:476
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:940
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:50

Definition at line 417 of file twinvqdec.c.