FFmpeg
Macros | Functions | Variables
g723_1enc.c File Reference
#include <stdint.h>
#include <string.h>
#include "libavutil/channel_layout.h"
#include "libavutil/common.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "avcodec.h"
#include "celp_math.h"
#include "g723_1.h"
#include "internal.h"
#include "put_bits.h"

Go to the source code of this file.

Macros

#define BITSTREAM_WRITER_LE
 
#define get_index(num, offset, size)
 Quantize the current LSP subvector. More...
 

Functions

static av_cold int g723_1_encode_init (AVCodecContext *avctx)
 
static void highpass_filter (int16_t *buf, int16_t *fir, int *iir)
 Remove DC component from the input signal. More...
 
static void comp_autocorr (int16_t *buf, int16_t *autocorr)
 Estimate autocorrelation of the input vector. More...
 
static void levinson_durbin (int16_t *lpc, int16_t *autocorr, int16_t error)
 Use Levinson-Durbin recursion to compute LPC coefficients from autocorrelation values. More...
 
static void comp_lpc_coeff (int16_t *buf, int16_t *lpc)
 Calculate LPC coefficients for the current frame. More...
 
static void lpc2lsp (int16_t *lpc, int16_t *prev_lsp, int16_t *lsp)
 
static void lsp_quantize (uint8_t *lsp_index, int16_t *lsp, int16_t *prev_lsp)
 Vector quantize the LSP frequencies. More...
 
static void iir_filter (int16_t *fir_coef, int16_t *iir_coef, int16_t *src, int16_t *dest)
 Perform IIR filtering. More...
 
static void perceptual_filter (G723_1_ChannelContext *p, int16_t *flt_coef, int16_t *unq_lpc, int16_t *buf)
 Apply the formant perceptual weighting filter. More...
 
static int estimate_pitch (int16_t *buf, int start)
 Estimate the open loop pitch period. More...
 
static void comp_harmonic_coeff (int16_t *buf, int16_t pitch_lag, HFParam *hf)
 Compute harmonic noise filter parameters. More...
 
static void harmonic_filter (HFParam *hf, const int16_t *src, int16_t *dest)
 Apply the harmonic noise shaping filter. More...
 
static void harmonic_noise_sub (HFParam *hf, const int16_t *src, int16_t *dest)
 
static void synth_percept_filter (int16_t *qnt_lpc, int16_t *perf_lpc, int16_t *perf_fir, int16_t *perf_iir, const int16_t *src, int16_t *dest, int scale)
 Combined synthesis and formant perceptual weighting filer. More...
 
static void acb_search (G723_1_ChannelContext *p, int16_t *residual, int16_t *impulse_resp, const int16_t *buf, int index)
 Compute the adaptive codebook contribution. More...
 
static void sub_acb_contrib (const int16_t *residual, const int16_t *impulse_resp, int16_t *buf)
 Subtract the adaptive codebook contribution from the input to obtain the residual. More...
 
static void get_fcb_param (FCBParam *optim, int16_t *impulse_resp, int16_t *buf, int pulse_cnt, int pitch_lag)
 Quantize the residual signal using the fixed codebook (MP-MLQ). More...
 
static void pack_fcb_param (G723_1_Subframe *subfrm, FCBParam *optim, int16_t *buf, int pulse_cnt)
 Encode the pulse position and gain of the current subframe. More...
 
static void fcb_search (G723_1_ChannelContext *p, int16_t *impulse_resp, int16_t *buf, int index)
 Compute the fixed codebook excitation. More...
 
static int pack_bitstream (G723_1_ChannelContext *p, AVPacket *avpkt)
 Pack the frame parameters into output bitstream. More...
 
static int g723_1_encode_frame (AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
 

Variables

static const AVCodecDefault defaults []
 
AVCodec ff_g723_1_encoder
 

Detailed Description

G.723.1 compatible encoder

Definition in file g723_1enc.c.

Macro Definition Documentation

◆ BITSTREAM_WRITER_LE

#define BITSTREAM_WRITER_LE

Definition at line 40 of file g723_1enc.c.

◆ get_index

#define get_index (   num,
  offset,
  size 
)
Value:
{ \
int error, max = -1; \
int16_t temp[4]; \
int i, j; \
for (i = 0; i < LSP_CB_SIZE; i++) { \
for (j = 0; j < size; j++){ \
temp[j] = (weight[j + (offset)] * lsp_band##num[i][j] + \
(1 << 14)) >> 15; \
} \
error = ff_g723_1_dot_product(lsp + (offset), temp, size) << 1; \
error -= ff_g723_1_dot_product(lsp_band##num[i], temp, size); \
if (error > max) { \
max = error; \
lsp_index[num] = i; \
} \
} \
}

Quantize the current LSP subvector.

Parameters
numband number
offsetoffset of the current subvector in an LPC_ORDER vector
sizesize of the current subvector

Definition at line 293 of file g723_1enc.c.

Function Documentation

◆ g723_1_encode_init()

static av_cold int g723_1_encode_init ( AVCodecContext avctx)
static

Definition at line 43 of file g723_1enc.c.

◆ highpass_filter()

static void highpass_filter ( int16_t *  buf,
int16_t *  fir,
int iir 
)
static

Remove DC component from the input signal.

Parameters
bufinput signal
firzero memory
iirpole memory

Definition at line 81 of file g723_1enc.c.

Referenced by g723_1_encode_frame().

◆ comp_autocorr()

static void comp_autocorr ( int16_t *  buf,
int16_t *  autocorr 
)
static

Estimate autocorrelation of the input vector.

Parameters
bufinput buffer
autocorrautocorrelation coefficients vector

Definition at line 97 of file g723_1enc.c.

Referenced by comp_lpc_coeff().

◆ levinson_durbin()

static void levinson_durbin ( int16_t *  lpc,
int16_t *  autocorr,
int16_t  error 
)
static

Use Levinson-Durbin recursion to compute LPC coefficients from autocorrelation values.

Parameters
lpcLPC coefficients vector
autocorrautocorrelation coefficients vector
errorprediction error

Definition at line 139 of file g723_1enc.c.

Referenced by comp_lpc_coeff().

◆ comp_lpc_coeff()

static void comp_lpc_coeff ( int16_t *  buf,
int16_t *  lpc 
)
static

Calculate LPC coefficients for the current frame.

Parameters
bufcurrent frame
prev_data2 trailing subframes of the previous frame
lpcLPC coefficients vector

Definition at line 183 of file g723_1enc.c.

Referenced by g723_1_encode_frame().

◆ lpc2lsp()

static void lpc2lsp ( int16_t *  lpc,
int16_t *  prev_lsp,
int16_t *  lsp 
)
static

< coefficients of the sum and difference polynomials (F1, F2) ordered as f1[0], f2[0], ...., f1[5], f2[5]

Evaluate F1 and F2 at uniform intervals of pi/256 along the unit circle and check for zero crossings.

Definition at line 199 of file g723_1enc.c.

Referenced by g723_1_encode_frame().

◆ lsp_quantize()

static void lsp_quantize ( uint8_t lsp_index,
int16_t *  lsp,
int16_t *  prev_lsp 
)
static

Vector quantize the LSP frequencies.

Parameters
lspthe current lsp vector
prev_lspthe previous lsp vector

Definition at line 319 of file g723_1enc.c.

Referenced by g723_1_encode_frame().

◆ iir_filter()

static void iir_filter ( int16_t *  fir_coef,
int16_t *  iir_coef,
int16_t *  src,
int16_t *  dest 
)
static

Perform IIR filtering.

Parameters
fir_coefFIR coefficients
iir_coefIIR coefficients
srcsource vector
destdestination vector

Definition at line 367 of file g723_1enc.c.

Referenced by perceptual_filter().

◆ perceptual_filter()

static void perceptual_filter ( G723_1_ChannelContext p,
int16_t *  flt_coef,
int16_t *  unq_lpc,
int16_t *  buf 
)
static

Apply the formant perceptual weighting filter.

Parameters
flt_coeffilter coefficients
unq_lpcunquantized lpc vector

Definition at line 390 of file g723_1enc.c.

Referenced by g723_1_encode_frame().

◆ estimate_pitch()

static int estimate_pitch ( int16_t *  buf,
int  start 
)
static

Estimate the open loop pitch period.

Parameters
bufperceptually weighted speech
startestimation is carried out from this position

Definition at line 422 of file g723_1enc.c.

Referenced by g723_1_encode_frame().

◆ comp_harmonic_coeff()

static void comp_harmonic_coeff ( int16_t *  buf,
int16_t  pitch_lag,
HFParam hf 
)
static

Compute harmonic noise filter parameters.

Parameters
bufperceptually weighted speech
pitch_lagopen loop pitch period
hfharmonic filter parameters

Definition at line 495 of file g723_1enc.c.

Referenced by g723_1_encode_frame().

◆ harmonic_filter()

static void harmonic_filter ( HFParam hf,
const int16_t *  src,
int16_t *  dest 
)
static

Apply the harmonic noise shaping filter.

Parameters
hffilter parameters

Definition at line 568 of file g723_1enc.c.

Referenced by g723_1_encode_frame().

◆ harmonic_noise_sub()

static void harmonic_noise_sub ( HFParam hf,
const int16_t *  src,
int16_t *  dest 
)
static

Definition at line 578 of file g723_1enc.c.

Referenced by g723_1_encode_frame().

◆ synth_percept_filter()

static void synth_percept_filter ( int16_t *  qnt_lpc,
int16_t *  perf_lpc,
int16_t *  perf_fir,
int16_t *  perf_iir,
const int16_t *  src,
int16_t *  dest,
int  scale 
)
static

Combined synthesis and formant perceptual weighting filer.

Parameters
qnt_lpcquantized lpc coefficients
perf_lpcperceptual filter coefficients
perf_firperceptual filter fir memory
perf_iirperceptual filter iir memory
scalethe filter output will be scaled by 2^scale

Definition at line 597 of file g723_1enc.c.

Referenced by g723_1_encode_frame().

◆ acb_search()

static void acb_search ( G723_1_ChannelContext p,
int16_t *  residual,
int16_t *  impulse_resp,
const int16_t *  buf,
int  index 
)
static

Compute the adaptive codebook contribution.

Parameters
bufinput signal
indexthe current subframe index

Definition at line 639 of file g723_1enc.c.

Referenced by g723_1_encode_frame().

◆ sub_acb_contrib()

static void sub_acb_contrib ( const int16_t *  residual,
const int16_t *  impulse_resp,
int16_t *  buf 
)
static

Subtract the adaptive codebook contribution from the input to obtain the residual.

Parameters
buftarget vector

Definition at line 757 of file g723_1enc.c.

Referenced by g723_1_encode_frame().

◆ get_fcb_param()

static void get_fcb_param ( FCBParam optim,
int16_t *  impulse_resp,
int16_t *  buf,
int  pulse_cnt,
int  pitch_lag 
)
static

Quantize the residual signal using the fixed codebook (MP-MLQ).

Parameters
optimoptimized fixed codebook parameters
bufexcitation vector

Definition at line 777 of file g723_1enc.c.

Referenced by fcb_search().

◆ pack_fcb_param()

static void pack_fcb_param ( G723_1_Subframe subfrm,
FCBParam optim,
int16_t *  buf,
int  pulse_cnt 
)
static

Encode the pulse position and gain of the current subframe.

Parameters
optimoptimized fixed CB parameters
bufexcitation vector

Definition at line 932 of file g723_1enc.c.

Referenced by fcb_search().

◆ fcb_search()

static void fcb_search ( G723_1_ChannelContext p,
int16_t *  impulse_resp,
int16_t *  buf,
int  index 
)
static

Compute the fixed codebook excitation.

Parameters
buftarget vector
impulse_respimpulse response of the combined filter

Definition at line 967 of file g723_1enc.c.

Referenced by g723_1_encode_frame().

◆ pack_bitstream()

static int pack_bitstream ( G723_1_ChannelContext p,
AVPacket avpkt 
)
static

Pack the frame parameters into output bitstream.

Parameters
frameoutput buffer
sizesize of the buffer

Definition at line 999 of file g723_1enc.c.

Referenced by g723_1_encode_frame().

◆ g723_1_encode_frame()

static int g723_1_encode_frame ( AVCodecContext avctx,
AVPacket avpkt,
const AVFrame frame,
int got_packet_ptr 
)
static

Compute the combined impulse response of the synthesis filter, formant perceptual weighting filter and harmonic noise shaping filter

Definition at line 1057 of file g723_1enc.c.

Variable Documentation

◆ defaults

const AVCodecDefault defaults[]
static
Initial value:
= {
{ "b", "6300" },
{ NULL },
}

Definition at line 1194 of file g723_1enc.c.

◆ ff_g723_1_encoder

AVCodec ff_g723_1_encoder
Initial value:
= {
.name = "g723_1",
.long_name = NULL_IF_CONFIG_SMALL("G.723.1"),
.priv_data_size = sizeof(G723_1_Context),
.encode2 = g723_1_encode_frame,
.sample_fmts = (const enum AVSampleFormat[]) {
},
}

Definition at line 1199 of file g723_1enc.c.

g723_1_encode_init
static av_cold int g723_1_encode_init(AVCodecContext *avctx)
Definition: g723_1enc.c:43
init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:686
G723_1_Context
Definition: g723_1.h:159
max
#define max(a, b)
Definition: cuda_runtime.h:33
LSP_CB_SIZE
#define LSP_CB_SIZE
Definition: g723_1.h:42
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
NULL
#define NULL
Definition: coverity.c:32
AV_CODEC_ID_G723_1
@ AV_CODEC_ID_G723_1
Definition: avcodec.h:616
ff_g723_1_dot_product
int ff_g723_1_dot_product(const int16_t *a, const int16_t *b, int length)
Definition: g723_1.c:54
weight
static int weight(int i, int blen, int offset)
Definition: diracdec.c:1564
error
static void error(const char *err)
Definition: target_dec_fuzzer.c:61
for
for(j=16;j >0;--j)
Definition: h264pred_template.c:469
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:188
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:59
size
int size
Definition: twinvq_data.h:11134
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
g723_1_encode_frame
static int g723_1_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Definition: g723_1enc.c:1057
AV_SAMPLE_FMT_S16
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition: samplefmt.h:61
temp
else temp
Definition: vf_mcdeint.c:256
defaults
static const AVCodecDefault defaults[]
Definition: g723_1enc.c:1194