fixed sound playback of ship destroyed
This commit is contained in:
+31
-9
@@ -48,7 +48,7 @@ int SoundBase::OnInit(int argc, char* argv[]) {
|
||||
int audio_rate = 22050;
|
||||
Uint16 audio_format = AUDIO_S16;
|
||||
int audio_channels = 2;
|
||||
int audio_buffers = 1024;
|
||||
int audio_buffers = 2048;
|
||||
|
||||
LogDebug("Sound Init");
|
||||
if (Mix_OpenAudio (audio_rate, audio_format, audio_channels, audio_buffers)) {
|
||||
@@ -97,6 +97,8 @@ void SoundBase::PlaySound (const std::string &sound_name) {
|
||||
iter = mSamples.find(sound_name);
|
||||
}
|
||||
|
||||
LogDebug ("Playing sound %s", sound_name.c_str());
|
||||
|
||||
iter->second->Play();
|
||||
}
|
||||
|
||||
@@ -116,6 +118,8 @@ void SoundBase::PlaySoundLoop (const std::string &sound_name, int count) {
|
||||
iter = mSamples.find(sound_name);
|
||||
}
|
||||
|
||||
LogDebug ("Playing sound loop %s", sound_name.c_str());
|
||||
|
||||
iter->second->Loop(count);
|
||||
}
|
||||
|
||||
@@ -127,15 +131,24 @@ void SoundBase::HaltSoundLoop (const std::string &sound_name) {
|
||||
|
||||
SampleIter iter = mSamples.find(sound_name);
|
||||
|
||||
if (iter == mSamples.end()) {
|
||||
// nothing to stop
|
||||
return;
|
||||
}
|
||||
|
||||
LogDebug ("Halting sound loop %s", sound_name.c_str());
|
||||
|
||||
iter->second->Stop();
|
||||
}
|
||||
|
||||
void SoundBase::LoadSound (const std::string &sound_name) {
|
||||
SampleIter iter = mSamples.find(sound_name);
|
||||
|
||||
if (iter == mSamples.end()) {
|
||||
SoundSamplePtr sample (new SoundSample);
|
||||
sample->Load(sound_name);
|
||||
mSamples[sound_name] = sample;
|
||||
|
||||
iter = mSamples.find(sound_name);
|
||||
}
|
||||
|
||||
iter->second->Stop();
|
||||
}
|
||||
|
||||
void SoundBase::PlayMusic (const std::string &music_name) {
|
||||
@@ -233,17 +246,26 @@ void HaltSoundLoop (const std::string &sound_name) {
|
||||
SoundInstance->HaltSoundLoop(sound_name);
|
||||
}
|
||||
|
||||
void LoadSound (const std::string &sound_name) {
|
||||
if (!SoundInstance) {
|
||||
LogError("Could not music volume: sound system not initialized!");
|
||||
}
|
||||
|
||||
SoundInstance->LoadSound (sound_name);
|
||||
}
|
||||
|
||||
void SetMusicVolume (const float &music_volume) {
|
||||
if (!SoundInstance) {
|
||||
LogError("Could set music volume: sound system not initialized!");
|
||||
LogError("Could not set music volume: sound system not initialized!");
|
||||
}
|
||||
|
||||
|
||||
SoundInstance->SetMusicVolume(music_volume);
|
||||
}
|
||||
|
||||
float GetMusicVolume () {
|
||||
if (!SoundInstance) {
|
||||
LogError("Could get music volume: sound system not initialized!");
|
||||
LogError("Could not get music volume: sound system not initialized!");
|
||||
}
|
||||
|
||||
return SoundInstance->GetMusicVolume();
|
||||
@@ -251,7 +273,7 @@ float GetMusicVolume () {
|
||||
|
||||
void SetEffectsVolume (const float &effects_volume) {
|
||||
if (!SoundInstance) {
|
||||
LogError("Could set effects volume: sound system not initialized!");
|
||||
LogError("Could not set effects volume: sound system not initialized!");
|
||||
}
|
||||
|
||||
SoundInstance->SetEffectsVolume(effects_volume);
|
||||
@@ -259,7 +281,7 @@ void SetEffectsVolume (const float &effects_volume) {
|
||||
|
||||
float GetEffectsVolume () {
|
||||
if (!SoundInstance) {
|
||||
LogError("Could get effects volume: sound system not initialized!");
|
||||
LogError("Could not get effects volume: sound system not initialized!");
|
||||
}
|
||||
|
||||
return SoundInstance->GetEffectsVolume();
|
||||
|
||||
@@ -36,6 +36,7 @@ class SoundBase : public Module {
|
||||
void PlaySound (const std::string &sound_name);
|
||||
void PlaySoundLoop (const std::string &sound_name, int count);
|
||||
void HaltSoundLoop (const std::string &sound_name);
|
||||
void LoadSound (const std::string &sound_name);
|
||||
void PlayMusic (const std::string &music_name);
|
||||
void HaltMusic ();
|
||||
|
||||
|
||||
@@ -8,6 +8,9 @@ void PlaySoundLoop (const std::string &sound_name, int count);
|
||||
void HaltSoundLoop (const std::string &sound_name);
|
||||
void PlayMusic (const std::string &music_name);
|
||||
|
||||
/** \brief Loads a sound effect for later use */
|
||||
void LoadSound (const std::string &sound_name);
|
||||
|
||||
/** \brief Sets the volume of the music channel to the given value
|
||||
*
|
||||
* \param music_value is a value from 0. (no music) to 1. (maximum volume)
|
||||
|
||||
Reference in New Issue
Block a user