Index: src/io/sink_sndfile.c
===================================================================
--- src/io/sink_sndfile.c	(revision 870ad7018d0370e0a040a5cafdc42c2b8f320d68)
+++ src/io/sink_sndfile.c	(revision 14ac1db982c8111ab2e74041c26d505f711fe536)
@@ -1,4 +1,4 @@
 /*
-  Copyright (C) 2012 Paul Brossier <piem@aubio.org>
+  Copyright (C) 2012-2014 Paul Brossier <piem@aubio.org>
 
   This file is part of aubio.
@@ -45,7 +45,10 @@
 };
 
+uint_t aubio_sink_sndfile_open(aubio_sink_sndfile_t *s);
+
 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);
-  SF_INFO sfinfo;
+  s->max_size = MAX_SIZE;
+  s->path = path;
 
   if (path == NULL) {
@@ -54,10 +57,60 @@
   }
 
+  s->samplerate = 0;
+  s->channels = 0;
+
+  // negative samplerate given, abort
+  if ((sint_t)samplerate < 0) goto beach;
+  // zero samplerate given. do not open yet
+  if ((sint_t)samplerate == 0) return s;
+
   s->samplerate = samplerate;
-  s->max_size = MAX_SIZE;
   s->channels = 1;
-  s->path = path;
 
+  if (aubio_sink_sndfile_open(s) != AUBIO_OK) {;
+    goto beach;
+  }
+  return s;
+
+beach:
+  del_aubio_sink_sndfile(s);
+  return NULL;
+}
+
+uint_t aubio_sink_sndfile_preset_samplerate(aubio_sink_sndfile_t *s, uint_t samplerate)
+{
+  if ((sint_t)(samplerate) <= 0) return AUBIO_FAIL;
+  s->samplerate = samplerate;
+  // automatically open when both samplerate and channels have been set
+  if (s->samplerate != 0 && s->channels != 0) {
+    return aubio_sink_sndfile_open(s);
+  }
+  return AUBIO_OK;
+}
+
+uint_t aubio_sink_sndfile_preset_channels(aubio_sink_sndfile_t *s, uint_t channels)
+{
+  if ((sint_t)(channels) <= 0) return AUBIO_FAIL;
+  s->channels = channels;
+  // automatically open when both samplerate and channels have been set
+  if (s->samplerate != 0 && s->channels != 0) {
+    return aubio_sink_sndfile_open(s);
+  }
+  return AUBIO_OK;
+}
+
+uint_t aubio_sink_sndfile_get_samplerate(aubio_sink_sndfile_t *s)
+{
+  return s->samplerate;
+}
+
+uint_t aubio_sink_sndfile_get_channels(aubio_sink_sndfile_t *s)
+{
+  return s->channels;
+}
+
+uint_t aubio_sink_sndfile_open(aubio_sink_sndfile_t *s) {
   /* set output format */
+  SF_INFO sfinfo;
   AUBIO_MEMSET(&sfinfo, 0, sizeof (sfinfo));
   sfinfo.samplerate = s->samplerate;
@@ -71,6 +124,5 @@
     /* show libsndfile err msg */
     AUBIO_ERR("sink_sndfile: Failed opening %s. %s\n", s->path, sf_strerror (NULL));
-    AUBIO_FREE(s);
-    return NULL;
+    return AUBIO_FAIL;
   }	
 
@@ -80,10 +132,9 @@
     AUBIO_ERR("sink_sndfile: %d x %d exceeds maximum aubio_sink_sndfile buffer size %d\n",
         s->max_size, s->channels, MAX_CHANNELS * MAX_CHANNELS);
-    AUBIO_FREE(s);
-    return NULL;
+    return AUBIO_FAIL;
   }
   s->scratch_data = AUBIO_ARRAY(float,s->scratch_size);
 
-  return s;
+  return AUBIO_OK;
 }
 
Index: src/io/sink_sndfile.h
===================================================================
--- src/io/sink_sndfile.h	(revision 870ad7018d0370e0a040a5cafdc42c2b8f320d68)
+++ src/io/sink_sndfile.h	(revision 14ac1db982c8111ab2e74041c26d505f711fe536)
@@ -1,4 +1,4 @@
 /*
-  Copyright (C) 2012-2013 Paul Brossier <piem@aubio.org>
+  Copyright (C) 2012-2014 Paul Brossier <piem@aubio.org>
 
   This file is part of aubio.
@@ -39,4 +39,5 @@
 #endif
 
+/** sink_sndfile object */
 typedef struct _aubio_sink_sndfile_t aubio_sink_sndfile_t;
 
@@ -52,6 +53,64 @@
   Creates a new sink object.
 
+  If samplerate is set to 0, the creation of the file will be delayed until
+  both ::aubio_sink_preset_samplerate and ::aubio_sink_preset_channels have
+  been called.
+
 */
 aubio_sink_sndfile_t * new_aubio_sink_sndfile(char_t * uri, uint_t samplerate);
+
+/**
+
+  preset sink samplerate
+
+  \param s sink, created with ::new_aubio_sink_sndfile
+  \param samplerate samplerate to preset the sink to, in Hz
+
+  \return 0 on success, 1 on error
+
+  Preset the samplerate of the sink. The file should have been created using a
+  samplerate of 0.
+
+  The file will be opened only when both samplerate and channels have been set.
+
+*/
+uint_t aubio_sink_sndfile_preset_samplerate(aubio_sink_sndfile_t *s, uint_t samplerate);
+
+/**
+
+  preset sink channels
+
+  \param s sink, created with ::new_aubio_sink_sndfile
+  \param channels number of channels to preset the sink to
+
+  \return 0 on success, 1 on error
+
+  Preset the samplerate of the sink. The file should have been created using a
+  samplerate of 0.
+
+  The file will be opened only when both samplerate and channels have been set.
+
+*/
+uint_t aubio_sink_sndfile_preset_channels(aubio_sink_sndfile_t *s, uint_t channels);
+
+/**
+
+  get samplerate of sink object
+
+  \param s sink object, created with ::new_aubio_sink_sndfile
+  \return samplerate, in Hz
+
+*/
+uint_t aubio_sink_sndfile_get_samplerate(aubio_sink_sndfile_t *s);
+
+/**
+
+  get channels of sink object
+
+  \param s sink object, created with ::new_aubio_sink_sndfile
+  \return number of channels
+
+*/
+uint_t aubio_sink_sndfile_get_channels(aubio_sink_sndfile_t *s);
 
 /**
@@ -65,4 +124,15 @@
 */
 void aubio_sink_sndfile_do(aubio_sink_sndfile_t * s, fvec_t * write_data, uint_t write);
+
+/**
+
+  write polyphonic vector of length hop_size to sink
+
+  \param s sink, created with ::new_aubio_sink_sndfile
+  \param write_data ::fmat_t samples to write to sink
+  \param write number of frames to write
+
+*/
+void aubio_sink_sndfile_do_multi(aubio_sink_sndfile_t * s, fmat_t * write_data, uint_t write);
 
 /**
