diff --git a/WaveSabreCore/CMakeLists.txt b/WaveSabreCore/CMakeLists.txt index 31ca1e2e..eb4f7689 100644 --- a/WaveSabreCore/CMakeLists.txt +++ b/WaveSabreCore/CMakeLists.txt @@ -52,9 +52,16 @@ add_library(WaveSabreCore src/StateVariableFilter.cpp src/SynthDevice.cpp src/Thunder.cpp - src/Twister.cpp) + src/Twister.cpp + ) + +if(WIN32) + target_sources(WaveSabreCore PRIVATE + ) + + target_link_libraries(WaveSabreCore PUBLIC Msacm32.lib) +endif() -target_link_libraries(WaveSabreCore Msacm32.lib) target_include_directories(WaveSabreCore PUBLIC include) if(MSVC) @@ -69,4 +76,15 @@ if(MSVC) target_compile_options(WaveSabreCore PUBLIC $<$:/Zc:sizedDealloc->) endif() +else() + # assuming GCC or clang for now + + if(CMAKE_BUILD_TYPE EQUAL Debug) + target_compile_options(WaveSabreCore PUBLIC -g -Og) + else() + #set_property(TARGET WaveSabreCore PROPERTY INTERPROCEDURAL_OPTIMIZATION ON) + target_compile_options(WaveSabreCore + PUBLIC -O2 -fno-exceptions -fno-rtti -fno-stack-protector -fno-stack-check -fno-unwind-tables -fno-asynchronous-unwind-tables -fomit-frame-pointer -fno-threadsafe-statics + PRIVATE -ffast-math -march=nocona -ffunction-sections -fdata-sections -Wl,--gc-sections) + endif() endif() diff --git a/WaveSabrePlayerLib/CMakeLists.txt b/WaveSabrePlayerLib/CMakeLists.txt index 6a0149d4..5a67dcf9 100644 --- a/WaveSabrePlayerLib/CMakeLists.txt +++ b/WaveSabrePlayerLib/CMakeLists.txt @@ -22,6 +22,9 @@ target_link_libraries(WaveSabrePlayerLib target_include_directories(WaveSabrePlayerLib PUBLIC include) +# we need C++11 for std::atomic +set_property(TARGET WaveSabrePlayerLib PROPERTY CXX_STANDARD 11) + if(MSVC) target_compile_definitions(WaveSabrePlayerLib PRIVATE _CRT_SECURE_NO_WARNINGS) target_compile_options(WaveSabrePlayerLib PUBLIC diff --git a/WaveSabrePlayerLib/include/WaveSabrePlayerLib/SongRenderer.h b/WaveSabrePlayerLib/include/WaveSabrePlayerLib/SongRenderer.h index f9c6a122..ea266996 100644 --- a/WaveSabrePlayerLib/include/WaveSabrePlayerLib/SongRenderer.h +++ b/WaveSabrePlayerLib/include/WaveSabrePlayerLib/SongRenderer.h @@ -172,7 +172,7 @@ namespace WaveSabrePlayerLib int bpm; int sampleRate; double length; - + int numDevices; WaveSabreCore::Device **devices; diff --git a/WaveSabrePlayerLib/src/SongRenderer.cpp b/WaveSabrePlayerLib/src/SongRenderer.cpp index 4923ac72..456a0e19 100644 --- a/WaveSabrePlayerLib/src/SongRenderer.cpp +++ b/WaveSabrePlayerLib/src/SongRenderer.cpp @@ -1,5 +1,19 @@ #include +#include +#include + +#ifdef _MSC_VER +void* __cdecl operator new[](size_t size) +{ + return malloc(size); +} +void __cdecl operator delete[](void* ptr) +{ + return free(ptr); +} +#endif + using namespace WaveSabreCore; namespace WaveSabrePlayerLib @@ -195,7 +209,8 @@ namespace WaveSabrePlayerLib // We have a free track that we can work on, yay! // Let's try to mark it so that no other thread takes it - if ((TrackRenderState)InterlockedCompareExchange((unsigned int *)&trackRenderStates[i], (unsigned int)TrackRenderState::Rendering, (unsigned int)TrackRenderState::Idle) == TrackRenderState::Idle) + int xv = (int)TrackRenderState::Idle; + if (std::atomic_compare_exchange_strong((std::atomic_int *)&trackRenderStates[i], &xv, (int)TrackRenderState::Rendering)) { // We marked it successfully, so now we'll do the work tracks[i]->Run(renderThreadNumFloatSamples); @@ -206,7 +221,8 @@ namespace WaveSabrePlayerLib } } - if (!InterlockedDecrement(&renderThreadsRunning)) + // returns the value *before* the call + if (std::atomic_fetch_sub((std::atomic_int *)&renderThreadsRunning, 1) == 1) SetEvent(renderDoneEvent); return true;