FFmpeg
Functions | Variables
ra144enc.c File Reference
#include <float.h>
#include "avcodec.h"
#include "audio_frame_queue.h"
#include "celp_filters.h"
#include "internal.h"
#include "mathops.h"
#include "put_bits.h"
#include "ra144.h"

Go to the source code of this file.

Functions

static av_cold int ra144_encode_close (AVCodecContext *avctx)
 
static av_cold int ra144_encode_init (AVCodecContext *avctx)
 
static int quantize (int value, const int16_t *table, unsigned int size)
 Quantize a value by searching a sorted table for the element with the nearest value. More...
 
static void orthogonalize (float *v, const float *u)
 Orthogonalize a vector to another vector. More...
 
static void get_match_score (float *work, const float *coefs, float *vect, const float *ortho1, const float *ortho2, const float *data, float *score, float *gain)
 Calculate match score and gain of an LPC-filtered vector with respect to input data, possibly orthogonalizing it to up to two other vectors. More...
 
static void create_adapt_vect (float *vect, const int16_t *cb, int lag)
 Create a vector from the adaptive codebook at a given lag value. More...
 
static int adaptive_cb_search (const int16_t *adapt_cb, float *work, const float *coefs, float *data)
 Search the adaptive codebook for the best entry and gain and remove its contribution from input data. More...
 
static void find_best_vect (float *work, const float *coefs, const int8_t cb[][BLOCKSIZE], const float *ortho1, const float *ortho2, float *data, int *idx, float *gain)
 Find the best vector of a fixed codebook by applying an LPC filter to codebook entries, possibly orthogonalizing them to up to two other vectors and matching the results with input data. More...
 
static void fixed_cb_search (float *work, const float *coefs, float *data, int cba_idx, int *cb1_idx, int *cb2_idx)
 Search the two fixed codebooks for the best entry and gain. More...
 
static void ra144_encode_subblock (RA144Context *ractx, const int16_t *sblock_data, const int16_t *lpc_coefs, unsigned int rms, PutBitContext *pb)
 Encode a subblock of the current frame. More...
 
