Added lock to inser FXs to avoid crashes.

Code clean up.
pull/764/head
jnonis 7 months ago
parent d98c7cf701
commit 7bcba9183a
  1. 2
      src/Makefile
  2. 11
      src/effect_base.cpp
  3. 12
      src/effect_base.h
  4. 2
      src/effect_chorus.h
  5. 2
      src/effect_delay.h
  6. 8
      src/effects.h
  7. 42
      src/minidexed.cpp
  8. 5
      src/minidexed.h

@ -9,7 +9,7 @@ CMSIS_DIR = ../CMSIS_5/CMSIS
OBJS = main.o kernel.o minidexed.o config.o userinterface.o uimenu.o \ OBJS = main.o kernel.o minidexed.o config.o userinterface.o uimenu.o \
mididevice.o midikeyboard.o serialmididevice.o pckeyboard.o \ mididevice.o midikeyboard.o serialmididevice.o pckeyboard.o \
sysexfileloader.o performanceconfig.o perftimer.o \ sysexfileloader.o performanceconfig.o perftimer.o \
effect.o effect_chorus.o effect_delay.o \ effect_base.o effect_chorus.o effect_delay.o \
effect_compressor.o effect_platervbstereo.o uibuttons.o midipin.o effect_compressor.o effect_platervbstereo.o uibuttons.o midipin.o
OPTIMIZE = -O3 OPTIMIZE = -O3

