ref: ad6e0fdd44a6740ab921aaeb8170c42542677f0e
parent: b839b5f7563076ea3e7f60589803cd75447b0793
author: Erik de Castro Lopo <[email protected]>
date: Thu May 24 08:54:31 EDT 2007
src_sinc.c : Change macros into inline functions for better error checking.
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-05-24 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
+
+ * src/src_sinc.c
+ Change macros into inline functions for better error checking.
+
2007-05-12 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
* tests.Makefile.am
--- a/src/src_sinc.c
+++ b/src/src_sinc.c
@@ -46,16 +46,8 @@
#define SHIFT_BITS 16
#define FP_ONE ((double) (((increment_t) 1) << SHIFT_BITS))
+#define INV_FP_ONE (1.0 / FP_ONE)
-#define DOUBLE_TO_FP(x) (lrint ((x) * FP_ONE))
-#define INT_TO_FP(x) (((increment_t) (x)) << SHIFT_BITS)
-
-#define FP_FRACTION_PART(x) ((x) & ((((increment_t) 1) << SHIFT_BITS) - 1))
-#define FP_INTEGER_PART(x) ((x) & (((increment_t) -1) << SHIFT_BITS))
-
-#define FP_TO_INT(x) (((x) >> SHIFT_BITS))
-#define FP_TO_DOUBLE(x) (FP_FRACTION_PART (x) / FP_ONE)
-
/*========================================================================================
*/
@@ -104,6 +96,39 @@
#include "fastest_coeffs.h"
} ; /* fastest_coeffs */
+
+static inline increment_t
+double_to_fp (double x)
+{ if (sizeof (increment_t) == 8)
+ return (llrint ((x) * FP_ONE)) ;
+ return (lrint ((x) * FP_ONE)) ;
+} /* double_to_fp */
+
+static inline increment_t
+INT_TO_FP (int x)
+{ return (((increment_t) (x)) << SHIFT_BITS) ;
+} /* INT_TO_FP */
+
+static inline int
+fp_fraction_part (increment_t x)
+{ return ((x) & ((((increment_t) 1) << SHIFT_BITS) - 1)) ;
+} /* fp_fraction_part */
+
+static inline int
+fp_integer_part (increment_t x)
+{ return ((x) & (((increment_t) -1) << SHIFT_BITS)) ;
+} /* fp_integer_part */
+
+static inline int
+fp_to_int (increment_t x)
+{ return (((x) >> SHIFT_BITS)) ;
+} /* fp_to_int */
+
+static inline double
+fp_to_double (increment_t x)
+{ return fp_fraction_part (x) * INV_FP_ONE ;
+} /* fp_to_double */
+
/*----------------------------------------------------------------------------------------
*/
@@ -314,9 +339,9 @@
if (src_ratio < 1.0)
float_increment = filter->index_inc * src_ratio ;
- increment = DOUBLE_TO_FP (float_increment) ;
+ increment = double_to_fp (float_increment) ;
- start_filter_index = DOUBLE_TO_FP (input_index * float_increment) ;
+ start_filter_index = double_to_fp (input_index * float_increment) ;
for (ch = 0 ; ch < filter->channels ; ch++)
{ data->data_out [filter->out_gen] = (float) ((float_increment / filter->index_inc) *
@@ -431,8 +456,8 @@
left = 0.0 ;
do
- { fraction = FP_TO_DOUBLE (filter_index) ;
- indx = FP_TO_INT (filter_index) ;
+ { fraction = fp_to_double (filter_index) ;
+ indx = fp_to_int (filter_index) ;
icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ;
@@ -451,8 +476,8 @@
right = 0.0 ;
do
- { fraction = FP_TO_DOUBLE (filter_index) ;
- indx = FP_TO_INT (filter_index) ;
+ { fraction = fp_to_double (filter_index) ;
+ indx = fp_to_int (filter_index) ;
icoeff = filter->coeffs [indx] + fraction * (filter->coeffs [indx + 1] - filter->coeffs [indx]) ;