ref: f45781966863a271d834ba95219da27999fff87f
parent: 0ceccb2dbdd82bb9bfbe106c791d2cf2495b1bcf
author: Jean-Marc Valin <[email protected]>
date: Fri Jul 4 12:47:28 EDT 2008
fixed-point: conversion of pre-echo avoidance now complete.
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -164,6 +164,29 @@
return (celt_int16_t)floor(.5+x);
#endif
}
+#ifdef FIXED_POINT
+static int ratio_compare(celt_word32_t num1, celt_word32_t den1, celt_word32_t num2, celt_word32_t den2)
+{
+ int shift = celt_zlog2(MAX32(num1, num2));
+ if (shift > 14)
+ {
+ num1 = SHR32(num1, shift-14);
+ num2 = SHR32(num2, shift-14);
+ }
+ shift = celt_zlog2(MAX32(den1, den2));
+ if (shift > 14)
+ {
+ den1 = SHR32(den1, shift-14);
+ den2 = SHR32(den2, shift-14);
+ }
+ return MULT16_16(EXTRACT16(num1),EXTRACT16(den2)) > MULT16_16(EXTRACT16(den1),EXTRACT16(num2));
+}
+#else
+static int ratio_compare(celt_word32_t num1, celt_word32_t den1, celt_word32_t num2, celt_word32_t den2)
+{
+ return num1*den2 > den1*num2;
+}
+#endif
static int transient_analysis(celt_word32_t *in, int len, int C, celt_word32_t *r)
{
@@ -170,7 +193,7 @@
int c, i, n;
celt_word32_t ratio;
/* FIXME: Remove the floats here */
- float maxN, maxD;
+ celt_word32_t maxN, maxD;
VARDECL(celt_word32_t, begin);
SAVE_STACK;
ALLOC(begin, len, celt_word32_t);
@@ -195,7 +218,7 @@
endi = begin[len-1]-begin[i];
num = endi*i;
den = (30+begin[i])*(len-i)+MULT16_32_Q15(QCONST16(.1f,15),endi)*len;
- if ((num*maxD > den*maxN) && (endi > MULT16_32_Q15(QCONST16(.05f,15),begin[i])))
+ if (ratio_compare(num, den, maxN, maxD) && (endi > MULT16_32_Q15(QCONST16(.05f,15),begin[i])))
{
maxN = num;
maxD = den;
@@ -208,6 +231,10 @@
n = -1;
ratio = 0;
}
+ if (ratio < 0)
+ ratio = 0;
+ if (ratio > 1000)
+ ratio = 1000;
*r = ratio*ratio;
RESTORE_STACK;
return n;