From 407f516e0d2b7e2bc20a68c92e85e51c6e58b915 Mon Sep 17 00:00:00 2001 From: oparviai Date: Fri, 3 Nov 2017 20:08:10 +0000 Subject: [PATCH] GNU compilation of SoundTouchDll that has easy function importing interfaces for java, mono etc --- source/SoundTouchDLL/SoundTouchDLL.cpp | 44 ++++++++++++++------------ source/SoundTouchDLL/SoundTouchDLL.h | 41 ++++++++++++++++-------- source/SoundTouchDLL/make-gnu-dll.sh | 8 +++++ 3 files changed, 59 insertions(+), 34 deletions(-) create mode 100755 source/SoundTouchDLL/make-gnu-dll.sh diff --git a/source/SoundTouchDLL/SoundTouchDLL.cpp b/source/SoundTouchDLL/SoundTouchDLL.cpp index a3e016a..b24485d 100644 --- a/source/SoundTouchDLL/SoundTouchDLL.cpp +++ b/source/SoundTouchDLL/SoundTouchDLL.cpp @@ -34,10 +34,32 @@ // //////////////////////////////////////////////////////////////////////////////// -#include + +#if defined(_WIN32) || defined(WIN32) + #include + + // DLL main in Windows compilation + BOOL APIENTRY DllMain( HANDLE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved + ) + { + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + return TRUE; + } +#endif + +#include #include #include "SoundTouchDLL.h" -#include "soundtouch.h" +#include "SoundTouch.h" using namespace soundtouch; @@ -45,24 +67,6 @@ using namespace soundtouch; #error "error - compile the dll version with float samples" #endif // SOUNDTOUCH_INTEGER_SAMPLES - -BOOL APIENTRY DllMain( HANDLE hModule, - DWORD ul_reason_for_call, - LPVOID lpReserved - ) -{ - switch (ul_reason_for_call) - { - case DLL_PROCESS_ATTACH: - case DLL_THREAD_ATTACH: - case DLL_THREAD_DETACH: - case DLL_PROCESS_DETACH: - break; - } - return TRUE; -} - - ////////////// typedef struct diff --git a/source/SoundTouchDLL/SoundTouchDLL.h b/source/SoundTouchDLL/SoundTouchDLL.h index 9bd3d2c..47533be 100644 --- a/source/SoundTouchDLL/SoundTouchDLL.h +++ b/source/SoundTouchDLL/SoundTouchDLL.h @@ -37,24 +37,37 @@ #ifndef _SoundTouchDLL_h_ #define _SoundTouchDLL_h_ -#ifdef __cplusplus +#if defined(_WIN32) || defined(WIN32) + // Windows + #ifndef __cplusplus + #error "Expected g++" + #endif + + #ifdef DLL_EXPORTS + #define SOUNDTOUCHDLL_API extern "C" __declspec(dllexport) + #else + #define SOUNDTOUCHDLL_API extern "C" __declspec(dllimport) + #endif -#ifdef DLL_EXPORTS - #define SOUNDTOUCHDLL_API extern "C" __declspec(dllexport) #else - #define SOUNDTOUCHDLL_API extern "C" __declspec(dllimport) + // GNU version + + #ifdef DLL_EXPORTS + // GCC declaration for exporting functions + #define SOUNDTOUCHDLL_API extern "C" __attribute__((__visibility__("default"))) + #else + // GCC doesn't require DLL imports + #define SOUNDTOUCHDLL_API + #endif + + // Linux-replacements for Windows declarations: + #define __cdecl + typedef unsigned int DWORD; + #define FALSE 0 + #define TRUE 1 + #endif -#else - -#ifdef DLL_EXPORTS - #define SOUNDTOUCHDLL_API __declspec(dllexport) -#else - #define SOUNDTOUCHDLL_API __declspec(dllimport) -#endif - -#endif // __cplusplus - typedef void * HANDLE; /// Create a new instance of SoundTouch processor. diff --git a/source/SoundTouchDLL/make-gnu-dll.sh b/source/SoundTouchDLL/make-gnu-dll.sh new file mode 100755 index 0000000..4e622f1 --- /dev/null +++ b/source/SoundTouchDLL/make-gnu-dll.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# +# This script compiles SoundTouch dynamic-link library for GNU environment +# with wrapper functions that are easier to import to Java / Mono / etc +# + +g++ -fPIC -shared -DDLL_EXPORTS -fvisibility=hidden -I../../include -o SoundTouchDll.so \ + SoundTouchDLL.cpp ../SoundTouch/*.cpp -I../SoundTouch -O3 -msse