#include "avcodec.h"
#include "get_bits.h"
#include "dsputil.h"
#include "fft.h"
#include "lsp.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 | 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 |
Typedefs | |
typedef struct TwinContext | TwinContext |
Enumerations | |
enum | FrameType { 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) |
Evaluates 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) |
Evaluates 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 *data_size, AVPacket *avpkt) |
static av_cold void | 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_init (AVCodecContext *avctx) |
static av_cold int | twin_decode_close (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 | twinvq_decoder |
#define AMP_MAX 13000.0 |
Definition at line 208 of file twinvq.c.
Referenced by dec_gain().
#define GAIN_BITS 8 |
Definition at line 207 of file twinvq.c.
Referenced by dec_gain().
#define MULAW_MU 100.0 |
Definition at line 206 of file twinvq.c.
Referenced by dec_gain().
#define PGAIN_MU 200 |
Definition at line 211 of file twinvq.c.
Referenced by read_and_decode_spectrum().
#define PPC_SHAPE_CB_SIZE 64 |
Definition at line 204 of file twinvq.c.
Referenced by read_and_decode_spectrum().
#define SUB_AMP_MAX 4500.0 |
Definition at line 205 of file twinvq.c.
Referenced by dec_gain().
#define SUB_GAIN_BITS 5 |
Definition at line 209 of file twinvq.c.
Referenced by dec_gain(), and init_bitstream_params().
#define WINDOW_TYPE_BITS 4 |
Definition at line 210 of file twinvq.c.
Referenced by init_bitstream_params(), and twin_decode_frame().
typedef struct TwinContext TwinContext |
enum FrameType |
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.
period | the period of the peak divised by 400.0 |
Definition at line 443 of file twinvq.c.
Referenced by decode_ppc().
static av_cold void construct_perm_table | ( | TwinContext * | tctx, | |
enum FrameType | ftype | |||
) | [static] |
Definition at line 965 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 696 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 492 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 580 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 541 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 467 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 352 of file twinvq.c.
Referenced by read_and_decode_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.
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. |
Definition at line 232 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] |
Evaluates the LPC amplitude spectrum envelope from the line spectrum pairs.
Definition at line 257 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 335 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] |
Evaluates 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.
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 301 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 281 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 602 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 657 of file twinvq.c.
Referenced by twin_decode_frame().
static av_cold void init_bitstream_params | ( | TwinContext * | tctx | ) | [static] |
Definition at line 989 of file twinvq.c.
Referenced by twin_decode_init().
static av_cold void init_mdct_win | ( | TwinContext * | tctx | ) | [static] |
Init IMDCT and windowing tables.
Definition at line 861 of file twinvq.c.
Referenced by twin_decode_init().
static void interpolate | ( | float * | out, | |
float | v1, | |||
float | v2, | |||
int | size | |||
) | [static] |
Definition at line 270 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 956 of file twinvq.c.
Referenced by construct_perm_table().
static void memset_float | ( | float * | buf, | |
float | val, | |||
int | size | |||
) | [static] |
Definition at line 214 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 396 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 905 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 723 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 528 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 946 of file twinvq.c.
Referenced by construct_perm_table().
static av_cold int twin_decode_close | ( | AVCodecContext * | avctx | ) | [static] |
static int twin_decode_frame | ( | AVCodecContext * | avctx, | |
void * | data, | |||
int * | data_size, | |||
AVPacket * | avpkt | |||
) | [static] |
static av_cold int twin_decode_init | ( | AVCodecContext * | avctx | ) | [static] |
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; }
Definition at line 422 of file twinvq.c.
Referenced by add_peak().
const ModeTab mode_08_08 [static] |
{ { { 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 }
const ModeTab mode_11_08 [static] |
{ { { 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 }
const ModeTab mode_11_10 [static] |
{ { { 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 }
const ModeTab mode_16_16 [static] |
{ { { 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 }
const ModeTab mode_22_20 [static] |
{ { { 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 }
const ModeTab mode_22_24 [static] |
{ { { 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 }
const ModeTab mode_22_32 [static] |
{ { { 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 }
const ModeTab mode_44_40 [static] |
{ { {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 }
const ModeTab mode_44_48 [static] |
{ { {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 }
{ "twinvq", AVMEDIA_TYPE_AUDIO, CODEC_ID_TWINVQ, sizeof(TwinContext), twin_decode_init, NULL, twin_decode_close, twin_decode_frame, .long_name = NULL_IF_CONFIG_SMALL("VQF TwinVQ"), }