Commit 493bccfb authored by nanahira's avatar nanahira

Merge branch 'patch-miniaudio' of github.com:Fluorohydride/ygopro into develop

parents 7dd1005a e337da72
...@@ -253,31 +253,29 @@ void SoundManager::PlayDialogSound(irr::gui::IGUIElement * element) { ...@@ -253,31 +253,29 @@ void SoundManager::PlayDialogSound(irr::gui::IGUIElement * element) {
PlaySoundEffect(SOUND_QUESTION); PlaySoundEffect(SOUND_QUESTION);
} }
} }
bool SoundManager::IsCurrentlyPlaying(wchar_t* music) { bool SoundManager::IsCurrentlyPlaying(char* song) {
#ifdef YGOPRO_USE_MINIAUDIO #ifdef YGOPRO_USE_MINIAUDIO
return currentPlayingMusic[0] && !mywcsncasecmp(currentPlayingMusic, music, 1024) && ma_sound_is_playing(&soundBGM); return currentPlayingMusic[0] && strcmp(currentPlayingMusic, song) == 0 && ma_sound_is_playing(&soundBGM);
#endif #endif
#ifdef YGOPRO_USE_IRRKLANG #ifdef YGOPRO_USE_IRRKLANG
char cmusic[1024]; return engineMusic->isCurrentlyPlaying(song);
BufferIO::EncodeUTF8(music, cmusic);
return engineMusic->isCurrentlyPlaying(cmusic);
#endif #endif
return false; return false;
} }
void SoundManager::PlayMusic(wchar_t* music, bool loop) { void SoundManager::PlayMusic(char* song, bool loop) {
#ifdef YGOPRO_USE_AUDIO #ifdef YGOPRO_USE_AUDIO
if(!mainGame->chkEnableMusic->isChecked()) if(!mainGame->chkEnableMusic->isChecked())
return; return;
if(!IsCurrentlyPlaying(music)) { if(!IsCurrentlyPlaying(song)) {
StopBGM(); StopBGM();
#ifdef YGOPRO_USE_MINIAUDIO #ifdef YGOPRO_USE_MINIAUDIO
BufferIO::CopyWStr(music, currentPlayingMusic, 1024); strcpy(currentPlayingMusic, song);
#ifdef _WIN32 #ifdef _WIN32
ma_sound_init_from_file_w(&engineMusic, music, MA_SOUND_FLAG_ASYNC | MA_SOUND_FLAG_STREAM, nullptr, nullptr, &soundBGM); wchar_t song_w[1024];
BufferIO::DecodeUTF8(song, song_w);
ma_sound_init_from_file_w(&engineMusic, song_w, MA_SOUND_FLAG_ASYNC | MA_SOUND_FLAG_STREAM, nullptr, nullptr, &soundBGM);
#else #else
char musicU[1024]; ma_sound_init_from_file(&engineMusic, song, MA_SOUND_FLAG_ASYNC | MA_SOUND_FLAG_STREAM, nullptr, nullptr, &soundBGM);
BufferIO::EncodeUTF8(music, musicU);
ma_sound_init_from_file(&engineMusic, musicU, MA_SOUND_FLAG_ASYNC | MA_SOUND_FLAG_STREAM, nullptr, nullptr, &soundBGM);
#endif #endif
ma_sound_set_looping(&soundBGM, loop); ma_sound_set_looping(&soundBGM, loop);
ma_sound_start(&soundBGM); ma_sound_start(&soundBGM);
...@@ -285,9 +283,7 @@ void SoundManager::PlayMusic(wchar_t* music, bool loop) { ...@@ -285,9 +283,7 @@ void SoundManager::PlayMusic(wchar_t* music, bool loop) {
#ifdef YGOPRO_USE_IRRKLANG #ifdef YGOPRO_USE_IRRKLANG
engineMusic->stopAllSounds(); engineMusic->stopAllSounds();
engineMusic->setSoundVolume(mainGame->gameConf.music_volume); engineMusic->setSoundVolume(mainGame->gameConf.music_volume);
char cmusic[1024]; soundBGM = engineMusic->play2D(song, loop, false, true);
BufferIO::EncodeUTF8(music, cmusic);
soundBGM = engineMusic->play2D(cmusic, loop, false, true);
#endif #endif
} }
#endif #endif
...@@ -298,6 +294,7 @@ void SoundManager::PlayBGM(int scene) { ...@@ -298,6 +294,7 @@ void SoundManager::PlayBGM(int scene) {
return; return;
if(!mainGame->chkMusicMode->isChecked()) if(!mainGame->chkMusicMode->isChecked())
scene = BGM_ALL; scene = BGM_ALL;
char BGMName[1024];
#if defined(YGOPRO_USE_MINIAUDIO) #if defined(YGOPRO_USE_MINIAUDIO)
if((scene != bgm_scene) && (bgm_scene != BGM_CUSTOM) || (scene != previous_bgm_scene) && (bgm_scene == BGM_CUSTOM) || !IsCurrentlyPlaying(currentPlayingMusic)) { if((scene != bgm_scene) && (bgm_scene != BGM_CUSTOM) || (scene != previous_bgm_scene) && (bgm_scene == BGM_CUSTOM) || !IsCurrentlyPlaying(currentPlayingMusic)) {
#elif defined(YGOPRO_USE_IRRKLANG) #elif defined(YGOPRO_USE_IRRKLANG)
...@@ -309,8 +306,9 @@ void SoundManager::PlayBGM(int scene) { ...@@ -309,8 +306,9 @@ void SoundManager::PlayBGM(int scene) {
bgm_scene = scene; bgm_scene = scene;
int bgm = rnd.get_random_integer(0, count -1); int bgm = rnd.get_random_integer(0, count -1);
auto name = BGMList[scene][bgm].c_str(); auto name = BGMList[scene][bgm].c_str();
wchar_t BGMName[1024]; wchar_t fname[1024];
myswprintf(BGMName, L"./sound/BGM/%ls", name); myswprintf(fname, L"./sound/BGM/%ls", name);
BufferIO::EncodeUTF8(fname, BGMName);
PlayMusic(BGMName, false); PlayMusic(BGMName, false);
} }
#endif #endif
......
...@@ -28,7 +28,7 @@ private: ...@@ -28,7 +28,7 @@ private:
ma_engine engineSound; ma_engine engineSound;
ma_engine engineMusic; ma_engine engineMusic;
ma_sound soundBGM; ma_sound soundBGM;
wchar_t currentPlayingMusic[1024]{}; char currentPlayingMusic[1024]{};
#endif #endif
#ifdef YGOPRO_USE_IRRKLANG #ifdef YGOPRO_USE_IRRKLANG
irrklang::ISoundEngine* engineSound; irrklang::ISoundEngine* engineSound;
...@@ -42,8 +42,8 @@ public: ...@@ -42,8 +42,8 @@ public:
void RefreshBGMList(); void RefreshBGMList();
void PlaySoundEffect(int sound); void PlaySoundEffect(int sound);
void PlayDialogSound(irr::gui::IGUIElement * element); void PlayDialogSound(irr::gui::IGUIElement * element);
bool IsCurrentlyPlaying(wchar_t* music); bool IsCurrentlyPlaying(char* song);
void PlayMusic(wchar_t* music, bool loop); void PlayMusic(char* song, bool loop);
void PlayBGM(int scene); void PlayBGM(int scene);
void PlayCustomBGM(wchar_t* BGMName); void PlayCustomBGM(wchar_t* BGMName);
void PlayCustomSound(wchar_t* SoundName); void PlayCustomSound(wchar_t* SoundName);
......
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