FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
g729dec.c File Reference
#include <inttypes.h>
#include <string.h>
#include "avcodec.h"
#include "libavutil/avutil.h"
#include "get_bits.h"
#include "audiodsp.h"
#include "internal.h"
#include "g729.h"
#include "lsp.h"
#include "celp_math.h"
#include "celp_filters.h"
#include "acelp_filters.h"
#include "acelp_pitch_delay.h"
#include "acelp_vectors.h"
#include "g729data.h"
#include "g729postfilter.h"

Go to the source code of this file.

Data Structures

struct  G729FormatDescription
 
struct  G729ChannelContext
 
struct  G729Context
 

Macros

#define LSFQ_MIN   40
 minimum quantized LSF value (3.2.4) 0.005 in Q13 More...
 
#define LSFQ_MAX   25681
 maximum quantized LSF value (3.2.4) 3.135 in Q13 More...
 
#define LSFQ_DIFF_MIN   321
 minimum LSF distance (3.2.4) 0.0391 in Q13 More...
 
#define INTERPOL_LEN   11
 interpolation filter length More...
 
#define SHARP_MIN   3277
 minimum gain pitch value (3.8, Equation 47) 0.2 in (1.14) More...
 
#define SHARP_MAX   13017
 maximum gain pitch value (3.8, Equation 47) (EE) This does not comply with the specification. More...
 
#define MR_ENERGY   1018156
 MR_ENERGY (mean removed energy) = mean_energy + 10 * log10(2^26 * subframe_size) in (7.13) More...
 
#define DECISION_NOISE   0
 
#define DECISION_INTERMEDIATE   1
 
#define DECISION_VOICE   2
 

Enumerations

enum  G729Formats { FORMAT_G729_8K = 0, FORMAT_G729D_6K4, FORMAT_COUNT }
 

Functions

static uint16_t g729_prng (uint16_t value)
 pseudo random number generator More...
 
static void lsf_decode (int16_t *lsfq, int16_t *past_quantizer_outputs[MA_NP+1], int16_t ma_predictor, int16_t vq_1st, int16_t vq_2nd_low, int16_t vq_2nd_high)
 Decodes LSF (Line Spectral Frequencies) from L0-L3 (3.2.4). More...
 
static void lsf_restore_from_previous (int16_t *lsfq, int16_t *past_quantizer_outputs[MA_NP+1], int ma_predictor_prev)
 Restores past LSP quantizer output using LSF from previous frame. More...
 
static void g729d_get_new_exc (int16_t *out, const int16_t *in, const int16_t *fc_cur, int dstate, int gain_code, int subframe_size)
 Constructs new excitation signal and applies phase filter to it. More...
 
static int g729d_onset_decision (int past_onset, const int16_t *past_gain_code)
 Makes decision about onset in current subframe. More...
 
static int16_t g729d_voice_decision (int onset, int prev_voice_decision, const int16_t *past_gain_pitch)
 Makes decision about voice presence in current subframe. More...
 
static int32_t scalarproduct_int16_c (const int16_t *v1, const int16_t *v2, int order)
 
static av_cold int decoder_init (AVCodecContext *avctx)
 
