diff options
-rw-r--r-- | libspeex/fixed_debug.h | 14 | ||||
-rw-r--r-- | libspeex/nb_celp.c | 5 | ||||
-rw-r--r-- | libspeex/sb_celp.c | 76 | ||||
-rw-r--r-- | libspeex/sb_celp.h | 5 |
4 files changed, 36 insertions, 64 deletions
diff --git a/libspeex/fixed_debug.h b/libspeex/fixed_debug.h index bb8d475..6525f01 100644 --- a/libspeex/fixed_debug.h +++ b/libspeex/fixed_debug.h @@ -114,16 +114,17 @@ static inline short _SHR16(int a, int shift, char *file, int line) spx_mips++; return res; } -static inline short SHL16(int a, int shift) +#define SHL16(a, shift) _SHL16(a, shift, __FILE__, __LINE__) +static inline short _SHL16(int a, int shift, char *file, int line) { int res; if (!VERIFY_SHORT(a) || !VERIFY_SHORT(shift)) { - fprintf (stderr, "SHL16: inputs are not short: %d %d\n", a, shift); + fprintf (stderr, "SHL16: inputs are not short: %d %d in %s: line %d\n", a, shift, file, line); } res = a<<shift; if (!VERIFY_SHORT(res)) - fprintf (stderr, "SHL16: output is not short: %d\n", res); + fprintf (stderr, "SHL16: output is not short: %d in %s: line %d\n", res, file, line); spx_mips++; return res; } @@ -201,17 +202,18 @@ static inline short _SUB16(int a, int b, char *file, int line) return res; } -static inline int ADD32(long long a, long long b) +#define ADD32(a, b) _ADD32(a, b, __FILE__, __LINE__) +static inline int _ADD32(long long a, long long b, char *file, int line) { long long res; if (!VERIFY_INT(a) || !VERIFY_INT(b)) { - fprintf (stderr, "ADD32: inputs are not int: %d %d\n", (int)a, (int)b); + fprintf (stderr, "ADD32: inputs are not int: %d %d in %s: line %d\n", (int)a, (int)b, file, line); } res = a+b; if (!VERIFY_INT(res)) { - fprintf (stderr, "ADD32: output is not int: %d\n", (int)res); + fprintf (stderr, "ADD32: output is not int: %d in %s: line %d\n", (int)res, file, line); } spx_mips++; return res; diff --git a/libspeex/nb_celp.c b/libspeex/nb_celp.c index f70b7da..605e71e 100644 --- a/libspeex/nb_celp.c +++ b/libspeex/nb_celp.c @@ -2035,9 +2035,8 @@ int nb_decoder_ctl(void *state, int request, void *ptr) case SPEEX_GET_EXC: { int i; - spx_word16_t *e = (spx_word16_t*)ptr; - for (i=0;i<st->frameSize;i++) - e[i]=st->exc[i]; + for (i=0;i<st->nbSubframes;i++) + ((spx_word16_t*)ptr)[i] = compute_rms16(st->exc+i*st->subframeSize, st->subframeSize); } break; case SPEEX_GET_DTX_STATUS: diff --git a/libspeex/sb_celp.c b/libspeex/sb_celp.c index fe4e830..2818470 100644 --- a/libspeex/sb_celp.c +++ b/libspeex/sb_celp.c @@ -716,7 +716,7 @@ int sb_encode(void *state, void *vin, SpeexBits *bits) if (st->innov_save) { for (i=0;i<st->subframeSize;i++) - innov_save[2*i]=innov[i]; + innov_save[2*i]=EXTRACT16(SHR32(innov[i],SIG_SHIFT)); } if (SUBMODE(double_codebook)) { @@ -808,8 +808,7 @@ void *sb_decoder_init(const SpeexMode *m) st->g0_mem = (spx_word32_t*)speex_alloc((QMF_ORDER)*sizeof(spx_word32_t)); st->g1_mem = (spx_word32_t*)speex_alloc((QMF_ORDER)*sizeof(spx_word32_t)); - st->exc = (spx_sig_t*)speex_alloc((st->frame_size)*sizeof(spx_sig_t)); - st->excBuf = (spx_sig_t*)speex_alloc((st->subframeSize)*sizeof(spx_sig_t)); + st->excBuf = (spx_word16_t*)speex_alloc((st->subframeSize)*sizeof(spx_word16_t)); st->qlsp = (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)); @@ -817,6 +816,7 @@ void *sb_decoder_init(const SpeexMode *m) st->interp_qlpc = (spx_coef_t*)speex_alloc(st->lpcSize*sizeof(spx_coef_t)); st->pi_gain = (spx_word32_t*)speex_alloc((st->nbSubframes)*sizeof(spx_word32_t)); + st->exc_rms = (spx_word16_t*)speex_alloc((st->nbSubframes)*sizeof(spx_word16_t)); st->mem_sp = (spx_mem_t*)speex_alloc((2*st->lpcSize)*sizeof(spx_mem_t)); st->low_innov = (spx_word16_t*)speex_alloc((st->frame_size)*sizeof(spx_word16_t)); @@ -844,13 +844,13 @@ void sb_decoder_destroy(void *state) speex_free(st->g0_mem); speex_free(st->g1_mem); - speex_free(st->exc); speex_free(st->excBuf); speex_free(st->qlsp); speex_free(st->old_qlsp); speex_free(st->interp_qlsp); speex_free(st->interp_qlpc); speex_free(st->pi_gain); + speex_free(st->exc_rms); speex_free(st->low_innov); speex_free(st->mem_sp); @@ -876,14 +876,10 @@ static void sb_decode_lost(SBDecState *st, spx_word16_t *out, int dtx, char *sta /* Final signal synthesis from excitation */ if (!dtx) { - spx_word16_t low_ener; - low_ener = .9*compute_rms(st->exc, st->frame_size); - for (i=0;i<st->frame_size;i++) - st->exc[i] = speex_rand(low_ener, &st->seed); + st->last_ener = MULT16_16_Q15(QCONST16(.9f,15),st->last_ener); } - for (i=0;i<st->frame_size;i++) - out[i+st->frame_size]=EXTRACT16(PSHR32(st->exc[i],SIG_SHIFT)); + out[i+st->frame_size] = speex_rand(st->last_ener, &st->seed); iir_mem16(out+st->frame_size, st->interp_qlpc, out+st->frame_size, st->frame_size, st->lpcSize, st->mem_sp, stack); @@ -907,7 +903,7 @@ int sb_decode(void *state, SpeexBits *bits, void *vout) int ret; char *stack; VARDECL(spx_word32_t *low_pi_gain); - VARDECL(spx_word16_t *low_exc); + VARDECL(spx_word16_t *low_exc_rms); VARDECL(spx_coef_t *ak); spx_int32_t dtx; const SpeexSBMode *mode; @@ -969,8 +965,6 @@ int sb_decode(void *state, SpeexBits *bits, void *vout) } for (i=0;i<st->frame_size;i++) - st->exc[i]=VERY_SMALL; - for (i=0;i<st->frame_size;i++) out[st->frame_size+i]=VERY_SMALL; st->first=1; @@ -984,13 +978,10 @@ int sb_decode(void *state, SpeexBits *bits, void *vout) } - for (i=0;i<st->frame_size;i++) - st->exc[i]=0; - ALLOC(low_pi_gain, st->nbSubframes, spx_word32_t); - ALLOC(low_exc, st->frame_size, spx_word16_t); + ALLOC(low_exc_rms, st->nbSubframes, spx_word16_t); speex_decoder_ctl(st->st_low, SPEEX_GET_PI_GAIN, low_pi_gain); - speex_decoder_ctl(st->st_low, SPEEX_GET_EXC, low_exc); + speex_decoder_ctl(st->st_low, SPEEX_GET_EXC, low_exc_rms); SUBMODE(lsp_unquant)(st->qlsp, st->lpcSize, bits); @@ -1004,7 +995,7 @@ int sb_decode(void *state, SpeexBits *bits, void *vout) for (sub=0;sub<st->nbSubframes;sub++) { - spx_sig_t *exc; + VARDECL(spx_word32_t *exc); spx_word16_t *innov_save=NULL; spx_word16_t *sp; spx_word16_t filter_ratio; @@ -1014,7 +1005,7 @@ int sb_decode(void *state, SpeexBits *bits, void *vout) offset = st->subframeSize*sub; sp=out+st->frame_size+offset; - exc=st->exc+offset; + ALLOC(exc, st->subframeSize, spx_word32_t); /* Pointer for saving innovation */ if (st->innov_save) { @@ -1093,9 +1084,8 @@ int sb_decode(void *state, SpeexBits *bits, void *vout) spx_word16_t gc; spx_word32_t scale; int qgc = speex_bits_unpack_unsigned(bits, 4); - - el = compute_rms16(low_exc+offset, st->subframeSize); - + + el = low_exc_rms[sub]; #ifdef FIXED_POINT gc = MULT16_32_Q15(28626,gc_quant_bound[qgc]); #else @@ -1132,20 +1122,22 @@ int sb_decode(void *state, SpeexBits *bits, void *vout) if (st->innov_save) { for (i=0;i<st->subframeSize;i++) - innov_save[2*i]=exc[i]; + innov_save[2*i]=EXTRACT16(PSHR32(exc[i],SIG_SHIFT)); } for (i=0;i<st->subframeSize;i++) - sp[i]=EXTRACT16(PSHR32(st->excBuf[i],SIG_SHIFT)); + sp[i]=st->excBuf[i]; iir_mem16(sp, st->interp_qlpc, sp, st->subframeSize, st->lpcSize, st->mem_sp, stack); for (i=0;i<st->subframeSize;i++) - st->excBuf[i]=exc[i]; + st->excBuf[i]=EXTRACT16(PSHR32(exc[i],SIG_SHIFT)); for (i=0;i<st->lpcSize;i++) st->interp_qlpc[i] = ak[i]; + st->exc_rms[sub] = compute_rms16(st->excBuf, st->subframeSize); } - + st->last_ener = compute_rms16(out+st->frame_size, st->frame_size); + qmf_synth(out, out+st->frame_size, h0, out, st->full_frame_size, QMF_ORDER, st->g0_mem, st->g1_mem, stack); for (i=0;i<st->lpcSize;i++) st->old_qlsp[i] = st->qlsp[i]; @@ -1383,17 +1375,7 @@ int sb_encoder_ctl(void *state, int request, void *ptr) case SPEEX_GET_EXC: { int i; - spx_sig_t *e = (spx_sig_t*)ptr; - for (i=0;i<st->full_frame_size;i++) - e[i]=0; - for (i=0;i<st->frame_size;i++) - e[2*i]=2*st->exc[i]; - } - break; - case SPEEX_GET_INNOV: - { - int i; - spx_sig_t *e = (spx_sig_t*)ptr; + spx_word16_t *e = (spx_word16_t*)ptr; for (i=0;i<st->full_frame_size;i++) e[i]=0; for (i=0;i<st->frame_size;i++) @@ -1487,6 +1469,7 @@ int sb_decoder_ctl(void *state, int request, void *ptr) st->mem_sp[i]=0; for (i=0;i<QMF_ORDER;i++) st->g0_mem[i]=st->g1_mem[i]=0; + st->last_ener=0; } break; case SPEEX_SET_SUBMODE_ENCODING: @@ -1518,21 +1501,8 @@ int sb_decoder_ctl(void *state, int request, void *ptr) case SPEEX_GET_EXC: { int i; - spx_sig_t *e = (spx_sig_t*)ptr; - for (i=0;i<st->full_frame_size;i++) - e[i]=0; - for (i=0;i<st->frame_size;i++) - e[2*i]=2*st->exc[i]; - } - break; - case SPEEX_GET_INNOV: - { - int i; - spx_sig_t *e = (spx_sig_t*)ptr; - for (i=0;i<st->full_frame_size;i++) - e[i]=0; - for (i=0;i<st->frame_size;i++) - e[2*i]=2*st->exc[i]; + for (i=0;i<st->nbSubframes;i++) + ((spx_word16_t*)ptr)[i] = st->exc_rms[i]; } break; case SPEEX_GET_DTX_STATUS: diff --git a/libspeex/sb_celp.h b/libspeex/sb_celp.h index a40c98d..4bc40af 100644 --- a/libspeex/sb_celp.h +++ b/libspeex/sb_celp.h @@ -126,8 +126,7 @@ typedef struct SBDecState { char *stack; spx_word32_t *g0_mem, *g1_mem; - spx_sig_t *exc; - spx_sig_t *excBuf; + spx_word16_t *excBuf; spx_lsp_t *qlsp; spx_lsp_t *old_qlsp; spx_lsp_t *interp_qlsp; @@ -135,9 +134,11 @@ typedef struct SBDecState { spx_mem_t *mem_sp; spx_word32_t *pi_gain; + spx_word16_t *exc_rms; spx_word16_t *innov_save; /** If non-NULL, innovation is copied here */ spx_word16_t *low_innov; /** Lower-band innovation is copied here magically */ + spx_word16_t last_ener; spx_int32_t seed; int encode_submode; |