libavcodec/twinvq.c File Reference

#include "avcodec.h"
#include "get_bits.h"
#include "dsputil.h"
#include "fft.h"
#include "lsp.h"
#include "sinewin.h"
#include <math.h>
#include <stdint.h>
#include "twinvq_data.h"

Go to the source code of this file.

Data Structures

struct  FrameMode
 Parameters and tables that are different for each frame type. More...
struct  ModeTab
 Parameters and tables that are different for every combination of bitrate/sample rate. More...
struct  TwinContext

Defines

#define PPC_SHAPE_CB_SIZE   64
#define PPC_SHAPE_LEN_MAX   60
#define SUB_AMP_MAX   4500.0
#define MULAW_MU   100.0
#define GAIN_BITS   8
#define AMP_MAX   13000.0
#define SUB_GAIN_BITS   5
#define WINDOW_TYPE_BITS   4
#define PGAIN_MU   200
#define LSP_COEFS_MAX   20
#define LSP_SPLIT_MAX   4
#define CHANNELS_MAX   2
#define SUBBLOCKS_MAX   16
#define BARK_N_COEF_MAX   4

Enumerations

enum  FrameType {
  ActiveFrame, SIDFrame, UntransmittedFrame, FT_SHORT = 0,
  FT_MEDIUM, FT_LONG, FT_PPC
}

Functions

static void memset_float (float *buf, float val, int size)
static float eval_lpc_spectrum (const float *lsp, float cos_val, int order)
 Evaluate a single LPC amplitude spectrum envelope coefficient from the line spectrum pairs.
static void eval_lpcenv (TwinContext *tctx, const float *cos_vals, float *lpc)
 Evaluate the LPC amplitude spectrum envelope from the line spectrum pairs.
static void interpolate (float *out, float v1, float v2, int size)
static float get_cos (int idx, int part, const float *cos_tab, int size)
static void eval_lpcenv_or_interp (TwinContext *tctx, enum FrameType ftype, float *out, const float *in, int size, int step, int part)
 Evaluate the LPC amplitude spectrum envelope from the line spectrum pairs.
static void eval_lpcenv_2parts (TwinContext *tctx, enum FrameType ftype, const float *buf, float *lpc, int size, int step)
static void dequant (TwinContext *tctx, GetBitContext *gb, float *out, enum FrameType ftype, const int16_t *cb0, const int16_t *cb1, int cb_len)
 Inverse quantization.
static float mulawinv (float y, float clip, float mu)
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 (TwinContext *tctx, int period_coef, const float *shape, float ppc_gain, float *speech)
static void dec_gain (TwinContext *tctx, GetBitContext *gb, enum FrameType ftype, float *out)
static void rearrange_lsp (int order, float *lsp, float min_dist)
 Rearrange the LSP coefficients so that they have a minimum distance of min_dist.
