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

◆ eval_lpc_spectrum()

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().

◆ eval_lpcenv()

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().

◆ interpolate()

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

◆ get_cos()

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().

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

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

◆ dequant()

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().

◆ dec_gain()

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().

◆ rearrange_lsp()

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().

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

◆ dec_lpc_spectrum_inv()

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().

◆ imdct_and_window()

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().

◆ imdct_output()

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().

◆ read_and_decode_spectrum()

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().

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

◆ init_mdct_win()

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().

◆ permutate_in_line()

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

Referenced by construct_perm_table().

◆ transpose_perm()

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

Referenced by construct_perm_table(), and load_native_model().

◆ linear_perm()

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

Definition at line 631 of file twinvq.c.

Referenced by construct_perm_table().

◆ construct_perm_table()

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

Definition at line 640 of file twinvq.c.

Referenced by init_bitstream_params().

◆ init_bitstream_params()

static av_cold void init_bitstream_params ( TwinVQContext tctx)
static

Definition at line 666 of file twinvq.c.

Referenced by ff_twinvq_decode_init().

◆ ff_twinvq_decode_close()

av_cold int ff_twinvq_decode_close ( AVCodecContext avctx)

Definition at line 741 of file twinvq.c.

Referenced by ff_twinvq_decode_init().

◆ ff_twinvq_decode_init()

av_cold int ff_twinvq_decode_init ( AVCodecContext avctx)

Definition at line 760 of file twinvq.c.

Referenced by metasound_decode_init(), and twinvq_decode_init().

Variable Documentation

◆ wtype_to_wsize

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().

◆ ff_twinvq_wtype_to_ftype_table

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