FFmpeg
Functions | Variables
twinvq.c File Reference
#include <math.h>
#include <stdint.h>
#include "libavutil/channel_layout.h"
#include "libavutil/float_dsp.h"
#include "avcodec.h"
#include "fft.h"
#include "internal.h"
#include "lsp.h"
#include "sinewin.h"
#include "twinvq.h"

Go to the source code of this file.

Functions

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. More...
 
static void eval_lpcenv (TwinVQContext *tctx, const float *cos_vals, float *lpc)
 Evaluate the LPC amplitude spectrum envelope from the line spectrum pairs. More...
 
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 (TwinVQContext *tctx, enum TwinVQFrameType ftype, float *out, const float *in, int size, int step, int part)
 Evaluate the LPC amplitude spectrum envelope from the line spectrum pairs. More...
 
static void eval_lpcenv_2parts (TwinVQContext *tctx, enum TwinVQFrameType ftype, const float *buf, float *lpc, int size, int step)
 
static void dequant (TwinVQContext *tctx, const uint8_t *cb_bits, float *out, enum TwinVQFrameType ftype, const int16_t *cb0, const int16_t *cb1, int cb_len)
 Inverse quantization. More...
 
static void dec_gain (TwinVQContext *tctx, enum TwinVQFrameType 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. More...
 
static void decode_lsp (TwinVQContext *tctx, int lpc_idx1, uint8_t *lpc_idx2, int lpc_hist_idx, float *lsp, float *hist)
 
static void dec_lpc_spectrum_inv (TwinVQContext *tctx, float *lsp, enum TwinVQFrameType ftype, float *lpc)
 
static void imdct_and_window (TwinVQContext *tctx, enum TwinVQFrameType ftype, int wtype, float *in, float *prev, int ch)
 
static void imdct_output (TwinVQContext *tctx, enum TwinVQFrameType ftype, int wtype, float **out, int offset)
 
static void read_and_decode_spectrum (TwinVQContext *tctx, float *out, enum TwinVQFrameType ftype)
 
int ff_twinvq_decode_frame (AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
 
static av_cold int init_mdct_win (TwinVQContext *tctx)
 Init IMDCT and windowing tables. More...
 
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 TwinVQFrameType 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. More...
 
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: More...
 
static void linear_perm (int16_t *out, int16_t *in, int n_blocks, int size)
 
static av_cold void construct_perm_table (TwinVQContext *tctx, enum TwinVQFrameType ftype)
 
static av_cold void init_bitstream_params (TwinVQContext *tctx)
 
av_cold int ff_twinvq_decode_close (AVCodecContext *avctx)
 
av_cold int ff_twinvq_decode_init (AVCodecContext *avctx)
 

Variables

static const uint8_t wtype_to_wsize [] = { 0, 0, 2, 2, 2, 1, 0, 1, 1 }
 
enum TwinVQFrameType ff_twinvq_wtype_to_ftype_table []
 

Function Documentation

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
lspa vector of the cosine of the LSP values
cos_valcos(PI*i/N) where i is the index of the LPC amplitude
orderthe 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 46 of file twinvq.c.

Referenced by eval_lpcenv(), and eval_lpcenv_or_interp().

static void eval_lpcenv ( TwinVQContext tctx,
const float *  cos_vals,
float *  lpc 
)
static

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

Definition at line 71 of file twinvq.c.

Referenced by dec_lpc_spectrum_inv().

static void interpolate ( float *  out,
float  v1,
float  v2,
int  size 
)
static
static float get_cos ( int  idx,
int  part,
const float *  cos_tab,
int  size 
)
inlinestatic

Definition at line 95 of file twinvq.c.

Referenced by eval_lpcenv_or_interp().

static void eval_lpcenv_or_interp ( TwinVQContext tctx,
enum TwinVQFrameType  ftype,
float *  out,
const float *  in,
int  size,
int  step,
int  part 
)
inlinestatic

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
stepthe size of a block "siiiibiiii"
inthe cosine of the LSP data
partis 0 for 0...PI (positive cosine values) and 1 for PI...2PI (negative cosine values)
sizethe size of the whole output

Definition at line 115 of file twinvq.c.

Referenced by eval_lpcenv_2parts().

static void eval_lpcenv_2parts ( TwinVQContext tctx,
enum TwinVQFrameType  ftype,
const float *  buf,
float *  lpc,
int  size,
int  step 
)
static

Definition at line 152 of file twinvq.c.

Referenced by dec_lpc_spectrum_inv().

static void dequant ( TwinVQContext tctx,
const uint8_t cb_bits,
float *  out,
enum TwinVQFrameType  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 172 of file twinvq.c.

Referenced by read_and_decode_spectrum().

static void dec_gain ( TwinVQContext tctx,
enum TwinVQFrameType  ftype,
float *  out 
)
static

Definition at line 214 of file twinvq.c.

Referenced by read_and_decode_spectrum().

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 250 of file twinvq.c.

Referenced by decode_lsp().

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

Definition at line 263 of file twinvq.c.

Referenced by read_and_decode_spectrum().

static void dec_lpc_spectrum_inv ( TwinVQContext tctx,
float *  lsp,
enum TwinVQFrameType  ftype,
float *  lpc 
)
static

Definition at line 303 of file twinvq.c.

Referenced by read_and_decode_spectrum().

static void imdct_and_window ( TwinVQContext tctx,
enum TwinVQFrameType  ftype,
int  wtype,
float *  in,
float *  prev,
int  ch 
)
static

Definition at line 327 of file twinvq.c.

Referenced by imdct_output(), and spectral_to_sample().

static void imdct_output ( TwinVQContext tctx,
enum TwinVQFrameType  ftype,
int  wtype,
float **  out,
int  offset 
)
static

Definition at line 378 of file twinvq.c.

Referenced by ff_twinvq_decode_frame().

static void read_and_decode_spectrum ( TwinVQContext tctx,
float *  out,
enum TwinVQFrameType  ftype 
)
static

Definition at line 412 of file twinvq.c.

Referenced by ff_twinvq_decode_frame().

int ff_twinvq_decode_frame ( AVCodecContext avctx,
void data,
int got_frame_ptr,
AVPacket avpkt 
)

Definition at line 476 of file twinvq.c.

Referenced by twinvq_mulawinv().

static av_cold int init_mdct_win ( TwinVQContext tctx)
static

Init IMDCT and windowing tables.

Definition at line 533 of file twinvq.c.

Referenced by ff_twinvq_decode_init().

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 TwinVQFrameType  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 590 of file twinvq.c.

Referenced by construct_perm_table().

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 630 of file twinvq.c.

Referenced by construct_perm_table(), and load_native_model().

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

Definition at line 641 of file twinvq.c.

Referenced by construct_perm_table().

static av_cold void construct_perm_table ( TwinVQContext tctx,
enum TwinVQFrameType  ftype 
)
static

Definition at line 650 of file twinvq.c.

Referenced by init_bitstream_params().

static av_cold void init_bitstream_params ( TwinVQContext tctx)
static

Definition at line 676 of file twinvq.c.

Referenced by ff_twinvq_decode_init().

av_cold int ff_twinvq_decode_close ( AVCodecContext avctx)

Definition at line 751 of file twinvq.c.

Referenced by ff_twinvq_decode_init(), and twinvq_mulawinv().

av_cold int ff_twinvq_decode_init ( AVCodecContext avctx)

Definition at line 770 of file twinvq.c.

Referenced by metasound_decode_init(), twinvq_decode_init(), and twinvq_mulawinv().

Variable Documentation

const uint8_t wtype_to_wsize[] = { 0, 0, 2, 2, 2, 1, 0, 1, 1 }
static

Definition at line 325 of file twinvq.c.

Referenced by imdct_and_window().

enum TwinVQFrameType ff_twinvq_wtype_to_ftype_table[]
Initial value:
= {
TWINVQ_FT_MEDIUM
}
Medium frame (divided in m<n sub-blocks)
Definition: twinvq.h:41
Short frame (divided in n sub-blocks)
Definition: twinvq.h:40
Long frame (single sub-block + PPC)
Definition: twinvq.h:42

Definition at line 470 of file twinvq.c.

Referenced by metasound_read_bitstream(), and twinvq_read_bitstream().