diff --git a/examples/ggwave-common-sdl2.cpp b/examples/ggwave-common-sdl2.cpp index acfa9b5..c68321b 100644 --- a/examples/ggwave-common-sdl2.cpp +++ b/examples/ggwave-common-sdl2.cpp @@ -25,7 +25,7 @@ SDL_AudioDeviceID g_devIdOut = 0; SDL_AudioSpec g_obtainedSpecInp; SDL_AudioSpec g_obtainedSpecOut; -GGWave *g_ggWave = nullptr; +std::shared_ptr g_ggWave = nullptr; } @@ -213,9 +213,7 @@ bool GGWave_init( } if (reinit) { - if (g_ggWave) delete g_ggWave; - - g_ggWave = new GGWave({ + g_ggWave = std::make_shared(GGWave::Parameters { payloadLength, (float) g_obtainedSpecInp.freq, (float) g_obtainedSpecOut.freq, @@ -228,7 +226,11 @@ bool GGWave_init( return true; } -GGWave *& GGWave_instance() { return g_ggWave; } +std::shared_ptr GGWave_instance() { return g_ggWave; } + +void GGWave_reset(void * parameters) { + g_ggWave = std::make_shared(*(GGWave::Parameters *)(parameters)); +} bool GGWave_mainLoop() { if (g_devIdInp == 0 && g_devIdOut == 0) { @@ -278,8 +280,7 @@ bool GGWave_deinit() { return false; } - delete g_ggWave; - g_ggWave = nullptr; + g_ggWave.reset(); SDL_PauseAudioDevice(g_devIdInp, 1); SDL_CloseAudioDevice(g_devIdInp); diff --git a/examples/ggwave-common-sdl2.h b/examples/ggwave-common-sdl2.h index d7d7ad4..13759de 100644 --- a/examples/ggwave-common-sdl2.h +++ b/examples/ggwave-common-sdl2.h @@ -1,6 +1,7 @@ #pragma once #include +#include class GGWave; @@ -8,6 +9,7 @@ class GGWave; void GGWave_setDefaultCaptureDeviceName(std::string name); bool GGWave_init(const int playbackId, const int captureId, const int payloadLength = -1, const float sampleRateOffset = 0); -GGWave *& GGWave_instance(); +std::shared_ptr GGWave_instance(); +void GGWave_reset(void * parameters); bool GGWave_mainLoop(); bool GGWave_deinit(); diff --git a/examples/waver/common.cpp b/examples/waver/common.cpp index cfabdd1..c626b3d 100644 --- a/examples/waver/common.cpp +++ b/examples/waver/common.cpp @@ -590,7 +590,11 @@ void updateCore() { static int rxDataLengthLast = 0; static float rxTimestampLast = 0.0f; static GGWave::TxRxData rxDataLast; - static auto & ggWave = GGWave_instance(); + + auto ggWave = GGWave_instance(); + if (ggWave == nullptr) { + return; + } { std::lock_guard lock(g_buffer.mutex); @@ -613,16 +617,18 @@ void updateCore() { GGWave::SampleFormat sampleFormatOutOld = ggWave->getSampleFormatOut(); auto rxProtocolsOld = ggWave->getRxProtocols(); - if (ggWave) delete ggWave; - - ggWave = new GGWave({ + GGWave::Parameters parameters { inputCurrent.payloadLength, sampleRateInpOld, sampleRateOutOld + inputCurrent.sampleRateOffset, GGWave::kDefaultSamplesPerFrame, GGWave::kDefaultSoundMarkerThreshold, sampleFormatInpOld, - sampleFormatOutOld}); + sampleFormatOutOld + }; + + GGWave_reset(¶meters); + ggWave = GGWave_instance(); ggWave->setRxProtocols(rxProtocolsOld); } @@ -1016,7 +1022,7 @@ void renderMain() { if (windowId == WindowId::Settings) { ImGui::BeginChild("Settings:main", ImGui::GetContentRegionAvail(), true, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse); - ImGui::Text("Waver v1.4.0"); + ImGui::Text("Waver v1.4.1"); ImGui::Separator(); ImGui::Text("%s", "");