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