annotate runner/MultiplexedReader.cpp @ 187:889f770abff3

mp3 file with ID3v2 tag in ISO-8859-1
author Chris Cannam
date Wed, 25 Feb 2015 09:31:39 +0000
parents 3287df4588dd
children 3f7c65f26559
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@185 31 } else if (r->getSampleRate() != m_sampleRate) {
Chris@185 32 m_channelCount = 0;
Chris@185 33 m_error = "Readers provided to MultiplexedReader must have the same sample rate";
Chris@107 34 } else {
Chris@107 35 if (r->getFrameCount() > m_frameCount) {
Chris@107 36 m_frameCount = r->getFrameCount();
Chris@107 37 }
Chris@107 38 if (!r->isQuicklySeekable()) {
Chris@107 39 m_quicklySeekable = false;
Chris@107 40 }
Chris@107 41 }
Chris@107 42 }
Chris@107 43 }
Chris@107 44
Chris@107 45 MultiplexedReader::~MultiplexedReader()
Chris@107 46 {
Chris@107 47 foreach (AudioFileReader *r, m_readers) {
Chris@107 48 delete r;
Chris@107 49 }
Chris@107 50 }
Chris@107 51
Chris@107 52 void
Chris@114 53 MultiplexedReader::getInterleavedFrames(int start, int frameCount,
Chris@114 54 SampleBlock &block) const
Chris@107 55 {
Chris@114 56 int out_chans = m_readers.size();
Chris@107 57
Chris@114 58 // Allocate and zero
Chris@114 59 block = SampleBlock(frameCount * out_chans, 0.f);
Chris@107 60
Chris@114 61 for (int out_chan = 0; out_chan < out_chans; ++out_chan) {
Chris@107 62
Chris@114 63 AudioFileReader *reader = m_readers[out_chan];
Chris@114 64 SampleBlock readerBlock;
Chris@114 65 reader->getInterleavedFrames(start, frameCount, readerBlock);
Chris@107 66
Chris@114 67 int in_chans = reader->getChannelCount();
Chris@107 68
Chris@114 69 for (int frame = 0; frame < frameCount; ++frame) {
Chris@114 70
Chris@114 71 int out_index = frame * out_chans + out_chan;
Chris@114 72
Chris@114 73 for (int in_chan = 0; in_chan < in_chans; ++in_chan) {
Chris@114 74 int in_index = frame * in_chans + in_chan;
Chris@114 75 if (in_index >= (int)readerBlock.size()) break;
Chris@114 76 block[out_index] += readerBlock[in_index];
Chris@107 77 }
Chris@114 78
Chris@114 79 if (in_chans > 1) {
Chris@114 80 block[out_index] /= float(in_chans);
Chris@114 81 }
Chris@107 82 }
Chris@107 83 }
Chris@107 84 }
Chris@107 85
Chris@107 86 int
Chris@107 87 MultiplexedReader::getDecodeCompletion() const
Chris@107 88 {
Chris@107 89 int completion = 100;
Chris@107 90 foreach (AudioFileReader *r, m_readers) {
Chris@107 91 int c = r->getDecodeCompletion();
Chris@107 92 if (c < 100) {
Chris@107 93 completion = c;
Chris@107 94 }
Chris@107 95 }
Chris@107 96 return completion;
Chris@107 97 }
Chris@107 98
Chris@107 99 bool
Chris@107 100 MultiplexedReader::isUpdating() const
Chris@107 101 {
Chris@107 102 foreach (AudioFileReader *r, m_readers) {
Chris@107 103 if (r->isUpdating()) return true;
Chris@107 104 }
Chris@107 105 return false;
Chris@107 106 }
Chris@107 107
Chris@107 108
Chris@107 109