Chris@148: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@148: Chris@148: /* Chris@148: Sonic Visualiser Chris@148: An audio file viewer and annotation editor. Chris@148: Centre for Digital Music, Queen Mary, University of London. Chris@148: This file copyright 2006 Chris Cannam. Chris@148: Chris@148: This program is free software; you can redistribute it and/or Chris@148: modify it under the terms of the GNU General Public License as Chris@148: published by the Free Software Foundation; either version 2 of the Chris@148: License, or (at your option) any later version. See the file Chris@148: COPYING included with this distribution for more information. Chris@148: */ Chris@148: Chris@1581: #ifndef SV_AUDIO_FILE_READER_H Chris@1581: #define SV_AUDIO_FILE_READER_H Chris@148: Chris@290: #include Chris@148: Chris@1038: #include "base/BaseTypes.h" Chris@317: #include "FileSource.h" Chris@316: Chris@327: #include Chris@632: #include Chris@327: Chris@175: class AudioFileReader : public QObject Chris@148: { Chris@175: Q_OBJECT Chris@175: Chris@148: public: Chris@148: virtual ~AudioFileReader() { } Chris@148: Chris@1313: /** Chris@1313: * Return true if the file was opened successfully and no error Chris@1313: * has subsequently occurred. Chris@1313: */ Chris@148: bool isOK() const { return (m_channelCount > 0); } Chris@148: Chris@1313: /** Chris@1313: * If isOK() is false, return an error string. Chris@1313: */ Chris@290: virtual QString getError() const { return ""; } Chris@148: Chris@1313: /** Chris@1313: * Return the number of audio sample frames (i.e. samples per Chris@1313: * channel) in the file. Chris@1313: */ Chris@1038: sv_frame_t getFrameCount() const { return m_frameCount; } Chris@1313: Chris@1313: /** Chris@1313: * Return the number of channels in the file. Chris@1313: */ Chris@929: int getChannelCount() const { return m_channelCount; } Chris@1313: Chris@1313: /** Chris@1313: * Return the samplerate at which the file is being read. This is Chris@1313: * the rate requested when the file was opened, which may differ Chris@1313: * from the native rate of the file (in which case the file will Chris@1313: * be resampled as it is read). Chris@1313: */ Chris@1040: sv_samplerate_t getSampleRate() const { return m_sampleRate; } Chris@660: Chris@1313: /** Chris@1313: * Return the native samplerate of the file. This will differ from Chris@1313: * getSampleRate() if the file is being resampled because it was Chris@1313: * requested to open at a different rate from native. Chris@1313: */ Chris@1313: virtual sv_samplerate_t getNativeRate() const { return m_sampleRate; } Chris@345: Chris@345: /** Chris@345: * Return the location of the audio data in the reader (as passed Chris@1809: * in to the FileSource constructor, for example). This might be a Chris@1809: * remote URL. Chris@1809: * Chris@1809: * See also getLocalFilename(). Chris@345: */ Chris@1809: virtual QString getLocation() const = 0; Chris@1809: Chris@1809: /** Chris@1809: * Return the local file path of the audio data. This is the Chris@1809: * filesystem location most likely to contain readable audio data, Chris@1809: * but it may be in a different place or format from the Chris@1809: * originally specified location - for example, if the file has Chris@1809: * been retrieved and decoded, then it will be the (possibly Chris@1809: * temporary) decode target file. Chris@1809: * Chris@1809: * This returns a non-empty value only if there is some local Chris@1809: * filename that contains exactly the audio data being provided by Chris@1809: * this reader. In some cases this may not exist, for example when Chris@1809: * a file has been resampled or normalised directly into a memory Chris@1809: * buffer. In this case, return an empty string. Chris@1809: * Chris@1809: * See also getLocation(). Chris@1809: */ Chris@1809: virtual QString getLocalFilename() const = 0; Chris@148: Chris@271: /** Chris@271: * Return the title of the work in the audio file, if known. This Chris@271: * may be implemented by subclasses that support file tagging. Chris@271: * This is not the same thing as the file name. Chris@271: */ Chris@1592: virtual QString getTitle() const = 0; Chris@271: Chris@333: /** Chris@333: * Return the "maker" of the work in the audio file, if known. Chris@333: * This could represent almost anything (band, composer, Chris@333: * conductor, artist etc). Chris@333: */ Chris@1592: virtual QString getMaker() const = 0; Chris@333: Chris@1010: /** Chris@1809: * Return any tag pairs picked up from the audio file. See also Chris@1809: * getTitle and getMaker, and note that a reader which does not Chris@1809: * implement getTags may still return values from those. Chris@1010: */ Chris@632: typedef std::map TagMap; Chris@632: virtual TagMap getTags() const { return TagMap(); } Chris@632: Chris@823: /** Chris@823: * Return true if this file supports fast seek and random Chris@823: * access. Typically this will be true for uncompressed formats Chris@823: * and false for compressed ones. Chris@823: */ Chris@823: virtual bool isQuicklySeekable() const = 0; Chris@823: Chris@1809: /** Chris@1809: * Return a percentage value indicating how far through decoding Chris@1809: * the audio file we are. This should be implemented by subclasses Chris@1809: * that will not know exactly how long the audio file is (in Chris@1809: * sample frames) until it has been completely decoded. A reader Chris@1809: * that initialises the frame count directly within its Chris@1809: * constructor should always return 100 from this. Chris@1809: */ Chris@1809: virtual int getDecodeCompletion() const { return 100; } Chris@1809: Chris@1809: /** Chris@1809: * Return true if decoding is still in progress and the frame Chris@1809: * count may change. Chris@1809: */ Chris@1809: virtual bool isUpdating() const { return false; } Chris@1809: Chris@148: /** Chris@327: * Return interleaved samples for count frames from index start. Chris@1096: * The resulting vector will contain count * getChannelCount() Chris@1096: * samples (or fewer if end of file is reached). Chris@327: * Chris@148: * The subclass implementations of this function must be Chris@148: * thread-safe -- that is, safe to call from multiple threads with Chris@148: * different arguments on the same object at the same time. Chris@148: */ Chris@1326: virtual floatvec_t getInterleavedFrames(sv_frame_t start, Chris@1326: sv_frame_t count) const = 0; Chris@175: Chris@327: /** Chris@327: * Return de-interleaved samples for count frames from index Chris@327: * start. Implemented in this class (it calls Chris@327: * getInterleavedFrames and de-interleaves). The resulting vector Chris@327: * will contain getChannelCount() sample blocks of count samples Chris@327: * each (or fewer if end of file is reached). Chris@327: */ Chris@1326: virtual std::vector getDeInterleavedFrames(sv_frame_t start, Chris@1326: sv_frame_t count) const; Chris@327: Chris@175: signals: Chris@175: void frameCountChanged(); Chris@148: Chris@148: protected: Chris@1038: sv_frame_t m_frameCount; Chris@929: int m_channelCount; Chris@1040: sv_samplerate_t m_sampleRate; Chris@148: }; Chris@148: Chris@148: #endif