src/io/ioutils.h: add functions to check samplerate and channels, use in sink_*.c
[aubio.git] / src / aubio_priv.h
index 5dd8f25..72ba091 100644 (file)
 #include <limits.h> // for CHAR_BIT, in C99 standard
 #endif
 
 #include <limits.h> // for CHAR_BIT, in C99 standard
 #endif
 
+#ifdef HAVE_STDARG_H
+#include <stdarg.h>
+#endif
+
 #ifdef HAVE_ACCELERATE
 #define HAVE_ATLAS 1
 #include <Accelerate/Accelerate.h>
 #ifdef HAVE_ACCELERATE
 #define HAVE_ATLAS 1
 #include <Accelerate/Accelerate.h>
@@ -168,16 +172,23 @@ typedef enum {
   AUBIO_FAIL = 1
 } aubio_status;
 
   AUBIO_FAIL = 1
 } aubio_status;
 
+/* Logging */
+
+#include "utils/log.h"
+
+/** internal logging function, defined in utils/log.c */
+uint_t aubio_log(sint_t level, const char_t *fmt, ...);
+
 #ifdef HAVE_C99_VARARGS_MACROS
 #ifdef HAVE_C99_VARARGS_MACROS
-#define AUBIO_ERR(...)               fprintf(stderr, "AUBIO ERROR: " __VA_ARGS__)
-#define AUBIO_MSG(...)               fprintf(stdout, __VA_ARGS__)
-#define AUBIO_DBG(...)               fprintf(stderr, __VA_ARGS__)
-#define AUBIO_WRN(...)               fprintf(stderr, "AUBIO WARNING: " __VA_ARGS__)
+#define AUBIO_ERR(...)               aubio_log(AUBIO_LOG_ERR, "AUBIO ERROR: " __VA_ARGS__)
+#define AUBIO_MSG(...)               aubio_log(AUBIO_LOG_MSG, __VA_ARGS__)
+#define AUBIO_DBG(...)               aubio_log(AUBIO_LOG_DBG, __VA_ARGS__)
+#define AUBIO_WRN(...)               aubio_log(AUBIO_LOG_WRN, "AUBIO WARNING: " __VA_ARGS__)
 #else
 #else
-#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(format, args...)   fprintf(stderr, "AUBIO WARNING: " format, ##args)
+#define AUBIO_ERR(format, args...)   aubio_log(stderr, "AUBIO ERROR: " format , ##args)
+#define AUBIO_MSG(format, args...)   aubio_log(stdout, format , ##args)
+#define AUBIO_DBG(format, args...)   aubio_log(stderr, format , ##args)
+#define AUBIO_WRN(format, args...)   aubio_log(stderr, "AUBIO WARNING: " format, ##args)
 #endif
 
 #define AUBIO_ERROR   AUBIO_ERR
 #endif
 
 #define AUBIO_ERROR   AUBIO_ERR
@@ -185,6 +196,9 @@ typedef enum {
 #define AUBIO_QUIT(_s)               exit(_s)
 #define AUBIO_SPRINTF                sprintf
 
 #define AUBIO_QUIT(_s)               exit(_s)
 #define AUBIO_SPRINTF                sprintf
 
+#define AUBIO_MAX_SAMPLERATE (192000*8)
+#define AUBIO_MAX_CHANNELS 1024
+
 /* pi and 2*pi */
 #ifndef M_PI
 #define PI         (3.14159265358979323846)
 /* pi and 2*pi */
 #ifndef M_PI
 #define PI         (3.14159265358979323846)
@@ -198,7 +212,7 @@ typedef enum {
 #endif
 
 /* aliases to math.h functions */
 #endif
 
 /* aliases to math.h functions */
-#ifndef HAVE_AUBIO_DOUBLE
+#if !HAVE_AUBIO_DOUBLE
 #define EXP        expf
 #define COS        cosf
 #define SIN        sinf
 #define EXP        expf
 #define COS        cosf
 #define SIN        sinf
@@ -209,6 +223,7 @@ typedef enum {
 #define LOG        logf
 #define FLOOR      floorf
 #define CEIL       ceilf
 #define LOG        logf
 #define FLOOR      floorf
 #define CEIL       ceilf
+#define ATAN       atanf
 #define ATAN2      atan2f
 #else
 #define EXP        exp
 #define ATAN2      atan2f
 #else
 #define EXP        exp
@@ -221,12 +236,13 @@ typedef enum {
 #define LOG        log
 #define FLOOR      floor
 #define CEIL       ceil
 #define LOG        log
 #define FLOOR      floor
 #define CEIL       ceil
+#define ATAN       atan
 #define ATAN2      atan2
 #endif
 #define ROUND(x)   FLOOR(x+.5)
 
 /* aliases to complex.h functions */
 #define ATAN2      atan2
 #endif
 #define ROUND(x)   FLOOR(x+.5)
 
 /* aliases to complex.h functions */
-#if defined(HAVE_AUBIO_DOUBLE) || !defined(HAVE_COMPLEX_H) || defined(WIN32)
+#if HAVE_AUBIO_DOUBLE || !defined(HAVE_COMPLEX_H) || defined(WIN32)
 /* mingw32 does not know about c*f functions */
 #define EXPC      cexp
 /** complex = CEXPC(complex) */
 /* mingw32 does not know about c*f functions */
 #define EXPC      cexp
 /** complex = CEXPC(complex) */
@@ -254,6 +270,11 @@ typedef enum {
 #define IMAG      cimagf
 #endif
 
 #define IMAG      cimagf
 #endif
 
+/* avoid unresolved symbol with msvc 9 */
+#if defined(_MSC_VER) && (_MSC_VER < 1900)
+#define isnan _isnan
+#endif
+
 /* handy shortcuts */
 #define DB2LIN(g) (POW(10.0,(g)*0.05f))
 #define LIN2DB(v) (20.0*LOG10(v))
 /* handy shortcuts */
 #define DB2LIN(g) (POW(10.0,(g)*0.05f))
 #define LIN2DB(v) (20.0*LOG10(v))
@@ -289,4 +310,12 @@ typedef enum {
 #define UNUSED
 #endif
 
 #define UNUSED
 #endif
 
+/* are we using gcc -std=c99 ? */
+#if defined(__STRICT_ANSI__)
+#define strnlen(a,b) MIN(strlen(a),b)
+#if !HAVE_AUBIO_DOUBLE
+#define floorf floor
+#endif
+#endif /* __STRICT_ANSI__ */
+
 #endif /* AUBIO_PRIV_H */
 #endif /* AUBIO_PRIV_H */