@ -1,4 +1,4 @@
#include "effect.h" #include "effect_base.h"
AudioEffect::AudioEffect(float32_t samplerate) AudioEffect::AudioEffect(float32_t samplerate)
{ {
@ -24,6 +24,15 @@ unsigned AudioEffect::getId()
return EFFECT_NONE; return EFFECT_NONE;
} }
void AudioEffect::process(const float32_t* inblock, float32_t* outblock, uint16_t len)
{
// Mono process
// Dummy buffer for right channel
float32_t dummyBuffer[len];
process(inblock, dummyBuffer, outblock, dummyBuffer, len);
}
void AudioEffect::process(const float32_t* inblockL, const float32_t* inblockR, float32_t* outblockL, float32_t* outblockR, uint16_t len) void AudioEffect::process(const float32_t* inblockL, const float32_t* inblockR, float32_t* outblockL, float32_t* outblockR, uint16_t len)
{ {
if (bypass) { if (bypass) {

@ -1,9 +1,8 @@
#ifndef _EFFECT_H #ifndef _EFFECT_BASE_H
#define _EFFECT_H #define _EFFECT_BASE_H
#include <stdint.h> //#include <stdint.h>
#include <arm_math.h> #include <arm_math.h>
#include "common.h"
#define EFFECT_NONE 0 #define EFFECT_NONE 0
#define EFFECT_CHORUS 1 #define EFFECT_CHORUS 1
@ -19,7 +18,10 @@ public:
bool getBypass(); bool getBypass();
virtual unsigned getId(); virtual unsigned getId();
//virtual void setParameter(unsigned param, unsigned value);
//virtual void getParameter(unsigned param);
void process(const float32_t* inblockL, float32_t* outblockL, uint16_t len);
void process(const float32_t* inblockL, const float32_t* inblockR, float32_t* outblockL, float32_t* outblockR, uint16_t len); void process(const float32_t* inblockL, const float32_t* inblockR, float32_t* outblockL, float32_t* outblockR, uint16_t len);
protected: protected:
bool bypass = false; bool bypass = false;
@ -39,4 +41,4 @@ protected:
virtual void doProcess(const float32_t* inblockL, const float32_t* inblockR, float32_t* outblockL, float32_t* outblockR, uint16_t len); virtual void doProcess(const float32_t* inblockL, const float32_t* inblockR, float32_t* outblockL, float32_t* outblockR, uint16_t len);
}; };
#endif // _EFFECT_H #endif // _EFFECT_BASE_H

@ -1,7 +1,7 @@
#ifndef _EFFECT_CHORUS_H #ifndef _EFFECT_CHORUS_H
#define _EFFECT_CHORUS_H #define _EFFECT_CHORUS_H
#include "effect.h" #include "effect_base.h"
#include "ykchorus/ChorusEngine.h" #include "ykchorus/ChorusEngine.h"
class AudioEffectChorus : public AudioEffect class AudioEffectChorus : public AudioEffect

@ -1,7 +1,7 @@
#ifndef _EFFECT_DELAY_H #ifndef _EFFECT_DELAY_H
#define _EFFECT_DELAY_H #define _EFFECT_DELAY_H
#include "effect.h" #include "effect_base.h"
class AudioEffectDelay : public AudioEffect class AudioEffectDelay : public AudioEffect
{ {

@ -0,0 +1,8 @@
#ifndef _EFFECTS_H
#define _EFFECTS_H
#include "effect_base.h"
#include "effect_chorus.h"
#include "effect_delay.h"
#endif // _EFFECTS_H

@ -91,6 +91,7 @@ CMiniDexed::CMiniDexed (CConfig *pConfig, CInterruptSystem *pInterrupt,
m_nAftertouchRange[i]=99; m_nAftertouchRange[i]=99;
m_nAftertouchTarget[i]=0; m_nAftertouchTarget[i]=0;
m_InsertFXSpinLock[i] = new CSpinLock();
m_InsertFX[i] = new AudioEffectNone(pConfig->GetSampleRate ()); m_InsertFX[i] = new AudioEffectNone(pConfig->GetSampleRate ());
m_nReverbSend[i] = 0; m_nReverbSend[i] = 0;
m_uchOPMask[i] = 0b111111; // All operators on m_uchOPMask[i] = 0b111111; // All operators on
@ -404,9 +405,10 @@ void CMiniDexed::Run (unsigned nCore)
for (unsigned i = 0; i < CConfig::TGsCore23; i++, nTG++) for (unsigned i = 0; i < CConfig::TGsCore23; i++, nTG++)
{ {
assert (m_pTG[nTG]); assert (m_pTG[nTG]);
float32_t Dummy[m_nFramesToProcess];
m_pTG[nTG]->getSamples (m_OutputLevel[nTG],m_nFramesToProcess); m_pTG[nTG]->getSamples (m_OutputLevel[nTG],m_nFramesToProcess);
m_InsertFX[nTG]->process(m_OutputLevel[nTG], Dummy, m_OutputLevel[nTG], Dummy, m_nFramesToProcess); m_InsertFXSpinLock[i]->Acquire();
m_InsertFX[nTG]->process(m_OutputLevel[nTG], m_OutputLevel[nTG], m_nFramesToProcess);
m_InsertFXSpinLock[i]->Release();
} }
} }
} }
@ -593,6 +595,8 @@ void CMiniDexed::setInsertFXType (unsigned nType, unsigned nTG)
assert (nTG < CConfig::ToneGenerators); assert (nTG < CConfig::ToneGenerators);
m_InsertFXSpinLock[nTG]->Acquire();
delete m_InsertFX[nTG]; delete m_InsertFX[nTG];
switch (nType) switch (nType)
@ -609,6 +613,8 @@ void CMiniDexed::setInsertFXType (unsigned nType, unsigned nTG)
break; break;
} }
m_InsertFXSpinLock[nTG]->Release();
m_UI.ParameterChanged (); m_UI.ParameterChanged ();
} }
@ -1103,9 +1109,10 @@ void CMiniDexed::ProcessSound (void)
} }
float32_t SampleBuffer[nFrames]; float32_t SampleBuffer[nFrames];
float32_t Dummy[nFrames];
m_pTG[0]->getSamples (SampleBuffer, nFrames); m_pTG[0]->getSamples (SampleBuffer, nFrames);
m_InsertFX[0]->process(SampleBuffer, Dummy, SampleBuffer, Dummy, nFrames); m_InsertFXSpinLock[0]->Acquire();
m_InsertFX[0]->process(SampleBuffer, SampleBuffer, nFrames);
m_InsertFXSpinLock[0]->Release();
// Convert single float array (mono) to int16 array // Convert single float array (mono) to int16 array
int16_t tmp_int[nFrames]; int16_t tmp_int[nFrames];
@ -1151,9 +1158,10 @@ void CMiniDexed::ProcessSound (void)
for (unsigned i = 0; i < CConfig::TGsCore1; i++) for (unsigned i = 0; i < CConfig::TGsCore1; i++)
{ {
assert (m_pTG[i]); assert (m_pTG[i]);
float32_t Dummy[nFrames];
m_pTG[i]->getSamples (m_OutputLevel[i], nFrames); m_pTG[i]->getSamples (m_OutputLevel[i], nFrames);
m_InsertFX[i]->process(m_OutputLevel[i], Dummy, m_OutputLevel[i], Dummy, nFrames); m_InsertFXSpinLock[i]->Acquire();
m_InsertFX[i]->process(m_OutputLevel[i], m_OutputLevel[i], nFrames);
m_InsertFXSpinLock[i]->Release();
} }
// wait for cores 2 and 3 to complete their work // wait for cores 2 and 3 to complete their work
@ -1206,7 +1214,7 @@ void CMiniDexed::ProcessSound (void)
m_ReverbSpinLock.Acquire (); m_ReverbSpinLock.Acquire ();
reverb_send_mixer->getMix(ReverbSendBuffer[indexL], ReverbSendBuffer[indexR]); reverb_send_mixer->getMix(ReverbSendBuffer[indexL], ReverbSendBuffer[indexR]);
reverb->doReverb(ReverbSendBuffer[indexL],ReverbSendBuffer[indexR],ReverbBuffer[indexL], ReverbBuffer[indexR],nFrames); reverb->doReverb(ReverbSendBuffer[indexL],ReverbSendBuffer[indexR],ReverbBuffer[indexL], ReverbBuffer[indexR],nFrames);
// scale down and add left reverb buffer by reverb level // scale down and add left reverb buffer by reverb level
@ -1999,13 +2007,16 @@ unsigned CMiniDexed::getChorusIEnable (uint8_t nTG)
void CMiniDexed::setChorusIEnable (uint8_t nTG, unsigned enable) void CMiniDexed::setChorusIEnable (uint8_t nTG, unsigned enable)
{ {
m_InsertFXSpinLock[nTG]->Acquire();
AudioEffect* effect = m_InsertFX[nTG]; AudioEffect* effect = m_InsertFX[nTG];
if (effect->getId() != EFFECT_CHORUS) { if (effect->getId() != EFFECT_CHORUS) {
m_InsertFXSpinLock[nTG]->Release();
return; return;
} }
AudioEffectChorus* chorus = (AudioEffectChorus*) effect; AudioEffectChorus* chorus = (AudioEffectChorus*) effect;
return chorus->setChorusI(enable); chorus->setChorusI(enable);
m_InsertFXSpinLock[nTG]->Release();
} }
unsigned CMiniDexed::getChorusIIEnable (uint8_t nTG) unsigned CMiniDexed::getChorusIIEnable (uint8_t nTG)
@ -2021,13 +2032,16 @@ unsigned CMiniDexed::getChorusIIEnable (uint8_t nTG)
void CMiniDexed::setChorusIIEnable (uint8_t nTG, unsigned enable) void CMiniDexed::setChorusIIEnable (uint8_t nTG, unsigned enable)
{ {
m_InsertFXSpinLock[nTG]->Acquire();
AudioEffect* effect = m_InsertFX[nTG]; AudioEffect* effect = m_InsertFX[nTG];
if (effect->getId() != EFFECT_CHORUS) { if (effect->getId() != EFFECT_CHORUS) {
m_InsertFXSpinLock[nTG]->Release();
return; return;
} }
AudioEffectChorus* chorus = (AudioEffectChorus*) effect; AudioEffectChorus* chorus = (AudioEffectChorus*) effect;
return chorus->setChorusII(enable); chorus->setChorusII(enable);
m_InsertFXSpinLock[nTG]->Release();
} }
unsigned CMiniDexed::getChorusIRate (uint8_t nTG) unsigned CMiniDexed::getChorusIRate (uint8_t nTG)
@ -2043,13 +2057,16 @@ unsigned CMiniDexed::getChorusIRate (uint8_t nTG)
void CMiniDexed::setChorusIRate (uint8_t nTG, unsigned int rate) void CMiniDexed::setChorusIRate (uint8_t nTG, unsigned int rate)
{ {
m_InsertFXSpinLock[nTG]->Acquire();
AudioEffect* effect = m_InsertFX[nTG]; AudioEffect* effect = m_InsertFX[nTG];
if (effect->getId() != EFFECT_CHORUS) { if (effect->getId() != EFFECT_CHORUS) {
m_InsertFXSpinLock[nTG]->Release();
return; return;
} }
AudioEffectChorus* chorus = (AudioEffectChorus*) effect; AudioEffectChorus* chorus = (AudioEffectChorus*) effect;
return chorus->setChorusIRate(rate); chorus->setChorusIRate(rate);
m_InsertFXSpinLock[nTG]->Release();
} }
unsigned CMiniDexed::getChorusIIRate (uint8_t nTG) unsigned CMiniDexed::getChorusIIRate (uint8_t nTG)
@ -2065,11 +2082,14 @@ unsigned CMiniDexed::getChorusIIRate (uint8_t nTG)
void CMiniDexed::setChorusIIRate (uint8_t nTG, unsigned int rate) void CMiniDexed::setChorusIIRate (uint8_t nTG, unsigned int rate)
{ {
m_InsertFXSpinLock[nTG]->Acquire();
AudioEffect* effect = m_InsertFX[nTG]; AudioEffect* effect = m_InsertFX[nTG];
if (effect->getId() != EFFECT_CHORUS) { if (effect->getId() != EFFECT_CHORUS) {
m_InsertFXSpinLock[nTG]->Release();
return; return;
} }
AudioEffectChorus* chorus = (AudioEffectChorus*) effect; AudioEffectChorus* chorus = (AudioEffectChorus*) effect;
return chorus->setChorusIIRate(rate); chorus->setChorusIIRate(rate);
m_InsertFXSpinLock[nTG]->Release();
} }

@ -44,9 +44,7 @@
#include "effect_mixer.hpp" #include "effect_mixer.hpp"
#include "effect_platervbstereo.h" #include "effect_platervbstereo.h"
#include "effect_compressor.h" #include "effect_compressor.h"
#include "effect.h" #include "effects.h"
#include "effect_chorus.h"
#include "effect_delay.h"
class CMiniDexed class CMiniDexed
#ifdef ARM_ALLOW_MULTI_CORE #ifdef ARM_ALLOW_MULTI_CORE
@ -338,6 +336,7 @@ private:
AudioStereoMixer<CConfig::ToneGenerators>* tg_mixer; AudioStereoMixer<CConfig::ToneGenerators>* tg_mixer;
AudioStereoMixer<CConfig::ToneGenerators>* reverb_send_mixer; AudioStereoMixer<CConfig::ToneGenerators>* reverb_send_mixer;
CSpinLock* m_InsertFXSpinLock[CConfig::ToneGenerators];
CSpinLock m_ReverbSpinLock; CSpinLock m_ReverbSpinLock;
bool m_bSavePerformance; bool m_bSavePerformance;

Loading…
Cancel
Save