static void decode_lsp (TwinContext *tctx, int lpc_idx1, uint8_t *lpc_idx2, int lpc_hist_idx, float *lsp, float *hist)
static void dec_lpc_spectrum_inv (TwinContext *tctx, float *lsp, enum FrameType ftype, float *lpc)
static void imdct_and_window (TwinContext *tctx, enum FrameType ftype, int wtype, float *in, float *prev, int ch)
static void imdct_output (TwinContext *tctx, enum FrameType ftype, int wtype, float *out)
static void dec_bark_env (TwinContext *tctx, const uint8_t *in, int use_hist, int ch, float *out, float gain, enum FrameType ftype)
static void read_and_decode_spectrum (TwinContext *tctx, GetBitContext *gb, float *out, enum FrameType ftype)
static int twin_decode_frame (AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
static av_cold int init_mdct_win (TwinContext *tctx)
 Init IMDCT and windowing tables.
static void permutate_in_line (int16_t *tab, int num_vect, int num_blocks, int block_size, const uint8_t line_len[2], int length_div, enum FrameType ftype)
 Interpret the data as if it were a num_blocks x line_len[0] matrix and for each line do a cyclic permutation, i.e.
static void transpose_perm (int16_t *out, int16_t *in, int num_vect, const uint8_t line_len[2], int length_div)
 Interpret the input data as in the following table:.
static void linear_perm (int16_t *out, int16_t *in, int n_blocks, int size)
static av_cold void construct_perm_table (TwinContext *tctx, enum FrameType ftype)
static av_cold void init_bitstream_params (TwinContext *tctx)
static av_cold int twin_decode_close (AVCodecContext *avctx)
static av_cold int twin_decode_init (AVCodecContext *avctx)

Variables

static const ModeTab mode_08_08
static const ModeTab mode_11_08
static const ModeTab mode_11_10
static const ModeTab mode_16_16
static const ModeTab mode_22_20
static const ModeTab mode_22_24
static const ModeTab mode_22_32
static const ModeTab mode_44_40
static const ModeTab mode_44_48
AVCodec ff_twinvq_decoder


Define Documentation

#define AMP_MAX   13000.0

Definition at line 212 of file twinvq.c.

Referenced by dec_gain().

#define BARK_N_COEF_MAX   4

Definition at line 220 of file twinvq.c.

Referenced by read_and_decode_spectrum().

#define CHANNELS_MAX   2

Definition at line 218 of file twinvq.c.

Referenced by read_and_decode_spectrum(), and twin_decode_init().

#define GAIN_BITS   8

Definition at line 211 of file twinvq.c.

Referenced by dec_gain(), and init_bitstream_params().

#define LSP_COEFS_MAX   20

Definition at line 216 of file twinvq.c.

Referenced by read_and_decode_spectrum().

#define LSP_SPLIT_MAX   4

Definition at line 217 of file twinvq.c.

Referenced by read_and_decode_spectrum().

#define MULAW_MU   100.0

Definition at line 210 of file twinvq.c.

Referenced by dec_gain().

#define PGAIN_MU   200

Definition at line 215 of file twinvq.c.

Referenced by read_and_decode_spectrum().

#define PPC_SHAPE_CB_SIZE   64

Definition at line 207 of file twinvq.c.

Referenced by read_and_decode_spectrum().

#define PPC_SHAPE_LEN_MAX   60

Definition at line 208 of file twinvq.c.

Referenced by read_and_decode_spectrum().

#define SUB_AMP_MAX   4500.0

Definition at line 209 of file twinvq.c.

Referenced by dec_gain().

#define SUB_GAIN_BITS   5

Definition at line 213 of file twinvq.c.

Referenced by dec_gain(), and init_bitstream_params().

#define SUBBLOCKS_MAX   16

Definition at line 219 of file twinvq.c.

Referenced by read_and_decode_spectrum().

#define WINDOW_TYPE_BITS   4

Definition at line 214 of file twinvq.c.

Referenced by init_bitstream_params(), and twin_decode_frame().


Enumeration Type Documentation

enum FrameType

Enumerator:
ActiveFrame  Active speech.
SIDFrame  Silence Insertion Descriptor frame.
UntransmittedFrame 
FT_SHORT  Short frame (divided in n sub-blocks).
FT_MEDIUM  Medium frame (divided in m<n sub-blocks).
FT_LONG  Long frame (single sub-block + PPC).
FT_PPC  Periodic Peak Component (part of the long frame).

Definition at line 34 of file twinvq.c.


Function Documentation

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:
period the period of the peak divised by 400.0

Definition at line 452 of file twinvq.c.

Referenced by decode_ppc().

static av_cold void construct_perm_table ( TwinContext tctx,
enum FrameType  ftype 
) [static]

Definition at line 999 of file twinvq.c.

Referenced by init_bitstream_params().

static void dec_bark_env ( TwinContext tctx,
const uint8_t in,
int  use_hist,
int  ch,
float *  out,
float  gain,
enum FrameType  ftype 
) [static]

Definition at line 706 of file twinvq.c.

Referenced by read_and_decode_spectrum().

static void dec_gain ( TwinContext tctx,
GetBitContext gb,
enum FrameType  ftype,
float *  out 
) [static]

Definition at line 501 of file twinvq.c.

Referenced by read_and_decode_spectrum().

static void dec_lpc_spectrum_inv ( TwinContext tctx,
float *  lsp,
enum FrameType  ftype,
float *  lpc 
) [static]

Definition at line 589 of file twinvq.c.

Referenced by read_and_decode_spectrum().

static void decode_lsp ( TwinContext tctx,
int  lpc_idx1,
uint8_t lpc_idx2,
int  lpc_hist_idx,
float *  lsp,
float *  hist 
) [static]

Definition at line 550 of file twinvq.c.

Referenced by read_and_decode_spectrum().

static void decode_ppc ( TwinContext tctx,
int  period_coef,
const float *  shape,
float  ppc_gain,
float *  speech 
) [static]

Definition at line 476 of file twinvq.c.

Referenced by read_and_decode_spectrum().

static void dequant ( TwinContext tctx,
GetBitContext gb,
float *  out,
enum FrameType  ftype,
const int16_t cb0,
const int16_t cb1,
int  cb_len 
) [static]

Inverse quantization.

Read CB coefficients for cb1 and cb2 from the bitstream, sum the corresponding vectors and write the result to *out after permutation.

Definition at line 361 of file twinvq.c.

static float eval_lpc_spectrum ( const float *  lsp,
float  cos_val,
int  order 
) [static]

Evaluate a single LPC amplitude spectrum envelope coefficient from the line spectrum pairs.

Parameters:
lsp a vector of the cosinus of the LSP values
cos_val cos(PI*i/N) where i is the index of the LPC amplitude
order the order of the LSP (and the size of the *lsp buffer). Must be a multiple of four.
Returns:
the LPC value
Todo:
reuse code from Vorbis decoder: vorbis_floor0_decode

Definition at line 241 of file twinvq.c.

Referenced by eval_lpcenv(), and eval_lpcenv_or_interp().

static void eval_lpcenv ( TwinContext tctx,
const float *  cos_vals,
float *  lpc 
) [static]

Evaluate the LPC amplitude spectrum envelope from the line spectrum pairs.

Definition at line 266 of file twinvq.c.

Referenced by dec_lpc_spectrum_inv().

static void eval_lpcenv_2parts ( TwinContext tctx,
enum FrameType  ftype,
const float *  buf,
float *  lpc,
int  size,
int  step 
) [static]

Definition at line 344 of file twinvq.c.

Referenced by dec_lpc_spectrum_inv().

static void eval_lpcenv_or_interp ( TwinContext tctx,
enum FrameType  ftype,
float *  out,
const float *  in,
int  size,
int  step,
int  part 
) [inline, static]

Evaluate the LPC amplitude spectrum envelope from the line spectrum pairs.

Probably for speed reasons, the coefficients are evaluated as siiiibiiiisiiiibiiiisiiiibiiiisiiiibiiiis ... where s is an evaluated value, i is a value interpolated from the others and b might be either calculated or interpolated, depending on an unexplained condition.

Parameters:
step the size of a block "siiiibiiii"
in the cosinus of the LSP data
part is 0 for 0...PI (positive cossinus values) and 1 for PI...2PI (negative cossinus values)
size the size of the whole output

Definition at line 310 of file twinvq.c.

Referenced by eval_lpcenv_2parts().

static float get_cos ( int  idx,
int  part,
const float *  cos_tab,
int  size 
) [inline, static]

Definition at line 290 of file twinvq.c.

Referenced by eval_lpcenv_or_interp().

static void imdct_and_window ( TwinContext tctx,
enum FrameType  ftype,
int  wtype,
float *  in,
float *  prev,
int  ch 
) [static]

Definition at line 611 of file twinvq.c.

Referenced by imdct_output().

static void imdct_output ( TwinContext tctx,
enum FrameType  ftype,
int  wtype,
float *  out 
) [static]

Definition at line 666 of file twinvq.c.

Referenced by twin_decode_frame().

static av_cold void init_bitstream_params ( TwinContext tctx  )  [static]

Definition at line 1025 of file twinvq.c.

Referenced by twin_decode_init().

static av_cold int init_mdct_win ( TwinContext tctx  )  [static]

Init IMDCT and windowing tables.

Definition at line 882 of file twinvq.c.

Referenced by twin_decode_init().

static void interpolate ( float *  out,
float  v1,
float  v2,
int  size 
) [static]

Definition at line 279 of file twinvq.c.

Referenced by eval_lpcenv_2parts(), and eval_lpcenv_or_interp().

static void linear_perm ( int16_t out,
int16_t in,
int  n_blocks,
int  size 
) [static]

Definition at line 990 of file twinvq.c.

Referenced by construct_perm_table().

static void memset_float ( float *  buf,
float  val,
int  size 
) [static]

Note:
not speed critical, hence not optimized

Definition at line 223 of file twinvq.c.

Referenced by dec_bark_env(), eval_lpcenv_2parts(), and twin_decode_init().

static float mulawinv ( float  y,
float  clip,
float  mu 
) [inline, static]

Definition at line 405 of file twinvq.c.

Referenced by dec_gain(), and read_and_decode_spectrum().

static void permutate_in_line ( int16_t tab,
int  num_vect,
int  num_blocks,
int  block_size,
const uint8_t  line_len[2],
int  length_div,
enum FrameType  ftype 
) [static]

Interpret the data as if it were a num_blocks x line_len[0] matrix and for each line do a cyclic permutation, i.e.

abcdefghijklm -> defghijklmabc where the amount to be shifted is evaluated depending on the column.

Definition at line 939 of file twinvq.c.

Referenced by construct_perm_table().

static void read_and_decode_spectrum ( TwinContext tctx,
GetBitContext gb,
float *  out,
enum FrameType  ftype 
) [static]

Definition at line 733 of file twinvq.c.

Referenced by twin_decode_frame().

static void rearrange_lsp ( int  order,
float *  lsp,
float  min_dist 
) [static]

Rearrange the LSP coefficients so that they have a minimum distance of min_dist.

This function does it exactly as described in section of 3.2.4 of the G.729 specification (but interestingly is different from what the reference decoder actually does).

Definition at line 537 of file twinvq.c.

Referenced by decode_lsp().

static void transpose_perm ( int16_t out,
int16_t in,
int  num_vect,
const uint8_t  line_len[2],
int  length_div 
) [static]

Interpret the input data as in the following table:.

 *
 * abcdefgh
 * ijklmnop
 * qrstuvw
 * x123456
 *
 * 

and transpose it, giving the output aiqxbjr1cks2dlt3emu4fvn5gow6hp

Definition at line 980 of file twinvq.c.

Referenced by construct_perm_table().

static av_cold int twin_decode_close ( AVCodecContext avctx  )  [static]

Definition at line 1094 of file twinvq.c.

Referenced by twin_decode_init().

static int twin_decode_frame ( AVCodecContext avctx,
void *  data,
int *  got_frame_ptr,
AVPacket avpkt 
) [static]

Definition at line 818 of file twinvq.c.

static av_cold int twin_decode_init ( AVCodecContext avctx  )  [static]

Definition at line 1113 of file twinvq.c.

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.;
    return b * test +  0.5;
 }

