diff --git a/src/Makefile b/src/Makefile index ce9a545..91ba0aa 100644 --- a/src/Makefile +++ b/src/Makefile @@ -9,7 +9,7 @@ CMSIS_DIR = ../CMSIS_5/CMSIS OBJS = main.o kernel.o minidexed.o config.o userinterface.o uimenu.o \ mididevice.o midikeyboard.o serialmididevice.o pckeyboard.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 OPTIMIZE = -O3 diff --git a/src/effect.cpp b/src/effect_base.cpp similarity index 82% rename from src/effect.cpp rename to src/effect_base.cpp index 30ace8a..22bca6f 100644 --- a/src/effect.cpp +++ b/src/effect_base.cpp @@ -1,4 +1,4 @@ -#include "effect.h" +#include "effect_base.h" AudioEffect::AudioEffect(float32_t samplerate) { @@ -24,6 +24,15 @@ unsigned AudioEffect::getId() 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) { if (bypass) { diff --git a/src/effect.h b/src/effect_base.h similarity index 76% rename from src/effect.h rename to src/effect_base.h index 1bfd675..ba44d7f 100644 --- a/src/effect.h +++ b/src/effect_base.h @@ -1,9 +1,8 @@ -#ifndef _EFFECT_H -#define _EFFECT_H +#ifndef _EFFECT_BASE_H +#define _EFFECT_BASE_H -#include +//#include #include -#include "common.h" #define EFFECT_NONE 0 #define EFFECT_CHORUS 1 @@ -19,7 +18,10 @@ public: bool getBypass(); 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); protected: 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); }; -#endif // _EFFECT_H \ No newline at end of file +#endif // _EFFECT_BASE_H \ No newline at end of file diff --git a/src/effect_chorus.h b/src/effect_chorus.h index aaae398..d3ffb61 100644 --- a/src/effect_chorus.h +++ b/src/effect_chorus.h @@ -1,7 +1,7 @@ #ifndef _EFFECT_CHORUS_H #define _EFFECT_CHORUS_H -#include "effect.h" +#include "effect_base.h" #include "ykchorus/ChorusEngine.h" class AudioEffectChorus : public AudioEffect diff --git a/src/effect_delay.h b/src/effect_delay.h index c131c74..8d58aac 100644 --- a/src/effect_delay.h +++ b/src/effect_delay.h @@ -1,7 +1,7 @@ #ifndef _EFFECT_DELAY_H #define _EFFECT_DELAY_H -#include "effect.h" +#include "effect_base.h" class AudioEffectDelay : public AudioEffect { diff --git a/src/effects.h b/src/effects.h new file mode 100644 index 0000000..614a60c --- /dev/null +++ b/src/effects.h @@ -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 \ No newline at end of file diff --git a/src/minidexed.cpp b/src/minidexed.cpp index 8f077d7..0650ff1 100644 --- a/src/minidexed.cpp +++ b/src/minidexed.cpp @@ -91,6 +91,7 @@ CMiniDexed::CMiniDexed (CConfig *pConfig, CInterruptSystem *pInterrupt, m_nAftertouchRange[i]=99; m_nAftertouchTarget[i]=0; + m_InsertFXSpinLock[i] = new CSpinLock(); m_InsertFX[i] = new AudioEffectNone(pConfig->GetSampleRate ()); m_nReverbSend[i] = 0; 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++) { assert (m_pTG[nTG]); - float32_t Dummy[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); + m_InsertFXSpinLock[nTG]->Acquire(); + delete m_InsertFX[nTG]; switch (nType) @@ -609,6 +613,8 @@ void CMiniDexed::setInsertFXType (unsigned nType, unsigned nTG) break; } + m_InsertFXSpinLock[nTG]->Release(); + m_UI.ParameterChanged (); } @@ -1103,9 +1109,10 @@ void CMiniDexed::ProcessSound (void) } float32_t SampleBuffer[nFrames]; - float32_t Dummy[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 int16_t tmp_int[nFrames]; @@ -1151,9 +1158,10 @@ void CMiniDexed::ProcessSound (void) for (unsigned i = 0; i < CConfig::TGsCore1; i++) { assert (m_pTG[i]); - float32_t Dummy[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 @@ -1206,7 +1214,7 @@ void CMiniDexed::ProcessSound (void) 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); // 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) { + m_InsertFXSpinLock[nTG]->Acquire(); AudioEffect* effect = m_InsertFX[nTG]; if (effect->getId() != EFFECT_CHORUS) { + m_InsertFXSpinLock[nTG]->Release(); return; } AudioEffectChorus* chorus = (AudioEffectChorus*) effect; - return chorus->setChorusI(enable); + chorus->setChorusI(enable); + m_InsertFXSpinLock[nTG]->Release(); } unsigned CMiniDexed::getChorusIIEnable (uint8_t nTG) @@ -2021,13 +2032,16 @@ unsigned CMiniDexed::getChorusIIEnable (uint8_t nTG) void CMiniDexed::setChorusIIEnable (uint8_t nTG, unsigned enable) { + m_InsertFXSpinLock[nTG]->Acquire(); AudioEffect* effect = m_InsertFX[nTG]; if (effect->getId() != EFFECT_CHORUS) { + m_InsertFXSpinLock[nTG]->Release(); return; } AudioEffectChorus* chorus = (AudioEffectChorus*) effect; - return chorus->setChorusII(enable); + chorus->setChorusII(enable); + m_InsertFXSpinLock[nTG]->Release(); } 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) { + m_InsertFXSpinLock[nTG]->Acquire(); AudioEffect* effect = m_InsertFX[nTG]; if (effect->getId() != EFFECT_CHORUS) { + m_InsertFXSpinLock[nTG]->Release(); return; } AudioEffectChorus* chorus = (AudioEffectChorus*) effect; - return chorus->setChorusIRate(rate); + chorus->setChorusIRate(rate); + m_InsertFXSpinLock[nTG]->Release(); } 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) { + m_InsertFXSpinLock[nTG]->Acquire(); AudioEffect* effect = m_InsertFX[nTG]; if (effect->getId() != EFFECT_CHORUS) { + m_InsertFXSpinLock[nTG]->Release(); return; } AudioEffectChorus* chorus = (AudioEffectChorus*) effect; - return chorus->setChorusIIRate(rate); + chorus->setChorusIIRate(rate); + m_InsertFXSpinLock[nTG]->Release(); } diff --git a/src/minidexed.h b/src/minidexed.h index 3ae6316..e23aa07 100644 --- a/src/minidexed.h +++ b/src/minidexed.h @@ -44,9 +44,7 @@ #include "effect_mixer.hpp" #include "effect_platervbstereo.h" #include "effect_compressor.h" -#include "effect.h" -#include "effect_chorus.h" -#include "effect_delay.h" +#include "effects.h" class CMiniDexed #ifdef ARM_ALLOW_MULTI_CORE @@ -338,6 +336,7 @@ private: AudioStereoMixer* tg_mixer; AudioStereoMixer* reverb_send_mixer; + CSpinLock* m_InsertFXSpinLock[CConfig::ToneGenerators]; CSpinLock m_ReverbSpinLock; bool m_bSavePerformance;