29 #include <boost/noncopyable.hpp>
31 namespace cinder {
namespace audio {
41 class Source :
public boost::noncopyable {
65 Source(
size_t sampleRate );
79 size_t mSampleRate, mMaxFramesPerRead;
86 static std::unique_ptr<SourceFile>
create(
const DataSourceRef &dataSource,
size_t sampleRate = 0 );
99 void seek(
size_t readPositionFrames );
118 virtual void performSeek(
size_t readPositionFrames ) = 0;
virtual size_t getNumChannels() const =0
Returns the number of channels.
void setSampleRate(size_t sampleRate)
Allows implementations to set the output samplerate.
Definition: Source.h:73
std::shared_ptr< Buffer > BufferRef
Definition: Buffer.h:293
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.
BufferRef loadBuffer()
Loads and returns the entire contents of this SourceFile.
Definition: Source.cpp:143
GLsizei const GLchar ** string
Definition: GLee.h:2427
Loads and reads from an audio file source.
Definition: Source.h:83
std::shared_ptr< class SourceFile > SourceFileRef
Definition: Source.h:34
size_t getMaxFramesPerRead() const
Returns the maximum number of frames that can be read with one call to read().
Definition: Source.h:54
size_t getSampleRate() const
Returns the user facing samplerate (output).
Definition: Source.h:46
virtual std::string getMetaData() const
Returns the metadata, if any, as a string.
Definition: Source.h:62
virtual size_t read(Buffer *buffer)=0
Loads either as many frames as buffer can hold, or as many as there are left.
virtual void performSeek(size_t readPositionFrames)=0
Implement to perform seek. readPositionFrames is in native file units.
SourceFileRef clone() const
Returns a copy of this Source, with identical properties and pointing at the same data source...
Definition: Source.h:92
double getNumSeconds() const
Returns the length in seconds.
Definition: Source.h:109
size_t mNumFrames
Definition: Source.h:122
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.
Definition: Source.h:71
virtual size_t performRead(Buffer *buffer, size_t bufferFrameOffset, size_t numFramesNeeded)=0
SourceFileRef load(const DataSourceRef &dataSource, size_t sampleRate=0)
Convenience method for loading a SourceFile from dataSource.
Definition: Source.h:126
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...
Definition: Source.cpp:44
GLuint buffer
Definition: GLee.h:2065
size_t read(Buffer *buffer) override
Loads either as many frames as buffer can hold, or as many as there are left.
Definition: Source.cpp:118
size_t getNumFrames() const
Returns the length in frames.
Definition: Source.h:107
GLuint GLuint GLsizei count
Definition: GLee.h:963
BufferDynamic mConverterReadBuffer
Definition: Source.h:76
virtual void setMaxFramesPerRead(size_t count)
Sets the maximum number of frames that can be read in one chunk.
Definition: Source.h:56
void seekToTime(double readPositionSeconds)
Seek to read position readPositionSeconds.
Definition: Source.h:101
virtual ~Source()
Definition: Source.cpp:86
virtual ~SourceFile()
Definition: Source.h:87
Source(size_t sampleRate)
Definition: Source.cpp:81
size_t mFileNumFrames
Definition: Source.h:122
std::shared_ptr< class Source > SourceRef
Definition: Source.h:33
double getReadPositionSeconds() const
Returns the current read position in seconds.
Definition: Source.h:105
size_t getReadPosition() const
Returns the current read position in frames.
Definition: Source.h:103
SourceFile(size_t sampleRate)
Definition: Source.cpp:90
virtual size_t getSampleRateNative() const =0
Returns the true samplerate of the Source.
std::shared_ptr< class DataSource > DataSourceRef
Definition: DataSource.h:35
std::unique_ptr< dsp::Converter > mConverter
Definition: Source.h:75
void seek(size_t readPositionFrames)
Seek the read position to readPositionFrames.
Definition: Source.cpp:180
Base class that is used to load and read from an audio source.
Definition: Source.h:41
size_t mReadPos
Definition: Source.h:122
static std::vector< std::string > getSupportedExtensions()
Returns a vector of extensions that SourceFile support for loading. Suitable for the extensions param...
Definition: Source.cpp:65
virtual void setupSampleRateConversion()
Sets up samplerate conversion if needed. Can be overridden by implementation if they handle samplerat...
Definition: Source.cpp:95