Skip to content

Commit

Permalink
SIPR16k decoder
Browse files Browse the repository at this point in the history
Originally committed as revision 21234 to svn://svn.ffmpeg.org/ffmpeg/trunk
  • Loading branch information
Vitor Sessak committed Jan 16, 2010
1 parent d79c06b commit d140b02
Show file tree
Hide file tree
Showing 8 changed files with 871 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Changelog
Expand Up @@ -48,7 +48,7 @@ version <next>:
- R210 decoder
- Auravision Aura 1 and 2 decoders
- Deluxe Paint Animation playback system
- SIPR decoding for modes 8k5, 6k5 and 5k0
- SIPR decoder
- Adobe Filmstrip muxer and demuxer


Expand Down
1 change: 0 additions & 1 deletion doc/general.texi
Expand Up @@ -620,7 +620,6 @@ following image formats are supported:
@item RealAudio 3.0 (dnet) @tab IX @tab X
@tab Real low bitrate AC-3 codec
@item RealAudio SIPR / ACELP.NET @tab @tab X
@tab 16 kbps mode not yet supported
@item Shorten @tab @tab X
@item Sierra VMD audio @tab @tab X
@tab Used in Sierra VMD files.
Expand Down
3 changes: 2 additions & 1 deletion libavcodec/Makefile
Expand Up @@ -263,7 +263,8 @@ OBJS-$(CONFIG_SGI_ENCODER) += sgienc.o rle.o
OBJS-$(CONFIG_SHORTEN_DECODER) += shorten.o
OBJS-$(CONFIG_SIPR_DECODER) += sipr.o acelp_pitch_delay.o \
celp_math.o acelp_vectors.o \
acelp_filters.o celp_filters.o lsp.o
acelp_filters.o celp_filters.o lsp.o \
sipr16k.o
OBJS-$(CONFIG_SMACKAUD_DECODER) += smacker.o
OBJS-$(CONFIG_SMACKER_DECODER) += smacker.o
OBJS-$(CONFIG_SMC_DECODER) += smc.o
Expand Down
2 changes: 1 addition & 1 deletion libavcodec/avcodec.h
Expand Up @@ -30,7 +30,7 @@
#include "libavutil/avutil.h"

#define LIBAVCODEC_VERSION_MAJOR 52
#define LIBAVCODEC_VERSION_MINOR 47
#define LIBAVCODEC_VERSION_MINOR 48
#define LIBAVCODEC_VERSION_MICRO 0

