comparison runner/MultiplexedReader.cpp @ 107:7b60603966cf multiplex

Implementation of MultiplexedReader -- now builds, not yet tested
author Chris Cannam
date Thu, 02 Oct 2014 08:16:42 +0100
parents
children 34a0dad473c3
comparison
equal deleted inserted replaced
106:de76b2df518f 107:7b60603966cf
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Sonic Annotator
5 A utility for batch feature extraction from audio files.
6 Mark Levy, Chris Sutton and Chris Cannam, Queen Mary, University of London.
7 Copyright 2007-2014 QMUL.
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information.
14 */
15
16 #include "MultiplexedReader.h"
17
18 MultiplexedReader::MultiplexedReader(QList<AudioFileReader *> readers) :
19 m_readers(readers)
20 {
21 m_channelCount = readers.size();
22 m_sampleRate = readers[0]->getSampleRate();
23
24 m_frameCount = 0;
25 m_quicklySeekable = true;
26
27 foreach (AudioFileReader *r, m_readers) {
28 if (!r->isOK()) {
29 m_channelCount = 0;
30 m_error = r->getError();
31 } else {
32 if (r->getFrameCount() > m_frameCount) {
33 m_frameCount = r->getFrameCount();
34 }
35 if (!r->isQuicklySeekable()) {
36 m_quicklySeekable = false;
37 }
38 }
39 }
40 }
41
42 MultiplexedReader::~MultiplexedReader()
43 {
44 foreach (AudioFileReader *r, m_readers) {
45 delete r;
46 }
47 }
48
49 void
50 MultiplexedReader::getInterleavedFrames(int start, int count,
51 SampleBlock &frames) const
52 {
53 int nr = m_readers.size();
54
55 frames = SampleBlock(count * nr);
56
57 for (int ri = 0; ri < nr; ++ri) {
58
59 AudioFileReader *reader = m_readers[ri];
60 SampleBlock rs(count * reader->getChannelCount());
61
62 reader->getInterleavedFrames(start, count, rs);
63
64 int nc = reader->getChannelCount();
65 for (int i = 0; i < count; ++i) {
66 for (int c = 0; c < nc; ++c) {
67 frames[i * nr + ri] += rs[i * nc + c];
68 }
69 }
70 }
71 }
72
73 int
74 MultiplexedReader::getDecodeCompletion() const
75 {
76 int completion = 100;
77 foreach (AudioFileReader *r, m_readers) {
78 int c = r->getDecodeCompletion();
79 if (c < 100) {
80 completion = c;
81 }
82 }
83 return completion;
84 }
85
86 bool
87 MultiplexedReader::isUpdating() const
88 {
89 foreach (AudioFileReader *r, m_readers) {
90 if (r->isUpdating()) return true;
91 }
92 return false;
93 }
94
95
96