Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
cinder::audio::SourceFile Class Referenceabstract

Loads and reads from an audio file source. More...

#include <Source.h>

Inheritance diagram for cinder::audio::SourceFile:
[legend]

Public Member Functions

virtual ~SourceFile ()
 
size_t read (Buffer *buffer) override
 Loads either as many frames as buffer can hold, or as many as there are left. More...
 
SourceFileRef clone () const
 Returns a copy of this Source, with identical properties and pointing at the same data source. More...
 
virtual SourceFileRef cloneWithSampleRate (size_t sampleRate) const =0
 Returns an copy of this Source with all properties identical except the sampleRate. This is useful if the SourceFile must match a samplerate that was unknown when it was first constructed. More...
 
BufferRef loadBuffer ()
 Loads and returns the entire contents of this SourceFile. More...
 
void seek (size_t readPositionFrames)
 Seek the read position to readPositionFrames. More...
 
void seekToTime (double readPositionSeconds)
 Seek to read position readPositionSeconds. More...
 
size_t getReadPosition () const
 Returns the current read position in frames. More...
 
double getReadPositionSeconds () const
 Returns the current read position in seconds. More...
 
size_t getNumFrames () const
 Returns the length in frames. More...
 
double getNumSeconds () const
 Returns the length in seconds. More...
 
size_t getSampleRate () const
 Returns the user facing samplerate (output). More...
 
virtual size_t getNumChannels () const =0
 Returns the number of channels. More...
 
virtual size_t getSampleRateNative () const =0
 Returns the true samplerate of the Source. More...
 
size_t getMaxFramesPerRead () const
 Returns the maximum number of frames that can be read with one call to read(). More...
 
virtual void setMaxFramesPerRead (size_t count)
 Sets the maximum number of frames that can be read in one chunk. More...
 
virtual std::string getMetaData () const
 Returns the metadata, if any, as a string. More...
 

Static Public Member Functions

static std::unique_ptr
< SourceFile
create (const DataSourceRef &dataSource, size_t sampleRate=0)
 Creates a new SourceFile from dataSource, with optional output samplerate. If sampleRate equals 0 the native file's samplerate is used. More...
 
static std::vector< std::stringgetSupportedExtensions ()
 Returns a vector of extensions that SourceFile support for loading. Suitable for the extensions parameter of getOpenFilePath(). More...
 

Protected Member Functions

 SourceFile (size_t sampleRate)
 
virtual void performSeek (size_t readPositionFrames)=0
 Implement to perform seek. readPositionFrames is in native file units. More...
 
virtual void setupSampleRateConversion ()
 Sets up samplerate conversion if needed. Can be overridden by implementation if they handle samplerate conversion in a specific way, else it is handled generically with a dsp::Converter. More...
 
virtual size_t performRead (Buffer *buffer, size_t bufferFrameOffset, size_t numFramesNeeded)=0
 
virtual bool supportsConversion ()
 Implementations should override and return true if they can provide samplerate conversion. If false (default), a Converter will be used if needed. More...
 
void setSampleRate (size_t sampleRate)
 Allows implementations to set the output samplerate. More...
 

Protected Attributes

size_t mNumFrames
 
size_t mFileNumFrames
 
size_t mReadPos
 
std::unique_ptr< dsp::ConvertermConverter
 
BufferDynamic mConverterReadBuffer
 

Detailed Description

Loads and reads from an audio file source.

Constructor & Destructor Documentation

virtual cinder::audio::SourceFile::~SourceFile ( )
virtual
cinder::audio::SourceFile::SourceFile ( size_t  sampleRate)
protected

Member Function Documentation

unique_ptr< SourceFile > cinder::audio::SourceFile::create ( const DataSourceRef dataSource,
size_t  sampleRate = 0 
)
static

Creates a new SourceFile from dataSource, with optional output samplerate. If sampleRate equals 0 the native file's samplerate is used.

size_t cinder::audio::SourceFile::read ( Buffer buffer)
overridevirtual

Loads either as many frames as buffer can hold, or as many as there are left.

Returns
number of frames read into buffer.

Implements cinder::audio::Source.

SourceFileRef cinder::audio::SourceFile::clone ( ) const

