mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-05-28 17:16:29 +03:00
Added a new example, it shows how to manage sounds and music.
Changed ChannelsCount to ChannelCount, since it makes more sense. Now PlayOffset and Duration in sounds and music is returned in seconds, as float.
This commit is contained in:
@@ -16,6 +16,7 @@ syntax: glob
|
||||
./eees*
|
||||
./eeew*
|
||||
./eetest*
|
||||
./eesound*
|
||||
./docs
|
||||
ee.tag
|
||||
log.log
|
||||
|
||||
@@ -17,7 +17,7 @@ class EE_API cAudioDevice {
|
||||
~cAudioDevice();
|
||||
|
||||
/** Get the OpenAL format that matches the given number of channels */
|
||||
static int GetFormatFromChannelsCount( unsigned int ChannelsCount );
|
||||
static int GetFormatFromChannelCount( unsigned int ChannelCount );
|
||||
|
||||
/** Checks if a AL or ALC extension is supported */
|
||||
static bool IsExtensionSupported( const std::string& extension );
|
||||
|
||||
@@ -25,7 +25,7 @@ class EE_API cMusic : public cSoundStream {
|
||||
/** Open a Music file from a file inside a pack file */
|
||||
bool OpenFromPack( cPack * Pack, const std::string& FilePackPath );
|
||||
|
||||
/** Get the Music Duration */
|
||||
/** Get the Music Duration in seconds */
|
||||
float GetDuration() const;
|
||||
private :
|
||||
virtual bool OnStart();
|
||||
|
||||
@@ -87,13 +87,13 @@ class EE_API cSound {
|
||||
/** Get the Sound State */
|
||||
Status State() const;
|
||||
|
||||
/** Get the current playing position of the sound */
|
||||
virtual Uint32 PlayingOffset() const;
|
||||
/** Get the current playing position of the sound in seconds */
|
||||
virtual float PlayingOffset() const;
|
||||
|
||||
/** Set the current playing position of the sound
|
||||
* @param TimeOffset : New playing position, expressed in miliseconds
|
||||
* @param TimeOffset : New playing position, expressed in seconds
|
||||
*/
|
||||
virtual void PlayingOffset( const Uint32& TimeOffset );
|
||||
virtual void PlayingOffset( const float& TimeOffset );
|
||||
|
||||
/** Assignment operator */
|
||||
cSound& operator =(const cSound& Other);
|
||||
|
||||
@@ -28,7 +28,7 @@ class EE_API cSoundBuffer {
|
||||
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 ChannelsCount, 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;
|
||||
@@ -43,10 +43,10 @@ class EE_API cSoundBuffer {
|
||||
unsigned int GetSampleRate() const;
|
||||
|
||||
/** Return the number of Channels */
|
||||
unsigned int GetChannelsCount() const;
|
||||
unsigned int GetChannelCount() const;
|
||||
|
||||
/** Get the Sound Duration */
|
||||
Uint32 GetDuration() const;
|
||||
/** Get the Sound Duration in seconds */
|
||||
float GetDuration() const;
|
||||
|
||||
/** Assignment operator */
|
||||
cSoundBuffer& operator =(const cSoundBuffer& Other);
|
||||
@@ -55,13 +55,13 @@ class EE_API cSoundBuffer {
|
||||
|
||||
unsigned int mBuffer; ///< OpenAL buffer identifier
|
||||
std::vector<Int16> mSamples; ///< Samples buffer
|
||||
Uint32 mDuration; ///< Sound duration, in miliseconds
|
||||
float mDuration; ///< Sound duration, in seconds
|
||||
|
||||
typedef std::set<cSound*> SoundList;
|
||||
mutable SoundList mSounds;
|
||||
|
||||
/** Update the internal buffer with the audio samples */
|
||||
bool Update( unsigned int ChannelsCount, unsigned int SampleRate );
|
||||
bool Update( unsigned int ChannelCount, unsigned int SampleRate );
|
||||
|
||||
void AttachSound( cSound* sound ) const;
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ class EE_API cSoundStream : private cThread, private cSound {
|
||||
/** @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 GetChannelsCount() 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
|
||||
@@ -68,14 +68,13 @@ class EE_API cSoundStream : private cThread, private cSound {
|
||||
Status State() const ;
|
||||
|
||||
/** @brief Get the current playing position of the stream
|
||||
** @return Current playing position, from the beginning of the stream. */
|
||||
Uint32 PlayingOffset() const;
|
||||
** @return Current playing position, from the beginning of the stream in seconds. */
|
||||
float 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 Uint32& timeOffset );
|
||||
** 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 ( in seconds ). */
|
||||
void PlayingOffset( const float &timeOffset );
|
||||
|
||||
/** Set the stream loop state. This parameter is disabled by default
|
||||
* @param Loop True to play in loop, false to play once
|
||||
@@ -90,7 +89,7 @@ class EE_API cSoundStream : private cThread, private cSound {
|
||||
protected:
|
||||
cSoundStream();
|
||||
|
||||
void Initialize(unsigned int ChannelsCount, unsigned int SampleRate);
|
||||
void Initialize(unsigned int ChannelCount, unsigned int SampleRate);
|
||||
private :
|
||||
virtual void Run();
|
||||
|
||||
@@ -117,7 +116,7 @@ class EE_API cSoundStream : private cThread, private cSound {
|
||||
|
||||
bool mIsStreaming; ///< Streaming state (true = playing, false = stopped)
|
||||
unsigned int mBuffers[BuffersCount]; ///< Sound buffers used to store temporary audio data
|
||||
unsigned int mChannelsCount; ///< Number of channels (1 = mono, 2 = stereo, ...)
|
||||
unsigned int mChannelCount; ///< Number of channels (1 = mono, 2 = stereo, ...)
|
||||
unsigned int mSampleRate; ///< Frequency (samples / second)
|
||||
unsigned long mFormat; ///< Format of the internal sound buffers
|
||||
bool mLoop; ///< Loop flag (true to loop, false to play once)
|
||||
|
||||
@@ -24,7 +24,7 @@ class tSoundLoader : public cObjectLoader {
|
||||
tSoundLoader( tSoundManager<T> * SndMngr, const T& id, const char* Data, std::size_t SizeInBytes );
|
||||
|
||||
/** @brief Load the sound from an array of samples */
|
||||
tSoundLoader( tSoundManager<T> * SndMngr, const T& id, const Int16* Samples, std::size_t SamplesCount, unsigned int ChannelsCount, unsigned int SampleRate );
|
||||
tSoundLoader( tSoundManager<T> * SndMngr, const T& id, const Int16* Samples, std::size_t SamplesCount, unsigned int ChannelCount, unsigned int SampleRate );
|
||||
|
||||
/** @brief Load the sound from the Pack file */
|
||||
tSoundLoader( tSoundManager<T> * SndMngr, const T& id, cPack* Pack, const std::string& FilePackPath );
|
||||
@@ -45,7 +45,7 @@ class tSoundLoader : public cObjectLoader {
|
||||
Uint32 mDataSize;
|
||||
const Int16 * mSamples;
|
||||
Uint32 mSamplesCount;
|
||||
Uint32 mChannelsCount;
|
||||
Uint32 mChannelCount;
|
||||
Uint32 mSampleRate;
|
||||
cPack * mPack;
|
||||
|
||||
@@ -88,7 +88,7 @@ tSoundLoader<T>::tSoundLoader( tSoundManager<T> * SndMngr,
|
||||
const T& id,
|
||||
const Int16* Samples,
|
||||
std::size_t SamplesCount,
|
||||
unsigned int ChannelsCount,
|
||||
unsigned int ChannelCount,
|
||||
unsigned int SampleRate
|
||||
) : cObjectLoader( cObjectLoader::SoundLoader ),
|
||||
mLoadType(SND_LT_SAMPLES),
|
||||
@@ -96,7 +96,7 @@ tSoundLoader<T>::tSoundLoader( tSoundManager<T> * SndMngr,
|
||||
mId(id),
|
||||
mSamples(Samples),
|
||||
mSamplesCount(SamplesCount),
|
||||
mChannelsCount(ChannelsCount),
|
||||
mChannelCount(ChannelCount),
|
||||
mSampleRate(SampleRate)
|
||||
{
|
||||
}
|
||||
@@ -153,7 +153,7 @@ void tSoundLoader<T>::LoadFromPack() {
|
||||
|
||||
template <typename T>
|
||||
void tSoundLoader<T>::LoadFromSamples() {
|
||||
mSndMngr->LoadFromSamples( mId, mSamples, mSamplesCount, mChannelsCount, mSampleRate );
|
||||
mSndMngr->LoadFromSamples( mId, mSamples, mSamplesCount, mChannelCount, mSampleRate );
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
||||
@@ -27,9 +27,9 @@ class tSoundManager {
|
||||
** @param id The sound id
|
||||
** @param Samples Pointer to the array of samples in memory
|
||||
** @param SamplesCount Number of samples in the array
|
||||
** @param ChannelsCount Number of channels (1 = mono, 2 = stereo, ...)
|
||||
** @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 ChannelsCount, 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 Pack The Pack file
|
||||
@@ -106,11 +106,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 ChannelsCount, 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, ChannelsCount, SampleRate ) ) {
|
||||
if ( tSound->Buf.LoadFromSamples( Samples, SamplesCount, ChannelCount, SampleRate ) ) {
|
||||
tSound->Snd.push_back( cSound( tSound->Buf ) );
|
||||
return true;
|
||||
}
|
||||
@@ -123,6 +123,9 @@ template <typename T>
|
||||
cSoundBuffer& tSoundManager<T>::GetBuffer( const T& id ) {
|
||||
if ( tSounds.find( id ) != tSounds.end() )
|
||||
return tSounds[id].Buf;
|
||||
|
||||
static cSoundBuffer soundBuf;
|
||||
return soundBuf;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
EE::Gaming Not documented at all.
|
||||
|
||||
@TODO Add more commented examples, showing at least the basic usage of the engine ( 10 or more examples at least ).
|
||||
STATE: 2 examples available. ( 20 % )
|
||||
STATE: 3 examples available. ( 30 % )
|
||||
|
||||
@TODO Improve the map editor ( add triggers, tiles selection to copy paste in other zones of the map, undo/redo actions ).
|
||||
STATE: Needs at least to reoffset tiles and objects for the map resizing.
|
||||
|
||||
21
premake4.lua
21
premake4.lua
@@ -99,7 +99,7 @@ newoption { trigger = "with-gles2", description = "Compile with GLES2 support" }
|
||||
newoption { trigger = "with-gles1", description = "Compile with GLES1 support" }
|
||||
newoption {
|
||||
trigger = "with-backend",
|
||||
description = "Select the backend to use for window and input handling.\n\t\t\tIf no backend is selected or if the selected is not installed the script will search for a backend present in the system, and will use it.\n\t\t\tIt's possible to build with more than one backend support.\n\t\t\t\tUse comma to separate the backends to build ( you can't mix SDL and SDL2, you'll get random crashes ).\n\t\t\t\tExample: --with-backend=SDL2,SFML2",
|
||||
description = "Select the backend to use for window and input handling.\n\t\t\tIf no backend is selected or if the selected is not installed the script will search for a backend present in the system, and will use it.\n\t\t\tIt's possible to build with more than one backend support.\n\t\t\t\tUse comma to separate the backends to build ( you can't mix SDL and SDL2, you'll get random crashes ).\n\t\t\t\tExample: --with-backend=SDL2,SFML",
|
||||
allowed = {
|
||||
{ "SDL", "SDL 1.2" },
|
||||
{ "SDL2", "SDL2 (default and recommended)" },
|
||||
@@ -257,7 +257,8 @@ function build_link_configuration( package_name )
|
||||
elseif ( backend_is("allegro5") ) then
|
||||
links { get_backend_link_name( "allegro" ), "allegro_main" }
|
||||
elseif ( backend_is("SFML") ) then
|
||||
links { get_backend_link_name( "SFML" ) }
|
||||
links { get_backend_link_name( "sfml-system" ) }
|
||||
links { get_backend_link_name( "sfml-window" ) }
|
||||
end
|
||||
else
|
||||
if ( os.is_real("macosx") ) then
|
||||
@@ -267,6 +268,9 @@ function build_link_configuration( package_name )
|
||||
links { "SDL2main" }
|
||||
elseif ( backend_is("allegro5") ) then
|
||||
links { "allegro_main" }
|
||||
elseif ( backend_is("SFML") ) then
|
||||
links { get_backend_link_name( "sfml-system" ) }
|
||||
links { get_backend_link_name( "sfml-window" ) }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -416,9 +420,11 @@ function add_sfml()
|
||||
defines { "EE_BACKEND_SFML_ACTIVE" }
|
||||
|
||||
if not can_add_static_backend("SFML") then
|
||||
table.insert( link_list, get_backend_link_name( "SFML" ) )
|
||||
table.insert( link_list, get_backend_link_name( "sfml-system" ) )
|
||||
table.insert( link_list, get_backend_link_name( "sfml-window" ) )
|
||||
else
|
||||
insert_static_backend( "SFML" )
|
||||
insert_static_backend( "libsfml-system" )
|
||||
insert_static_backend( "libsfml-window" )
|
||||
end
|
||||
end
|
||||
|
||||
@@ -700,6 +706,7 @@ solution "eepp"
|
||||
files { "src/test/*.cpp" }
|
||||
build_link_configuration( "eetest" )
|
||||
|
||||
-- Examples
|
||||
project "eepp-es"
|
||||
kind "WindowedApp"
|
||||
language "C++"
|
||||
@@ -711,3 +718,9 @@ solution "eepp"
|
||||
language "C++"
|
||||
files { "src/examples/empty_window/*.cpp" }
|
||||
build_link_configuration( "eeew" )
|
||||
|
||||
project "eepp-sound"
|
||||
kind "WindowedApp"
|
||||
language "C++"
|
||||
files { "src/examples/sound/*.cpp" }
|
||||
build_link_configuration( "eesound" )
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 2.7.1, 2013-05-28T01:40:53. -->
|
||||
<!-- Written by QtCreator 2.7.1, 2013-05-28T17:37:23. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.ActiveTarget</variable>
|
||||
@@ -48,9 +48,9 @@
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
|
||||
<value type="QByteArray" key="ProjectExplorer.ProjectConfiguration.Id">{388e5431-b31b-42b3-b9ad-9002d279d75d}</value>
|
||||
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
|
||||
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">14</value>
|
||||
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
||||
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
|
||||
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">6</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
|
||||
<value type="QString" key="GenericProjectManager.GenericBuildConfiguration.BuildDirectory">/home/programming/eepp/make/linux</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||
@@ -309,6 +309,46 @@
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">release-win-all</value>
|
||||
<value type="QByteArray" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericBuildConfiguration</value>
|
||||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.14">
|
||||
<value type="QString" key="GenericProjectManager.GenericBuildConfiguration.BuildDirectory">/home/programming/eepp/make/linux</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets"/>
|
||||
<value type="bool" key="GenericProjectManager.GenericMakeStep.Clean">false</value>
|
||||
<value type="QString" key="GenericProjectManager.GenericMakeStep.MakeArguments">-j4 eepp-sound</value>
|
||||
<value type="QString" key="GenericProjectManager.GenericMakeStep.MakeCommand">make</value>
|
||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
|
||||
<value type="QByteArray" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
|
||||
</valuemap>
|
||||
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
|
||||
<value type="QByteArray" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
|
||||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||
<value type="QString" key="ProjectExplorer.ProcessStep.Arguments">clean</value>
|
||||
<value type="QString" key="ProjectExplorer.ProcessStep.Command">make</value>
|
||||
<value type="QString" key="ProjectExplorer.ProcessStep.WorkingDirectory">%{buildDir}</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Custom Process Step</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
|
||||
<value type="QByteArray" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.ProcessStep</value>
|
||||
</valuemap>
|
||||
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
|
||||
<value type="QByteArray" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
|
||||
</valuemap>
|
||||
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
|
||||
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
|
||||
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">debug-test</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">debug-sound</value>
|
||||
<value type="QByteArray" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericBuildConfiguration</value>
|
||||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.2">
|
||||
<value type="QString" key="GenericProjectManager.GenericBuildConfiguration.BuildDirectory">/home/programming/eepp/make/linux</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||
@@ -629,7 +669,7 @@
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">release-es</value>
|
||||
<value type="QByteArray" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericBuildConfiguration</value>
|
||||
</valuemap>
|
||||
<value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">14</value>
|
||||
<value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">15</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
|
||||
@@ -926,7 +966,54 @@
|
||||
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||
</valuemap>
|
||||
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">6</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.6">
|
||||
<value type="bool" key="Analyzer.Project.UseGlobal">true</value>
|
||||
<valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/>
|
||||
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectBusEvents">false</value>
|
||||
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectSystime">false</value>
|
||||
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableBranchSim">false</value>
|
||||
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableCacheSim">false</value>
|
||||
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableEventToolTips">true</value>
|
||||
<value type="double" key="Analyzer.Valgrind.Callgrind.MinimumCostRatio">0.01</value>
|
||||
<value type="double" key="Analyzer.Valgrind.Callgrind.VisualisationMinimumCostRatio">10</value>
|
||||
<value type="bool" key="Analyzer.Valgrind.FilterExternalIssues">true</value>
|
||||
<value type="int" key="Analyzer.Valgrind.NumCallers">25</value>
|
||||
<valuelist type="QVariantList" key="Analyzer.Valgrind.RemovedSuppressionFiles"/>
|
||||
<value type="bool" key="Analyzer.Valgrind.TrackOrigins">true</value>
|
||||
<value type="QString" key="Analyzer.Valgrind.ValgrindExecutable">valgrind</value>
|
||||
<valuelist type="QVariantList" key="Analyzer.Valgrind.VisibleErrorKinds">
|
||||
<value type="int">0</value>
|
||||
<value type="int">1</value>
|
||||
<value type="int">2</value>
|
||||
<value type="int">3</value>
|
||||
<value type="int">4</value>
|
||||
<value type="int">5</value>
|
||||
<value type="int">6</value>
|
||||
<value type="int">7</value>
|
||||
<value type="int">8</value>
|
||||
<value type="int">9</value>
|
||||
<value type="int">10</value>
|
||||
<value type="int">11</value>
|
||||
<value type="int">12</value>
|
||||
<value type="int">13</value>
|
||||
<value type="int">14</value>
|
||||
</valuelist>
|
||||
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Arguments"></value>
|
||||
<value type="int" key="ProjectExplorer.CustomExecutableRunConfiguration.BaseEnvironmentBase">2</value>
|
||||
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Executable">/home/programming/eepp/eesound-debug</value>
|
||||
<value type="bool" key="ProjectExplorer.CustomExecutableRunConfiguration.UseTerminal">false</value>
|
||||
<valuelist type="QVariantList" key="ProjectExplorer.CustomExecutableRunConfiguration.UserEnvironmentChanges"/>
|
||||
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.WorkingDirectory">%{buildDir}</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Run /home/programming/eepp/eesound-debug</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">eesound-debug</value>
|
||||
<value type="QByteArray" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
|
||||
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebugger">true</value>
|
||||
<value type="bool" key="RunConfiguration.UseMultiProcess">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||
</valuemap>
|
||||
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">7</value>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
|
||||
@@ -608,3 +608,4 @@
|
||||
../../src/eepp/audio/csoundfile.hpp
|
||||
../../src/eepp/audio/openal.hpp
|
||||
../../src/eepp/window/backend/SDL2/cbackendsdl2.cpp
|
||||
../../src/examples/sound/sound.cpp
|
||||
|
||||
@@ -78,10 +78,10 @@ bool cAudioDevice::IsExtensionSupported( const std::string& extension ) {
|
||||
return alIsExtensionPresent( extension.c_str() ) != AL_FALSE;
|
||||
}
|
||||
|
||||
int cAudioDevice::GetFormatFromChannelsCount( unsigned int ChannelsCount ) {
|
||||
int cAudioDevice::GetFormatFromChannelCount( unsigned int ChannelCount ) {
|
||||
EnsureALInit();
|
||||
|
||||
switch ( ChannelsCount ) {
|
||||
switch ( ChannelCount ) {
|
||||
case 1 : return AL_FORMAT_MONO16;
|
||||
case 2 : return AL_FORMAT_STEREO16;
|
||||
case 4 : return alGetEnumValue("AL_FORMAT_QUAD16");
|
||||
|
||||
@@ -50,10 +50,10 @@ bool cMusic::OpenFromFile( const std::string& Filename ) {
|
||||
}
|
||||
|
||||
// Compute the duration
|
||||
mDuration = static_cast<float>( mFile->GetSamplesCount() ) / mFile->GetSampleRate() / mFile->GetChannelsCount();
|
||||
mDuration = static_cast<float>( mFile->GetSamplesCount() ) / mFile->GetSampleRate() / mFile->GetChannelCount();
|
||||
|
||||
// Initialize the stream
|
||||
Initialize( mFile->GetChannelsCount(), mFile->GetSampleRate() );
|
||||
Initialize( mFile->GetChannelCount(), mFile->GetSampleRate() );
|
||||
|
||||
cLog::instance()->Write( "Music file " + Filename + " loaded." );
|
||||
|
||||
@@ -74,7 +74,7 @@ bool cMusic::OpenFromMemory( const char * Data, std::size_t SizeInBytes ) {
|
||||
|
||||
mDuration = static_cast<float>( mFile->GetSamplesCount() ) / mFile->GetSampleRate(); // Compute the duration
|
||||
|
||||
Initialize( mFile->GetChannelsCount(), mFile->GetSampleRate() ); // Initialize the stream
|
||||
Initialize( mFile->GetChannelCount(), mFile->GetSampleRate() ); // Initialize the stream
|
||||
|
||||
cLog::instance()->Write( "Music file loaded from memory." );
|
||||
|
||||
|
||||
@@ -164,15 +164,16 @@ cSound::Status cSound::GetState() const {
|
||||
return cSound::Stopped;
|
||||
}
|
||||
|
||||
Uint32 cSound::PlayingOffset() const {
|
||||
float cSound::PlayingOffset() const {
|
||||
float Seconds = 0.f;
|
||||
|
||||
ALCheck( alGetSourcef( mSource, AL_SEC_OFFSET, &Seconds ) );
|
||||
|
||||
return static_cast<Uint32> ( Seconds * 1000 );
|
||||
return Seconds;
|
||||
}
|
||||
|
||||
void cSound::PlayingOffset( const Uint32& TimeOffset ) {
|
||||
ALCheck( alSourcef( mSource, AL_SEC_OFFSET, TimeOffset / 1000.f ) );
|
||||
void cSound::PlayingOffset( const float &TimeOffset ) {
|
||||
ALCheck( alSourcef( mSource, AL_SEC_OFFSET, TimeOffset ) );
|
||||
}
|
||||
|
||||
cSound& cSound::operator =( const cSound& Other ) {
|
||||
|
||||
@@ -26,7 +26,7 @@ cSoundBuffer::cSoundBuffer(const cSoundBuffer& Copy) :
|
||||
EnsureALInit();
|
||||
|
||||
ALCheck( alGenBuffers( 1, &mBuffer ) );
|
||||
Update( Copy.GetChannelsCount(), Copy.GetSampleRate() );
|
||||
Update( Copy.GetChannelCount(), Copy.GetSampleRate() );
|
||||
}
|
||||
|
||||
cSoundBuffer::~cSoundBuffer() {
|
||||
@@ -60,7 +60,7 @@ bool cSoundBuffer::LoadFromFile(const std::string& Filename) {
|
||||
if ( NULL != File ) {
|
||||
// Get the sound parameters
|
||||
std::size_t NbSamples = File->GetSamplesCount();
|
||||
unsigned int ChannelsCount = File->GetChannelsCount();
|
||||
unsigned int ChannelCount = File->GetChannelCount();
|
||||
unsigned int SampleRate = File->GetSampleRate();
|
||||
|
||||
// Read the samples from the opened file
|
||||
@@ -72,7 +72,7 @@ bool cSoundBuffer::LoadFromFile(const std::string& Filename) {
|
||||
// Update the internal buffer with the new samples
|
||||
eeDelete( File );
|
||||
|
||||
return Update( ChannelsCount, SampleRate );
|
||||
return Update( ChannelCount, SampleRate );
|
||||
} else {
|
||||
cLog::instance()->Write( "Failed to read audio data from file \"" + Filename + "\"" );
|
||||
|
||||
@@ -105,7 +105,7 @@ bool cSoundBuffer::LoadFromMemory( const char* Data, std::size_t SizeInBytes ) {
|
||||
if ( NULL != File ) {
|
||||
// Get the sound parameters
|
||||
std::size_t NbSamples = File->GetSamplesCount();
|
||||
unsigned int ChannelsCount = File->GetChannelsCount();
|
||||
unsigned int ChannelCount = File->GetChannelCount();
|
||||
unsigned int SampleRate = File->GetSampleRate();
|
||||
|
||||
// Read the samples from the opened file
|
||||
@@ -117,7 +117,7 @@ bool cSoundBuffer::LoadFromMemory( const char* Data, std::size_t SizeInBytes ) {
|
||||
// Update the internal buffer with the new samples
|
||||
eeDelete( File );
|
||||
|
||||
return Update( ChannelsCount, SampleRate );
|
||||
return Update( ChannelCount, SampleRate );
|
||||
} else {
|
||||
cLog::instance()->Write( "Failed to read audio data from file in memory" );
|
||||
|
||||
@@ -131,15 +131,15 @@ bool cSoundBuffer::LoadFromMemory( const char* Data, std::size_t SizeInBytes ) {
|
||||
}
|
||||
}
|
||||
|
||||
bool cSoundBuffer::LoadFromSamples( const Int16 * Samples, std::size_t SamplesCount, unsigned int ChannelsCount, unsigned int SampleRate ) {
|
||||
if ( Samples && SamplesCount && ChannelsCount && SampleRate ) {
|
||||
bool cSoundBuffer::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 );
|
||||
|
||||
cLog::instance()->Write( "Sound file loaded from memory samples." );
|
||||
|
||||
// Update the internal buffer with the new samples
|
||||
return Update( ChannelsCount, SampleRate );
|
||||
return Update( ChannelCount, SampleRate );
|
||||
} else {
|
||||
// Error...
|
||||
cLog::instance()->Write( "Failed to load sound buffer from memory Samples" );
|
||||
@@ -149,7 +149,7 @@ bool cSoundBuffer::LoadFromSamples( const Int16 * Samples, std::size_t SamplesCo
|
||||
|
||||
bool cSoundBuffer::SaveToFile(const std::string& Filename) const {
|
||||
// Create the sound file in write mode
|
||||
std::auto_ptr<cSoundFile> File( cSoundFile::CreateWrite( Filename, GetChannelsCount(), GetSampleRate() ) );
|
||||
std::auto_ptr<cSoundFile> File( cSoundFile::CreateWrite( Filename, GetChannelCount(), GetSampleRate() ) );
|
||||
|
||||
if ( File.get() ) {
|
||||
// Write the samples to the opened file
|
||||
@@ -176,13 +176,13 @@ unsigned int cSoundBuffer::GetSampleRate() const {
|
||||
return SampleRate;
|
||||
}
|
||||
|
||||
unsigned int cSoundBuffer::GetChannelsCount() const {
|
||||
ALint ChannelsCount;
|
||||
ALCheck( alGetBufferi( mBuffer, AL_CHANNELS, &ChannelsCount ) );
|
||||
return ChannelsCount;
|
||||
unsigned int cSoundBuffer::GetChannelCount() const {
|
||||
ALint ChannelCount;
|
||||
ALCheck( alGetBufferi( mBuffer, AL_CHANNELS, &ChannelCount ) );
|
||||
return ChannelCount;
|
||||
}
|
||||
|
||||
Uint32 cSoundBuffer::GetDuration() const {
|
||||
float cSoundBuffer::GetDuration() const {
|
||||
return mDuration;
|
||||
}
|
||||
|
||||
@@ -197,13 +197,13 @@ cSoundBuffer& cSoundBuffer::operator =( const cSoundBuffer& Other ) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool cSoundBuffer::Update( unsigned int ChannelsCount, unsigned int SampleRate ) {
|
||||
bool cSoundBuffer::Update( unsigned int ChannelCount, unsigned int SampleRate ) {
|
||||
// Check parameters
|
||||
if ( !SampleRate || !ChannelsCount || mSamples.empty() )
|
||||
if ( !SampleRate || !ChannelCount || mSamples.empty() )
|
||||
return false;
|
||||
|
||||
// Find the good format according to the number of channels
|
||||
ALenum Format = cAudioDevice::GetFormatFromChannelsCount( ChannelsCount );
|
||||
ALenum Format = cAudioDevice::GetFormatFromChannelCount( ChannelCount );
|
||||
|
||||
// Check if the format is valid
|
||||
if ( Format == 0 ) {
|
||||
@@ -216,7 +216,7 @@ bool cSoundBuffer::Update( unsigned int ChannelsCount, unsigned int SampleRate )
|
||||
ALCheck( alBufferData( mBuffer, Format, &mSamples[0], Size, SampleRate ) );
|
||||
|
||||
// Compute the duration
|
||||
mDuration = static_cast<Uint32>( 1000 * mSamples.size() ) / SampleRate / ChannelsCount;
|
||||
mDuration = (float)mSamples.size() / (float)SampleRate / (float)ChannelCount;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace EE { namespace Audio {
|
||||
|
||||
cSoundFile::cSoundFile() :
|
||||
mNbSamples (0),
|
||||
mChannelsCount(0),
|
||||
mChannelCount(0),
|
||||
mSampleRate (0)
|
||||
{
|
||||
}
|
||||
@@ -29,15 +29,15 @@ cSoundFile * cSoundFile::CreateRead( const std::string& Filename ) {
|
||||
// Open it for reading
|
||||
if ( NULL != File ) {
|
||||
std::size_t SamplesCount;
|
||||
unsigned int ChannelsCount;
|
||||
unsigned int ChannelCount;
|
||||
unsigned int SampleRate;
|
||||
|
||||
if ( File->OpenRead( Filename, SamplesCount, ChannelsCount, SampleRate ) ) {
|
||||
if ( File->OpenRead( Filename, SamplesCount, ChannelCount, SampleRate ) ) {
|
||||
File->mFilename = Filename;
|
||||
File->mData = NULL;
|
||||
File->mSize = 0;
|
||||
File->mNbSamples = SamplesCount;
|
||||
File->mChannelsCount = ChannelsCount;
|
||||
File->mChannelCount = ChannelCount;
|
||||
File->mSampleRate = SampleRate;
|
||||
} else {
|
||||
eeDelete( File );
|
||||
@@ -60,15 +60,15 @@ cSoundFile * cSoundFile::CreateRead( const char* Data, std::size_t SizeInMemory
|
||||
// Open it for reading
|
||||
if ( NULL != File ) {
|
||||
std::size_t SamplesCount;
|
||||
unsigned int ChannelsCount;
|
||||
unsigned int ChannelCount;
|
||||
unsigned int SampleRate;
|
||||
|
||||
if ( File->OpenRead( Data, SizeInMemory, SamplesCount, ChannelsCount, SampleRate ) ) {
|
||||
if ( File->OpenRead( Data, SizeInMemory, SamplesCount, ChannelCount, SampleRate ) ) {
|
||||
File->mFilename = "";
|
||||
File->mData = Data;
|
||||
File->mSize = SizeInMemory;
|
||||
File->mNbSamples = SamplesCount;
|
||||
File->mChannelsCount = ChannelsCount;
|
||||
File->mChannelCount = ChannelCount;
|
||||
File->mSampleRate = SampleRate;
|
||||
} else {
|
||||
eeDelete( File );
|
||||
@@ -79,7 +79,7 @@ cSoundFile * cSoundFile::CreateRead( const char* Data, std::size_t SizeInMemory
|
||||
return File;
|
||||
}
|
||||
|
||||
cSoundFile * cSoundFile::CreateWrite( const std::string& Filename, unsigned int ChannelsCount, unsigned int SampleRate ) {
|
||||
cSoundFile * cSoundFile::CreateWrite( const std::string& Filename, unsigned int ChannelCount, unsigned int SampleRate ) {
|
||||
// Create the file according to its type
|
||||
cSoundFile * File = NULL;
|
||||
|
||||
@@ -90,12 +90,12 @@ cSoundFile * cSoundFile::CreateWrite( const std::string& Filename, unsigned int
|
||||
|
||||
// Open it for writing
|
||||
if ( NULL != File ) {
|
||||
if ( File->OpenWrite( Filename, ChannelsCount, SampleRate ) ) {
|
||||
if ( File->OpenWrite( Filename, ChannelCount, SampleRate ) ) {
|
||||
File->mFilename = "";
|
||||
File->mData = NULL;
|
||||
File->mSize = 0;
|
||||
File->mNbSamples = 0;
|
||||
File->mChannelsCount = ChannelsCount;
|
||||
File->mChannelCount = ChannelCount;
|
||||
File->mSampleRate = SampleRate;
|
||||
} else {
|
||||
eeDelete( File );
|
||||
@@ -111,8 +111,8 @@ std::size_t cSoundFile::GetSamplesCount() const
|
||||
return mNbSamples;
|
||||
}
|
||||
|
||||
unsigned int cSoundFile::GetChannelsCount() const {
|
||||
return mChannelsCount;
|
||||
unsigned int cSoundFile::GetChannelCount() const {
|
||||
return mChannelCount;
|
||||
}
|
||||
|
||||
unsigned int cSoundFile::GetSampleRate() const {
|
||||
@@ -122,10 +122,10 @@ unsigned int cSoundFile::GetSampleRate() const {
|
||||
bool cSoundFile::Restart() {
|
||||
if ( mData ) {
|
||||
// Reopen from memory
|
||||
return OpenRead( mData, mSize, mNbSamples, mChannelsCount, mSampleRate );
|
||||
return OpenRead( mData, mSize, mNbSamples, mChannelCount, mSampleRate );
|
||||
} else if ( mFilename != "" ) {
|
||||
// Reopen from file
|
||||
return OpenRead( mFilename, mNbSamples, mChannelsCount, mSampleRate );
|
||||
return OpenRead( mFilename, mNbSamples, mChannelCount, mSampleRate );
|
||||
} else {
|
||||
cLog::instance()->Write( "Warning : trying to restart a sound opened in write mode, which is not allowed" );
|
||||
return false;
|
||||
|
||||
@@ -15,7 +15,7 @@ class EE_API cSoundFile {
|
||||
static cSoundFile * CreateRead(const char* Data, std::size_t SizeInBytes);
|
||||
|
||||
/** @brief Open a sound file for writing */
|
||||
static cSoundFile * CreateWrite(const std::string& Filename, unsigned int ChannelsCount, unsigned int SampleRate);
|
||||
static cSoundFile * CreateWrite(const std::string& Filename, unsigned int ChannelCount, unsigned int SampleRate);
|
||||
|
||||
virtual ~cSoundFile();
|
||||
|
||||
@@ -25,7 +25,7 @@ class EE_API cSoundFile {
|
||||
/** @brief Get the number of channels used by the sound
|
||||
* @return Number of channels (1 = mono, 2 = stereo)
|
||||
*/
|
||||
unsigned int GetChannelsCount() const;
|
||||
unsigned int GetChannelCount() const;
|
||||
|
||||
/** @brief Get the sample rate of the sound
|
||||
* @return Sample rate, in samples per second
|
||||
@@ -52,14 +52,14 @@ class EE_API cSoundFile {
|
||||
protected :
|
||||
cSoundFile();
|
||||
|
||||
virtual bool OpenRead(const std::string& Filename, std::size_t& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate);
|
||||
virtual bool OpenRead(const std::string& Filename, std::size_t& NbSamples, unsigned int& ChannelCount, unsigned int& SampleRate);
|
||||
|
||||
virtual bool OpenRead(const char* Data, std::size_t SizeInBytes, std::size_t& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate);
|
||||
virtual bool OpenRead(const char* Data, std::size_t SizeInBytes, std::size_t& NbSamples, unsigned int& ChannelCount, unsigned int& SampleRate);
|
||||
|
||||
virtual bool OpenWrite(const std::string& Filename, unsigned int ChannelsCount, unsigned int SampleRate);
|
||||
virtual bool OpenWrite(const std::string& Filename, unsigned int ChannelCount, unsigned int SampleRate);
|
||||
|
||||
std::size_t mNbSamples;
|
||||
unsigned int mChannelsCount;
|
||||
unsigned int mChannelCount;
|
||||
unsigned int mSampleRate;
|
||||
std::string mFilename;
|
||||
const char * mData;
|
||||
|
||||
@@ -49,7 +49,7 @@ bool cSoundFileDefault::IsFileSupported( const char* Data, std::size_t SizeInByt
|
||||
return false;
|
||||
}
|
||||
|
||||
bool cSoundFileDefault::OpenRead( const std::string& Filename, std::size_t& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate ) {
|
||||
bool cSoundFileDefault::OpenRead( const std::string& Filename, std::size_t& NbSamples, unsigned int& ChannelCount, unsigned int& SampleRate ) {
|
||||
// If the file is already opened, first close it
|
||||
if ( NULL != mFile )
|
||||
sf_close( mFile );
|
||||
@@ -64,18 +64,18 @@ bool cSoundFileDefault::OpenRead( const std::string& Filename, std::size_t& NbSa
|
||||
}
|
||||
|
||||
// Set the sound parameters
|
||||
mChannelsCount = fileInfos.channels;
|
||||
mChannelCount = fileInfos.channels;
|
||||
mSampleRate = fileInfos.samplerate;
|
||||
mNbSamples = static_cast<std::size_t>(fileInfos.frames) * mChannelsCount;
|
||||
mNbSamples = static_cast<std::size_t>(fileInfos.frames) * mChannelCount;
|
||||
|
||||
ChannelsCount = mChannelsCount;
|
||||
ChannelCount = mChannelCount;
|
||||
SampleRate = mSampleRate;
|
||||
NbSamples = mNbSamples;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cSoundFileDefault::OpenRead( const char* Data, std::size_t SizeInBytes, std::size_t& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate ) {
|
||||
bool cSoundFileDefault::OpenRead( const char* Data, std::size_t SizeInBytes, std::size_t& NbSamples, unsigned int& ChannelCount, unsigned int& SampleRate ) {
|
||||
// If the file is already opened, first close it
|
||||
if ( NULL != mFile )
|
||||
sf_close( mFile );
|
||||
@@ -93,18 +93,18 @@ bool cSoundFileDefault::OpenRead( const char* Data, std::size_t SizeInBytes, std
|
||||
}
|
||||
|
||||
// Set the sound parameters
|
||||
mChannelsCount = fileInfos.channels;
|
||||
mChannelCount = fileInfos.channels;
|
||||
mSampleRate = fileInfos.samplerate;
|
||||
mNbSamples = static_cast<std::size_t>(fileInfos.frames) * mChannelsCount;
|
||||
mNbSamples = static_cast<std::size_t>(fileInfos.frames) * mChannelCount;
|
||||
|
||||
ChannelsCount = mChannelsCount;
|
||||
ChannelCount = mChannelCount;
|
||||
SampleRate = mSampleRate;
|
||||
NbSamples = mNbSamples;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cSoundFileDefault::OpenWrite( const std::string& Filename, unsigned int ChannelsCount, unsigned int SampleRate ) {
|
||||
bool cSoundFileDefault::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 );
|
||||
@@ -119,7 +119,7 @@ bool cSoundFileDefault::OpenWrite( const std::string& Filename, unsigned int Cha
|
||||
|
||||
// Fill the sound infos with parameters
|
||||
SF_INFO fileInfos;
|
||||
fileInfos.channels = ChannelsCount;
|
||||
fileInfos.channels = ChannelCount;
|
||||
fileInfos.samplerate = SampleRate;
|
||||
fileInfos.format = Format | (Format == SF_FORMAT_OGG ? SF_FORMAT_VORBIS : SF_FORMAT_PCM_16);
|
||||
|
||||
|
||||
@@ -28,11 +28,11 @@ class EE_API cSoundFileDefault : public cSoundFile {
|
||||
|
||||
virtual void Seek( Uint32 timeOffset );
|
||||
private :
|
||||
virtual bool OpenRead( const std::string& Filename, std::size_t& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate );
|
||||
virtual bool OpenRead( const std::string& Filename, std::size_t& NbSamples, unsigned int& ChannelCount, unsigned int& SampleRate );
|
||||
|
||||
virtual bool OpenRead( const char* Data, std::size_t SizeInBytes, std::size_t& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate );
|
||||
virtual bool OpenRead( const char* Data, std::size_t SizeInBytes, std::size_t& NbSamples, unsigned int& ChannelCount, unsigned int& SampleRate );
|
||||
|
||||
virtual bool OpenWrite( const std::string& Filename, unsigned int ChannelsCount, unsigned int SampleRate );
|
||||
virtual bool OpenWrite( const std::string& Filename, unsigned int ChannelCount, unsigned int SampleRate );
|
||||
|
||||
static int GetFormatFromFilename(const std::string& Filename);
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace EE { namespace Audio {
|
||||
|
||||
cSoundFileOgg::cSoundFileOgg() :
|
||||
mStream (NULL),
|
||||
mChannelsCount(0)
|
||||
mChannelCount(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -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& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate ) {
|
||||
bool cSoundFileOgg::OpenRead( const std::string& Filename, std::size_t& NbSamples, unsigned int& ChannelCount, unsigned int& SampleRate ) {
|
||||
// Close the file if already opened
|
||||
if ( NULL != mStream )
|
||||
stb_vorbis_close( mStream );
|
||||
@@ -57,14 +57,14 @@ bool cSoundFileOgg::OpenRead( const std::string& Filename, std::size_t& NbSample
|
||||
|
||||
// Get the music parameters
|
||||
stb_vorbis_info Infos = stb_vorbis_get_info( mStream );
|
||||
ChannelsCount = mChannelsCount = Infos.channels;
|
||||
ChannelCount = mChannelCount = Infos.channels;
|
||||
SampleRate = Infos.sample_rate;
|
||||
NbSamples = static_cast<std::size_t>( stb_vorbis_stream_length_in_samples( mStream ) * ChannelsCount );
|
||||
NbSamples = static_cast<std::size_t>( stb_vorbis_stream_length_in_samples( mStream ) * ChannelCount );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cSoundFileOgg::OpenRead( const char* Data, std::size_t SizeInBytes, std::size_t& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate ) {
|
||||
bool cSoundFileOgg::OpenRead( const char* Data, std::size_t SizeInBytes, std::size_t& NbSamples, unsigned int& ChannelCount, unsigned int& SampleRate ) {
|
||||
// Close the file if already opened
|
||||
if ( NULL != mStream )
|
||||
stb_vorbis_close( mStream );
|
||||
@@ -82,18 +82,18 @@ bool cSoundFileOgg::OpenRead( const char* Data, std::size_t SizeInBytes, std::si
|
||||
|
||||
// Get the music parameters
|
||||
stb_vorbis_info Infos = stb_vorbis_get_info( mStream );
|
||||
ChannelsCount = mChannelsCount = Infos.channels;
|
||||
ChannelCount = mChannelCount = Infos.channels;
|
||||
SampleRate = Infos.sample_rate;
|
||||
NbSamples = static_cast<std::size_t>( stb_vorbis_stream_length_in_samples( mStream ) * ChannelsCount );
|
||||
NbSamples = static_cast<std::size_t>( stb_vorbis_stream_length_in_samples( mStream ) * ChannelCount );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::size_t cSoundFileOgg::Read( Int16 * Data, std::size_t NbSamples ) {
|
||||
if ( NULL != mStream && Data && NbSamples ) {
|
||||
int Read = stb_vorbis_get_samples_short_interleaved( mStream, mChannelsCount, Data, static_cast<int>( NbSamples ) );
|
||||
int Read = stb_vorbis_get_samples_short_interleaved( mStream, mChannelCount, Data, static_cast<int>( NbSamples ) );
|
||||
|
||||
std::size_t scount = Read * mChannelsCount;
|
||||
std::size_t scount = Read * mChannelCount;
|
||||
|
||||
return scount;
|
||||
}
|
||||
|
||||
@@ -23,12 +23,12 @@ class EE_API cSoundFileOgg : public cSoundFile {
|
||||
|
||||
virtual void Seek( Uint32 timeOffset );
|
||||
private :
|
||||
virtual bool OpenRead(const std::string& Filename, std::size_t& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate);
|
||||
virtual bool OpenRead(const std::string& Filename, std::size_t& NbSamples, unsigned int& ChannelCount, unsigned int& SampleRate);
|
||||
|
||||
virtual bool OpenRead(const char* Data, std::size_t SizeInBytes, std::size_t& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate);
|
||||
virtual bool OpenRead(const char* Data, std::size_t SizeInBytes, std::size_t& NbSamples, unsigned int& ChannelCount, unsigned int& SampleRate);
|
||||
|
||||
stb_vorbis * mStream; ///< Vorbis stream
|
||||
unsigned int mChannelsCount; ///< Number of channels (1 = mono, 2 = stereo)
|
||||
unsigned int mChannelCount; ///< Number of channels (1 = mono, 2 = stereo)
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace EE { namespace Audio {
|
||||
|
||||
cSoundStream::cSoundStream() :
|
||||
mIsStreaming(false),
|
||||
mChannelsCount(0),
|
||||
mChannelCount(0),
|
||||
mSampleRate (0),
|
||||
mFormat (0),
|
||||
mLoop(false),
|
||||
@@ -20,15 +20,15 @@ cSoundStream::~cSoundStream() {
|
||||
Stop(); // Stop the sound if it was playing
|
||||
}
|
||||
|
||||
void cSoundStream::Initialize(unsigned int ChannelsCount, unsigned int SampleRate) {
|
||||
mChannelsCount = ChannelsCount;
|
||||
void cSoundStream::Initialize(unsigned int ChannelCount, unsigned int SampleRate) {
|
||||
mChannelCount = ChannelCount;
|
||||
mSampleRate = SampleRate;
|
||||
|
||||
// Deduce the format from the number of channels
|
||||
mFormat = cAudioDevice::GetFormatFromChannelsCount(ChannelsCount);
|
||||
mFormat = cAudioDevice::GetFormatFromChannelCount(ChannelCount);
|
||||
|
||||
if ( mFormat == 0 ) { // Check if the format is valid
|
||||
mChannelsCount = 0;
|
||||
mChannelCount = 0;
|
||||
mSampleRate = 0;
|
||||
cLog::instance()->Write( "Unsupported number of channels." );
|
||||
}
|
||||
@@ -61,8 +61,8 @@ void cSoundStream::Stop() {
|
||||
Wait();
|
||||
}
|
||||
|
||||
unsigned int cSoundStream::GetChannelsCount() const {
|
||||
return mChannelsCount;
|
||||
unsigned int cSoundStream::GetChannelCount() const {
|
||||
return mChannelCount;
|
||||
}
|
||||
|
||||
unsigned int cSoundStream::GetSampleRate() const {
|
||||
@@ -78,11 +78,21 @@ cSound::Status cSoundStream::GetState() const {
|
||||
return status;
|
||||
}
|
||||
|
||||
Uint32 cSoundStream::PlayingOffset() const {
|
||||
return static_cast<Uint32>( cSound::PlayingOffset() ) * 1000 + 1000 * mSamplesProcessed / mSampleRate / mChannelsCount;
|
||||
float cSoundStream::PlayingOffset() const {
|
||||
//return static_cast<Uint32>( cSound::PlayingOffset() ) * 1000 + 1000 * mSamplesProcessed / mSampleRate / mChannelCount;
|
||||
|
||||
if ( mSampleRate && mChannelCount ) {
|
||||
float secs = 0.f;
|
||||
|
||||
ALCheck( alGetSourcef( mSource, AL_SEC_OFFSET, &secs ) );
|
||||
|
||||
return secs + (float)mSamplesProcessed / (float)mSampleRate / (float)mChannelCount;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void cSoundStream::PlayingOffset( const Uint32& timeOffset ) {
|
||||
void cSoundStream::PlayingOffset(const float &timeOffset ) {
|
||||
// Stop the stream
|
||||
Stop();
|
||||
|
||||
@@ -90,7 +100,7 @@ void cSoundStream::PlayingOffset( const Uint32& timeOffset ) {
|
||||
OnSeek( timeOffset );
|
||||
|
||||
// Restart streaming
|
||||
mSamplesProcessed = static_cast<Uint32>( timeOffset ) * mSampleRate * mChannelsCount / 1000;
|
||||
mSamplesProcessed = static_cast<Uint32>( timeOffset ) * mSampleRate * mChannelCount;
|
||||
|
||||
mIsStreaming = true;
|
||||
|
||||
|
||||
71
src/examples/sound/sound.cpp
Normal file
71
src/examples/sound/sound.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
#include <eepp/ee.hpp>
|
||||
|
||||
// Get the process path to be used to load the sounds ( it is safer )
|
||||
std::string AppPath = Sys::GetProcessPath();
|
||||
|
||||
/// Play a sound
|
||||
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;
|
||||
|
||||
if ( SoundManager.LoadFromFile( "sound", AppPath + "assets/sounds/sound.ogg" ) ) {
|
||||
// Get the sound buffer to display the buffer information
|
||||
cSoundBuffer& buffer = SoundManager.GetBuffer( "sound" );
|
||||
|
||||
// Display sound informations
|
||||
std::cout << "sound.ogg :" << std::endl;
|
||||
std::cout << " " << buffer.GetDuration() << " seconds" << std::endl;
|
||||
std::cout << " " << buffer.GetSampleRate() << " samples / sec" << std::endl;
|
||||
std::cout << " " << buffer.GetChannelCount() << " channels" << std::endl;
|
||||
|
||||
// Play the sound
|
||||
SoundManager.Play( "sound" );
|
||||
}
|
||||
}
|
||||
|
||||
/// Play a music
|
||||
void playMusic() {
|
||||
// Load an ogg music file
|
||||
cMusic music;
|
||||
|
||||
if (!music.OpenFromFile( AppPath + "assets/sounds/music.ogg" ) )
|
||||
return;
|
||||
|
||||
// Display music informations
|
||||
std::cout << "music.ogg :" << std::endl;
|
||||
std::cout << " " << music.GetDuration() << " seconds" << std::endl;
|
||||
std::cout << " " << music.GetSampleRate() << " samples / sec" << std::endl;
|
||||
std::cout << " " << music.GetChannelCount() << " channels" << std::endl;
|
||||
|
||||
// Play it
|
||||
music.Play();
|
||||
|
||||
// Loop while the music is playing
|
||||
while ( music.State() == cSound::Playing ) {
|
||||
// Leave some CPU time for other processes
|
||||
Sys::Sleep( 100 );
|
||||
|
||||
// Display the playing position
|
||||
std::cout << "\rPlaying... " << music.PlayingOffset() << " sec ";
|
||||
std::cout << std::flush;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
/// Entry point of application
|
||||
EE_MAIN_FUNC int main (int argc, char * argv [])
|
||||
{
|
||||
// Play a sound
|
||||
playSound();
|
||||
|
||||
// Play a music
|
||||
playMusic();
|
||||
|
||||
// Wait until the user presses 'enter' key
|
||||
std::cout << "Press enter to exit..." << std::endl;
|
||||
std::cin.ignore(10000, '\n');
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user