annotate 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
rev   line source
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@107 50 MultiplexedReader::getInterleavedFrames(int start, int count,
Chris@107 51 SampleBlock &frames) const
Chris@107 52 {
Chris@107 53 int nr = m_readers.size();
Chris@107 54
Chris@107 55 frames = SampleBlock(count * nr);
Chris@107 56
Chris@107 57 for (int ri = 0; ri < nr; ++ri) {
Chris@107 58
Chris@107 59 AudioFileReader *reader = m_readers[ri];
Chris@107 60 SampleBlock rs(count * reader->getChannelCount());
Chris@107 61
Chris@107 62 reader->getInterleavedFrames(start, count, rs);
Chris@107 63
Chris@107 64 int nc = reader->getChannelCount();
Chris@107 65 for (int i = 0; i < count; ++i) {
Chris@107 66 for (int c = 0; c < nc; ++c) {
Chris@107 67 frames[i * nr + ri] += rs[i * nc + c];
Chris@107 68 }
Chris@107 69 }
Chris@107 70 }
Chris@107 71 }
Chris@107 72
Chris@107 73 int
Chris@107 74 MultiplexedReader::getDecodeCompletion() const
Chris@107 75 {
Chris@107 76 int completion = 100;
Chris@107 77 foreach (AudioFileReader *r, m_readers) {
Chris@107 78 int c = r->getDecodeCompletion();
Chris@107 79 if (c < 100) {
Chris@107 80 completion = c;
Chris@107 81 }
Chris@107 82 }
Chris@107 83 return completion;
Chris@107 84 }
Chris@107 85
Chris@107 86 bool
Chris@107 87 MultiplexedReader::isUpdating() const
Chris@107 88 {
Chris@107 89 foreach (AudioFileReader *r, m_readers) {
Chris@107 90 if (r->isUpdating()) return true;
Chris@107 91 }
Chris@107 92 return false;
Chris@107 93 }
Chris@107 94
Chris@107 95
Chris@107 96