diff --git a/outputQt.cpp b/outputQt.cpp index f044074..a67fa63 100644 --- a/outputQt.cpp +++ b/outputQt.cpp @@ -138,8 +138,9 @@ Generator::addWave(unsigned char note, unsigned char vel) { wav.state_age = 0; wav.age = 0; wav.env = defaultEnv; - + mutex.lock(); waveList.push_back(wav); + mutex.unlock(); } qint64 @@ -228,6 +229,7 @@ Generator::generateData(qint64 len) { filteredData = QVector(numSamples, 0); // All samples for each active note in waveList are synthesized separately. + mutex.lock(); QMutableListIterator i(waveList); while (i.hasNext()) { @@ -305,7 +307,8 @@ Generator::generateData(qint64 len) { i.setValue(wav); } } - + mutex.unlock(); + for (unsigned int sample = 0; sample < numSamples; sample++) { convBuffer[convBuffer_ind] = synthData[sample]; filteredData[sample] = 0; @@ -323,7 +326,7 @@ Generator::generateData(qint64 len) { delayBuffer[delayBuffer_ind] = filteredData[sample]; delayBuffer_ind = (delayBuffer_ind + 1) % delayBuffer_size; - // Primitive Reverb algorith. + // Primitive Reverb algorithm. if (rev.active) { qreal reverb = 0; unsigned int ind; diff --git a/outputQt.h b/outputQt.h index 6047d4a..5f8d46d 100644 --- a/outputQt.h +++ b/outputQt.h @@ -25,6 +25,7 @@ #include #include +#include #include "linearSynthesis.h" #include "ADSRenvelope.h" @@ -124,6 +125,7 @@ public slots: qreal fftTimer; + QMutex mutex; #ifdef USE_FFTW fftw_complex *fftwIn, *fftwOut; fftw_plan fftwPlan;