#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 *data_size, AVPacket *avpkt) |
Variables | |
AVCodec | ff_qcelp_decoder |
Development mentored by Benjamin Larson
Definition in file qcelpdec.c.
enum qcelp_packet_rate |
Definition at line 47 of file qcelpdec.c.
static void apply_gain_ctrl | ( | float * | v_out, | |
const float * | v_ref, | |||
const float * | v_in | |||
) | [static] |
Apply generic gain control.
v_out | output vector | |
v_in | gain-controlled vector | |
v_ref | vector to control gain of |
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
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] |
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.
cbgain | the unpacked cbgain array |
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] |
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.
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] |
Convert codebook transmission codes to GAIN and INDEX.
q | the context | |
gain | array holding the decoded gain |
Definition at line 207 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.
q | the context | |
lspf | line spectral pair frequencies |
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.
avctx | the AV codec context | |
buf_size | length of the buffer | |
buf | the bufffer |
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.
memory | buffer for the previous state of the filter
| |
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
| |
pfrac | per-subframe boolean array, 1 if the lag is fractional, 0 otherwise |
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] |
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
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] |
Reconstruct LPC coefficients from the line spectral pair frequencies and perform bandwidth expansion.
lspf | line spectral pair frequencies | |
lpc | linear predictive coding coefficients |
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] |
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 851 of file qcelpdec.c.