Index: src/aubio_priv.h
===================================================================
--- src/aubio_priv.h	(revision 08246ee55357da38cb8b16822834e5c610814cca)
+++ src/aubio_priv.h	(revision 1dfe40925bf16faa125beae73a84e425dec95480)
@@ -63,4 +63,8 @@
 #endif
 
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
 #ifdef HAVE_LIMITS_H
 #include <limits.h> // for CHAR_BIT, in C99 standard
@@ -71,10 +75,6 @@
 #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
@@ -84,9 +84,15 @@
 #elif defined(HAVE_CBLAS_H)
 #include <cblas.h>
-#endif
-#endif
-
-#ifdef HAVE_ACCELERATE
+#elif !defined(HAVE_ACCELERATE)
+#error "HAVE_BLAS was defined, but no blas header was found"
+#endif /* end of cblas includes */
+#endif
+
+#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
@@ -331,4 +337,16 @@
 #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))
Index: src/io/sink.c
===================================================================
--- src/io/sink.c	(revision 08246ee55357da38cb8b16822834e5c610814cca)
+++ src/io/sink.c	(revision 1dfe40925bf16faa125beae73a84e425dec95480)
@@ -216,5 +216,5 @@
 
 void del_aubio_sink(aubio_sink_t * s) {
-  AUBIO_ASSERT(s);
+  //AUBIO_ASSERT(s);
   if (s && s->s_del && s->sink)
     s->s_del((void *)s->sink);
Index: src/io/sink_wavwrite.c
===================================================================
--- src/io/sink_wavwrite.c	(revision 08246ee55357da38cb8b16822834e5c610814cca)
+++ src/io/sink_wavwrite.c	(revision 1dfe40925bf16faa125beae73a84e425dec95480)
@@ -28,6 +28,4 @@
 #include "io/sink_wavwrite.h"
 #include "io/ioutils.h"
-
-#include <errno.h>
 
 #define MAX_SIZE 4096
@@ -168,7 +166,5 @@
   s->fid = fopen((const char *)s->path, "wb");
   if (!s->fid) {
-    char errorstr[256];
-    AUBIO_STRERROR(errno, errorstr, sizeof(errorstr));
-    AUBIO_ERR("sink_wavwrite: could not open %s (%s)\n", s->path, errorstr);
+    AUBIO_STRERR("sink_wavwrite: could not open %s (%s)\n", s->path, errorstr);
     goto beach;
   }
@@ -216,9 +212,9 @@
 
   // fwrite(*, *, 1, s->fid) was called 13 times, check success
-  if (written != 13) {
-    char errorstr[256];
-    AUBIO_STRERROR(errno, errorstr, sizeof(errorstr));
-    AUBIO_WRN("sink_wavwrite: writing header to %s failed, expected %d"
-        " write but got only %d (%s)\n", s->path, 13, written, errorstr);
+  if (written != 13 || fflush(s->fid)) {
+    AUBIO_STRERR("sink_wavwrite: writing header to %s failed"
+        " (wrote %d/%d, %s)\n", s->path, written, 13, errorstr);
+    fclose(s->fid);
+    s->fid = NULL;
     return AUBIO_FAIL;
   }
@@ -247,7 +243,5 @@
 
   if (written_frames != write) {
-    char errorstr[256];
-    AUBIO_STRERROR(errno, errorstr, sizeof(errorstr));
-    AUBIO_WRN("sink_wavwrite: trying to write %d frames to %s, but only %d"
+    AUBIO_STRERR("sink_wavwrite: trying to write %d frames to %s, but only %d"
         " could be written (%s)\n", write, s->path, written_frames, errorstr);
   }
@@ -298,14 +292,10 @@
   written += fwrite(write_little_endian(data_size, buf, 4), 4, 1, s->fid);
   if (written != 2 || err != 0) {
-    char errorstr[256];
-    AUBIO_STRERROR(errno, errorstr, sizeof(errorstr));
-    AUBIO_WRN("sink_wavwrite: updating header of %s failed, expected %d"
+    AUBIO_STRERR("sink_wavwrite: updating header of %s failed, expected %d"
         " write but got only %d (%s)\n", s->path, 2, written, errorstr);
   }
   // close file
   if (fclose(s->fid)) {
-    char errorstr[256];
-    AUBIO_STRERROR(errno, errorstr, sizeof(errorstr));
-    AUBIO_ERR("sink_wavwrite: Error closing file %s (%s)\n", s->path, errorstr);
+    AUBIO_STRERR("sink_wavwrite: Error closing file %s (%s)\n", s->path, errorstr);
   }
   s->fid = NULL;
Index: src/io/source.c
===================================================================
--- src/io/source.c	(revision 08246ee55357da38cb8b16822834e5c610814cca)
+++ src/io/source.c	(revision 1dfe40925bf16faa125beae73a84e425dec95480)
@@ -139,5 +139,5 @@
 
 void del_aubio_source(aubio_source_t * s) {
-  AUBIO_ASSERT(s);
+  //AUBIO_ASSERT(s);
   if (s && s->s_del && s->source)
     s->s_del((void *)s->source);
Index: src/io/source_avcodec.c
===================================================================
--- src/io/source_avcodec.c	(revision 08246ee55357da38cb8b16822834e5c610814cca)
+++ src/io/source_avcodec.c	(revision 1dfe40925bf16faa125beae73a84e425dec95480)
@@ -31,5 +31,4 @@
 #endif
 #include <libavutil/opt.h>
-#include <stdlib.h>
 
 // determine whether we use libavformat from ffmpeg or from libav
@@ -121,7 +120,7 @@
     uint_t samplerate, uint_t hop_size) {
   aubio_source_avcodec_t * s = AUBIO_NEW(aubio_source_avcodec_t);
-  AVFormatContext *avFormatCtx = s->avFormatCtx;
-  AVCodecContext *avCodecCtx = s->avCodecCtx;
-  AVFrame *avFrame = s->avFrame;
+  AVFormatContext *avFormatCtx = NULL;
+  AVCodecContext *avCodecCtx = NULL;
+  AVFrame *avFrame = NULL;
   sint_t selected_stream = -1;
 #if FF_API_LAVF_AVCTX
@@ -465,7 +464,7 @@
       (const uint8_t **)avFrame->data, in_samples);
 #endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
-  if (out_samples <= 0) {
-    AUBIO_WRN("source_avcodec: no sample found while converting frame (%s)\n",
-        s->path);
+  if (out_samples < 0) {
+    AUBIO_WRN("source_avcodec: error while resampling %s (%d)\n",
+        s->path, out_samples);
     goto beach;
   }
@@ -474,12 +473,4 @@
 
 beach:
-  s->avFormatCtx = avFormatCtx;
-  s->avCodecCtx = avCodecCtx;
-  s->avFrame = avFrame;
-#if defined(HAVE_AVRESAMPLE) || defined(HAVE_SWRESAMPLE)
-  s->avr = avr;
-#endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
-  s->output = output;
-
   av_packet_unref(&avPacket);
 }
@@ -629,8 +620,9 @@
 #ifdef HAVE_AVRESAMPLE
     avresample_close( s->avr );
+    av_free ( s->avr );
 #elif defined(HAVE_SWRESAMPLE)
     swr_close ( s->avr );
-#endif
-    av_free ( s->avr );
+    swr_free ( &s->avr );
+#endif
   }
   s->avr = NULL;
Index: src/io/source_sndfile.c
===================================================================
--- src/io/source_sndfile.c	(revision 08246ee55357da38cb8b16822834e5c610814cca)
+++ src/io/source_sndfile.c	(revision 1dfe40925bf16faa125beae73a84e425dec95480)
@@ -175,4 +175,9 @@
   sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data,
       s->scratch_size);
+  uint_t read_length = read_samples / s->input_channels;
+
+  /* where to store de-interleaved data */
+  smpl_t *ptr_data;
+
   if (!s->handle) {
     AUBIO_ERR("source_sndfile: could not read from %s (file was closed)\n",
@@ -182,8 +187,4 @@
   }
 
-  uint_t read_length = read_samples / s->input_channels;
-
-  /* where to store de-interleaved data */
-  smpl_t *ptr_data;
 #ifdef HAVE_SAMPLERATE
   if (s->ratio != 1) {
@@ -226,4 +227,9 @@
   sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data,
       s->scratch_size);
+  uint_t read_length = read_samples / s->input_channels;
+
+  /* where to store de-interleaved data */
+  smpl_t **ptr_data;
+
   if (!s->handle) {
     AUBIO_ERR("source_sndfile: could not read from %s (file was closed)\n",
@@ -233,8 +239,4 @@
   }
 
-  uint_t read_length = read_samples / s->input_channels;
-
-  /* where to store de-interleaved data */
-  smpl_t **ptr_data;
 #ifdef HAVE_SAMPLERATE
   if (s->ratio != 1) {
Index: src/io/source_wavread.c
===================================================================
--- src/io/source_wavread.c	(revision 08246ee55357da38cb8b16822834e5c610814cca)
+++ src/io/source_wavread.c	(revision 1dfe40925bf16faa125beae73a84e425dec95480)
@@ -28,9 +28,7 @@
 #include "source_wavread.h"
 
-#include <errno.h>
-
 #define AUBIO_WAVREAD_BUFSIZE 1024
 
-#define SHORT_TO_FLOAT(x) (smpl_t)(x * 3.0517578125e-05)
+//#define SHORT_TO_FLOAT(x) (smpl_t)(x * 3.0517578125e-05)
 
 struct _aubio_source_wavread_t {
@@ -101,5 +99,5 @@
   s->fid = fopen((const char *)path, "rb");
   if (!s->fid) {
-    AUBIO_ERR("source_wavread: Failed opening %s (System error: %s)\n", s->path, strerror(errno));
+    AUBIO_STRERR("source_wavread: Failed opening %s (%s)\n", s->path, errorstr);
     goto beach;
   }
@@ -134,6 +132,6 @@
     bytes_junk += read_little_endian(buf, 4);
     if (fseek(s->fid, bytes_read + bytes_junk, SEEK_SET) != 0) {
-      AUBIO_ERR("source_wavread: Failed opening %s (could not seek past JUNK Chunk: %s)\n",
-          s->path, strerror(errno));
+      AUBIO_STRERR("source_wavread: Failed opening %s (could not seek past JUNK Chunk: %s)\n",
+          s->path, errorstr);
       goto beach;
     }
@@ -262,6 +260,6 @@
     bytes_junk += read_little_endian(buf, 4);
     if (fseek(s->fid, bytes_read + bytes_junk, SEEK_SET) != 0) {
-      AUBIO_ERR("source_wavread: could not seek past unknown chunk in %s (%s)\n",
-          s->path, strerror(errno));
+      AUBIO_STRERR("source_wavread: could not seek past unknown chunk in %s (%s)\n",
+          s->path, errorstr);
       goto beach;
     }
@@ -443,5 +441,5 @@
   ret = fseek(s->fid, s->seek_start + pos * s->blockalign, SEEK_SET);
   if (ret != 0) {
-    AUBIO_ERR("source_wavread: could not seek %s at %d (%s)\n", s->path, pos, strerror(errno));
+    AUBIO_STRERR("source_wavread: could not seek %s at %d (%s)\n", s->path, pos, errorstr);
     return AUBIO_FAIL;
   }
@@ -464,5 +462,5 @@
   }
   if (fclose(s->fid)) {
-    AUBIO_ERR("source_wavread: could not close %s (%s)\n", s->path, strerror(errno));
+    AUBIO_STRERR("source_wavread: could not close %s (%s)\n", s->path, errorstr);
     return AUBIO_FAIL;
   }
