annotate data/fileio/AudioFileReader.h @ 1881:b504df98c3be

Ensure completion on output model is started at zero, so if it's checked before the input model has become ready and the transform has begun, it is not accidentally reported as complete (affected re-aligning models in Sonic Lineup when replacing the session)
author Chris Cannam
date Fri, 26 Jun 2020 11:45:39 +0100
parents 73447d746db3
children
rev   line source
Chris@148 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@148 2
Chris@148 3 /*
Chris@148 4 Sonic Visualiser
Chris@148 5 An audio file viewer and annotation editor.
Chris@148 6 Centre for Digital Music, Queen Mary, University of London.
Chris@148 7 This file copyright 2006 Chris Cannam.
Chris@148 8
Chris@148 9 This program is free software; you can redistribute it and/or
Chris@148 10 modify it under the terms of the GNU General Public License as
Chris@148 11 published by the Free Software Foundation; either version 2 of the
Chris@148 12 License, or (at your option) any later version. See the file
Chris@148 13 COPYING included with this distribution for more information.
Chris@148 14 */
Chris@148 15
Chris@1581 16 #ifndef SV_AUDIO_FILE_READER_H
Chris@1581 17 #define SV_AUDIO_FILE_READER_H
Chris@148 18
Chris@290 19 #include <QString>
Chris@148 20
Chris@1038 21 #include "base/BaseTypes.h"
Chris@317 22 #include "FileSource.h"
Chris@316 23
Chris@327 24 #include <vector>
Chris@632 25 #include <map>
Chris@327 26
Chris@175 27 class AudioFileReader : public QObject
Chris@148 28 {
Chris@175 29 Q_OBJECT
Chris@175 30
Chris@148 31 public:
Chris@148 32 virtual ~AudioFileReader() { }
Chris@148 33
Chris@1313 34 /**
Chris@1313 35 * Return true if the file was opened successfully and no error
Chris@1313 36 * has subsequently occurred.
Chris@1313 37 */
Chris@148 38 bool isOK() const { return (m_channelCount > 0); }
Chris@148 39
Chris@1313 40 /**
Chris@1313 41 * If isOK() is false, return an error string.
Chris@1313 42 */
Chris@290 43 virtual QString getError() const { return ""; }
Chris@148 44
Chris@1313 45 /**
Chris@1313 46 * Return the number of audio sample frames (i.e. samples per
Chris@1313 47 * channel) in the file.
Chris@1313 48 */
Chris@1038 49 sv_frame_t getFrameCount() const { return m_frameCount; }
Chris@1313 50
Chris@1313 51 /**
Chris@1313 52 * Return the number of channels in the file.
Chris@1313 53 */
Chris@929 54 int getChannelCount() const { return m_channelCount; }
Chris@1313 55
Chris@1313 56 /**
Chris@1313 57 * Return the samplerate at which the file is being read. This is
Chris@1313 58 * the rate requested when the file was opened, which may differ
Chris@1313 59 * from the native rate of the file (in which case the file will
Chris@1313 60 * be resampled as it is read).
Chris@1313 61 */
Chris@1040 62 sv_samplerate_t getSampleRate() const { return m_sampleRate; }
Chris@660 63
Chris@1313 64 /**
Chris@1313 65 * Return the native samplerate of the file. This will differ from
Chris@1313 66 * getSampleRate() if the file is being resampled because it was
Chris@1313 67 * requested to open at a different rate from native.
Chris@1313 68 */
Chris@1313 69 virtual sv_samplerate_t getNativeRate() const { return m_sampleRate; }
Chris@345 70
Chris@345 71 /**
Chris@345 72 * Return the location of the audio data in the reader (as passed
Chris@1809 73 * in to the FileSource constructor, for example). This might be a
Chris@1809 74 * remote URL.
Chris@1809 75 *
Chris@1809 76 * See also getLocalFilename().
Chris@345 77 */
Chris@1809 78 virtual QString getLocation() const = 0;
Chris@1809 79
Chris@1809 80 /**
Chris@1809 81 * Return the local file path of the audio data. This is the
Chris@1809 82 * filesystem location most likely to contain readable audio data,
Chris@1809 83 * but it may be in a different place or format from the
Chris@1809 84 * originally specified location - for example, if the file has
Chris@1809 85 * been retrieved and decoded, then it will be the (possibly
Chris@1809 86 * temporary) decode target file.
Chris@1809 87 *
Chris@1809 88 * This returns a non-empty value only if there is some local
Chris@1809 89 * filename that contains exactly the audio data being provided by
Chris@1809 90 * this reader. In some cases this may not exist, for example when
Chris@1809 91 * a file has been resampled or normalised directly into a memory
Chris@1809 92 * buffer. In this case, return an empty string.
Chris@1809 93 *
Chris@1809 94 * See also getLocation().
Chris@1809 95 */
Chris@1809 96 virtual QString getLocalFilename() const = 0;
Chris@148 97
Chris@271 98 /**
Chris@271 99 * Return the title of the work in the audio file, if known. This
Chris@271 100 * may be implemented by subclasses that support file tagging.
Chris@271 101 * This is not the same thing as the file name.
Chris@271 102 */
Chris@1592 103 virtual QString getTitle() const = 0;
Chris@271 104
Chris@333 105 /**
Chris@333 106 * Return the "maker" of the work in the audio file, if known.
Chris@333 107 * This could represent almost anything (band, composer,
Chris@333 108 * conductor, artist etc).
Chris@333 109 */
Chris@1592 110 virtual QString getMaker() const = 0;
Chris@333 111
Chris@1010 112 /**
Chris@1809 113 * Return any tag pairs picked up from the audio file. See also
Chris@1809 114 * getTitle and getMaker, and note that a reader which does not
Chris@1809 115 * implement getTags may still return values from those.
Chris@1010 116 */
Chris@632 117 typedef std::map<QString, QString> TagMap;
Chris@632 118 virtual TagMap getTags() const { return TagMap(); }
Chris@632 119
Chris@823 120 /**
Chris@823 121 * Return true if this file supports fast seek and random
Chris@823 122 * access. Typically this will be true for uncompressed formats
Chris@823 123 * and false for compressed ones.
Chris@823 124 */
Chris@823 125 virtual bool isQuicklySeekable() const = 0;
Chris@823 126
Chris@1809 127 /**
Chris@1809 128 * Return a percentage value indicating how far through decoding
Chris@1809 129 * the audio file we are. This should be implemented by subclasses
Chris@1809 130 * that will not know exactly how long the audio file is (in
Chris@1809 131 * sample frames) until it has been completely decoded. A reader
Chris@1809 132 * that initialises the frame count directly within its
Chris@1809 133 * constructor should always return 100 from this.
Chris@1809 134 */
Chris@1809 135 virtual int getDecodeCompletion() const { return 100; }
Chris@1809 136
Chris@1809 137 /**
Chris@1809 138 * Return true if decoding is still in progress and the frame
Chris@1809 139 * count may change.
Chris@1809 140 */
Chris@1809 141 virtual bool isUpdating() const { return false; }
Chris@1809 142
Chris@148 143 /**
Chris@327 144 * Return interleaved samples for count frames from index start.
Chris@1096 145 * The resulting vector will contain count * getChannelCount()
Chris@1096 146 * samples (or fewer if end of file is reached).
Chris@327 147 *
Chris@148 148 * The subclass implementations of this function must be
Chris@148 149 * thread-safe -- that is, safe to call from multiple threads with
Chris@148 150 * different arguments on the same object at the same time.
Chris@148 151 */
Chris@1326 152 virtual floatvec_t getInterleavedFrames(sv_frame_t start,
Chris@1326 153 sv_frame_t count) const = 0;
Chris@175 154
Chris@327 155 /**
Chris@327 156 * Return de-interleaved samples for count frames from index
Chris@327 157 * start. Implemented in this class (it calls
Chris@327 158 * getInterleavedFrames and de-interleaves). The resulting vector
Chris@327 159 * will contain getChannelCount() sample blocks of count samples
Chris@327 160 * each (or fewer if end of file is reached).
Chris@327 161 */
Chris@1326 162 virtual std::vector<floatvec_t> getDeInterleavedFrames(sv_frame_t start,
Chris@1326 163 sv_frame_t count) const;
Chris@327 164
Chris@175 165 signals:
Chris@175 166 void frameCountChanged();
Chris@148 167
Chris@148 168 protected:
Chris@1038 169 sv_frame_t m_frameCount;
Chris@929 170 int m_channelCount;
Chris@1040 171 sv_samplerate_t m_sampleRate;
Chris@148 172 };
Chris@148 173
Chris@148 174 #endif