FFmpeg
Data Structures | Enumerations | Functions | Variables
qcelpdec.c File Reference
#include "libavutil/avassert.h"
#include "libavutil/channel_layout.h"
#include "libavutil/float_dsp.h"
#include "avcodec.h"
#include "codec_internal.h"
#include "decode.h"
#include "get_bits.h"
#include "qcelpdata.h"
#include "celp_filters.h"
#include "acelp_filters.h"
#include "acelp_vectors.h"
#include "lsp.h"

Go to the source code of this file.

Data Structures

struct  QCELPContext
 

Enumerations

enum  qcelp_packet_rate {
  I_F_Q = -1, SILENCE, RATE_OCTAVE, RATE_QUARTER,
  RATE_HALF, RATE_FULL
}
 

Functions

static av_cold int qcelp_decode_init (AVCodecContext *avctx)
 Initialize the speech codec according to the specification. More...
 
static int decode_lspf (QCELPContext *q, float *lspf)
 Decode the 10 quantized LSP frequencies from the LSPV/LSP transmission codes of any bitrate and check for badly received packets. More...
 
static void decode_gain_and_index (QCELPContext *q, float *gain)
 Convert codebook transmission codes to GAIN and INDEX. More...
 
static int codebook_sanity_check_for_rate_quarter (const uint8_t *cbgain)
 If the received packet is Rate 1/4 a further sanity check is made of the codebook gain. More...
 
static void compute_svector (QCELPContext *q, const float *gain, float *cdn_vector)
 Compute the scaled codebook vector Cdn From INDEX and GAIN for all rates. More...
 
static void apply_gain_ctrl (float *v_out, const float *v_ref, const float *v_in)
 Apply generic gain control. More...
 
static const floatdo_pitchfilter (float memory[303], const float v_in[160], const float gain[4], const uint8_t *lag, const uint8_t pfrac[4])
 Apply filter in pitch-subframe steps. More...
 
static void apply_pitch_filters (QCELPContext *q, float *cdn_vector)
 Apply pitch synthesis filter and pitch prefilter to the scaled codebook vector. More...
 
static void lspf2lpc (const float *lspf, float *lpc)
 Reconstruct LPC coefficients from the line spectral pair frequencies and perform bandwidth expansion. More...
 
static void interpolate_lpc (QCELPContext *q, const float *curr_lspf, float *lpc, const int subframe_num)
 Interpolate LSP frequencies and compute LPC coefficients for a given bitrate & pitch subframe. More...
 
static qcelp_packet_rate buf_size2bitrate (const int buf_size)
 
static qcelp_packet_rate determine_bitrate (AVCodecContext *avctx, const int buf_size, const uint8_t **buf)
 Determine the bitrate from the frame size and/or the first byte of the frame. More...
 
static void warn_insufficient_frame_quality (AVCodecContext *avctx, const char *message)
 
static void postfilter (QCELPContext *q, float *samples, float *lpc)
 
