annotate data/fileio/AudioFileReader.h @ 1478:8ff5505ad28d plugin-path-config

Get an expected value
author Chris Cannam
date Thu, 07 Jun 2018 16:40:28 +0100
parents 54af1e21705c
children ad5f892c0c4d f8e3dcbafb4d
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@148 16 #ifndef _AUDIO_FILE_READER_H_
Chris@148 17 #define _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@345 73 * in to the FileSource constructor, for example).
Chris@345 74 */
Chris@345 75 virtual QString getLocation() const { return ""; }
Chris@148 76
Chris@271 77 /**
Chris@271 78 * Return the title of the work in the audio file, if known. This
Chris@271 79 * may be implemented by subclasses that support file tagging.
Chris@271 80 * This is not the same thing as the file name.
Chris@271 81 */
Chris@290 82 virtual QString getTitle() const { return ""; }
Chris@271 83
Chris@333 84 /**
Chris@333 85 * Return the "maker" of the work in the audio file, if known.
Chris@333 86 * This could represent almost anything (band, composer,
Chris@333 87 * conductor, artist etc).
Chris@333 88 */
Chris@333 89 virtual QString getMaker() const { return ""; }
Chris@333 90
Chris@1010 91 /**
Chris@1010 92 * Return the local file path of the audio data. This is the
Chris@1010 93 * location most likely to contain readable audio data: it may be
Chris@1010 94 * in a different place or format from the originally specified
Chris@1010 95 * location, for example if the file has been retrieved and
Chris@1010 96 * decoded. In some cases there may be no local file path, and
Chris@1010 97 * this will return "" if there is none.
Chris@1010 98 */
Chris@1010 99 virtual QString getLocalFilename() const { return ""; }
Chris@1010 100
Chris@632 101 typedef std::map<QString, QString> TagMap;
Chris@632 102 virtual TagMap getTags() const { return TagMap(); }
Chris@632 103
Chris@823 104 /**
Chris@823 105 * Return true if this file supports fast seek and random
Chris@823 106 * access. Typically this will be true for uncompressed formats
Chris@823 107 * and false for compressed ones.
Chris@823 108 */
Chris@823 109 virtual bool isQuicklySeekable() const = 0;
Chris@823 110
Chris@148 111 /**
Chris@327 112 * Return interleaved samples for count frames from index start.
Chris@1096 113 * The resulting vector will contain count * getChannelCount()
Chris@1096 114 * samples (or fewer if end of file is reached).
Chris@327 115 *
Chris@148 116 * The subclass implementations of this function must be
Chris@148 117 * thread-safe -- that is, safe to call from multiple threads with
Chris@148 118 * different arguments on the same object at the same time.
Chris@148 119 */
Chris@1326 120 virtual floatvec_t getInterleavedFrames(sv_frame_t start,
Chris@1326 121 sv_frame_t count) const = 0;
Chris@175 122
Chris@327 123 /**
Chris@327 124 * Return de-interleaved samples for count frames from index
Chris@327 125 * start. Implemented in this class (it calls
Chris@327 126 * getInterleavedFrames and de-interleaves). The resulting vector
Chris@327 127 * will contain getChannelCount() sample blocks of count samples
Chris@327 128 * each (or fewer if end of file is reached).
Chris@327 129 */
Chris@1326 130 virtual std::vector<floatvec_t> getDeInterleavedFrames(sv_frame_t start,
Chris@1326 131 sv_frame_t count) const;
Chris@327 132
Chris@265 133 // only subclasses that do not know exactly how long the audio
Chris@265 134 // file is until it's been completely decoded should implement this
Chris@265 135 virtual int getDecodeCompletion() const { return 100; } // %
Chris@265 136
Chris@176 137 virtual bool isUpdating() const { return false; }
Chris@176 138
Chris@175 139 signals:
Chris@175 140 void frameCountChanged();
Chris@148 141
Chris@148 142 protected:
Chris@1038 143 sv_frame_t m_frameCount;
Chris@929 144 int m_channelCount;
Chris@1040 145 sv_samplerate_t m_sampleRate;
Chris@148 146 };
Chris@148 147
Chris@148 148 #endif