diff options
author | Jean-Marc Valin <jean-marc.valin@usherbrooke.ca> | 2011-02-21 22:05:10 +0300 |
---|---|---|
committer | Jean-Marc Valin <jean-marc.valin@usherbrooke.ca> | 2011-02-21 22:05:10 +0300 |
commit | de32a5bf617f782f6a478c5cd50fb040b0fbffe9 (patch) | |
tree | ece1ca49b3ab97ff3c0aecb8fed4146585d0cc00 | |
parent | e3de5057b6a24905f0c86bc5155e90d859ba86d9 (diff) |
Splitting the resampler buffering between encode and decode
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/opus_decoder.c | 27 | ||||
-rw-r--r-- | src/opus_decoder.h | 4 | ||||
-rw-r--r-- | src/opus_encoder.h | 2 |
4 files changed, 30 insertions, 5 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 03a48da5..e51b55c4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,5 +1,5 @@ -INCLUDES = -I$(top_srcdir)/celt/libcelt/ -I$(top_srcdir)/silk/interface +INCLUDES = -I$(top_srcdir)/celt/libcelt/ -I$(top_srcdir)/silk/interface -I$(top_srcdir)/silk/src_SigProc_FIX lib_LTLIBRARIES = libietfcodec.la libietfcodec_la_SOURCES = opus_decoder.c opus_encoder.c diff --git a/src/opus_decoder.c b/src/opus_decoder.c index 41671ebe..18f7319b 100644 --- a/src/opus_decoder.c +++ b/src/opus_decoder.c @@ -36,7 +36,7 @@ #include "entdec.h" #include "modes.h" #include "SKP_Silk_SDK_API.h" - +#include "SKP_Silk_SigProc_FIX.h" OpusDecoder *opus_decoder_create(int Fs, int channels) { @@ -166,6 +166,12 @@ int opus_decode(OpusDecoder *st, const unsigned char *data, DecControl.internalSampleRate = 16000; } + if (transition) + { + /*SKP_Silk_resampler_state_struct state; + SKP_Silk_resampler_init( &state, st->Fs, 16000); + */ + } lost_flag = data == NULL ? 1 : 2 * decode_fec; decoded_samples = 0; do { @@ -219,8 +225,23 @@ int opus_decode(OpusDecoder *st, const unsigned char *data, celt_decoder_ctl(st->celt_dec, CELT_RESET_STATE); /* Decode CELT */ celt_ret = celt_decode_with_ec(st->celt_dec, decode_fec?NULL:data, len, pcm_celt, frame_size, &dec); - for (i=0;i<frame_size*st->channels;i++) - pcm[i] = ADD_SAT16(pcm[i], pcm_celt[i]); + /* Mix and add resampler delay compensation to CELT */ + for (i=0;i<DECODER_DELAY*st->channels;i++) + pcm[i] = ADD_SAT16(pcm[i], st->delay_buffer[i+(DECODER_BUFFER-DECODER_DELAY)*st->channels]); + for (;i<frame_size*st->channels;i++) + pcm[i] = ADD_SAT16(pcm[i], pcm_celt[i-DECODER_DELAY*st->channels]); + + if (frame_size>DECODER_BUFFER) + { + for (i=0;i<DECODER_BUFFER*st->channels;i++) + st->delay_buffer[i] = pcm_celt[(frame_size-DECODER_BUFFER)*st->channels+i]; + } else { + int tmp = DECODER_BUFFER-frame_size; + for (i=0;i<tmp*st->channels;i++) + st->delay_buffer[i] = st->delay_buffer[i+frame_size*st->channels]; + for (i=0;i<frame_size*st->channels;i++) + st->delay_buffer[tmp*st->channels+i] = pcm_celt[i]; + } } if (transition) diff --git a/src/opus_decoder.h b/src/opus_decoder.h index 1b0569c2..fd27fe1b 100644 --- a/src/opus_decoder.h +++ b/src/opus_decoder.h @@ -31,6 +31,9 @@ #include "celt.h" #include "opus.h" +#define DECODER_DELAY 5 +#define DECODER_BUFFER 120 + struct OpusDecoder { CELTDecoder *celt_dec; void *silk_dec; @@ -42,6 +45,7 @@ struct OpusDecoder { int Fs; int prev_mode; + short delay_buffer[DECODER_BUFFER*2]; #ifdef OPUS_TEST_RANGE_CODER_STATE int rangeFinal; #endif diff --git a/src/opus_encoder.h b/src/opus_encoder.h index a800a747..9cdab6c2 100644 --- a/src/opus_encoder.h +++ b/src/opus_encoder.h @@ -33,7 +33,7 @@ #include "SKP_Silk_SDK_API.h" /* FIXME: This is only valid for 48 kHz */ -#define ENCODER_DELAY_COMPENSATION 130 +#define ENCODER_DELAY_COMPENSATION 125 #define ENCODER_BUFFER 480 struct OpusEncoder { |