#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
Expand Down
44 changes: 34 additions & 10 deletions libavcodec/sipr.c
Expand Up @@ -51,6 +51,7 @@ typedef struct {

/* bitstream parameters */
uint8_t number_of_fc_indexes;
uint8_t ma_predictor_bits; ///< size in bits of the switched MA predictor

/** size in bits of the i-th stage vector of quantizer */
uint8_t vq_indexes_bits[5];
Expand All @@ -64,6 +65,22 @@ typedef struct {
} SiprModeParam;

static const SiprModeParam modes[MODE_COUNT] = {
[MODE_16k] = {
.mode_name = "16k",
.bits_per_frame = 160,
.subframe_count = SUBFRAME_COUNT_16k,
.frames_per_packet = 1,
.pitch_sharp_factor = 0.00,

.number_of_fc_indexes = 10,
.ma_predictor_bits = 1,
.vq_indexes_bits = {7, 8, 7, 7, 7},
.pitch_delay_bits = {9, 6},
.gp_index_bits = 4,
.fc_index_bits = {4, 5, 4, 5, 4, 5, 4, 5, 4, 5},
.gc_index_bits = 5
},

[MODE_8k5] = {
.mode_name = "8k5",
.bits_per_frame = 152,
Expand All @@ -72,6 +89,7 @@ static const SiprModeParam modes[MODE_COUNT] = {
.pitch_sharp_factor = 0.8,

.number_of_fc_indexes = 3,
.ma_predictor_bits = 0,
.vq_indexes_bits = {6, 7, 7, 7, 5},
.pitch_delay_bits = {8, 5, 5},
.gp_index_bits = 0,
Expand All @@ -87,6 +105,7 @@ static const SiprModeParam modes[MODE_COUNT] = {
.pitch_sharp_factor = 0.8,

.number_of_fc_indexes = 3,
.ma_predictor_bits = 0,
.vq_indexes_bits = {6, 7, 7, 7, 5},
.pitch_delay_bits = {8, 5, 5},
.gp_index_bits = 0,
Expand All @@ -102,6 +121,7 @@ static const SiprModeParam modes[MODE_COUNT] = {
.pitch_sharp_factor = 0.85,

.number_of_fc_indexes = 1,
.ma_predictor_bits = 0,
.vq_indexes_bits = {6, 7, 7, 7, 5},
.pitch_delay_bits = {8, 5, 8, 5, 5},
.gp_index_bits = 0,
Expand Down Expand Up @@ -173,6 +193,8 @@ static void decode_parameters(SiprParameters* parms, GetBitContext *pgb,
{
int i, j;

parms->ma_pred_switch = get_bits(pgb, p->ma_predictor_bits);

for (i = 0; i < 5; i++)
parms->vq_indexes[i] = get_bits(pgb, p->vq_indexes_bits[i]);

Expand Down Expand Up @@ -490,6 +512,9 @@ static av_cold int sipr_decoder_init(AVCodecContext * avctx)

av_log(avctx, AV_LOG_DEBUG, "Mode: %s\n", modes[ctx->mode].mode_name);

if (ctx->mode == MODE_16k)
ff_sipr_init_16k(ctx);

for (i = 0; i < LP_FILTER_ORDER; i++)
ctx->lsp_history[i] = cos((i+1) * M_PI / (LP_FILTER_ORDER + 1));

Expand All @@ -498,12 +523,6 @@ static av_cold int sipr_decoder_init(AVCodecContext * avctx)

avctx->sample_fmt = SAMPLE_FMT_FLT;

if (ctx->mode == MODE_16k) {
av_log(avctx, AV_LOG_ERROR, "decoding 16kbps SIPR files is not "
"supported yet.\n");
return -1;
}

dsputil_init(&ctx->dsp, avctx);

return 0;
Expand All @@ -518,6 +537,7 @@ static int sipr_decode_frame(AVCodecContext *avctx, void *datap,
const SiprModeParam *mode_par = &modes[ctx->mode];
GetBitContext gb;
float *data = datap;
int subframe_size = ctx->mode == MODE_16k ? L_SUBFR_16k : SUBFR_SIZE;
int i;

ctx->avctx = avctx;
Expand All @@ -529,7 +549,7 @@ static int sipr_decode_frame(AVCodecContext *avctx, void *datap,
*data_size = 0;
return -1;
}
if (*data_size < SUBFR_SIZE * mode_par->subframe_count * sizeof(float)) {
if (*data_size < subframe_size * mode_par->subframe_count * sizeof(float)) {
av_log(avctx, AV_LOG_ERROR,
"Error processing packet: output buffer (%d) too small\n",
*data_size);
Expand All @@ -542,12 +562,16 @@ static int sipr_decode_frame(AVCodecContext *avctx, void *datap,

for (i = 0; i < mode_par->frames_per_packet; i++) {
decode_parameters(&parm, &gb, mode_par);
decode_frame(ctx, &parm, data);

data += SUBFR_SIZE * mode_par->subframe_count;
if (ctx->mode == MODE_16k)
ff_sipr_decode_frame_16k(ctx, &parm, data);
else
decode_frame(ctx, &parm, data);

data += subframe_size * mode_par->subframe_count;
}

*data_size = mode_par->frames_per_packet * SUBFR_SIZE *
*data_size = mode_par->frames_per_packet * subframe_size *
mode_par->subframe_count * sizeof(float);

return mode_par->bits_per_frame >> 3;
Expand Down
28 changes: 26 additions & 2 deletions libavcodec/sipr.h
Expand Up @@ -28,6 +28,11 @@
#include "dsputil.h"
#include "acelp_pitch_delay.h"

#define LP_FILTER_ORDER_16k 16
#define L_SUBFR_16k 80
#define PITCH_MIN 30
#define PITCH_MAX 281

#define LSFQ_DIFF_MIN (0.0125 * M_PI)

#define LP_FILTER_ORDER 10
Expand All @@ -38,6 +43,8 @@
/** Subframe size for all modes except 16k */
#define SUBFR_SIZE 48

#define SUBFRAME_COUNT_16k 2

typedef enum {
MODE_16k,
MODE_8k5,
Expand All @@ -53,9 +60,9 @@ typedef struct {
SiprMode mode;

float past_pitch_gain;
float lsf_history[LP_FILTER_ORDER];
float lsf_history[LP_FILTER_ORDER_16k];

float excitation[L_INTERPOL + PITCH_DELAY_MAX + 5*SUBFR_SIZE];
float excitation[L_INTERPOL + PITCH_MAX + 2 * L_SUBFR_16k];

DECLARE_ALIGNED_16(float, synth_buf[LP_FILTER_ORDER + 5*SUBFR_SIZE + 6]);

Expand All @@ -70,14 +77,31 @@ typedef struct {
float postfilter_agc;
float postfilter_mem5k0[PITCH_DELAY_MAX + LP_FILTER_ORDER];
float postfilter_syn5k0[LP_FILTER_ORDER + SUBFR_SIZE*5];

/* 16k */
int pitch_lag_prev;
float iir_mem[LP_FILTER_ORDER_16k+1];
float filt_buf[2][LP_FILTER_ORDER_16k+1];
float *filt_mem[2];
float mem_preemph[LP_FILTER_ORDER_16k];
float synth[LP_FILTER_ORDER_16k];
double lsp_history_16k[16];
} SiprContext;

typedef struct {
int ma_pred_switch; ///< switched moving average predictor
int vq_indexes[5];
int pitch_delay[5]; ///< pitch delay
int gp_index[5]; ///< adaptive-codebook gain indexes
int16_t fc_indexes[5][10]; ///< fixed-codebook indexes
int gc_index[5]; ///< fixed-codebook gain indexes
} SiprParameters;

extern const float ff_pow_0_5[16];

void ff_sipr_init_16k(SiprContext *ctx);

void ff_sipr_decode_frame_16k(SiprContext *ctx, SiprParameters *params,
float *out_data);

#endif /* AVCODEC_SIPR_H */

0 comments on commit d140b02

Please sign in to comment.