static int qcelp_decode_frame (AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
 

Variables

const FFCodec ff_qcelp_decoder
 

Detailed Description

QCELP decoder

Author
Reynaldo H. Verdejo Pinochet
Remarks
FFmpeg merging spearheaded by Kenan Gillet
Development mentored by Benjamin Larson

Definition in file qcelpdec.c.

Enumeration Type Documentation

◆ qcelp_packet_rate

Enumerator
I_F_Q 

insufficient frame quality

SILENCE 
RATE_OCTAVE 
RATE_QUARTER 
RATE_HALF 
RATE_FULL 

Definition at line 43 of file qcelpdec.c.

Function Documentation

◆ qcelp_decode_init()

static av_cold int qcelp_decode_init ( AVCodecContext avctx)
static

Initialize the speech codec according to the specification.

TIA/EIA/IS-733 2.4.9

Definition at line 84 of file qcelpdec.c.

◆ decode_lspf()

static int decode_lspf ( QCELPContext q,
float lspf 
)
static

Decode the 10 quantized LSP frequencies from the LSPV/LSP transmission codes of any bitrate and check for badly received packets.

Parameters
qthe context
lspfline spectral pair frequencies
Returns
0 on success, -1 if the packet is badly received

TIA/EIA/IS-733 2.4.3.2.6.2-2, 2.4.8.7.3

Definition at line 110 of file qcelpdec.c.

Referenced by qcelp_decode_frame().

◆ decode_gain_and_index()

static void decode_gain_and_index ( QCELPContext q,
float gain 
)
static

Convert codebook transmission codes to GAIN and INDEX.

Parameters
qthe context
gainarray holding the decoded gain

TIA/EIA/IS-733 2.4.6.2

Definition at line 194 of file qcelpdec.c.

Referenced by qcelp_decode_frame().

◆ codebook_sanity_check_for_rate_quarter()

static int codebook_sanity_check_for_rate_quarter ( const uint8_t *  cbgain)
static

If the received packet is Rate 1/4 a further sanity check is made of the codebook gain.

Parameters
cbgainthe unpacked cbgain array
Returns
-1 if the sanity check fails, 0 otherwise

TIA/EIA/IS-733 2.4.8.7.3

Definition at line 272 of file qcelpdec.c.

Referenced by qcelp_decode_frame().

◆ compute_svector()

static void compute_svector ( QCELPContext q,
const float gain,
float cdn_vector 
)
static

Compute the scaled codebook vector Cdn From INDEX and GAIN for all rates.

The specification lacks some information here.

TIA/EIA/IS-733 has an omission on the codebook index determination formula for RATE_FULL and RATE_HALF frames at section 2.4.8.1.1. It says you have to subtract the decoded index parameter from the given scaled codebook vector index 'n' to get the desired circular codebook index, but it does not mention that you have to clamp 'n' to [0-9] in order to get RI-compliant results.

The reason for this mistake seems to be the fact they forgot to mention you have to do these calculations per codebook subframe and adjust given equation values accordingly.

Parameters
qthe context
gainarray holding the 4 pitch subframe gain values
cdn_vectorarray for the generated scaled codebook vector

Definition at line 308 of file qcelpdec.c.

Referenced by qcelp_decode_frame().

◆ apply_gain_ctrl()

static void apply_gain_ctrl ( float v_out,
const float v_ref,
const float v_in 
)
static

Apply generic gain control.

Parameters
v_outoutput vector
v_ingain-controlled vector
v_refvector to control gain of

TIA/EIA/IS-733 2.4.8.3, 2.4.8.6

Definition at line 395 of file qcelpdec.c.

Referenced by apply_pitch_filters().

◆ do_pitchfilter()

static const float* do_pitchfilter ( float  memory[303],
const float  v_in[160],
const float  gain[4],
const uint8_t *  lag,
const uint8_t  pfrac[4] 
)
static

Apply filter in pitch-subframe steps.

Parameters
memorybuffer for the previous state of the filter
  • must be able to contain 303 elements
  • the 143 first elements are from the previous state
  • the next 160 are for output
v_ininput filter vector
gainper-subframe gain array, each element is between 0.0 and 2.0
lagper-subframe lag array, each element is
  • between 16 and 143 if its corresponding pfrac is 0,
  • between 16 and 139 otherwise
pfracper-subframe boolean array, 1 if the lag is fractional, 0 otherwise
Returns
filter output vector

Definition at line 422 of file qcelpdec.c.

Referenced by apply_pitch_filters().

◆ apply_pitch_filters()

static void apply_pitch_filters ( QCELPContext q,
float cdn_vector 
)
static

Apply pitch synthesis filter and pitch prefilter to the scaled codebook vector.

TIA/EIA/IS-733 2.4.5.2, 2.4.8.7.2

Parameters
qthe context
cdn_vectorthe scaled codebook vector

Definition at line 466 of file qcelpdec.c.

Referenced by qcelp_decode_frame().

◆ lspf2lpc()

static void lspf2lpc ( const float lspf,
float lpc 
)
static

Reconstruct LPC coefficients from the line spectral pair frequencies and perform bandwidth expansion.

Parameters
lspfline spectral pair frequencies
lpclinear predictive coding coefficients
Note
: bandwidth_expansion_coeff could be precalculated into a table but it seems to be slower on x86

TIA/EIA/IS-733 2.4.3.3.5

Definition at line 535 of file qcelpdec.c.

Referenced by interpolate_lpc().

◆ interpolate_lpc()

static void interpolate_lpc ( QCELPContext q,
const float curr_lspf,
float lpc,
const int  subframe_num 
)
static

Interpolate LSP frequencies and compute LPC coefficients for a given bitrate & pitch subframe.

TIA/EIA/IS-733 2.4.3.3.4, 2.4.8.7.2

Parameters
qthe context
curr_lspfLSP frequencies vector of the current frame
lpcfloat vector for the resulting LPC
subframe_numframe number in decoded stream

Definition at line 563 of file qcelpdec.c.

Referenced by qcelp_decode_frame().

◆ buf_size2bitrate()

static qcelp_packet_rate buf_size2bitrate ( const int  buf_size)
static

Definition at line 587 of file qcelpdec.c.

Referenced by determine_bitrate().

◆ determine_bitrate()

static qcelp_packet_rate determine_bitrate ( AVCodecContext avctx,
const int  buf_size,
const uint8_t **  buf 
)
static

Determine the bitrate from the frame size and/or the first byte of the frame.

Parameters
avctxthe AV codec context
buf_sizelength of the buffer
bufthe buffer
Returns
the bitrate on success, I_F_Q if the bitrate cannot be satisfactorily determined

TIA/EIA/IS-733 2.4.8.7.1

Definition at line 612 of file qcelpdec.c.

Referenced by qcelp_decode_frame().

◆ warn_insufficient_frame_quality()

static void warn_insufficient_frame_quality ( AVCodecContext avctx,
const char *  message 
)
static

Definition at line 646 of file qcelpdec.c.

Referenced by qcelp_decode_frame().

◆ postfilter()

static void postfilter ( QCELPContext q,
float samples,
float lpc 
)
static

Definition at line 653 of file qcelpdec.c.

Referenced by qcelp_decode_frame().

◆ qcelp_decode_frame()

static int qcelp_decode_frame ( AVCodecContext avctx,
AVFrame frame,
int got_frame_ptr,
AVPacket avpkt 
)
static

Definition at line 685 of file qcelpdec.c.

Variable Documentation

◆ ff_qcelp_decoder

const FFCodec ff_qcelp_decoder
Initial value:
= {
.p.name = "qcelp",
CODEC_LONG_NAME("QCELP / PureVoice"),
.p.type = AVMEDIA_TYPE_AUDIO,
.priv_data_size = sizeof(QCELPContext),
}

Definition at line 791 of file qcelpdec.c.

qcelp_decode_init
static av_cold int qcelp_decode_init(AVCodecContext *avctx)
Initialize the speech codec according to the specification.
Definition: qcelpdec.c:84
qcelp_decode_frame
static int qcelp_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Definition: qcelpdec.c:685
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:298
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:264
AV_CODEC_CAP_CHANNEL_CONF
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
Definition: codec.h:109
AV_CODEC_ID_QCELP
@ AV_CODEC_ID_QCELP
Definition: codec_id.h:459
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
QCELPContext
Definition: qcelpdec.c:52