From 00f4e3f7792e20f8d7a9013e56621efed3cfbdf3 Mon Sep 17 00:00:00 2001 From: Mooneer Salem Date: Wed, 2 Oct 2024 10:32:14 -0700 Subject: [PATCH] Export symbols so we can actually link other Windows projects to librade.dll. --- CMakeLists.txt | 2 ++ src/CMakeLists.txt | 18 +++++++++++------- src/rade_api.h | 32 +++++++++++++++++++------------- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 459c0bf..01a0038 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,8 @@ project(RADAE LANGUAGES C ) +option(BUILD_SHARED_LIBS + "Build shared library. Set to OFF for static library." ON) option(AVX "Enable AVX CPU optimizations." ON) if(NOT CODEC2_DEV_BUILD_DIR) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index aae1565..fd563e3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,12 +3,16 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}) add_executable(lpcnet_demo lpcnet_demo.c) target_link_libraries(lpcnet_demo opus m) -add_executable(radae_tx radae_tx.c rade_api.c) -#set_source_files_properties(rade_api.c PROPERTIES COMPILE_FLAGS "${PYTHON_C_FLAGS}") -target_link_libraries(radae_tx Python3::Python Python3::NumPy) +add_library(rade rade_api.c) +target_link_libraries(rade Python3::Python Python3::NumPy) +set_target_properties(rade PROPERTIES + SOVERSION "0.1" + PUBLIC_HEADER "rade_api.h" +) -add_executable(radae_rx radae_rx.c rade_api.c) -target_link_libraries(radae_rx Python3::Python Python3::NumPy) +add_executable(radae_tx radae_tx.c) +target_link_libraries(radae_tx rade Python3::Python Python3::NumPy) + +add_executable(radae_rx radae_rx.c) +target_link_libraries(radae_rx rade Python3::Python Python3::NumPy) -add_library(rade SHARED rade_api.c) -target_link_libraries(rade Python3::Python Python3::NumPy) diff --git a/src/rade_api.h b/src/rade_api.h index 7dd6694..cecd365 100644 --- a/src/rade_api.h +++ b/src/rade_api.h @@ -39,6 +39,12 @@ #include +#if _WIN32 +#define RADE_EXPORT __declspec(dllexport) __stdcall +#else +#define RADE_EXPORT + +#endif // _WIN32 // This declares a single-precision (float) complex number #ifndef __RADE_COMP__ @@ -58,38 +64,38 @@ extern "C" { #define RADE_SPEECH_SAMPLE_RATE 16000 // speech sample rate // note single context only in this version, one context has one Tx, and one Rx -struct rade *rade_open(char model_file[]); -void rade_close(struct rade *r); +RADE_EXPORT struct rade *rade_open(char model_file[]); +RADE_EXPORT void rade_close(struct rade *r); // Allows API users to determine if the API has changed -int rade_version(void); +RADE_EXPORT int rade_version(void); // helpers to set up arrays -int rade_n_tx_out(struct rade *r); -int rade_n_tx_eoo_out(struct rade *r); -int rade_nin_max(struct rade *r); -int rade_n_features_in_out(struct rade *r); +RADE_EXPORT int rade_n_tx_out(struct rade *r); +RADE_EXPORT int rade_n_tx_eoo_out(struct rade *r); +RADE_EXPORT int rade_nin_max(struct rade *r); +RADE_EXPORT int rade_n_features_in_out(struct rade *r); // note vocoder is not encapsulated in API in this version // returns number of RADE_COMP samples written to tx_out[] -int rade_tx(struct rade *r, RADE_COMP tx_out[], float features_in[]); +RADE_EXPORT int rade_tx(struct rade *r, RADE_COMP tx_out[], float features_in[]); // call this for the final frame at the end of over // returns the number of RADE_COMP samples written to tx_eoo_out[] -int rade_tx_eoo(struct rade *r, RADE_COMP tx_eoo_out[]); +RADE_EXPORT int rade_tx_eoo(struct rade *r, RADE_COMP tx_eoo_out[]); // call me before each call to rade_rx(), provide nin samples to rx_in[] -int rade_nin(struct rade *r); +RADE_EXPORT int rade_nin(struct rade *r); // returns non-zero if features_out[] contains valid output. The number // returned is the number of samples written to features_out[] -int rade_rx(struct rade *r, float features_out[], RADE_COMP rx_in[]); +RADE_EXPORT int rade_rx(struct rade *r, float features_out[], RADE_COMP rx_in[]); // returns non-zero if Rx is currently in sync -int rade_sync(struct rade *r); +RADE_EXPORT int rade_sync(struct rade *r); // returns the current frequency offset of the Rx signal ( when rade_sync()!=0 ) -float rade_freq_offset(struct rade *r); +RADE_EXPORT float rade_freq_offset(struct rade *r); #ifdef __cplusplus }