diff options
author | Jean-Marc Valin <jeval@station513.(none)> | 2008-08-05 20:00:05 +0400 |
---|---|---|
committer | Jean-Marc Valin <jeval@station513.(none)> | 2008-08-05 20:00:05 +0400 |
commit | 8d225323179a4642c58df0466beb960b0b367f29 (patch) | |
tree | a75970982017c8f9d1665ddbb797d87ab6405c69 /libspeex | |
parent | 785e61a593c61ebc0afee5d87eca9cc73e16d6a6 (diff) |
Narrowband state now contained in a single block
Diffstat (limited to 'libspeex')
-rw-r--r-- | libspeex/modes.c | 14 | ||||
-rw-r--r-- | libspeex/nb_celp.c | 65 | ||||
-rw-r--r-- | libspeex/nb_celp.h | 46 |
3 files changed, 47 insertions, 78 deletions
diff --git a/libspeex/modes.c b/libspeex/modes.c index e10a32e..c873b0e 100644 --- a/libspeex/modes.c +++ b/libspeex/modes.c @@ -318,15 +318,15 @@ static const SpeexSubmode nb_submode7 = { /* Default mode for narrowband */ static const SpeexNBMode nb_mode = { - 160, /*frameSize*/ - 40, /*subframeSize*/ - 10, /*lpcSize*/ - 17, /*pitchStart*/ - 144, /*pitchEnd*/ + NB_FRAME_SIZE, /*frameSize*/ + NB_SUBFRAME_SIZE, /*subframeSize*/ + NB_ORDER, /*lpcSize*/ + NB_PITCH_START, /*pitchStart*/ + NB_PITCH_END, /*pitchEnd*/ #ifdef FIXED_POINT - 29491, 19661, /* gamma1, gamma2 */ + 29491, 19661, /* gamma1, gamma2 */ #else - 0.9, 0.6, /* gamma1, gamma2 */ + 0.9, 0.6, /* gamma1, gamma2 */ #endif QCONST16(.0002,15), /*lpc_floor*/ {NULL, &nb_submode1, &nb_submode2, &nb_submode3, &nb_submode4, &nb_submode5, &nb_submode6, &nb_submode7, diff --git a/libspeex/nb_celp.c b/libspeex/nb_celp.c index b13960a..98537c6 100644 --- a/libspeex/nb_celp.c +++ b/libspeex/nb_celp.c @@ -132,7 +132,7 @@ void *nb_encoder_init(const SpeexMode *m) st->frameSize = mode->frameSize; st->nbSubframes=mode->frameSize/mode->subframeSize; st->subframeSize=mode->subframeSize; - st->windowSize = st->frameSize+st->subframeSize; + st->windowSize = NB_WINDOW_SIZE; st->lpcSize = mode->lpcSize; st->gamma1=mode->gamma1; st->gamma2=mode->gamma2; @@ -155,39 +155,19 @@ void *nb_encoder_init(const SpeexMode *m) st->cumul_gain = 1024; - /* Allocating input buffer */ - st->winBuf = (spx_word16_t*)speex_alloc((st->windowSize-st->frameSize)*sizeof(spx_word16_t)); - /* Allocating excitation buffer */ - st->excBuf = (spx_word16_t*)speex_alloc((mode->frameSize+mode->pitchEnd+2)*sizeof(spx_word16_t)); - st->exc = st->excBuf + mode->pitchEnd + 2; - st->swBuf = (spx_word16_t*)speex_alloc((mode->frameSize+mode->pitchEnd+2)*sizeof(spx_word16_t)); - st->sw = st->swBuf + mode->pitchEnd + 2; - st->window= lpc_window; /* Create the window for autocorrelation (lag-windowing) */ st->lagWindow = lag_window; - st->old_lsp = (spx_lsp_t*)speex_alloc((st->lpcSize)*sizeof(spx_lsp_t)); - st->old_qlsp = (spx_lsp_t*)speex_alloc((st->lpcSize)*sizeof(spx_lsp_t)); st->first = 1; for (i=0;i<st->lpcSize;i++) st->old_lsp[i]= DIV32(MULT16_16(QCONST16(3.1415927f, LSP_SHIFT), i+1), st->lpcSize+1); - st->mem_sp = (spx_mem_t*)speex_alloc((st->lpcSize)*sizeof(spx_mem_t)); - st->mem_sw = (spx_mem_t*)speex_alloc((st->lpcSize)*sizeof(spx_mem_t)); - st->mem_sw_whole = (spx_mem_t*)speex_alloc((st->lpcSize)*sizeof(spx_mem_t)); - st->mem_exc = (spx_mem_t*)speex_alloc((st->lpcSize)*sizeof(spx_mem_t)); - st->mem_exc2 = (spx_mem_t*)speex_alloc((st->lpcSize)*sizeof(spx_mem_t)); - - st->pi_gain = (spx_word32_t*)speex_alloc((st->nbSubframes)*sizeof(spx_word32_t)); st->innov_rms_save = NULL; - st->pitch = (int*)speex_alloc((st->nbSubframes)*sizeof(int)); - #ifndef DISABLE_VBR - st->vbr = (VBRState*)speex_alloc(sizeof(VBRState)); - vbr_init(st->vbr); + vbr_init(&st->vbr); st->vbr_quality = 8; st->vbr_enabled = 0; st->vbr_max = 0; @@ -219,23 +199,8 @@ void nb_encoder_destroy(void *state) speex_free_scratch(st->stack); #endif - speex_free (st->winBuf); - speex_free (st->excBuf); - speex_free (st->old_qlsp); - speex_free (st->swBuf); - - speex_free (st->old_lsp); - speex_free (st->mem_sp); - speex_free (st->mem_sw); - speex_free (st->mem_sw_whole); - speex_free (st->mem_exc); - speex_free (st->mem_exc2); - speex_free (st->pi_gain); - speex_free (st->pitch); - #ifndef DISABLE_VBR - vbr_destroy(st->vbr); - speex_free (st->vbr); + vbr_destroy(&st->vbr); #endif /* #ifndef DISABLE_VBR */ #ifdef VORBIS_PSYCHO @@ -291,6 +256,8 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) ALLOC(interp_lpc, st->lpcSize, spx_coef_t); ALLOC(interp_qlpc, st->lpcSize, spx_coef_t); + st->exc = st->excBuf + st->max_pitch + 2; + st->sw = st->swBuf + st->max_pitch + 2; /* Move signals 1 frame towards the past */ SPEEX_MOVE(st->excBuf, st->excBuf+st->frameSize, st->max_pitch+2); SPEEX_MOVE(st->swBuf, st->swBuf+st->frameSize, st->max_pitch+2); @@ -421,7 +388,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) /*VBR stuff*/ #ifndef DISABLE_VBR - if (st->vbr && (st->vbr_enabled||st->vad_enabled)) + if (st->vbr_enabled||st->vad_enabled) { float lsp_dist=0; for (i=0;i<st->lpcSize;i++) @@ -447,7 +414,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) st->vbr_quality=0; } - st->relative_quality = vbr_analysis(st->vbr, in, st->frameSize, ol_pitch, GAIN_SCALING_1*ol_pitch_coef); + st->relative_quality = vbr_analysis(&st->vbr, in, st->frameSize, ol_pitch, GAIN_SCALING_1*ol_pitch_coef); /*if (delta_qual<0)*/ /* delta_qual*=.1*(3+st->vbr_quality);*/ if (st->vbr_enabled) @@ -956,14 +923,8 @@ void *nb_decoder_init(const SpeexMode *m) st->lpc_enh_enabled=1; - st->excBuf = (spx_word16_t*)speex_alloc((st->frameSize + 2*st->max_pitch + st->subframeSize + 12)*sizeof(spx_word16_t)); - st->exc = st->excBuf + 2*st->max_pitch + st->subframeSize + 6; SPEEX_MEMSET(st->excBuf, 0, st->frameSize + st->max_pitch); - st->interp_qlpc = (spx_coef_t*)speex_alloc(st->lpcSize*sizeof(spx_coef_t)); - st->old_qlsp = (spx_lsp_t*)speex_alloc(st->lpcSize*sizeof(spx_lsp_t)); - st->mem_sp = (spx_mem_t*)speex_alloc(st->lpcSize*sizeof(spx_mem_t)); - st->pi_gain = (spx_word32_t*)speex_alloc((st->nbSubframes)*sizeof(spx_word32_t)); st->last_pitch = 40; st->count_lost=0; st->pitch_gain_buf[0] = st->pitch_gain_buf[1] = st->pitch_gain_buf[2] = 0; @@ -999,12 +960,6 @@ void nb_decoder_destroy(void *state) speex_free_scratch(st->stack); #endif - speex_free (st->excBuf); - speex_free (st->interp_qlpc); - speex_free (st->old_qlsp); - speex_free (st->mem_sp); - speex_free (st->pi_gain); - speex_free(state); } @@ -1026,7 +981,9 @@ static void nb_decode_lost(DecState *st, spx_word16_t *out, char *stack) spx_word16_t gain_med; spx_word16_t innov_gain; spx_word16_t noise_gain; - + + st->exc = st->excBuf + 2*st->max_pitch + st->subframeSize + 6; + if (st->count_lost<10) fact = attenuation[st->count_lost]; else @@ -1106,6 +1063,8 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) st=(DecState*)state; stack=st->stack; + st->exc = st->excBuf + 2*st->max_pitch + st->subframeSize + 6; + /* Check if we're in DTX mode*/ if (!bits && st->dtx_enabled) { diff --git a/libspeex/nb_celp.h b/libspeex/nb_celp.h index 3fecab6..37cd283 100644 --- a/libspeex/nb_celp.h +++ b/libspeex/nb_celp.h @@ -46,6 +46,16 @@ #include "vorbis_psy.h" #endif +#define NB_ORDER 10 +#define NB_FRAME_SIZE 160 +#define NB_SUBFRAME_SIZE 40 +#define NB_NB_SUBFRAMES 4 +#define NB_PITCH_START 17 +#define NB_PITCH_END 144 + +#define NB_WINDOW_SIZE (NB_FRAME_SIZE+NB_SUBFRAME_SIZE) +#define NB_EXCBUF (NB_FRAME_SIZE+NB_PITCH_END+2) +#define NB_DEC_BUFFER (NB_FRAME_SIZE+2*NB_PITCH_END+NB_SUBFRAME_SIZE+12) /**Structure representing the full state of the narrowband encoder*/ typedef struct EncState { const SpeexMode *mode; /**< Mode corresponding to the state */ @@ -62,7 +72,7 @@ typedef struct EncState { int bounded_pitch; /**< Next frame should not rely on previous frames for pitch */ int ol_pitch; /**< Open-loop pitch */ int ol_voiced; /**< Open-loop voiced/non-voiced decision */ - int *pitch; + int pitch[NB_NB_SUBFRAMES]; #ifdef VORBIS_PSYCHO VorbisPsy *psy; @@ -75,26 +85,26 @@ typedef struct EncState { spx_word16_t gamma2; /**< Perceptual filter: A(z/gamma2) */ spx_word16_t lpc_floor; /**< Noise floor multiplier for A[0] in LPC analysis*/ char *stack; /**< Pseudo-stack allocation for temporary memory */ - spx_word16_t *winBuf; /**< Input buffer (original signal) */ - spx_word16_t *excBuf; /**< Excitation buffer */ + spx_word16_t winBuf[NB_WINDOW_SIZE-NB_FRAME_SIZE]; /**< Input buffer (original signal) */ + spx_word16_t excBuf[NB_EXCBUF]; /**< Excitation buffer */ spx_word16_t *exc; /**< Start of excitation frame */ - spx_word16_t *swBuf; /**< Weighted signal buffer */ + spx_word16_t swBuf[NB_EXCBUF]; /**< Weighted signal buffer */ spx_word16_t *sw; /**< Start of weighted signal frame */ const spx_word16_t *window; /**< Temporary (Hanning) window */ const spx_word16_t *lagWindow; /**< Window applied to auto-correlation */ - spx_lsp_t *old_lsp; /**< LSPs for previous frame */ - spx_lsp_t *old_qlsp; /**< Quantized LSPs for previous frame */ - spx_mem_t *mem_sp; /**< Filter memory for signal synthesis */ - spx_mem_t *mem_sw; /**< Filter memory for perceptually-weighted signal */ - spx_mem_t *mem_sw_whole; /**< Filter memory for perceptually-weighted signal (whole frame)*/ - spx_mem_t *mem_exc; /**< Filter memory for excitation (whole frame) */ - spx_mem_t *mem_exc2; /**< Filter memory for excitation (whole frame) */ + spx_lsp_t old_lsp[NB_ORDER]; /**< LSPs for previous frame */ + spx_lsp_t old_qlsp[NB_ORDER]; /**< Quantized LSPs for previous frame */ + spx_mem_t mem_sp[NB_ORDER]; /**< Filter memory for signal synthesis */ + spx_mem_t mem_sw[NB_ORDER]; /**< Filter memory for perceptually-weighted signal */ + spx_mem_t mem_sw_whole[NB_ORDER]; /**< Filter memory for perceptually-weighted signal (whole frame)*/ + spx_mem_t mem_exc[NB_ORDER]; /**< Filter memory for excitation (whole frame) */ + spx_mem_t mem_exc2[NB_ORDER]; /**< Filter memory for excitation (whole frame) */ spx_mem_t mem_hp[2]; /**< High-pass filter memory */ - spx_word32_t *pi_gain; /**< Gain of LPC filter at theta=pi (fe/2) */ + spx_word32_t pi_gain[NB_NB_SUBFRAMES]; /**< Gain of LPC filter at theta=pi (fe/2) */ spx_word16_t *innov_rms_save; /**< If non-NULL, innovation RMS is copied here */ #ifndef DISABLE_VBR - VBRState *vbr; /**< State of the VBR data */ + VBRState vbr; /**< State of the VBR data */ float vbr_quality; /**< Quality setting for VBR encoding */ float relative_quality; /**< Relative quality that will be needed by VBR */ spx_int32_t vbr_enabled; /**< 1 for enabling VBR, 0 otherwise */ @@ -135,13 +145,13 @@ typedef struct DecState { spx_word16_t last_ol_gain; /**< Open-loop gain for previous frame */ char *stack; /**< Pseudo-stack allocation for temporary memory */ - spx_word16_t *excBuf; /**< Excitation buffer */ + spx_word16_t excBuf[NB_DEC_BUFFER]; /**< Excitation buffer */ spx_word16_t *exc; /**< Start of excitation frame */ - spx_lsp_t *old_qlsp; /**< Quantized LSPs for previous frame */ - spx_coef_t *interp_qlpc; /**< Interpolated quantized LPCs */ - spx_mem_t *mem_sp; /**< Filter memory for synthesis signal */ + spx_lsp_t old_qlsp[NB_ORDER]; /**< Quantized LSPs for previous frame */ + spx_coef_t interp_qlpc[NB_ORDER]; /**< Interpolated quantized LPCs */ + spx_mem_t mem_sp[NB_ORDER]; /**< Filter memory for synthesis signal */ spx_mem_t mem_hp[2]; /**< High-pass filter memory */ - spx_word32_t *pi_gain; /**< Gain of LPC filter at theta=pi (fe/2) */ + spx_word32_t pi_gain[NB_NB_SUBFRAMES]; /**< Gain of LPC filter at theta=pi (fe/2) */ spx_word16_t *innov_save; /** If non-NULL, innovation is copied here */ spx_word16_t level; |