Skip to content

Commit

Permalink
[faudio] new port
Browse files Browse the repository at this point in the history
Add new port FAudio, an "accuracy-focused XAudio reimplementation for
open platforms".

Use the PLATFORM_WIN32 cmake flag on Windows, otherwise use the sdl2
dependency.

MSVC build PR is here:

FNA-XNA/FAudio#333

, followup PR to fix alignment is here:

FNA-XNA/FAudio#334

, and another followup for the SDL2 dependency:

FNA-XNA/FAudio#335

, the MSYS2 package is here:

https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-faudio/PKGBUILD
.

Signed-off-by: Rafael Kitover <[email protected]>
  • Loading branch information
rkitover committed Mar 10, 2024
1 parent 0719a71 commit d4ff574
Show file tree
Hide file tree
Showing 7 changed files with 233 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ports/faudio/clang-alignment.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/src/FAudio_internal.h b/src/FAudio_internal.h
index 20538b8..eaa21f7 100644
--- a/src/FAudio_internal.h
+++ b/src/FAudio_internal.h
@@ -211,8 +211,8 @@ extern void FAudio_Log(char const *msg);
#endif

/* Alignment macro for gcc/clang/msvc */
-#if defined(__GNUC__) || defined(__clang__)
-#define ALIGN(type, boundary) type __attribute_((aligned(boundary)))
+#if defined(__clang__) || defined(__GNUC__)
+#define ALIGN(type, boundary) type __attribute__((aligned(boundary)))
#elif defined(_MSC_VER)
#define ALIGN(type, boundary) __declspec(align(boundary)) type
#else
85 changes: 85 additions & 0 deletions ports/faudio/msvc-build.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a741caa..a71a494 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -104,7 +104,7 @@ add_library(FAudio
)

if(PLATFORM_WIN32)
- target_link_libraries(FAudio PRIVATE -ldxguid -luuid -lwinmm -lole32 -ladvapi32 -luser32 -lmfplat -lmfreadwrite -lmfuuid -lpropsys)
+ target_link_libraries(FAudio PRIVATE dxguid uuid winmm ole32 advapi32 user32 mfplat mfreadwrite mfuuid propsys)
target_compile_definitions(FAudio PUBLIC FAUDIO_WIN32_PLATFORM)
target_compile_definitions(FAudio PRIVATE HAVE_WMADEC=1)
set(PLATFORM_CFLAGS "-DFAUDIO_WIN32_PLATFORM")
diff --git a/src/FAudio_internal.h b/src/FAudio_internal.h
index 0d35951..20538b8 100644
--- a/src/FAudio_internal.h
+++ b/src/FAudio_internal.h
@@ -37,8 +37,8 @@
#include <assert.h>
#include <inttypes.h>

-#include <windef.h>
-#include <winbase.h>
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>

#define FAudio_malloc malloc
#define FAudio_realloc realloc
@@ -210,6 +210,15 @@ extern void FAudio_Log(char const *msg);
#define restrict
#endif

+/* Alignment macro for gcc/clang/msvc */
+#if defined(__GNUC__) || defined(__clang__)
+#define ALIGN(type, boundary) type __attribute_((aligned(boundary)))
+#elif defined(_MSC_VER)
+#define ALIGN(type, boundary) __declspec(align(boundary)) type
+#else
+#define ALIGN(type, boundary) type
+#endif
+
/* Threading Types */

