AidaDSP / aidadsp-lv2

Aida DSP's audio plugins in lv2 format
GNU General Public License v3.0
35 stars 9 forks source link

BUG: 2 instances of the plugin #9

Closed spunktsch closed 1 year ago

spunktsch commented 1 year ago

the main output gets distorted as soon as you add a second instance of the plugin.

falkTX commented 1 year ago

I can reproduce oddities with 2 instances, where the 2nd instance gets crackling sound while the 1st instance is still fine.

the bad sound mostly goes away on the 2nd instance when deleting the 1st. adding another instance and connecting something into it brings the issue back again.

seems that we can keep 2 instances running mostly fine, but feeding audio to multiple instances generates noise. (which makes the whole thing pointless)

if we connect 2 instances in series, the bad noise goes away. this makes me think the issue is running multiple plugins in parallel, as done with mod-host with jack2.

falkTX commented 1 year ago

Seems like it, when putting in place a global mutex to ensure no 2 instances are called concurrently, there is no weird noise happening.

Testing with this

diff --git a/rt-neural-generic/src/rt-neural-generic.cpp b/rt-neural-generic/src/rt-neural-generic.cpp
index 682c795..d96460b 100644
--- a/rt-neural-generic/src/rt-neural-generic.cpp
+++ b/rt-neural-generic/src/rt-neural-generic.cpp
@@ -1,5 +1,9 @@
 #include "rt-neural-generic.h"

+// FIXME running multiple instances in parallel causes noise
+#include <pthread.h>
+static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER;
+
 /**********************************************************************************************************************************************************/

 static const LV2_Descriptor Descriptor = {
@@ -348,6 +352,7 @@ void RtNeuralGeneric::connect_port(LV2_Handle instance, uint32_t port, void *dat

 void RtNeuralGeneric::run(LV2_Handle instance, uint32_t n_samples)
 {
+    pthread_mutex_lock(&g_lock);
     RtNeuralGeneric *self = (RtNeuralGeneric*) instance;
     PluginURIs* uris   = &self->uris;

@@ -447,6 +453,7 @@ void RtNeuralGeneric::run(LV2_Handle instance, uint32_t n_samples)
     self->pregain_old = pregain;
     self->master_old = master;
     /*++++++++ END AUDIO DSP ++++++++*/
+    pthread_mutex_unlock(&g_lock);
 }

 /**********************************************************************************************************************************************************/
MaxPayne86 commented 1 year ago

@falkTX thanks, what if you remove the mutex (i.e. to replicate the issue) but you disable neural network processing with the apposite switch in one of the two plugins? My Dwarf is arriving tomorrow. I cannot replicate on my setup (derivative Mod).

falkTX commented 1 year ago

I will keep making some tests. seems that using 256 frames also works around the issue.