waver : fix data race with ggwave instance + v1.4.1

This commit is contained in:
Georgi Gerganov
2021-07-02 21:41:40 +03:00
parent e2ef350693
commit 59f576f1e8
3 changed files with 23 additions and 14 deletions

View File

@@ -25,7 +25,7 @@ SDL_AudioDeviceID g_devIdOut = 0;
SDL_AudioSpec g_obtainedSpecInp; SDL_AudioSpec g_obtainedSpecInp;
SDL_AudioSpec g_obtainedSpecOut; SDL_AudioSpec g_obtainedSpecOut;
GGWave *g_ggWave = nullptr; std::shared_ptr<GGWave> g_ggWave = nullptr;
} }
@@ -213,9 +213,7 @@ bool GGWave_init(
} }
if (reinit) { if (reinit) {
if (g_ggWave) delete g_ggWave; g_ggWave = std::make_shared<GGWave>(GGWave::Parameters {
g_ggWave = new GGWave({
payloadLength, payloadLength,
(float) g_obtainedSpecInp.freq, (float) g_obtainedSpecInp.freq,
(float) g_obtainedSpecOut.freq, (float) g_obtainedSpecOut.freq,
@@ -228,7 +226,11 @@ bool GGWave_init(
return true; return true;
} }
GGWave *& GGWave_instance() { return g_ggWave; } std::shared_ptr<GGWave> GGWave_instance() { return g_ggWave; }
void GGWave_reset(void * parameters) {
g_ggWave = std::make_shared<GGWave>(*(GGWave::Parameters *)(parameters));
}
bool GGWave_mainLoop() { bool GGWave_mainLoop() {
if (g_devIdInp == 0 && g_devIdOut == 0) { if (g_devIdInp == 0 && g_devIdOut == 0) {
@@ -278,8 +280,7 @@ bool GGWave_deinit() {
return false; return false;
} }
delete g_ggWave; g_ggWave.reset();
g_ggWave = nullptr;
SDL_PauseAudioDevice(g_devIdInp, 1); SDL_PauseAudioDevice(g_devIdInp, 1);
SDL_CloseAudioDevice(g_devIdInp); SDL_CloseAudioDevice(g_devIdInp);

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include <string> #include <string>
#include <memory>
class GGWave; class GGWave;
@@ -8,6 +9,7 @@ class GGWave;
void GGWave_setDefaultCaptureDeviceName(std::string name); void GGWave_setDefaultCaptureDeviceName(std::string name);
bool GGWave_init(const int playbackId, const int captureId, const int payloadLength = -1, const float sampleRateOffset = 0); bool GGWave_init(const int playbackId, const int captureId, const int payloadLength = -1, const float sampleRateOffset = 0);
GGWave *& GGWave_instance(); std::shared_ptr<GGWave> GGWave_instance();
void GGWave_reset(void * parameters);
bool GGWave_mainLoop(); bool GGWave_mainLoop();
bool GGWave_deinit(); bool GGWave_deinit();

View File

@@ -590,7 +590,11 @@ void updateCore() {
static int rxDataLengthLast = 0; static int rxDataLengthLast = 0;
static float rxTimestampLast = 0.0f; static float rxTimestampLast = 0.0f;
static GGWave::TxRxData rxDataLast; static GGWave::TxRxData rxDataLast;
static auto & ggWave = GGWave_instance();
auto ggWave = GGWave_instance();
if (ggWave == nullptr) {
return;
}
{ {
std::lock_guard<std::mutex> lock(g_buffer.mutex); std::lock_guard<std::mutex> lock(g_buffer.mutex);
@@ -613,16 +617,18 @@ void updateCore() {
GGWave::SampleFormat sampleFormatOutOld = ggWave->getSampleFormatOut(); GGWave::SampleFormat sampleFormatOutOld = ggWave->getSampleFormatOut();
auto rxProtocolsOld = ggWave->getRxProtocols(); auto rxProtocolsOld = ggWave->getRxProtocols();
if (ggWave) delete ggWave; GGWave::Parameters parameters {
ggWave = new GGWave({
inputCurrent.payloadLength, inputCurrent.payloadLength,
sampleRateInpOld, sampleRateInpOld,
sampleRateOutOld + inputCurrent.sampleRateOffset, sampleRateOutOld + inputCurrent.sampleRateOffset,
GGWave::kDefaultSamplesPerFrame, GGWave::kDefaultSamplesPerFrame,
GGWave::kDefaultSoundMarkerThreshold, GGWave::kDefaultSoundMarkerThreshold,
sampleFormatInpOld, sampleFormatInpOld,
sampleFormatOutOld}); sampleFormatOutOld
};
GGWave_reset(&parameters);
ggWave = GGWave_instance();
ggWave->setRxProtocols(rxProtocolsOld); ggWave->setRxProtocols(rxProtocolsOld);
} }
@@ -1016,7 +1022,7 @@ void renderMain() {
if (windowId == WindowId::Settings) { if (windowId == WindowId::Settings) {
ImGui::BeginChild("Settings:main", ImGui::GetContentRegionAvail(), true, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse); 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::Separator();
ImGui::Text("%s", ""); ImGui::Text("%s", "");