added some midi controls

pull/1/head
Steve Lascos 7 years ago
parent 6b59f022b3
commit 61d45bff5f
  1. 77
      src/AudioEffectAnalogDelay.cpp
  2. 17
      src/AudioEffectAnalogDelay.h
  3. 2
      src/LibBasicFunctions.cpp

@ -9,16 +9,28 @@
namespace BAGuitar { namespace BAGuitar {
constexpr int MIDI_NUM_PARAMS = 4;
constexpr int MIDI_CHANNEL = 0;
constexpr int MIDI_CONTROL = 1;
constexpr int MIDI_ENABLE = 0;
constexpr int MIDI_DELAY = 1;
constexpr int MIDI_FEEDBACK = 2;
constexpr int MIDI_MIX = 3;
AudioEffectAnalogDelay::AudioEffectAnalogDelay(float maxDelay) AudioEffectAnalogDelay::AudioEffectAnalogDelay(float maxDelay)
: AudioStream(1, m_inputQueueArray) : AudioStream(1, m_inputQueueArray)
{ {
m_memory = new AudioDelay(maxDelay); m_memory = new AudioDelay(maxDelay);
m_maxDelaySamples = calcAudioSamples(maxDelay);
} }
AudioEffectAnalogDelay::AudioEffectAnalogDelay(size_t numSamples) AudioEffectAnalogDelay::AudioEffectAnalogDelay(size_t numSamples)
: AudioStream(1, m_inputQueueArray) : AudioStream(1, m_inputQueueArray)
{ {
m_memory = new AudioDelay(numSamples); m_memory = new AudioDelay(numSamples);
m_maxDelaySamples = numSamples;
} }
// requires preallocated memory large enough // requires preallocated memory large enough
@ -26,6 +38,7 @@ AudioEffectAnalogDelay::AudioEffectAnalogDelay(ExtMemSlot *slot)
: AudioStream(1, m_inputQueueArray) : AudioStream(1, m_inputQueueArray)
{ {
m_memory = new AudioDelay(slot); m_memory = new AudioDelay(slot);
m_maxDelaySamples = slot->size();
m_externalMemory = true; m_externalMemory = true;
} }
@ -74,7 +87,7 @@ void AudioEffectAnalogDelay::update(void)
m_callCount++; m_callCount++;
Serial.println(String("AudioEffectAnalgDelay::update: ") + m_callCount); //Serial.println(String("AudioEffectAnalgDelay::update: ") + m_callCount);
// Preprocessing // Preprocessing
audio_block_t *preProcessed = allocate(); audio_block_t *preProcessed = allocate();
@ -151,6 +164,68 @@ void AudioEffectAnalogDelay::delay(size_t delaySamples)
} }
void AudioEffectAnalogDelay::processMidi(int channel, int control, int value)
{
float val = (float)value / 127.0f;
if ((m_midiConfig[MIDI_DELAY][MIDI_CHANNEL] == channel) &&
(m_midiConfig[MIDI_DELAY][MIDI_CONTROL] == control)) {
// Delay
Serial.println(String("AudioEffectAnalogDelay::delay: ") + val);
delay((size_t)(val * m_maxDelaySamples));
return;
}
if ((m_midiConfig[MIDI_ENABLE][MIDI_CHANNEL] == channel) &&
(m_midiConfig[MIDI_ENABLE][MIDI_CONTROL] == control)) {
// Enable
if (val >= 65) { enable(); Serial.println(String("AudioEffectAnalogDelay::enable: ON") + value); }
else { disable(); Serial.println(String("AudioEffectAnalogDelay::enable: OFF") + value); }
return;
}
if ((m_midiConfig[MIDI_FEEDBACK][MIDI_CHANNEL] == channel) &&
(m_midiConfig[MIDI_FEEDBACK][MIDI_CONTROL] == control)) {
// Feedback
Serial.println(String("AudioEffectAnalogDelay::feedback: ") + val);
feedback(val);
return;
}
if ((m_midiConfig[MIDI_MIX][MIDI_CHANNEL] == channel) &&
(m_midiConfig[MIDI_MIX][MIDI_CONTROL] == control)) {
// Mix
Serial.println(String("AudioEffectAnalogDelay::mix: ") + val);
mix(val);
return;
}
}
void AudioEffectAnalogDelay::mapMidiDelay(int control, int channel)
{
m_midiConfig[MIDI_DELAY][MIDI_CHANNEL] = channel;
m_midiConfig[MIDI_DELAY][MIDI_CONTROL] = control;
}
void AudioEffectAnalogDelay::mapMidiEnable(int control, int channel)
{
m_midiConfig[MIDI_ENABLE][MIDI_CHANNEL] = channel;
m_midiConfig[MIDI_ENABLE][MIDI_CONTROL] = control;
}
void AudioEffectAnalogDelay::mapMidiFeedback(int control, int channel)
{
m_midiConfig[MIDI_FEEDBACK][MIDI_CHANNEL] = channel;
m_midiConfig[MIDI_FEEDBACK][MIDI_CONTROL] = control;
}
void AudioEffectAnalogDelay::mapMidiMix(int control, int channel)
{
m_midiConfig[MIDI_MIX][MIDI_CHANNEL] = channel;
m_midiConfig[MIDI_MIX][MIDI_CONTROL] = control;
}
void AudioEffectAnalogDelay::m_preProcessing(audio_block_t *out, audio_block_t *dry, audio_block_t *wet) void AudioEffectAnalogDelay::m_preProcessing(audio_block_t *out, audio_block_t *dry, audio_block_t *wet)
{ {
if ( out && dry && wet) { if ( out && dry && wet) {

@ -33,21 +33,34 @@ public:
void enable() { m_enable = true; } void enable() { m_enable = true; }
void disable() { m_enable = false; } void disable() { m_enable = false; }
void processMidi(int channel, int control, int value);
void mapMidiEnable(int control, int channel = 0);
void mapMidiDelay(int control, int channel = 0);
void mapMidiFeedback(int control, int channel = 0);
void mapMidiMix(int control, int channel = 0);
private: private:
audio_block_t *m_inputQueueArray[1]; audio_block_t *m_inputQueueArray[1];
bool m_enable = false; bool m_enable = false;
bool m_externalMemory = false; bool m_externalMemory = false;
AudioDelay *m_memory = nullptr; AudioDelay *m_memory = nullptr;
size_t m_maxDelaySamples = 0;
// Controls
int m_midiConfig[4][2];
//int m_midiEnable[2] = {0,16};
size_t m_delaySamples = 0; size_t m_delaySamples = 0;
//int m_midiDelay[2] = {0,20};
float m_feedback = 0.0f; float m_feedback = 0.0f;
//int m_midiFeedback[2] = {0,21};
float m_mix = 0.0f; float m_mix = 0.0f;
//int m_midiMix[2] = {0,22};
size_t m_callCount = 0;
audio_block_t *m_previousBlock = nullptr; audio_block_t *m_previousBlock = nullptr;
void m_preProcessing(audio_block_t *out, audio_block_t *dry, audio_block_t *wet); void m_preProcessing(audio_block_t *out, audio_block_t *dry, audio_block_t *wet);
void m_postProcessing(audio_block_t *out, audio_block_t *dry, audio_block_t *wet); void m_postProcessing(audio_block_t *out, audio_block_t *dry, audio_block_t *wet);
size_t m_callCount = 0;
}; };
} }

@ -174,7 +174,7 @@ bool AudioDelay::getSamples(audio_block_t *dest, size_t offset, size_t numSample
m_slot->setReadPosition((size_t)readPosition); m_slot->setReadPosition((size_t)readPosition);
} }
m_slot->printStatus(); //m_slot->printStatus();
// write the data to the destination block in reverse // write the data to the destination block in reverse
// int16_t *destPtr = dest->data + AUDIO_BLOCK_SAMPLES-1; // int16_t *destPtr = dest->data + AUDIO_BLOCK_SAMPLES-1;

Loading…
Cancel
Save