#include <DecodingWavFileReader.h>

Inheritance diagram for DecodingWavFileReader:
Inheritance graph
Collaboration diagram for DecodingWavFileReader:
Collaboration graph

Classes

class  DecodeThread
 

Public Types

enum  CacheMode { CacheInTemporaryFile, CacheInMemory }
 
enum  DecodeMode { DecodeAtOnce, DecodeThreaded }
 
typedef std::map< QString, QString > TagMap
 Return any tag pairs picked up from the audio file. More...
 

Public Slots

void cancelled ()
 

Signals

void progress (int)
 
void frameCountChanged ()
 

Public Member Functions

 DecodingWavFileReader (FileSource source, DecodeMode decodeMode, CacheMode cacheMode, sv_samplerate_t targetRate=0, bool normalised=false, ProgressReporter *reporter=0)
 
virtual ~DecodingWavFileReader ()
 
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 getError () const override
 If isOK() is false, return an error string. More...
 
QString getLocation () const override
 Return the location of the audio data in the reader (as passed in to the FileSource constructor, for example). 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...
 
floatvec_t getInterleavedFrames (sv_frame_t start, sv_frame_t count) const override
 Return interleaved samples for count frames from index start. More...
 
sv_samplerate_t getNativeRate () const override
 Return the native samplerate of the file. More...
 
QString getLocalFilename () const override
 Return the local file path of the audio data. More...
 
bool isQuicklySeekable () const override
 Intermediate cache means all CodedAudioFileReaders are quickly seekable. More...
 
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 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

void addBlock (const floatvec_t &frames)
 
void initialiseDecodeCache ()
 
void setFramesToTrim (sv_frame_t fromStart, sv_frame_t fromEnd)
 
void addSamplesToDecodeCache (float **samples, sv_frame_t nframes)
 
void addSamplesToDecodeCache (float *samplesInterleaved, sv_frame_t nframes)
 
void addSamplesToDecodeCache (const floatvec_t &interleaved)
 
void finishDecodeCache ()
 
bool isDecodeCacheInitialised () const
 
void startSerialised (QString id, const std::atomic< bool > *cancelled)
 
void endSerialised ()
 

Protected Attributes

FileSource m_source
 
QString m_title
 
QString m_maker
 
QString m_path
 
QString m_error
 
std::atomic< bool > m_cancelled
 
sv_frame_t m_processed
 
int m_completion
 
WavFileReaderm_original
 
ProgressReporterm_reporter
 
DecodeThreadm_decodeThread
 
QMutex m_cacheMutex
 
CacheMode m_cacheMode
 
floatvec_t m_data
 
QMutex m_dataLock
 
bool m_initialised
 
Serialiserm_serialiser
 
sv_samplerate_t m_fileRate
 
QString m_cacheFileName
 
SNDFILE * m_cacheFileWritePtr
 
WavFileReaderm_cacheFileReader
 
float * m_cacheWriteBuffer
 
sv_frame_t m_cacheWriteBufferIndex
 
sv_frame_t m_cacheWriteBufferFrames
 
breakfastquay::Resampler * m_resampler
 
float * m_resampleBuffer
 
int m_resampleBufferFrames
 
sv_frame_t m_fileFrameCount
 
bool m_normalised
 
float m_max
 
float m_gain
 
sv_frame_t m_trimFromStart
 
sv_frame_t m_trimFromEnd
 
sv_frame_t m_clippedCount
 
sv_frame_t m_firstNonzero
 
sv_frame_t m_lastNonzero
 
sv_frame_t m_frameCount
 
int m_channelCount
 
sv_samplerate_t m_sampleRate
 

Detailed Description

Definition at line 29 of file DecodingWavFileReader.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
CacheInTemporaryFile 
CacheInMemory 

Definition at line 47 of file CodedAudioFileReader.h.

Enumerator
DecodeAtOnce 
DecodeThreaded 

Definition at line 52 of file CodedAudioFileReader.h.

Constructor & Destructor Documentation

DecodingWavFileReader::~DecodingWavFileReader ( )
virtual

