<div dir="ltr">Hello,<div><br></div><div>I'm currently trying to make a VST that uses libpd and the pd update allowing multi instances (via pd_instance). But it's not working, for some reason that I can't find, pthread seems to crash randomly after the second VST is loaded. </div>
<div><br></div><div>Here is what I added to libpd to be able to sync the VSTs :</div><div><br></div><div><u>z_libpd.h</u></div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
EXTERN void libpd_lock(void);<br>EXTERN void libpd_unlock(void);</blockquote></div></blockquote><div><br></div><div>z_libpd.c</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
static pthread_mutex_t libpd_mutex = PTHREAD_MUTEX_INITIALIZER;<br></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
void libpd_lock() {<br> pthread_mutex_lock(&libpd_mutex);<br>}<br></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
void libpd_unlock() {<br> pthread_mutex_unlock(&libpd_mutex);<br>}</blockquote></blockquote><div><br></div><div><br></div><div><div>And here is the code of my VST that I made using the JUCE framework (I wont paste the functions I let as the ones generated by JUCE)</div>
<div><br></div><div>PluginProcessor.h</div><div><br></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
#ifndef PLUGINPROCESSOR_H_INCLUDED<br>#define PLUGINPROCESSOR_H_INCLUDED<br></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
#include "../JuceLibraryCode/JuceHeader.h"<br></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
extern "C"<br>{<br>#include "z_libpd.h"<br>#include "m_imp.h"<br>}<br><br>class TestMultiInstanceAudioProcessor : public AudioProcessor<br>{<br>public:<br> <br> TestMultiInstanceAudioProcessor();<br>
~TestMultiInstanceAudioProcessor();<br> <br> void prepareToPlay (double sampleRate, int samplesPerBlock);<br> void releaseResources();<br> void processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages);<br>
</blockquote><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> /*</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Other auto-generated functions<br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> ----<br>
*/ </blockquote><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">private:<br></blockquote>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> t_pdinstance *_pdInstance; <br> <br> float **_juceIn;<br>
float **_juceOut;<br> float *_pdIn;<br> float *_pdOut;<br> float _ticks;<br> float _blockSize;<br> void *_patchHandle;<br></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
};<br></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">#endif // PLUGINPROCESSOR_H_INCLUDED</blockquote>
</blockquote><div><div><br></div><div><br></div><div>PluginProcessor.cpp<br></div><div><br></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
#include "PluginProcessor.h"<br>#include "PluginEditor.h"<br><br>TestMultiInstanceAudioProcessor::TestMultiInstanceAudioProcessor()<br>{<br> //Initializing pd instance<br> _pdInstance = pdinstance_new();<br>
<br> <br> /// Init pd and enable dsp<br> libpd_lock();<br> pd_setinstance(_pdInstance);<br> libpd_init();<br> libpd_start_message(1);<br> libpd_add_float(1.0f);<br> libpd_finish_message("pd", "dsp");<br>
libpd_unlock();<br> //Init pd buffers<br> _juceIn = NULL;<br> _juceOut = NULL;<br> _pdIn = NULL;<br> _pdOut = NULL;<br>}<br></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
TestMultiInstanceAudioProcessor::~TestMultiInstanceAudioProcessor()<br>{<br> if (_juceIn)<br> {<br> for (int i = 0; i < getNumInputChannels(); ++i)<br> delete _juceIn[i];<br> delete _juceIn;<br> for (int i = 0; i < getNumOutputChannels(); ++i)<br>
delete _juceOut[i];<br> delete _juceOut;<br> delete _pdIn;<br> delete _pdOut;<br> }<br> delete _pdInstance;<br>}<br><br>void TestMultiInstanceAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)<br>
{<br> //Init libpd audio<br> libpd_lock();<br> pd_setinstance(_pdInstance);<br> libpd_init_audio(getNumInputChannels(),<br> getNumOutputChannels(),<br> sampleRate);<br> juce::String patchPath = juce::File::getSpecialLocation(juce::File::currentApplicationFile).getParentDirectory().getFullPathName();<br>
_patchHandle = libpd_openfile("440.pd",<br> patchPath.toRawUTF8());<br> libpd_unlock();<br> //Init buffers<br> _juceIn = new float*[getNumInputChannels()];<br> for (int i = 0; i < getNumInputChannels(); ++i)<br>
_juceIn[i] = new float[samplesPerBlock];<br> _juceOut = new float*[getNumOutputChannels()];<br> for (int i = 0; i < getNumOutputChannels(); ++i)<br> _juceOut[i] = new float[samplesPerBlock];<br> _pdIn = new float[getNumInputChannels() * samplesPerBlock];<br>
_pdOut = new float[getNumOutputChannels() * samplesPerBlock];<br> //Settings ticks<br> _ticks = samplesPerBlock / libpd_blocksize();<br> _blockSize = samplesPerBlock;<br>}<br></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
void TestMultiInstanceAudioProcessor::releaseResources()<br>{<br> if (_juceIn)<br> {<br> for (int i = 0; i < getNumInputChannels(); ++i)<br> delete _juceIn[i];<br> delete _juceIn;<br> for (int i = 0; i < getNumOutputChannels(); ++i)<br>
delete _juceOut[i];<br> delete _juceOut;<br> delete _pdIn;<br> delete _pdOut;<br> _juceIn = NULL;<br> _juceOut = NULL;<br> _pdIn = NULL;<br> _pdOut = NULL;<br> }<br> if (_patchHandle) {<br> libpd_lock();<br>
pd_setinstance(_pdInstance);<br> libpd_closefile(_patchHandle);<br> libpd_unlock();<br> }<br>}<br></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
void TestMultiInstanceAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)<br>{<br> libpd_lock();<br> pd_setinstance(_pdInstance);<br> libpd_process_float(_ticks, _pdIn, _pdOut);<br>
libpd_unlock();<br> for (int i = 0; i < _blockSize * getNumOutputChannels(); ++i)<br> for (int channel = 0; channel < getNumOutputChannels(); ++channel)<br> _juceOut[channel][i / getNumOutputChannels()] = _pdOut[i];<br>
for (int channel = 0; channel < getNumOutputChannels(); ++channel)<br> buffer.copyFrom(channel, 0, _juceOut[channel], _blockSize);<br>}</blockquote></div></div></blockquote><div><div><br></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">/*</blockquote></div></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> Other autogenerated functions </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
...</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">*/</blockquote><div> </div></blockquote>
According to my logs and my debugger, it never crashes in the VST functions, it seems to crash on some pthread functions like pthread_kill but I never use these functions...<div><br></div><div>Does someone has any idea of where it could come from ?</div>
<div><br></div><div>Regards</div><div><br></div><div>-- <br><div dir="ltr">SAUVAGEOT Paul-Arthur.</div>
</div></div>