Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Synth_Dexed
Submodule Synth_Dexed updated from 8c677c to a02b5c
202 changes: 188 additions & 14 deletions src/minidexed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ CMiniDexed::CMiniDexed (CConfig *pConfig, CInterruptSystem *pInterrupt,
m_GetChunkTimer ("GetChunk",
1000000U * pConfig->GetChunkSize ()/2 / pConfig->GetSampleRate ()),
m_bProfileEnabled (m_pConfig->GetProfileEnabled ()),
m_Limiter {pConfig->GetSampleRate(), pConfig->GetSampleRate()},
m_pNet(nullptr),
m_pNetDevice(nullptr),
m_WLAN(nullptr),
Expand Down Expand Up @@ -116,6 +117,13 @@ CMiniDexed::CMiniDexed (CConfig *pConfig, CInterruptSystem *pInterrupt,

m_nReverbSend[i] = 0;

m_bCompressorEnable[i] = 1;
m_nCompressorPreGain[i] = 0;
m_nCompressorAttack[i] = 5;
m_nCompressorRelease[i] = 200;
m_nCompressorThresh[i] = -20;
m_nCompressorRatio[i] = 5;

// Active the required number of active TGs
if (i<m_nToneGenerators)
{
Expand Down Expand Up @@ -254,7 +262,13 @@ CMiniDexed::CMiniDexed (CConfig *pConfig, CInterruptSystem *pInterrupt,
SetParameter (ParameterReverbLevel, 99);
// END setup reverb

SetParameter (ParameterCompressorEnable, 1);
SetParameter (ParameterLimiterEnable, 1);
SetParameter (ParameterLimiterPreGain, 0);
SetParameter (ParameterLimiterAttack, 5);
SetParameter (ParameterLimiterRelease, 5);
SetParameter (ParameterLimiterThresh, -3);
SetParameter (ParameterLimiterRatio, 20);
SetParameter (ParameterLimiterHPFilterEnable, 0);

SetPerformanceSelectChannel(m_pConfig->GetPerformanceSelectChannel());

Expand Down Expand Up @@ -1004,14 +1018,6 @@ void CMiniDexed::SetParameter (TParameter Parameter, int nValue)

switch (Parameter)
{
case ParameterCompressorEnable:
for (unsigned nTG = 0; nTG < m_nToneGenerators; nTG++)
{
assert (m_pTG[nTG]);
m_pTG[nTG]->setCompressor (!!nValue);
}
break;

case ParameterReverbEnable:
nValue=constrain((int)nValue,0,1);
m_ReverbSpinLock.Acquire ();
Expand Down Expand Up @@ -1069,6 +1075,56 @@ void CMiniDexed::SetParameter (TParameter Parameter, int nValue)
BankSelectPerformance(nValue);
break;

case ParameterLimiterEnable:
break;

case ParameterLimiterPreGain:
nValue=constrain(nValue,-20,20);
m_LimiterSpinLock.Acquire ();
for (int i=0; i<2; ++i)
m_Limiter[i].setPreGain_dB(nValue);
m_LimiterSpinLock.Release ();
break;

case ParameterLimiterAttack:
nValue=constrain(nValue,0,1000);
m_LimiterSpinLock.Acquire ();
for (int i=0; i<2; ++i)
m_Limiter[i].setAttack_sec(nValue / 1000.0f, m_pConfig->GetSampleRate());
m_LimiterSpinLock.Release ();
break;

case ParameterLimiterRelease:
nValue=constrain(nValue,0,1000);
m_LimiterSpinLock.Acquire ();
for (int i=0; i<2; ++i)
m_Limiter[i].setRelease_sec(nValue / 1000.0f, m_pConfig->GetSampleRate());
m_LimiterSpinLock.Release ();
break;

case ParameterLimiterThresh:
nValue=constrain(nValue,-60,0);
m_LimiterSpinLock.Acquire ();
for (int i=0; i<2; ++i)
m_Limiter[i].setThresh_dBFS(nValue);
m_LimiterSpinLock.Release ();
break;

case ParameterLimiterRatio:
nValue=constrain(nValue,1,20);
m_LimiterSpinLock.Acquire ();
for (int i=0; i<2; ++i)
m_Limiter[i].setCompressionRatio(nValue);
m_LimiterSpinLock.Release ();
break;

case ParameterLimiterHPFilterEnable:
m_LimiterSpinLock.Acquire ();
for (int i=0; i<2; ++i)
m_Limiter[i].enableHPFilter(nValue);
m_LimiterSpinLock.Release ();
break;

default:
assert (0);
break;
Expand Down Expand Up @@ -1132,6 +1188,13 @@ void CMiniDexed::SetTGParameter (TTGParameter Parameter, int nValue, unsigned nT

case TGParameterReverbSend: SetReverbSend (nValue, nTG); break;

case TGParameterCompressorEnable: SetCompressorEnable (nValue, nTG); break;
case TGParameterCompressorPreGain: SetCompressorPreGain (nValue, nTG); break;
case TGParameterCompressorAttack: SetCompressorAttack (nValue, nTG); break;
case TGParameterCompressorRelease: SetCompressorRelease (nValue, nTG); break;
case TGParameterCompressorThresh: SetCompressorThresh (nValue, nTG); break;
case TGParameterCompressorRatio: SetCompressorRatio (nValue, nTG); break;

default:
assert (0);
break;
Expand Down Expand Up @@ -1182,7 +1245,13 @@ int CMiniDexed::GetTGParameter (TTGParameter Parameter, unsigned nTG)
case TGParameterATAmplitude: return getModController(3, 2, nTG);
case TGParameterATEGBias: return getModController(3, 3, nTG);


case TGParameterCompressorEnable: return m_bCompressorEnable[nTG];
case TGParameterCompressorPreGain: return m_nCompressorPreGain[nTG];
case TGParameterCompressorAttack: return m_nCompressorAttack[nTG];
case TGParameterCompressorRelease: return m_nCompressorRelease[nTG];
case TGParameterCompressorThresh: return m_nCompressorThresh[nTG];
case TGParameterCompressorRatio: return m_nCompressorRatio[nTG];

default:
assert (0);
return 0;
Expand Down Expand Up @@ -1434,6 +1503,14 @@ void CMiniDexed::ProcessSound (void)
}
// END adding reverb

if (m_nParameter[ParameterLimiterEnable])
{
m_LimiterSpinLock.Acquire ();
m_Limiter[0].doCompression (SampleBuffer[0], nFrames);
m_Limiter[1].doCompression (SampleBuffer[1], nFrames);
m_LimiterSpinLock.Release ();
}

// swap stereo channels if needed prior to writing back out
if (m_bChannelsSwapped)
{
Expand Down Expand Up @@ -1547,9 +1624,15 @@ bool CMiniDexed::DoSavePerformance (void)
m_PerformanceConfig.SetAftertouchTarget (m_nAftertouchTarget[nTG], nTG);

m_PerformanceConfig.SetReverbSend (m_nReverbSend[nTG], nTG);

m_PerformanceConfig.SetCompressorEnable (m_bCompressorEnable[nTG], nTG);
m_PerformanceConfig.SetCompressorPreGain (m_nCompressorPreGain[nTG], nTG);
m_PerformanceConfig.SetCompressorAttack (m_nCompressorAttack[nTG], nTG);
m_PerformanceConfig.SetCompressorRelease (m_nCompressorRelease[nTG], nTG);
m_PerformanceConfig.SetCompressorThresh (m_nCompressorThresh[nTG], nTG);
m_PerformanceConfig.SetCompressorRatio (m_nCompressorRatio[nTG], nTG);
}

m_PerformanceConfig.SetCompressorEnable (!!m_nParameter[ParameterCompressorEnable]);
m_PerformanceConfig.SetReverbEnable (!!m_nParameter[ParameterReverbEnable]);
m_PerformanceConfig.SetReverbSize (m_nParameter[ParameterReverbSize]);
m_PerformanceConfig.SetReverbHighDamp (m_nParameter[ParameterReverbHighDamp]);
Expand All @@ -1558,6 +1641,14 @@ bool CMiniDexed::DoSavePerformance (void)
m_PerformanceConfig.SetReverbDiffusion (m_nParameter[ParameterReverbDiffusion]);
m_PerformanceConfig.SetReverbLevel (m_nParameter[ParameterReverbLevel]);

m_PerformanceConfig.SetLimiterEnable (m_nParameter[ParameterLimiterEnable]);
m_PerformanceConfig.SetLimiterPreGain (m_nParameter[ParameterLimiterPreGain]);
m_PerformanceConfig.SetLimiterAttack (m_nParameter[ParameterLimiterAttack]);
m_PerformanceConfig.SetLimiterRelease (m_nParameter[ParameterLimiterRelease]);
m_PerformanceConfig.SetLimiterThresh (m_nParameter[ParameterLimiterThresh]);
m_PerformanceConfig.SetLimiterRatio (m_nParameter[ParameterLimiterRatio]);
m_PerformanceConfig.SetLimiterHPFilterEnable (m_nParameter[ParameterLimiterHPFilterEnable]);

if(m_bSaveAsDeault)
{
m_PerformanceConfig.SetNewPerformanceBank(0);
Expand All @@ -1567,6 +1658,77 @@ bool CMiniDexed::DoSavePerformance (void)
return m_PerformanceConfig.Save ();
}

void CMiniDexed::SetCompressorEnable(bool compressor, unsigned nTG)
{
assert (nTG < CConfig::AllToneGenerators);
if (nTG >= m_nToneGenerators) return; // Not an active TG

assert (m_pTG[nTG]);
m_bCompressorEnable[nTG] = compressor;
m_pTG[nTG]->setCompressor (compressor);
m_UI.ParameterChanged ();
}

void CMiniDexed::SetCompressorPreGain (int preGain, unsigned nTG)
{
preGain = constrain (preGain, -20, 20);
assert (nTG < CConfig::AllToneGenerators);
if (nTG >= m_nToneGenerators) return; // Not an active TG

assert (m_pTG[nTG]);
m_nCompressorPreGain[nTG] = preGain;
m_pTG[nTG]->setCompressorPreGain_dB (preGain);
m_UI.ParameterChanged ();
}

void CMiniDexed::SetCompressorAttack (unsigned attack, unsigned nTG)
{
attack = constrain (attack, 0u, 1000u);
assert (nTG < CConfig::AllToneGenerators);
if (nTG >= m_nToneGenerators) return; // Not an active TG

assert (m_pTG[nTG]);
m_nCompressorAttack[nTG] = attack;
m_pTG[nTG]->setCompressorAttack_sec (attack / 1000.0);
m_UI.ParameterChanged ();
}

void CMiniDexed::SetCompressorRelease (unsigned release, unsigned nTG)
{
release = constrain (release, 0u, 1000u);
assert (nTG < CConfig::AllToneGenerators);
if (nTG >= m_nToneGenerators) return; // Not an active TG

assert (m_pTG[nTG]);
m_nCompressorRelease[nTG] = release;
m_pTG[nTG]->setCompressorRelease_sec (release / 1000.0);
m_UI.ParameterChanged ();
}

void CMiniDexed::SetCompressorThresh (int thresh, unsigned nTG)
{
thresh = constrain (thresh, -60, 0);
assert (nTG < CConfig::AllToneGenerators);
if (nTG >= m_nToneGenerators) return; // Not an active TG

assert (m_pTG[nTG]);
m_nCompressorThresh[nTG] = thresh;
m_pTG[nTG]->setCompressorThresh_dBFS (thresh);
m_UI.ParameterChanged ();
}

void CMiniDexed::SetCompressorRatio (unsigned ratio, unsigned nTG)
{
ratio = constrain (ratio, 1u, 20u);
assert (nTG < CConfig::AllToneGenerators);
if (nTG >= m_nToneGenerators) return; // Not an active TG

assert (m_pTG[nTG]);
m_nCompressorRatio[nTG] = ratio;
m_pTG[nTG]->setCompressionRatio (ratio);
m_UI.ParameterChanged ();
}

void CMiniDexed::setMonoMode(uint8_t mono, uint8_t nTG)
{
assert (nTG < CConfig::AllToneGenerators);
Expand Down Expand Up @@ -2037,12 +2199,16 @@ void CMiniDexed::LoadPerformanceParameters(void)
setBreathControllerTarget (m_PerformanceConfig.GetBreathControlTarget (nTG), nTG);
setAftertouchRange (m_PerformanceConfig.GetAftertouchRange (nTG), nTG);
setAftertouchTarget (m_PerformanceConfig.GetAftertouchTarget (nTG), nTG);



SetCompressorEnable (m_PerformanceConfig.GetCompressorEnable (nTG), nTG);
SetCompressorPreGain (m_PerformanceConfig.GetCompressorPreGain (nTG), nTG);
SetCompressorAttack (m_PerformanceConfig.GetCompressorAttack (nTG), nTG);;
SetCompressorRelease (m_PerformanceConfig.GetCompressorRelease (nTG), nTG);
SetCompressorThresh (m_PerformanceConfig.GetCompressorThresh (nTG), nTG);
SetCompressorRatio (m_PerformanceConfig.GetCompressorRatio (nTG), nTG);
}

// Effects
SetParameter (ParameterCompressorEnable, m_PerformanceConfig.GetCompressorEnable () ? 1 : 0);
SetParameter (ParameterReverbEnable, m_PerformanceConfig.GetReverbEnable () ? 1 : 0);
SetParameter (ParameterReverbSize, m_PerformanceConfig.GetReverbSize ());
SetParameter (ParameterReverbHighDamp, m_PerformanceConfig.GetReverbHighDamp ());
Expand All @@ -2051,6 +2217,14 @@ void CMiniDexed::LoadPerformanceParameters(void)
SetParameter (ParameterReverbDiffusion, m_PerformanceConfig.GetReverbDiffusion ());
SetParameter (ParameterReverbLevel, m_PerformanceConfig.GetReverbLevel ());

SetParameter (ParameterLimiterEnable, m_PerformanceConfig.GetLimiterEnable ());
SetParameter (ParameterLimiterPreGain, m_PerformanceConfig.GetLimiterPreGain ());
SetParameter (ParameterLimiterAttack, m_PerformanceConfig.GetLimiterAttack ());
SetParameter (ParameterLimiterRelease, m_PerformanceConfig.GetLimiterRelease ());
SetParameter (ParameterLimiterThresh, m_PerformanceConfig.GetLimiterThresh ());
SetParameter (ParameterLimiterRatio, m_PerformanceConfig.GetLimiterRatio ());
SetParameter (ParameterLimiterHPFilterEnable, m_PerformanceConfig.GetLimiterHPFilterEnable ());

m_UI.DisplayChanged ();
}

Expand Down
33 changes: 32 additions & 1 deletion src/minidexed.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "effect_platervbstereo.h"
#include "udpmididevice.h"
#include "net/ftpdaemon.h"
#include "../Synth_Dexed/src/compressor.h"

class CMiniDexed
#ifdef ARM_ALLOW_MULTI_CORE
Expand Down Expand Up @@ -106,6 +107,13 @@ class CMiniDexed

void SetReverbSend (unsigned nReverbSend, unsigned nTG); // 0 .. 127

void SetCompressorEnable (bool compressor, unsigned nTG); // 0 .. 1 (default 1)
void SetCompressorPreGain (int preGain, unsigned nTG); // -20 .. 20 dB (default 0)
void SetCompressorAttack (unsigned attack, unsigned nTG); // 0 .. 1000 ms (default 5)
void SetCompressorRelease (unsigned release, unsigned nTG); // 0 .. 1000 ms (default 200)
void SetCompressorThresh (int thresh, unsigned nTG); // -60 .. 0 dBFS (default -20)
void SetCompressorRatio (unsigned ratio, unsigned nTG); // 1 .. 20 (default 5)

void setMonoMode(uint8_t mono, uint8_t nTG);
void setPitchbendRange(uint8_t range, uint8_t nTG);
void setPitchbendStep(uint8_t step, uint8_t nTG);
Expand Down Expand Up @@ -158,7 +166,6 @@ class CMiniDexed
// Must match the order in CUIMenu::TParameter
enum TParameter
{
ParameterCompressorEnable,
ParameterReverbEnable,
ParameterReverbSize,
ParameterReverbHighDamp,
Expand All @@ -168,6 +175,13 @@ class CMiniDexed
ParameterReverbLevel,
ParameterPerformanceSelectChannel,
ParameterPerformanceBank,
ParameterLimiterEnable,
ParameterLimiterPreGain,
ParameterLimiterAttack,
ParameterLimiterRelease,
ParameterLimiterThresh,
ParameterLimiterRatio,
ParameterLimiterHPFilterEnable,
ParameterUnknown
};

Expand Down Expand Up @@ -220,6 +234,13 @@ class CMiniDexed
TGParameterATPitch,
TGParameterATAmplitude,
TGParameterATEGBias,

TGParameterCompressorEnable,
TGParameterCompressorPreGain,
TGParameterCompressorAttack,
TGParameterCompressorRelease,
TGParameterCompressorThresh,
TGParameterCompressorRatio,

TGParameterUnknown
};
Expand Down Expand Up @@ -304,6 +325,13 @@ class CMiniDexed
int m_nNoteShift[CConfig::AllToneGenerators];

unsigned m_nReverbSend[CConfig::AllToneGenerators];

bool m_bCompressorEnable[CConfig::AllToneGenerators];
int m_nCompressorPreGain[CConfig::AllToneGenerators];
unsigned m_nCompressorAttack[CConfig::AllToneGenerators];
unsigned m_nCompressorRelease[CConfig::AllToneGenerators];
int m_nCompressorThresh[CConfig::AllToneGenerators];
unsigned m_nCompressorRatio[CConfig::AllToneGenerators];

uint8_t m_nRawVoiceData[156];

Expand Down Expand Up @@ -340,6 +368,9 @@ class CMiniDexed

CSpinLock m_ReverbSpinLock;

Compressor m_Limiter[2];
CSpinLock m_LimiterSpinLock;

// Network
CNetSubSystem* m_pNet;
CNetDevice* m_pNetDevice;
Expand Down
Loading
Loading