diff options
author | jm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800> | 2007-01-02 16:37:37 +0300 |
---|---|---|
committer | jm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800> | 2007-01-02 16:37:37 +0300 |
commit | 576d051794478808a969940eea5df9853124f7fc (patch) | |
tree | 0a593f88d209cfae04636f657cb54141a897c430 /libspeex | |
parent | da7f92f056329230c36b0e6de9bc66a85b76dcb0 (diff) |
simplified the double_codebook code and improved accuracy slightly
git-svn-id: http://svn.xiph.org/trunk/speex@12290 0101bb08-14d6-0310-b084-bc0e0c8e3800
Diffstat (limited to 'libspeex')
-rw-r--r-- | libspeex/nb_celp.c | 82 |
1 files changed, 37 insertions, 45 deletions
diff --git a/libspeex/nb_celp.c b/libspeex/nb_celp.c index f8928d5..e37f0ef 100644 --- a/libspeex/nb_celp.c +++ b/libspeex/nb_celp.c @@ -961,11 +961,6 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) for (i=0;i<st->subframeSize;i++) exc[i] = EXTRACT16(SATURATE32(PSHR32(ADD32(SHL32(exc32[i],1),innov[i]),SIG_SHIFT),32767)); - if (innov_save) - { - for (i=0;i<st->subframeSize;i++) - innov_save[i] = EXTRACT16(PSHR32(innov[i],SIG_SHIFT)); - } /* In some (rare) modes, we do a second search (more bits) to reduce noise even more */ if (SUBMODE(double_codebook)) { char *tmp_stack=stack; @@ -980,14 +975,16 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) innov2, syn_resp, bits, stack, st->complexity, 0); signal_mul(innov2, innov2, MULT16_32_Q15(QCONST16(0.454545f,15),ener), st->subframeSize); for (i=0;i<st->subframeSize;i++) - exc[i] = ADD32(exc[i],PSHR32(innov2[i],SIG_SHIFT)); - if (innov_save) - { - for (i=0;i<st->subframeSize;i++) - innov_save[i] = ADD16(innov_save[i],EXTRACT16(PSHR32(innov2[i],SIG_SHIFT))); - } + innov[i] = ADD32(innov[i],innov2[i]); stack = tmp_stack; } + for (i=0;i<st->subframeSize;i++) + exc[i] = EXTRACT16(SATURATE32(PSHR32(ADD32(SHL32(exc32[i],1),innov[i]),SIG_SHIFT),32767)); + if (innov_save) + { + for (i=0;i<st->subframeSize;i++) + innov_save[i] = EXTRACT16(PSHR32(innov[i],SIG_SHIFT)); + } } else { speex_error("No fixed codebook"); } @@ -1575,16 +1572,38 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) { /*Fixed codebook contribution*/ SUBMODE(innovation_unquant)(innov, SUBMODE(innovation_params), st->subframeSize, bits, stack, &st->seed); + /* De-normalize innovation and update excitation */ +#ifdef FIXED_POINT + signal_mul(innov, innov, ener, st->subframeSize); +#else + signal_mul(innov, innov, ener, st->subframeSize); +#endif + /* Decode second codebook (only for some modes) */ + if (SUBMODE(double_codebook)) + { + char *tmp_stack=stack; + VARDECL(spx_sig_t *innov2); + ALLOC(innov2, st->subframeSize, spx_sig_t); + for (i=0;i<st->subframeSize;i++) + innov2[i]=0; + SUBMODE(innovation_unquant)(innov2, SUBMODE(innovation_params), st->subframeSize, bits, stack, &st->seed); + signal_mul(innov2, innov2, MULT16_32_Q15(QCONST16(0.454545f,15),ener), st->subframeSize); + for (i=0;i<st->subframeSize;i++) + innov[i] = ADD32(innov[i], innov2[i]); + stack = tmp_stack; + } + for (i=0;i<st->subframeSize;i++) + exc[i]=EXTRACT16(SATURATE32(PSHR32(ADD32(SHL32(exc32[i],1),innov[i]),SIG_SHIFT),32767)); + /*print_vec(exc, 40, "innov");*/ + if (innov_save) + { + for (i=0;i<st->subframeSize;i++) + innov_save[i] = EXTRACT16(PSHR32(innov[i], SIG_SHIFT)); + } } else { speex_error("No fixed codebook"); } - /* De-normalize innovation and update excitation */ -#ifdef FIXED_POINT - signal_mul(innov, innov, ener, st->subframeSize); -#else - signal_mul(innov, innov, ener, st->subframeSize); -#endif /*Vocoder mode*/ if (st->submodeID==1) { @@ -1616,35 +1635,8 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) st->voc_mean = .95*st->voc_mean + .05*exc[i]; exc[i]-=st->voc_mean; } - } else { - for (i=0;i<st->subframeSize;i++) - exc[i]=EXTRACT16(SATURATE32(PSHR32(ADD32(SHL32(exc32[i],1),innov[i]),SIG_SHIFT),32767)); - /*print_vec(exc, 40, "innov");*/ - } - if (innov_save) - { - for (i=0;i<st->subframeSize;i++) - innov_save[i] = EXTRACT16(PSHR32(innov[i], SIG_SHIFT)); - } - /* Decode second codebook (only for some modes) */ - if (SUBMODE(double_codebook)) - { - char *tmp_stack=stack; - VARDECL(spx_sig_t *innov2); - ALLOC(innov2, st->subframeSize, spx_sig_t); - for (i=0;i<st->subframeSize;i++) - innov2[i]=0; - SUBMODE(innovation_unquant)(innov2, SUBMODE(innovation_params), st->subframeSize, bits, stack, &st->seed); - signal_mul(innov2, innov2, MULT16_32_Q15(QCONST16(0.454545f,15),ener), st->subframeSize); - for (i=0;i<st->subframeSize;i++) - exc[i] = EXTRACT16(SATURATE32(ADD32(EXTEND32(exc[i]),PSHR32(innov2[i],SIG_SHIFT)),32767)); - if (innov_save) - { - for (i=0;i<st->subframeSize;i++) - innov_save[i] = ADD16(innov_save[i],EXTRACT16(PSHR32(innov2[i], SIG_SHIFT))); - } - stack = tmp_stack; } + } } |