This commit is contained in:
natural-law 2010-10-21 06:44:02 +00:00
parent 78a93db918
commit 0397ea0a74
4 changed files with 50 additions and 26 deletions

View File

@ -1,7 +1,7 @@
############################################################################ ############################################################################
# #
# Makefile for building : SimpleAudioEngine_Arm.TMK3 # Makefile for building : SimpleAudioEngine_Arm_uphone.TMK3
# Created by TMK3_V2.3, please do not modify. # Created by TMK3_V2.3, please do not modify.
# #
############################################################################# #############################################################################
@ -27,10 +27,10 @@ MKDIR = mkdir -p
first: all first: all
OBJECTS = \ OBJECTS = \
$(OBJECTS_DIR)/SoundDataManager.o \
$(OBJECTS_DIR)/ResourceHandle.o \ $(OBJECTS_DIR)/ResourceHandle.o \
$(OBJECTS_DIR)/SoundPlayer.o \ $(OBJECTS_DIR)/SimpleAudioEngine.o \
$(OBJECTS_DIR)/SimpleAudioEngine.o $(OBJECTS_DIR)/SoundDataManager.o \
$(OBJECTS_DIR)/SoundPlayer.o
ADD_OBJECTS += ADD_OBJECTS +=
@ -49,15 +49,15 @@ clean :
-$(DEL_FILE) $(OBJECTS) -$(DEL_FILE) $(OBJECTS)
-$(DEL_FILE) $(TARGET) -$(DEL_FILE) $(TARGET)
$(OBJECTS_DIR)/SoundDataManager.o : ./include/SoundDataManager.cpp $(OBJECTS_DIR)/ResourceHandle.o : ./uphone/ResourceHandle.cpp
$(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/SoundDataManager.o ./include/SoundDataManager.cpp $(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/ResourceHandle.o ./uphone/ResourceHandle.cpp
$(OBJECTS_DIR)/ResourceHandle.o : ./Platform/uPhone/ResourceHandle.cpp $(OBJECTS_DIR)/SimpleAudioEngine.o : ./uphone/SimpleAudioEngine.cpp
$(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/ResourceHandle.o ./Platform/uPhone/ResourceHandle.cpp $(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/SimpleAudioEngine.o ./uphone/SimpleAudioEngine.cpp
$(OBJECTS_DIR)/SoundPlayer.o : ./Platform/uPhone/SoundPlayer.cpp $(OBJECTS_DIR)/SoundDataManager.o : ./uphone/SoundDataManager.cpp
$(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/SoundPlayer.o ./Platform/uPhone/SoundPlayer.cpp $(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/SoundDataManager.o ./uphone/SoundDataManager.cpp
$(OBJECTS_DIR)/SimpleAudioEngine.o : ./SimpleAudioEngine/SimpleAudioEngine.cpp $(OBJECTS_DIR)/SoundPlayer.o : ./uphone/SoundPlayer.cpp
$(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/SimpleAudioEngine.o ./SimpleAudioEngine/SimpleAudioEngine.cpp $(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/SoundPlayer.o ./uphone/SoundPlayer.cpp

View File

@ -63,9 +63,15 @@ public:
bool isBackgroundMusicPlaying(); bool isBackgroundMusicPlaying();
// properties // properties
/**
@brief The volume of the background music max value is 100,the min value is 0
*/
int GetBackgroundMusicVolume(); int GetBackgroundMusicVolume();
void SetBackgroundMusicVolume(int volume); void SetBackgroundMusicVolume(int volume);
/**
@brief The volume of the effects max value is 100,the min value is 0
*/
int GetEffectsVolume(); int GetEffectsVolume();
void SetEffectsVolume(int volume); void SetEffectsVolume(int volume);
@ -96,11 +102,6 @@ public:
@param[in] nSoundId the sound id returned from preloadEffect @param[in] nSoundId the sound id returned from preloadEffect
*****************************************************************************/ *****************************************************************************/
void playPreloadedEffect(int nSoundId); void playPreloadedEffect(int nSoundId);
protected:
int m_nBackgroundMusicVolume;
int m_nEffectsVolume;
bool m_bWillPlayBackgroundMusic;
}; };
#endif // _SIMPLE_AUDIO_ENGINE_H_ #endif // _SIMPLE_AUDIO_ENGINE_H_

View File

@ -13,6 +13,11 @@ static PlayerArray *s_pEffectPlayers = NULL;
static SoundDataManager *s_pDataManager = NULL; static SoundDataManager *s_pDataManager = NULL;
static SoundPlayer *s_pBackPlayer = NULL; static SoundPlayer *s_pBackPlayer = NULL;
static int s_nBackgroundMusicVolume = 100;
static int s_nEffectsVolume = 100;
static bool s_bWillPlayBackgroundMusic = false;
void removeAllEffectPlayers() void removeAllEffectPlayers()
{ {
PlayerArrayIterator iter; PlayerArrayIterator iter;
@ -30,21 +35,20 @@ void removeAllEffectPlayers()
} }
SimpleAudioEngine::SimpleAudioEngine() SimpleAudioEngine::SimpleAudioEngine()
: m_nBackgroundMusicVolume(100)
, m_nEffectsVolume(100)
, m_bWillPlayBackgroundMusic(false)
{ {
if (s_pEffectPlayers) if (s_pEffectPlayers)
{ {
removeAllEffectPlayers(); removeAllEffectPlayers();
} }
s_pEffectPlayers = new PlayerArray(); s_pEffectPlayers = new PlayerArray();
SetEffectsVolume(s_nEffectsVolume);
if (s_pBackPlayer) if (s_pBackPlayer)
{ {
delete s_pBackPlayer; delete s_pBackPlayer;
} }
s_pBackPlayer = new SoundPlayer(); s_pBackPlayer = new SoundPlayer();
SetBackgroundMusicVolume(s_nBackgroundMusicVolume);
if (s_pDataManager) if (s_pDataManager)
{ {
@ -131,7 +135,7 @@ void SimpleAudioEngine::rewindBackgroundMusic()
bool SimpleAudioEngine::willPlayBackgroundMusic() bool SimpleAudioEngine::willPlayBackgroundMusic()
{ {
return m_bWillPlayBackgroundMusic; return s_bWillPlayBackgroundMusic;
} }
bool SimpleAudioEngine::isBackgroundMusicPlaying() bool SimpleAudioEngine::isBackgroundMusicPlaying()
@ -149,26 +153,44 @@ bool SimpleAudioEngine::isBackgroundMusicPlaying()
// properties // properties
int SimpleAudioEngine::GetBackgroundMusicVolume() int SimpleAudioEngine::GetBackgroundMusicVolume()
{ {
return m_nBackgroundMusicVolume; return s_nBackgroundMusicVolume;
} }
void SimpleAudioEngine::SetBackgroundMusicVolume(int volume) void SimpleAudioEngine::SetBackgroundMusicVolume(int volume)
{ {
if (volume > 100)
{
volume = 100;
}
else if (volume < 0)
{
volume = 0;
}
if (s_pBackPlayer) if (s_pBackPlayer)
{ {
s_pBackPlayer->SetVolumeValue(volume); s_pBackPlayer->SetVolumeValue(volume);
} }
m_nBackgroundMusicVolume = volume; s_nBackgroundMusicVolume = volume;
} }
int SimpleAudioEngine::GetEffectsVolume() int SimpleAudioEngine::GetEffectsVolume()
{ {
return m_nEffectsVolume; return s_nEffectsVolume;
} }
void SimpleAudioEngine::SetEffectsVolume(int volume) void SimpleAudioEngine::SetEffectsVolume(int volume)
{ {
if (volume > 100)
{
volume = 100;
}
else if (volume < 0)
{
volume = 0;
}
PlayerArrayIterator iter; PlayerArrayIterator iter;
for (iter = s_pEffectPlayers->begin(); iter != s_pEffectPlayers->end(); ++iter) for (iter = s_pEffectPlayers->begin(); iter != s_pEffectPlayers->end(); ++iter)
@ -179,7 +201,7 @@ void SimpleAudioEngine::SetEffectsVolume(int volume)
} }
} }
m_nEffectsVolume = volume; s_nEffectsVolume = volume;
} }
@ -253,7 +275,7 @@ void SimpleAudioEngine::playPreloadedEffect(int nSoundId)
s_pEffectPlayers->push_back(pPlayer); s_pEffectPlayers->push_back(pPlayer);
// set the player volume // set the player volume
pPlayer->SetVolumeValue(m_nEffectsVolume); pPlayer->SetVolumeValue(s_nEffectsVolume);
} }
// play the sound and record the player // play the sound and record the player

View File

@ -5,6 +5,7 @@
#include <map> #include <map>
#include "uthash.h" #include "uthash.h"
#include "SimpleAudioEngine.h" #include "SimpleAudioEngine.h"
#include <string>
typedef struct _hashElement typedef struct _hashElement
{ {