comparison runner/MultiplexedReader.cpp @ 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 7b60603966cf
children 3287df4588dd
comparison
equal deleted inserted replaced
113:297f9e415e39 114:34a0dad473c3
45 delete r; 45 delete r;
46 } 46 }
47 } 47 }
48 48
49 void 49 void
50 MultiplexedReader::getInterleavedFrames(int start, int count, 50 MultiplexedReader::getInterleavedFrames(int start, int frameCount,
51 SampleBlock &frames) const 51 SampleBlock &block) const
52 { 52 {
53 int nr = m_readers.size(); 53 int out_chans = m_readers.size();
54 54
55 frames = SampleBlock(count * nr); 55 // Allocate and zero
56 block = SampleBlock(frameCount * out_chans, 0.f);
56 57
57 for (int ri = 0; ri < nr; ++ri) { 58 for (int out_chan = 0; out_chan < out_chans; ++out_chan) {
58 59
59 AudioFileReader *reader = m_readers[ri]; 60 AudioFileReader *reader = m_readers[out_chan];
60 SampleBlock rs(count * reader->getChannelCount()); 61 SampleBlock readerBlock;
62 reader->getInterleavedFrames(start, frameCount, readerBlock);
61 63
62 reader->getInterleavedFrames(start, count, rs); 64 int in_chans = reader->getChannelCount();
63 65
64 int nc = reader->getChannelCount(); 66 for (int frame = 0; frame < frameCount; ++frame) {
65 for (int i = 0; i < count; ++i) { 67
66 for (int c = 0; c < nc; ++c) { 68 int out_index = frame * out_chans + out_chan;
67 frames[i * nr + ri] += rs[i * nc + c]; 69
70 for (int in_chan = 0; in_chan < in_chans; ++in_chan) {
71 int in_index = frame * in_chans + in_chan;
72 if (in_index >= (int)readerBlock.size()) break;
73 block[out_index] += readerBlock[in_index];
68 } 74 }
75
76 if (in_chans > 1) {
77 block[out_index] /= float(in_chans);
78 }
69 } 79 }
70 } 80 }
71 } 81 }
72 82
73 int 83 int