Skip to content

Commit

Permalink
libmysofa: add package (#6076)
Browse files Browse the repository at this point in the history
* init

* fixup

* revise

* re-check

* check old solution

* test

* check

* check

* export surface

* h

* pic off

* "-DCMAKE_POLICY_DEFAULT_CMP0057=NEW"

* fix export

* test

* check without pos-i-code

* follow upstream

* check ems & bsd

* h

* !wasm & is_plat("cross", "bsd")

* revise

* follow upstream

* test CI

* retry

* return os.rm("share/default.sofa")

* Update xmake.lua

* rerun ci

* CRLF -> LF

* test ci

* check wasm for defined(__UBUNTU__)

* test ci
  • Loading branch information
luadebug authored Jan 3, 2025
1 parent 4aa0a40 commit e6a84e8
Show file tree
Hide file tree
Showing 2 changed files with 306 additions and 0 deletions.
258 changes: 258 additions & 0 deletions packages/l/libmysofa/patches/v1.3.2/fix-build.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index dcaa92a..76fd021 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -10,38 +10,39 @@ endmacro(use_c99)

use_c99()

+find_package(ZLIB REQUIRED)
configure_file(config.h.in config.h)
-include_directories(${CMAKE_CURRENT_BINARY_DIR})
+include_directories(${CMAKE_CURRENT_BINARY_DIR} ${ZLIB_INCLUDE_DIRS})

if(NOT MSVC)
- if(NOT WIN32)
+ if(NOT WIN32 AND NOT EMSCRIPTEN)
find_library(MATH m)
else()
set(MATH "")
endif()
- include(FindZLIB)
else()
set(MATH "")
+ if(0)
find_program(NUGET nuget)
if(NUGET)
execute_process(COMMAND ${NUGET} install zlib)
endif()
include_directories(
${PROJECT_SOURCE_DIR}/windows/third-party/zlib-1.2.11/include/)
+ endif()
endif()

if(NOT MSVC)
- if(NOT WIN32)
+ if(NOT WIN32 AND NOT EMSCRIPTEN)
find_library(MATH m)
else()
set(MATH "")
endif()
- include(FindZLIB)
- include_directories(${ZLIB_INCLUDE_DIRS})
set(PKG_CONFIG_PRIVATELIBS "-lm ${PKG_CONFIG_PRIVATELIBS}")
set(PKG_CONFIG_PRIVATELIBS "-lz ${PKG_CONFIG_PRIVATELIBS}")
else()
set(MATH "")
+ if(0)
find_program(NUGET nuget)
if(NOT NUGET)
message(
@@ -53,6 +54,7 @@ else()
endif()
include_directories(
${PROJECT_SOURCE_DIR}/windows/third-party/zlib-1.2.11/include/)
+ endif()
endif()

set(libsrc
@@ -80,6 +82,7 @@ set(libsrc
set(public-headers
hrtf/mysofa.h
)
+install(FILES "${public-headers}" DESTINATION include)

if(BUILD_STATIC_LIBS)
add_library(mysofa-static STATIC ${libsrc})
@@ -88,7 +91,7 @@ target_include_directories(mysofa-static
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/hrtf>"
$<INSTALL_INTERFACE:include/>
)
-target_link_libraries(mysofa-static LINK_PRIVATE ${MATH} ${ZLIB_LIBRARIES})
+target_link_libraries(mysofa-static LINK_PRIVATE ${MATH} ZLIB::ZLIB)
set_target_properties(
mysofa-static
PROPERTIES OUTPUT_NAME mysofa CLEAN_DIRECT_OUTPUT 1 POSITION_INDEPENDENT_CODE
@@ -169,6 +172,11 @@ else()
mysofa_export.h)
endif()

+install(
+ FILES ${PROJECT_BINARY_DIR}/src/mysofa_export.h
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
+)
+
if(BUILD_TESTS)
add_executable(mysofa2json tests/sofa2json.c tests/json.c)
if(BUILD_STATIC_LIBS)
diff --git a/src/hrtf/mysofa.h b/src/hrtf/mysofa.h
index 206e77b..82bc9d9 100644
--- a/src/hrtf/mysofa.h
+++ b/src/hrtf/mysofa.h
@@ -14,6 +14,7 @@ extern "C" {
#include <stdint.h>
#include <stddef.h>

+#include "mysofa_export.h"
#define MYSOFA_DEFAULT_NEIGH_STEP_ANGLE 0.5f
#define MYSOFA_DEFAULT_NEIGH_STEP_RADIUS 0.01f

@@ -127,44 +128,44 @@ enum {
MYSOFA_ONLY_SOURCES_WITH_MC_SUPPORTED
};

-struct MYSOFA_HRTF *mysofa_load(const char *filename, int *err);
-struct MYSOFA_HRTF *mysofa_load_data(const char *data, size_t size, int *err);
+MYSOFA_EXPORT struct MYSOFA_HRTF *mysofa_load(const char *filename, int *err);
+MYSOFA_EXPORT struct MYSOFA_HRTF *mysofa_load_data(const char *data, size_t size, int *err);

-int mysofa_check(struct MYSOFA_HRTF *hrtf);
-char *mysofa_getAttribute(struct MYSOFA_ATTRIBUTE *attr, char *name);
-void mysofa_tospherical(struct MYSOFA_HRTF *hrtf);
-void mysofa_tocartesian(struct MYSOFA_HRTF *hrtf);
-void mysofa_free(struct MYSOFA_HRTF *hrtf);
+MYSOFA_EXPORT int mysofa_check(struct MYSOFA_HRTF *hrtf);
+MYSOFA_EXPORT char *mysofa_getAttribute(struct MYSOFA_ATTRIBUTE *attr, char *name);
+MYSOFA_EXPORT void mysofa_tospherical(struct MYSOFA_HRTF *hrtf);
+MYSOFA_EXPORT void mysofa_tocartesian(struct MYSOFA_HRTF *hrtf);
+MYSOFA_EXPORT void mysofa_free(struct MYSOFA_HRTF *hrtf);

-struct MYSOFA_LOOKUP *mysofa_lookup_init(struct MYSOFA_HRTF *hrtf);
-int mysofa_lookup(struct MYSOFA_LOOKUP *lookup, float *coordinate);
-void mysofa_lookup_free(struct MYSOFA_LOOKUP *lookup);
+MYSOFA_EXPORT struct MYSOFA_LOOKUP *mysofa_lookup_init(struct MYSOFA_HRTF *hrtf);
+MYSOFA_EXPORT int mysofa_lookup(struct MYSOFA_LOOKUP *lookup, float *coordinate);
+MYSOFA_EXPORT void mysofa_lookup_free(struct MYSOFA_LOOKUP *lookup);

-struct MYSOFA_NEIGHBORHOOD *
+MYSOFA_EXPORT struct MYSOFA_NEIGHBORHOOD *
mysofa_neighborhood_init(struct MYSOFA_HRTF *hrtf,
struct MYSOFA_LOOKUP *lookup);
-struct MYSOFA_NEIGHBORHOOD *mysofa_neighborhood_init_withstepdefine(
+MYSOFA_EXPORT struct MYSOFA_NEIGHBORHOOD *mysofa_neighborhood_init_withstepdefine(
struct MYSOFA_HRTF *hrtf, struct MYSOFA_LOOKUP *lookup,
float neighbor_angle_step, float neighbor_radius_step);
-int *mysofa_neighborhood(struct MYSOFA_NEIGHBORHOOD *neighborhood, int pos);
-void mysofa_neighborhood_free(struct MYSOFA_NEIGHBORHOOD *neighborhood);
+MYSOFA_EXPORT int *mysofa_neighborhood(struct MYSOFA_NEIGHBORHOOD *neighborhood, int pos);
+MYSOFA_EXPORT void mysofa_neighborhood_free(struct MYSOFA_NEIGHBORHOOD *neighborhood);

-float *mysofa_interpolate(struct MYSOFA_HRTF *hrtf, float *cordinate,
+MYSOFA_EXPORT float *mysofa_interpolate(struct MYSOFA_HRTF *hrtf, float *cordinate,
int nearest, int *neighborhood, float *fir,
float *delays);

-int mysofa_resample(struct MYSOFA_HRTF *hrtf, float samplerate);
-float mysofa_loudness(struct MYSOFA_HRTF *hrtf);
-int mysofa_minphase(struct MYSOFA_HRTF *hrtf, float threshold);
+MYSOFA_EXPORT int mysofa_resample(struct MYSOFA_HRTF *hrtf, float samplerate);
+MYSOFA_EXPORT float mysofa_loudness(struct MYSOFA_HRTF *hrtf);
+MYSOFA_EXPORT int mysofa_minphase(struct MYSOFA_HRTF *hrtf, float threshold);

-struct MYSOFA_EASY *mysofa_cache_lookup(const char *filename, float samplerate);
-struct MYSOFA_EASY *mysofa_cache_store(struct MYSOFA_EASY *,
+MYSOFA_EXPORT struct MYSOFA_EASY *mysofa_cache_lookup(const char *filename, float samplerate);
+MYSOFA_EXPORT struct MYSOFA_EASY *mysofa_cache_store(struct MYSOFA_EASY *,
const char *filename, float samplerate);
-void mysofa_cache_release(struct MYSOFA_EASY *);
-void mysofa_cache_release_all(void);
+MYSOFA_EXPORT void mysofa_cache_release(struct MYSOFA_EASY *);
+MYSOFA_EXPORT void mysofa_cache_release_all(void);

-void mysofa_c2s(float values[3]);
-void mysofa_s2c(float values[3]);
+MYSOFA_EXPORT void mysofa_c2s(float values[3]);
+MYSOFA_EXPORT void mysofa_s2c(float values[3]);

struct MYSOFA_EASY {
struct MYSOFA_HRTF *hrtf;
@@ -173,38 +174,38 @@ struct MYSOFA_EASY {
float *fir;
};

-struct MYSOFA_EASY *mysofa_open(const char *filename, float samplerate,
+MYSOFA_EXPORT struct MYSOFA_EASY *mysofa_open(const char *filename, float samplerate,
int *filterlength, int *err);
-struct MYSOFA_EASY *mysofa_open_no_norm(const char *filename, float samplerate,
+MYSOFA_EXPORT struct MYSOFA_EASY *mysofa_open_no_norm(const char *filename, float samplerate,
int *filterlength, int *err);
-struct MYSOFA_EASY *mysofa_open_advanced(const char *filename, float samplerate,
+MYSOFA_EXPORT struct MYSOFA_EASY *mysofa_open_advanced(const char *filename, float samplerate,
int *filterlength, int *err, bool norm,
float neighbor_angle_step,
float neighbor_radius_step);
-struct MYSOFA_EASY *mysofa_open_data(const char *data, long size,
+MYSOFA_EXPORT struct MYSOFA_EASY *mysofa_open_data(const char *data, long size,
float samplerate, int *filterlength,
int *err);
-struct MYSOFA_EASY *mysofa_open_data_no_norm(const char *data, long size,
+MYSOFA_EXPORT struct MYSOFA_EASY *mysofa_open_data_no_norm(const char *data, long size,
float samplerate,
int *filterlength, int *err);
-struct MYSOFA_EASY *mysofa_open_data_advanced(
+MYSOFA_EXPORT struct MYSOFA_EASY *mysofa_open_data_advanced(
const char *data, long size, float samplerate, int *filterlength, int *err,
bool norm, float neighbor_angle_step, float neighbor_radius_step);
-struct MYSOFA_EASY *mysofa_open_cached(const char *filename, float samplerate,
+MYSOFA_EXPORT struct MYSOFA_EASY *mysofa_open_cached(const char *filename, float samplerate,
int *filterlength, int *err);
-void mysofa_getfilter_short(struct MYSOFA_EASY *easy, float x, float y, float z,
+MYSOFA_EXPORT void mysofa_getfilter_short(struct MYSOFA_EASY *easy, float x, float y, float z,
short *IRleft, short *IRright, int *delayLeft,
int *delayRight);
-void mysofa_getfilter_float(struct MYSOFA_EASY *easy, float x, float y, float z,
+MYSOFA_EXPORT void mysofa_getfilter_float(struct MYSOFA_EASY *easy, float x, float y, float z,
float *IRleft, float *IRright, float *delayLeft,
float *delayRight);
-void mysofa_getfilter_float_nointerp(struct MYSOFA_EASY *easy, float x, float y,
+MYSOFA_EXPORT void mysofa_getfilter_float_nointerp(struct MYSOFA_EASY *easy, float x, float y,
float z, float *IRleft, float *IRright,
float *delayLeft, float *delayRight);
-void mysofa_close(struct MYSOFA_EASY *easy);
-void mysofa_close_cached(struct MYSOFA_EASY *easy);
+MYSOFA_EXPORT void mysofa_close(struct MYSOFA_EASY *easy);
+MYSOFA_EXPORT void mysofa_close_cached(struct MYSOFA_EASY *easy);

-void mysofa_getversion(int *major, int *minor, int *patch);
+MYSOFA_EXPORT void mysofa_getversion(int *major, int *minor, int *patch);

#ifdef __cplusplus
}
diff --git a/src/hrtf/portable_endian.h b/src/hrtf/portable_endian.h
index d1e76f5..5fb4b55 100644
--- a/src/hrtf/portable_endian.h
+++ b/src/hrtf/portable_endian.h
@@ -13,7 +13,7 @@

#endif

-#if defined(__linux__) || defined(__CYGWIN__)
+#if defined(__linux__) || defined(__CYGWIN__) || defined(__illumos__) || defined(__GNU__) || defined(__linux) || defined(linux) || defined(__gnu_linux__)

# include <endian.h>

@@ -41,23 +41,10 @@
# define __LITTLE_ENDIAN LITTLE_ENDIAN
# define __PDP_ENDIAN PDP_ENDIAN

-#elif defined(__OpenBSD__)
+#elif defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)

# include <sys/endian.h>

-#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
-
-# include <sys/endian.h>
-
-# define be16toh(x) betoh16(x)
-# define le16toh(x) letoh16(x)
-
-# define be32toh(x) betoh32(x)
-# define le32toh(x) letoh32(x)
-
-# define be64toh(x) betoh64(x)
-# define le64toh(x) letoh64(x)
-
#elif defined(__WINDOWS__)

# include <windows.h>
48 changes: 48 additions & 0 deletions packages/l/libmysofa/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package("libmysofa")
set_homepage("https://github.com/hoene/libmysofa")
set_description("Reader for AES SOFA files to get better HRTFs")

set_license("BSD-3-Clause")

add_urls("https://github.com/hoene/libmysofa/archive/refs/tags/$(version).tar.gz",
"https://github.com/hoene/libmysofa.git")

add_versions("v1.3.2", "6c5224562895977e87698a64cb7031361803d136057bba35ed4979b69ab4ba76")

add_patches("v1.3.2", "patches/v1.3.2/fix-build.patch", "a28aed4c5e766081ff90a7aed74c58b77927432a80385f6aad9f3278cde6bb59")

add_deps("cmake", "zlib")

if is_plat("linux", "bsd") then
add_syslinks("pthread")
end

on_install(function (package)
if package:is_plat("wasm", "cross") then
io.replace("src/CMakeLists.txt", [[find_library(MATH m)]], [[set(MATH "")]], {plain = true})
end
if is_host("windows") and package:is_plat("wasm") then
io.replace("src/hrtf/portable_endian.h", [[elif defined(__WINDOWS__)]], [[elif 1]], {plain = true})
end
if is_host("linux") and package:is_plat("wasm") then
io.replace("src/hrtf/portable_endian.h", [[if defined(__linux__)]], [[if 1]], {plain = true})
end
if is_host("bsd") and package:is_plat("wasm") then
io.replace("src/hrtf/portable_endian.h", [[defined(__FreeBSD__)]], [[1]], {plain = true})
end
if is_host("macosx") and package:is_plat("wasm") then
io.replace("src/hrtf/portable_endian.h", [[elif defined(__APPLE__)]], [[elif 1]], {plain = true})
end
os.rm("windows/third-party/zlib-1.2.11")
os.rm("share/default.sofa")
os.cp("share/MIT_KEMAR_normal_pinna.sofa", "share/default.sofa")
local configs = {"-DBUILD_TESTS=OFF", "-DCMAKE_POLICY_DEFAULT_CMP0057=NEW"}
table.insert(configs, "-DBUILD_STATIC_LIBS=" .. (package:config("shared") and "OFF" or "ON"))
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
import("package.tools.cmake").install(package, configs)
end)

on_test(function (package)
assert(package:has_cfuncs("mysofa_open", {includes = "mysofa.h"}))
end)

0 comments on commit e6a84e8

Please sign in to comment.