WavFileReader.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2006 Chris Cannam.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef SV_WAV_FILE_READER_H
17 #define SV_WAV_FILE_READER_H
18 
19 #include "AudioFileReader.h"
20 
21 #ifdef Q_OS_WIN
22 #include <windows.h>
23 #define ENABLE_SNDFILE_WINDOWS_PROTOTYPES 1
24 #endif
25 
26 #include <sndfile.h>
27 #include <QMutex>
28 
29 #include <set>
30 
42 {
43 public:
44  enum class Normalisation { None, Peak };
45 
47  bool fileUpdating = false,
49  virtual ~WavFileReader();
50 
51  QString getLocation() const override { return m_source.getLocation(); }
52  QString getError() const override { return m_error; }
53 
54  QString getTitle() const override { return m_title; }
55  QString getMaker() const override { return m_maker; }
56 
57  QString getLocalFilename() const override { return m_path; }
58 
59  bool isQuicklySeekable() const override { return m_seekable; }
60 
65  floatvec_t getInterleavedFrames(sv_frame_t start, sv_frame_t count) const override;
66 
67  static void getSupportedExtensions(std::set<QString> &extensions);
68  static bool supportsExtension(QString ext);
69  static bool supportsContentType(QString type);
70  static bool supports(FileSource &source);
71 
72  int getDecodeCompletion() const override { return 100; }
73 
74  bool isUpdating() const override { return m_updating; }
75 
76  void updateFrameCount();
77  void updateDone();
78 
79 protected:
80  SF_INFO m_fileInfo;
81  SNDFILE *m_file;
82 
84  QString m_path;
85  QString m_error;
86  QString m_title;
87  QString m_maker;
88 
89  bool m_seekable;
90 
91  mutable QMutex m_mutex;
95 
97  float m_max;
98 
99  bool m_updating;
100 
102  sv_frame_t count) const;
103  float getMax() const;
104 };
105 
106 #endif
bool isUpdating() const override
Return true if decoding is still in progress and the frame count may change.
Definition: WavFileReader.h:74
SF_INFO m_fileInfo
Definition: WavFileReader.h:80
Normalisation m_normalisation
Definition: WavFileReader.h:96
int64_t sv_frame_t
Frame index, the unit of our time axis.
Definition: BaseTypes.h:31
QString getLocation() const
Return the location filename or URL as passed to the constructor.
Definition: FileSource.cpp:616
int getDecodeCompletion() const override
Return a percentage value indicating how far through decoding the audio file we are.
Definition: WavFileReader.h:72
FileSource m_source
Definition: WavFileReader.h:83
Reader for audio files using libsndfile.
Definition: WavFileReader.h:41
static bool supportsExtension(QString ext)
sv_frame_t m_lastCount
Definition: WavFileReader.h:94
sv_frame_t m_lastStart
Definition: WavFileReader.h:93
floatvec_t getInterleavedFramesUnnormalised(sv_frame_t start, sv_frame_t count) const
static bool supportsContentType(QString type)
WavFileReader(FileSource source, bool fileUpdating=false, Normalisation normalise=Normalisation::None)
bool isQuicklySeekable() const override
Return true if this file supports fast seek and random access.
Definition: WavFileReader.h:59
static bool supports(FileSource &source)
std::vector< float, breakfastquay::StlAllocator< float > > floatvec_t
Definition: BaseTypes.h:53
QString m_title
Definition: WavFileReader.h:86
FileSource is a class used to refer to the contents of a file that may be either local or at a remote...
Definition: FileSource.h:59
static void getSupportedExtensions(std::set< QString > &extensions)
QString m_path
Definition: WavFileReader.h:84
QString getError() const override
If isOK() is false, return an error string.
Definition: WavFileReader.h:52
floatvec_t m_buffer
Definition: WavFileReader.h:92
SNDFILE * m_file
Definition: WavFileReader.h:81
QString getLocation() const override
Return the location of the audio data in the reader (as passed in to the FileSource constructor...
Definition: WavFileReader.h:51
void updateFrameCount()
QString m_maker
Definition: WavFileReader.h:87
QString getTitle() const override
Return the title of the work in the audio file, if known.
Definition: WavFileReader.h:54
virtual ~WavFileReader()
QString m_error
Definition: WavFileReader.h:85
floatvec_t getInterleavedFrames(sv_frame_t start, sv_frame_t count) const override
Must be safe to call from multiple threads with different arguments on the same object at the same ti...
float getMax() const
QString getMaker() const override
Return the "maker" of the work in the audio file, if known.
Definition: WavFileReader.h:55
QString getLocalFilename() const override
Return the local file path of the audio data.
Definition: WavFileReader.h:57