Audio module refactored.

--HG--
branch : dev
This commit is contained in:
Martí­n Lucas Golini
2017-02-14 23:33:16 -03:00
parent 35955a80bd
commit 603334294e
23 changed files with 392 additions and 392 deletions

View File

@@ -17,15 +17,15 @@ class EE_API AudioDevice {
~AudioDevice();
/** Get the OpenAL format that matches the given number of channels */
static int GetFormatFromChannelCount( unsigned int ChannelCount );
static int getFormatFromChannelCount( unsigned int ChannelCount );
/** Checks if a AL or ALC extension is supported */
static bool IsExtensionSupported( const std::string& extension );
static bool isExtensionSupported( const std::string& extension );
/** @return True if the audio device was initialized */
static bool IsAvailable();
static bool isAvailable();
private :
void PrintInfo();
void printInfo();
};
}}

View File

@@ -11,28 +11,28 @@ class EE_API AudioListener {
/** Change the global volume of all the sounds. ( default 100 )
* @param Volume New global volume, in the range [0, 100]
*/
static void GlobalVolume( const float& Volume );
static void globalVolume( const float& Volume );
/** Get the Global Volume */
static float GlobalVolume();
static float globalVolume();
/** Change the position of the listener. \n The default position is (0, 0, 0) */
static void Position( const float& X, const float& Y, const float& Z );
static void position( const float& X, const float& Y, const float& Z );
/** Change the position of the listener from a 3D vector. */
static void Position(const Vector3ff& Position);
static void position(const Vector3ff& position);
/** Get the current position of the listener */
static Vector3ff Position();
static Vector3ff position();
/** Change the orientation of the listener (the point he must look at). \n The default target is (0, 0, -1). */
static void Target( const float& X, const float& Y, const float& Z );
static void target( const float& X, const float& Y, const float& Z );
/** Change the orientation of the listener from a 3D vector. */
static void Target(const Vector3ff& Target);
static void target(const Vector3ff& target);
/** Get the current orientation of the listener (the point he's looking at) */
static Vector3ff Target();
static Vector3ff target();
};
}}

View File

