Added LED gate pin

pull/1/head
Steve Lascos 7 years ago
parent 03b38585bb
commit dc63f9871e
  1. 4
      src/AudioEffectSOS.h
  2. 4
      src/common/AudioDelay.cpp
  3. 31
      src/common/ParameterAutomation.cpp
  4. 17
      src/effects/AudioEffectSOS.cpp

@ -38,6 +38,7 @@ public:
BYPASS = 0, ///< controls effect bypass
GATE_TRIGGER, ///< begins the gate sequence
GATE_OPEN_TIME, ///< controls how long it takes to open the gate
//GATE_HOLD_TIME, ///< controls how long the gate stays open at unity
GATE_CLOSE_TIME, ///< controls how long it takes to close the gate (release)
FEEDBACK, ///< controls the amount of feedback, more gives longer SOS sustain
VOLUME, ///< controls the output volume level
@ -56,6 +57,8 @@ public:
virtual ~AudioEffectSOS(); ///< Destructor
void setGateLedGpio(int pinId);
// *** PARAMETERS ***
void gateOpenTime(float milliseconds);
@ -118,6 +121,7 @@ private:
audio_block_t *m_previousBlock = nullptr;
audio_block_t *m_blockToRelease = nullptr;
size_t m_maxDelaySamples = 0;
int m_gateLedPinId = -1;
// Controls
int m_midiConfig[NUM_CONTROLS][2]; // stores the midi parameter mapping

@ -97,6 +97,10 @@ audio_block_t* AudioDelay::getBlock(size_t index)
size_t AudioDelay::getMaxDelaySamples()
{
if (m_type == MemType::MEM_EXTERNAL) {
// update the max delay sample size
m_maxDelaySamples = (m_slot->size() / sizeof(int16_t)) - AUDIO_BLOCK_SAMPLES;
}
return m_maxDelaySamples;
}

@ -29,6 +29,7 @@ namespace BALibrary {
///////////////////////////////////////////////////////////////////////////////
constexpr int LINEAR_SLOPE = 0;
constexpr float EXPONENTIAL_K = 5.0f;
constexpr float EXP_EXPONENTIAL_K = expf(EXPONENTIAL_K);
template <class T>
ParameterAutomation<T>::ParameterAutomation()
@ -99,11 +100,18 @@ T ParameterAutomation<T>::getNextValue()
m_currentValueX += m_slopeX;
float value;
float returnValue;
switch(m_function) {
case Function::EXPONENTIAL :
// f(x) = exp(-k*x)
if (m_positiveSlope) {
// Growth: f(x) = exp(k*x) / exp(k)
value = expf(EXPONENTIAL_K*m_currentValueX) / EXP_EXPONENTIAL_K;
} else {
// Decay: f(x) = 1 - exp(-k*x)
value = 1.0f - expf(-EXPONENTIAL_K*m_currentValueX);
}
break;
case Function::PARABOLIC :
value = m_currentValueX*m_currentValueX;
@ -122,15 +130,15 @@ T ParameterAutomation<T>::getNextValue()
return m_endValue;
}
float returnValue;
if (m_positiveSlope) {
returnValue = m_startValue + (m_scaleY*value);
} else {
returnValue = m_startValue - (m_scaleY*value);
}
// Serial.println(String("Start/End values: ") + m_startValue + String(":") + m_endValue);
// Serial.print("Parameter m_currentValueX is "); Serial.println(m_currentValueX, 6);
// Serial.print("Parameter returnValue is "); Serial.println(returnValue, 6);
//Serial.print("Parameter m_currentValueX is "); Serial.println(m_currentValueX, 6);
//Serial.print("Parameter returnValue is "); Serial.println(returnValue, 6);
return returnValue;
}
@ -169,7 +177,7 @@ ParameterAutomationSequence<T>::~ParameterAutomationSequence()
template <class T>
void ParameterAutomationSequence<T>::setupParameter(int index, T startValue, T endValue, size_t durationSamples, typename ParameterAutomation<T>::Function function)
{
Serial.println("setupParameter() called");
Serial.println(String("setupParameter() called with samples: ") + durationSamples);
m_paramArray[index]->reconfigure(startValue, endValue, durationSamples, function);
m_currentIndex = 0;
}
@ -177,7 +185,7 @@ void ParameterAutomationSequence<T>::setupParameter(int index, T startValue, T e
template <class T>
void ParameterAutomationSequence<T>::setupParameter(int index, T startValue, T endValue, float durationMilliseconds, typename ParameterAutomation<T>::Function function)
{
Serial.println("setupParameter() called");
Serial.print(String("setupParameter() called with time: ")); Serial.println(durationMilliseconds, 6);
m_paramArray[index]->reconfigure(startValue, endValue, durationMilliseconds, function);
m_currentIndex = 0;
}
@ -208,6 +216,7 @@ T ParameterAutomationSequence<T>::getNextValue()
if (m_currentIndex >= m_numStages) {
// Last stage already finished
Serial.println("Last stage finished");
m_running = false;
m_currentIndex = 0;
} else {
@ -223,15 +232,7 @@ T ParameterAutomationSequence<T>::getNextValue()
template <class T>
bool ParameterAutomationSequence<T>::isFinished()
{
bool finished = true;
for (int i=0; i<m_numStages; i++) {
if (!m_paramArray[i]->isFinished()) {
finished = false;
break;
}
}
m_running = !finished;
return finished;
return !m_running;
}
// Template instantiation

@ -51,6 +51,12 @@ AudioEffectSOS::~AudioEffectSOS()
if (m_memory) delete m_memory;
}
void AudioEffectSOS::setGateLedGpio(int pinId)
{
m_gateLedPinId = pinId;
pinMode(static_cast<uint8_t>(m_gateLedPinId), OUTPUT);
}
void AudioEffectSOS::enable(void)
{
m_enable = true;
@ -62,7 +68,7 @@ void AudioEffectSOS::enable(void)
}
m_delaySamples = m_maxDelaySamples;
m_inputGateAuto.setupParameter(GATE_OPEN_STAGE, 0.0f, 1.0f, 1000.0f, ParameterAutomation<float>::Function::EXPONENTIAL);
m_inputGateAuto.setupParameter(GATE_HOLD_STAGE, 1.0f, 1.0f, 1000.0f, ParameterAutomation<float>::Function::HOLD);
m_inputGateAuto.setupParameter(GATE_HOLD_STAGE, 1.0f, 1.0f, m_maxDelaySamples, ParameterAutomation<float>::Function::HOLD);
m_inputGateAuto.setupParameter(GATE_CLOSE_STAGE, 1.0f, 0.0f, 1000.0f, ParameterAutomation<float>::Function::EXPONENTIAL);
}
@ -261,6 +267,15 @@ void AudioEffectSOS::m_preProcessing (audio_block_t *out, audio_block_t *input,
} else if (input) {
memcpy(out->data, input->data, sizeof(int16_t) * AUDIO_BLOCK_SAMPLES);
}
// Update the gate LED
if (m_gateLedPinId >= 0) {
if (m_inputGateAuto.isFinished()) {
digitalWriteFast(m_gateLedPinId, 0x0);
} else {
digitalWriteFast(m_gateLedPinId, 0x1);
}
}
}
void AudioEffectSOS::m_postProcessing(audio_block_t *out, audio_block_t *in)

Loading…
Cancel
Save