shithub: aubio

Download patch

ref: a97eb17080f83a762b0004119080b07926e4bf7e
parent: 2d64a24e5bbe1f921a76d5c57421e37ece6745bb
author: Paul Brossier <piem@piem.org>
date: Wed Dec 12 20:46:29 EST 2018

[io] sink_wavwrite_do writes all to channels if more than one

--- a/src/io/sink_wavwrite.c
+++ b/src/io/sink_wavwrite.c
@@ -233,7 +233,7 @@
 
 
 void aubio_sink_wavwrite_do(aubio_sink_wavwrite_t *s, fvec_t * write_data, uint_t write){
-  uint_t i = 0, written_frames = 0;
+  uint_t c = 0, i = 0, written_frames = 0;
 
   if (write > s->max_size) {
     AUBIO_WRN("sink_wavwrite: trying to write %d frames to %s, "
@@ -241,10 +241,12 @@
     write = s->max_size;
   }
 
-  for (i = 0; i < write; i++) {
-    s->scratch_data[i] = HTOLES(FLOAT_TO_SHORT(write_data->data[i]));
+  for (c = 0; c < s->channels; c++) {
+    for (i = 0; i < write; i++) {
+      s->scratch_data[i * s->channels + c] = HTOLES(FLOAT_TO_SHORT(write_data->data[i]));
+    }
   }
-  written_frames = fwrite(s->scratch_data, 2, write, s->fid);
+  written_frames = fwrite(s->scratch_data, 2, write * s->channels, s->fid);
 
   if (written_frames != write) {
     AUBIO_WRN("sink_wavwrite: trying to write %d frames to %s, "