static int decode_frame (AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
 
static av_cold int decode_close (AVCodecContext *avctx)
 

Variables

static const G729FormatDescription format_g729_8k
 
static const G729FormatDescription format_g729d_6k4
 
const AVCodec ff_g729_decoder
 
const AVCodec ff_acelp_kelvin_decoder
 

Macro Definition Documentation

◆ LSFQ_MIN

#define LSFQ_MIN   40

minimum quantized LSF value (3.2.4) 0.005 in Q13

Definition at line 46 of file g729dec.c.

◆ LSFQ_MAX

#define LSFQ_MAX   25681

maximum quantized LSF value (3.2.4) 3.135 in Q13

Definition at line 52 of file g729dec.c.

◆ LSFQ_DIFF_MIN

#define LSFQ_DIFF_MIN   321

minimum LSF distance (3.2.4) 0.0391 in Q13

Definition at line 58 of file g729dec.c.

◆ INTERPOL_LEN

#define INTERPOL_LEN   11

interpolation filter length

Definition at line 61 of file g729dec.c.

◆ SHARP_MIN

#define SHARP_MIN   3277

minimum gain pitch value (3.8, Equation 47) 0.2 in (1.14)

Definition at line 67 of file g729dec.c.

◆ SHARP_MAX

#define SHARP_MAX   13017

maximum gain pitch value (3.8, Equation 47) (EE) This does not comply with the specification.

Specification says about 0.8, which should be 13107 in (1.14), but reference C code uses 13017 (equals to 0.7945) instead of it.

Definition at line 76 of file g729dec.c.

◆ MR_ENERGY

#define MR_ENERGY   1018156

MR_ENERGY (mean removed energy) = mean_energy + 10 * log10(2^26 * subframe_size) in (7.13)

Definition at line 81 of file g729dec.c.

◆ DECISION_NOISE

#define DECISION_NOISE   0

Definition at line 83 of file g729dec.c.

◆ DECISION_INTERMEDIATE

#define DECISION_INTERMEDIATE   1

Definition at line 84 of file g729dec.c.

◆ DECISION_VOICE

#define DECISION_VOICE   2

Definition at line 85 of file g729dec.c.

Enumeration Type Documentation

◆ G729Formats

Enumerator
FORMAT_G729_8K 
FORMAT_G729D_6K4 
FORMAT_COUNT 

Definition at line 87 of file g729dec.c.

Function Documentation

◆ g729_prng()

static uint16_t g729_prng ( uint16_t  value)
inlinestatic

pseudo random number generator

Definition at line 185 of file g729dec.c.

Referenced by decode_frame().

◆ lsf_decode()

static void lsf_decode ( int16_t *  lsfq,
int16_t *  past_quantizer_outputs[MA_NP+1],
int16_t  ma_predictor,
int16_t  vq_1st,
int16_t  vq_2nd_low,
int16_t  vq_2nd_high 
)
static

Decodes LSF (Line Spectral Frequencies) from L0-L3 (3.2.4).

Parameters
[out]lsfq(2.13) quantized LSF coefficients
[in,out]past_quantizer_outputs(2.13) quantizer outputs from previous frames
ma_predictorswitched MA predictor of LSP quantizer
vq_1stfirst stage vector of quantizer
vq_2nd_lowsecond stage lower vector of LSP quantizer
vq_2nd_highsecond stage higher vector of LSP quantizer

Definition at line 199 of file g729dec.c.

Referenced by decode_frame().

◆ lsf_restore_from_previous()

static void lsf_restore_from_previous ( int16_t *  lsfq,
int16_t *  past_quantizer_outputs[MA_NP+1],
int  ma_predictor_prev 
)
static

Restores past LSP quantizer output using LSF from previous frame.

Parameters
[in,out]lsfq(2.13) quantized LSF coefficients
[in,out]past_quantizer_outputs(2.13) quantizer outputs from previous frames
ma_predictor_prevMA predictor from previous frame
lsfq_prev(2.13) quantized LSF coefficients from previous frame

Definition at line 240 of file g729dec.c.

Referenced by decode_frame().

◆ g729d_get_new_exc()

static void g729d_get_new_exc ( int16_t *  out,
const int16_t *  in,
const int16_t *  fc_cur,
int  dstate,
int  gain_code,
int  subframe_size 
)
static

Constructs new excitation signal and applies phase filter to it.

Parameters
[out]outconstructed speech signal
inoriginal excitation signal
fc_cur(2.13) original fixed-codebook vector
gain_code(14.1) gain code
subframe_sizelength of the subframe

Definition at line 265 of file g729dec.c.

Referenced by decode_frame().

◆ g729d_onset_decision()

static int g729d_onset_decision ( int  past_onset,
const int16_t *  past_gain_code 
)
static

Makes decision about onset in current subframe.

Parameters
past_onsetdecision result of previous subframe
past_gain_codegain code of current and previous subframe
Returns
onset decision result for current subframe

Definition at line 292 of file g729dec.c.

Referenced by decode_frame().

◆ g729d_voice_decision()

static int16_t g729d_voice_decision ( int  onset,
int  prev_voice_decision,
const int16_t *  past_gain_pitch 
)
static

Makes decision about voice presence in current subframe.

Parameters
onsetonset level
prev_voice_decisionvoice decision result from previous subframe
past_gain_pitchpitch gain of current and previous subframes
Returns
voice decision result for current subframe

Definition at line 308 of file g729dec.c.

Referenced by decode_frame().

◆ scalarproduct_int16_c()

static int32_t scalarproduct_int16_c ( const int16_t *  v1,
const int16_t *  v2,
int  order 
)
static

Definition at line 336 of file g729dec.c.

Referenced by decoder_init().

◆ decoder_init()

static av_cold int decoder_init ( AVCodecContext avctx)
static

Definition at line 349 of file g729dec.c.

◆ decode_frame()

static int decode_frame ( AVCodecContext avctx,
void *  data,
int got_frame_ptr,
AVPacket avpkt 
)
static

< switched MA predictor of LSP quantizer

< first stage vector of quantizer

< second stage lower vector of quantizer (size in bits)

< second stage higher vector of quantizer (size in bits)

< frame erasure detected during decoding

< parity check failed

< whether one of the subframes is declared as periodic or not

< adaptive codebook index

< fixed-codebook vector pulse signs

< fixed-codebook indexes

< gain codebook (first stage) index

< gain codebook (second stage) index

Definition at line 402 of file g729dec.c.

◆ decode_close()

static av_cold int decode_close ( AVCodecContext avctx)
static

Definition at line 745 of file g729dec.c.

Variable Documentation

◆ format_g729_8k

const G729FormatDescription format_g729_8k
static
Initial value:
= {
.ac_index_bits = {8,5},
.parity_bit = 1,
.gc_1st_index_bits = GC_1ST_IDX_BITS_8K,
.gc_2nd_index_bits = GC_2ND_IDX_BITS_8K,
.fc_signs_bits = 4,
.fc_indexes_bits = 13,
.block_size = G729_8K_BLOCK_SIZE,
}

Definition at line 162 of file g729dec.c.

Referenced by decode_frame().

◆ format_g729d_6k4

const G729FormatDescription format_g729d_6k4
static
Initial value:
= {
.ac_index_bits = {8,4},
.parity_bit = 0,
.gc_1st_index_bits = GC_1ST_IDX_BITS_6K4,
.gc_2nd_index_bits = GC_2ND_IDX_BITS_6K4,
.fc_signs_bits = 2,
.fc_indexes_bits = 9,
.block_size = G729D_6K4_BLOCK_SIZE,
}

Definition at line 172 of file g729dec.c.

Referenced by decode_frame().

◆ ff_g729_decoder

const AVCodec ff_g729_decoder
Initial value:
= {
.name = "g729",
.long_name = NULL_IF_CONFIG_SMALL("G.729"),
.priv_data_size = sizeof(G729Context),
.close = decode_close,
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
}

Definition at line 753 of file g729dec.c.

◆ ff_acelp_kelvin_decoder

const AVCodec ff_acelp_kelvin_decoder
Initial value:
= {
.name = "acelp.kelvin",
.long_name = NULL_IF_CONFIG_SMALL("Sipro ACELP.KELVIN"),
.priv_data_size = sizeof(G729Context),
.close = decode_close,
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
}

Definition at line 766 of file g729dec.c.

G729_8K_BLOCK_SIZE
#define G729_8K_BLOCK_SIZE
Definition: g729.h:30
FF_CODEC_CAP_INIT_THREADSAFE
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: internal.h:42
decode_close
static av_cold int decode_close(AVCodecContext *avctx)
Definition: g729dec.c:745
init
static int init
Definition: av_tx.c:47
GC_1ST_IDX_BITS_8K
#define GC_1ST_IDX_BITS_8K
gain codebook (first stage) index, 8k mode (size in bits)
Definition: g729data.h:32
G729Context
Definition: g729dec.c:156
decode
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:71
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
decode_frame
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: g729dec.c:402
GC_2ND_IDX_BITS_8K
#define GC_2ND_IDX_BITS_8K
gain codebook (second stage) index, 8k mode (size in bits)
Definition: g729data.h:33
AV_CODEC_ID_ACELP_KELVIN
@ AV_CODEC_ID_ACELP_KELVIN
Definition: codec_id.h:513
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
decoder_init
static av_cold int decoder_init(AVCodecContext *avctx)
Definition: g729dec.c:349
AV_CODEC_ID_G729
@ AV_CODEC_ID_G729
Definition: codec_id.h:476
AV_CODEC_CAP_SUBFRAMES
#define AV_CODEC_CAP_SUBFRAMES
Codec can output multiple frames per AVPacket Normally demuxers return one frame at a time,...
Definition: codec.h:100
G729D_6K4_BLOCK_SIZE
#define G729D_6K4_BLOCK_SIZE
Definition: g729.h:31
GC_2ND_IDX_BITS_6K4
#define GC_2ND_IDX_BITS_6K4
gain codebook (second stage) index, 6.4k mode (size in bits)
Definition: g729data.h:36
GC_1ST_IDX_BITS_6K4
#define GC_1ST_IDX_BITS_6K4
gain codebook (first stage) index, 6.4k mode (size in bits)
Definition: g729data.h:35