changeset 6439:edac9b35835d

Fixed lround replacement, hopefully fast enough.
author atmos4
date Sun, 16 Jun 2002 01:44:33 +0000
parents 88938fa0c659
children 2997a3faf381
files libao2/pl_eq.c
diffstat 1 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libao2/pl_eq.c	Sat Jun 15 23:55:06 2002 +0000
+++ b/libao2/pl_eq.c	Sun Jun 16 01:44:33 2002 +0000
@@ -89,16 +89,21 @@
   return CONTROL_UNKNOWN;
 }
 
+// return rounded 16bit int
+static inline int16_t lround16(double n){
+  return (int16_t)((n)>=0.0?(n)+0.5:(n)-0.5);
+}
+
 // 2nd order Band-pass Filter design
 void bp2(int16_t* a, int16_t* b, float fc, float q){
   double th=2*3.141592654*fc;
   double C=(1 - tan(th*q/2))/(1 + tan(th*q/2));
   
-  a[0] = (int16_t)( 16383.0 * (1 + C) * cos(th) + 0.5);
-  a[1] = (int16_t)(-16383.0 * C + 0.5);
+  a[0] = lround16( 16383.0 * (1 + C) * cos(th));
+  a[1] = lround16(-16383.0 * C);
   
-  b[0] = (int16_t)(-16383.0 * (C - 1)/2 + 0.5);
-  b[1] = (int16_t)(-16383.0 * 1.0050 + 0.5);
+  b[0] = lround16(-16383.0 * (C - 1)/2);
+  b[1] = lround16(-16383.0 * 1.0050);
 }
 
 // empty buffers