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)
 Decode the 10 quantized LSP frequencies from the LSPV/LSP transmission codes of any bitrate and check for badly received packets.
static void decode_gain_and_index (QCELPContext *q, float *gain)
 Convert 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)
 Compute 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)
 Reconstruct LPC coefficients from the line spectral pair frequencies and perform bandwidth expansion.
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.
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 *got_frame_ptr, AVPacket *avpkt)

Variables

AVCodec 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

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

Referenced by qcelp_decode_frame().

static qcelp_packet_rate buf_size2bitrate ( const int  buf_size  )  [static]

Definition at line 589 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 278 of file qcelpdec.c.

Referenced by qcelp_decode_frame().

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

Definition at line 314 of file qcelpdec.c.

Referenced by qcelp_decode_frame().

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

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

Referenced by qcelp_decode_frame().

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:
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 116 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 614 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 426 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]

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

Referenced by qcelp_decode_frame().

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

Reconstruct LPC coefficients from the line spectral pair frequencies and perform 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 537 of file qcelpdec.c.

Referenced by interpolate_lpc().

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

Definition at line 655 of file qcelpdec.c.

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

Definition at line 686 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 89 of file qcelpdec.c.

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

Definition at line 648 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,
    .capabilities   = CODEC_CAP_DR1,
    .priv_data_size = sizeof(QCELPContext),
    .long_name      = NULL_IF_CONFIG_SMALL("QCELP / PureVoice"),
}

Definition at line 793 of file qcelpdec.c.


Generated on Fri Oct 26 02:46:10 2012 for FFmpeg by  doxygen 1.5.8