changeset 114:34a0dad473c3 multiplex

Average channels of file contributing to each input, don't sum
author Chris Cannam
date Fri, 03 Oct 2014 09:30:18 +0100
parents 297f9e415e39
children 95de6db296a1
files .hgsubstate runner/MultiplexedReader.cpp
diffstat 2 files changed, 23 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/.hgsubstate	Thu Oct 02 16:46:39 2014 +0100
+++ b/.hgsubstate	Fri Oct 03 09:30:18 2014 +0100
@@ -1,2 +1,2 @@
 d16f0fd6db6104d87882bc43788a3bb1b0f8c528 dataquay
-58c4d69b4dd8ff05908097ea2d5c520067b12aa4 svcore
+c9d456b1fcde4ddc6e0347c4eb105a8b6e4ca527 svcore
--- a/runner/MultiplexedReader.cpp	Thu Oct 02 16:46:39 2014 +0100
+++ b/runner/MultiplexedReader.cpp	Fri Oct 03 09:30:18 2014 +0100
@@ -47,25 +47,35 @@
 }
 
 void
-MultiplexedReader::getInterleavedFrames(int start, int count,
-					SampleBlock &frames) const
+MultiplexedReader::getInterleavedFrames(int start, int frameCount,
+					SampleBlock &block) const
 {
-    int nr = m_readers.size();
+    int out_chans = m_readers.size();
 
-    frames = SampleBlock(count * nr);
+    // Allocate and zero
+    block = SampleBlock(frameCount * out_chans, 0.f);
 
-    for (int ri = 0; ri < nr; ++ri) {
+    for (int out_chan = 0; out_chan < out_chans; ++out_chan) {
 
-	AudioFileReader *reader = m_readers[ri];
-	SampleBlock rs(count * reader->getChannelCount());
+	AudioFileReader *reader = m_readers[out_chan];
+	SampleBlock readerBlock;
+	reader->getInterleavedFrames(start, frameCount, readerBlock);
 
-	reader->getInterleavedFrames(start, count, rs);
+	int in_chans = reader->getChannelCount();
 
-	int nc = reader->getChannelCount();
-	for (int i = 0; i < count; ++i) {
-	    for (int c = 0; c < nc; ++c) {
-		frames[i * nr + ri] += rs[i * nc + c];
+	for (int frame = 0; frame < frameCount; ++frame) {
+
+            int out_index = frame * out_chans + out_chan;
+
+	    for (int in_chan = 0; in_chan < in_chans; ++in_chan) {
+                int in_index = frame * in_chans + in_chan;
+                if (in_index >= (int)readerBlock.size()) break;
+		block[out_index] += readerBlock[in_index];
 	    }
+
+            if (in_chans > 1) {
+                block[out_index] /= float(in_chans);
+            }
 	}
     }
 }