Definition at line 107 of file DecodingWavFileReader.cpp.

References m_cancelled, m_decodeThread, and m_original.

Member Function Documentation

QString DecodingWavFileReader::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 41 of file DecodingWavFileReader.h.

References m_title.

QString DecodingWavFileReader::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 42 of file DecodingWavFileReader.h.

References m_maker.

QString DecodingWavFileReader::getError ( ) const
inlineoverridevirtual

If isOK() is false, return an error string.

Reimplemented from AudioFileReader.

Definition at line 44 of file DecodingWavFileReader.h.

References m_error.

QString DecodingWavFileReader::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 45 of file DecodingWavFileReader.h.

References FileSource::getLocation(), getSupportedExtensions(), m_source, supports(), supportsContentType(), and supportsExtension().

void DecodingWavFileReader::getSupportedExtensions ( std::set< QString > &  extensions)
static

Definition at line 181 of file DecodingWavFileReader.cpp.

References WavFileReader::getSupportedExtensions().

Referenced by getLocation().

bool DecodingWavFileReader::supportsExtension ( QString  ext)
static

Definition at line 187 of file DecodingWavFileReader.cpp.

References WavFileReader::supportsExtension().

Referenced by getLocation().

bool DecodingWavFileReader::supportsContentType ( QString  type)
static

Definition at line 193 of file DecodingWavFileReader.cpp.

References WavFileReader::supportsContentType().

Referenced by getLocation().

bool DecodingWavFileReader::supports ( FileSource source)
static

Definition at line 199 of file DecodingWavFileReader.cpp.

References WavFileReader::supports().

Referenced by getLocation().

int DecodingWavFileReader::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 52 of file DecodingWavFileReader.h.

References m_completion.

bool DecodingWavFileReader::isUpdating ( ) const
inlineoverridevirtual

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

Reimplemented from AudioFileReader.

Definition at line 54 of file DecodingWavFileReader.h.

References cancelled(), and m_decodeThread.

void DecodingWavFileReader::cancelled ( )
slot

Definition at line 119 of file DecodingWavFileReader.cpp.

References m_cancelled.

Referenced by DecodingWavFileReader(), and isUpdating().

floatvec_t CodedAudioFileReader::getInterleavedFrames ( sv_frame_t  start,
sv_frame_t  count 
) const
overridevirtualinherited

Return interleaved samples for count frames from index start.

The resulting vector will contain count * getChannelCount() samples (or fewer if end of file is reached).

The subclass implementations of this function must be thread-safe – that is, safe to call from multiple threads with different arguments on the same object at the same time.

Implements AudioFileReader.

Definition at line 550 of file CodedAudioFileReader.cpp.

References CodedAudioFileReader::CacheInMemory, CodedAudioFileReader::CacheInTemporaryFile, WavFileReader::getInterleavedFrames(), AudioFileReader::isOK(), CodedAudioFileReader::m_cacheFileReader, CodedAudioFileReader::m_cacheMode, AudioFileReader::m_channelCount, CodedAudioFileReader::m_data, CodedAudioFileReader::m_dataLock, CodedAudioFileReader::m_gain, CodedAudioFileReader::m_initialised, CodedAudioFileReader::m_normalised, and SVDEBUG.

sv_samplerate_t CodedAudioFileReader::getNativeRate ( ) const
inlineoverridevirtualinherited

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 from AudioFileReader.

Definition at line 59 of file CodedAudioFileReader.h.

QString CodedAudioFileReader::getLocalFilename ( ) const
inlineoverridevirtualinherited

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 61 of file CodedAudioFileReader.h.

bool CodedAudioFileReader::isQuicklySeekable ( ) const
inlineoverridevirtualinherited

Intermediate cache means all CodedAudioFileReaders are quickly seekable.

Implements AudioFileReader.

Definition at line 64 of file CodedAudioFileReader.h.

void CodedAudioFileReader::progress ( int  )
signalinherited

Referenced by addBlock().