static int ra144_encode_frame (AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
 

Variables

AVCodec ff_ra_144_encoder
 

Detailed Description

Real Audio 1.0 (14.4K) encoder

Author
Francesco Lavra franc.nosp@m.esco.nosp@m.lavra.nosp@m.@int.nosp@m.erfre.nosp@m.e.it

Definition in file ra144enc.c.

Function Documentation

◆ ra144_encode_close()

static av_cold int ra144_encode_close ( AVCodecContext avctx)
static

Definition at line 38 of file ra144enc.c.

Referenced by ra144_encode_init().

◆ ra144_encode_init()

static av_cold int ra144_encode_init ( AVCodecContext avctx)
static

Definition at line 47 of file ra144enc.c.

◆ quantize()

static int quantize ( int  value,
const int16_t *  table,
unsigned int  size 
)
static

Quantize a value by searching a sorted table for the element with the nearest value.

Parameters
valuevalue to quantize
tablearray containing the quantization table
sizesize of the quantization table
Returns
index of the quantization table corresponding to the element with the nearest value

Definition at line 89 of file ra144enc.c.

Referenced by ra144_encode_frame().

◆ orthogonalize()

static void orthogonalize ( float *  v,
const float *  u 
)
static

Orthogonalize a vector to another vector.

Parameters
vvector to orthogonalize
uvector against which orthogonalization is performed

Definition at line 114 of file ra144enc.c.

Referenced by fixed_cb_search(), and get_match_score().

◆ get_match_score()

static void get_match_score ( float *  work,
const float *  coefs,
float *  vect,
const float *  ortho1,
const float *  ortho2,
const float *  data,
float *  score,
float *  gain 
)
static

Calculate match score and gain of an LPC-filtered vector with respect to input data, possibly orthogonalizing it to up to two other vectors.

Parameters
workarray used to calculate the filtered vector
coefscoefficients of the LPC filter
vectoriginal vector
ortho1first vector against which orthogonalization is performed
ortho2second vector against which orthogonalization is performed
datainput data
scorepointer to variable where match score is returned
gainpointer to variable where gain is returned

Definition at line 142 of file ra144enc.c.

Referenced by adaptive_cb_search(), and find_best_vect().

◆ create_adapt_vect()

static void create_adapt_vect ( float *  vect,
const int16_t *  cb,
int  lag 
)
static

Create a vector from the adaptive codebook at a given lag value.

Parameters
vectarray where vector is stored
cbadaptive codebook
laglag value

Definition at line 175 of file ra144enc.c.

Referenced by adaptive_cb_search().

◆ adaptive_cb_search()

static int adaptive_cb_search ( const int16_t *  adapt_cb,
float *  work,
const float *  coefs,
float *  data 
)
static

Search the adaptive codebook for the best entry and gain and remove its contribution from input data.

Parameters
adapt_cbarray from which the adaptive codebook is extracted
workarray used to calculate LPC-filtered vectors
coefscoefficients of the LPC filter
datainput data
Returns
index of the best entry of the adaptive codebook

Re-calculate the filtered vector from the vector with maximum match score and remove its contribution from input data.

Definition at line 198 of file ra144enc.c.

Referenced by ra144_encode_subblock().

◆ find_best_vect()

static void find_best_vect ( float *  work,
const float *  coefs,
const int8_t  cb[][BLOCKSIZE],
const float *  ortho1,
const float *  ortho2,
float *  data,
int idx,
float *  gain 
)
static

Find the best vector of a fixed codebook by applying an LPC filter to codebook entries, possibly orthogonalizing them to up to two other vectors and matching the results with input data.

Parameters
workarray used to calculate the filtered vectors
coefscoefficients of the LPC filter
cbfixed codebook
ortho1first vector against which orthogonalization is performed
ortho2second vector against which orthogonalization is performed
datainput data
idxpointer to variable where the index of the best codebook entry is returned
gainpointer to variable where the gain of the best codebook entry is returned

Definition at line 246 of file ra144enc.c.

Referenced by fixed_cb_search().

◆ fixed_cb_search()

static void fixed_cb_search ( float *  work,
const float *  coefs,
float *  data,
int  cba_idx,
int cb1_idx,
int cb2_idx 
)
static

Search the two fixed codebooks for the best entry and gain.

Parameters
workarray used to calculate LPC-filtered vectors
coefscoefficients of the LPC filter
datainput data
cba_idxindex of the best entry of the adaptive codebook
cb1_idxpointer to variable where the index of the best entry of the first fixed codebook is returned
cb2_idxpointer to variable where the index of the best entry of the second fixed codebook is returned

The filtered vector from the adaptive codebook can be retrieved from work, because this function is called just after adaptive_cb_search().

Re-calculate the filtered vector from the vector with maximum match score and remove its contribution from input data.

Definition at line 281 of file ra144enc.c.

Referenced by ra144_encode_subblock().

◆ ra144_encode_subblock()

static void ra144_encode_subblock ( RA144Context ractx,
const int16_t *  sblock_data,
const int16_t *  lpc_coefs,
unsigned int  rms,
PutBitContext pb 
)
static

Encode a subblock of the current frame.

Parameters
ractxencoder context
sblock_datainput data of the subblock
lpc_coefscoefficients of the LPC filter
rmsRMS of the reflection coefficients
pbpointer to PutBitContext of the current frame

Calculate the zero-input response of the LPC filter and subtract it from input data.

Codebook search is performed without taking into account the contribution of the previous subblock, since it has been just subtracted from input data.

The filtered vector from the adaptive codebook can be retrieved from work, see implementation of adaptive_cb_search().

Definition at line 330 of file ra144enc.c.

Referenced by ra144_encode_frame().

◆ ra144_encode_frame()

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

< reflection coefficients of the frame

< RMS of the reflection coefficients

Since the LPC coefficients are calculated on a frame centered over the fourth subframe, to encode a given frame, data from the next frame is needed. In each call to this function, the previous frame (whose data are saved in the encoder context) is encoded, and data from the current frame are saved in the encoder context to be used in the next function call.

TODO: apply perceptual weighting of the input speech through bandwidth expansion of the LPC filter.

The filter is unstable: use the coefficients of the previous frame.

Definition at line 430 of file ra144enc.c.

Variable Documentation

◆ ff_ra_144_encoder

AVCodec ff_ra_144_encoder
Initial value:
= {
.name = "real_144",
.long_name = NULL_IF_CONFIG_SMALL("RealAudio 1.0 (14.4K)"),
.priv_data_size = sizeof(RA144Context),
.encode2 = ra144_encode_frame,
.supported_samplerates = (const int[]){ 8000, 0 },
.channel_layouts = (const uint64_t[]) { AV_CH_LAYOUT_MONO, 0 },
}

Definition at line 545 of file ra144enc.c.

init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:716
AV_CH_LAYOUT_MONO
#define AV_CH_LAYOUT_MONO
Definition: channel_layout.h:85
AV_CODEC_ID_RA_144
@ AV_CODEC_ID_RA_144
Definition: codec_id.h:396
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
RA144Context
Definition: ra144.h:37
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
ra144_encode_close
static av_cold int ra144_encode_close(AVCodecContext *avctx)
Definition: ra144enc.c:38
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
AV_SAMPLE_FMT_S16
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition: samplefmt.h:61
AV_CODEC_CAP_DELAY
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: codec.h:75
ra144_encode_frame
static int ra144_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Definition: ra144enc.c:430
AV_CODEC_CAP_SMALL_LAST_FRAME
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
Definition: codec.h:80
ra144_encode_init
static av_cold int ra144_encode_init(AVCodecContext *avctx)
Definition: ra144enc.c:47