typedef void* FAudioThread;
diff --git a/src/FAudio_internal_simd.c b/src/FAudio_internal_simd.c
index b21d49a..296b2cc 100644
--- a/src/FAudio_internal_simd.c
+++ b/src/FAudio_internal_simd.c
@@ -903,7 +903,7 @@ void FAudio_INTERNAL_ResampleMono_NEON(
cur_frac = vdupq_n_s32(
(uint32_t) (cur_scalar & FIXED_FRACTION_MASK) - DOUBLE_TO_FIXED(0.5)
);
- int32_t __attribute__((aligned(16))) data[4] =
+ ALIGN(int32_t, 16) data[4] =
{
0,
(uint32_t) (resampleStep & FIXED_FRACTION_MASK),
@@ -1077,7 +1077,7 @@ void FAudio_INTERNAL_ResampleStereo_NEON(
cur_frac = vdupq_n_s32(
(uint32_t) (cur_scalar & FIXED_FRACTION_MASK) - DOUBLE_TO_FIXED(0.5)
);
- int32_t __attribute__((aligned(16))) data[4] =
+ ALIGN(int32_t, 16) data[4] =
{
0,
0,
diff --git a/src/FAudio_platform_win32.c b/src/FAudio_platform_win32.c
index 08ad24f..cd07e5d 100644
--- a/src/FAudio_platform_win32.c
+++ b/src/FAudio_platform_win32.c
@@ -43,6 +43,14 @@
#include <mmdeviceapi.h>

DEFINE_GUID(CLSID_CWMADecMediaObject, 0x2eeb4adf, 0x4578, 0x4d10, 0xbc, 0xa7, 0xbb, 0x95, 0x5f, 0x56, 0x32, 0x0a);
+
+#ifdef _MSC_VER
+DEFINE_GUID(IID_IAudioClient, 0x1CB9AD4C, 0xDBFA, 0x4c32, 0xB1, 0x78, 0xC2, 0xF5, 0x68, 0xA7, 0x03, 0xB2);
+DEFINE_GUID(IID_IAudioRenderClient, 0xF294ACFC, 0x3146, 0x4483, 0xA7, 0xBF, 0xAD, 0xDC, 0xA7, 0xC2, 0x60, 0xE2);
+DEFINE_GUID(IID_IMMDeviceEnumerator, 0xA95664D2, 0x9614, 0x4F35, 0xA7, 0x46, 0xDE, 0x8D, 0xB6, 0x36, 0x17, 0xE6);
+DEFINE_GUID(CLSID_MMDeviceEnumerator, 0xBCDE0395, 0xE52F, 0x467C, 0x8E, 0x3D, 0xC4, 0x57, 0x92, 0x91, 0x69, 0x2E);
+#endif
+
DEFINE_MEDIATYPE_GUID(MFAudioFormat_XMAudio2, FAUDIO_FORMAT_XMAUDIO2);

static CRITICAL_SECTION faudio_cs = { NULL, -1, 0, 0, 0, 0 };
36 changes: 36 additions & 0 deletions ports/faudio/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO FNA-XNA/faudio
REF "${VERSION}"
SHA512 c5b6a6b672095bc2a3d303cee591a8bceecef3ccba417b2023f6ae927143e0524495daea2d4cc2880b09de632a805e291db5894d7cb910535743b2025f14b712
HEAD_REF master
PATCHES
msvc-build.patch
clang-alignment.patch
sdl2-dependency.patch
)

set(options "")
if(VCPKG_TARGET_IS_WINDOWS)
list(APPEND options -DPLATFORM_WIN32=TRUE)
endif()

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
${options}
)

vcpkg_cmake_install()
vcpkg_copy_pdbs()
vcpkg_fixup_pkgconfig()

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include" "${CURRENT_PACKAGES_DIR}/debug/share")

vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/FAudio)

vcpkg_install_copyright(
COMMENT "FAudio is licensed under the Zlib license."
FILE_LIST
"${SOURCE_PATH}/LICENSE"
)
61 changes: 61 additions & 0 deletions ports/faudio/sdl2-dependency.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
commit 12308ff56ed463c65a58bc3ee47b4a7c16dbce29
Author: Kai Pastor <[email protected]>
Date: Sun Mar 10 18:30:19 2024 +0000

build: fix dependency on SDL2

This is a followup on 81d5a24 (build: fix building with MSVC,
2024-03-07) and 68a555e (build: fix __attribute__((aligned(x))) on
gcc/clang, 2024-03-09) for the purposes of creating a vcpkg FAudio port.

Add a `Requires.private: sdl2` to the pkgconf file for the SDL2
dependency when not using PLATFORM_WIN32.

Add the SDL2 dependency to the generated cmake config file when not
using PLATFORM_WIN32 as well.

Signed-off-by: Rafael Kitover <[email protected]>

diff --git a/CMakeLists.txt b/CMakeLists.txt
index a71a494..17f3aac 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -298,6 +298,11 @@ install(
include(cmake/JoinPaths.cmake)
join_paths(FAUDIO_PKGCONF_LIBDIR "\${prefix}" "${CMAKE_INSTALL_LIBDIR}")
join_paths(FAUDIO_PKGCONF_INCLUDEDIR "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
+
+if(NOT PLATFORM_WIN32)
+ set(PC_REQUIRES_PRIVATE "Requires.private: sdl2")
+endif()
+
configure_file(
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}.pc.in"
${PROJECT_BINARY_DIR}/generated/${PROJECT_NAME}.pc
diff --git a/cmake/FAudio.pc.in b/cmake/FAudio.pc.in
index 3907ccb..6d96dbe 100644
--- a/cmake/FAudio.pc.in
+++ b/cmake/FAudio.pc.in
@@ -7,6 +7,7 @@ Name: @PROJECT_NAME@
URL: https://github.com/FNA-XNA/FAudio
Description: Accuracy-focused XAudio reimplementation for open platforms
Version: @LIB_VERSION@
+@PC_REQUIRES_PRIVATE@

Libs: -L${libdir} -l@PROJECT_NAME@
Cflags: -I${includedir} @PLATFORM_CFLAGS@
diff --git a/cmake/config.cmake.in b/cmake/config.cmake.in
index 8bb8c0e..09585d7 100644
--- a/cmake/config.cmake.in
+++ b/cmake/config.cmake.in
@@ -1,5 +1,10 @@
@PACKAGE_INIT@

+if(NOT "@PLATFORM_WIN32@")
+ include(CMakeFindDependencyMacro)
+ find_dependency(SDL2 CONFIG)
+endif()
+
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
check_required_components("@CMAKE_PROJECT_NAME@")

23 changes: 23 additions & 0 deletions ports/faudio/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "faudio",
"version-string": "24.03",
"description": "FAudio - accuracy-focused XAudio reimplementation for open platforms",
"homepage": "https://fna-xna.github.io/",
"license": "Zlib",
"supports": "!uwp",
"dependencies": [
{
"name": "sdl2",
"default-features": false,
"platform": "!windows"
},
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
}
]
}
4 changes: 4 additions & 0 deletions versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -2620,6 +2620,10 @@
"baseline": "2.7.0",
"port-version": 5
},
"faudio": {
"baseline": "24.03",
"port-version": 0
},
"fawdlstty-libfv": {
"baseline": "0.0.8",
"port-version": 0
Expand Down
9 changes: 9 additions & 0 deletions versions/f-/faudio.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"versions": [
{
"git-tree": "fce143f5fce50d539e20d423c1b1cd475f8951a3",
"version-string": "24.03",
"port-version": 0
}
]
}

0 comments on commit d4ff574

Please sign in to comment.