Audio Module refactored.

This commit is contained in:
Martín Lucas Golini
2014-06-14 02:56:58 -03:00
parent f9455c7556
commit e71d79ccd8
28 changed files with 314 additions and 314 deletions

View File

@@ -1,13 +1,13 @@
#ifndef EEPP_AUDIO_HPP
#define EEPP_AUDIO_HPP
#include <eepp/audio/caudiodevice.hpp>
#include <eepp/audio/caudiolistener.hpp>
#include <eepp/audio/csound.hpp>
#include <eepp/audio/csoundbuffer.hpp>
#include <eepp/audio/csoundstream.hpp>
#include <eepp/audio/cmusic.hpp>
#include <eepp/audio/tsoundloader.hpp>
#include <eepp/audio/tsoundmanager.hpp>
#include <eepp/audio/audiodevice.hpp>
#include <eepp/audio/audiolistener.hpp>
#include <eepp/audio/sound.hpp>
#include <eepp/audio/soundbuffer.hpp>
#include <eepp/audio/soundstream.hpp>
#include <eepp/audio/music.hpp>
#include <eepp/audio/soundloader.hpp>
#include <eepp/audio/soundmanager.hpp>
#endif

View File

@@ -1,7 +1,7 @@
#ifndef EE_AUDIOCAUDIODEVICE_H
#define EE_AUDIOCAUDIODEVICE_H
#include <eepp/audio/caudiolistener.hpp>
#include <eepp/audio/audiolistener.hpp>
namespace EE { namespace Audio {
@@ -10,11 +10,11 @@ namespace EE { namespace Audio {
the creation and destruction of the audio device and
context and stores the device capabilities
*/
class EE_API cAudioDevice {
class EE_API AudioDevice {
public :
cAudioDevice();
AudioDevice();
~cAudioDevice();
~AudioDevice();
/** Get the OpenAL format that matches the given number of channels */
static int GetFormatFromChannelCount( unsigned int ChannelCount );

View File

@@ -6,7 +6,7 @@
namespace EE { namespace Audio {
/** @brief Listener is a global interface for defining the audio listener properties. */
class EE_API cAudioListener {
class EE_API AudioListener {
public:
/** Change the global volume of all the sounds. ( default 100 )
* @param Volume New global volume, in the range [0, 100]

View File

@@ -2,19 +2,19 @@
#define EE_AUDIOCMUSIC_H
#include <eepp/audio/base.hpp>
#include <eepp/audio/csoundstream.hpp>
#include <eepp/audio/soundstream.hpp>
namespace EE { namespace Audio {
class cSoundFile;
class SoundFile;
/** @brief Streamed music played from an audio file */
class EE_API cMusic : public cSoundStream {
class EE_API Music : public SoundStream {
public :
/** Construct the music with a buffer size */
cMusic( std::size_t BufferSize = 48000 );
Music( std::size_t BufferSize = 48000 );
~cMusic();
~Music();
/** Open a Music file from a path */
bool OpenFromFile( const std::string& Filename );
@@ -34,7 +34,7 @@ class EE_API cMusic : public cSoundStream {
virtual void OnSeek( cTime timeOffset);
cSoundFile * mFile; ///< Sound file
SoundFile * mFile; ///< Sound file
float mDuration; ///< Music duration, in seconds
std::vector<Int16> mSamples; ///< Temporary buffer of samples
SafeDataPointer mData;

View File

@@ -2,13 +2,13 @@
#define EE_AUDIOCSOUND_H
#include <eepp/audio/base.hpp>
#include <eepp/audio/caudiolistener.hpp>
#include <eepp/audio/csoundbuffer.hpp>
#include <eepp/audio/audiolistener.hpp>
#include <eepp/audio/soundbuffer.hpp>
namespace EE { namespace Audio {
/** @brief Regular sound that can be played in the audio environment */
class EE_API cSound {
class EE_API Sound {
public :
/** @brief The state of the sound */
enum Status {
@@ -17,15 +17,15 @@ class EE_API cSound {
Playing
};
cSound();
Sound();
~cSound();
~Sound();
/** Construct the sound with a buffer. */
cSound( const cSoundBuffer& Buffer, const bool& Loop = false, const float& Pitch = 1.f, const float& Volume = 100.f, const eeVector3ff& Position = eeVector3ff(0, 0, 0) );
Sound( const SoundBuffer& Buffer, const bool& Loop = false, const float& Pitch = 1.f, const float& Volume = 100.f, const eeVector3ff& Position = eeVector3ff(0, 0, 0) );
/** Copy constructor */
cSound(const cSound& Copy);
Sound(const Sound& Copy);
/** Play the Sound */
void Play();
@@ -37,7 +37,7 @@ class EE_API cSound {
void Stop();
/** Set the Sound Source Buffer */
void Buffer( const cSoundBuffer& Buffer );
void Buffer( const SoundBuffer& Buffer );
/** Set the Sound Loop State */
void Loop( const bool& Loop );
@@ -61,7 +61,7 @@ class EE_API cSound {
void Attenuation( const float& Attenuation );
/** Get the Sound Source Buffer */
const cSoundBuffer* Buffer() const;
const SoundBuffer* Buffer() const;
/** Get the Sound Loop State */
bool Loop() const;
@@ -96,7 +96,7 @@ class EE_API cSound {
virtual void PlayingOffset( const cTime &TimeOffset );
/** Assignment operator */
cSound& operator =(const cSound& Other);
Sound& operator =(const Sound& Other);
/** 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
@@ -110,15 +110,15 @@ class EE_API cSound {
/** \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 cSoundBuffer that
* 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();
private :
friend class cSoundStream;
friend class SoundStream;
unsigned int mSource; ///< OpenAL source identifier
const cSoundBuffer * mBuffer; ///< Sound buffer bound to the source
const SoundBuffer * mBuffer; ///< Sound buffer bound to the source
};
}}

View File

@@ -6,17 +6,17 @@
namespace EE { namespace Audio {
class cSound;
class Sound;
/** @brief Storage for audio samples defining a sound */
class EE_API cSoundBuffer {
class EE_API SoundBuffer {
public :
cSoundBuffer();
SoundBuffer();
~cSoundBuffer();
~SoundBuffer();
/** Copy constructor */
cSoundBuffer(const cSoundBuffer& Copy);
SoundBuffer(const SoundBuffer& Copy);
/** Load the Sound Buffer from a file */
bool LoadFromFile( const std::string& Filename );
@@ -49,23 +49,23 @@ class EE_API cSoundBuffer {
cTime GetDuration() const;
/** Assignment operator */
cSoundBuffer& operator =(const cSoundBuffer& Other);
SoundBuffer& operator =(const SoundBuffer& Other);
private :
friend class cSound;
friend class Sound;
unsigned int mBuffer; ///< OpenAL buffer identifier
std::vector<Int16> mSamples; ///< Samples buffer
cTime mDuration; ///< Sound duration, in seconds
typedef std::set<cSound*> SoundList;
typedef std::set<Sound*> SoundList;
mutable SoundList mSounds;
/** Update the internal buffer with the audio samples */
bool Update( unsigned int ChannelCount, unsigned int SampleRate );
void AttachSound( cSound* sound ) const;
void AttachSound( Sound* sound ) const;
void DetachSound( cSound* sound ) const;
void DetachSound( Sound* sound ) const;
};

View File

@@ -2,7 +2,7 @@
#define EE_AUDIOTSOUNDLOADER_HPP
#include <eepp/audio/base.hpp>
#include <eepp/audio/tsoundmanager.hpp>
#include <eepp/audio/soundmanager.hpp>
#include <eepp/system/cobjectloader.hpp>
namespace EE { namespace Audio {
@@ -170,7 +170,7 @@ void tSoundLoader<T>::Unload() {
}
}
typedef tSoundLoader<std::string> cSoundLoader;
typedef tSoundLoader<std::string> SoundLoader;
}}

View File

@@ -2,8 +2,8 @@
#define EE_AUDIOTSOUNDMANAGER_H
#include <eepp/audio/base.hpp>
#include <eepp/audio/csound.hpp>
#include <eepp/audio/csoundbuffer.hpp>
#include <eepp/audio/sound.hpp>
#include <eepp/audio/soundbuffer.hpp>
namespace EE { namespace Audio {
@@ -38,7 +38,7 @@ class tSoundManager {
bool LoadFromPack( const T& id, cPack* Pack, const std::string& FilePackPath );
/** @return The sound buffer of the sound id */
cSoundBuffer& 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 */
@@ -49,17 +49,17 @@ class tSoundManager {
bool Remove( const T& id );
/** @return The sound id if exists */
cSound& operator[] ( const T& id );
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 */
cSound& GetFreeSound( const T& id );
Sound& GetFreeSound( const T& id );
~tSoundManager();
private:
typedef struct sSound {
cSoundBuffer Buf;
std::vector<cSound> Snd;
SoundBuffer Buf;
std::vector<Sound> Snd;
} sSound;
std::map<T, sSound> tSounds;
};
@@ -70,7 +70,7 @@ bool tSoundManager<T>::LoadFromPack( const T& id, cPack* Pack, const std::string
sSound * tSound = &tSounds[id];
if ( tSound->Buf.LoadFromPack( Pack, FilePackPath ) ) {
tSound->Snd.push_back( cSound( tSound->Buf ) );
tSound->Snd.push_back( Sound( tSound->Buf ) );
return true;
}
}
@@ -84,7 +84,7 @@ bool tSoundManager<T>::LoadFromFile( const T& id, const std::string& filepath )
sSound * tSound = &tSounds[id];
if ( tSound->Buf.LoadFromFile( filepath ) ) {
tSound->Snd.push_back( cSound( tSound->Buf ) );
tSound->Snd.push_back( Sound( tSound->Buf ) );
return true;
}
}
@@ -98,7 +98,7 @@ bool tSoundManager<T>::LoadFromMemory( const T& id, const char* Data, std::size_
sSound * tSound = &tSounds[id];
if ( tSound->Buf.LoadFromMemory( Data, SizeInBytes ) ) {
tSound->Snd.push_back( cSound( tSound->Buf ) );
tSound->Snd.push_back( Sound( tSound->Buf ) );
return true;
}
}
@@ -112,7 +112,7 @@ bool tSoundManager<T>::LoadFromSamples( const T& id, const Int16* Samples, std::
sSound * tSound = &tSounds[id];
if ( tSound->Buf.LoadFromSamples( Samples, SamplesCount, ChannelCount, SampleRate ) ) {
tSound->Snd.push_back( cSound( tSound->Buf ) );
tSound->Snd.push_back( Sound( tSound->Buf ) );
return true;
}
}
@@ -121,16 +121,16 @@ bool tSoundManager<T>::LoadFromSamples( const T& id, const Int16* Samples, std::
}
template <typename T>
cSoundBuffer& tSoundManager<T>::GetBuffer( const T& id ) {
SoundBuffer& tSoundManager<T>::GetBuffer( const T& id ) {
if ( tSounds.find( id ) != tSounds.end() )
return tSounds[id].Buf;
static cSoundBuffer soundBuf;
static SoundBuffer soundBuf;
return soundBuf;
}
template <typename T>
cSound& 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,12 +139,12 @@ cSound& 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() != cSound::Playing ) {
if ( tSound->Snd[i].GetState() != Sound::Playing ) {
return tSound->Snd[i];
}
}
tSound->Snd.push_back( cSound( tSound->Buf ) );
tSound->Snd.push_back( Sound( tSound->Buf ) );
return tSound->Snd[ tSound->Snd.size() - 1 ];
}
@@ -153,7 +153,7 @@ cSound& tSoundManager<T>::GetFreeSound( const T& id ) {
}
template <typename T>
cSound& tSoundManager<T>::operator[] ( const T& id ) {
Sound& tSoundManager<T>::operator[] ( const T& id ) {
if ( tSounds.find( id ) != tSounds.end() )
return tSounds[id].Snd[0];
@@ -170,14 +170,14 @@ 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() != cSound::Playing ) {
if ( tSound->Snd[i].GetState() != Sound::Playing ) {
tSound->Snd[i].Play();
return;
}
}
// Otherwise create a new one and play it.
tSound->Snd.push_back( cSound( tSound->Buf ) );
tSound->Snd.push_back( Sound( tSound->Buf ) );
tSound->Snd[ tSize ].Play();
}
}
@@ -202,7 +202,7 @@ bool tSoundManager<T>::Remove( const T& id ) {
return false;
}
typedef tSoundManager<std::string> cSoundManager;
typedef tSoundManager<std::string> SoundManager;
}}

View File

@@ -2,21 +2,21 @@
#define EE_AUDIOCSOUNDSTREAM_H
#include <eepp/audio/base.hpp>
#include <eepp/audio/csound.hpp>
#include <eepp/audio/sound.hpp>
namespace EE { namespace Audio {
/** @brief Abstract base class for streamed audio sources */
class EE_API cSoundStream : private cThread, private cSound {
class EE_API SoundStream : private cThread, private Sound {
public:
using cSound::Pause;
using cSound::Pitch;
using cSound::Volume;
using cSound::Position;
using cSound::MinDistance;
using cSound::Attenuation;
using cSound::SetRelativeToListener;
using cSound::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 {
@@ -24,7 +24,7 @@ class EE_API cSoundStream : private cThread, private cSound {
std::size_t SamplesCount; ///< Number of samples pointed by Samples
};
virtual ~cSoundStream();
virtual ~SoundStream();
/** \brief Start or resume playing the audio stream
** This function starts the stream if it was stopped, resumes
@@ -86,7 +86,7 @@ class EE_API cSoundStream : private cThread, private cSound {
*/
bool Loop() const;
protected:
cSoundStream();
SoundStream();
void Initialize(unsigned int ChannelCount, unsigned int SampleRate);
private :

View File

@@ -1,22 +1,22 @@
../../include/eepp/audio/tsoundmanager.hpp
../../include/eepp/audio/tsoundloader.hpp
../../include/eepp/audio/csoundstream.hpp
../../include/eepp/audio/csoundbuffer.hpp
../../include/eepp/audio/csound.hpp
../../include/eepp/audio/cmusic.hpp
../../include/eepp/audio/caudiolistener.hpp
../../include/eepp/audio/caudiodevice.hpp
../../include/eepp/audio/soundmanager.hpp
../../include/eepp/audio/soundloader.hpp
../../include/eepp/audio/soundstream.hpp
../../include/eepp/audio/soundbuffer.hpp
../../include/eepp/audio/sound.hpp
../../include/eepp/audio/music.hpp
../../include/eepp/audio/audiolistener.hpp
../../include/eepp/audio/audiodevice.hpp
../../include/eepp/audio/base.hpp
../../src/eepp/audio/openal.cpp
../../src/eepp/audio/csoundstream.cpp
../../src/eepp/audio/csoundfileogg.cpp
../../src/eepp/audio/csoundfiledefault.cpp
../../src/eepp/audio/csoundfile.cpp
../../src/eepp/audio/csoundbuffer.cpp
../../src/eepp/audio/csound.cpp
../../src/eepp/audio/cmusic.cpp
../../src/eepp/audio/caudiolistener.cpp
../../src/eepp/audio/caudiodevice.cpp
../../src/eepp/audio/soundstream.cpp
../../src/eepp/audio/soundfileogg.cpp
../../src/eepp/audio/soundfiledefault.cpp
../../src/eepp/audio/soundfile.cpp
../../src/eepp/audio/soundbuffer.cpp
../../src/eepp/audio/sound.cpp
../../src/eepp/audio/music.cpp
../../src/eepp/audio/audiolistener.cpp
../../src/eepp/audio/audiodevice.cpp
../../include/eepp/core/utf.hpp
../../include/eepp/core/string.hpp
../../include/eepp/core/stlcontainers.hpp
@@ -561,8 +561,8 @@
../../src/eepp/physics/moment.cpp
../../src/eepp/physics/area.cpp
../../premake4.lua
../../src/eepp/audio/csoundfileogg.hpp
../../src/eepp/audio/csoundfiledefault.hpp
../../src/eepp/audio/soundfileogg.hpp
../../src/eepp/audio/soundfiledefault.hpp
../../include/eepp/gaming/cgameobjectobject.hpp
../../src/eepp/gaming/cgameobjectobject.cpp
../../src/eepp/gaming/cgameobjectpolyline.cpp
@@ -598,7 +598,7 @@
../../src/eepp/helper/SOIL2/src/SOIL2/SOIL2.c
../../src/eepp/helper/SOIL2/src/SOIL2/stbi_ext_c.h
../../src/eepp/helper/SOIL2/src/SOIL2/stbi_ext.h
../../src/eepp/audio/csoundfile.hpp
../../src/eepp/audio/soundfile.hpp
../../src/eepp/audio/openal.hpp
../../src/eepp/window/backend/SDL2/cbackendsdl2.cpp
../../src/examples/sound/sound.cpp

View File

@@ -1,5 +1,5 @@
#include <eepp/audio/caudiodevice.hpp>
#include <eepp/audio/caudiolistener.hpp>
#include <eepp/audio/audiodevice.hpp>
#include <eepp/audio/audiolistener.hpp>
#include <eepp/audio/openal.hpp>
namespace EE { namespace Audio {
@@ -7,7 +7,7 @@ namespace EE { namespace Audio {
ALCdevice * mDevice = NULL;
ALCcontext * mContext = NULL;
cAudioDevice::cAudioDevice() {
AudioDevice::AudioDevice() {
PrintInfo();
// Create the device
@@ -42,7 +42,7 @@ cAudioDevice::cAudioDevice() {
}
}
void cAudioDevice::PrintInfo() {
void AudioDevice::PrintInfo() {
std::string log( "OpenAL devices detected:\n" );
if ( alcIsExtensionPresent( NULL, (const ALCchar *) "ALC_ENUMERATION_EXT" ) == AL_TRUE ) {
@@ -62,7 +62,7 @@ void cAudioDevice::PrintInfo() {
eePRINTL( log.c_str() );
}
cAudioDevice::~cAudioDevice() {
AudioDevice::~AudioDevice() {
// Destroy the context
alcMakeContextCurrent( NULL );
@@ -74,7 +74,7 @@ cAudioDevice::~cAudioDevice() {
alcCloseDevice( mDevice );
}
bool cAudioDevice::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 cAudioDevice::IsExtensionSupported( const std::string& extension ) {
return alIsExtensionPresent( extension.c_str() ) != AL_FALSE;
}
int cAudioDevice::GetFormatFromChannelCount( unsigned int ChannelCount ) {
int AudioDevice::GetFormatFromChannelCount( unsigned int ChannelCount ) {
EnsureALInit();
int format = 0;
@@ -104,7 +104,7 @@ int cAudioDevice::GetFormatFromChannelCount( unsigned int ChannelCount ) {
return format;
}
bool cAudioDevice::IsAvailable() {
bool AudioDevice::IsAvailable() {
return NULL != mDevice && NULL != mContext;
}

View File

@@ -1,9 +1,9 @@
#include <eepp/audio/caudiolistener.hpp>
#include <eepp/audio/audiolistener.hpp>
#include <eepp/audio/openal.hpp>
namespace EE { namespace Audio {
void cAudioListener::GlobalVolume( const float& Volume ) {
void AudioListener::GlobalVolume( const float& Volume ) {
EnsureALInit();
#if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN
@@ -11,7 +11,7 @@ void cAudioListener::GlobalVolume( const float& Volume ) {
#endif
}
float cAudioListener::GlobalVolume() {
float AudioListener::GlobalVolume() {
EnsureALInit();
float Volume = 0.f;
@@ -21,17 +21,17 @@ float cAudioListener::GlobalVolume() {
return Volume * 100.f;
}
void cAudioListener::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 cAudioListener::Position(const eeVector3ff& Position) {
cAudioListener::Position( Position.x, Position.y, Position.z );
void AudioListener::Position(const eeVector3ff& Position) {
AudioListener::Position( Position.x, Position.y, Position.z );
}
eeVector3ff cAudioListener::Position() {
eeVector3ff AudioListener::Position() {
EnsureALInit();
eeVector3ff Position;
@@ -40,18 +40,18 @@ eeVector3ff cAudioListener::Position() {
return Position;
}
void cAudioListener::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 cAudioListener::Target(const eeVector3ff& Target) {
cAudioListener::Target( Target.x, Target.y, Target.z );
void AudioListener::Target(const eeVector3ff& Target) {
AudioListener::Target( Target.x, Target.y, Target.z );
}
eeVector3ff cAudioListener::Target() {
eeVector3ff AudioListener::Target() {
EnsureALInit();
float Orientation[6];

View File

@@ -1,29 +1,29 @@
#include <eepp/audio/cmusic.hpp>
#include <eepp/audio/csoundfile.hpp>
#include <eepp/audio/music.hpp>
#include <eepp/audio/soundfile.hpp>
#include <eepp/system/cpackmanager.hpp>
namespace EE { namespace Audio {
cMusic::cMusic( std::size_t BufferSize ) :
Music::Music( std::size_t BufferSize ) :
mFile ( NULL ),
mDuration( 0.f ),
mSamples( BufferSize )
{
}
cMusic::~cMusic() {
Music::~Music() {
Stop();
eeSAFE_DELETE( mFile );
}
bool cMusic::OpenFromPack( cPack* Pack, const std::string& FilePackPath ) {
bool Music::OpenFromPack( cPack* Pack, const std::string& FilePackPath ) {
if ( Pack->IsOpen() && Pack->ExtractFileToMemory( FilePackPath, mData ) )
return OpenFromMemory( reinterpret_cast<const char*> ( mData.Data ), mData.DataSize );
return false;
}
bool cMusic::OpenFromFile( const std::string& Filename ) {
bool Music::OpenFromFile( const std::string& Filename ) {
if ( !FileSystem::FileExists( Filename ) ) {
if ( cPackManager::instance()->FallbackToPacks() ) {
std::string tPath( Filename );
@@ -42,7 +42,7 @@ bool cMusic::OpenFromFile( const std::string& Filename ) {
Stop();
eeSAFE_DELETE( mFile );
mFile = cSoundFile::CreateRead( Filename );
mFile = SoundFile::CreateRead( Filename );
if ( NULL == mFile ) {
eePRINTL( "Failed to open %s for reading", Filename.c_str() );
@@ -60,12 +60,12 @@ bool cMusic::OpenFromFile( const std::string& Filename ) {
return true;
}
bool cMusic::OpenFromMemory( const char * Data, std::size_t SizeInBytes ) {
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 = cSoundFile::CreateRead( Data, SizeInBytes );
mFile = SoundFile::CreateRead( Data, SizeInBytes );
if ( NULL == mFile ) {
eePRINTL( "Failed to open music from memory for reading" );
@@ -81,11 +81,11 @@ bool cMusic::OpenFromMemory( const char * Data, std::size_t SizeInBytes ) {
return true;
}
bool cMusic::OnStart() {
bool Music::OnStart() {
return NULL != mFile && mFile->Restart();
}
bool cMusic::OnGetData( cSoundStream::Chunk& Data ) {
bool Music::OnGetData( SoundStream::Chunk& Data ) {
if ( NULL != mFile ) {
// Fill the chunk parameters
Data.Samples = &mSamples[0];
@@ -98,11 +98,11 @@ bool cMusic::OnGetData( cSoundStream::Chunk& Data ) {
return false;
}
cTime cMusic::GetDuration() const {
cTime Music::GetDuration() const {
return Seconds( mDuration );
}
void cMusic::OnSeek( cTime timeOffset ) {
void Music::OnSeek( cTime timeOffset ) {
if ( NULL != mFile ) {
mFile->Seek( timeOffset );
}

View File

@@ -1,5 +1,5 @@
#include <eepp/audio/openal.hpp>
#include <eepp/audio/caudiodevice.hpp>
#include <eepp/audio/audiodevice.hpp>
#include <iostream>
namespace EE { namespace Audio {
@@ -41,7 +41,7 @@ void ALCheckError(const std::string& File, unsigned int Line) {
}
void EnsureALInit() {
static cAudioDevice GlobalDevice;
static AudioDevice GlobalDevice;
}
}}

View File

@@ -1,10 +1,10 @@
#include <eepp/audio/csound.hpp>
#include <eepp/audio/caudiodevice.hpp>
#include <eepp/audio/sound.hpp>
#include <eepp/audio/audiodevice.hpp>
#include <eepp/audio/openal.hpp>
namespace EE { namespace Audio {
cSound::cSound() :
Sound::Sound() :
mBuffer(NULL)
{
EnsureALInit();
@@ -13,7 +13,7 @@ cSound::cSound() :
ALCheck( alSourcei( mSource, AL_BUFFER, 0 ) );
}
cSound::cSound( const cSoundBuffer& Buffer, const bool& Loop, const float& Pitch, const float& Volume, const eeVector3ff& Position ) :
Sound::Sound( const SoundBuffer& Buffer, const bool& Loop, const float& Pitch, const float& Volume, const eeVector3ff& Position ) :
mBuffer(&Buffer)
{
EnsureALInit();
@@ -27,7 +27,7 @@ cSound::cSound( const cSoundBuffer& Buffer, const bool& Loop, const float& Pitch
ALCheck( alSource3f( mSource, AL_POSITION, Position.x, Position.y, Position.z ) );
}
cSound::cSound(const cSound& Copy) :
Sound::Sound(const Sound& Copy) :
mBuffer(Copy.mBuffer)
{
EnsureALInit();
@@ -41,7 +41,7 @@ cSound::cSound(const cSound& Copy) :
ALCheck( alSource3f( mSource, AL_POSITION, Copy.Position().x, Copy.Position().y, Copy.Position().z) );
}
cSound::~cSound() {
Sound::~Sound() {
if ( mSource ) {
if ( mBuffer ) {
Stop();
@@ -52,19 +52,19 @@ cSound::~cSound() {
}
}
void cSound::Play() {
void Sound::Play() {
ALCheck( alSourcePlay( mSource ) );
}
void cSound::Pause() {
void Sound::Pause() {
ALCheck( alSourcePause( mSource ) );
}
void cSound::Stop() {
void Sound::Stop() {
ALCheck( alSourceStop( mSource ) );
}
void cSound::Buffer(const cSoundBuffer& Buffer) {
void Sound::Buffer(const SoundBuffer& Buffer) {
if ( NULL != mBuffer ) {
Stop();
mBuffer->DetachSound( this );
@@ -76,60 +76,60 @@ void cSound::Buffer(const cSoundBuffer& Buffer) {
ALCheck( alSourcei( mSource, AL_BUFFER, mBuffer ? mBuffer->mBuffer : 0 ) );
}
void cSound::Loop( const bool& Loop ) {
void Sound::Loop( const bool& Loop ) {
ALCheck( alSourcei( mSource, AL_LOOPING, Loop ) );
}
void cSound::Pitch( const float& Pitch ) {
void Sound::Pitch( const float& Pitch ) {
ALCheck( alSourcef( mSource, AL_PITCH, Pitch ) );
}
void cSound::Volume( const float& Volume ) {
void Sound::Volume( const float& Volume ) {
ALCheck( alSourcef( mSource, AL_GAIN, Volume * 0.01f ) );
}
void cSound::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 cSound::Position( const eeVector3ff& Position ) {
void Sound::Position( const eeVector3ff& Position ) {
this->Position( Position.x, Position.y, Position.z );
}
void cSound::MinDistance( const float& MinDistance ) {
void Sound::MinDistance( const float& MinDistance ) {
ALCheck( alSourcef( mSource, AL_REFERENCE_DISTANCE, MinDistance ) );
}
void cSound::Attenuation( const float& Attenuation ) {
void Sound::Attenuation( const float& Attenuation ) {
ALCheck( alSourcef( mSource, AL_ROLLOFF_FACTOR, Attenuation ) );
}
const cSoundBuffer* cSound::Buffer() const {
const SoundBuffer* Sound::Buffer() const {
return mBuffer;
}
bool cSound::Loop() const {
bool Sound::Loop() const {
ALint Loop;
ALCheck( alGetSourcei( mSource, AL_LOOPING, &Loop ) );
return Loop != 0;
}
float cSound::Pitch() const {
float Sound::Pitch() const {
float Pitch;
ALCheck( alGetSourcef( mSource, AL_PITCH, &Pitch ) );
return Pitch;
}
float cSound::Volume() const {
float Sound::Volume() const {
float Gain = 1;
ALCheck( alGetSourcef( mSource, AL_GAIN, &Gain ) );
return Gain * 100.f;
}
eeVector3ff cSound::Position() const {
eeVector3ff Sound::Position() const {
eeVector3ff Position;
#if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN
@@ -139,35 +139,35 @@ eeVector3ff cSound::Position() const {
return Position;
}
float cSound::MinDistance() const {
float Sound::MinDistance() const {
float MinDistance;
ALCheck( alGetSourcef( mSource, AL_REFERENCE_DISTANCE, &MinDistance ) );
return MinDistance;
}
float cSound::Attenuation() const {
float Sound::Attenuation() const {
float Attenuation;
ALCheck( alGetSourcef( mSource, AL_ROLLOFF_FACTOR, &Attenuation ) );
return Attenuation;
}
cSound::Status cSound::GetState() const {
Sound::Status Sound::GetState() const {
ALint State;
ALCheck( alGetSourcei( mSource, AL_SOURCE_STATE, &State ) );
switch (State) {
case AL_INITIAL :
case AL_STOPPED : return cSound::Stopped;
case AL_PAUSED : return cSound::Paused;
case AL_PLAYING : return cSound::Playing;
case AL_STOPPED : return Sound::Stopped;
case AL_PAUSED : return Sound::Paused;
case AL_PLAYING : return Sound::Playing;
}
return cSound::Stopped;
return Sound::Stopped;
}
cTime cSound::PlayingOffset() const {
cTime Sound::PlayingOffset() const {
float secs = 0.f;
ALCheck( alGetSourcef( mSource, AL_SEC_OFFSET, &secs ) );
@@ -175,11 +175,11 @@ cTime cSound::PlayingOffset() const {
return Seconds( secs );
}
void cSound::PlayingOffset( const cTime &TimeOffset ) {
void Sound::PlayingOffset( const cTime &TimeOffset ) {
ALCheck( alSourcef( mSource, AL_SEC_OFFSET, TimeOffset.AsSeconds() ) );
}
cSound& cSound::operator =( const cSound& Other ) {
Sound& Sound::operator =( const Sound& Other ) {
if ( NULL != mBuffer ) {
Stop();
mBuffer->DetachSound( this );
@@ -202,17 +202,17 @@ cSound& cSound::operator =( const cSound& Other ) {
return *this;
}
void cSound::SetRelativeToListener( const bool& Relative ) {
void Sound::SetRelativeToListener( const bool& Relative ) {
ALCheck( alSourcei( mSource, AL_SOURCE_RELATIVE, Relative ) );
}
bool cSound::IsRelativeToListener() const {
bool Sound::IsRelativeToListener() const {
ALint Relative;
ALCheck( alGetSourcei( mSource, AL_SOURCE_RELATIVE, &Relative ) );
return Relative != 0;
}
void cSound::ResetBuffer() {
void Sound::ResetBuffer() {
// First stop the sound in case it is playing
Stop();
@@ -226,7 +226,7 @@ void cSound::ResetBuffer() {
}
}
cSound::Status cSound::State() const {
Sound::Status Sound::State() const {
return GetState();
}

View File

@@ -1,14 +1,14 @@
#include <eepp/audio/csoundbuffer.hpp>
#include <eepp/audio/csound.hpp>
#include <eepp/audio/csoundfile.hpp>
#include <eepp/audio/caudiodevice.hpp>
#include <eepp/audio/soundbuffer.hpp>
#include <eepp/audio/sound.hpp>
#include <eepp/audio/soundfile.hpp>
#include <eepp/audio/audiodevice.hpp>
#include <eepp/system/cpackmanager.hpp>
#include <eepp/audio/openal.hpp>
#include <memory>
namespace EE { namespace Audio {
cSoundBuffer::cSoundBuffer() :
SoundBuffer::SoundBuffer() :
mBuffer(0),
mDuration()
{
@@ -17,7 +17,7 @@ cSoundBuffer::cSoundBuffer() :
ALCheck( alGenBuffers( 1, &mBuffer ) );
}
cSoundBuffer::cSoundBuffer(const cSoundBuffer& Copy) :
SoundBuffer::SoundBuffer(const SoundBuffer& Copy) :
mBuffer(0),
mSamples(Copy.mSamples),
mDuration(Copy.mDuration),
@@ -29,7 +29,7 @@ cSoundBuffer::cSoundBuffer(const cSoundBuffer& Copy) :
Update( Copy.GetChannelCount(), Copy.GetSampleRate() );
}
cSoundBuffer::~cSoundBuffer() {
SoundBuffer::~SoundBuffer() {
for ( SoundList::const_iterator it = mSounds.begin(); it != mSounds.end(); ++it )
(*it)->ResetBuffer();
@@ -37,7 +37,7 @@ cSoundBuffer::~cSoundBuffer() {
ALCheck( alDeleteBuffers( 1, &mBuffer ) );
}
bool cSoundBuffer::LoadFromFile(const std::string& Filename) {
bool SoundBuffer::LoadFromFile(const std::string& Filename) {
if ( !FileSystem::FileExists( Filename ) ) {
if ( cPackManager::instance()->FallbackToPacks() ) {
std::string tPath( Filename );
@@ -54,7 +54,7 @@ bool cSoundBuffer::LoadFromFile(const std::string& Filename) {
}
// Create the sound file
cSoundFile * File = cSoundFile::CreateRead( Filename );
SoundFile * File = SoundFile::CreateRead( Filename );
// Open the sound file
if ( NULL != File ) {
@@ -87,7 +87,7 @@ bool cSoundBuffer::LoadFromFile(const std::string& Filename) {
}
}
bool cSoundBuffer::LoadFromPack( cPack* Pack, const std::string& FilePackPath ) {
bool SoundBuffer::LoadFromPack( cPack* Pack, const std::string& FilePackPath ) {
bool Ret = false;
SafeDataPointer PData;
@@ -97,9 +97,9 @@ bool cSoundBuffer::LoadFromPack( cPack* Pack, const std::string& FilePackPath )
return Ret;
}
bool cSoundBuffer::LoadFromMemory( const char* Data, std::size_t SizeInBytes ) {
bool SoundBuffer::LoadFromMemory( const char* Data, std::size_t SizeInBytes ) {
// Create the sound file
cSoundFile * File = cSoundFile::CreateRead( Data, SizeInBytes );
SoundFile * File = SoundFile::CreateRead( Data, SizeInBytes );
// Open the sound file
if ( NULL != File ) {
@@ -131,7 +131,7 @@ bool cSoundBuffer::LoadFromMemory( const char* Data, std::size_t SizeInBytes ) {
}
}
bool cSoundBuffer::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 );
@@ -147,9 +147,9 @@ bool cSoundBuffer::LoadFromSamples( const Int16 * Samples, std::size_t SamplesCo
}
}
bool cSoundBuffer::SaveToFile(const std::string& Filename) const {
bool SoundBuffer::SaveToFile(const std::string& Filename) const {
// Create the sound file in write mode
std::auto_ptr<cSoundFile> File( cSoundFile::CreateWrite( Filename, GetChannelCount(), GetSampleRate() ) );
std::auto_ptr<SoundFile> File( SoundFile::CreateWrite( Filename, GetChannelCount(), GetSampleRate() ) );
if ( File.get() ) {
// Write the samples to the opened file
@@ -162,32 +162,32 @@ bool cSoundBuffer::SaveToFile(const std::string& Filename) const {
}
}
const Int16* cSoundBuffer::GetSamples() const {
const Int16* SoundBuffer::GetSamples() const {
return mSamples.empty() ? NULL : &mSamples[0];
}
std::size_t cSoundBuffer::GetSamplesCount() const {
std::size_t SoundBuffer::GetSamplesCount() const {
return mSamples.size();
}
unsigned int cSoundBuffer::GetSampleRate() const {
unsigned int SoundBuffer::GetSampleRate() const {
ALint SampleRate;
ALCheck( alGetBufferi( mBuffer, AL_FREQUENCY, &SampleRate ) );
return SampleRate;
}
unsigned int cSoundBuffer::GetChannelCount() const {
unsigned int SoundBuffer::GetChannelCount() const {
ALint ChannelCount;
ALCheck( alGetBufferi( mBuffer, AL_CHANNELS, &ChannelCount ) );
return ChannelCount;
}
cTime cSoundBuffer::GetDuration() const {
cTime SoundBuffer::GetDuration() const {
return mDuration;
}
cSoundBuffer& cSoundBuffer::operator =( const cSoundBuffer& Other ) {
cSoundBuffer Temp( Other );
SoundBuffer& SoundBuffer::operator =( const SoundBuffer& Other ) {
SoundBuffer Temp( Other );
std::swap( mSamples , Temp.mSamples );
std::swap( mBuffer , Temp.mBuffer );
@@ -197,13 +197,13 @@ cSoundBuffer& cSoundBuffer::operator =( const cSoundBuffer& Other ) {
return *this;
}
bool cSoundBuffer::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 = cAudioDevice::GetFormatFromChannelCount( ChannelCount );
ALenum Format = AudioDevice::GetFormatFromChannelCount( ChannelCount );
// Check if the format is valid
if ( Format == 0 ) {
@@ -228,11 +228,11 @@ bool cSoundBuffer::Update( unsigned int ChannelCount, unsigned int SampleRate )
return true;
}
void cSoundBuffer::AttachSound( cSound* sound ) const {
void SoundBuffer::AttachSound( Sound* sound ) const {
mSounds.insert(sound);
}
void cSoundBuffer::DetachSound( cSound* sound ) const {
void SoundBuffer::DetachSound( Sound* sound ) const {
mSounds.erase(sound);
}

View File

@@ -1,29 +1,29 @@
#include <eepp/audio/csoundfile.hpp>
#include <eepp/audio/soundfile.hpp>
#ifdef EE_LIBSNDFILE_ENABLED
#include <eepp/audio/csoundfiledefault.hpp>
#include <eepp/audio/soundfiledefault.hpp>
#endif
#include <eepp/audio/csoundfileogg.hpp>
#include <eepp/audio/soundfileogg.hpp>
namespace EE { namespace Audio {
cSoundFile::cSoundFile() :
SoundFile::SoundFile() :
mSamplesCount (0),
mChannelCount(0),
mSampleRate (0)
{
}
cSoundFile::~cSoundFile()
SoundFile::~SoundFile()
{
}
cSoundFile * cSoundFile::CreateRead( const std::string& Filename ) {
SoundFile * SoundFile::CreateRead( const std::string& Filename ) {
// Create the file according to its type
cSoundFile * File = NULL;
SoundFile * File = NULL;
if ( cSoundFileOgg::IsFileSupported( Filename, true ) ) File = eeNew( cSoundFileOgg, () );
if ( SoundFileOgg::IsFileSupported( Filename, true ) ) File = eeNew( SoundFileOgg, () );
#ifdef EE_LIBSNDFILE_ENABLED
else if ( cSoundFileDefault::IsFileSupported( Filename, true ) ) File = eeNew( cSoundFileDefault, () );
else if ( SoundFileDefault::IsFileSupported( Filename, true ) ) File = eeNew( SoundFileDefault, () );
#endif
// Open it for reading
@@ -48,13 +48,13 @@ cSoundFile * cSoundFile::CreateRead( const std::string& Filename ) {
return File;
}
cSoundFile * cSoundFile::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
cSoundFile * File = NULL;
SoundFile * File = NULL;
if ( cSoundFileOgg::IsFileSupported( Data, SizeInMemory ) ) File = eeNew( cSoundFileOgg, () );
if ( SoundFileOgg::IsFileSupported( Data, SizeInMemory ) ) File = eeNew( SoundFileOgg, () );
#ifdef EE_LIBSNDFILE_ENABLED
else if ( cSoundFileDefault::IsFileSupported( Data, SizeInMemory ) ) File = eeNew( cSoundFileDefault, () );
else if ( SoundFileDefault::IsFileSupported( Data, SizeInMemory ) ) File = eeNew( SoundFileDefault, () );
#endif
// Open it for reading
@@ -79,13 +79,13 @@ cSoundFile * cSoundFile::CreateRead( const char* Data, std::size_t SizeInMemory
return File;
}
cSoundFile * cSoundFile::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
cSoundFile * File = NULL;
SoundFile * File = NULL;
if ( cSoundFileOgg::IsFileSupported( Filename, false ) ) File = eeNew( cSoundFileOgg, () );
if ( SoundFileOgg::IsFileSupported( Filename, false ) ) File = eeNew( SoundFileOgg, () );
#ifdef EE_LIBSNDFILE_ENABLED
else if ( cSoundFileDefault::IsFileSupported( Filename, false ) ) File = eeNew( cSoundFileDefault, () );
else if ( SoundFileDefault::IsFileSupported( Filename, false ) ) File = eeNew( SoundFileDefault, () );
#endif
// Open it for writing
@@ -106,20 +106,20 @@ cSoundFile * cSoundFile::CreateWrite( const std::string& Filename, unsigned int
return File;
}
std::size_t cSoundFile::GetSamplesCount() const
std::size_t SoundFile::GetSamplesCount() const
{
return mSamplesCount;
}
unsigned int cSoundFile::GetChannelCount() const {
unsigned int SoundFile::GetChannelCount() const {
return mChannelCount;
}
unsigned int cSoundFile::GetSampleRate() const {
unsigned int SoundFile::GetSampleRate() const {
return mSampleRate;
}
bool cSoundFile::Restart() {
bool SoundFile::Restart() {
if ( mData ) {
// Reopen from memory
return OpenRead( mData, mSize, mSamplesCount, mChannelCount, mSampleRate );
@@ -132,31 +132,31 @@ bool cSoundFile::Restart() {
}
}
bool cSoundFile::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 cSoundFile::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 cSoundFile::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 cSoundFile::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 cSoundFile::Write(const Int16*, std::size_t) {
void SoundFile::Write(const Int16*, std::size_t) {
eePRINTL( "Failed to write to sound file (not supported)" );
}
void cSoundFile::Seek( cTime timeOffset ) {
void SoundFile::Seek( cTime timeOffset ) {
eePRINTL( "Trying to seek a file that doesn't support seeking." );
}

View File

@@ -6,18 +6,18 @@
namespace EE { namespace Audio {
/** @brief Provide read and write access to sound files */
class EE_API cSoundFile {
class EE_API SoundFile {
public:
/** @brief Open a sound file for reading */
static cSoundFile * CreateRead(const std::string& Filename);
static SoundFile * CreateRead(const std::string& Filename);
/** @brief Open a sound file from memory for reading */
static cSoundFile * 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 cSoundFile * 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 ~cSoundFile();
virtual ~SoundFile();
/** @brief Get the total number of audio samples in the file */
std::size_t GetSamplesCount() const;
@@ -50,7 +50,7 @@ class EE_API cSoundFile {
** @param timeOffset New playing position, from the beginning of the file */
virtual void Seek( cTime timeOffset );
protected :
cSoundFile();
SoundFile();
virtual bool OpenRead(const std::string& Filename, std::size_t& SamplesCount, unsigned int& ChannelCount, unsigned int& SampleRate);

View File

@@ -1,20 +1,20 @@
#include <eepp/audio/csoundfiledefault.hpp>
#include <eepp/audio/soundfiledefault.hpp>
#ifdef EE_LIBSNDFILE_ENABLED
namespace EE { namespace Audio {
cSoundFileDefault::cSoundFileDefault() :
SoundFileDefault::SoundFileDefault() :
mFile(NULL)
{
}
cSoundFileDefault::~cSoundFileDefault() {
SoundFileDefault::~SoundFileDefault() {
if ( NULL != mFile )
sf_close( mFile );
}
bool cSoundFileDefault::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;
@@ -33,7 +33,7 @@ bool cSoundFileDefault::IsFileSupported( const std::string& Filename, bool Read
}
}
bool cSoundFileDefault::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 );
@@ -51,7 +51,7 @@ bool cSoundFileDefault::IsFileSupported( const char* Data, std::size_t SizeInByt
return false;
}
bool cSoundFileDefault::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,7 +78,7 @@ bool cSoundFileDefault::OpenRead( const std::string& Filename, std::size_t& Samp
return true;
}
bool cSoundFileDefault::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 );
@@ -108,7 +108,7 @@ bool cSoundFileDefault::OpenRead( const char* Data, std::size_t SizeInBytes, std
return true;
}
bool cSoundFileDefault::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 );
@@ -138,26 +138,26 @@ bool cSoundFileDefault::OpenWrite( const std::string& Filename, unsigned int Cha
return true;
}
std::size_t cSoundFileDefault::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 cSoundFileDefault::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 cSoundFileDefault::Seek( cTime timeOffset ) {
void SoundFileDefault::Seek( cTime timeOffset ) {
if ( NULL != mFile ) {
sf_count_t frameOffset = static_cast<sf_count_t>( timeOffset.AsSeconds() * mSampleRate / 1000 );
sf_seek( mFile, frameOffset, SEEK_SET );
}
}
int cSoundFileDefault::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 cSoundFileDefault::GetFormatFromFilename(const std::string& Filename) {
return -1;
}
SF_VIRTUAL_IO cSoundFileDefault::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 = &cSoundFileDefault::MemoryIO::GetLength;
io.read = &cSoundFileDefault::MemoryIO::Read;
io.seek = &cSoundFileDefault::MemoryIO::Seek;
io.tell = &cSoundFileDefault::MemoryIO::Tell;
io.write = &cSoundFileDefault::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 cSoundFileDefault::MemoryIO::Prepare( const void * data, std::size
return io;
}
sf_count_t cSoundFileDefault::MemoryIO::GetLength( void* UserData ) {
sf_count_t SoundFileDefault::MemoryIO::GetLength( void* UserData ) {
MemoryIO * self = static_cast<MemoryIO*>(UserData);
return self->mTotalSize;
}
sf_count_t cSoundFileDefault::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 cSoundFileDefault::MemoryIO::Read( void* Ptr, sf_count_t Count, void*
return Count;
}
sf_count_t cSoundFileDefault::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 cSoundFileDefault::MemoryIO::Seek( sf_count_t Offset, int Whence, voi
return Position;
}
sf_count_t cSoundFileDefault::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 cSoundFileDefault::MemoryIO::Write( const void*, sf_count_t, void* ) {
sf_count_t SoundFileDefault::MemoryIO::Write( const void*, sf_count_t, void* ) {
return 0;
}

View File

@@ -6,15 +6,15 @@
#ifdef EE_LIBSNDFILE_ENABLED
#include <sndfile.h>
#include <eepp/audio/csoundfile.hpp>
#include <eepp/audio/soundfile.hpp>
namespace EE { namespace Audio {
class EE_API cSoundFileDefault : public cSoundFile {
class EE_API SoundFileDefault : public SoundFile {
public :
cSoundFileDefault();
SoundFileDefault();
~cSoundFileDefault();
~SoundFileDefault();
/** Check if a given file is supported by this loader. */
static bool IsFileSupported(const std::string& Filename, bool Read);

View File

@@ -1,20 +1,20 @@
#include <eepp/audio/csoundfileogg.hpp>
#include <eepp/audio/soundfileogg.hpp>
#include <eepp/helper/stb_vorbis/stb_vorbis.h>
namespace EE { namespace Audio {
cSoundFileOgg::cSoundFileOgg() :
SoundFileOgg::SoundFileOgg() :
mStream (NULL),
mChannelCount(0)
{
}
cSoundFileOgg::~cSoundFileOgg() {
SoundFileOgg::~SoundFileOgg() {
if ( NULL != mStream )
stb_vorbis_close( mStream );
}
bool cSoundFileOgg::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 cSoundFileOgg::IsFileSupported( const std::string& Filename, bool Read ) {
return false;
}
bool cSoundFileOgg::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 cSoundFileOgg::IsFileSupported( const char* Data, std::size_t SizeInBytes )
return false;
}
bool cSoundFileOgg::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 cSoundFileOgg::OpenRead( const std::string& Filename, std::size_t& SamplesC
return true;
}
bool cSoundFileOgg::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 cSoundFileOgg::OpenRead( const char* Data, std::size_t SizeInBytes, std::si
return true;
}
std::size_t cSoundFileOgg::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 cSoundFileOgg::Read( Int16 * Data, std::size_t SamplesCount ) {
return 0;
}
void cSoundFileOgg::Seek( cTime timeOffset ) {
void SoundFileOgg::Seek( cTime timeOffset ) {
if ( NULL != mStream ) {
Uint32 frameOffset = static_cast<Uint32>( timeOffset.AsSeconds() * mSampleRate / 1000 );
stb_vorbis_seek( mStream, frameOffset );

View File

@@ -2,16 +2,16 @@
#define EE_AUDIOCSOUNDFILEOGG_H
#include <eepp/audio/base.hpp>
#include <eepp/audio/csoundfile.hpp>
#include <eepp/audio/soundfile.hpp>
struct stb_vorbis;
namespace EE { namespace Audio {
class EE_API cSoundFileOgg : public cSoundFile {
class EE_API SoundFileOgg : public SoundFile {
public:
cSoundFileOgg();
~cSoundFileOgg();
SoundFileOgg();
~SoundFileOgg();
/** Check if a given file is supported by this loader. */
static bool IsFileSupported(const std::string& Filename, bool Read);

View File

@@ -1,12 +1,12 @@
#include <eepp/audio/csoundstream.hpp>
#include <eepp/audio/caudiodevice.hpp>
#include <eepp/audio/soundstream.hpp>
#include <eepp/audio/audiodevice.hpp>
#include <eepp/system/sys.hpp>
#include <eepp/audio/openal.hpp>
using namespace EE::System;
namespace EE { namespace Audio {
cSoundStream::cSoundStream() :
SoundStream::SoundStream() :
mIsStreaming(false),
mChannelCount(0),
mSampleRate (0),
@@ -16,16 +16,16 @@ cSoundStream::cSoundStream() :
{
}
cSoundStream::~cSoundStream() {
SoundStream::~SoundStream() {
Stop(); // Stop the sound if it was playing
}
void cSoundStream::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 = cAudioDevice::GetFormatFromChannelCount(ChannelCount);
mFormat = AudioDevice::GetFormatFromChannelCount(ChannelCount);
if ( mFormat == 0 ) { // Check if the format is valid
mChannelCount = 0;
@@ -34,14 +34,14 @@ void cSoundStream::Initialize(unsigned int ChannelCount, unsigned int SampleRate
}
}
void cSoundStream::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
cSound::Play();
Sound::Play();
return;
}
@@ -52,33 +52,33 @@ void cSoundStream::Play() {
Launch();
}
void cSoundStream::Pause() {
void SoundStream::Pause() {
ALCheck( alSourcePause( mSource ) );
}
void cSoundStream::Stop() {
void SoundStream::Stop() {
mIsStreaming = false; // Wait for the thread to terminate
Wait();
}
unsigned int cSoundStream::GetChannelCount() const {
unsigned int SoundStream::GetChannelCount() const {
return mChannelCount;
}
unsigned int cSoundStream::GetSampleRate() const {
unsigned int SoundStream::GetSampleRate() const {
return mSampleRate;
}
cSound::Status cSoundStream::GetState() const {
Status status = cSound::GetState();
Sound::Status SoundStream::GetState() const {
Status status = Sound::GetState();
if ( ( status == cSound::Stopped ) && mIsStreaming ) // To compensate for the lag between Play() and alSourcePlay()
status = cSound::Playing;
if ( ( status == Sound::Stopped ) && mIsStreaming ) // To compensate for the lag between Play() and alSourcePlay()
status = Sound::Playing;
return status;
}
cTime cSoundStream::PlayingOffset() const {
cTime SoundStream::PlayingOffset() const {
if ( mSampleRate && mChannelCount ) {
float secs = 0.f;
@@ -90,7 +90,7 @@ cTime cSoundStream::PlayingOffset() const {
return cTime::Zero;
}
void cSoundStream::PlayingOffset( const cTime &timeOffset ) {
void SoundStream::PlayingOffset( const cTime &timeOffset ) {
Status oldStatus = State();
// Stop the stream
@@ -114,15 +114,15 @@ void cSoundStream::PlayingOffset( const cTime &timeOffset ) {
}
}
void cSoundStream::Loop( const bool& Loop ) {
void SoundStream::Loop( const bool& Loop ) {
mLoop = Loop;
}
bool cSoundStream::Loop() const {
bool SoundStream::Loop() const {
return mLoop;
}
void cSoundStream::Run() {
void SoundStream::Run() {
ALCheck( alGenBuffers( BuffersCount, mBuffers ) );
for ( int i = 0; i < BuffersCount; ++i )
@@ -131,14 +131,14 @@ void cSoundStream::Run() {
// Fill the queue
bool RequestStop = FillQueue();
cSound::Play();
Sound::Play();
while ( mIsStreaming ) {
// The stream has been interrupted !
if ( cSound::GetState() == cSound::Stopped ) {
if ( Sound::GetState() == Sound::Stopped ) {
// User requested to stop : finish the streaming loop
if ( !RequestStop ) {
cSound::Play();
Sound::Play();
} else {
// Streaming is not completed : restart the sound
mIsStreaming = false;
@@ -147,12 +147,12 @@ void cSoundStream::Run() {
// Get the number of buffers that have been processed (ie. ready for reuse)
ALint NbProcessed = 0;
ALCheck( alGetSourcei( cSound::mSource, AL_BUFFERS_PROCESSED, &NbProcessed ) );
ALCheck( alGetSourcei( Sound::mSource, AL_BUFFERS_PROCESSED, &NbProcessed ) );
while ( NbProcessed-- ) {
// Pop the first unused buffer from the queue
ALuint Buffer;
ALCheck( alSourceUnqueueBuffers( cSound::mSource, 1, &Buffer ) );
ALCheck( alSourceUnqueueBuffers( Sound::mSource, 1, &Buffer ) );
// Find its number
Uint32 bufferNum = 0;
@@ -183,22 +183,22 @@ void cSoundStream::Run() {
}
// Leave some time for the other threads if the stream is still playing
if ( cSound::GetState() != cSound::Stopped )
if ( Sound::GetState() != Sound::Stopped )
Sys::Sleep(10);
}
// Stop the playback
cSound::Stop();
Sound::Stop();
// Unqueue any buffer left in the queue
ClearQueue();
// Delete the buffers
ALCheck( alSourcei( cSound::mSource, AL_BUFFER, 0 ) );
ALCheck( alSourcei( Sound::mSource, AL_BUFFER, 0 ) );
ALCheck( alDeleteBuffers( BuffersCount, mBuffers ) );
}
bool cSoundStream::FillAndPushBuffer( const unsigned int& Buffer ) {
bool SoundStream::FillAndPushBuffer( const unsigned int& Buffer ) {
bool RequestStop = false;
// Acquire audio data
@@ -233,13 +233,13 @@ bool cSoundStream::FillAndPushBuffer( const unsigned int& Buffer ) {
ALCheck( alBufferData( buffer, mFormat, Data.Samples, Size, mSampleRate ) );
// Push it into the sound queue
ALCheck( alSourceQueueBuffers( cSound::mSource, 1, &buffer ) );
ALCheck( alSourceQueueBuffers( Sound::mSource, 1, &buffer ) );
}
return RequestStop;
}
bool cSoundStream::FillQueue() {
bool SoundStream::FillQueue() {
// Fill and enqueue all the available buffers
bool RequestStop = false;
@@ -251,18 +251,18 @@ bool cSoundStream::FillQueue() {
return RequestStop;
}
void cSoundStream::ClearQueue() {
void SoundStream::ClearQueue() {
// Get the number of buffers still in the queue
ALint NbQueued;
ALCheck( alGetSourcei( cSound::mSource, AL_BUFFERS_QUEUED, &NbQueued ) );
ALCheck( alGetSourcei( Sound::mSource, AL_BUFFERS_QUEUED, &NbQueued ) );
// Unqueue them all
ALuint Buffer;
for ( ALint i = 0; i < NbQueued; ++i )
ALCheck( alSourceUnqueueBuffers( cSound::mSource, 1, &Buffer ) );
ALCheck( alSourceUnqueueBuffers( Sound::mSource, 1, &Buffer ) );
}
cSound::Status cSoundStream::State() const {
Sound::Status SoundStream::State() const {
return GetState();
}

View File

@@ -1,7 +1,7 @@
#include <eepp/graphics/cconsole.hpp>
#include <eepp/window/cengine.hpp>
#include <eepp/graphics/renderer/cgl.hpp>
#include <eepp/audio/caudiolistener.hpp>
#include <eepp/audio/audiolistener.hpp>
#include <eepp/window/cinput.hpp>
#include <eepp/window/ccursormanager.hpp>
#include <eepp/window/cwindow.hpp>
@@ -728,7 +728,7 @@ void cConsole::CmdSetVolume( const std::vector < String >& params ) {
bool Res = String::FromString<Float>( tFloat, params[1] );
if ( Res && ( tFloat >= 0.0f && tFloat <= 100.0f ) ) {
EE::Audio::cAudioListener::GlobalVolume( tFloat );
EE::Audio::AudioListener::GlobalVolume( tFloat );
PrivPushText( "setvolume " + String::ToStr( tFloat ) );
return;
}

View File

@@ -9,7 +9,7 @@
#include <eepp/graphics/cframebuffermanager.hpp>
#include <eepp/graphics/cvertexbuffermanager.hpp>
#include <eepp/ui/cuimanager.hpp>
#include <eepp/audio/caudiolistener.hpp>
#include <eepp/audio/audiolistener.hpp>
#include <eepp/helper/haikuttf/hkfontmanager.hpp>
#include <eepp/physics/cphysicsmanager.hpp>
#include <eepp/network/ssl/csslsocket.hpp>

View File

@@ -7,11 +7,11 @@ std::string AppPath = Sys::GetProcessPath();
void PlaySound() {
// The sound manager class simplyfies the load of a SoundBuffer and the creation of the Sound
// It manages the sound playing, if the sound channel is already playing, it will open a new channel to play the sound
cSoundManager SoundManager;
SoundManager SoundManager;
if ( SoundManager.LoadFromFile( "sound", AppPath + "assets/sounds/sound.ogg" ) ) {
// Get the sound buffer to display the buffer information
cSoundBuffer& buffer = SoundManager.GetBuffer( "sound" );
SoundBuffer& buffer = SoundManager.GetBuffer( "sound" );
// Display sound informations
std::cout << "sound.ogg :" << std::endl;
@@ -27,7 +27,7 @@ void PlaySound() {
/// Play a music
void PlayMusic() {
// Load an ogg music file
cMusic music;
Music music;
if (!music.OpenFromFile( AppPath + "assets/sounds/music.ogg" ) )
return;
@@ -42,7 +42,7 @@ void PlayMusic() {
music.Play();
// Loop while the music is playing
while ( music.State() == cSound::Playing ) {
while ( music.State() == Sound::Playing ) {
// Leave some CPU time for other processes
Sys::Sleep( 100 );

View File

@@ -91,7 +91,7 @@ void cEETest::Init() {
CreateShaders();
if ( mMusEnabled ) {
Mus = eeNew( cMusic, () );
Mus = eeNew( Music, () );
if ( Mus->OpenFromFile( MyPath + "sounds/music.ogg" ) ) {
Mus->Loop( true );
@@ -818,7 +818,7 @@ void cEETest::LoadTextures() {
}
#endif
mResLoad.Add( eeNew( cSoundLoader, ( &SndMng, "mysound", MyPath + "sounds/sound.ogg" ) ) );
mResLoad.Add( eeNew( SoundLoader, ( &SndMng, "mysound", MyPath + "sounds/sound.ogg" ) ) );
mResLoad.Load( cb::Make1( this, &cEETest::OnTextureLoaded ) );
@@ -1284,7 +1284,7 @@ void cEETest::Input() {
mWindow->FrameRateLimit( 10 );
if ( mMusEnabled && Mus->State() == cSound::Playing )
if ( mMusEnabled && Mus->State() == Sound::Playing )
Mus->Pause();
} else {
@@ -1300,7 +1300,7 @@ void cEETest::Input() {
mWindow->FrameRateLimit( mLastFPSLimit );
if ( mMusEnabled && Mus->State() == cSound::Paused )
if ( mMusEnabled && Mus->State() == Sound::Paused )
Mus->Play();
}

View File

@@ -121,8 +121,8 @@ class cEETest : private cThread {
bool iL1, iL2;
Float HWidth, HHeight;
cMusic * Mus;
cSoundManager SndMng;
Music * Mus;
SoundManager SndMng;
bool DrawBack;