Index: src/io/sink.c
===================================================================
--- src/io/sink.c	(revision 11a1abeed4f2c07cef3779baea79f777ead327ed)
+++ src/io/sink.c	(revision 8aed26d0f87080653ecfa3d43e21296c13580e94)
@@ -23,16 +23,30 @@
 #include "fvec.h"
 #include "io/sink.h"
+#ifdef __APPLE__
+#include "io/sink_apple_audio.h"
+#endif /* __APPLE__ */
+#ifdef HAVE_SNDFILE
+#include "io/sink_sndfile.h"
+#endif
 
 struct _aubio_sink_t { 
-  uint_t hopsize;
-  uint_t samplerate;
+  void *sink;
 };
 
-aubio_sink_t * new_aubio_sink(char_t * uri, uint_t hop_size, uint_t samplerate) {
+aubio_sink_t * new_aubio_sink(char_t * uri, uint_t samplerate) {
   aubio_sink_t * s = AUBIO_NEW(aubio_sink_t);
-  return s;
+#ifdef __APPLE__
+  s->sink = (void *)new_aubio_sink_apple_audio(uri, samplerate);
+  if (s->sink) return s;
+#else /* __APPLE__ */
+#if HAVE_SNDFILE
+  s->sink = (void *)new_aubio_sink_sndfile(uri, samplerate);
+  if (s->sink) return s;
+#endif /* HAVE_SNDFILE */
+#endif /* __APPLE__ */
+  if (s->sink == NULL) { AUBIO_FREE(s); return NULL; }
 }
 
-void aubio_sink_do(aubio_sink_t * s, fvec_t * write_data, uint_t * written) {
+void aubio_sink_do(aubio_sink_t * s, fvec_t * write_data, uint_t write) {
 }
 
Index: src/io/sink.h
===================================================================
--- src/io/sink.h	(revision 11a1abeed4f2c07cef3779baea79f777ead327ed)
+++ src/io/sink.h	(revision 8aed26d0f87080653ecfa3d43e21296c13580e94)
@@ -33,6 +33,6 @@
 
 typedef struct _aubio_sink_t aubio_sink_t;
-aubio_sink_t * new_aubio_sink(char_t * method, uint_t hop_size, uint_t samplerate);
-void aubio_sink_do(aubio_sink_t * s, fvec_t * write_data, uint_t * written);
+aubio_sink_t * new_aubio_sink(char_t * method, uint_t samplerate);
+void aubio_sink_do(aubio_sink_t * s, fvec_t * write_data, uint_t written);
 void del_aubio_sink(aubio_sink_t * s);
 
Index: src/io/sink_sndfile.c
===================================================================
--- src/io/sink_sndfile.c	(revision 11a1abeed4f2c07cef3779baea79f777ead327ed)
+++ src/io/sink_sndfile.c	(revision 8aed26d0f87080653ecfa3d43e21296c13580e94)
@@ -34,5 +34,4 @@
 
 struct _aubio_sink_sndfile_t {
-  uint_t hop_size;
   uint_t samplerate;
   uint_t channels;
@@ -43,5 +42,5 @@
 };
 
-aubio_sink_sndfile_t * new_aubio_sink_sndfile(char_t * path, uint_t samplerate, uint_t hop_size) {
+aubio_sink_sndfile_t * new_aubio_sink_sndfile(char_t * path, uint_t samplerate) {
   aubio_sink_sndfile_t * s = AUBIO_NEW(aubio_sink_sndfile_t);
 
@@ -51,6 +50,6 @@
   }
 
-  s->hop_size = hop_size;
   s->samplerate = samplerate;
+  s->max_size = MAX_SIZE;
   s->channels = 1;
   s->path = path;
@@ -72,9 +71,9 @@
   }	
 
-  s->scratch_size = s->hop_size*s->channels;
+  s->scratch_size = s->max-size*s->channels;
   /* allocate data for de/interleaving reallocated when needed. */
   if (s->scratch_size >= MAX_SIZE * MAX_CHANNELS) {
     AUBIO_ERR("%d x %d exceeds maximum aubio_sink_sndfile buffer size %d\n",
-        s->hop_size, s->channels, MAX_CHANNELS * MAX_CHANNELS);
+        s->max_size, s->channels, MAX_CHANNELS * MAX_CHANNELS);
     return NULL;
   }
@@ -84,19 +83,29 @@
 }
 
-void aubio_sink_sndfile_do(aubio_sink_sndfile_t *s, fvec_t * write, uint_t * written){
+void aubio_sink_sndfile_do(aubio_sink_sndfile_t *s, fvec_t * write_data, uint_t write){
   sf_count_t written_frames = 0;
   int i, j,	channels = s->channels;
-  int nsamples = channels*(*written);
+  int nsamples = channels*write;
   smpl_t *pwrite;
+
+  if (write > s->max_size) {
+    write = s->max_size;
+    AUBIO_WRN("trying to write %d frames, but only %d can be written at a time",
+      write, s->max_frames);
+  }
 
   /* interleaving data  */
   for ( i = 0; i < channels; i++) {
-    pwrite = (smpl_t *)write->data;
-    for (j=0; j < s->hop_size; j++) {
+    pwrite = (smpl_t *)write_data->data;
+    for (j=0; j < write; j++) {
       s->scratch_data[channels*j+i] = pwrite[j];
     }
   }
-  written_frames = sf_write_float (s->handle, s->scratch_data, nsamples);
-  *written = written_frames/channels;
+
+  uint_t written = sf_write_float (s->handle, s->scratch_data, nsamples);
+  if (written/channels != write) {
+    AUBIO_WRN("trying to write %d frames to %s, but only %d could be written",
+      write, s->path, written);
+  }
   return;
 }
Index: src/io/sink_sndfile.h
===================================================================
--- src/io/sink_sndfile.h	(revision 11a1abeed4f2c07cef3779baea79f777ead327ed)
+++ src/io/sink_sndfile.h	(revision 8aed26d0f87080653ecfa3d43e21296c13580e94)
@@ -33,6 +33,6 @@
 
 typedef struct _aubio_sink_sndfile_t aubio_sink_sndfile_t;
-aubio_sink_sndfile_t * new_aubio_sink_sndfile(char_t * method, uint_t hop_size, uint_t samplerate);
-void aubio_sink_sndfile_do(aubio_sink_sndfile_t * s, fvec_t * write_data, uint_t * written);
+aubio_sink_sndfile_t * new_aubio_sink_sndfile(char_t * method, uint_t samplerate);
+void aubio_sink_sndfile_do(aubio_sink_sndfile_t * s, fvec_t * write_data, uint_t write);
 void del_aubio_sink_sndfile(aubio_sink_sndfile_t * s);
 