@@ -17,22 +17,22 @@ class EE_API Music : public SoundStream {
~Music();
/** Open a Music file from a path */
bool OpenFromFile( const std::string& Filename );
bool openFromFile( const std::string& Filename );
/** Open a Music file from memory */
bool OpenFromMemory( const char * Data, std::size_t SizeInBytes );
bool openFromMemory( const char * Data, std::size_t SizeInBytes );
/** Open a Music file from a file inside a pack file */
bool OpenFromPack( Pack * Pack, const std::string& FilePackPath );
bool openFromPack( Pack * Pack, const std::string& FilePackPath );
/** Get the Music Duration */
Time GetDuration() const;
Time getDuration() const;
private :
virtual bool OnStart();
virtual bool onStart();
virtual bool OnGetData(Chunk& Data);
virtual bool onGetData(Chunk& Data);
virtual void OnSeek( Time timeOffset);
virtual void onSeek( Time timeOffset);
SoundFile * mFile; ///< Sound file
float mDuration; ///< Music duration, in seconds

View File

@@ -22,78 +22,78 @@ class EE_API Sound {
~Sound();
/** Construct the sound with a buffer. */
Sound( const SoundBuffer& Buffer, const bool& Loop = false, const float& Pitch = 1.f, const float& Volume = 100.f, const Vector3ff& Position = Vector3ff(0, 0, 0) );
Sound( const SoundBuffer& buffer, const bool& loop = false, const float& pitch = 1.f, const float& volume = 100.f, const Vector3ff& position = Vector3ff(0, 0, 0) );
/** Copy constructor */
Sound(const Sound& Copy);
/** Play the Sound */
void Play();
void play();
/** Pause the Sound */
void Pause();
void pause();
/** Stop the Sound */
void Stop();
void stop();
/** Set the Sound Source Buffer */
void Buffer( const SoundBuffer& Buffer );
void buffer( const SoundBuffer& buffer );
/** Set the Sound Loop State */
void Loop( const bool& Loop );
void loop( const bool& loop );
/** Set the Sound Pitch */
void Pitch( const float& Pitch );
void pitch( const float& pitch );
/** Set the Sound Volume */
void Volume( const float& Volume );
void volume( const float& volume );
/** Set the Sound Position. The default position is (0, 0, 0) */
void Position( const float& X, const float& Y, const float& Z );
void position( const float& X, const float& Y, const float& Z );
/** Set the Sound Position from a 3D Vector. The default position is (0, 0, 0) */
void Position( const Vector3ff& Position );
void position( const Vector3ff& position );
/** Set the minimum distance - closer than this distance, \n the listener will hear the sound at its maximum volume. \n The default minimum distance is 1.0. */
void MinDistance( const float& MinDistance );
void minDistance( const float& minDistance );
/** Set the attenuation factor. \n The higher the attenuation, the more the sound will be attenuated with distance from listener. \n The default attenuation factor 1.0. */
void Attenuation( const float& Attenuation );
void attenuation( const float& attenuation );
/** Get the Sound Source Buffer */
const SoundBuffer* Buffer() const;
const SoundBuffer* buffer() const;
/** Get the Sound Loop State */
bool Loop() const;
bool loop() const;
/** Get the Sound Pitch */
float Pitch() const;
float pitch() const;
/** Get the Sound Volume */
float Volume() const;
float volume() const;
/** Get the Sound Position */
Vector3ff Position() const;
Vector3ff position() const;
/** Get the Minimun Distance */
float MinDistance() const;
float minDistance() const;
/** Get the Sound Attenuation */
float Attenuation() const;
float attenuation() const;
/** Get the Sound State */
Status GetState() const;
Status getState() const;
/** Get the Sound State */
Status State() const;
Status state() const;
/** Get the current playing position of the sound */
virtual Time PlayingOffset() const;
virtual Time playingOffset() const;
/** Set the current playing position of the sound
* @param TimeOffset : New playing position
*/
virtual void PlayingOffset( const Time &TimeOffset );
virtual void playingOffset( const Time &TimeOffset );
/** Assignment operator */
Sound& operator =(const Sound& Other);
@@ -101,19 +101,19 @@ class EE_API Sound {
/** Make the sound's position relative to the listener's position, or absolute. The default value is false (absolute)
* @param Relative : True to set the position relative, false to set it absolute
*/
void SetRelativeToListener( const bool& Relative );
void setRelativeToListener( const bool& Relative );
/** Tell if the sound's position is relative to the listener's position, or if it's absolute
* @return True if the position is relative, false if it's absolute
*/
bool IsRelativeToListener() const;
bool isRelativeToListener() const;
/** \brief Reset the internal buffer of the sound
* This function is for internal use only, you don't have
* to use it. It is called by the SoundBuffer that
* this sound uses, when it is destroyed in order to prevent
* the sound from using a dead buffer. */
void ResetBuffer();
void resetBuffer();
private :
friend class SoundStream;

View File

@@ -19,34 +19,34 @@ class EE_API SoundBuffer {
SoundBuffer(const SoundBuffer& Copy);
/** Load the Sound Buffer from a file */
bool LoadFromFile( const std::string& Filename );
bool loadFromFile( const std::string& Filename );
/** Load the Sound Buffer from a file inside a pack file*/
bool LoadFromPack( Pack* Pack, const std::string& FilePackPath );
bool loadFromPack( Pack* Pack, const std::string& FilePackPath );
/** Load the Sound Buffer from a file in memory */
bool LoadFromMemory( const char* Data, std::size_t SizeInBytes );
bool loadFromMemory( const char* Data, std::size_t SizeInBytes );
/** Load the Sound Buffer from an array of samples. Assumed format for samples is 16 bits signed integer */
bool LoadFromSamples( const Int16* Samples, std::size_t SamplesCount, unsigned int ChannelCount, unsigned int SampleRate );
bool loadFromSamples( const Int16* Samples, std::size_t SamplesCount, unsigned int ChannelCount, unsigned int SampleRate );
/** Save the Sound Buffer to a file */
bool SaveToFile( const std::string& Filename ) const;
bool saveToFile( const std::string& Filename ) const;
/** @return The Sound Samples */
const Int16* GetSamples() const;
const Int16* getSamples() const;
/** @return The Samples Count */
std::size_t GetSamplesCount() const;
std::size_t getSamplesCount() const;
/** Get the Sample Rate */
unsigned int GetSampleRate() const;
unsigned int getSampleRate() const;
/** Return the number of Channels */
unsigned int GetChannelCount() const;
unsigned int getChannelCount() const;
/** Get the Sound Duration */
Time GetDuration() const;
Time getDuration() const;
/** Assignment operator */
SoundBuffer& operator =(const SoundBuffer& Other);
@@ -61,11 +61,11 @@ class EE_API SoundBuffer {
mutable SoundList mSounds;
/** Update the internal buffer with the audio samples */
bool Update( unsigned int ChannelCount, unsigned int SampleRate );
bool update( unsigned int ChannelCount, unsigned int SampleRate );
void AttachSound( Sound* sound ) const;
void attachSound( Sound* sound ) const;
void DetachSound( Sound* sound ) const;
void detachSound( Sound* sound ) const;
};

View File

@@ -35,7 +35,7 @@ class tSoundLoader : public ObjectLoader {
void unload();
/** @return The sound id */
const T& Id() const;
const T& id() const;
protected:
Uint32 mLoadType;
tSoundManager<T> * mSndMngr;
@@ -51,10 +51,10 @@ class tSoundLoader : public ObjectLoader {
void start();
private:
void LoadFromPath();
void LoadFromMemory();
void LoadFromPack();
void LoadFromSamples();
void loadFromPath();
void loadFromMemory();
void loadFromPack();
void loadFromSamples();
};
template <typename T>
@@ -124,47 +124,47 @@ void tSoundLoader<T>::start() {
ObjectLoader::start();
if ( SND_LT_PATH == mLoadType )
LoadFromPath();
loadFromPath();
else if ( SND_LT_MEM == mLoadType )
LoadFromMemory();
loadFromMemory();
else if ( SND_LT_PACK == mLoadType )
LoadFromPack();
loadFromPack();
else if ( SND_LT_SAMPLES == mLoadType )
LoadFromSamples();
loadFromSamples();
setLoaded();
}
}
template <typename T>
void tSoundLoader<T>::LoadFromPath() {
mSndMngr->LoadFromFile( mId, mFilepath );
void tSoundLoader<T>::loadFromPath() {
mSndMngr->loadFromFile( mId, mFilepath );
}
template <typename T>
void tSoundLoader<T>::LoadFromMemory() {
mSndMngr->LoadFromMemory( mId, mData, mDataSize );
void tSoundLoader<T>::loadFromMemory() {
mSndMngr->loadFromMemory( mId, mData, mDataSize );
}
template <typename T>
void tSoundLoader<T>::LoadFromPack() {
mSndMngr->LoadFromPack( mId, mPack, mFilepath );
void tSoundLoader<T>::loadFromPack() {
mSndMngr->loadFromPack( mId, mPack, mFilepath );
}
template <typename T>
void tSoundLoader<T>::LoadFromSamples() {
mSndMngr->LoadFromSamples( mId, mSamples, mSamplesCount, mChannelCount, mSampleRate );
void tSoundLoader<T>::loadFromSamples() {
mSndMngr->loadFromSamples( mId, mSamples, mSamplesCount, mChannelCount, mSampleRate );
}
template <typename T>
const T& tSoundLoader<T>::Id() const {
const T& tSoundLoader<T>::id() const {
return mId;
}
template <typename T>
void tSoundLoader<T>::unload() {
if ( mLoaded ) {
mSndMngr->Remove( mId );
mSndMngr->remove( mId );
reset();
}

View File

@@ -15,13 +15,13 @@ class tSoundManager {
** @param id The sound Id
** @param filepath The sound path
*/
bool LoadFromFile( const T& id, const std::string& filepath );
bool loadFromFile( const T& id, const std::string& filepath );
/** @brief Load the sound from memory
** @param id The sound id
** @param Data The pointer to the data
** @param SizeInBytes The size of the file to load */
bool LoadFromMemory( const T& id, const char* Data, std::size_t SizeInBytes );
bool loadFromMemory( const T& id, const char* Data, std::size_t SizeInBytes );
/** @brief Load the sound from an array of samples.
** @param id The sound id
@@ -29,31 +29,31 @@ class tSoundManager {
** @param SamplesCount Number of samples in the array
** @param ChannelCount Number of channels (1 = mono, 2 = stereo, ...)
** @param SampleRate Sample rate (number of samples to play per second) */
bool LoadFromSamples( const T& id, const Int16* Samples, std::size_t SamplesCount, unsigned int ChannelCount, unsigned int SampleRate );
bool loadFromSamples( const T& id, const Int16* Samples, std::size_t SamplesCount, unsigned int ChannelCount, unsigned int SampleRate );
/** @brief Load the sound from a Pack file
** @param id The id to use to identificate the sound
** @param Pack The Pack file
** @param FilePackPath The pack file path */
bool LoadFromPack( const T& id, Pack* Pack, const std::string& FilePackPath );
bool loadFromPack( const T& id, Pack* Pack, const std::string& FilePackPath );
/** @return The sound buffer of the sound id */
SoundBuffer& GetBuffer( const T& id );
SoundBuffer& getBuffer( const T& id );
/** Play the sound. This method will open a new channel if the channel seted for the sound is already playing.
** @param id The sound id to play */
void Play( const T& id );
void play( const T& id );
/** Remove a sound from the sound manager.
** @param id The sound id to remove */
bool Remove( const T& id );
bool remove( const T& id );
/** @return The sound id if exists */
Sound& operator[] ( const T& id );
/** @brief Search for the sound id, and return a sound that is not playing, if all the sounds are playing, creates a new sound.
** @return The sound */
Sound& GetFreeSound( const T& id );
Sound& getFreeSound( const T& id );
~tSoundManager();
private:
@@ -65,11 +65,11 @@ class tSoundManager {
};
template <typename T>
bool tSoundManager<T>::LoadFromPack( const T& id, Pack* Pack, const std::string& FilePackPath ) {
bool tSoundManager<T>::loadFromPack( const T& id, Pack* Pack, const std::string& FilePackPath ) {
if ( tSounds.find( id ) == tSounds.end() ) { // if id doesn't exists
sSound * tSound = &tSounds[id];
if ( tSound->Buf.LoadFromPack( Pack, FilePackPath ) ) {
if ( tSound->Buf.loadFromPack( Pack, FilePackPath ) ) {
tSound->Snd.push_back( Sound( tSound->Buf ) );
return true;
}
@@ -79,11 +79,11 @@ bool tSoundManager<T>::LoadFromPack( const T& id, Pack* Pack, const std::string&
}
template <typename T>
bool tSoundManager<T>::LoadFromFile( const T& id, const std::string& filepath ) {
bool tSoundManager<T>::loadFromFile( const T& id, const std::string& filepath ) {
if ( tSounds.find( id ) == tSounds.end() ) { // if id doesn't exists
sSound * tSound = &tSounds[id];
if ( tSound->Buf.LoadFromFile( filepath ) ) {
if ( tSound->Buf.loadFromFile( filepath ) ) {
tSound->Snd.push_back( Sound( tSound->Buf ) );
return true;
}
@@ -93,11 +93,11 @@ bool tSoundManager<T>::LoadFromFile( const T& id, const std::string& filepath )
}
template <typename T>
bool tSoundManager<T>::LoadFromMemory( const T& id, const char* Data, std::size_t SizeInBytes ) {
bool tSoundManager<T>::loadFromMemory( const T& id, const char* Data, std::size_t SizeInBytes ) {
if ( tSounds.find( id ) == tSounds.end() ) { // if id doesn't exists
sSound * tSound = &tSounds[id];
if ( tSound->Buf.LoadFromMemory( Data, SizeInBytes ) ) {
if ( tSound->Buf.loadFromMemory( Data, SizeInBytes ) ) {
tSound->Snd.push_back( Sound( tSound->Buf ) );
return true;
}
@@ -107,11 +107,11 @@ bool tSoundManager<T>::LoadFromMemory( const T& id, const char* Data, std::size_
}
template <typename T>
bool tSoundManager<T>::LoadFromSamples( const T& id, const Int16* Samples, std::size_t SamplesCount, unsigned int ChannelCount, unsigned int SampleRate ) {
bool tSoundManager<T>::loadFromSamples( const T& id, const Int16* Samples, std::size_t SamplesCount, unsigned int ChannelCount, unsigned int SampleRate ) {
if ( tSounds.find( id ) == tSounds.end() ) { // if id doesn't exists
sSound * tSound = &tSounds[id];
if ( tSound->Buf.LoadFromSamples( Samples, SamplesCount, ChannelCount, SampleRate ) ) {
if ( tSound->Buf.loadFromSamples( Samples, SamplesCount, ChannelCount, SampleRate ) ) {
tSound->Snd.push_back( Sound( tSound->Buf ) );
return true;
}
@@ -121,7 +121,7 @@ bool tSoundManager<T>::LoadFromSamples( const T& id, const Int16* Samples, std::
}
template <typename T>
SoundBuffer& tSoundManager<T>::GetBuffer( const T& id ) {
SoundBuffer& tSoundManager<T>::getBuffer( const T& id ) {
if ( tSounds.find( id ) != tSounds.end() )
return tSounds[id].Buf;
@@ -130,7 +130,7 @@ SoundBuffer& tSoundManager<T>::GetBuffer( const T& id ) {
}
template <typename T>
Sound& tSoundManager<T>::GetFreeSound( const T& id ) {
Sound& tSoundManager<T>::getFreeSound( const T& id ) {
typename std::map<T, sSound>::iterator it = tSounds.find( id );
if ( it != tSounds.end() ) {
@@ -139,7 +139,7 @@ Sound& tSoundManager<T>::GetFreeSound( const T& id ) {
for ( Uint32 i = 0; i < tSize; i++ ) {
// If there is a free slot, use it.
if ( tSound->Snd[i].GetState() != Sound::Playing ) {
if ( tSound->Snd[i].getState() != Sound::Playing ) {
return tSound->Snd[i];
}
}
@@ -161,7 +161,7 @@ Sound& tSoundManager<T>::operator[] ( const T& id ) {
}
template <typename T>
void tSoundManager<T>::Play( const T& id ) {
void tSoundManager<T>::play( const T& id ) {
typename std::map<T, sSound>::iterator it = tSounds.find( id );
if ( it != tSounds.end() ) {
@@ -170,15 +170,15 @@ void tSoundManager<T>::Play( const T& id ) {
for ( Uint32 i = 0; i < tSize; i++ ) {
// If there is a free slot, use it.
if ( tSound->Snd[i].GetState() != Sound::Playing ) {
tSound->Snd[i].Play();
if ( tSound->Snd[i].getState() != Sound::Playing ) {
tSound->Snd[i].play();
return;
}
}
// Otherwise create a new one and play it.
tSound->Snd.push_back( Sound( tSound->Buf ) );
tSound->Snd[ tSize ].Play();
tSound->Snd[ tSize ].play();
}
}
@@ -193,7 +193,7 @@ tSoundManager<T>::~tSoundManager() {
}
template <typename T>
bool tSoundManager<T>::Remove( const T& id ) {
bool tSoundManager<T>::remove( const T& id ) {
if ( tSounds.find( id ) != tSounds.end() ) {
tSounds.erase( id );
return true;

View File

@@ -9,14 +9,14 @@ namespace EE { namespace Audio {
/** @brief Abstract base class for streamed audio sources */
class EE_API SoundStream : private Thread, private Sound {
public:
using Sound::Pause;
using Sound::Pitch;
using Sound::Volume;
using Sound::Position;
using Sound::MinDistance;
using Sound::Attenuation;
using Sound::SetRelativeToListener;
using Sound::IsRelativeToListener;
using Sound::pause;
using Sound::pitch;
using Sound::volume;
using Sound::position;
using Sound::minDistance;
using Sound::attenuation;
using Sound::setRelativeToListener;
using Sound::isRelativeToListener;
/** @brief Structure defining a chunk of audio data to stream */
struct Chunk {
@@ -33,81 +33,81 @@ class EE_API SoundStream : private Thread, private Sound {
** This function uses its own thread so that it doesn't block
** the rest of the program while the stream is played.
** @see Pause, Stop */
void Play();
void play();
/** @brief Pause the audio stream
** This function pauses the stream if it was playing,
** otherwise (stream already paused or stopped) it has no effect.
** @see Play, Stop */
void Pause();
void pause();
/** @brief Stop playing the audio stream
** This function stops the stream if it was playing or paused,
** and does nothing if it was already stopped.
** It also resets the playing position (unlike pause()).
** @see Play, Pause */
void Stop();
void stop();
/** @brief Return the number of channels of the stream
** 1 channel means a mono sound, 2 means stereo, etc.
** @return Number of channels */
unsigned int GetChannelCount() const;
unsigned int getChannelCount() const;
/** @brief Get the stream sample rate of the stream
** The sample rate is the number of audio samples played per
** second. The higher, the better the quality.
** @return Sample rate, in number of samples per second */
unsigned int GetSampleRate() const;
unsigned int getSampleRate() const;
/** @brief Get the current status of the stream (stopped, paused, playing)
** @return Current status */
Status GetState() const;
Status getState() const;
/** @brief Get the current status of the stream (stopped, paused, playing)
** @return Current status */
Status State() const ;
Status state() const ;
/** @brief Get the current playing position of the stream
** @return Current playing position, from the beginning of the stream. */
Time PlayingOffset() const;
Time playingOffset() const;
/** @brief Change the current playing position of the stream
** The playing position can be changed when the stream is either paused or playing.
** @param timeOffset New playing position, from the beginning of the stream. */
void PlayingOffset( const Time &timeOffset );
void playingOffset( const Time &timeOffset );
/** Set the stream loop state. This parameter is disabled by default
* @param Loop True to play in loop, false to play once
*/
void Loop( const bool& Loop);
void loop( const bool& loop);
/** Tell whether or not the stream is looping
* @return True if the music is looping, false otherwise
*/
bool Loop() const;
bool loop() const;
protected:
SoundStream();
void Initialize(unsigned int ChannelCount, unsigned int SampleRate);
void initialize(unsigned int ChannelCount, unsigned int SampleRate);
private :
virtual void run();
virtual bool OnGetData( Chunk& Data ) = 0;
virtual bool onGetData( Chunk& Data ) = 0;
virtual void OnSeek( Time timeOffset ) = 0;
virtual void onSeek( Time timeOffset ) = 0;
/** Fill a new buffer with audio data, and push it to the playing queue
* @param Buffer Buffer to fill
* @return True if the derived class wish to continue playback
*/
bool FillAndPushBuffer( const unsigned int& Buffer );
bool fillAndPushBuffer( const unsigned int& buffer );
/** Fill the buffers queue with all available buffers
* @return True if the derived class has requested to stop
*/
bool FillQueue();
bool fillQueue();
void ClearQueue();
void clearQueue();
enum {
BuffersCount = 3

View File

@@ -8,7 +8,7 @@ ALCdevice * mDevice = NULL;
ALCcontext * mContext = NULL;
AudioDevice::AudioDevice() {
PrintInfo();
printInfo();
// Create the device
mDevice = alcOpenDevice( NULL );
@@ -42,7 +42,7 @@ AudioDevice::AudioDevice() {
}
}
void AudioDevice::PrintInfo() {
void AudioDevice::printInfo() {
std::string log( "OpenAL devices detected:\n" );
if ( alcIsExtensionPresent( NULL, (const ALCchar *) "ALC_ENUMERATION_EXT" ) == AL_TRUE ) {
@@ -74,7 +74,7 @@ AudioDevice::~AudioDevice() {
alcCloseDevice( mDevice );
}
bool AudioDevice::IsExtensionSupported( const std::string& extension ) {
bool AudioDevice::isExtensionSupported( const std::string& extension ) {
EnsureALInit();
if ( ( extension.length() > 2 ) && ( extension.substr(0, 3) == "ALC" ) )
@@ -83,7 +83,7 @@ bool AudioDevice::IsExtensionSupported( const std::string& extension ) {
return alIsExtensionPresent( extension.c_str() ) != AL_FALSE;
}
int AudioDevice::GetFormatFromChannelCount( unsigned int ChannelCount ) {
int AudioDevice::getFormatFromChannelCount( unsigned int ChannelCount ) {
EnsureALInit();
int format = 0;
@@ -104,7 +104,7 @@ int AudioDevice::GetFormatFromChannelCount( unsigned int ChannelCount ) {
return format;
}
bool AudioDevice::IsAvailable() {
bool AudioDevice::isAvailable() {
return NULL != mDevice && NULL != mContext;
}

View File

@@ -3,7 +3,7 @@
namespace EE { namespace Audio {
void AudioListener::GlobalVolume( const float& Volume ) {
void AudioListener::globalVolume( const float& Volume ) {
EnsureALInit();
#if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN
@@ -11,7 +11,7 @@ void AudioListener::GlobalVolume( const float& Volume ) {
#endif
}
float AudioListener::GlobalVolume() {
float AudioListener::globalVolume() {
EnsureALInit();
float Volume = 0.f;
@@ -21,17 +21,17 @@ float AudioListener::GlobalVolume() {
return Volume * 100.f;
}
void AudioListener::Position( const float& X, const float& Y, const float& Z ) {
void AudioListener::position( const float& X, const float& Y, const float& Z ) {
EnsureALInit();
ALCheck( alListener3f( AL_POSITION, X, Y, Z ) );
}
void AudioListener::Position(const Vector3ff& Position) {
AudioListener::Position( Position.x, Position.y, Position.z );
void AudioListener::position(const Vector3ff& Position) {
AudioListener::position( Position.x, Position.y, Position.z );
}
Vector3ff AudioListener::Position() {
Vector3ff AudioListener::position() {
EnsureALInit();
Vector3ff Position;
@@ -40,18 +40,18 @@ Vector3ff AudioListener::Position() {
return Position;
}
void AudioListener::Target( const float& X, const float& Y, const float& Z ) {
void AudioListener::target( const float& X, const float& Y, const float& Z ) {
EnsureALInit();
float Orientation[] = {X, Y, Z, 0.f, 1.f, 0.f};
ALCheck( alListenerfv( AL_ORIENTATION, Orientation ) );
}
void AudioListener::Target(const Vector3ff& Target) {
AudioListener::Target( Target.x, Target.y, Target.z );
void AudioListener::target(const Vector3ff& Target) {
AudioListener::target( Target.x, Target.y, Target.z );
}
Vector3ff AudioListener::Target() {
Vector3ff AudioListener::target() {
EnsureALInit();
float Orientation[6];

View File

@@ -12,18 +12,18 @@ Music::Music( std::size_t BufferSize ) :
}
Music::~Music() {
Stop();
stop();
eeSAFE_DELETE( mFile );
}
bool Music::OpenFromPack( Pack* Pack, const std::string& FilePackPath ) {
bool Music::openFromPack( Pack* Pack, const std::string& FilePackPath ) {
if ( Pack->isOpen() && Pack->extractFileToMemory( FilePackPath, mData ) )
return OpenFromMemory( reinterpret_cast<const char*> ( mData.Data ), mData.DataSize );
return openFromMemory( reinterpret_cast<const char*> ( mData.Data ), mData.DataSize );
return false;
}
bool Music::OpenFromFile( const std::string& Filename ) {
bool Music::openFromFile( const std::string& Filename ) {
if ( !FileSystem::fileExists( Filename ) ) {
if ( PackManager::instance()->fallbackToPacks() ) {
std::string tPath( Filename );
@@ -31,7 +31,7 @@ bool Music::OpenFromFile( const std::string& Filename ) {
Pack * tPack = PackManager::instance()->exists( tPath );
if ( NULL != tPack ) {
return OpenFromPack( tPack, tPath );
return openFromPack( tPack, tPath );
}
}
@@ -39,10 +39,10 @@ bool Music::OpenFromFile( const std::string& Filename ) {
}
// Create the sound file implementation, and open it in read mode
Stop();
stop();
eeSAFE_DELETE( mFile );
mFile = SoundFile::CreateRead( Filename );
mFile = SoundFile::createRead( Filename );
if ( NULL == mFile ) {
eePRINTL( "Failed to open %s for reading", Filename.c_str() );
@@ -50,46 +50,46 @@ bool Music::OpenFromFile( const std::string& Filename ) {
}
// Compute the duration
mDuration = static_cast<float>( mFile->GetSamplesCount() ) / mFile->GetSampleRate() / mFile->GetChannelCount();
mDuration = static_cast<float>( mFile->getSamplesCount() ) / mFile->getSampleRate() / mFile->getChannelCount();
// Initialize the stream
Initialize( mFile->GetChannelCount(), mFile->GetSampleRate() );
initialize( mFile->getChannelCount(), mFile->getSampleRate() );
eePRINTL( "Music file %s loaded.", Filename.c_str() );
return true;
}
bool Music::OpenFromMemory( const char * Data, std::size_t SizeInBytes ) {
Stop();
bool Music::openFromMemory( const char * Data, std::size_t SizeInBytes ) {
stop();
eeSAFE_DELETE( mFile );
// Create the sound file implementation, and open it in read mode
mFile = SoundFile::CreateRead( Data, SizeInBytes );
mFile = SoundFile::createRead( Data, SizeInBytes );
if ( NULL == mFile ) {
eePRINTL( "Failed to open music from memory for reading" );
return false;
}
mDuration = static_cast<float>( mFile->GetSamplesCount() ) / mFile->GetSampleRate(); // Compute the duration
mDuration = static_cast<float>( mFile->getSamplesCount() ) / mFile->getSampleRate(); // Compute the duration
Initialize( mFile->GetChannelCount(), mFile->GetSampleRate() ); // Initialize the stream
initialize( mFile->getChannelCount(), mFile->getSampleRate() ); // Initialize the stream
eePRINTL( "Music file loaded from memory." );
return true;
}
bool Music::OnStart() {
return NULL != mFile && mFile->Restart();
bool Music::onStart() {
return NULL != mFile && mFile->restart();
}
bool Music::OnGetData( SoundStream::Chunk& Data ) {
bool Music::onGetData( SoundStream::Chunk& Data ) {
if ( NULL != mFile ) {
// Fill the chunk parameters
Data.Samples = &mSamples[0];
Data.SamplesCount = mFile->Read( &mSamples[0], mSamples.size() );
Data.SamplesCount = mFile->read( &mSamples[0], mSamples.size() );
// Check if we have reached the end of the audio file
return Data.SamplesCount == mSamples.size();
@@ -98,13 +98,13 @@ bool Music::OnGetData( SoundStream::Chunk& Data ) {
return false;
}
Time Music::GetDuration() const {
Time Music::getDuration() const {
return Seconds( mDuration );
}
void Music::OnSeek( Time timeOffset ) {
void Music::onSeek( Time timeOffset ) {
if ( NULL != mFile ) {
mFile->Seek( timeOffset );
mFile->seek( timeOffset );
}
}

View File

@@ -35,16 +35,16 @@ Sound::Sound(const Sound& Copy) :
ALCheck( alGenSources( 1, &mSource ) );
ALCheck( alSourcei ( mSource, AL_BUFFER, mBuffer ? mBuffer->mBuffer : 0) );
ALCheck( alSourcei ( mSource, AL_LOOPING, Copy.Loop()) );
ALCheck( alSourcef ( mSource, AL_PITCH, Copy.Pitch()) );
ALCheck( alSourcef ( mSource, AL_GAIN, Copy.Volume() * 0.01f) );
ALCheck( alSource3f( mSource, AL_POSITION, Copy.Position().x, Copy.Position().y, Copy.Position().z) );
ALCheck( alSourcei ( mSource, AL_LOOPING, Copy.loop()) );
ALCheck( alSourcef ( mSource, AL_PITCH, Copy.pitch()) );
ALCheck( alSourcef ( mSource, AL_GAIN, Copy.volume() * 0.01f) );
ALCheck( alSource3f( mSource, AL_POSITION, Copy.position().x, Copy.position().y, Copy.position().z) );
}
Sound::~Sound() {
if ( mSource ) {
if ( mBuffer ) {
Stop();
stop();
ALCheck( alSourcei(mSource, AL_BUFFER, 0 ) );
}
@@ -52,84 +52,84 @@ Sound::~Sound() {
}
}
void Sound::Play() {
void Sound::play() {
ALCheck( alSourcePlay( mSource ) );
}
void Sound::Pause() {
void Sound::pause() {
ALCheck( alSourcePause( mSource ) );
}
void Sound::Stop() {
void Sound::stop() {
ALCheck( alSourceStop( mSource ) );
}
void Sound::Buffer(const SoundBuffer& Buffer) {
void Sound::buffer(const SoundBuffer& Buffer) {
if ( NULL != mBuffer ) {
Stop();
mBuffer->DetachSound( this );
stop();
mBuffer->detachSound( this );
}
mBuffer = &Buffer;
mBuffer->AttachSound (this );
mBuffer->attachSound (this );
ALCheck( alSourcei( mSource, AL_BUFFER, mBuffer ? mBuffer->mBuffer : 0 ) );
}
void Sound::Loop( const bool& Loop ) {
void Sound::loop( const bool& Loop ) {
ALCheck( alSourcei( mSource, AL_LOOPING, Loop ) );
}
void Sound::Pitch( const float& Pitch ) {
void Sound::pitch( const float& Pitch ) {
ALCheck( alSourcef( mSource, AL_PITCH, Pitch ) );
}
void Sound::Volume( const float& Volume ) {
void Sound::volume( const float& Volume ) {
ALCheck( alSourcef( mSource, AL_GAIN, Volume * 0.01f ) );
}
void Sound::Position( const float& X, const float& Y, const float& Z ) {
void Sound::position( const float& X, const float& Y, const float& Z ) {
ALCheck( alSource3f( mSource, AL_POSITION, X, Y, Z ) );
}
void Sound::Position( const Vector3ff& Position ) {
this->Position( Position.x, Position.y, Position.z );
void Sound::position( const Vector3ff& Position ) {
this->position( Position.x, Position.y, Position.z );
}
void Sound::MinDistance( const float& MinDistance ) {
void Sound::minDistance( const float& MinDistance ) {
ALCheck( alSourcef( mSource, AL_REFERENCE_DISTANCE, MinDistance ) );
}
void Sound::Attenuation( const float& Attenuation ) {
void Sound::attenuation( const float& Attenuation ) {
ALCheck( alSourcef( mSource, AL_ROLLOFF_FACTOR, Attenuation ) );
}
const SoundBuffer* Sound::Buffer() const {
const SoundBuffer* Sound::buffer() const {
return mBuffer;
}
bool Sound::Loop() const {
bool Sound::loop() const {
ALint Loop;
ALCheck( alGetSourcei( mSource, AL_LOOPING, &Loop ) );
return Loop != 0;
}
float Sound::Pitch() const {
float Sound::pitch() const {
float Pitch;
ALCheck( alGetSourcef( mSource, AL_PITCH, &Pitch ) );
return Pitch;
}
float Sound::Volume() const {
float Sound::volume() const {
float Gain = 1;
ALCheck( alGetSourcef( mSource, AL_GAIN, &Gain ) );
return Gain * 100.f;
}
Vector3ff Sound::Position() const {
Vector3ff Sound::position() const {
Vector3ff Position;
#if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN
@@ -139,21 +139,21 @@ Vector3ff Sound::Position() const {
return Position;
}
float Sound::MinDistance() const {
float Sound::minDistance() const {
float MinDistance;
ALCheck( alGetSourcef( mSource, AL_REFERENCE_DISTANCE, &MinDistance ) );
return MinDistance;
}
float Sound::Attenuation() const {
float Sound::attenuation() const {
float Attenuation;
ALCheck( alGetSourcef( mSource, AL_ROLLOFF_FACTOR, &Attenuation ) );
return Attenuation;
}
Sound::Status Sound::GetState() const {
Sound::Status Sound::getState() const {
ALint State;
ALCheck( alGetSourcei( mSource, AL_SOURCE_STATE, &State ) );
@@ -167,7 +167,7 @@ Sound::Status Sound::GetState() const {
return Sound::Stopped;
}
Time Sound::PlayingOffset() const {
Time Sound::playingOffset() const {
float secs = 0.f;
ALCheck( alGetSourcef( mSource, AL_SEC_OFFSET, &secs ) );
@@ -175,59 +175,59 @@ Time Sound::PlayingOffset() const {
return Seconds( secs );
}
void Sound::PlayingOffset( const Time &TimeOffset ) {
void Sound::playingOffset( const Time &TimeOffset ) {
ALCheck( alSourcef( mSource, AL_SEC_OFFSET, TimeOffset.asSeconds() ) );
}
Sound& Sound::operator =( const Sound& Other ) {
if ( NULL != mBuffer ) {
Stop();
mBuffer->DetachSound( this );
stop();
mBuffer->detachSound( this );
mBuffer = NULL;
}
// Copy the sound attributes
if ( NULL != Other.mBuffer ) {
Buffer( *Other.mBuffer );
buffer( *Other.mBuffer );
}
Loop( Other.Loop() );
Pitch( Other.Pitch() );
Volume( Other.Volume() );
Position( Other.Position() );
SetRelativeToListener( Other.IsRelativeToListener() );
MinDistance( Other.MinDistance()) ;
Attenuation( Other.Attenuation() );
loop( Other.loop() );
pitch( Other.pitch() );
volume( Other.volume() );
position( Other.position() );
setRelativeToListener( Other.isRelativeToListener() );
minDistance( Other.minDistance()) ;
attenuation( Other.attenuation() );
return *this;
}
void Sound::SetRelativeToListener( const bool& Relative ) {
void Sound::setRelativeToListener( const bool& Relative ) {
ALCheck( alSourcei( mSource, AL_SOURCE_RELATIVE, Relative ) );
}
bool Sound::IsRelativeToListener() const {
bool Sound::isRelativeToListener() const {
ALint Relative;
ALCheck( alGetSourcei( mSource, AL_SOURCE_RELATIVE, &Relative ) );
return Relative != 0;
}
void Sound::ResetBuffer() {
void Sound::resetBuffer() {
// First stop the sound in case it is playing
Stop();
stop();
// Detach the buffer
if ( NULL != mBuffer ) {
ALCheck( alSourcei( mSource, AL_BUFFER, 0 ) );
mBuffer->DetachSound( this );
mBuffer->detachSound( this );
mBuffer = NULL;
}
}
Sound::Status Sound::State() const {
return GetState();
Sound::Status Sound::state() const {
return getState();
}
}}

View File

@@ -26,18 +26,18 @@ SoundBuffer::SoundBuffer(const SoundBuffer& Copy) :
EnsureALInit();
ALCheck( alGenBuffers( 1, &mBuffer ) );
Update( Copy.GetChannelCount(), Copy.GetSampleRate() );
update( Copy.getChannelCount(), Copy.getSampleRate() );
}
SoundBuffer::~SoundBuffer() {
for ( SoundList::const_iterator it = mSounds.begin(); it != mSounds.end(); ++it )
(*it)->ResetBuffer();
(*it)->resetBuffer();
if ( mBuffer )
ALCheck( alDeleteBuffers( 1, &mBuffer ) );
}
bool SoundBuffer::LoadFromFile(const std::string& Filename) {
bool SoundBuffer::loadFromFile(const std::string& Filename) {
if ( !FileSystem::fileExists( Filename ) ) {
if ( PackManager::instance()->fallbackToPacks() ) {
std::string tPath( Filename );
@@ -45,7 +45,7 @@ bool SoundBuffer::LoadFromFile(const std::string& Filename) {
Pack * tPack = PackManager::instance()->exists( tPath );
if ( NULL != tPack ) {
return LoadFromPack( tPack, tPath );
return loadFromPack( tPack, tPath );
}
}
@@ -54,25 +54,25 @@ bool SoundBuffer::LoadFromFile(const std::string& Filename) {
}
// Create the sound file
SoundFile * File = SoundFile::CreateRead( Filename );
SoundFile * File = SoundFile::createRead( Filename );
// Open the sound file
if ( NULL != File ) {
// Get the sound parameters
std::size_t SamplesCount = File->GetSamplesCount();
unsigned int ChannelCount = File->GetChannelCount();
unsigned int SampleRate = File->GetSampleRate();
std::size_t SamplesCount = File->getSamplesCount();
unsigned int ChannelCount = File->getChannelCount();
unsigned int SampleRate = File->getSampleRate();
// Read the samples from the opened file
mSamples.resize( SamplesCount );
if ( File->Read( &mSamples[0], SamplesCount ) == SamplesCount ) {
if ( File->read( &mSamples[0], SamplesCount ) == SamplesCount ) {
eePRINTL( "Sound file %s loaded.", Filename.c_str() );
// Update the internal buffer with the new samples
eeDelete( File );
return Update( ChannelCount, SampleRate );
return update( ChannelCount, SampleRate );
} else {
eePRINTL( "Failed to read audio data from file %s", Filename.c_str() );
@@ -87,37 +87,37 @@ bool SoundBuffer::LoadFromFile(const std::string& Filename) {
}
}
bool SoundBuffer::LoadFromPack( Pack* Pack, const std::string& FilePackPath ) {
bool SoundBuffer::loadFromPack( Pack* Pack, const std::string& FilePackPath ) {
bool Ret = false;
SafeDataPointer PData;
if ( Pack->isOpen() && Pack->extractFileToMemory( FilePackPath, PData ) )
Ret = LoadFromMemory( reinterpret_cast<const char*> ( PData.Data ), PData.DataSize );
Ret = loadFromMemory( reinterpret_cast<const char*> ( PData.Data ), PData.DataSize );
return Ret;
}
bool SoundBuffer::LoadFromMemory( const char* Data, std::size_t SizeInBytes ) {
bool SoundBuffer::loadFromMemory( const char* Data, std::size_t SizeInBytes ) {
// Create the sound file
SoundFile * File = SoundFile::CreateRead( Data, SizeInBytes );
SoundFile * File = SoundFile::createRead( Data, SizeInBytes );
// Open the sound file
if ( NULL != File ) {
// Get the sound parameters
std::size_t SamplesCount = File->GetSamplesCount();
unsigned int ChannelCount = File->GetChannelCount();
unsigned int SampleRate = File->GetSampleRate();
std::size_t SamplesCount = File->getSamplesCount();
unsigned int ChannelCount = File->getChannelCount();
unsigned int SampleRate = File->getSampleRate();
// Read the samples from the opened file
mSamples.resize( SamplesCount );
if ( File->Read( &mSamples[0], SamplesCount ) == SamplesCount ) {
if ( File->read( &mSamples[0], SamplesCount ) == SamplesCount ) {
eePRINTL( "Sound file loaded from memory." );
// Update the internal buffer with the new samples
eeDelete( File );
return Update( ChannelCount, SampleRate );
return update( ChannelCount, SampleRate );
} else {
eePRINTL( "Failed to read audio data from file in memory" );
@@ -131,7 +131,7 @@ bool SoundBuffer::LoadFromMemory( const char* Data, std::size_t SizeInBytes ) {
}
}
bool SoundBuffer::LoadFromSamples( const Int16 * Samples, std::size_t SamplesCount, unsigned int ChannelCount, unsigned int SampleRate ) {
bool SoundBuffer::loadFromSamples( const Int16 * Samples, std::size_t SamplesCount, unsigned int ChannelCount, unsigned int SampleRate ) {
if ( Samples && SamplesCount && ChannelCount && SampleRate ) {
// Copy the new audio samples
mSamples.assign( Samples, Samples + SamplesCount );
@@ -139,7 +139,7 @@ bool SoundBuffer::LoadFromSamples( const Int16 * Samples, std::size_t SamplesCou
eePRINTL( "Sound file loaded from memory samples." );
// Update the internal buffer with the new samples
return Update( ChannelCount, SampleRate );
return update( ChannelCount, SampleRate );
} else {
// Error...
eePRINTL( "Failed to load sound buffer from memory Samples" );
@@ -147,13 +147,13 @@ bool SoundBuffer::LoadFromSamples( const Int16 * Samples, std::size_t SamplesCou
}
}
bool SoundBuffer::SaveToFile(const std::string& Filename) const {
bool SoundBuffer::saveToFile(const std::string& Filename) const {
// Create the sound file in write mode
std::unique_ptr<SoundFile> File( SoundFile::CreateWrite( Filename, GetChannelCount(), GetSampleRate() ) );
std::unique_ptr<SoundFile> File( SoundFile::createWrite( Filename, getChannelCount(), getSampleRate() ) );
if ( File.get() ) {
// Write the samples to the opened file
File->Write( &mSamples[0], mSamples.size() );
File->write( &mSamples[0], mSamples.size() );
return true;
} else {
// Error...
@@ -162,27 +162,27 @@ bool SoundBuffer::SaveToFile(const std::string& Filename) const {
}
}
const Int16* SoundBuffer::GetSamples() const {
const Int16* SoundBuffer::getSamples() const {
return mSamples.empty() ? NULL : &mSamples[0];
}
std::size_t SoundBuffer::GetSamplesCount() const {
std::size_t SoundBuffer::getSamplesCount() const {
return mSamples.size();
}
unsigned int SoundBuffer::GetSampleRate() const {
unsigned int SoundBuffer::getSampleRate() const {
ALint SampleRate;
ALCheck( alGetBufferi( mBuffer, AL_FREQUENCY, &SampleRate ) );
return SampleRate;
}
unsigned int SoundBuffer::GetChannelCount() const {
unsigned int SoundBuffer::getChannelCount() const {
ALint ChannelCount;
ALCheck( alGetBufferi( mBuffer, AL_CHANNELS, &ChannelCount ) );
return ChannelCount;
}
Time SoundBuffer::GetDuration() const {
Time SoundBuffer::getDuration() const {
return mDuration;
}
@@ -197,13 +197,13 @@ SoundBuffer& SoundBuffer::operator =( const SoundBuffer& Other ) {
return *this;
}
bool SoundBuffer::Update( unsigned int ChannelCount, unsigned int SampleRate ) {
bool SoundBuffer::update( unsigned int ChannelCount, unsigned int SampleRate ) {
// Check parameters
if ( !SampleRate || !ChannelCount || mSamples.empty() )
return false;
// Find the good format according to the number of channels
ALenum Format = AudioDevice::GetFormatFromChannelCount( ChannelCount );
ALenum Format = AudioDevice::getFormatFromChannelCount( ChannelCount );
// Check if the format is valid
if ( Format == 0 ) {
@@ -216,7 +216,7 @@ bool SoundBuffer::Update( unsigned int ChannelCount, unsigned int SampleRate ) {
// Detach the buffer from the sounds that use it (to avoid OpenAL errors)
for (SoundList::const_iterator it = sounds.begin(); it != sounds.end(); ++it)
(*it)->ResetBuffer();
(*it)->resetBuffer();
// Fill the buffer
ALsizei Size = static_cast<ALsizei>( mSamples.size() ) * sizeof(Int16);
@@ -228,11 +228,11 @@ bool SoundBuffer::Update( unsigned int ChannelCount, unsigned int SampleRate ) {
return true;
}
void SoundBuffer::AttachSound( Sound* sound ) const {
void SoundBuffer::attachSound( Sound* sound ) const {
mSounds.insert(sound);
}
void SoundBuffer::DetachSound( Sound* sound ) const {
void SoundBuffer::detachSound( Sound* sound ) const {
mSounds.erase(sound);
}

View File

@@ -17,13 +17,13 @@ SoundFile::~SoundFile()
{
}
SoundFile * SoundFile::CreateRead( const std::string& Filename ) {
SoundFile * SoundFile::createRead( const std::string& Filename ) {
// Create the file according to its type
SoundFile * File = NULL;
if ( SoundFileOgg::IsFileSupported( Filename, true ) ) File = eeNew( SoundFileOgg, () );
if ( SoundFileOgg::isFileSupported( Filename, true ) ) File = eeNew( SoundFileOgg, () );
#ifdef EE_LIBSNDFILE_ENABLED
else if ( SoundFileDefault::IsFileSupported( Filename, true ) ) File = eeNew( SoundFileDefault, () );
else if ( SoundFileDefault::isFileSupported( Filename, true ) ) File = eeNew( SoundFileDefault, () );
#endif
// Open it for reading
@@ -32,7 +32,7 @@ SoundFile * SoundFile::CreateRead( const std::string& Filename ) {
unsigned int ChannelCount;
unsigned int SampleRate;
if ( File->OpenRead( Filename, SamplesCount, ChannelCount, SampleRate ) ) {
if ( File->openRead( Filename, SamplesCount, ChannelCount, SampleRate ) ) {
File->mFilename = Filename;
File->mData = NULL;
File->mSize = 0;
@@ -48,13 +48,13 @@ SoundFile * SoundFile::CreateRead( const std::string& Filename ) {
return File;
}
SoundFile * SoundFile::CreateRead( const char* Data, std::size_t SizeInMemory ) {
SoundFile * SoundFile::createRead( const char* Data, std::size_t SizeInMemory ) {
// Create the file according to its type
SoundFile * File = NULL;
if ( SoundFileOgg::IsFileSupported( Data, SizeInMemory ) ) File = eeNew( SoundFileOgg, () );
if ( SoundFileOgg::isFileSupported( Data, SizeInMemory ) ) File = eeNew( SoundFileOgg, () );
#ifdef EE_LIBSNDFILE_ENABLED
else if ( SoundFileDefault::IsFileSupported( Data, SizeInMemory ) ) File = eeNew( SoundFileDefault, () );
else if ( SoundFileDefault::isFileSupported( Data, SizeInMemory ) ) File = eeNew( SoundFileDefault, () );
#endif
// Open it for reading
@@ -63,7 +63,7 @@ SoundFile * SoundFile::CreateRead( const char* Data, std::size_t SizeInMemory )
unsigned int ChannelCount;
unsigned int SampleRate;
if ( File->OpenRead( Data, SizeInMemory, SamplesCount, ChannelCount, SampleRate ) ) {
if ( File->openRead( Data, SizeInMemory, SamplesCount, ChannelCount, SampleRate ) ) {
File->mFilename = "";
File->mData = Data;
File->mSize = SizeInMemory;
@@ -79,18 +79,18 @@ SoundFile * SoundFile::CreateRead( const char* Data, std::size_t SizeInMemory )
return File;
}
SoundFile * SoundFile::CreateWrite( const std::string& Filename, unsigned int ChannelCount, unsigned int SampleRate ) {
SoundFile * SoundFile::createWrite( const std::string& Filename, unsigned int ChannelCount, unsigned int SampleRate ) {
// Create the file according to its type
SoundFile * File = NULL;
if ( SoundFileOgg::IsFileSupported( Filename, false ) ) File = eeNew( SoundFileOgg, () );
if ( SoundFileOgg::isFileSupported( Filename, false ) ) File = eeNew( SoundFileOgg, () );
#ifdef EE_LIBSNDFILE_ENABLED
else if ( SoundFileDefault::IsFileSupported( Filename, false ) ) File = eeNew( SoundFileDefault, () );
else if ( SoundFileDefault::isFileSupported( Filename, false ) ) File = eeNew( SoundFileDefault, () );
#endif
// Open it for writing
if ( NULL != File ) {
if ( File->OpenWrite( Filename, ChannelCount, SampleRate ) ) {
if ( File->openWrite( Filename, ChannelCount, SampleRate ) ) {
File->mFilename = "";
File->mData = NULL;
File->mSize = 0;
@@ -106,57 +106,57 @@ SoundFile * SoundFile::CreateWrite( const std::string& Filename, unsigned int Ch
return File;
}
std::size_t SoundFile::GetSamplesCount() const
std::size_t SoundFile::getSamplesCount() const
{
return mSamplesCount;
}
unsigned int SoundFile::GetChannelCount() const {
unsigned int SoundFile::getChannelCount() const {
return mChannelCount;
}
unsigned int SoundFile::GetSampleRate() const {
unsigned int SoundFile::getSampleRate() const {
return mSampleRate;
}
bool SoundFile::Restart() {
bool SoundFile::restart() {
if ( mData ) {
// Reopen from memory
return OpenRead( mData, mSize, mSamplesCount, mChannelCount, mSampleRate );
return openRead( mData, mSize, mSamplesCount, mChannelCount, mSampleRate );
} else if ( mFilename != "" ) {
// Reopen from file
return OpenRead( mFilename, mSamplesCount, mChannelCount, mSampleRate );
return openRead( mFilename, mSamplesCount, mChannelCount, mSampleRate );
} else {
eePRINTL( "Warning : trying to restart a sound opened in write mode, which is not allowed" );
return false;
}
}
bool SoundFile::OpenRead(const std::string& Filename, std::size_t&, unsigned int&, unsigned int&) {
bool SoundFile::openRead(const std::string& Filename, std::size_t&, unsigned int&, unsigned int&) {
eePRINTL( "Failed to open sound file %s, format is not supported by eepp", Filename.c_str() );
return false;
}
bool SoundFile::OpenRead(const char*, std::size_t, std::size_t&, unsigned int&, unsigned int&) {
bool SoundFile::openRead(const char*, std::size_t, std::size_t&, unsigned int&, unsigned int&) {
eePRINTL( "Failed to open sound file from memory, format is not supported by eepp" );
return false;
}
bool SoundFile::OpenWrite(const std::string& Filename, unsigned int, unsigned int) {
bool SoundFile::openWrite(const std::string& Filename, unsigned int, unsigned int) {
eePRINTL( "Failed to open sound file %s, format is not supported by eepp", Filename.c_str() );
return false;
}
std::size_t SoundFile::Read(Int16*, std::size_t) {
std::size_t SoundFile::read(Int16*, std::size_t) {
eePRINTL( "Failed to read from sound file (not supported)" );
return 0;
}
void SoundFile::Write(const Int16*, std::size_t) {
void SoundFile::write(const Int16*, std::size_t) {
eePRINTL( "Failed to write to sound file (not supported)" );
}
void SoundFile::Seek( Time timeOffset ) {
void SoundFile::seek( Time timeOffset ) {
eePRINTL( "Trying to seek a file that doesn't support seeking." );
}

View File

@@ -9,54 +9,54 @@ namespace EE { namespace Audio {
class EE_API SoundFile {
public:
/** @brief Open a sound file for reading */
static SoundFile * CreateRead(const std::string& Filename);
static SoundFile * createRead(const std::string& Filename);
/** @brief Open a sound file from memory for reading */
static SoundFile * CreateRead(const char* Data, std::size_t SizeInBytes);
static SoundFile * createRead(const char* Data, std::size_t SizeInBytes);
/** @brief Open a sound file for writing */
static SoundFile * CreateWrite(const std::string& Filename, unsigned int ChannelCount, unsigned int SampleRate);
static SoundFile * createWrite(const std::string& Filename, unsigned int ChannelCount, unsigned int SampleRate);
virtual ~SoundFile();
/** @brief Get the total number of audio samples in the file */
std::size_t GetSamplesCount() const;
std::size_t getSamplesCount() const;
/** @brief Get the number of channels used by the sound
* @return Number of channels (1 = mono, 2 = stereo)
*/
unsigned int GetChannelCount() const;
unsigned int getChannelCount() const;
/** @brief Get the sample rate of the sound
* @return Sample rate, in samples per second
*/
unsigned int GetSampleRate() const;
unsigned int getSampleRate() const;
/** @brief Restarts the audio from the beginning. */
bool Restart();
bool restart();
/** @brief Read audio samples from the loaded sound
** @param data Pointer to the sample array to fill
** @param sampleCount Number of samples to read
** @return Number of samples actually read (may be less than \a sampleCount) */
virtual std::size_t Read(Int16* Data, std::size_t SamplesCount);
virtual std::size_t read(Int16* Data, std::size_t SamplesCount);
/** @brief Write audio samples to the file
** @param data Pointer to the sample array to write
** @param sampleCount Number of samples to write */
virtual void Write(const Int16* Data, std::size_t SamplesCount);
virtual void write(const Int16* Data, std::size_t SamplesCount);
/** @brief Change the current read position in the file
** @param timeOffset New playing position, from the beginning of the file */
virtual void Seek( Time timeOffset );
virtual void seek( Time timeOffset );
protected :
SoundFile();
virtual bool OpenRead(const std::string& Filename, std::size_t& SamplesCount, unsigned int& ChannelCount, unsigned int& SampleRate);
virtual bool openRead(const std::string& Filename, std::size_t& SamplesCount, unsigned int& ChannelCount, unsigned int& SampleRate);
virtual bool OpenRead(const char* Data, std::size_t SizeInBytes, std::size_t& SamplesCount, unsigned int& ChannelCount, unsigned int& SampleRate);
virtual bool openRead(const char* Data, std::size_t SizeInBytes, std::size_t& SamplesCount, unsigned int& ChannelCount, unsigned int& SampleRate);
virtual bool OpenWrite(const std::string& Filename, unsigned int ChannelCount, unsigned int SampleRate);
virtual bool openWrite(const std::string& Filename, unsigned int ChannelCount, unsigned int SampleRate);
std::size_t mSamplesCount;
unsigned int mChannelCount;

View File

@@ -14,7 +14,7 @@ SoundFileDefault::~SoundFileDefault() {
sf_close( mFile );
}
bool SoundFileDefault::IsFileSupported( const std::string& Filename, bool Read ) {
bool SoundFileDefault::isFileSupported( const std::string& Filename, bool Read ) {
if ( Read ) {
// Open the sound file
SF_INFO fileInfos;
@@ -29,14 +29,14 @@ bool SoundFileDefault::IsFileSupported( const std::string& Filename, bool Read )
return false;
} else {
// Check the extension
return GetFormatFromFilename(Filename) != -1;
return getFormatFromFilename(Filename) != -1;
}
}
bool SoundFileDefault::IsFileSupported( const char* Data, std::size_t SizeInBytes ) {
bool SoundFileDefault::isFileSupported( const char* Data, std::size_t SizeInBytes ) {
// Define the I/O custom functions for reading from memory
MemoryIO tMemoryIO;
SF_VIRTUAL_IO io = tMemoryIO.Prepare( Data, SizeInBytes );
SF_VIRTUAL_IO io = tMemoryIO.prepare( Data, SizeInBytes );
// Open the sound file
SF_INFO fileInfos;
@@ -51,7 +51,7 @@ bool SoundFileDefault::IsFileSupported( const char* Data, std::size_t SizeInByte
return false;
}
bool SoundFileDefault::OpenRead( const std::string& Filename, std::size_t& SamplesCount, unsigned int& ChannelCount, unsigned int& SampleRate ) {
bool SoundFileDefault::openRead( const std::string& Filename, std::size_t& SamplesCount, unsigned int& ChannelCount, unsigned int& SampleRate ) {
// If the file is already opened, first close it
if ( NULL != mFile )
sf_close( mFile );
@@ -78,13 +78,13 @@ bool SoundFileDefault::OpenRead( const std::string& Filename, std::size_t& Sampl
return true;
}
bool SoundFileDefault::OpenRead( const char* Data, std::size_t SizeInBytes, std::size_t& SamplesCount, unsigned int& ChannelCount, unsigned int& SampleRate ) {
bool SoundFileDefault::openRead( const char* Data, std::size_t SizeInBytes, std::size_t& SamplesCount, unsigned int& ChannelCount, unsigned int& SampleRate ) {
// If the file is already opened, first close it
if ( NULL != mFile )
sf_close( mFile );
// Prepare the memory I/O structure
SF_VIRTUAL_IO io = mMemoryIO.Prepare( Data, SizeInBytes );
SF_VIRTUAL_IO io = mMemoryIO.prepare( Data, SizeInBytes );
// Open the sound file
SF_INFO fileInfos;
@@ -108,13 +108,13 @@ bool SoundFileDefault::OpenRead( const char* Data, std::size_t SizeInBytes, std:
return true;
}
bool SoundFileDefault::OpenWrite( const std::string& Filename, unsigned int ChannelCount, unsigned int SampleRate ) {
bool SoundFileDefault::openWrite( const std::string& Filename, unsigned int ChannelCount, unsigned int SampleRate ) {
// If the file is already opened, first close it
if ( NULL != mFile )
sf_close( mFile );
// Find the right format according to the file extension
int Format = GetFormatFromFilename( Filename );
int Format = getFormatFromFilename( Filename );
if (Format == -1) {
// Error : unrecognized extension
eePRINTL( "Failed to create sound file %s : unknown format", Filename.c_str() );
@@ -138,26 +138,26 @@ bool SoundFileDefault::OpenWrite( const std::string& Filename, unsigned int Chan
return true;
}
std::size_t SoundFileDefault::Read( Int16 * Data, std::size_t SamplesCount ) {
std::size_t SoundFileDefault::read( Int16 * Data, std::size_t SamplesCount ) {
if ( NULL != mFile && Data && SamplesCount )
return static_cast<std::size_t>( sf_read_short( mFile, Data, SamplesCount ) );
else
return 0;
}
void SoundFileDefault::Write( const Int16 * Data, std::size_t SamplesCount ) {
void SoundFileDefault::write( const Int16 * Data, std::size_t SamplesCount ) {
if ( NULL != mFile && Data && SamplesCount )
sf_write_short( mFile, Data, SamplesCount );
}
void SoundFileDefault::Seek( Time timeOffset ) {
void SoundFileDefault::seek( Time timeOffset ) {
if ( NULL != mFile ) {
sf_count_t frameOffset = static_cast<sf_count_t>( timeOffset.AsSeconds() * mSampleRate / 1000 );
sf_seek( mFile, frameOffset, SEEK_SET );
}
}
int SoundFileDefault::GetFormatFromFilename(const std::string& Filename) {
int SoundFileDefault::getFormatFromFilename(const std::string& Filename) {
// Extract the extension
std::string ext = "wav";
std::string::size_type Pos = Filename.find_last_of(".");
@@ -194,14 +194,14 @@ int SoundFileDefault::GetFormatFromFilename(const std::string& Filename) {
return -1;
}
SF_VIRTUAL_IO SoundFileDefault::MemoryIO::Prepare( const void * data, std::size_t sizeInBytes ) {
SF_VIRTUAL_IO SoundFileDefault::MemoryIO::prepare( const void * data, std::size_t sizeInBytes ) {
// Setup the I/O functions
SF_VIRTUAL_IO io;
io.get_filelen = &SoundFileDefault::MemoryIO::GetLength;
io.read = &SoundFileDefault::MemoryIO::Read;
io.seek = &SoundFileDefault::MemoryIO::Seek;
io.tell = &SoundFileDefault::MemoryIO::Tell;
io.write = &SoundFileDefault::MemoryIO::Write;
io.get_filelen = &SoundFileDefault::MemoryIO::getLength;
io.read = &SoundFileDefault::MemoryIO::read;
io.seek = &SoundFileDefault::MemoryIO::seek;
io.tell = &SoundFileDefault::MemoryIO::tell;
io.write = &SoundFileDefault::MemoryIO::write;
// Initialize the memory data
mDataStart = static_cast<const char*>(data);
@@ -211,13 +211,13 @@ SF_VIRTUAL_IO SoundFileDefault::MemoryIO::Prepare( const void * data, std::size_
return io;
}
sf_count_t SoundFileDefault::MemoryIO::GetLength( void* UserData ) {
sf_count_t SoundFileDefault::MemoryIO::getLength( void* UserData ) {
MemoryIO * self = static_cast<MemoryIO*>(UserData);
return self->mTotalSize;
}
sf_count_t SoundFileDefault::MemoryIO::Read( void* Ptr, sf_count_t Count, void* UserData ) {
sf_count_t SoundFileDefault::MemoryIO::read( void* Ptr, sf_count_t Count, void* UserData ) {
MemoryIO * self = static_cast<MemoryIO*>(UserData);
sf_count_t Position = self->mDataPtr - self->mDataStart;
@@ -232,7 +232,7 @@ sf_count_t SoundFileDefault::MemoryIO::Read( void* Ptr, sf_count_t Count, void*
return Count;
}
sf_count_t SoundFileDefault::MemoryIO::Seek( sf_count_t Offset, int Whence, void* UserData ) {
sf_count_t SoundFileDefault::MemoryIO::seek( sf_count_t Offset, int Whence, void* UserData ) {
MemoryIO * self = static_cast<MemoryIO*>(UserData);
sf_count_t Position = 0;
@@ -262,13 +262,13 @@ sf_count_t SoundFileDefault::MemoryIO::Seek( sf_count_t Offset, int Whence, void
return Position;
}
sf_count_t SoundFileDefault::MemoryIO::Tell( void* UserData ) {
sf_count_t SoundFileDefault::MemoryIO::tell( void* UserData ) {
MemoryIO * self = static_cast<MemoryIO*>(UserData);
return self->mDataPtr - self->mDataStart;
}
sf_count_t SoundFileDefault::MemoryIO::Write( const void*, sf_count_t, void* ) {
sf_count_t SoundFileDefault::MemoryIO::write( const void*, sf_count_t, void* ) {
return 0;
}

View File

@@ -17,34 +17,34 @@ class EE_API SoundFileDefault : public SoundFile {
~SoundFileDefault();
/** Check if a given file is supported by this loader. */
static bool IsFileSupported(const std::string& Filename, bool Read);
static bool isFileSupported(const std::string& Filename, bool read);
/** Check if a given file in memory is supported by this loader. */
static bool IsFileSupported(const char* Data, std::size_t SizeInBytes);
static bool isFileSupported(const char* Data, std::size_t SizeInBytes);
virtual std::size_t Read(Int16* Data, std::size_t SamplesCount);
virtual std::size_t read(Int16* Data, std::size_t SamplesCount);
virtual void Write(const Int16* Data, std::size_t SamplesCount);
virtual void write(const Int16* Data, std::size_t SamplesCount);
virtual void Seek( Time timeOffset );
virtual void seek( Time timeOffset );
private :
virtual bool OpenRead( const std::string& Filename, std::size_t& SamplesCount, unsigned int& ChannelCount, unsigned int& SampleRate );
virtual bool openRead( const std::string& Filename, std::size_t& SamplesCount, unsigned int& ChannelCount, unsigned int& SampleRate );
virtual bool OpenRead( const char* Data, std::size_t SizeInBytes, std::size_t& SamplesCount, unsigned int& ChannelCount, unsigned int& SampleRate );
virtual bool openRead( const char* Data, std::size_t SizeInBytes, std::size_t& SamplesCount, unsigned int& ChannelCount, unsigned int& SampleRate );
virtual bool OpenWrite( const std::string& Filename, unsigned int ChannelCount, unsigned int SampleRate );
virtual bool openWrite( const std::string& Filename, unsigned int ChannelCount, unsigned int SampleRate );
static int GetFormatFromFilename(const std::string& Filename);
static int getFormatFromFilename(const std::string& Filename);
class MemoryIO {
public:
SF_VIRTUAL_IO Prepare(const void* data, std::size_t sizeInBytes);
SF_VIRTUAL_IO prepare(const void* data, std::size_t sizeInBytes);
private:
static sf_count_t GetLength(void* UserData);
static sf_count_t Read(void* Ptr, sf_count_t Count, void* UserData);
static sf_count_t Seek(sf_count_t Offset, int Whence, void* UserData);
static sf_count_t Tell(void* UserData);
static sf_count_t Write(const void* Ptr, sf_count_t Count, void* UserData);
static sf_count_t getLength(void* UserData);
static sf_count_t read(void* Ptr, sf_count_t Count, void* UserData);
static sf_count_t seek(sf_count_t Offset, int Whence, void* UserData);
static sf_count_t tell(void* UserData);
static sf_count_t write(const void* Ptr, sf_count_t Count, void* UserData);
const char * mDataStart; ///< Pointer to the begining of the data
const char * mDataPtr; ///< Pointer to the current read / write position

View File

@@ -14,7 +14,7 @@ SoundFileOgg::~SoundFileOgg() {
stb_vorbis_close( mStream );
}
bool SoundFileOgg::IsFileSupported( const std::string& Filename, bool Read ) {
bool SoundFileOgg::isFileSupported( const std::string& Filename, bool Read ) {
if ( Read ) {
// Open the vorbis stream
stb_vorbis* Stream = stb_vorbis_open_filename( const_cast<char*>( Filename.c_str() ), NULL, NULL );
@@ -28,7 +28,7 @@ bool SoundFileOgg::IsFileSupported( const std::string& Filename, bool Read ) {
return false;
}
bool SoundFileOgg::IsFileSupported( const char* Data, std::size_t SizeInBytes ) {
bool SoundFileOgg::isFileSupported( const char* Data, std::size_t SizeInBytes ) {
// Open the vorbis stream
unsigned char* Buffer = reinterpret_cast<unsigned char*>( const_cast<char*>( Data ) );
int Length = static_cast<int>( SizeInBytes );
@@ -42,7 +42,7 @@ bool SoundFileOgg::IsFileSupported( const char* Data, std::size_t SizeInBytes )
return false;
}
bool SoundFileOgg::OpenRead( const std::string& Filename, std::size_t& SamplesCount, unsigned int& ChannelCount, unsigned int& SampleRate ) {
bool SoundFileOgg::openRead( const std::string& Filename, std::size_t& SamplesCount, unsigned int& ChannelCount, unsigned int& SampleRate ) {
// Close the file if already opened
if ( NULL != mStream )
stb_vorbis_close( mStream );
@@ -64,7 +64,7 @@ bool SoundFileOgg::OpenRead( const std::string& Filename, std::size_t& SamplesCo
return true;
}
bool SoundFileOgg::OpenRead( const char* Data, std::size_t SizeInBytes, std::size_t& SamplesCount, unsigned int& ChannelCount, unsigned int& SampleRate ) {
bool SoundFileOgg::openRead( const char* Data, std::size_t SizeInBytes, std::size_t& SamplesCount, unsigned int& ChannelCount, unsigned int& SampleRate ) {
// Close the file if already opened
if ( NULL != mStream )
stb_vorbis_close( mStream );
@@ -89,7 +89,7 @@ bool SoundFileOgg::OpenRead( const char* Data, std::size_t SizeInBytes, std::siz
return true;
}
std::size_t SoundFileOgg::Read( Int16 * Data, std::size_t SamplesCount ) {
std::size_t SoundFileOgg::read( Int16 * Data, std::size_t SamplesCount ) {
if ( NULL != mStream && Data && SamplesCount ) {
int Read = stb_vorbis_get_samples_short_interleaved( mStream, mChannelCount, Data, static_cast<int>( SamplesCount ) );
@@ -101,7 +101,7 @@ std::size_t SoundFileOgg::Read( Int16 * Data, std::size_t SamplesCount ) {
return 0;
}
void SoundFileOgg::Seek( Time timeOffset ) {
void SoundFileOgg::seek( Time timeOffset ) {
if ( NULL != mStream ) {
Uint32 frameOffset = static_cast<Uint32>( timeOffset.asSeconds() * mSampleRate / 1000 );
stb_vorbis_seek( mStream, frameOffset );

View File

@@ -14,18 +14,18 @@ class EE_API SoundFileOgg : public SoundFile {
~SoundFileOgg();
/** Check if a given file is supported by this loader. */
static bool IsFileSupported(const std::string& Filename, bool Read);
static bool isFileSupported(const std::string& Filename, bool read);
/** Check if a given file in memory is supported by this loader. */
static bool IsFileSupported(const char* Data, std::size_t SizeInBytes);
static bool isFileSupported(const char* Data, std::size_t SizeInBytes);
virtual std::size_t Read(Int16* Data, std::size_t SamplesCount);
virtual std::size_t read(Int16* Data, std::size_t SamplesCount);
virtual void Seek( Time timeOffset );
virtual void seek( Time timeOffset );
private :
virtual bool OpenRead(const std::string& Filename, std::size_t& SamplesCount, unsigned int& ChannelCount, unsigned int& SampleRate);
virtual bool openRead(const std::string& Filename, std::size_t& SamplesCount, unsigned int& ChannelCount, unsigned int& SampleRate);
virtual bool OpenRead(const char* Data, std::size_t SizeInBytes, std::size_t& SamplesCount, unsigned int& ChannelCount, unsigned int& SampleRate);
virtual bool openRead(const char* Data, std::size_t SizeInBytes, std::size_t& SamplesCount, unsigned int& ChannelCount, unsigned int& SampleRate);
stb_vorbis * mStream; ///< Vorbis stream
unsigned int mChannelCount; ///< Number of channels (1 = mono, 2 = stereo)

View File

@@ -17,15 +17,15 @@ SoundStream::SoundStream() :
}
SoundStream::~SoundStream() {
Stop(); // Stop the sound if it was playing
stop(); // Stop the sound if it was playing
}
void SoundStream::Initialize(unsigned int ChannelCount, unsigned int SampleRate) {
void SoundStream::initialize(unsigned int ChannelCount, unsigned int SampleRate) {
mChannelCount = ChannelCount;
mSampleRate = SampleRate;
// Deduce the format from the number of channels
mFormat = AudioDevice::GetFormatFromChannelCount(ChannelCount);
mFormat = AudioDevice::getFormatFromChannelCount(ChannelCount);
if ( mFormat == 0 ) { // Check if the format is valid
mChannelCount = 0;
@@ -34,43 +34,43 @@ void SoundStream::Initialize(unsigned int ChannelCount, unsigned int SampleRate)
}
}
void SoundStream::Play() {
void SoundStream::play() {
if ( mFormat == 0 ) { // Check if the sound parameters have been set
eePRINTL( "Failed to play audio stream : sound parameters have not been initialized (call Initialize first)." );
return;
}
if ( mIsStreaming ) { // If the sound is already playing (probably paused), just resume it
Sound::Play();
Sound::play();
return;
}
OnSeek( Time::Zero );
onSeek( Time::Zero );
mSamplesProcessed = 0;
mIsStreaming = true; // Start updating the stream in a separate thread to avoid blocking the application
launch();
}
void SoundStream::Pause() {
void SoundStream::pause() {
ALCheck( alSourcePause( mSource ) );
}
void SoundStream::Stop() {
void SoundStream::stop() {
mIsStreaming = false; // Wait for the thread to terminate
wait();
}
unsigned int SoundStream::GetChannelCount() const {
unsigned int SoundStream::getChannelCount() const {
return mChannelCount;
}
unsigned int SoundStream::GetSampleRate() const {
unsigned int SoundStream::getSampleRate() const {
return mSampleRate;
}
Sound::Status SoundStream::GetState() const {
Status status = Sound::GetState();
Sound::Status SoundStream::getState() const {
Status status = Sound::getState();
if ( ( status == Sound::Stopped ) && mIsStreaming ) // To compensate for the lag between Play() and alSourcePlay()
status = Sound::Playing;
@@ -78,7 +78,7 @@ Sound::Status SoundStream::GetState() const {
return status;
}
Time SoundStream::PlayingOffset() const {
Time SoundStream::playingOffset() const {
if ( mSampleRate && mChannelCount ) {
float secs = 0.f;
@@ -90,14 +90,14 @@ Time SoundStream::PlayingOffset() const {
return Time::Zero;
}
void SoundStream::PlayingOffset( const Time &timeOffset ) {
Status oldStatus = State();
void SoundStream::playingOffset( const Time &timeOffset ) {
Status oldStatus = state();
// Stop the stream
Stop();
stop();
// Let the derived class update the current position
OnSeek( timeOffset );
onSeek( timeOffset );
// Restart streaming
mSamplesProcessed = static_cast<Uint32>( timeOffset.asSeconds() ) * mSampleRate * mChannelCount;
@@ -108,17 +108,17 @@ void SoundStream::PlayingOffset( const Time &timeOffset ) {
// Recover old status
if ( oldStatus == Stopped ) {
Stop();
stop();
} else if ( oldStatus == Paused ) {
Pause();
pause();
}
}
void SoundStream::Loop( const bool& Loop ) {
void SoundStream::loop( const bool& Loop ) {
mLoop = Loop;
}
bool SoundStream::Loop() const {
bool SoundStream::loop() const {
return mLoop;
}
@@ -129,16 +129,16 @@ void SoundStream::run() {
mEndBuffers[i] = false;
// Fill the queue
bool RequestStop = FillQueue();
bool RequestStop = fillQueue();
Sound::Play();
Sound::play();
while ( mIsStreaming ) {
// The stream has been interrupted !
if ( Sound::GetState() == Sound::Stopped ) {
if ( Sound::getState() == Sound::Stopped ) {
// User requested to stop : finish the streaming loop
if ( !RequestStop ) {
Sound::Play();
Sound::play();
} else {
// Streaming is not completed : restart the sound
mIsStreaming = false;
@@ -177,45 +177,45 @@ void SoundStream::run() {
// Fill it and push it back into the playing queue
if ( !RequestStop ) {
if ( FillAndPushBuffer( bufferNum ) )
if ( fillAndPushBuffer( bufferNum ) )
RequestStop = true;
}
}
// Leave some time for the other threads if the stream is still playing
if ( Sound::GetState() != Sound::Stopped )
if ( Sound::getState() != Sound::Stopped )
Sys::sleep(10);
}
// Stop the playback
Sound::Stop();
Sound::stop();
// Unqueue any buffer left in the queue
ClearQueue();
clearQueue();
// Delete the buffers
ALCheck( alSourcei( Sound::mSource, AL_BUFFER, 0 ) );
ALCheck( alDeleteBuffers( BuffersCount, mBuffers ) );
}
bool SoundStream::FillAndPushBuffer( const unsigned int& Buffer ) {
bool SoundStream::fillAndPushBuffer( const unsigned int& Buffer ) {
bool RequestStop = false;
// Acquire audio data
Chunk Data = {NULL, 0};
if ( !OnGetData( Data ) ) {
if ( !onGetData( Data ) ) {
// Mark the buffer as the last one (so that we know when to reset the playing position)
mEndBuffers[ Buffer ] = true;
// Check if the stream must loop or stop
if ( mLoop ) {
// Return to the beginning of the stream source
OnSeek( Time::Zero );
onSeek( Time::Zero );
// If we previously had no data, try to fill the buffer once again
if ( !Data.Samples || ( Data.SamplesCount == 0 ) ) {
return FillAndPushBuffer( Buffer );
return fillAndPushBuffer( Buffer );
}
} else {
// Not looping: request stop
@@ -239,19 +239,19 @@ bool SoundStream::FillAndPushBuffer( const unsigned int& Buffer ) {
return RequestStop;
}
bool SoundStream::FillQueue() {
bool SoundStream::fillQueue() {
// Fill and enqueue all the available buffers
bool RequestStop = false;
for ( int i = 0; (i < BuffersCount) && !RequestStop; ++i ) {
if ( FillAndPushBuffer( i ) )
if ( fillAndPushBuffer( i ) )
RequestStop = true;
}
return RequestStop;
}
void SoundStream::ClearQueue() {
void SoundStream::clearQueue() {
// Get the number of buffers still in the queue
ALint NbQueued;
ALCheck( alGetSourcei( Sound::mSource, AL_BUFFERS_QUEUED, &NbQueued ) );
@@ -262,8 +262,8 @@ void SoundStream::ClearQueue() {
ALCheck( alSourceUnqueueBuffers( Sound::mSource, 1, &Buffer ) );
}
Sound::Status SoundStream::State() const {
return GetState();
Sound::Status SoundStream::state() const {
return getState();
}
}}

View File

@@ -802,7 +802,7 @@ void Console::CmdSetVolume( const std::vector < String >& params ) {
bool Res = String::fromString<Float>( tFloat, params[1] );
if ( Res && ( tFloat >= 0.0f && tFloat <= 100.0f ) ) {
EE::Audio::AudioListener::GlobalVolume( tFloat );
EE::Audio::AudioListener::globalVolume( tFloat );
return;
}
}

View File

@@ -9,18 +9,18 @@ void PlaySound() {
// It manages the sound playing, if the sound channel is already playing, it will open a new channel to play the sound
SoundManager SoundManager;
if ( SoundManager.LoadFromFile( "sound", AppPath + "assets/sounds/sound.ogg" ) ) {
if ( SoundManager.loadFromFile( "sound", AppPath + "assets/sounds/sound.ogg" ) ) {
// Get the sound buffer to display the buffer information
SoundBuffer& buffer = SoundManager.GetBuffer( "sound" );
SoundBuffer& buffer = SoundManager.getBuffer( "sound" );
// Display sound informations
std::cout << "sound.ogg :" << std::endl;
std::cout << " " << buffer.GetDuration().asSeconds() << " seconds" << std::endl;
std::cout << " " << buffer.GetSampleRate() << " samples / sec" << std::endl;
std::cout << " " << buffer.GetChannelCount() << " channels" << std::endl;
std::cout << " " << buffer.getDuration().asSeconds() << " seconds" << std::endl;
std::cout << " " << buffer.getSampleRate() << " samples / sec" << std::endl;
std::cout << " " << buffer.getChannelCount() << " channels" << std::endl;
// Play the sound
SoundManager.Play( "sound" );
SoundManager.play( "sound" );
}
}
@@ -29,25 +29,25 @@ void PlayMusic() {
// Load an ogg music file
Music music;
if (!music.OpenFromFile( AppPath + "assets/sounds/music.ogg" ) )
if (!music.openFromFile( AppPath + "assets/sounds/music.ogg" ) )
return;
// Display music informations
std::cout << "music.ogg :" << std::endl;
std::cout << " " << music.GetDuration().asSeconds() << " seconds" << std::endl;
std::cout << " " << music.GetSampleRate() << " samples / sec" << std::endl;
std::cout << " " << music.GetChannelCount() << " channels" << std::endl;
std::cout << " " << music.getDuration().asSeconds() << " seconds" << std::endl;
std::cout << " " << music.getSampleRate() << " samples / sec" << std::endl;
std::cout << " " << music.getChannelCount() << " channels" << std::endl;
// Play it
music.Play();
music.play();
// Loop while the music is playing
while ( music.State() == Sound::Playing ) {
while ( music.state() == Sound::Playing ) {
// Leave some CPU time for other processes
Sys::sleep( 100 );
// Display the playing position
std::cout << "\rPlaying... " << music.PlayingOffset().asSeconds() << " sec ";
std::cout << "\rPlaying... " << music.playingOffset().asSeconds() << " sec ";
std::cout << std::flush;
}

View File

@@ -93,9 +93,9 @@ void EETest::Init() {
if ( mMusEnabled ) {
Mus = eeNew( Music, () );
if ( Mus->OpenFromFile( MyPath + "sounds/music.ogg" ) ) {
Mus->Loop( true );
Mus->Play();
if ( Mus->openFromFile( MyPath + "sounds/music.ogg" ) ) {
Mus->loop( true );
Mus->play();
}
}
@@ -805,7 +805,7 @@ void EETest::CmdSetPartsNum ( const std::vector < String >& params ) {
}
void EETest::OnTextureLoaded( ResourceLoader * ResLoaded ) {
SndMng.Play( "mysound" );
SndMng.play( "mysound" );
}
void EETest::LoadTextures() {
@@ -1300,8 +1300,8 @@ void EETest::Input() {
mWindow->FrameRateLimit( 10 );
if ( mMusEnabled && Mus->State() == Sound::Playing )
Mus->Pause();
if ( mMusEnabled && Mus->state() == Sound::Playing )
Mus->pause();
} else {
if ( mLastFPSLimit != mWindow->FrameRateLimit() && !mWasMinimized )
@@ -1316,8 +1316,8 @@ void EETest::Input() {
mWindow->FrameRateLimit( mLastFPSLimit );
if ( mMusEnabled && Mus->State() == Sound::Paused )
Mus->Play();
if ( mMusEnabled && Mus->state() == Sound::Paused )
Mus->play();
}
if ( KM->IsKeyDown( KEY_ESCAPE ) )
@@ -1488,7 +1488,7 @@ void EETest::Input() {
DrawBack = false;
if ( KM->IsKeyUp( KEY_P ) )
SndMng.Play( "mysound" );
SndMng.play( "mysound" );
if ( KM->ControlPressed() && KM->IsKeyUp(KEY_P) ) {
ShowParticles = !ShowParticles;