FFmpeg
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_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 int16_t hamming_window [LPC_FRAME]
 Hamming window coefficients scaled by 2^15. More...
 
static const int16_t binomial_window [LPC_ORDER]
 Binomial window coefficients scaled by 2^15. More...
 
static const int16_t bandwidth_expand [LPC_ORDER]
 0.994^i scaled by 2^15 More...
 
static const int16_t percept_flt_tbl [2][LPC_ORDER]
 0.5^i scaled by 2^15 More...
 
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

#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)] * ff_g723_1_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(ff_g723_1_lsp_band##num[i], temp, size); \
if (error > max) { \
max = error; \
lsp_index[num] = i; \
} \
} \
}
else temp
Definition: vf_mcdeint.c:256
static void error(const char *err)
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
#define LSP_CB_SIZE
Definition: g723_1.h:42
#define max(a, b)
Definition: cuda_runtime.h:33
ptrdiff_t size
Definition: opengl_enc.c:100
int ff_g723_1_dot_product(const int16_t *a, const int16_t *b, int length)
Definition: g723_1.c:1125
if(ret)
static int weight(int i, int blen, int offset)
Definition: diracdec.c:1561
int
for(j=16;j >0;--j)
int i
Definition: input.c:407

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 341 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 91 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 129 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 145 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 187 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 231 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 247 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 367 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 415 of file g723_1enc.c.

Referenced by 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 438 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 470 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 543 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 616 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 626 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 645 of file g723_1enc.c.

Referenced by g723_1_encode_frame().

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 687 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 805 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 825 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 980 of file g723_1enc.c.

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

Referenced by g723_1_encode_frame().

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

Variable Documentation

const int16_t hamming_window[LPC_FRAME]
static
Initial value:
= {
2621, 2631, 2659, 2705, 2770, 2853, 2955, 3074, 3212, 3367,
3541, 3731, 3939, 4164, 4405, 4663, 4937, 5226, 5531, 5851,
6186, 6534, 6897, 7273, 7661, 8062, 8475, 8899, 9334, 9780,
10235, 10699, 11172, 11653, 12141, 12636, 13138, 13645, 14157, 14673,
15193, 15716, 16242, 16769, 17298, 17827, 18356, 18884, 19411, 19935,
20457, 20975, 21489, 21999, 22503, 23002, 23494, 23978, 24455, 24924,
25384, 25834, 26274, 26704, 27122, 27529, 27924, 28306, 28675, 29031,
29373, 29700, 30012, 30310, 30592, 30857, 31107, 31340, 31557, 31756,
31938, 32102, 32249, 32377, 32488, 32580, 32654, 32710, 32747, 32766,
32766, 32747, 32710, 32654, 32580, 32488, 32377, 32249, 32102, 31938,
31756, 31557, 31340, 31107, 30857, 30592, 30310, 30012, 29700, 29373,
29031, 28675, 28306, 27924, 27529, 27122, 26704, 26274, 25834, 25384,
24924, 24455, 23978, 23494, 23002, 22503, 21999, 21489, 20975, 20457,
19935, 19411, 18884, 18356, 17827, 17298, 16769, 16242, 15716, 15193,
14673, 14157, 13645, 13138, 12636, 12141, 11653, 11172, 10699, 10235,
9780, 9334, 8899, 8475, 8062, 7661, 7273, 6897, 6534, 6186,
5851, 5531, 5226, 4937, 4663, 4405, 4164, 3939, 3731, 3541,
3367, 3212, 3074, 2955, 2853, 2770, 2705, 2659, 2631, 2621
}

Hamming window coefficients scaled by 2^15.

Definition at line 46 of file g723_1enc.c.

Referenced by comp_autocorr().

const int16_t binomial_window[LPC_ORDER]
static
Initial value:
= {
32749, 32695, 32604, 32477, 32315, 32118, 31887, 31622, 31324, 30995
}

Binomial window coefficients scaled by 2^15.

Definition at line 70 of file g723_1enc.c.

Referenced by comp_autocorr().

const int16_t bandwidth_expand[LPC_ORDER]
static
Initial value:
= {
32571, 32376, 32182, 31989, 31797, 31606, 31416, 31228, 31040, 30854
}

0.994^i scaled by 2^15

Definition at line 77 of file g723_1enc.c.

Referenced by lpc2lsp().

const int16_t percept_flt_tbl[2][LPC_ORDER]
static
Initial value:
= {
{29491, 26542, 23888, 21499, 19349, 17414, 15673, 14106, 12695, 11425},
{16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32}
}

0.5^i scaled by 2^15

Definition at line 84 of file g723_1enc.c.

Referenced by perceptual_filter().

const AVCodecDefault defaults[]
static
Initial value:
= {
{ "b", "6300" },
{ NULL },
}
#define NULL
Definition: coverity.c:32

Definition at line 1242 of file g723_1enc.c.

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:1105
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:115
static av_cold int g723_1_encode_init(AVCodecContext *avctx)
Definition: g723_1enc.c:91
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
signed 16 bits
Definition: samplefmt.h:61
static const AVCodecDefault defaults[]
Definition: g723_1enc.c:1242
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:940

Definition at line 1247 of file g723_1enc.c.