Reader for audio files using libsndfile. More...

#include <WavFileReader.h>

Inheritance diagram for WavFileReader:
Inheritance graph
Collaboration diagram for WavFileReader:
Collaboration graph

Public Types

enum  Normalisation { Normalisation::None, Normalisation::Peak }
 
typedef std::map< QString, QString > TagMap
 Return any tag pairs picked up from the audio file. More...
 

Signals

void frameCountChanged ()
 

Public Member Functions

 WavFileReader (FileSource source, bool fileUpdating=false, Normalisation normalise=Normalisation::None)
 
virtual ~WavFileReader ()
 
QString getLocation () const override
 Return the location of the audio data in the reader (as passed in to the FileSource constructor, for example). More...
 
QString getError () const override
 If isOK() is false, return an error string. More...
 
QString getTitle () const override
 Return the title of the work in the audio file, if known. More...
 
QString getMaker () const override
 Return the "maker" of the work in the audio file, if known. More...
 
QString getLocalFilename () const override
 Return the local file path of the audio data. More...
 
bool isQuicklySeekable () const override
 Return true if this file supports fast seek and random access. More...
 
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 time. More...
 
int getDecodeCompletion () const override
 Return a percentage value indicating how far through decoding the audio file we are. More...
 
bool isUpdating () const override
 Return true if decoding is still in progress and the frame count may change. More...
 
void updateFrameCount ()
 
void updateDone ()
 
bool isOK () const
 Return true if the file was opened successfully and no error has subsequently occurred. More...
 
