summaryrefslogtreecommitdiffstats
path: root/apps/codecs/libspeex/nb_celp.c
diff options
context:
space:
mode:
authorDan Everton <dan@iocaine.org>2007-05-22 09:50:31 +0000
committerDan Everton <dan@iocaine.org>2007-05-22 09:50:31 +0000
commitdf6f2f9a3c88a7a4a8ad0382ee4ee7c9a3ee3256 (patch)
treed9862e5d04f4014def5911bb4ff8206c85636fb7 /apps/codecs/libspeex/nb_celp.c
parent8970055ec107a2387eedbb373889d0f540745121 (diff)
downloadrockbox-df6f2f9a3c88a7a4a8ad0382ee4ee7c9a3ee3256.tar.gz
rockbox-df6f2f9a3c88a7a4a8ad0382ee4ee7c9a3ee3256.zip
Upgrade to libspeex 1.2beta2. Very minor performance increase (0.6% on coldfire).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13461 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/libspeex/nb_celp.c')
-rw-r--r--apps/codecs/libspeex/nb_celp.c44
1 files changed, 37 insertions, 7 deletions
diff --git a/apps/codecs/libspeex/nb_celp.c b/apps/codecs/libspeex/nb_celp.c
index 85e4ca015e..e41ad6e703 100644
--- a/apps/codecs/libspeex/nb_celp.c
+++ b/apps/codecs/libspeex/nb_celp.c
@@ -1257,7 +1257,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout)
speex_mode_query(&speex_wb_mode, SPEEX_SUBMODE_BITS_PER_FRAME, &advance);
if (advance < 0)
{
- speex_warning ("Invalid wideband mode encountered. Corrupted stream?");
+ speex_notify("Invalid mode encountered. The stream is corrupted.");
return -2;
}
advance -= (SB_SUBMODE_BITS+1);
@@ -1272,7 +1272,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout)
speex_mode_query(&speex_wb_mode, SPEEX_SUBMODE_BITS_PER_FRAME, &advance);
if (advance < 0)
{
- speex_warning ("Invalid wideband mode encountered: corrupted stream?");
+ speex_notify("Invalid mode encountered. The stream is corrupted.");
return -2;
}
advance -= (SB_SUBMODE_BITS+1);
@@ -1280,7 +1280,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout)
wideband = speex_bits_unpack_unsigned(bits, 1);
if (wideband)
{
- speex_warning ("More than two wideband layers found: corrupted stream?");
+ speex_notify("More than two wideband layers found. The stream is corrupted.");
return -2;
}
@@ -1305,7 +1305,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout)
return ret;
} else if (m>8) /* Invalid mode */
{
- speex_warning("Invalid mode encountered: corrupted stream?");
+ speex_notify("Invalid mode encountered. The stream is corrupted.");
return -2;
}
@@ -1526,7 +1526,11 @@ int nb_decode(void *state, SpeexBits *bits, void *vout)
#ifdef EPIC_48K
}
#endif
-
+ /* Ensuring that things aren't blowing up as would happen if e.g. an encoder is
+ crafting packets to make us produce NaNs and slow down the decoder (vague DoS threat).
+ We can probably be even more aggressive and limit to 15000 or so. */
+ sanitize_values32(exc32, NEG32(QCONST32(32000,SIG_SHIFT-1)), QCONST32(32000,SIG_SHIFT-1), st->subframeSize);
+
tmp = gain_3tap_to_1tap(pitch_gain);
pitch_average += tmp;
@@ -1698,7 +1702,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout)
for (i=0;i<st->lpcSize;i+=2)
{
/*pi_g += -st->interp_qlpc[i] + st->interp_qlpc[i+1];*/
- pi_g = ADD32(pi_g, SUB32(EXTEND32(st->interp_qlpc[i+1]),EXTEND32(st->interp_qlpc[i])));
+ pi_g = ADD32(pi_g, SUB32(EXTEND32(ak[i+1]),EXTEND32(ak[i])));
}
st->pi_gain[sub] = pi_g;
}
@@ -1716,6 +1720,14 @@ int nb_decode(void *state, SpeexBits *bits, void *vout)
/*for (i=0;i<st->frameSize;i++)
printf ("%d\n", (int)st->frame[i]);*/
+ /* Tracking output level */
+ st->level = 1+PSHR32(ol_gain,SIG_SHIFT);
+ st->max_level = MAX16(MULT16_16_Q15(QCONST16(.99f,15), st->max_level), st->level);
+ st->min_level = MIN16(ADD16(1,MULT16_16_Q14(QCONST16(1.01f,14), st->min_level)), st->level);
+ if (st->max_level < st->min_level+1)
+ st->max_level = st->min_level+1;
+ /*printf ("%f %f %f %d\n", og, st->min_level, st->max_level, update);*/
+
/* Store the LSPs for interpolation in the next frame */
for (i=0;i<st->lpcSize;i++)
st->old_qlsp[i] = qlsp[i];
@@ -1924,6 +1936,9 @@ int nb_encoder_ctl(void *state, int request, void *ptr)
case SPEEX_SET_WIDEBAND:
st->isWideband = *((spx_int32_t*)ptr);
break;
+ case SPEEX_GET_STACK:
+ *((char**)ptr) = st->stack;
+ break;
default:
speex_warning_int("Unknown nb_ctl request: ", request);
return -1;
@@ -2006,7 +2021,19 @@ int nb_decoder_ctl(void *state, int request, void *ptr)
case SPEEX_GET_HIGHPASS:
(*(spx_int32_t*)ptr) = st->highpass_enabled;
break;
-
+ case SPEEX_GET_ACTIVITY:
+ {
+ float ret;
+ ret = log(st->level/st->min_level)/log(st->max_level/st->min_level);
+ if (ret>1)
+ ret = 1;
+ /* Done in a strange way to catch NaNs as well */
+ if (!(ret > 0))
+ ret = 0;
+ /*printf ("%f %f %f %f\n", st->level, st->min_level, st->max_level, ret);*/
+ (*(spx_int32_t*)ptr) = (int)(100*ret);
+ }
+ break;
case SPEEX_GET_PI_GAIN:
{
int i;
@@ -2031,6 +2058,9 @@ int nb_decoder_ctl(void *state, int request, void *ptr)
case SPEEX_SET_WIDEBAND:
st->isWideband = *((spx_int32_t*)ptr);
break;
+ case SPEEX_GET_STACK:
+ *((char**)ptr) = st->stack;
+ break;
default:
speex_warning_int("Unknown nb_ctl request: ", request);
return -1;