src/io/sink_sndfile.c: add missing do_multi
authorPaul Brossier <piem@piem.org>
Sun, 23 Feb 2014 16:29:42 +0000 (13:29 -0300)
committerPaul Brossier <piem@piem.org>
Sun, 23 Feb 2014 16:29:42 +0000 (13:29 -0300)
src/io/sink_sndfile.c

index 2824e74..5fae2cf 100644 (file)
@@ -26,8 +26,9 @@
 #include <sndfile.h>
 
 #include "aubio_priv.h"
 #include <sndfile.h>
 
 #include "aubio_priv.h"
-#include "sink_sndfile.h"
 #include "fvec.h"
 #include "fvec.h"
+#include "fmat.h"
+#include "io/sink_sndfile.h"
 
 #define MAX_CHANNELS 6
 #define MAX_SIZE 4096
 
 #define MAX_CHANNELS 6
 #define MAX_SIZE 4096
@@ -166,6 +167,34 @@ void aubio_sink_sndfile_do(aubio_sink_sndfile_t *s, fvec_t * write_data, uint_t
   return;
 }
 
   return;
 }
 
+void aubio_sink_sndfile_do_multi(aubio_sink_sndfile_t *s, fmat_t * write_data, uint_t write){
+  uint_t i, j, channels = s->channels;
+  int nsamples = channels*write;
+  smpl_t *pwrite;
+  sf_count_t written_frames;
+
+  if (write > s->max_size) {
+    AUBIO_WRN("trying to write %d frames, but only %d can be written at a time",
+      write, s->max_size);
+    write = s->max_size;
+  }
+
+  /* interleaving data  */
+  for ( i = 0; i < write_data->height; i++) {
+    pwrite = (smpl_t *)write_data->data[i];
+    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);
+  if (written_frames/channels != write) {
+    AUBIO_WRN("sink_sndfile: trying to write %d frames to %s, but only %d could be written",
+      write, s->path, (uint_t)written_frames);
+  }
+  return;
+}
+
 uint_t aubio_sink_sndfile_close (aubio_sink_sndfile_t *s) {
   if (!s->handle) {
     return AUBIO_FAIL;
 uint_t aubio_sink_sndfile_close (aubio_sink_sndfile_t *s) {
   if (!s->handle) {
     return AUBIO_FAIL;