From 5c3bc67959790ea0339894c21ee25e81669f81a8 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Thu, 28 Aug 2008 23:34:24 -0400 Subject: [PATCH] Fixed a bunch of fixed-point overflows on insanely hot signals by changing the time-domain representation from Q14 to Q12 (Q29 to Q27 using the standard convention). --- configure.ac | 2 +- libcelt/arch.h | 6 +----- libcelt/bands.c | 4 ++-- libcelt/celt.c | 6 +++--- libcelt/mathops.h | 2 +- libcelt/quant_bands.c | 6 ++++-- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/configure.ac b/configure.ac index 2ca8ba36..330162db 100644 --- a/configure.ac +++ b/configure.ac @@ -6,7 +6,7 @@ AM_CONFIG_HEADER([config.h]) CELT_MAJOR_VERSION=0 CELT_MINOR_VERSION=4 -CELT_MICRO_VERSION=0 +CELT_MICRO_VERSION=1 CELT_EXTRA_VERSION= CELT_VERSION=$CELT_MAJOR_VERSION.$CELT_MINOR_VERSION.$CELT_MICRO_VERSION$CELT_EXTRA_VERSION diff --git a/libcelt/arch.h b/libcelt/arch.h index 4722bbe6..4ac7cfcf 100644 --- a/libcelt/arch.h +++ b/libcelt/arch.h @@ -71,9 +71,7 @@ typedef celt_word32_t celt_mask_t; #define Q15ONE 32767 #define Q30ONE 1073741823 -#define SIG_SCALING 16384.f -#define SIG_SCALING_1 (1.f/16384.f) -#define SIG_SHIFT 14 +#define SIG_SHIFT 12 #define NORM_SCALING 16384 #define NORM_SCALING_1 (1.f/16384.f) @@ -135,8 +133,6 @@ typedef float celt_mask_t; #define Q15ONE 1.0f #define Q30ONE 1.0f -#define SIG_SCALING 1.f -#define SIG_SCALING_1 1.f #define NORM_SCALING 1.f #define NORM_SCALING_1 1.f #define ENER_SCALING 1.f diff --git a/libcelt/bands.c b/libcelt/bands.c index d686f2d5..22876635 100644 --- a/libcelt/bands.c +++ b/libcelt/bands.c @@ -175,9 +175,9 @@ void denormalise_bands(const CELTMode *m, const celt_norm_t * restrict X, celt_s for (i=0;inbEBands;i++) { int j; - celt_word32_t g = MULT16_32_Q13(sqrtC_1[C-1],bank[i*C+c]); + celt_word32_t g = MULT16_32_Q15(sqrtC_1[C-1],bank[i*C+c]); j=eBands[i]; do { - freq[j*C+c] = MULT16_32_Q15(X[j*C+c], g); + freq[j*C+c] = SHL32(MULT16_32_Q15(X[j*C+c], g),2); } while (++jpreemph_memE[c]),1)); + *inp = SUB32(tmp, SHR32(MULT16_16(preemph,st->preemph_memE[c]),3)); st->preemph_memE[c] = SCALEIN(*pcmp); inp += C; pcmp += C; diff --git a/libcelt/mathops.h b/libcelt/mathops.h index 22588cd9..8e1a132a 100644 --- a/libcelt/mathops.h +++ b/libcelt/mathops.h @@ -246,7 +246,7 @@ static inline celt_word32_t celt_exp2(celt_word16_t x) celt_word16_t frac; integer = SHR16(x,11); if (integer>14) - return 0x7fffffff; + return 0x7f000000; else if (integer < -15) return 0; frac = SHL16(x-SHL16(integer,11),3); diff --git a/libcelt/quant_bands.c b/libcelt/quant_bands.c index 9778aab1..967163d5 100644 --- a/libcelt/quant_bands.c +++ b/libcelt/quant_bands.c @@ -52,17 +52,19 @@ const celt_word16_t eMeans[24] = {45.f, -8.f, -12.f, -2.5f, 1.f, 0.f, 0.f, 0.f, static inline celt_ener_t dB2Amp(celt_ener_t dB) { celt_ener_t amp; + if (dB>24659) + dB=24659; amp = PSHR32(celt_exp2(MULT16_16_Q14(21771,dB)),2)-QCONST16(.3f, 14); if (amp < 0) amp = 0; - return amp; + return PSHR32(amp,2); } #define DBofTWO 24661 static inline celt_word16_t amp2dB(celt_ener_t amp) { /* equivalent to return 6.0207*log2(.3+amp) */ - return ROUND16(MULT16_16(24661,celt_log2(ADD32(QCONST32(.3f,14),amp))),12); + return ROUND16(MULT16_16(24661,celt_log2(ADD32(QCONST32(.3f,14),SHL32(amp,2)))),12); /* return DB_SCALING*20*log10(.3+ENER_SCALING_1*amp); */ } #else