src/aubio_priv.h: no attributes for ms compilers
[aubio.git] / src / aubio_priv.h
index 683056f..81cf24a 100644 (file)
@@ -24,8 +24,8 @@
  * This file is for inclusion from _within_ the library only.
  */
 
-#ifndef _AUBIO_PRIV_H
-#define _AUBIO_PRIV_H
+#ifndef _AUBIO__PRIV_H
+#define _AUBIO__PRIV_H
 
 /*********************
  *
@@ -33,9 +33,7 @@
  *
  */
 
-#if 1 //HAVE_CONFIG_H
 #include "config.h"
-#endif
 
 #if HAVE_STDLIB_H
 #include <stdlib.h>
 #endif
 
 /* must be included before fftw3.h */
-#if HAVE_COMPLEX_H
+#ifdef HAVE_COMPLEX_H
 #include <complex.h>
 #endif
 
-#if HAVE_FFTW3 || HAVE_FFTW3F
+#if defined(HAVE_FFTW3) || defined(HAVE_FFTW3F)
 #include <fftw3.h>
 #endif
 
-#if HAVE_MATH_H
+#ifdef HAVE_MATH_H
 #include <math.h>
 #endif
 
-#if HAVE_STRING_H
+#ifdef HAVE_STRING_H
 #include <string.h>
 #endif
 
+#ifdef HAVE_LIMITS_H
+#include <limits.h> // for CHAR_BIT, in C99 standard
+#endif
+
 #include "types.h"
 
+#define AUBIO_UNSTABLE 1
+
+#include "mathutils.h"
+
 /****
  * 
  * SYSTEM INTERFACE
@@ -73,8 +79,8 @@
 /* Memory management */
 #define AUBIO_MALLOC(_n)             malloc(_n)
 #define AUBIO_REALLOC(_p,_n)         realloc(_p,_n)
-#define AUBIO_NEW(_t)                (_t*)malloc(sizeof(_t))
-#define AUBIO_ARRAY(_t,_n)           (_t*)malloc((_n)*sizeof(_t))
+#define AUBIO_NEW(_t)                (_t*)calloc(sizeof(_t), 1)
+#define AUBIO_ARRAY(_t,_n)           (_t*)calloc((_n)*sizeof(_t), 1)
 #define AUBIO_MEMCPY(_dst,_src,_n)   memcpy(_dst,_src,_n)
 #define AUBIO_MEMSET(_dst,_src,_t)   memset(_dst,_src,_t)
 #define AUBIO_FREE(_p)               free(_p)
 /* Error reporting */
 typedef enum {
   AUBIO_OK = 0,
-  AUBIO_FAIL = -1
+  AUBIO_FAIL = 1
 } aubio_status;
 
 #ifdef HAVE_C99_VARARGS_MACROS
@@ -114,7 +120,7 @@ typedef enum {
 #define AUBIO_ERR(format, args...)   fprintf(stderr, "AUBIO ERROR: " format , ##args)
 #define AUBIO_MSG(format, args...)   fprintf(stdout, format , ##args)
 #define AUBIO_DBG(format, args...)   fprintf(stderr, format , ##args)
-#define AUBIO_WRN(...)               fprintf(stderr, "AUBIO WARNING: " format, ##args)
+#define AUBIO_WRN(format, args...)   fprintf(stderr, "AUBIO WARNING: " format, ##args)
 #endif
 
 #define AUBIO_ERROR   AUBIO_ERR
@@ -122,8 +128,12 @@ typedef enum {
 #define AUBIO_QUIT(_s)               exit(_s)
 #define AUBIO_SPRINTF                sprintf
 
-/* Libc shortcuts */
+/* pi and 2*pi */
+#ifndef M_PI
+#define PI         (3.14159265358979323846)
+#else
 #define PI         (M_PI)
+#endif
 #define TWO_PI     (PI*2.)
 
 /* aliases to math.h functions */
@@ -138,6 +148,7 @@ typedef enum {
 #define LOG        logf
 #define FLOOR      floorf
 #define CEIL       ceilf
+#define ATAN2      atan2f
 #else
 #define EXP        exp
 #define COS        cos
@@ -149,6 +160,7 @@ typedef enum {
 #define LOG        log
 #define FLOOR      floor
 #define CEIL       ceil
+#define ATAN2      atan2
 #endif
 #define ROUND(x)   FLOOR(x+.5)
 
@@ -193,14 +205,23 @@ typedef enum {
 
 #define VERY_SMALL_NUMBER 2.e-42 //1.e-37
 
-#define IS_DENORMAL(f) f < VERY_SMALL_NUMBER
+/** if ABS(f) < VERY_SMALL_NUMBER, returns 1, else 0 */
+#define IS_DENORMAL(f) ABS(f) < VERY_SMALL_NUMBER
 
+/** if ABS(f) < VERY_SMALL_NUMBER, returns 0., else f */
 #define KILL_DENORMAL(f)  IS_DENORMAL(f) ? 0. : f
-#define CEIL_DENORMAL(f)  IS_DENORMAL(f) ? VERY_SMALL_NUMBER : f
+
+/** if f > VERY_SMALL_NUMBER, returns f, else returns VERY_SMALL_NUMBER */
+#define CEIL_DENORMAL(f)  f < VERY_SMALL_NUMBER ? VERY_SMALL_NUMBER : f
 
 #define SAFE_LOG10(f) LOG10(CEIL_DENORMAL(f))
 #define SAFE_LOG(f)   LOG(CEIL_DENORMAL(f))
 
+/** silence unused parameter warning by adding an attribute */
+#if defined(__GNUC__)
 #define UNUSED __attribute__((unused))
+#else
+#define UNUSED
+#endif
 
-#endif/*_AUBIO_PRIV_H*/
+#endif /* _AUBIO__PRIV_H */