Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/speexdsp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800>2006-11-18 01:37:39 +0300
committerjm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800>2006-11-18 01:37:39 +0300
commitd4695483ae0908ac2dffb9e2de773b6416db37ea (patch)
treefa48ec2c95db86f99dbc725573ecc73456101cdf /libspeex/nb_celp.c
parentfc6dd4004006d66a7a1c3ea811b748a01a6388c6 (diff)
Third (hopefully last) set of fixes for the overflow problem on clipped input.
git-svn-id: http://svn.xiph.org/trunk/speex@12130 0101bb08-14d6-0310-b084-bc0e0c8e3800
Diffstat (limited to 'libspeex/nb_celp.c')
-rw-r--r--libspeex/nb_celp.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/libspeex/nb_celp.c b/libspeex/nb_celp.c
index 0a13c2e..be56770 100644
--- a/libspeex/nb_celp.c
+++ b/libspeex/nb_celp.c
@@ -838,9 +838,9 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
for (i=0;i<st->lpcSize;i++)
st->mem_sw[i]=mem[i];
- /* Compute target signal */
+ /* Compute target signal (saturation prevents overflows on clipped input speech) */
for (i=0;i<st->subframeSize;i++)
- target[i]=SUB16(sw[i],PSHR32(ringing[i],1));
+ target[i]=EXTRACT16(SATURATE(SUB32(sw[i],PSHR32(ringing[i],1)),32767));
/* Reset excitation */
for (i=0;i<st->subframeSize;i++)
@@ -908,8 +908,9 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
for (i=0;i<st->subframeSize;i++)
innov[i]=0;
+ /* FIXME: Make sure this is save from overflows (so far so good) */
for (i=0;i<st->subframeSize;i++)
- real_exc[i] = SUB16(real_exc[i], PSHR32(exc32[i],SIG_SHIFT-1));
+ real_exc[i] = SUB16(real_exc[i], EXTRACT16(PSHR32(exc32[i],SIG_SHIFT-1)));
ener = SHL32(EXTEND32(compute_rms16(real_exc, st->subframeSize)),SIG_SHIFT);
@@ -960,7 +961,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits)
signal_mul(innov, innov, ener, st->subframeSize);
for (i=0;i<st->subframeSize;i++)
- exc[i] = EXTRACT16(PSHR32(ADD32(SHL32(exc32[i],1),innov[i]),SIG_SHIFT));
+ exc[i] = EXTRACT16(SATURATE32(PSHR32(ADD32(SHL32(exc32[i],1),innov[i]),SIG_SHIFT),32767));
} else {
speex_error("No fixed codebook");
}
@@ -1426,6 +1427,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout)
int qe;
qe = speex_bits_unpack_unsigned(bits, 5);
#ifdef FIXED_POINT
+ /* FIXME: Perhaps we could slightly lower the gain here when the output is going to saturate? */
ol_gain = MULT16_32_Q15(28406,ol_gain_table[qe]);
#else
ol_gain = SIG_SCALING*exp(qe/3.5);
@@ -1638,7 +1640,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout)
SUBMODE(innovation_unquant)(innov2, SUBMODE(innovation_params), st->subframeSize, bits, stack, &st->seed);
signal_mul(innov2, innov2, MULT16_32_Q15(QCONST16(0.454545,15),ener), st->subframeSize);
for (i=0;i<st->subframeSize;i++)
- exc[i] = ADD16(exc[i],PSHR32(innov2[i],SIG_SHIFT));
+ exc[i] = EXTRACT16(SATURATE32(ADD32(EXTEND32(exc[i]),PSHR32(innov2[i],SIG_SHIFT)),32767));
if (innov_save)
{
for (i=0;i<st->subframeSize;i++)