#include <string.h>
#endif
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
#ifdef HAVE_LIMITS_H
#include <limits.h> // for CHAR_BIT, in C99 standard
#endif
#include <stdarg.h>
#endif
-#if defined(HAVE_ACCELERATE)
-#define HAVE_ATLAS 1
-#define HAVE_BLAS 1
-#include <Accelerate/Accelerate.h>
-#elif defined(HAVE_ATLAS_CBLAS_H)
-#elif defined(HAVE_BLAS)
+#if defined(HAVE_BLAS) // --enable-blas=true
+// check which cblas header we found
#if defined(HAVE_ATLAS_CBLAS_H)
#define HAVE_ATLAS 1
#include <atlas/cblas.h>
#include <openblas/cblas.h>
#elif defined(HAVE_CBLAS_H)
#include <cblas.h>
-#endif
+#elif !defined(HAVE_ACCELERATE)
+#error "HAVE_BLAS was defined, but no blas header was found"
+#endif /* end of cblas includes */
#endif
-#ifdef HAVE_ACCELERATE
+#if defined(HAVE_ACCELERATE)
+// include accelerate framework after blas
+#define HAVE_ATLAS 1
+#define HAVE_BLAS 1
#include <Accelerate/Accelerate.h>
+
#ifndef HAVE_AUBIO_DOUBLE
#define aubio_vDSP_mmov vDSP_mmov
#define aubio_vDSP_vmul vDSP_vmul
#define AUBIO_ERR(...) aubio_log(AUBIO_LOG_ERR, "AUBIO ERROR: " __VA_ARGS__)
#define AUBIO_INF(...) aubio_log(AUBIO_LOG_INF, "AUBIO INFO: " __VA_ARGS__)
#define AUBIO_MSG(...) aubio_log(AUBIO_LOG_MSG, __VA_ARGS__)
-#define AUBIO_DBG(...) aubio_log(AUBIO_LOG_DBG, __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
#define AUBIO_ERR(format, args...) aubio_log(AUBIO_LOG_ERR, "AUBIO ERROR: " format , ##args)
#define AUBIO_INF(format, args...) aubio_log(AUBIO_LOG_INF, "AUBIO INFO: " format , ##args)
#define AUBIO_MSG(format, args...) aubio_log(AUBIO_LOG_MSG, format , ##args)
-#define AUBIO_DBG(format, args...) aubio_log(AUBIO_LOG_DBG, format , ##args)
+#define _AUBIO_DBG(format, args...) aubio_log(AUBIO_LOG_DBG, format , ##args)
#define AUBIO_WRN(format, args...) aubio_log(AUBIO_LOG_WRN, "AUBIO WARNING: " format, ##args)
#endif
+#ifdef DEBUG
+#define AUBIO_DBG _AUBIO_DBG
+#else
+// disable debug output
+#define AUBIO_DBG(format, args...)
+#endif
+
#define AUBIO_ERROR AUBIO_ERR
#define AUBIO_QUIT(_s) exit(_s)
#define AUBIO_STRERROR(errno,buf,len) strerror_s(buf, len, errno)
#endif
+#ifdef HAVE_C99_VARARGS_MACROS
+#define AUBIO_STRERR(...) \
+ char errorstr[256]; \
+ AUBIO_STRERROR(errno, errorstr, sizeof(errorstr)); \
+ AUBIO_ERR(__VA_ARGS__)
+#else
+#define AUBIO_STRERR(format, args...) \
+ char errorstr[256]; \
+ AUBIO_STRERROR(errno, errorstr, sizeof(errorstr)); \
+ AUBIO_ERR(format, ##args)
+#endif
+
/* handy shortcuts */
#define DB2LIN(g) (POW(10.0,(g)*0.05f))
#define LIN2DB(v) (20.0*LOG10(v))