void CodedAudioFileReader::setFramesToTrim ( sv_frame_t  fromStart,
sv_frame_t  fromEnd 
)
protectedinherited
bool CodedAudioFileReader::isDecodeCacheInitialised ( ) const
inlineprotectedinherited
void CodedAudioFileReader::startSerialised ( QString  id,
const std::atomic< bool > *  cancelled 
)
protectedinherited

Definition at line 108 of file CodedAudioFileReader.cpp.

References CodedAudioFileReader::m_serialiser.

Referenced by MP3FileReader::accept().

void CodedAudioFileReader::endSerialised ( )
protectedinherited
sv_frame_t AudioFileReader::getFrameCount ( ) const
inlineinherited

Return the number of audio sample frames (i.e.

samples per channel) in the file.

Definition at line 49 of file AudioFileReader.h.

References AudioFileReader::m_frameCount.

Referenced by addBlock(), DecodingWavFileReader(), AudioFileSizeEstimator::estimate(), ReadOnlyWaveFileModel::getFrameCount(), and WritableWaveFileModel::normaliseToTarget().

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(), AudioFileSizeEstimator::estimate(), ReadOnlyWaveFileModel::getSampleRate(), and ReadOnlyWaveFileModel::ReadOnlyWaveFileModel().

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

FileSource DecodingWavFileReader::m_source
protected

Definition at line 62 of file DecodingWavFileReader.h.

Referenced by getLocation().

QString DecodingWavFileReader::m_title
protected

Definition at line 63 of file DecodingWavFileReader.h.

Referenced by DecodingWavFileReader(), and getTitle().

QString DecodingWavFileReader::m_maker
protected

Definition at line 64 of file DecodingWavFileReader.h.

Referenced by DecodingWavFileReader(), and getMaker().

QString DecodingWavFileReader::m_path
protected

Definition at line 65 of file DecodingWavFileReader.h.

Referenced by DecodingWavFileReader().

QString DecodingWavFileReader::m_error
protected

Definition at line 66 of file DecodingWavFileReader.h.

Referenced by DecodingWavFileReader(), and getError().

std::atomic<bool> DecodingWavFileReader::m_cancelled
protected
sv_frame_t DecodingWavFileReader::m_processed
protected

Definition at line 68 of file DecodingWavFileReader.h.

Referenced by addBlock().

int DecodingWavFileReader::m_completion
protected

Definition at line 69 of file DecodingWavFileReader.h.

Referenced by addBlock(), and getDecodeCompletion().

WavFileReader* DecodingWavFileReader::m_original
protected

Definition at line 71 of file DecodingWavFileReader.h.

Referenced by addBlock(), DecodingWavFileReader(), and ~DecodingWavFileReader().

ProgressReporter* DecodingWavFileReader::m_reporter
protected

Definition at line 72 of file DecodingWavFileReader.h.

Referenced by addBlock(), and DecodingWavFileReader().

DecodeThread* DecodingWavFileReader::m_decodeThread
protected
QMutex CodedAudioFileReader::m_dataLock
mutableprotectedinherited
Serialiser* CodedAudioFileReader::m_serialiser
protectedinherited
QString CodedAudioFileReader::m_cacheFileName
protectedinherited
sv_frame_t CodedAudioFileReader::m_cacheWriteBufferIndex
protectedinherited
sv_frame_t CodedAudioFileReader::m_cacheWriteBufferFrames
protectedinherited
int CodedAudioFileReader::m_resampleBufferFrames
protectedinherited
sv_frame_t CodedAudioFileReader::m_fileFrameCount
protectedinherited
bool CodedAudioFileReader::m_normalised
protectedinherited
float CodedAudioFileReader::m_max
protectedinherited
float CodedAudioFileReader::m_gain
protectedinherited
sv_frame_t CodedAudioFileReader::m_trimFromStart
protectedinherited
sv_frame_t CodedAudioFileReader::m_clippedCount
protectedinherited
sv_frame_t CodedAudioFileReader::m_firstNonzero
protectedinherited
sv_frame_t CodedAudioFileReader::m_lastNonzero
protectedinherited

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