FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions | Variables
g723_1enc.c File Reference

G.723.1 compatible encoder. More...

#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_Context *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_Context *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_Context *p, int16_t *impulse_resp, int16_t *buf, int index)
 Compute the fixed codebook excitation. More...
 
static int pack_bitstream (G723_1_Context *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

AVCodec ff_g723_1_encoder
 

Detailed Description

G.723.1 compatible encoder.

Definition in file g723_1enc.c.

Macro Definition Documentation

#define BITSTREAM_WRITER_LE

Definition at line 40 of file g723_1enc.c.

#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; \
} \
} \
}
else temp
Definition: vf_mcdeint.c:259
#define LSP_CB_SIZE
Definition: g723_1.h:42
ptrdiff_t size
Definition: opengl_enc.c:101
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
int ff_g723_1_dot_product(const int16_t *a, const int16_t *b, int length)
Definition: g723_1.c:54
static int weight(int i, int blen, int offset)
Definition: diracdec.c:1506
if(ret< 0)
Definition: vf_mcdeint.c:282
for(j=16;j >0;--j)

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 291 of file g723_1enc.c.

Referenced by lsp_quantize().

Function Documentation

static av_cold int g723_1_encode_init ( AVCodecContext avctx)
static

Definition at line 43 of file g723_1enc.c.

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 79 of file g723_1enc.c.

Referenced by g723_1_encode_frame().

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 95 of file g723_1enc.c.

Referenced by comp_lpc_coeff().

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 137 of file g723_1enc.c.

Referenced by 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 181 of file g723_1enc.c.

Referenced by g723_1_encode_frame().

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 197 of file g723_1enc.c.

Referenced by g723_1_encode_frame().

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 317 of file g723_1enc.c.

Referenced by g723_1_encode_frame().

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 365 of file g723_1enc.c.

Referenced by perceptual_filter().

static void perceptual_filter ( G723_1_Context 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 388 of file g723_1enc.c.

Referenced by g723_1_encode_frame().

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 420 of file g723_1enc.c.

Referenced by g723_1_encode_frame().

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 493 of file g723_1enc.c.

Referenced by g723_1_encode_frame().

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 566 of file g723_1enc.c.

Referenced by g723_1_encode_frame().

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

Definition at line 576 of file g723_1enc.c.

Referenced by g723_1_encode_frame().

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 595 of file g723_1enc.c.

Referenced by g723_1_encode_frame().

static void acb_search ( G723_1_Context 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 637 of file g723_1enc.c.

Referenced by g723_1_encode_frame().

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 755 of file g723_1enc.c.

Referenced by g723_1_encode_frame().

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 775 of file g723_1enc.c.

Referenced by fcb_search().

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 930 of file g723_1enc.c.

Referenced by fcb_search().

static void fcb_search ( G723_1_Context 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 965 of file g723_1enc.c.

Referenced by g723_1_encode_frame().

static int pack_bitstream ( G723_1_Context p,
AVPacket avpkt 
)
static

Pack the frame parameters into output bitstream.

Parameters
frameoutput buffer
sizesize of the buffer

Definition at line 997 of file g723_1enc.c.

Referenced by 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 1055 of file g723_1enc.c.

Variable Documentation

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[]) {
},
}
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
static int g723_1_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Definition: g723_1enc.c:1055
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
static av_cold int g723_1_encode_init(AVCodecContext *avctx)
Definition: g723_1enc.c:43
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
signed 16 bits
Definition: samplefmt.h:61
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:701

Definition at line 1191 of file g723_1enc.c.