Commit c2e71eef authored by nanahira's avatar nanahira

test se

parent 82f1e003
...@@ -36,6 +36,7 @@ bool SoundManager::Init() { ...@@ -36,6 +36,7 @@ bool SoundManager::Init() {
} }
engineConfig.pResourceManager = &resourceManager; engineConfig.pResourceManager = &resourceManager;
#endif #endif
playingSoundEffect = FALSE;
if(ma_engine_init(&engineConfig, &engineSound) != MA_SUCCESS || ma_engine_init(&engineConfig, &engineMusic) != MA_SUCCESS) { if(ma_engine_init(&engineConfig, &engineSound) != MA_SUCCESS || ma_engine_init(&engineConfig, &engineMusic) != MA_SUCCESS) {
return false; return false;
} else { } else {
...@@ -85,6 +86,28 @@ void SoundManager::RefershBGMDir(std::wstring path, int scene) { ...@@ -85,6 +86,28 @@ void SoundManager::RefershBGMDir(std::wstring path, int scene) {
} }
}); });
} }
void SoundManager::PlaySound(char* sound) {
#ifdef YGOPRO_USE_AUDIO
if(!mainGame->chkEnableSound->isChecked())
return;
#ifdef YGOPRO_USE_MINIAUDIO
StopSound();
SetSoundVolume(mainGame->gameConf.sound_volume);
#ifdef _WIN32
wchar_t sound_w[1024];
BufferIO::DecodeUTF8(song, sound_w);
ma_sound_init_from_file_w(&engineSound, sound_w, MA_SOUND_FLAG_ASYNC | MA_SOUND_FLAG_STREAM, nullptr, nullptr, &soundEffect);
#else
ma_sound_init_from_file(&engineSound, sound, MA_SOUND_FLAG_ASYNC | MA_SOUND_FLAG_STREAM, nullptr, nullptr, &soundEffect);
#endif
ma_sound_start(&soundEffect);
#endif
#ifdef YGOPRO_USE_IRRKLANG
SetSoundVolume(mainGame->gameConf.sound_volume);
engineSound->play2D(soundPath);
#endif
#endif
}
void SoundManager::PlaySoundEffect(int sound) { void SoundManager::PlaySoundEffect(int sound) {
#ifdef YGOPRO_USE_AUDIO #ifdef YGOPRO_USE_AUDIO
if(!mainGame->chkEnableSound->isChecked()) if(!mainGame->chkEnableSound->isChecked())
...@@ -220,14 +243,7 @@ void SoundManager::PlaySoundEffect(int sound) { ...@@ -220,14 +243,7 @@ void SoundManager::PlaySoundEffect(int sound) {
} }
char soundPath[40]; char soundPath[40];
std::snprintf(soundPath, 40, "./sound/%s.wav", soundName); std::snprintf(soundPath, 40, "./sound/%s.wav", soundName);
#ifdef YGOPRO_USE_MINIAUDIO PlaySound(soundPath);
ma_engine_set_volume(&engineSound, mainGame->gameConf.sound_volume);
ma_engine_play_sound(&engineSound, soundPath, nullptr);
#endif
#ifdef YGOPRO_USE_IRRKLANG
engineSound->setSoundVolume(mainGame->gameConf.sound_volume);
engineSound->play2D(soundPath);
#endif
#endif // YGOPRO_USE_AUDIO #endif // YGOPRO_USE_AUDIO
} }
void SoundManager::PlayDialogSound(irr::gui::IGUIElement * element) { void SoundManager::PlayDialogSound(irr::gui::IGUIElement * element) {
...@@ -268,6 +284,7 @@ void SoundManager::PlayMusic(char* song, bool loop) { ...@@ -268,6 +284,7 @@ void SoundManager::PlayMusic(char* song, bool loop) {
return; return;
if(!IsCurrentlyPlaying(song)) { if(!IsCurrentlyPlaying(song)) {
StopBGM(); StopBGM();
SetSoundVolume(mainGame->gameConf.music_volume);
#ifdef YGOPRO_USE_MINIAUDIO #ifdef YGOPRO_USE_MINIAUDIO
strcpy(currentPlayingMusic, song); strcpy(currentPlayingMusic, song);
#ifdef _WIN32 #ifdef _WIN32
...@@ -281,8 +298,6 @@ void SoundManager::PlayMusic(char* song, bool loop) { ...@@ -281,8 +298,6 @@ void SoundManager::PlayMusic(char* song, bool loop) {
ma_sound_start(&soundBGM); ma_sound_start(&soundBGM);
#endif #endif
#ifdef YGOPRO_USE_IRRKLANG #ifdef YGOPRO_USE_IRRKLANG
engineMusic->stopAllSounds();
engineMusic->setSoundVolume(mainGame->gameConf.music_volume);
soundBGM = engineMusic->play2D(song, loop, false, true); soundBGM = engineMusic->play2D(song, loop, false, true);
#endif #endif
} }
...@@ -352,7 +367,15 @@ void SoundManager::StopBGM() { ...@@ -352,7 +367,15 @@ void SoundManager::StopBGM() {
#endif #endif
} }
void SoundManager::StopSound() { void SoundManager::StopSound() {
// TODO: stop all sounds #ifdef YGOPRO_USE_MINIAUDIO
if(!playingSoundEffect || !ma_sound_is_playing(&soundEffect))
return;
playingSoundEffect = FALSE;
ma_sound_uninit(&soundEffect);
#endif
#ifdef YGOPRO_USE_IRRKLANG
engineSound->stopAllSounds();
#endif
} }
void SoundManager::SetSoundVolume(double volume) { void SoundManager::SetSoundVolume(double volume) {
#ifdef YGOPRO_USE_MINIAUDIO #ifdef YGOPRO_USE_MINIAUDIO
......
...@@ -30,6 +30,7 @@ private: ...@@ -30,6 +30,7 @@ private:
ma_sound soundBGM; ma_sound soundBGM;
char currentPlayingMusic[1024]{}; char currentPlayingMusic[1024]{};
ma_sound soundEffect; ma_sound soundEffect;
char playingSoundEffect;
#endif #endif
#ifdef YGOPRO_USE_IRRKLANG #ifdef YGOPRO_USE_IRRKLANG
irrklang::ISoundEngine* engineSound; irrklang::ISoundEngine* engineSound;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment