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@1348: #ifndef SV_WAV_FILE_READER_H Chris@1348: #define SV_WAV_FILE_READER_H Chris@148: Chris@148: #include "AudioFileReader.h" Chris@148: Chris@1350: #ifdef Q_OS_WIN Chris@1350: #include Chris@1349: #define ENABLE_SNDFILE_WINDOWS_PROTOTYPES 1 Chris@1350: #endif Chris@1349: Chris@148: #include Chris@148: #include Chris@148: Chris@157: #include Chris@157: Chris@823: /** Chris@823: * Reader for audio files using libsndfile. Chris@823: * Chris@823: * This is typically intended for seekable file types that can be read Chris@823: * directly (e.g. WAV, AIFF etc). Chris@823: * Chris@823: * Compressed files supported by libsndfile (e.g. Ogg, FLAC) should Chris@823: * normally be read using DecodingWavFileReader instead (which decodes Chris@823: * to an intermediate cached file). Chris@823: */ Chris@148: class WavFileReader : public AudioFileReader Chris@148: { Chris@148: public: Chris@1520: enum class Normalisation { None, Peak }; Chris@1520: Chris@1513: WavFileReader(FileSource source, Chris@1513: bool fileUpdating = false, Chris@1520: Normalisation normalise = Normalisation::None); Chris@148: virtual ~WavFileReader(); Chris@148: Chris@345: virtual QString getLocation() const { return m_source.getLocation(); } Chris@290: virtual QString getError() const { return m_error; } Chris@290: Chris@1010: virtual QString getLocalFilename() const { return m_path; } Chris@1010: Chris@823: virtual bool isQuicklySeekable() const { return m_seekable; } Chris@823: Chris@148: /** Chris@148: * Must be safe to call from multiple threads with different Chris@148: * arguments on the same object at the same time. Chris@148: */ Chris@1513: virtual floatvec_t getInterleavedFrames(sv_frame_t start, sv_frame_t count) Chris@1513: const; Chris@148: Chris@290: static void getSupportedExtensions(std::set &extensions); Chris@316: static bool supportsExtension(QString ext); Chris@316: static bool supportsContentType(QString type); Chris@317: static bool supports(FileSource &source); Chris@157: Chris@265: virtual int getDecodeCompletion() const { return 100; } Chris@265: Chris@176: bool isUpdating() const { return m_updating; } Chris@176: Chris@175: void updateFrameCount(); Chris@176: void updateDone(); Chris@175: Chris@148: protected: Chris@148: SF_INFO m_fileInfo; Chris@1349: SNDFILE *m_file; Chris@148: Chris@317: FileSource m_source; Chris@290: QString m_path; Chris@290: QString m_error; Chris@148: Chris@823: bool m_seekable; Chris@823: Chris@148: mutable QMutex m_mutex; Chris@1326: mutable floatvec_t m_buffer; Chris@1038: mutable sv_frame_t m_lastStart; Chris@1038: mutable sv_frame_t m_lastCount; Chris@176: Chris@1520: Normalisation m_normalisation; Chris@1513: float m_max; Chris@1513: Chris@176: bool m_updating; Chris@1513: Chris@1513: floatvec_t getInterleavedFramesUnnormalised(sv_frame_t start, Chris@1513: sv_frame_t count) const; Chris@1513: float getMax() const; Chris@148: }; Chris@148: Chris@148: #endif