sv_frame_t getFrameCount () const
 Return the number of audio sample frames (i.e. More...
 
int getChannelCount () const
 Return the number of channels in the file. More...
 
sv_samplerate_t getSampleRate () const
 Return the samplerate at which the file is being read. More...
 
virtual sv_samplerate_t getNativeRate () const
 Return the native samplerate of the file. More...
 
virtual TagMap getTags () const
 
virtual std::vector< floatvec_tgetDeInterleavedFrames (sv_frame_t start, sv_frame_t count) const
 Return de-interleaved samples for count frames from index start. More...
 

Static Public Member Functions

static void getSupportedExtensions (std::set< QString > &extensions)
 
static bool supportsExtension (QString ext)
 
static bool supportsContentType (QString type)
 
static bool supports (FileSource &source)
 

Protected Member Functions

floatvec_t getInterleavedFramesUnnormalised (sv_frame_t start, sv_frame_t count) const
 
float getMax () const
 

Protected Attributes

SF_INFO m_fileInfo
 
SNDFILE * m_file
 
FileSource m_source
 
QString m_path
 
QString m_error
 
QString m_title
 
QString m_maker
 
bool m_seekable
 
QMutex m_mutex
 
floatvec_t m_buffer
 
sv_frame_t m_lastStart
 
sv_frame_t m_lastCount
 
Normalisation m_normalisation
 
float m_max
 
bool m_updating
 
sv_frame_t m_frameCount
 
int m_channelCount
 
sv_samplerate_t m_sampleRate
 

Detailed Description

Reader for audio files using libsndfile.

This is typically intended for seekable file types that can be read directly (e.g. WAV, AIFF etc).

Compressed files supported by libsndfile (e.g. Ogg, FLAC) should normally be read using DecodingWavFileReader instead (which decodes to an intermediate cached file).

Definition at line 41 of file WavFileReader.h.

Member Typedef Documentation

typedef std::map<QString, QString> AudioFileReader::TagMap
inherited

Return any tag pairs picked up from the audio file.

See also getTitle and getMaker, and note that a reader which does not implement getTags may still return values from those.

Definition at line 117 of file AudioFileReader.h.

Member Enumeration Documentation

Enumerator
None 
Peak 

Definition at line 44 of file WavFileReader.h.

Constructor & Destructor Documentation

WavFileReader::WavFileReader ( FileSource  source,
bool  fileUpdating = false,
Normalisation  normalise = Normalisation::None 
)
WavFileReader::~WavFileReader ( )
virtual

Definition at line 112 of file WavFileReader.cpp.

References m_file.

Member Function Documentation

QString WavFileReader::getLocation ( ) const
inlineoverridevirtual

Return the location of the audio data in the reader (as passed in to the FileSource constructor, for example).

This might be a remote URL.

See also getLocalFilename().

Implements AudioFileReader.

Definition at line 51 of file WavFileReader.h.

References FileSource::getLocation(), and m_source.

QString WavFileReader::getError ( ) const
inlineoverridevirtual
QString WavFileReader::getTitle ( ) const
inlineoverridevirtual

Return the title of the work in the audio file, if known.

This may be implemented by subclasses that support file tagging. This is not the same thing as the file name.

Implements AudioFileReader.

Definition at line 54 of file WavFileReader.h.

References m_title.

Referenced by DecodingWavFileReader::DecodingWavFileReader().

QString WavFileReader::getMaker ( ) const
inlineoverridevirtual

Return the "maker" of the work in the audio file, if known.

This could represent almost anything (band, composer, conductor, artist etc).

Implements AudioFileReader.

Definition at line 55 of file WavFileReader.h.

References m_maker.

Referenced by DecodingWavFileReader::DecodingWavFileReader().

QString WavFileReader::getLocalFilename ( ) const
inlineoverridevirtual

Return the local file path of the audio data.

This is the filesystem location most likely to contain readable audio data, but it may be in a different place or format from the originally specified location - for example, if the file has been retrieved and decoded, then it will be the (possibly temporary) decode target file.

This returns a non-empty value only if there is some local filename that contains exactly the audio data being provided by this reader. In some cases this may not exist, for example when a file has been resampled or normalised directly into a memory buffer. In this case, return an empty string.

See also getLocation().

Implements AudioFileReader.

Definition at line 57 of file WavFileReader.h.

References m_path.

bool WavFileReader::isQuicklySeekable ( ) const
inlineoverridevirtual

Return true if this file supports fast seek and random access.

Typically this will be true for uncompressed formats and false for compressed ones.

Implements AudioFileReader.

Definition at line 59 of file WavFileReader.h.

References getInterleavedFrames(), getSupportedExtensions(), m_seekable, supports(), supportsContentType(), and supportsExtension().

floatvec_t WavFileReader::getInterleavedFrames ( sv_frame_t  start,
sv_frame_t  count 
) const
overridevirtual

Must be safe to call from multiple threads with different arguments on the same object at the same time.

Implements AudioFileReader.

Definition at line 164 of file WavFileReader.cpp.

References getInterleavedFramesUnnormalised(), in_range_for(), m_max, m_normalisation, and None.

Referenced by DecodingWavFileReader::DecodingWavFileReader(), CodedAudioFileReader::getInterleavedFrames(), getMax(), isQuicklySeekable(), and WritableWaveFileModel::normaliseToTarget().

void WavFileReader::getSupportedExtensions ( std::set< QString > &  extensions)
static
bool WavFileReader::supportsExtension ( QString  ext)
static
bool WavFileReader::supportsContentType ( QString  type)
static
int WavFileReader::getDecodeCompletion ( ) const
inlineoverridevirtual

Return a percentage value indicating how far through decoding the audio file we are.

This should be implemented by subclasses that will not know exactly how long the audio file is (in sample frames) until it has been completely decoded. A reader that initialises the frame count directly within its constructor should always return 100 from this.

Reimplemented from AudioFileReader.

Definition at line 72 of file WavFileReader.h.

bool WavFileReader::isUpdating ( ) const
inlineoverridevirtual

Return true if decoding is still in progress and the frame count may change.

Reimplemented from AudioFileReader.

Definition at line 74 of file WavFileReader.h.

References m_updating, updateDone(), and updateFrameCount().

void WavFileReader::updateDone ( )
floatvec_t WavFileReader::getInterleavedFramesUnnormalised ( sv_frame_t  start,
sv_frame_t  count 
) const
protected
float WavFileReader::getMax ( ) const
protected
sv_frame_t AudioFileReader::getFrameCount ( ) const
inlineinherited
int AudioFileReader::getChannelCount ( ) const
inlineinherited
sv_samplerate_t AudioFileReader::getSampleRate ( ) const
inlineinherited

Return the samplerate at which the file is being read.

This is the rate requested when the file was opened, which may differ from the native rate of the file (in which case the file will be resampled as it is read).

Definition at line 62 of file AudioFileReader.h.

References AudioFileReader::m_sampleRate.

Referenced by AudioFileReaderFactory::createReader(), DecodingWavFileReader::DecodingWavFileReader(), AudioFileSizeEstimator::estimate(), ReadOnlyWaveFileModel::getSampleRate(), and ReadOnlyWaveFileModel::ReadOnlyWaveFileModel().

virtual sv_samplerate_t AudioFileReader::getNativeRate ( ) const
inlinevirtualinherited

Return the native samplerate of the file.

This will differ from getSampleRate() if the file is being resampled because it was requested to open at a different rate from native.

Reimplemented in CodedAudioFileReader.

Definition at line 69 of file AudioFileReader.h.

References AudioFileReader::getLocalFilename(), AudioFileReader::getLocation(), AudioFileReader::getMaker(), AudioFileReader::getTitle(), and AudioFileReader::m_sampleRate.

Referenced by ReadOnlyWaveFileModel::getNativeRate().

virtual TagMap AudioFileReader::getTags ( ) const
inlinevirtualinherited

Reimplemented in MP3FileReader.

Definition at line 118 of file AudioFileReader.h.

References AudioFileReader::isQuicklySeekable().

vector< floatvec_t > AudioFileReader::getDeInterleavedFrames ( sv_frame_t  start,
sv_frame_t  count 
) const
virtualinherited

Return de-interleaved samples for count frames from index start.

Implemented in this class (it calls getInterleavedFrames and de-interleaves). The resulting vector will contain getChannelCount() sample blocks of count samples each (or fewer if end of file is reached).

Definition at line 21 of file AudioFileReader.cpp.

References AudioFileReader::getChannelCount(), and AudioFileReader::getInterleavedFrames().

Referenced by AudioFileReader::isUpdating().

void AudioFileReader::frameCountChanged ( )
signalinherited

Member Data Documentation

SF_INFO WavFileReader::m_fileInfo
protected
SNDFILE* WavFileReader::m_file
protected
FileSource WavFileReader::m_source
protected

Definition at line 83 of file WavFileReader.h.

Referenced by getLocation().

QString WavFileReader::m_path
protected

Definition at line 84 of file WavFileReader.h.

Referenced by getLocalFilename(), updateFrameCount(), and WavFileReader().

QString WavFileReader::m_error
protected

Definition at line 85 of file WavFileReader.h.

Referenced by getError(), and WavFileReader().

QString WavFileReader::m_title
protected

Definition at line 86 of file WavFileReader.h.

Referenced by getTitle(), and WavFileReader().

QString WavFileReader::m_maker
protected

Definition at line 87 of file WavFileReader.h.

Referenced by getMaker(), and WavFileReader().

bool WavFileReader::m_seekable
protected

Definition at line 89 of file WavFileReader.h.

Referenced by isQuicklySeekable(), and WavFileReader().

QMutex WavFileReader::m_mutex
mutableprotected

Definition at line 91 of file WavFileReader.h.

Referenced by getInterleavedFramesUnnormalised(), and updateFrameCount().

floatvec_t WavFileReader::m_buffer
mutableprotected

Definition at line 92 of file WavFileReader.h.

Referenced by getInterleavedFramesUnnormalised().

sv_frame_t WavFileReader::m_lastStart
mutableprotected

Definition at line 93 of file WavFileReader.h.

Referenced by getInterleavedFramesUnnormalised().

sv_frame_t WavFileReader::m_lastCount
mutableprotected

Definition at line 94 of file WavFileReader.h.

Referenced by getInterleavedFramesUnnormalised().

Normalisation WavFileReader::m_normalisation
protected

Definition at line 96 of file WavFileReader.h.

Referenced by getInterleavedFrames(), updateDone(), and WavFileReader().

float WavFileReader::m_max
protected

Definition at line 97 of file WavFileReader.h.

Referenced by getInterleavedFrames(), updateDone(), and WavFileReader().

bool WavFileReader::m_updating
protected

Definition at line 99 of file WavFileReader.h.

Referenced by isUpdating(), updateDone(), and WavFileReader().


The documentation for this class was generated from the following files: