Skip to content

Commit

Permalink
Protect the graph with a mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
pdesaulniers committed Sep 20, 2018
1 parent e07fddb commit adc67b3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Makefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export DISTRHO_NAMESPACE ?= WOLF_SHAPER_DISTRHO
export DGL_NAMESPACE ?= WOLF_SHAPER_DGL

EXTRA_INCLUDES ?=
EXTRA_LIBS ?=
EXTRA_LIBS ?= -pthread

# --------------------------------------------------------------
# Fallback to Linux if no other OS defined
Expand Down Expand Up @@ -128,8 +128,8 @@ endif
ifeq ($(HAVE_DGL),true)

ifeq ($(LINUX),true)
DGL_FLAGS = $(shell pkg-config --cflags gl x11) -lpthread
DGL_LIBS = $(shell pkg-config --libs gl x11) -lpthread
DGL_FLAGS = $(shell pkg-config --cflags gl x11)
DGL_LIBS = $(shell pkg-config --libs gl x11)
endif

ifeq ($(MACOS),true)
Expand Down
22 changes: 20 additions & 2 deletions plugins/wolf-shaper/WolfShaperPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/

#include "DistrhoPlugin.hpp"
#include "extra/Mutex.hpp"
#include "extra/ScopedPointer.hpp"

#include <cstdio>
#include <cstdlib>
Expand Down Expand Up @@ -212,6 +214,8 @@ class WolfShaper : public Plugin

void setState(const char *key, const char *value) override
{
const MutexLocker cml(mutex);

if (std::strcmp(key, "graph") == 0)
{
lineEditor.rebuildFromString(value);
Expand Down Expand Up @@ -247,7 +251,7 @@ class WolfShaper : public Plugin

float calculateValueOutsideGraph(float value)
{
const bool bipolarMode = parameters[paramBipolarMode].getRawValue() > 0.50f;
const bool bipolarMode = lineEditor.getBipolarMode();

if (bipolarMode)
{
Expand All @@ -272,7 +276,7 @@ class WolfShaper : public Plugin
return calculateValueOutsideGraph(input);
}

const bool bipolarMode = parameters[paramBipolarMode].getRawValue() > 0.50f;
const bool bipolarMode = lineEditor.getBipolarMode();

if (bipolarMode)
{
Expand All @@ -287,6 +291,17 @@ class WolfShaper : public Plugin

void run(const float **inputs, float **outputs, uint32_t frames) override
{
if (!mutex.tryLock())
{
if (outputs[0] != inputs[0])
std::memcpy(outputs[0], inputs[0], sizeof(float) * frames);

if (outputs[1] != inputs[1])
std::memcpy(outputs[1], inputs[1], sizeof(float) * frames);

return;
}

float max = 0.0f;

const int oversamplingParameter = std::round(parameters[paramOversample].getRawValue());
Expand Down Expand Up @@ -357,13 +372,16 @@ class WolfShaper : public Plugin
oversampler.downsample(outputs);

setParameterValue(paramOut, max);

mutex.unlock();
}

private:
ParamSmooth parameters[paramCount];
Oversampler oversampler;

wolf::Graph lineEditor;
Mutex mutex;

float removeDCPrev;

Expand Down

0 comments on commit adc67b3

Please sign in to comment.