update WAV writer for interleaved audio support
authorKostya Shishkov <kostya.shishkov@gmail.com>
Fri, 6 Mar 2020 18:14:40 +0000 (19:14 +0100)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Fri, 6 Mar 2020 18:14:40 +0000 (19:14 +0100)
src/wavwriter.rs

index d72b82a11606444e98af59e4d3d71d046445226e..fbf825d88e79046a4f0dd01349472fb2175b92d0 100644 (file)
@@ -37,11 +37,19 @@ macro_rules! write_data {
         let nch = ainfo.get_channels() as usize;
         let mut offs: Vec<usize> = Vec::with_capacity(nch);
         for ch in 0..nch { offs.push($buf.get_offset(ch)); }
+        let is_planar = $buf.get_step() == 1;
         let data = $buf.get_data();
 
-        for i in 0..len {
-            for ch in 0..nch {
-                let sample = data[offs[ch] + i];
+        if is_planar {
+            for i in 0..len {
+                for ch in 0..nch {
+                    let sample = data[offs[ch] + i];
+                    $write($wr, sample)?;
+                }
+            }
+        } else {
+            for i in 0..len*nch {
+                let sample = data[i];
                 $write($wr, sample)?;
             }
         }