Commit bcc1b348 authored by wind2009's avatar wind2009

Merge remote-tracking branch 'upstream/patch-miniaudio' into develop

parents 0077af77 f4d23d09
......@@ -95,6 +95,9 @@ jobs:
if: matrix.audiolib == 'miniaudio'
run: |
git clone --depth=1 --branch 0.11.22 https://github.com/mackron/miniaudio
cd miniaudio
xcopy /Y extras\miniaudio_split\miniaudio.* .
cd ..
- name: Download ogg
if: matrix.audiolib == 'miniaudio'
......@@ -295,6 +298,9 @@ jobs:
- name: Download miniaudio
run: |
git clone --depth=1 --branch 0.11.22 https://github.com/mackron/miniaudio
cd miniaudio
cp extras/miniaudio_split/miniaudio.* .
cd ..
- name: Download irrlicht
run: |
......@@ -387,6 +393,9 @@ jobs:
- name: Download miniaudio
run: |
git clone --depth=1 --branch 0.11.22 https://github.com/mackron/miniaudio
cd miniaudio
cp extras/miniaudio_split/miniaudio.* .
cd ..
- name: Download irrlicht
run: |
......
......@@ -3034,6 +3034,7 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) {
case MSG_CHAIN_DISABLED: {
int ct = BufferIO::ReadUInt8(pbuf);
if(!mainGame->dInfo.isReplay || !mainGame->dInfo.isReplaySkiping) {
soundManager.PlaySoundEffect(SOUND_NEGATE);
mainGame->showcardcode = mainGame->dField.chains[ct - 1].code;
mainGame->showcarddif = 0;
mainGame->showcard = 3;
......
......@@ -1898,14 +1898,12 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) {
return true;
break;
}
#ifdef YGOPRO_USE_AUDIO
case CHECKBOX_ENABLE_MUSIC: {
if(!mainGame->chkEnableMusic->isChecked())
soundManager.StopBGM();
return true;
break;
}
#endif
case CHECKBOX_DISABLE_CHAT: {
bool show = (mainGame->is_building && !mainGame->is_siding) ? false : !mainGame->chkIgnore1->isChecked();
mainGame->wChat->setVisible(show);
......@@ -1998,7 +1996,6 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) {
return true;
break;
}
#ifdef YGOPRO_USE_AUDIO
case SCROLL_VOLUME: {
mainGame->gameConf.sound_volume = (double)mainGame->scrSoundVolume->getPos() / 100;
mainGame->gameConf.music_volume = (double)mainGame->scrMusicVolume->getPos() / 100;
......@@ -2007,7 +2004,6 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) {
return true;
break;
}
#endif
case SCROLL_TAB_HELPER: {
irr::core::rect<irr::s32> pos = mainGame->tabHelper->getRelativePosition();
mainGame->tabHelper->setRelativePosition(irr::core::recti(0, mainGame->scrTabHelper->getPos() * -1, pos.LowerRightCorner.X, pos.LowerRightCorner.Y));
......
......@@ -42,7 +42,7 @@ project "YGOPro"
defines { "YGOPRO_USE_AUDIO" }
if AUDIO_LIB == "miniaudio" then
defines { "YGOPRO_USE_MINIAUDIO" }
includedirs { "../miniaudio/extras/miniaudio_split" }
includedirs { "../miniaudio" }
links { "miniaudio" }
if MINIAUDIO_SUPPORT_OPUS_VORBIS then
defines { "YGOPRO_MINIAUDIO_SUPPORT_OPUS_VORBIS" }
......
......@@ -128,6 +128,10 @@ void SoundManager::PlaySoundEffect(int sound) {
strcpy(soundName, "token");
break;
}
case SOUND_NEGATE: {
strcpy(soundName, "negate");
break;
}
case SOUND_ATTACK: {
strcpy(soundName, "attack");
break;
......@@ -149,7 +153,7 @@ void SoundManager::PlaySoundEffect(int sound) {
break;
}
case SOUND_RECOVER: {
strcpy(soundName, "recover");
strcpy(soundName, "gainlp");
break;
}
case SOUND_COUNTER_ADD: {
......@@ -161,11 +165,11 @@ void SoundManager::PlaySoundEffect(int sound) {
break;
}
case SOUND_COIN: {
strcpy(soundName, "coin");
strcpy(soundName, "coinflip");
break;
}
case SOUND_DICE: {
strcpy(soundName, "dice");
strcpy(soundName, "diceroll");
break;
}
case SOUND_NEXT_TURN: {
......@@ -205,7 +209,7 @@ void SoundManager::PlaySoundEffect(int sound) {
break;
}
case SOUND_CHAT: {
strcpy(soundName, "chat");
strcpy(soundName, "chatmessage");
break;
}
default:
......@@ -213,17 +217,17 @@ void SoundManager::PlaySoundEffect(int sound) {
}
char soundPath[40];
std::snprintf(soundPath, 40, "./sound/%s.wav", soundName);
SetSoundVolume(mainGame->gameConf.sound_volume);
#ifdef YGOPRO_USE_MINIAUDIO
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
}
void SoundManager::PlayDialogSound(irr::gui::IGUIElement * element) {
#ifdef YGOPRO_USE_AUDIO
if(element == mainGame->wMessage) {
PlaySoundEffect(SOUND_INFO);
} else if(element == mainGame->wQuery) {
......@@ -245,32 +249,44 @@ void SoundManager::PlayDialogSound(irr::gui::IGUIElement * element) {
} else if(element == mainGame->wFTSelect) {
PlaySoundEffect(SOUND_QUESTION);
}
#endif // YGOPRO_USE_AUDIO
}
bool SoundManager::IsCurrentlyPlaying(char* song) {
bool SoundManager::IsPlayingMusic(wchar_t* music) {
#ifdef YGOPRO_USE_MINIAUDIO
return currentPlayingMusic[0] && strcmp(currentPlayingMusic, song) == 0 && ma_sound_is_playing(&soundBGM);
if(music) {
return !mywcsncasecmp(currentPlayingMusic, music, 1024) && ma_sound_is_playing(&soundBGM);
} else {
return ma_sound_is_playing(&soundBGM);
}
#endif
#ifdef YGOPRO_USE_IRRKLANG
return engineMusic->isCurrentlyPlaying(song);
if(music) {
char cmusic[1024];
BufferIO::EncodeUTF8(music, cmusic);
return engineMusic->isCurrentlyPlaying(cmusic);
} else {
return soundBGM && !soundBGM->isFinished();
}
#endif
return false;
}
void SoundManager::PlayMusic(char* song, bool loop) {
void SoundManager::PlayMusic(wchar_t* music, bool loop) {
#ifdef YGOPRO_USE_AUDIO
if(!mainGame->chkEnableMusic->isChecked())
return;
if(!IsCurrentlyPlaying(song)) {
if(!IsPlayingMusic(music)) {
StopBGM();
SetMusicVolume(mainGame->gameConf.music_volume);
#ifdef YGOPRO_USE_MINIAUDIO
strcpy(currentPlayingMusic, song);
ma_sound_init_from_file(&engineMusic, song, MA_SOUND_FLAG_ASYNC | MA_SOUND_FLAG_STREAM, nullptr, nullptr, &soundBGM);
BufferIO::CopyWStr(music, currentPlayingMusic, 1024);
ma_sound_init_from_file_w(&engineMusic, music, MA_SOUND_FLAG_ASYNC | MA_SOUND_FLAG_STREAM, nullptr, nullptr, &soundBGM);
ma_sound_set_looping(&soundBGM, loop);
ma_sound_start(&soundBGM);
#endif
#ifdef YGOPRO_USE_IRRKLANG
engineMusic->stopAllSounds();
engineMusic->setSoundVolume(mainGame->gameConf.music_volume);
soundBGM = engineMusic->play2D(song, loop, false, true);
char cmusic[1024];
BufferIO::EncodeUTF8(music, cmusic);
soundBGM = engineMusic->play2D(cmusic, loop, false, true);
#endif
}
#endif
......@@ -281,21 +297,15 @@ void SoundManager::PlayBGM(int scene) {
return;
if(!mainGame->chkMusicMode->isChecked())
scene = BGM_ALL;
char BGMName[1024];
#if defined(YGOPRO_USE_MINIAUDIO)
if(scene != bgm_scene || !IsCurrentlyPlaying(currentPlayingMusic)) {
#elif defined(YGOPRO_USE_IRRKLANG)
if(scene != bgm_scene || (soundBGM && soundBGM->isFinished())) {
#endif
if(scene != bgm_scene || !IsPlayingMusic()) {
int count = BGMList[scene].size();
if(count <= 0)
return;
bgm_scene = scene;
int bgm = rnd.get_random_integer(0, count -1);
auto name = BGMList[scene][bgm].c_str();
wchar_t fname[1024];
myswprintf(fname, L"./sound/BGM/%ls", name);
BufferIO::EncodeUTF8(fname, BGMName);
wchar_t BGMName[1024];
myswprintf(BGMName, L"./sound/BGM/%ls", name);
PlayMusic(BGMName, false);
}
#endif
......
......@@ -15,7 +15,7 @@ namespace ygo {
class SoundManager {
private:
std::vector<std::wstring> BGMList[8];
int bgm_scene;
int bgm_scene{};
mt19937 rnd;
#ifdef YGOPRO_USE_MINIAUDIO
ma_engine_config engineConfig;
......@@ -26,7 +26,7 @@ private:
ma_engine engineSound;
ma_engine engineMusic;
ma_sound soundBGM;
char currentPlayingMusic[1024]{};
wchar_t currentPlayingMusic[1024]{};
#endif
#ifdef YGOPRO_USE_IRRKLANG
irrklang::ISoundEngine* engineSound;
......@@ -40,8 +40,8 @@ public:
void RefreshBGMList();
void PlaySoundEffect(int sound);
void PlayDialogSound(irr::gui::IGUIElement * element);
bool IsCurrentlyPlaying(char* song);
void PlayMusic(char* song, bool loop);
bool IsPlayingMusic(wchar_t* music = 0);
void PlayMusic(wchar_t* music, bool loop);
void PlayBGM(int scene);
void StopBGM();
void SetSoundVolume(double volume);
......@@ -60,6 +60,7 @@ extern SoundManager soundManager;
#define SOUND_DESTROYED 108
#define SOUND_BANISHED 109
#define SOUND_TOKEN 110
#define SOUND_NEGATE 111
#define SOUND_ATTACK 201
#define SOUND_DIRECT_ATTACK 202
......
project "miniaudio"
kind "StaticLib"
files { "extras/miniaudio_split/miniaudio.*" }
files { "miniaudio.c", "miniaudio.h" }
defines { "MA_NO_ENCODING", "MA_NO_GENERATION", "MA_NO_NEON" }
if MINIAUDIO_SUPPORT_OPUS_VORBIS then
......
......@@ -8,6 +8,7 @@ equip.wav
destroyed.wav
banished.wav
token.wav
negate.wav
attack.wav
directattack.wav
draw.wav
......
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