Returns a copy of this Source, with identical properties and pointing at the same data source.

virtual SourceFileRef cinder::audio::SourceFile::cloneWithSampleRate ( size_t  sampleRate) const
pure virtual

Returns an copy of this Source with all properties identical except the sampleRate. This is useful if the SourceFile must match a samplerate that was unknown when it was first constructed.

Implemented in cinder::audio::cocoa::SourceFileCoreAudio, and cinder::audio::SourceFileOggVorbis.

BufferRef cinder::audio::SourceFile::loadBuffer ( )

Loads and returns the entire contents of this SourceFile.

Returns
a BufferRef containing the file contents.
void cinder::audio::SourceFile::seek ( size_t  readPositionFrames)

Seek the read position to readPositionFrames.

void cinder::audio::SourceFile::seekToTime ( double  readPositionSeconds)

Seek to read position readPositionSeconds.

size_t cinder::audio::SourceFile::getReadPosition ( ) const

Returns the current read position in frames.

double cinder::audio::SourceFile::getReadPositionSeconds ( ) const

Returns the current read position in seconds.

size_t cinder::audio::SourceFile::getNumFrames ( ) const

Returns the length in frames.

double cinder::audio::SourceFile::getNumSeconds ( ) const

Returns the length in seconds.

vector< std::string > cinder::audio::SourceFile::getSupportedExtensions ( )
static

Returns a vector of extensions that SourceFile support for loading. Suitable for the extensions parameter of getOpenFilePath().

virtual void cinder::audio::SourceFile::performSeek ( size_t  readPositionFrames)
protectedpure virtual

Implement to perform seek. readPositionFrames is in native file units.

Implemented in cinder::audio::SourceFileOggVorbis.

void cinder::audio::SourceFile::setupSampleRateConversion ( )
protectedvirtual

Sets up samplerate conversion if needed. Can be overridden by implementation if they handle samplerate conversion in a specific way, else it is handled generically with a dsp::Converter.

size_t cinder::audio::Source::getSampleRate ( ) const
inherited

Returns the user facing samplerate (output).

virtual size_t cinder::audio::Source::getNumChannels ( ) const
pure virtualinherited

Returns the number of channels.

Implemented in cinder::audio::cocoa::SourceFileCoreAudio, and cinder::audio::SourceFileOggVorbis.

virtual size_t cinder::audio::Source::getSampleRateNative ( ) const
pure virtualinherited

Returns the true samplerate of the Source.

Note
Actual output samplerate may differ.
See also
getSampleRate()

Implemented in cinder::audio::cocoa::SourceFileCoreAudio, and cinder::audio::SourceFileOggVorbis.

size_t cinder::audio::Source::getMaxFramesPerRead ( ) const
inherited

Returns the maximum number of frames that can be read with one call to read().

virtual void cinder::audio::Source::setMaxFramesPerRead ( size_t  count)
virtualinherited

Sets the maximum number of frames that can be read in one chunk.

virtual std::string cinder::audio::Source::getMetaData ( ) const
virtualinherited

Returns the metadata, if any, as a string.

Reimplemented in cinder::audio::SourceFileOggVorbis.

virtual size_t cinder::audio::Source::performRead ( Buffer buffer,
size_t  bufferFrameOffset,
size_t  numFramesNeeded 
)
protectedpure virtualinherited

Implement to perform read of frames into buffer starting at offset bufferFrameOffset

Returns
the actual number of frames read.

Implemented in cinder::audio::SourceFileOggVorbis.

virtual bool cinder::audio::Source::supportsConversion ( )
protectedvirtualinherited

Implementations should override and return true if they can provide samplerate conversion. If false (default), a Converter will be used if needed.

void cinder::audio::Source::setSampleRate ( size_t  sampleRate)
protectedinherited

Allows implementations to set the output samplerate.

Member Data Documentation

size_t cinder::audio::SourceFile::mNumFrames
protected
size_t cinder::audio::SourceFile::mFileNumFrames
protected
size_t cinder::audio::SourceFile::mReadPos
protected
std::unique_ptr<dsp::Converter> cinder::audio::Source::mConverter
protectedinherited
BufferDynamic cinder::audio::Source::mConverterReadBuffer
protectedinherited

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