# HG changeset patch # User Chris Cannam # Date 1412325018 -3600 # Node ID 34a0dad473c3c98adc5837c29ced67b752fb8349 # Parent 297f9e415e3906919ca9a12af82947bad528bee0 Average channels of file contributing to each input, don't sum diff -r 297f9e415e39 -r 34a0dad473c3 .hgsubstate --- 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 diff -r 297f9e415e39 -r 34a0dad473c3 runner/MultiplexedReader.cpp --- 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); + } } } }