aboutsummaryrefslogtreecommitdiff
path: root/celt
diff options
context:
space:
mode:
authorRalph Giles <giles@mozilla.com>2012-03-22 14:13:33 -0700
committerJean-Marc Valin <jmvalin@jmvalin.ca>2012-04-02 11:21:44 -0400
commitd9474d9085ab1418220dc8c74e8da4dcc43f99b4 (patch)
tree22595fa1b70ad9676d901bcb0aa6c13b4191d89f /celt
parentf40285212c1423b056563c1ca0655e6e59a00016 (diff)
downloadlibopus-d9474d9085ab1418220dc8c74e8da4dcc43f99b4.tar.gz
Cast a factor to maintain precision on 16 bit systems.
The multiply would overflow with 16 bit ints. Thanks to Riccardo Micci for pointing out the issue. Thanks to Tim Terriberry for the valid range of the decay argument. Note that ft is unsigned, but always less than 32736, so we could use a 16 bit signed type here if it allows the compiler to produce faster code (with signed 16*16 and 16*32 multiplies). In the absense of actual cycle counts from a real platform, I've left it as an unsigned for the sake of readability. For similar reasons we cast (16384-decay) to a signed integer even though it is also always positive.
Diffstat (limited to 'celt')
-rw-r--r--celt/laplace.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/celt/laplace.c b/celt/laplace.c
index 53673130..30f2aab1 100644
--- a/celt/laplace.c
+++ b/celt/laplace.c
@@ -40,11 +40,12 @@
direction). */
#define LAPLACE_NMIN (16)
+/* When called, decay is positive and at most 11456. */
static unsigned ec_laplace_get_freq1(unsigned fs0, int decay)
{
unsigned ft;
ft = 32768 - LAPLACE_MINP*(2*LAPLACE_NMIN) - fs0;
- return ft*(16384-decay)>>15;
+ return ft*(opus_int32)(16384-decay)>>15;
}
void ec_laplace_encode(ec_enc *enc, int *value, unsigned fs, int decay)