Add caudio (#1180)
* Add caudio * Use 4 spaces * Add openal-soft as packagedeps * Remove macosx support * Add win32_fix.patch * Add another OpenAL include path to patch * Update xmake.lua Co-authored-by: ruki <waruqi@gmail.com>pull/1202/head
parent
e83650b16b
commit
a9e31110af
2 changed files with 118 additions and 0 deletions
@ -0,0 +1,37 @@ |
||||
diff --git a/CMake/Dependencies.cmake b/CMake/Dependencies.cmake
|
||||
index 349082d..b745b12 100644
|
||||
--- a/CMake/Dependencies.cmake
|
||||
+++ b/CMake/Dependencies.cmake
|
||||
@@ -27,5 +27,6 @@ MACRO_DISPLAY_FEATURE_LOG()
|
||||
|
||||
# Add library and include paths from the dependencies
|
||||
include_directories(
|
||||
+ ${OPENAL_INCLUDE_DIR}/../
|
||||
${OPENAL_INCLUDE_DIR}
|
||||
)
|
||||
diff --git a/cAudio/include/cAudioString.h b/cAudio/include/cAudioString.h
|
||||
index f70d2f0..d8a4815 100644
|
||||
--- a/cAudio/include/cAudioString.h
|
||||
+++ b/cAudio/include/cAudioString.h
|
||||
@@ -49,8 +49,8 @@ namespace cAudio
|
||||
static int id = 0;
|
||||
static char buffer[8][1024];
|
||||
id = ++id & 0x7;
|
||||
-
|
||||
- int buff_size = WideCharToMultiByte(CP_UTF8, 0, str.c_str(), (int)(str.size() < 1023 ? str.size() : 1023), buffer[id], 1023, 0, false);
|
||||
+ std::wstring widestr(str.begin(), str.end());
|
||||
+ int buff_size = WideCharToMultiByte(CP_UTF8, 0, widestr.c_str(), (int)(str.size() < 1023 ? str.size() : 1023), buffer[id], 1023, 0, false);
|
||||
buffer[id][buff_size] = 0;
|
||||
buffer[id][1023] = 0;
|
||||
return buffer[id];
|
||||
@@ -61,7 +61,9 @@ namespace cAudio
|
||||
int str_len = (int)strlen(str);
|
||||
int buf_size = MultiByteToWideChar(CP_UTF8, 0, str, str_len, 0, 0);
|
||||
cAudioString s(buf_size, L'\0');
|
||||
- MultiByteToWideChar(CP_UTF8, 0, str, str_len, &s[0], buf_size);
|
||||
+ std::wstring widestr(s.begin(), s.end());
|
||||
+ MultiByteToWideChar(CP_UTF8, 0, str, str_len, &widestr[0], buf_size);
|
||||
+ s = std::string(widestr.begin(), widestr.end());
|
||||
return s;
|
||||
}
|
||||
|
@ -0,0 +1,81 @@ |
||||
package("caudio") |
||||
|
||||
set_homepage("https://github.com/R4stl1n/cAudio") |
||||
set_description("3D Audio Engine Based on Openal") |
||||
|
||||
add_urls("https://github.com/R4stl1n/cAudio/archive/refs/tags/$(version).zip", |
||||
"https://github.com/R4stl1n/cAudio.git") |
||||
add_versions("2.3.1", "10f36cd7e1583405ade9001c3782fdf04be09f0f74e56cba23fac3a2b3ed5ae5") |
||||
|
||||
add_patches("2.3.1", path.join(os.scriptdir(), "patches", "2.3.1", "win32_fix.patch"), "92d09b63479e203e59cece12fb5d539ab73f6654228ad44b221361db50639acf") |
||||
|
||||
add_deps("openal-soft") |
||||
add_links("cAudio", "Vorbis", "Ogg") |
||||
|
||||
on_install("windows", "linux", function (package) |
||||
local dep_dir = (package:is_arch("x64", "x86_64") and "Dependencies64" or "Dependencies") |
||||
local configs = { |
||||
"-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"), |
||||
"-DCAUDIO_STATIC=" .. (package:config("shared") and "OFF" or "ON"), |
||||
"-DCAUDIO_DEPENDENCIES_DIR=" .. dep_dir, |
||||
"-DCAUDIO_BUILD_SAMPLES=OFF" |
||||
} |
||||
local cxflags |
||||
local shflags |
||||
if package:is_plat("windows") then |
||||
io.replace("cAudio/Headers/cOpenALUtil.h", "#if !defined(CAUDIO_PLATFORM_LINUX)", "#if 0", {plain = true}) |
||||
if not package:dep("openal-soft"):config("shared") then |
||||
cxflags = "-DAL_LIBTYPE_STATIC" |
||||
end |
||||
shflags = "winmm.lib" |
||||
end |
||||
import("package.tools.cmake").install(package, configs, {buildir = "CMake", |
||||
cxflags = cxflags, shflags = shflags}) |
||||
os.cp("cAudio/include/*.h", package:installdir("include")) |
||||
os.cp("cAudio/Headers/*.h", package:installdir("include")) |
||||
os.cp(path.join(dep_dir, "include/*"), package:installdir("include")) |
||||
os.cp("CMake/include/*.h", package:installdir("include")) |
||||
os.trycp("CMake/lib/**.lib", package:installdir("lib")) |
||||
end) |
||||
|
||||
on_test(function (package) |
||||
assert(package:check_cxxsnippets({test = [[ |
||||
void test(int argc, char* argv[]) { |
||||
cAudio::IAudioManager* audioMgr = cAudio::createAudioManager(false); |
||||
if(audioMgr) |
||||
{ |
||||
cAudio::IAudioDeviceList* pDeviceList = cAudio::createAudioDeviceList(); |
||||
unsigned int deviceCount = pDeviceList->getDeviceCount(); |
||||
cAudio::cAudioString defaultDeviceName = pDeviceList->getDefaultDeviceName(); |
||||
for(unsigned int i=0; i<deviceCount; ++i) |
||||
{ |
||||
cAudio::cAudioString deviceName = pDeviceList->getDeviceName(i); |
||||
if(deviceName.compare(defaultDeviceName) == 0); |
||||
} |
||||
unsigned int deviceSelection = 0; |
||||
|
||||
audioMgr->initialize(pDeviceList->getDeviceName(deviceSelection).c_str()); |
||||
CAUDIO_DELETE pDeviceList; |
||||
pDeviceList = 0; |
||||
|
||||
cAudio::IAudioSource* mysound = audioMgr->create("song", "../Media/cAudioTheme1.ogg",true); |
||||
|
||||
for (size_t i=0; i<10; i++) |
||||
{ |
||||
audioMgr->play2D("../Media/bling.ogg"); |
||||
} |
||||
if(mysound) |
||||
{ |
||||
mysound->setVolume(0.5); |
||||
mysound->play2d(false); |
||||
|
||||
while(mysound->isPlaying()) |
||||
cAudio::cAudioSleep(10); |
||||
|
||||
} |
||||
|
||||
cAudio::destroyAudioManager(audioMgr); |
||||
} |
||||
} |
||||
]]}, {configs = {languages = "cxx11"}, includes = "cAudio.h"})) |
||||
end) |
Loading…
Reference in new issue