From c2a6fad3869dc5d927ebdd14f382a8c290035559 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Mon, 13 May 2019 05:28:49 +0800 Subject: [PATCH] Support building nlsound lowlevel as dll --- code/nel/include/nel/misc/types_nl.h | 7 ++++++ code/nel/include/nel/sound/driver/buffer.h | 24 +++++++++---------- code/nel/include/nel/sound/driver/effect.h | 4 ++-- .../include/nel/sound/driver/sound_driver.h | 18 ++++++++------ code/nel/include/nel/sound/driver/source.h | 4 ++-- code/nel/src/sound/driver/CMakeLists.txt | 6 ++++- .../driver/dsound/sound_driver_dsound.cpp | 2 +- code/nel/src/sound/driver/effect.cpp | 11 +++------ .../sound/driver/openal/sound_driver_al.cpp | 4 ++-- code/nel/src/sound/driver/sound_driver.cpp | 19 +++++++-------- .../driver/xaudio2/sound_driver_xaudio2.cpp | 2 +- 11 files changed, 55 insertions(+), 46 deletions(-) diff --git a/code/nel/include/nel/misc/types_nl.h b/code/nel/include/nel/misc/types_nl.h index 6947b3a91..30c14bb09 100644 --- a/code/nel/include/nel/misc/types_nl.h +++ b/code/nel/include/nel/misc/types_nl.h @@ -544,14 +544,21 @@ typedef uint16 ucchar; #define NL_DECL_DLLIMP #endif +// TODO: Move this within libraries? #ifdef NL_DLLEXP #ifdef NLMISC_DLLEXP #define NLMISC_API NL_DECL_DLLEXP #else #define NLMISC_API NL_DECL_DLLIMP #endif +#ifdef NLSOUND_LOWLEVEL_DLLEXP +#define NLSOUND_LOWLEVEL_API NL_DECL_DLLEXP +#else +#define NLSOUND_LOWLEVEL_API NL_DECL_DLLIMP +#endif #else #define NLMISC_API +#define NLSOUND_LOWLEVEL_API #endif // To define a 64bits constant; ie: UINT64_CONSTANT(0x123456781234) diff --git a/code/nel/include/nel/sound/driver/buffer.h b/code/nel/include/nel/sound/driver/buffer.h index 8e6030949..7e9b04da4 100644 --- a/code/nel/include/nel/sound/driver/buffer.h +++ b/code/nel/include/nel/sound/driver/buffer.h @@ -99,21 +99,21 @@ public: //@{ //\name ***deprecated*** /// Set the sample format. Example: freq=44100. ***deprecated*** - void setFormat(TSampleFormat format, uint freq); + NLSOUND_LOWLEVEL_API void setFormat(TSampleFormat format, uint freq); /// Return the format and frequency. ***deprecated*** - void getFormat(TSampleFormat& format, uint& freq) const; + NLSOUND_LOWLEVEL_API void getFormat(TSampleFormat &format, uint &freq) const; /// Convert old sample format to new buffer format - static void sampleFormatToBufferFormat(TSampleFormat sampleFormat, TBufferFormat &bufferFormat, uint8 &channels, uint8 &bitsPerSample); + NLSOUND_LOWLEVEL_API static void sampleFormatToBufferFormat(TSampleFormat sampleFormat, TBufferFormat &bufferFormat, uint8 &channels, uint8 &bitsPerSample); /// Convert new buffer format to old sample format - static void bufferFormatToSampleFormat(TBufferFormat bufferFormat, uint8 channels, uint8 bitsPerSample, TSampleFormat &sampleFormat); + NLSOUND_LOWLEVEL_API static void bufferFormatToSampleFormat(TBufferFormat bufferFormat, uint8 channels, uint8 bitsPerSample, TSampleFormat &sampleFormat); //@} //@{ //\name Utility functions /// Return pcm size in bytes from duration in seconds. - static uint getPCMSizeFromDuration(float duration, uint8 channels, uint8 bitsPerSample, uint32 frequency); + NLSOUND_LOWLEVEL_API static uint getPCMSizeFromDuration(float duration, uint8 channels, uint8 bitsPerSample, uint32 frequency); /// Return duration in seconds from pcm size in bytes. - static float getDurationFromPCMSize(uint size, uint8 channels, uint8 bitsPerSample, uint32 frequency); + NLSOUND_LOWLEVEL_API static float getDurationFromPCMSize(uint size, uint8 channels, uint8 bitsPerSample, uint32 frequency); //@} //@{ @@ -126,17 +126,17 @@ public: uint8 StepIndex; }; /// Encode 16bit Mono PCM buffer into Mono ADPCM. - static void encodeADPCM(const sint16 *indata, uint8 *outdata, uint nbSample, TADPCMState &state); + NLSOUND_LOWLEVEL_API static void encodeADPCM(const sint16 *indata, uint8 *outdata, uint nbSample, TADPCMState &state); /// Decode Mono ADPCM into 16bit Mono PCM. - static void decodeADPCM(const uint8 *indata, sint16 *outdata, uint nbSample, TADPCMState &state); + NLSOUND_LOWLEVEL_API static void decodeADPCM(const uint8 *indata, sint16 *outdata, uint nbSample, TADPCMState &state); /// Read a wav file. Data type uint8 is used as unspecified buffer format. - static bool readWav(const uint8 *wav, uint size, std::vector &result, TBufferFormat &bufferFormat, uint8 &channels, uint8 &bitsPerSample, uint32 &frequency); + NLSOUND_LOWLEVEL_API static bool readWav(const uint8 *wav, uint size, std::vector &result, TBufferFormat &bufferFormat, uint8 &channels, uint8 &bitsPerSample, uint32 &frequency); /// Write a wav file. Data type uint8 does not imply a buffer of any format. - static bool writeWav(const uint8 *buffer, uint size, TBufferFormat bufferFormat, uint8 channels, uint8 bitsPerSample, uint32 frequency, NLMISC::IStream &out); + NLSOUND_LOWLEVEL_API static bool writeWav(const uint8 *buffer, uint size, TBufferFormat bufferFormat, uint8 channels, uint8 bitsPerSample, uint32 frequency, NLMISC::IStream &out); /// Convert buffer data to 16bit Mono PCM. Resulting vector size is in samples. - static bool convertToMono16PCM(const uint8 *buffer, uint size, std::vector &result, TBufferFormat bufferFormat, uint8 channels, uint8 bitsPerSample); + NLSOUND_LOWLEVEL_API static bool convertToMono16PCM(const uint8 *buffer, uint size, std::vector &result, TBufferFormat bufferFormat, uint8 channels, uint8 bitsPerSample); /// Convert 16bit Mono PCM buffer data to ADPCM. - static bool convertMono16PCMToMonoADPCM(const sint16 *buffer, uint samples, std::vector &result); + NLSOUND_LOWLEVEL_API static bool convertMono16PCMToMonoADPCM(const sint16 *buffer, uint samples, std::vector &result); //@} private: diff --git a/code/nel/include/nel/sound/driver/effect.h b/code/nel/include/nel/sound/driver/effect.h index 585e6bff1..0d6e2194e 100644 --- a/code/nel/include/nel/sound/driver/effect.h +++ b/code/nel/include/nel/sound/driver/effect.h @@ -165,8 +165,8 @@ public: /* This struct can *float* on water! */ }; - IReverbEffect(); - virtual ~IReverbEffect(); + IReverbEffect() {} + virtual ~IReverbEffect() {} /// Set the environment (you have full control now, have fun); size: [1.0, 100.0] in meters, default: 7.5 m; influences environment parameters, 7.5 is no change virtual void setEnvironment(const CEnvironment &environment = CEnvironment(), float roomSize = 7.5f) = 0; diff --git a/code/nel/include/nel/sound/driver/sound_driver.h b/code/nel/include/nel/sound/driver/sound_driver.h index e38126fff..d4298a9d9 100644 --- a/code/nel/include/nel/sound/driver/sound_driver.h +++ b/code/nel/include/nel/sound/driver/sound_driver.h @@ -25,8 +25,8 @@ #include "effect.h" /// This namespace contains the sound classes -namespace NLSOUND -{ +namespace NLSOUND { + class IBuffer; class IListener; class ISource; @@ -38,6 +38,12 @@ namespace NLSOUND # define EAX_AVAILABLE 0 #endif +/// Version of the driver interface. To increment when the interface change. +/// Interface version, increase when any part of sound_lowlevel is changed. +/// Put your name in comment to make sure you don't commit with +/// the same interface version number as someone else. +#define NLSOUND_INTERFACE_VERSION 0x17 // Kaetemi + /* * Deprecated sound sample format. * For compatibility with old code. @@ -119,16 +125,14 @@ public: virtual const std::string &unmap(const NLMISC::TStringId &stringId) = 0; }; - /// Version of the driver interface. To increment when the interface change. - static const uint32 InterfaceVersion; - /// Return driver name from type. - static const char *getDriverName(TDriver driverType); + NLSOUND_LOWLEVEL_API static const char *getDriverName(TDriver driverType); /** The static method which builds the sound driver instance * In case of failure, can throw one of these ESoundDriver exception objects: * ESoundDriverNotFound, ESoundDriverCorrupted, ESoundDriverOldVersion, ESoundDriverUnknownVersion */ - static ISoundDriver *createDriver(IStringMapperProvider *stringMapper, TDriver driverType = DriverAuto); + NLSOUND_LOWLEVEL_API static ISoundDriver *createDriver(int interfaceVersion, IStringMapperProvider *stringMapper, TDriver driverType = DriverAuto); + inline static ISoundDriver *createDriver(IStringMapperProvider *stringMapper, TDriver driverType = DriverAuto) { return createDriver(NLSOUND_INTERFACE_VERSION, stringMapper, driverType); } /// Constructor ISoundDriver() { } diff --git a/code/nel/include/nel/sound/driver/source.h b/code/nel/include/nel/sound/driver/source.h index d2f4a5186..dcb1adb88 100644 --- a/code/nel/include/nel/sound/driver/source.h +++ b/code/nel/include/nel/sound/driver/source.h @@ -481,9 +481,9 @@ public: protected: // common method used only with OptionManualRolloff. return the volume in 1/100th DB ( = mB)modified - static sint32 computeManualRollOff(sint32 volumeMB, sint32 mbMin, sint32 mbMax, double alpha, float sqrdist, float distMin, float distMax); + NLSOUND_LOWLEVEL_API static sint32 computeManualRollOff(sint32 volumeMB, sint32 mbMin, sint32 mbMax, double alpha, float sqrdist, float distMin, float distMax); // common method used only with OptionManualRolloff. return the rolloff in amplitude ratio (gain) - static float computeManualRolloff(double alpha, float sqrdist, float distMin, float distMax); + NLSOUND_LOWLEVEL_API static float computeManualRolloff(double alpha, float sqrdist, float distMin, float distMax); }; diff --git a/code/nel/src/sound/driver/CMakeLists.txt b/code/nel/src/sound/driver/CMakeLists.txt index 320c4ee05..814bc19ce 100644 --- a/code/nel/src/sound/driver/CMakeLists.txt +++ b/code/nel/src/sound/driver/CMakeLists.txt @@ -1,7 +1,7 @@ FILE(GLOB SRC *.cpp *.h) FILE(GLOB HEADERS ../../../include/nel/sound/driver/*.h) -NL_TARGET_LIB(nelsnd_lowlevel ${HEADERS} ${SRC}) +NL_TARGET_LIB2(nelsnd_lowlevel ${HEADERS} ${SRC}) TARGET_LINK_LIBRARIES(nelsnd_lowlevel nelmisc) NL_DEFAULT_PROPS(nelsnd_lowlevel "NeL, Library: Sound Lowlevel") @@ -10,6 +10,10 @@ NL_ADD_STATIC_SND_DRIVERS(nelsnd_lowlevel) NL_ADD_LIB_SUFFIX(nelsnd_lowlevel) +IF(WIN32 AND NOT WITH_STATIC2) + ADD_DEFINITIONS(-DNLSOUND_LOWLEVEL_DLLEXP) +ENDIF() + IF(WITH_PCH) ADD_NATIVE_PRECOMPILED_HEADER(nelsnd_lowlevel ${CMAKE_CURRENT_SOURCE_DIR}/stdsound_lowlevel.h ${CMAKE_CURRENT_SOURCE_DIR}/stdsound_lowlevel.cpp) ENDIF() diff --git a/code/nel/src/sound/driver/dsound/sound_driver_dsound.cpp b/code/nel/src/sound/driver/dsound/sound_driver_dsound.cpp index d95b80ca0..6d7e13915 100644 --- a/code/nel/src/sound/driver/dsound/sound_driver_dsound.cpp +++ b/code/nel/src/sound/driver/dsound/sound_driver_dsound.cpp @@ -143,7 +143,7 @@ uint32 interfaceVersionDSound() __declspec(dllexport) uint32 NLSOUND_interfaceVersion() #endif { - return ISoundDriver::InterfaceVersion; + return NLSOUND_INTERFACE_VERSION; } // ****************************************************************** diff --git a/code/nel/src/sound/driver/effect.cpp b/code/nel/src/sound/driver/effect.cpp index a25ad203a..a2a10746c 100644 --- a/code/nel/src/sound/driver/effect.cpp +++ b/code/nel/src/sound/driver/effect.cpp @@ -22,17 +22,12 @@ using namespace std; // using namespace NLMISC; -namespace NLSOUND { - -IReverbEffect::IReverbEffect() +// leave not static else this workaround don't work +void dummyToAvoidStupidCompilerWarning_effect_cpp() { - } -IReverbEffect::~IReverbEffect() -{ - -} +namespace NLSOUND { } /* namespace NLSOUND */ diff --git a/code/nel/src/sound/driver/openal/sound_driver_al.cpp b/code/nel/src/sound/driver/openal/sound_driver_al.cpp index d237f533a..7c9ce786d 100644 --- a/code/nel/src/sound/driver/openal/sound_driver_al.cpp +++ b/code/nel/src/sound/driver/openal/sound_driver_al.cpp @@ -122,7 +122,7 @@ uint32 interfaceVersionOpenAl() __declspec(dllexport) uint32 NLSOUND_interfaceVersion() #endif { - return ISoundDriver::InterfaceVersion; + return NLSOUND_INTERFACE_VERSION; } // ****************************************************************** @@ -172,7 +172,7 @@ ISoundDriver* NLSOUND_createISoundDriverInstance(ISoundDriver::IStringMapperProv uint32 NLSOUND_interfaceVersion () { - return ISoundDriver::InterfaceVersion; + return NLSOUND_INTERFACE_VERSION; } #ifndef NL_STATIC diff --git a/code/nel/src/sound/driver/sound_driver.cpp b/code/nel/src/sound/driver/sound_driver.cpp index 7eeaf9f57..c0ec0ee5a 100644 --- a/code/nel/src/sound/driver/sound_driver.cpp +++ b/code/nel/src/sound/driver/sound_driver.cpp @@ -47,13 +47,7 @@ using namespace NLMISC; -namespace NLSOUND -{ - -/// Interface version, increase when any part of sound_lowlevel is changed. -/// Put your name in comment to make sure you don't commit with -/// the same interface version number as someone else. -const uint32 ISoundDriver::InterfaceVersion = 0x16; // Kaetemi +namespace NLSOUND { #ifdef NL_STATIC @@ -103,8 +97,13 @@ const char *ISoundDriver::getDriverName(TDriver driverType) /* * The static method which builds the sound driver instance */ -ISoundDriver *ISoundDriver::createDriver(IStringMapperProvider *stringMapper, TDriver driverType) +ISoundDriver *ISoundDriver::createDriver(int interfaceVersion, IStringMapperProvider *stringMapper, TDriver driverType) { + if (interfaceVersion < NLSOUND_INTERFACE_VERSION) + throw ESoundDriverUnknownVersion("nlsnd_lowlevel"); + else if (interfaceVersion > NLSOUND_INTERFACE_VERSION) + throw ESoundDriverOldVersion("nlsnd_lowlevel"); + #ifdef NL_STATIC nlinfo("Creating statically linked sound driver %s", getDriverName(driverType)); @@ -245,9 +244,9 @@ ISoundDriver *ISoundDriver::createDriver(IStringMapperProvider *stringMapper, TD versionDriver = (ISDRV_VERSION_PROC) driverLib.getSymbolAddress(IDRV_VERSION_PROC_NAME); if (versionDriver != NULL) { - if (versionDriver()ISoundDriver::InterfaceVersion) + else if (versionDriver() > NLSOUND_INTERFACE_VERSION) throw ESoundDriverUnknownVersion(dllName); } diff --git a/code/nel/src/sound/driver/xaudio2/sound_driver_xaudio2.cpp b/code/nel/src/sound/driver/xaudio2/sound_driver_xaudio2.cpp index 992f6c66d..33cb693fc 100644 --- a/code/nel/src/sound/driver/xaudio2/sound_driver_xaudio2.cpp +++ b/code/nel/src/sound/driver/xaudio2/sound_driver_xaudio2.cpp @@ -83,7 +83,7 @@ uint32 interfaceVersionXAudio2() __declspec(dllexport) uint32 NLSOUND_interfaceVersion() #endif { - return ISoundDriver::InterfaceVersion; + return NLSOUND_INTERFACE_VERSION; } // ******************************************************************