libavcodec/qcelpdec.c File Reference

QCELP decoder. More...

#include <stddef.h>
#include "avcodec.h"
#include "internal.h"
#include "get_bits.h"
#include "qcelpdata.h"
#include "celp_math.h"
#include "celp_filters.h"
#include "acelp_filters.h"
#include "acelp_vectors.h"
#include "lsp.h"
#include <assert.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.
static int decode_lspf (QCELPContext *q, float *lspf)
 Decodes the 10 quantized LSP frequencies from the LSPV/LSP transmission codes of any bitrate and checks for badly received packets.
static void decode_gain_and_index (QCELPContext *q, float *gain)
 Converts codebook transmission codes to GAIN and INDEX.
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.
static void compute_svector (QCELPContext *q, const float *gain, float *cdn_vector)
 Computes the scaled codebook vector Cdn From INDEX and GAIN for all rates.
static void apply_gain_ctrl (float *v_out, const float *v_ref, const float *v_in)
 Apply generic gain control.
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])
 Apply filter in pitch-subframe steps.
static void apply_pitch_filters (QCELPContext *q, float *cdn_vector)
 Apply pitch synthesis filter and pitch prefilter to the scaled codebook vector.
static void lspf2lpc (const float *lspf, float *lpc)
 Reconstructs LPC coefficients from the line spectral pair frequencies and performs bandwidth expansion.
static void interpolate_lpc (QCELPContext *q, const float *curr_lspf, float *lpc, const int subframe_num)
 Interpolates LSP frequencies and computes LPC coefficients for a given bitrate & pitch subframe.
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.
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, void *data, int *data_size, AVPacket *avpkt)

Variables

AVCodec 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

Enumerator:
I_F_Q  insufficient frame quality
SILENCE 
RATE_OCTAVE 
RATE_QUARTER 
RATE_HALF 
RATE_FULL 

Definition at line 47 of file qcelpdec.c.


Function Documentation

static void apply_gain_ctrl ( float *  v_out,
const float *  v_ref,
const float *  v_in 
) [static]

Apply generic gain control.

Parameters:
v_out output vector
v_in gain-controlled vector
v_ref vector to control gain of
TIA/EIA/IS-733 2.4.8.3, 2.4.8.6

Definition at line 423 of file qcelpdec.c.

Referenced by 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:
q the context
cdn_vector the scaled codebook vector

Definition at line 500 of file qcelpdec.c.

Referenced by qcelp_decode_frame().

static qcelp_packet_rate buf_size2bitrate ( const int  buf_size  )  [static]

Definition at line 632 of file qcelpdec.c.

Referenced by determine_bitrate().

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:
cbgain the unpacked cbgain array
Returns:
-1 if the sanity check fails, 0 otherwise
TIA/EIA/IS-733 2.4.8.7.3

Definition at line 295 of file qcelpdec.c.

Referenced by qcelp_decode_frame().

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

Computes 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:
q the context
gain array holding the 4 pitch subframe gain values
cdn_vector array for the generated scaled codebook vector

Definition at line 332 of file qcelpdec.c.

Referenced by qcelp_decode_frame().

static void decode_gain_and_index ( QCELPContext q,
float *  gain 
) [static]

Converts codebook transmission codes to GAIN and INDEX.

Parameters:
q the context
gain array holding the decoded gain
TIA/EIA/IS-733 2.4.6.2

Definition at line 207 of file qcelpdec.c.

Referenced by qcelp_decode_frame().

static int decode_lspf ( QCELPContext q,
float *  lspf 
) [static]

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

Parameters:
q the context
lspf line 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 114 of file qcelpdec.c.

Referenced by qcelp_decode_frame().

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:
avctx the AV codec context
buf_size length of the buffer
buf the bufffer
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 658 of file qcelpdec.c.

Referenced by qcelp_decode_frame().

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:
memory buffer 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_in input filter vector
gain per-subframe gain array, each element is between 0.0 and 2.0
lag per-subframe lag array, each element is
  • between 16 and 143 if its corresponding pfrac is 0,
  • between 16 and 139 otherwise
pfrac per-subframe boolean array, 1 if the lag is fractional, 0 otherwise
Returns:
filter output vector

Definition at line 452 of file qcelpdec.c.

Referenced by apply_pitch_filters().

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

Interpolates LSP frequencies and computes LPC coefficients for a given bitrate & pitch subframe.

TIA/EIA/IS-733 2.4.3.3.4, 2.4.8.7.2

Parameters:
q the context
curr_lspf LSP frequencies vector of the current frame
lpc float vector for the resulting LPC
subframe_num frame number in decoded stream

Definition at line 607 of file qcelpdec.c.

Referenced by qcelp_decode_frame().

static void lspf2lpc ( const float *  lspf,
float *  lpc 
) [static]

Reconstructs LPC coefficients from the line spectral pair frequencies and performs bandwidth expansion.

Parameters:
lspf line spectral pair frequencies
lpc linear 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 578 of file qcelpdec.c.

Referenced by interpolate_lpc().

static void postfilter ( QCELPContext q,
float *  samples,
float *  lpc 
) [static]

Definition at line 704 of file qcelpdec.c.

static int qcelp_decode_frame ( AVCodecContext avctx,
void *  data,
int *  data_size,
AVPacket avpkt 
) [static]

Definition at line 734 of file qcelpdec.c.

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 90 of file qcelpdec.c.

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

Definition at line 697 of file qcelpdec.c.

Referenced by qcelp_decode_frame().


Variable Documentation

Initial value:

{
    .name   = "qcelp",
    .type   = AVMEDIA_TYPE_AUDIO,
    .id     = CODEC_ID_QCELP,
    .init   = qcelp_decode_init,
    .decode = qcelp_decode_frame,
    .priv_data_size = sizeof(QCELPContext),
    .long_name = NULL_IF_CONFIG_SMALL("QCELP / PureVoice"),
}

Definition at line 845 of file qcelpdec.c.


Generated on Fri Oct 26 02:36:53 2012 for FFmpeg by  doxygen 1.5.8