Commit 896d233b authored by nanahira's avatar nanahira

Merge branch 'develop' into server-develop

parents 92b4432f be30dfe5
#!/bin/sh
set -x
set -o errexit
cd miniaudio
external_built_dir="$PWD/external-built"
is_macos=false
if [ "$(uname)" = "Darwin" ]; then
is_macos=true
fi
maybe_patch_configure() {
if $is_macos; then
sed -i.bak 's/-force_cpusubtype_ALL//g' configure*
fi
}
build_single_thing() {
lib_name="$1"
cd "external/$lib_name"
shift
maybe_patch_configure
PKG_CONFIG_PATH="$external_built_dir/lib/pkgconfig" ./configure --prefix="$external_built_dir" --enable-static=yes --enable-shared=no "$@"
make -j$(nproc)
make install
cd ../..
}
build_single_thing ogg
build_single_thing opus
build_single_thing opusfile --disable-examples --disable-http
build_single_thing vorbis --with-ogg="$external_built_dir"
cd ..
...@@ -8,8 +8,15 @@ export EVENT_INCLUDE_DIR=$PWD/libevent-stable/include ...@@ -8,8 +8,15 @@ export EVENT_INCLUDE_DIR=$PWD/libevent-stable/include
export EVENT_LIB_DIR=$PWD/libevent-stable/lib export EVENT_LIB_DIR=$PWD/libevent-stable/lib
export IRRLICHT_INCLUDE_DIR=$PWD/irrlicht/include export IRRLICHT_INCLUDE_DIR=$PWD/irrlicht/include
export IRRLICHT_LIB_DIR=$PWD/irrlicht/lib/$(arch) export IRRLICHT_LIB_DIR=$PWD/irrlicht/lib/$(arch)
export OPUS_INCLUDE_DIR=$PWD/miniaudio/external-built/include/opus
export OPUS_LIB_DIR=$PWD/miniaudio/external-built/lib
export VORBIS_INCLUDE_DIR=$PWD/miniaudio/external-built/include
export VORBIS_LIB_DIR=$PWD/miniaudio/external-built/lib
export OGG_INCLUDE_DIR=$PWD/miniaudio/external-built/include
export OGG_LIB_DIR=$PWD/miniaudio/external-built/lib
./.ci/libevent-prebuild.sh ./.ci/libevent-prebuild.sh
./.ci/build-opus.sh
./premake5 gmake --cc=clang --build-freetype --build-sqlite ./premake5 gmake --cc=clang --build-freetype --build-sqlite
......
...@@ -8,6 +8,10 @@ if [[ -z "$TARGET_PLATFORM" ]]; then ...@@ -8,6 +8,10 @@ if [[ -z "$TARGET_PLATFORM" ]]; then
TARGET_PLATFORM=linux TARGET_PLATFORM=linux
fi fi
if [[ "$TARGET_PLATFORM" != "linuxarm" ]]; then
ARCHIVE_FILES+=(sound)
fi
apt update && apt -y install tar zstd apt update && apt -y install tar zstd
mkdir dist replay mkdir dist replay
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
set -x set -x
set -o errexit set -o errexit
ARCHIVE_FILES=(ygopro LICENSE README.md lflist.conf strings.conf system.conf cards.cdb script textures deck single pics replay sound windbot bot bot.conf locales fonts pack) ARCHIVE_FILES=(ygopro LICENSE README.md lflist.conf strings.conf system.conf cards.cdb script textures deck single pics replay windbot bot bot.conf locales fonts pack)
# TARGET_LOCALE # TARGET_LOCALE
# ARCHIVE_SUFFIX # ARCHIVE_SUFFIX
...@@ -10,6 +10,10 @@ if [[ -z "$TARGET_PLATFORM" ]]; then ...@@ -10,6 +10,10 @@ if [[ -z "$TARGET_PLATFORM" ]]; then
TARGET_PLATFORM=linux TARGET_PLATFORM=linux
fi fi
if [[ "$TARGET_PLATFORM" != "linuxarm" ]]; then
ARCHIVE_FILES+=(sound)
fi
apt update && apt -y install tar git zstd apt update && apt -y install tar git zstd
mkdir dist replay mkdir dist replay
......
#!/bin/sh
set -x
set -o errexit
if [ ! -d "miniaudio" ]; then
git clone --depth=1 --branch 0.11.22 https://github.com/mackron/miniaudio
fi
mkdir -p miniaudio/external
install_external() {
dir="$1"
url="$2"
if [ ! -d "miniaudio/external/$dir" ]; then
mkdir -p "miniaudio/external/$dir"
# Download the external library and strip one level of directories from the archive
wget -O - "$url" | tar --strip-components=1 -C "miniaudio/external/$dir" -zxf -
fi
}
install_external "ogg" "https://github.com/xiph/ogg/releases/download/v1.3.5/libogg-1.3.5.tar.gz"
install_external "opus" "https://github.com/xiph/opus/releases/download/v1.5.2/opus-1.5.2.tar.gz"
install_external "opusfile" "https://github.com/xiph/opusfile/releases/download/v0.12/opusfile-0.12.tar.gz"
install_external "vorbis" "https://github.com/xiph/vorbis/releases/download/v1.3.7/libvorbis-1.3.7.tar.gz"
...@@ -12,6 +12,7 @@ jobs: ...@@ -12,6 +12,7 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
os: [windows-2019, windows-2022] os: [windows-2019, windows-2022]
audiolib: [miniaudio, irrklang]
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
...@@ -90,6 +91,76 @@ jobs: ...@@ -90,6 +91,76 @@ jobs:
7z x ${{ steps.sqlite.outputs.filepath }} 7z x ${{ steps.sqlite.outputs.filepath }}
move sqlite-amalgamation-3490100 sqlite3 move sqlite-amalgamation-3490100 sqlite3
- name: Download miniaudio
if: matrix.audiolib == 'miniaudio'
run: |
git clone --depth=1 --branch 0.11.22 https://github.com/mackron/miniaudio
- name: Download ogg
if: matrix.audiolib == 'miniaudio'
id: ogg
uses: mercury233/action-cache-download-file@v1.0.0
with:
url: https://github.com/xiph/ogg/releases/download/v1.3.5/libogg-1.3.5.tar.gz
- name: Extract ogg
if: matrix.audiolib == 'miniaudio'
run: |
tar xf ${{ steps.ogg.outputs.filepath }}
move libogg-1.3.5 miniaudio/external/ogg
- name: Download opus
if: matrix.audiolib == 'miniaudio'
id: opus
uses: mercury233/action-cache-download-file@v1.0.0
with:
url: https://github.com/xiph/opus/releases/download/v1.5.2/opus-1.5.2.tar.gz
- name: Extract opus
if: matrix.audiolib == 'miniaudio'
run: |
tar xf ${{ steps.opus.outputs.filepath }}
move opus-1.5.2 miniaudio/external/opus
- name: Download opusfile
if: matrix.audiolib == 'miniaudio'
id: opusfile
uses: mercury233/action-cache-download-file@v1.0.0
with:
url: https://github.com/xiph/opusfile/releases/download/v0.12/opusfile-0.12.tar.gz
- name: Extract opusfile
if: matrix.audiolib == 'miniaudio'
run: |
tar xf ${{ steps.opusfile.outputs.filepath }}
move opusfile-0.12 miniaudio/external/opusfile
- name: Download vorbis
if: matrix.audiolib == 'miniaudio'
id: vorbis
uses: mercury233/action-cache-download-file@v1.0.0
with:
url: https://github.com/xiph/vorbis/releases/download/v1.3.7/libvorbis-1.3.7.tar.gz
- name: Extract vorbis
if: matrix.audiolib == 'miniaudio'
run: |
tar xf ${{ steps.vorbis.outputs.filepath }}
move libvorbis-1.3.7 miniaudio/external/vorbis
- name: Download irrKlang
if: matrix.audiolib == 'irrklang'
id: irrKlang
uses: mercury233/action-cache-download-file@v1.0.0
with:
url: https://www.ambiera.at/downloads/irrKlang-32bit-1.6.0.zip
- name: Extract irrKlang
if: matrix.audiolib == 'irrklang'
run: |
7z x ${{ steps.irrKlang.outputs.filepath }}
move irrKlang-1.6.0 irrKlang
- name: Download irrlicht - name: Download irrlicht
run: | run: |
git clone --depth=1 https://github.com/mercury233/irrlicht git clone --depth=1 https://github.com/mercury233/irrlicht
...@@ -123,16 +194,26 @@ jobs: ...@@ -123,16 +194,26 @@ jobs:
xcopy /E premake\* . xcopy /E premake\* .
xcopy /E resource\* . xcopy /E resource\* .
- name: Use premake to generate Visual Studio solution (2019) - name: Use premake to generate Visual Studio solution (2019, miniaudio)
if: matrix.os == 'windows-2019' if: matrix.os == 'windows-2019' && matrix.audiolib == 'miniaudio'
run: | run: |
.\premake5.exe vs2019 --winxp-support .\premake5.exe vs2019 --winxp-support
- name: Use premake to generate Visual Studio solution (2022) - name: Use premake to generate Visual Studio solution (2022, miniaudio)
if: matrix.os == 'windows-2022' if: matrix.os == 'windows-2022' && matrix.audiolib == 'miniaudio'
run: | run: |
.\premake5.exe vs2022 .\premake5.exe vs2022
- name: Use premake to generate Visual Studio solution (2019, irrKlang)
if: matrix.os == 'windows-2019' && matrix.audiolib == 'irrklang'
run: |
.\premake5.exe vs2019 --winxp-support --audio-lib=irrklang
- name: Use premake to generate Visual Studio solution (2022, irrKlang)
if: matrix.os == 'windows-2022' && matrix.audiolib == 'irrklang'
run: |
.\premake5.exe vs2022 --audio-lib=irrklang
- name: Add msbuild to PATH - name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v2 uses: microsoft/setup-msbuild@v2
...@@ -143,7 +224,7 @@ jobs: ...@@ -143,7 +224,7 @@ jobs:
- name: Upload build artifacts - name: Upload build artifacts
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: YGOPro-${{ matrix.os }} name: YGOPro-${{ matrix.os }}-${{ matrix.audiolib }}
path: | path: |
bin/release/YGOPro.exe bin/release/YGOPro.exe
...@@ -186,7 +267,7 @@ jobs: ...@@ -186,7 +267,7 @@ jobs:
- name: Install dependencies - name: Install dependencies
run: | run: |
sudo apt-get update sudo apt-get update
sudo apt-get install -y libevent-dev libfreetype6-dev libgl1-mesa-dev libglu1-mesa-dev libsqlite3-dev libxxf86vm-dev sudo apt-get install -y libevent-dev libfreetype6-dev libgl1-mesa-dev libglu1-mesa-dev libsqlite3-dev libxxf86vm-dev libopusfile-dev libvorbis-dev
- name: Download premake - name: Download premake
id: premake id: premake
...@@ -211,6 +292,10 @@ jobs: ...@@ -211,6 +292,10 @@ jobs:
tar xf ${{ steps.lua.outputs.filepath }} tar xf ${{ steps.lua.outputs.filepath }}
mv lua-5.4.7 lua mv lua-5.4.7 lua
- name: Download miniaudio
run: |
git clone --depth=1 --branch 0.11.22 https://github.com/mackron/miniaudio
- name: Download irrlicht - name: Download irrlicht
run: | run: |
git clone --depth=1 https://github.com/mercury233/irrlicht git clone --depth=1 https://github.com/mercury233/irrlicht
...@@ -223,7 +308,8 @@ jobs: ...@@ -223,7 +308,8 @@ jobs:
- name: Use premake to generate make files - name: Use premake to generate make files
run: | run: |
./premake5 gmake \ ./premake5 gmake \
--freetype-include-dir="/usr/include/freetype2" --freetype-include-dir="/usr/include/freetype2" \
--opus-include-dir="/usr/include/opus"
- name: Make - name: Make
run: | run: |
...@@ -271,9 +357,9 @@ jobs: ...@@ -271,9 +357,9 @@ jobs:
# git pull origin master # git pull origin master
# cd .. # cd ..
# - name: Install dependencies - name: Install dependencies
# run: | run: |
# brew install freetype libevent libx11 sqlite zlib brew install freetype libevent libx11 sqlite opus opusfile libvorbis
- name: Download premake - name: Download premake
id: premake id: premake
...@@ -298,6 +384,10 @@ jobs: ...@@ -298,6 +384,10 @@ jobs:
tar xf ${{ steps.lua.outputs.filepath }} tar xf ${{ steps.lua.outputs.filepath }}
mv lua-5.4.7 lua mv lua-5.4.7 lua
- name: Download miniaudio
run: |
git clone --depth=1 --branch 0.11.22 https://github.com/mackron/miniaudio
- name: Download irrlicht - name: Download irrlicht
run: | run: |
git clone --depth=1 https://github.com/mercury233/irrlicht git clone --depth=1 https://github.com/mercury233/irrlicht
...@@ -319,6 +409,7 @@ jobs: ...@@ -319,6 +409,7 @@ jobs:
./premake5 gmake \ ./premake5 gmake \
--cc=clang \ --cc=clang \
--freetype-include-dir="/usr/local/include/freetype2" \ --freetype-include-dir="/usr/local/include/freetype2" \
--opus-include-dir="/usr/local/include/opus" \
--irrlicht-include-dir="../irrlicht/include" \ --irrlicht-include-dir="../irrlicht/include" \
--irrlicht-lib-dir="../irrlicht/source/Irrlicht/MacOSX/build/Release" --irrlicht-lib-dir="../irrlicht/source/Irrlicht/MacOSX/build/Release"
...@@ -333,6 +424,12 @@ jobs: ...@@ -333,6 +424,12 @@ jobs:
--freetype-lib-dir="/opt/homebrew/lib" \ --freetype-lib-dir="/opt/homebrew/lib" \
--sqlite-include-dir="/opt/homebrew/opt/sqlite/include" \ --sqlite-include-dir="/opt/homebrew/opt/sqlite/include" \
--sqlite-lib-dir="/opt/homebrew/opt/sqlite/lib" \ --sqlite-lib-dir="/opt/homebrew/opt/sqlite/lib" \
--miniaudio-include-dir="/opt/homebrew/include" \
--miniaudio-lib-dir="/opt/homebrew/lib" \
--opus-include-dir="/opt/homebrew/include/opus" \
--opus-lib-dir="/opt/homebrew/lib" \
--vorbis-include-dir="/opt/homebrew/include" \
--vorbis-lib-dir="/opt/homebrew/lib" \
--irrlicht-include-dir="../irrlicht/include" \ --irrlicht-include-dir="../irrlicht/include" \
--irrlicht-lib-dir="../irrlicht/source/Irrlicht/MacOSX/build/Release" --irrlicht-lib-dir="../irrlicht/source/Irrlicht/MacOSX/build/Release"
......
...@@ -16,6 +16,7 @@ build ...@@ -16,6 +16,7 @@ build
/irrklang /irrklang
/irrlicht* /irrlicht*
/lua /lua
/miniaudio
# gframe additionals # gframe additionals
/gframe/ygopro.ico /gframe/ygopro.ico
......
...@@ -22,6 +22,8 @@ mat_common: ...@@ -22,6 +22,8 @@ mat_common:
# freetype # freetype
#- wget -O - https://cdn01.moecube.com/ygopro-build-materials/freetype-2.11.1.tar.gz | tar zfx - #- wget -O - https://cdn01.moecube.com/ygopro-build-materials/freetype-2.11.1.tar.gz | tar zfx -
#- mv freetype-2.11.1 freetype #- mv freetype-2.11.1 freetype
# miniaudio
#- ./.ci/prepare-miniaudio.sh
# premake # premake
- cp -rf premake/* .; - cp -rf premake/* .;
artifacts: artifacts:
...@@ -29,6 +31,7 @@ mat_common: ...@@ -29,6 +31,7 @@ mat_common:
- lua - lua
#- freetype #- freetype
- sqlite3 - sqlite3
#- miniaudio
mat_submodules: mat_submodules:
stage: prepare stage: prepare
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
project "cminiaudio"
kind "StaticLib"
files { "*.c", "*.h" }
filter "system:linux"
links { "dl", "pthread", "m" }
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -2,9 +2,6 @@ include "lzma/." ...@@ -2,9 +2,6 @@ include "lzma/."
if (SERVER_ZIP_SUPPORT or not SERVER_MODE) then if (SERVER_ZIP_SUPPORT or not SERVER_MODE) then
include "spmemvfs/." include "spmemvfs/."
end end
if USE_AUDIO then
include "miniaudio/."
end
if SERVER_MODE then if SERVER_MODE then
if SERVER_PRO3_SUPPORT then if SERVER_PRO3_SUPPORT then
...@@ -86,7 +83,29 @@ end ...@@ -86,7 +83,29 @@ end
if USE_AUDIO then if USE_AUDIO then
defines { "YGOPRO_USE_AUDIO" } defines { "YGOPRO_USE_AUDIO" }
links { "cminiaudio" } if AUDIO_LIB == "miniaudio" then
defines { "YGOPRO_USE_MINIAUDIO" }
includedirs { "../miniaudio/extras/miniaudio_split" }
links { "miniaudio" }
if MINIAUDIO_SUPPORT_OPUS_VORBIS then
defines { "YGOPRO_MINIAUDIO_SUPPORT_OPUS_VORBIS" }
includedirs { "../miniaudio/extras/decoders/libopus", "../miniaudio/extras/decoders/libvorbis" }
if not MINIAUDIO_BUILD_OPUS_VORBIS then
links { "opusfile", "vorbisfile", "opus", "vorbis", "ogg" }
libdirs { OPUS_LIB_DIR, VORBIS_LIB_DIR, OGG_LIBDIR }
end
end
end
if AUDIO_LIB == "irrklang" then
defines { "YGOPRO_USE_IRRKLANG" }
includedirs { IRRKLANG_INCLUDE_DIR }
if not IRRKLANG_PRO then
libdirs { IRRKLANG_LIB_DIR }
end
if IRRKLANG_PRO_BUILD_IKPMP3 then
links { "ikpmp3" }
end
end
end end
filter "system:windows" filter "system:windows"
...@@ -103,6 +122,17 @@ if SERVER_MODE then ...@@ -103,6 +122,17 @@ if SERVER_MODE then
else else
links { "opengl32", "ws2_32", "winmm", "gdi32", "kernel32", "user32", "imm32", "Dnsapi" } links { "opengl32", "ws2_32", "winmm", "gdi32", "kernel32", "user32", "imm32", "Dnsapi" }
end end
if USE_AUDIO and AUDIO_LIB == "irrklang" then
links { "irrKlang" }
if IRRKLANG_PRO then
defines { "IRRKLANG_STATIC" }
filter { "not configurations:Debug" }
libdirs { IRRKLANG_PRO_RELEASE_LIB_DIR }
filter { "configurations:Debug" }
libdirs { IRRKLANG_PRO_DEBUG_LIB_DIR }
filter {}
end
end
filter "not system:windows" filter "not system:windows"
links { "event_pthreads", "dl", "pthread", "resolv" } links { "event_pthreads", "dl", "pthread", "resolv" }
filter "system:macosx" filter "system:macosx"
...@@ -114,8 +144,15 @@ end ...@@ -114,8 +144,15 @@ end
buildoptions { "--target=arm64-apple-macos12" } buildoptions { "--target=arm64-apple-macos12" }
linkoptions { "-arch arm64" } linkoptions { "-arch arm64" }
end end
if USE_AUDIO and AUDIO_LIB == "irrklang" then
links { "irrklang" }
end
filter "system:linux" filter "system:linux"
linkoptions { "-static-libstdc++", "-static-libgcc" } linkoptions { "-static-libstdc++", "-static-libgcc" }
if not SERVER_MODE then if not SERVER_MODE then
links { "GL", "X11", "Xxf86vm" } links { "GL", "X11", "Xxf86vm" }
end end
if USE_AUDIO and AUDIO_LIB == "irrklang" then
links { "IrrKlang" }
linkoptions{ IRRKLANG_LINK_RPATH }
end
#include "sound_manager.h" #include "sound_manager.h"
#include "myfilesystem.h" #include "myfilesystem.h"
#if defined(YGOPRO_USE_MINIAUDIO) && defined(YGOPRO_MINIAUDIO_SUPPORT_OPUS_VORBIS)
#include <miniaudio_libvorbis.h>
#include <miniaudio_libopus.h>
#endif
#ifdef IRRKLANG_STATIC
#include "../ikpmp3/ikpMP3.h"
#endif
namespace ygo { namespace ygo {
...@@ -12,11 +19,41 @@ bool SoundManager::Init() { ...@@ -12,11 +19,41 @@ bool SoundManager::Init() {
RefreshBGMList(); RefreshBGMList();
bgm_process = false; bgm_process = false;
rnd.reset((unsigned int)std::time(nullptr)); rnd.reset((unsigned int)std::time(nullptr));
if(ma_engine_init(nullptr, &engineSound) || ma_engine_init(nullptr, &engineMusic)) { #ifdef YGOPRO_USE_MINIAUDIO
engineConfig = ma_engine_config_init();
#ifdef YGOPRO_MINIAUDIO_SUPPORT_OPUS_VORBIS
ma_decoding_backend_vtable* pCustomBackendVTables[] =
{
ma_decoding_backend_libvorbis,
ma_decoding_backend_libopus
};
resourceManagerConfig = ma_resource_manager_config_init();
resourceManagerConfig.ppCustomDecodingBackendVTables = pCustomBackendVTables;
resourceManagerConfig.customDecodingBackendCount = sizeof(pCustomBackendVTables) / sizeof(pCustomBackendVTables[0]);
resourceManagerConfig.pCustomDecodingBackendUserData = NULL;
if(ma_resource_manager_init(&resourceManagerConfig, &resourceManager) != MA_SUCCESS) {
return false;
}
engineConfig.pResourceManager = &resourceManager;
#endif
if(ma_engine_init(&engineConfig, &engineSound) != MA_SUCCESS || ma_engine_init(&engineConfig, &engineMusic) != MA_SUCCESS) {
return false; return false;
} else { } else {
return true; return true;
} }
#endif // YGOPRO_USE_MINIAUDIO
#ifdef YGOPRO_USE_IRRKLANG
engineSound = irrklang::createIrrKlangDevice();
engineMusic = irrklang::createIrrKlangDevice();
if(!engineSound || !engineMusic) {
return false;
} else {
#ifdef IRRKLANG_STATIC
irrklang::ikpMP3Init(engineMusic);
#endif
return true;
}
#endif // YGOPRO_USE_IRRKLANG
#endif // YGOPRO_USE_AUDIO #endif // YGOPRO_USE_AUDIO
return false; return false;
} }
...@@ -36,7 +73,12 @@ void SoundManager::RefreshBGMList() { ...@@ -36,7 +73,12 @@ void SoundManager::RefreshBGMList() {
void SoundManager::RefershBGMDir(std::wstring path, int scene) { void SoundManager::RefershBGMDir(std::wstring path, int scene) {
std::wstring search = L"./sound/BGM/" + path; std::wstring search = L"./sound/BGM/" + path;
FileSystem::TraversalDir(search.c_str(), [this, &path, scene](const wchar_t* name, bool isdir) { FileSystem::TraversalDir(search.c_str(), [this, &path, scene](const wchar_t* name, bool isdir) {
if(!isdir && (IsExtension(name, L".mp3") || IsExtension(name, L".ogg"))) { if(!isdir && (
IsExtension(name, L".mp3")
#if defined(YGOPRO_MINIAUDIO_SUPPORT_OPUS_VORBIS) || defined(YGOPRO_USE_IRRKLANG)
|| IsExtension(name, L".ogg")
#endif
)) {
std::wstring filename = path + L"/" + name; std::wstring filename = path + L"/" + name;
BGMList[BGM_ALL].push_back(filename); BGMList[BGM_ALL].push_back(filename);
BGMList[scene].push_back(filename); BGMList[scene].push_back(filename);
...@@ -44,6 +86,7 @@ void SoundManager::RefershBGMDir(std::wstring path, int scene) { ...@@ -44,6 +86,7 @@ void SoundManager::RefershBGMDir(std::wstring path, int scene) {
}); });
} }
void SoundManager::PlaySoundEffect(int sound) { void SoundManager::PlaySoundEffect(int sound) {
#ifdef YGOPRO_USE_AUDIO
if(!mainGame->chkEnableSound->isChecked()) if(!mainGame->chkEnableSound->isChecked())
return; return;
char soundName[32]; char soundName[32];
...@@ -177,10 +220,15 @@ void SoundManager::PlaySoundEffect(int sound) { ...@@ -177,10 +220,15 @@ 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_AUDIO #ifdef YGOPRO_USE_MINIAUDIO
ma_engine_set_volume(&engineSound, mainGame->gameConf.sound_volume); ma_engine_set_volume(&engineSound, mainGame->gameConf.sound_volume);
auto res = ma_engine_play_sound(&engineSound, soundPath, nullptr); ma_engine_play_sound(&engineSound, soundPath, nullptr);
#endif #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) { void SoundManager::PlayDialogSound(irr::gui::IGUIElement * element) {
if(element == mainGame->wMessage) { if(element == mainGame->wMessage) {
...@@ -206,8 +254,11 @@ void SoundManager::PlayDialogSound(irr::gui::IGUIElement * element) { ...@@ -206,8 +254,11 @@ void SoundManager::PlayDialogSound(irr::gui::IGUIElement * element) {
} }
} }
bool SoundManager::IsCurrentlyPlaying(char* song) { bool SoundManager::IsCurrentlyPlaying(char* song) {
#ifdef YGOPRO_USE_AUDIO #ifdef YGOPRO_USE_MINIAUDIO
return currentPlayingMusic[0] && strcmp(currentPlayingMusic, song) == 0 && ma_sound_is_playing(&soundBGM); return currentPlayingMusic[0] && strcmp(currentPlayingMusic, song) == 0 && ma_sound_is_playing(&soundBGM);
#endif
#ifdef YGOPRO_USE_IRRKLANG
return engineMusic->isCurrentlyPlaying(song);
#endif #endif
return false; return false;
} }
...@@ -217,6 +268,7 @@ void SoundManager::PlayMusic(char* song, bool loop) { ...@@ -217,6 +268,7 @@ void SoundManager::PlayMusic(char* song, bool loop) {
return; return;
if(!IsCurrentlyPlaying(song)) { if(!IsCurrentlyPlaying(song)) {
StopBGM(); StopBGM();
#ifdef YGOPRO_USE_MINIAUDIO
strcpy(currentPlayingMusic, song); strcpy(currentPlayingMusic, song);
#ifdef _WIN32 #ifdef _WIN32
wchar_t song_w[1024]; wchar_t song_w[1024];
...@@ -227,6 +279,12 @@ void SoundManager::PlayMusic(char* song, bool loop) { ...@@ -227,6 +279,12 @@ void SoundManager::PlayMusic(char* song, bool loop) {
#endif #endif
ma_sound_set_looping(&soundBGM, loop); ma_sound_set_looping(&soundBGM, loop);
ma_sound_start(&soundBGM); ma_sound_start(&soundBGM);
#endif
#ifdef YGOPRO_USE_IRRKLANG
engineMusic->stopAllSounds();
engineMusic->setSoundVolume(mainGame->gameConf.music_volume);
soundBGM = engineMusic->play2D(song, loop, false, true);
#endif
} }
#endif #endif
} }
...@@ -237,7 +295,11 @@ void SoundManager::PlayBGM(int scene) { ...@@ -237,7 +295,11 @@ void SoundManager::PlayBGM(int scene) {
if(!mainGame->chkMusicMode->isChecked()) if(!mainGame->chkMusicMode->isChecked())
scene = BGM_ALL; scene = BGM_ALL;
char BGMName[1024]; char BGMName[1024];
if ((scene != bgm_scene) && (bgm_scene != BGM_CUSTOM) || (scene != previous_bgm_scene) && (bgm_scene == BGM_CUSTOM) || !IsCurrentlyPlaying(currentPlayingMusic)) { #if defined(YGOPRO_USE_MINIAUDIO)
if((scene != bgm_scene) && (bgm_scene != BGM_CUSTOM) || (scene != previous_bgm_scene) && (bgm_scene == BGM_CUSTOM) || !IsCurrentlyPlaying(currentPlayingMusic)) {
#elif defined(YGOPRO_USE_IRRKLANG)
if((scene != bgm_scene) && (bgm_scene != BGM_CUSTOM) || (scene != previous_bgm_scene) && (bgm_scene == BGM_CUSTOM) || (soundBGM && soundBGM->isFinished())) {
#endif
int count = BGMList[scene].size(); int count = BGMList[scene].size();
if(count <= 0) if(count <= 0)
return; return;
...@@ -273,24 +335,33 @@ void SoundManager::PlayCustomSound(char* SoundName) { ...@@ -273,24 +335,33 @@ void SoundManager::PlayCustomSound(char* SoundName) {
#endif #endif
} }
void SoundManager::StopBGM() { void SoundManager::StopBGM() {
#ifdef YGOPRO_USE_AUDIO #ifdef YGOPRO_USE_MINIAUDIO
if(!currentPlayingMusic[0]) if(!currentPlayingMusic[0])
return; return;
memset(currentPlayingMusic, 0, sizeof(currentPlayingMusic)); memset(currentPlayingMusic, 0, sizeof(currentPlayingMusic));
ma_sound_uninit(&soundBGM); ma_sound_uninit(&soundBGM);
#endif #endif
#ifdef YGOPRO_USE_IRRKLANG
engineMusic->stopAllSounds();
#endif
} }
void SoundManager::StopSound() { void SoundManager::StopSound() {
// TODO: stop all sounds // TODO: stop all sounds
} }
void SoundManager::SetSoundVolume(double volume) { void SoundManager::SetSoundVolume(double volume) {
#ifdef YGOPRO_USE_AUDIO #ifdef YGOPRO_USE_MINIAUDIO
ma_engine_set_volume(&engineSound, volume); ma_engine_set_volume(&engineSound, volume);
#endif #endif
#ifdef YGOPRO_USE_IRRKLANG
engineSound->setSoundVolume(volume);
#endif
} }
void SoundManager::SetMusicVolume(double volume) { void SoundManager::SetMusicVolume(double volume) {
#ifdef YGOPRO_USE_AUDIO #ifdef YGOPRO_USE_MINIAUDIO
ma_engine_set_volume(&engineMusic, volume); ma_engine_set_volume(&engineMusic, volume);
#endif #endif
#ifdef YGOPRO_USE_IRRKLANG
engineMusic->setSoundVolume(volume);
#endif
} }
} }
...@@ -3,8 +3,11 @@ ...@@ -3,8 +3,11 @@
#include "game.h" #include "game.h"
#include "../ocgcore/mtrandom.h" #include "../ocgcore/mtrandom.h"
#ifdef YGOPRO_USE_AUDIO #ifdef YGOPRO_USE_MINIAUDIO
#include "miniaudio/miniaudio.h" #include <miniaudio.h>
#endif
#ifdef YGOPRO_USE_IRRKLANG
#include <irrKlang.h>
#endif #endif
namespace ygo { namespace ygo {
...@@ -16,11 +19,21 @@ private: ...@@ -16,11 +19,21 @@ private:
int previous_bgm_scene; int previous_bgm_scene;
bool bgm_process; bool bgm_process;
mt19937 rnd; mt19937 rnd;
#ifdef YGOPRO_USE_AUDIO #ifdef YGOPRO_USE_MINIAUDIO
ma_engine_config engineConfig;
#ifdef YGOPRO_MINIAUDIO_SUPPORT_OPUS_VORBIS
ma_resource_manager_config resourceManagerConfig;
ma_resource_manager resourceManager;
#endif
ma_engine engineSound; ma_engine engineSound;
ma_engine engineMusic; ma_engine engineMusic;
ma_sound soundBGM; ma_sound soundBGM;
char currentPlayingMusic[1024]{}; char currentPlayingMusic[1024]{};
#endif
#ifdef YGOPRO_USE_IRRKLANG
irrklang::ISoundEngine* engineSound;
irrklang::ISoundEngine* engineMusic;
irrklang::ISound* soundBGM;
#endif #endif
void RefershBGMDir(std::wstring path, int scene); void RefershBGMDir(std::wstring path, int scene);
......
project "miniaudio"
kind "StaticLib"
files { "extras/miniaudio_split/miniaudio.*" }
if MINIAUDIO_SUPPORT_OPUS_VORBIS then
files { "extras/decoders/libopus/*", "extras/decoders/libvorbis/*" }
if MINIAUDIO_BUILD_OPUS_VORBIS then
files { "external/ogg/src/**.c", "external/ogg/src/**.h" }
files { "external/opus/src/**.c", "external/opus/src/**.h" }
files { "external/opus/celt/*.c", "external/opus/celt/*.h" }
files { "external/opus/silk/*.c", "external/opus/silk/*.h" }
files { "external/opus/silk/float/*.c", "external/opus/silk/float/*.h" }
files { "external/opusfile/src/**.c", "external/opusfile/src/**.h" }
files { "external/vorbis/lib/**.c", "external/vorbis/lib/**.h" }
removefiles { "external/opus/src/opus_demo.c", "external/opus/src/tone.c",
"external/opus/src/opus_encoder.c",
"external/vorbis/lib/psy.h", "external/vorbis/lib/psytune.c", "external/vorbis/lib/tone.c",}
defines { "USE_ALLOCA", "OPUS_BUILD" }
includedirs {
"external/ogg/include",
"external/opus/include",
"external/opus/celt",
"external/opus/silk",
"external/opus/silk/float",
"external/opusfile/include",
"external/vorbis/include"
}
else
includedirs { OPUS_INCLUDE_DIR, VORBIS_INCLUDE_DIR, OGG_INCLUDE_DIR }
end
end
filter "system:linux"
links { "dl", "pthread", "m" }
filter { "architecture:ARM" }
defines { "MA_NO_NEON" }
filter { "architecture:ARM64" }
defines { "MA_NO_NEON" }
filter {}
-- default global settings -- default global settings
BUILD_LUA = true BUILD_LUA = true
LUA_LIB_NAME = "lua"
BUILD_EVENT = os.istarget("windows") BUILD_EVENT = os.istarget("windows")
BUILD_FREETYPE = os.istarget("windows") BUILD_FREETYPE = os.istarget("windows")
BUILD_SQLITE = os.istarget("windows") BUILD_SQLITE = os.istarget("windows")
BUILD_IRRLICHT = not os.istarget("macosx") BUILD_IRRLICHT = not os.istarget("macosx")
LUA_LIB_NAME = "lua"
USE_AUDIO = true
AUDIO_LIB = "miniaudio"
MINIAUDIO_SUPPORT_OPUS_VORBIS = true
MINIAUDIO_BUILD_OPUS_VORBIS = os.istarget("windows")
IRRKLANG_PRO_BUILD_IKPMP3 = false
SERVER_MODE = true SERVER_MODE = true
SERVER_ZIP_SUPPORT = false SERVER_ZIP_SUPPORT = false
...@@ -20,7 +27,7 @@ newoption { trigger = "build-lua", category = "YGOPro - lua", description = "" } ...@@ -20,7 +27,7 @@ newoption { trigger = "build-lua", category = "YGOPro - lua", description = "" }
newoption { trigger = "no-build-lua", category = "YGOPro - lua", description = "" } newoption { trigger = "no-build-lua", category = "YGOPro - lua", description = "" }
newoption { trigger = "lua-include-dir", category = "YGOPro - lua", description = "", value = "PATH" } newoption { trigger = "lua-include-dir", category = "YGOPro - lua", description = "", value = "PATH" }
newoption { trigger = "lua-lib-dir", category = "YGOPro - lua", description = "", value = "PATH" } newoption { trigger = "lua-lib-dir", category = "YGOPro - lua", description = "", value = "PATH" }
newoption { trigger = "lua-lib-name", category = "YGOPro - lua", description = "", value = "NAME", default = "lua" } newoption { trigger = "lua-lib-name", category = "YGOPro - lua", description = "", value = "NAME", default = LUA_LIB_NAME }
newoption { trigger = "lua-deb", category = "YGOPro - lua", description = "" } newoption { trigger = "lua-deb", category = "YGOPro - lua", description = "" }
newoption { trigger = "build-event", category = "YGOPro - event", description = "" } newoption { trigger = "build-event", category = "YGOPro - event", description = "" }
...@@ -42,6 +49,32 @@ newoption { trigger = "build-irrlicht", category = "YGOPro - irrlicht", descript ...@@ -42,6 +49,32 @@ newoption { trigger = "build-irrlicht", category = "YGOPro - irrlicht", descript
newoption { trigger = "no-build-irrlicht", category = "YGOPro - irrlicht", description = "" } newoption { trigger = "no-build-irrlicht", category = "YGOPro - irrlicht", description = "" }
newoption { trigger = "irrlicht-include-dir", category = "YGOPro - irrlicht", description = "", value = "PATH" } newoption { trigger = "irrlicht-include-dir", category = "YGOPro - irrlicht", description = "", value = "PATH" }
newoption { trigger = "irrlicht-lib-dir", category = "YGOPro - irrlicht", description = "", value = "PATH" } newoption { trigger = "irrlicht-lib-dir", category = "YGOPro - irrlicht", description = "", value = "PATH" }
newoption { trigger = "no-audio", category = "YGOPro", description = "" }
newoption { trigger = "audio-lib", category = "YGOPro", description = "", value = "miniaudio, irrklang", default = AUDIO_LIB }
newoption { trigger = "miniaudio-include-dir", category = "YGOPro - miniaudio", description = "", value = "PATH" }
newoption { trigger = "miniaudio-lib-dir", category = "YGOPro - miniaudio", description = "", value = "PATH" }
newoption { trigger = "miniaudio-support-opus-vorbis", category = "YGOPro - miniaudio", description = "" }
newoption { trigger = "no-miniaudio-support-opus-vorbis", category = "YGOPro - miniaudio", description = "" }
newoption { trigger = "build-opus-vorbis", category = "YGOPro - miniaudio", description = "" }
newoption { trigger = "no-build-opus-vorbis", category = "YGOPro - miniaudio", description = "" }
newoption { trigger = "opus-include-dir", category = "YGOPro - miniaudio", description = "", value = "PATH" }
newoption { trigger = "opus-lib-dir", category = "YGOPro - miniaudio", description = "", value = "PATH" }
newoption { trigger = "vorbis-include-dir", category = "YGOPro - miniaudio", description = "", value = "PATH" }
newoption { trigger = "vorbis-lib-dir", category = "YGOPro - miniaudio", description = "", value = "PATH" }
newoption { trigger = "ogg-include-dir", category = "YGOPro - miniaudio", description = "", value = "PATH" }
newoption { trigger = "ogg-lib-dir", category = "YGOPro - miniaudio", description = "", value = "PATH" }
newoption { trigger = "use-irrklang", category = "YGOPro - irrklang", description = "Deprecated, use audio-lib=irrklang" }
newoption { trigger = "no-use-irrklang", category = "YGOPro - irrklang", description = "Deprecated, use no-audio" }
newoption { trigger = "irrklang-include-dir", category = "YGOPro - irrklang", description = "", value = "PATH" }
newoption { trigger = "irrklang-lib-dir", category = "YGOPro - irrklang", description = "", value = "PATH" }
newoption { trigger = "irrklang-pro", category = "YGOPro - irrklang - pro", description = "" }
newoption { trigger = "no-irrklang-pro", category = "YGOPro - irrklang - pro", description = "" }
newoption { trigger = "irrklang-pro-release-lib-dir", category = "YGOPro - irrklang - pro", description = "", value = "PATH" }
newoption { trigger = "irrklang-pro-debug-lib-dir", category = "YGOPro - irrklang - pro", description = "", value = "PATH" }
newoption { trigger = 'build-ikpmp3', category = "YGOPro - irrklang - ikpmp3", description = "" }
newoption { trigger = "winxp-support", category = "YGOPro", description = "" } newoption { trigger = "winxp-support", category = "YGOPro", description = "" }
newoption { trigger = "mac-arm", category = "YGOPro", description = "Cross compile for Apple Silicon" } newoption { trigger = "mac-arm", category = "YGOPro", description = "Cross compile for Apple Silicon" }
...@@ -156,6 +189,74 @@ if not BUILD_IRRLICHT then ...@@ -156,6 +189,74 @@ if not BUILD_IRRLICHT then
end end
USE_AUDIO = not SERVER_MODE and not GetParam("no-audio") USE_AUDIO = not SERVER_MODE and not GetParam("no-audio")
if GetParam("no-audio") then
USE_AUDIO = false
elseif GetParam("no-use-miniaudio") then
print("Warning: --no-use-miniaudio is deprecated, use --no-audio")
USE_AUDIO = false
elseif GetParam("use-miniaudio") then
print("Warning: --use-miniaudio is deprecated, use --audio-lib=miniaudio")
USE_AUDIO = true
AUDIO_LIB = "miniaudio"
elseif GetParam("no-use-irrklang") then
print("Warning: --no-use-irrklang is deprecated, use --no-audio")
USE_AUDIO = false
elseif GetParam("use-irrklang") then
print("Warning: --use-irrklang is deprecated, use --audio-lib=irrklang")
USE_AUDIO = true
AUDIO_LIB = "irrklang"
end
if USE_AUDIO then
AUDIO_LIB = GetParam("audio-lib") or AUDIO_LIB
if AUDIO_LIB == "miniaudio" then
if GetParam("miniaudio-support-opus-vorbis") then
MINIAUDIO_SUPPORT_OPUS_VORBIS = true
elseif GetParam("no-miniaudio-support-opus-vorbis") then
MINIAUDIO_SUPPORT_OPUS_VORBIS = false
end
if MINIAUDIO_SUPPORT_OPUS_VORBIS then
if GetParam("no-build-opus-vorbis") then
MINIAUDIO_BUILD_OPUS_VORBIS = false
elseif GetParam("build-opus-vorbis") then
MINIAUDIO_BUILD_OPUS_VORBIS = true
end
if not MINIAUDIO_BUILD_OPUS_VORBIS then
OPUS_INCLUDE_DIR = GetParam("opus-include-dir") or os.findheader("opus")
OPUS_LIB_DIR = GetParam("opus-lib-dir") or os.findlib("opusfile")
VORBIS_INCLUDE_DIR = GetParam("vorbis-include-dir") or os.findheader("vorbis")
VORBIS_LIB_DIR = GetParam("vorbis-lib-dir") or os.findlib("vorbis")
OGG_INCLUDE_DIR = GetParam("ogg-include-dir") or os.findheader("ogg")
OCG_LIB_DIR = GetParam("ogg-lib-dir") or os.findlib("ogg")
end
end
elseif AUDIO_LIB == "irrklang" then
print("Warning: irrKlang is deprecated and may be removed in future, please consider switching to miniaudio")
IRRKLANG_INCLUDE_DIR = GetParam("irrklang-include-dir") or "../irrklang/include"
if os.istarget("windows") then
IRRKLANG_LIB_DIR = "../irrklang/lib/Win32-visualStudio"
elseif os.istarget("linux") then
IRRKLANG_LIB_DIR = "../irrklang/bin/linux-gcc-64"
IRRKLANG_LINK_RPATH = "-Wl,-rpath=./irrklang/bin/linux-gcc-64/"
elseif os.istarget("macosx") then
IRRKLANG_LIB_DIR = "../irrklang/bin/macosx-gcc"
end
IRRKLANG_LIB_DIR = GetParam("irrklang-lib-dir") or IRRKLANG_LIB_DIR
if GetParam("irrklang-pro") and os.istarget("windows") then
IRRKLANG_PRO = true
elseif GetParam("no-irrklang-pro") then
IRRKLANG_PRO = false
end
if IRRKLANG_PRO then
-- irrklang pro can't use the pro lib to debug
IRRKLANG_PRO_RELEASE_LIB_DIR = GetParam("irrklang-pro-release-lib-dir") or "../irrklang/lib/Win32-vs2019"
IRRKLANG_PRO_DEBUG_LIB_DIR = GetParam("irrklang-pro-debug-lib-dir") or "../irrklang/lib/Win32-visualStudio-debug"
end
IRRKLANG_PRO_BUILD_IKPMP3 = GetParam("build-ikpmp3") or IRRKLANG_PRO
else
error("Unknown audio library: " .. AUDIO_LIB)
end
end
if GetParam("winxp-support") and os.istarget("windows") then if GetParam("winxp-support") and os.istarget("windows") then
WINXP_SUPPORT = true WINXP_SUPPORT = true
...@@ -310,3 +411,11 @@ end ...@@ -310,3 +411,11 @@ end
if BUILD_SQLITE then if BUILD_SQLITE then
include "sqlite3" include "sqlite3"
end end
if USE_AUDIO then
if AUDIO_LIB=="miniaudio" then
include "miniaudio"
end
if IRRKLANG_PRO_BUILD_IKPMP3 then
include "ikpmp3"
end
end
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