Note:
if this function is replaced by just ROUNDED_DIV(a*b,400.), 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 431 of file twinvq.c.

Referenced by add_peak().


Variable Documentation

Initial value:

 {
    .name           = "twinvq",
    .type           = AVMEDIA_TYPE_AUDIO,
    .id             = CODEC_ID_TWINVQ,
    .priv_data_size = sizeof(TwinContext),
    .init           = twin_decode_init,
    .close          = twin_decode_close,
    .decode         = twin_decode_frame,
    .capabilities   = CODEC_CAP_DR1,
    .long_name      = NULL_IF_CONFIG_SMALL("VQF TwinVQ"),
}

Definition at line 1174 of file twinvq.c.

const ModeTab 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, tab.lsp08,   1, 5, 3, 3, tab.shape08  , 8, 28, 20, 6, 40
}

Definition at line 94 of file twinvq.c.

const ModeTab 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, tab.lsp11,   1, 6, 4, 3, tab.shape11  , 9, 36, 30, 7, 90
}

Definition at line 103 of file twinvq.c.

const ModeTab 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, tab.lsp11,   1, 6, 4, 3, tab.shape11  , 9, 36, 30, 7, 90
}

Definition at line 112 of file twinvq.c.

const ModeTab 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, tab.lsp16,   1, 6, 4, 3, tab.shape16  , 9, 56, 60, 7, 180
}

Definition at line 121 of file twinvq.c.

const ModeTab 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, tab.lsp22_1, 1, 6, 4, 3, tab.shape22_1, 9, 56, 36, 7, 144
}

Definition at line 130 of file twinvq.c.

const ModeTab 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, tab.lsp22_1, 1, 6, 4, 3, tab.shape22_1, 9, 56, 36, 7, 144
}

Definition at line 139 of file twinvq.c.

const ModeTab 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 148 of file twinvq.c.

const ModeTab 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, tab.lsp44,   1, 6, 4, 4, tab.shape44  , 9, 84, 54, 7, 432
}

Definition at line 157 of file twinvq.c.

const ModeTab 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, tab.lsp44,   1, 6, 4, 4, tab.shape44  , 9, 84, 54, 7, 432
}

Definition at line 166 of file twinvq.c.


Generated on Fri Oct 26 02:47:59 2012 for FFmpeg by  doxygen 1.5.8