Page MenuHomePhorge

AudioSource.h
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

AudioSource.h

#ifndef _ECHOAUDIOSOURCE_H_
#define _ECHOAUDIOSOURCE_H_
#include <echo/Types.h>
#include <echo/Chrono/Chrono.h>
namespace Echo
{
class AudioBuffer;
/**
* Abstract Base class for Audio Sources
*/
class AudioSource
{
public:
AudioSource();
virtual ~AudioSource();
/**
* Restart the audio source.
* Will be called when the AudioBuffer finds that it reached the end of the
* source. After Reset is called. If the source is a audio file then Restart()
* should start reading from the start of the file's audio data again.
*/
virtual void Restart()=0;
/**
* Get length of the buffer.
* @return the length of the Source in seconds.
*/
virtual Seconds GetLength()=0;
/**
* Get the number of channels the audio source provides.
* @return the number of channels, e.g. 1 for mono and 2 for stereo.
*/
virtual u32 GetNumChannels()=0;
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
/**
* UpdateBuffer is called by the buffer on the source when the buffer needs to be updated with more data.
* The frequency is determined by the buffer and can be platform dependent. The buffer will call this
* more rapidly when it is nearer to being played out in an attempt to be filled with enough data to play
* without interruptions.
* This method should call AudioBuffer::Append() to append up to numBytes to the buffer.
* @param buffer the audio buffer to append data to.
* @param numBytes the requested number of bytes to append to the buffer.
* @return the number of bytes.
*/
virtual u32 UpdateBuffer(AudioBuffer& buffer, u32 numBytes)=0;
/**
* Get the bit depth of a sample.
* @return the bit depth.
*/
virtual u32 GetBitDepth() = 0;
/**
* Get the sample rate.
* This is samples per second,known as hertz.
* @return the sample rate.
*/
virtual u32 GetSampleRate() = 0;
/**
* The required buffer length for this audio source to effectively operate as a stream in seconds.
*/
virtual Seconds GetRequiredBufferLengthInSeconds();
/**
* Get the audio source buffer update frequency.
* The Buffer will query the source to determine the update frequency in percent of the buffer.
* For example. if this method returned 0.2f then every 20% of the buffer playback the buffer
* would be updated.
*
* This function should return a value less than 0.5f. The logic for this is that if the buffer
* falls behind by 2 updates then it will force another update to catch up. If this update was
* greater than or equal to 0.5 then the update would lag too far behind and cause an audio skip.
*
* If this returns >= 0.5f then the value is adjusted to 0.4f.
*/
virtual f32 GetUpdateFrequencyInPercent();
};
}
#endif

File Metadata

Mime Type
text/x-c++
Expires
Wed, Jan 15, 9:34 PM (11 m, 15 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
72059
Default Alt Text
AudioSource.h (2 KB)

Event Timeline