Holger Wirtz 6 years ago
parent c4cf09efed
commit 5b0a478dcc
  1. 6
      src/AudioEffectSimpleChorus.h
  2. 63
      src/effects/AudioEffectSimpleChorus.cpp

@ -139,8 +139,6 @@ private:
bool m_enable = false;
BALibrary::AudioDelay *m_memory = nullptr;
size_t m_maxDelaySamples = 0;
audio_block_t *m_previousBlock = nullptr;
audio_block_t *m_blockToRelease = nullptr;
BALibrary::LowFrequencyOscillatorVector<float> lfo;
// Controls
@ -148,7 +146,9 @@ private:
size_t m_delaySamples = 0;
float m_frequency = 1.0f;
float m_intensity = 1.0f;
float m_mix = 0.0f;
float m_mix = 0.5f;
audio_block_t *m_blockToRelease = nullptr;
audio_block_t *m_previousBlock = nullptr;
void m_postProcessing(audio_block_t *out, audio_block_t *dry, audio_block_t *wet);

@ -34,15 +34,12 @@ void AudioEffectSimpleChorus::update(void)
{
audio_block_t *inputAudioBlock = receiveReadOnly(); // get the next block of input samples
/*
// Check is block is disabled
if (m_enable == false) {
// do not transmit or process any audio, return as quickly as possible.
if (inputAudioBlock) release(inputAudioBlock);
// release all held memory resources
if (m_previousBlock) {
release(m_previousBlock); m_previousBlock = nullptr;
}
// when using internal memory we have to release all references in the ring buffer
while (m_memory->getRingBuffer()->size() > 0) {
audio_block_t *releaseBlock = m_memory->getRingBuffer()->front();
@ -67,45 +64,47 @@ void AudioEffectSimpleChorus::update(void)
release(inputAudioBlock);
return;
}
*/
// Otherwise perform normal processing
// In order to make use of the SPI DMA, we need to request the read from memory first,
// then do other processing while it fills in the back.
audio_block_t *blockToOutput = nullptr; // this will hold the output audio
blockToOutput = allocate();
if (!blockToOutput) return; // skip this update cycle due to failure
// get the data. If using external memory with DMA, this won't be filled until
// later.
m_memory->getSamples(blockToOutput, m_delaySamples);
//audio_block_t *blockToRelease = m_memory->addBlock(blockToOutput);
// If using DMA, we need something else to do while that read executes, so
// move on to input preprocessing
// Chorus
float *mod = lfo.getNextVector();
for(uint8_t i=0;i<AUDIO_BLOCK_SAMPLES;i++)
{
/// HIER
//float sample=std::roundf((m_delaySamples/2)*mod[i]*(float)inputAudioBlock->data[i])+(m_delaySamples/2);
//inputAudioBlock->data[i] = (int16_t)sample/2+inputAudioBlock->data[i]/2;
blockToOutput->data[i]=(float(inputAudioBlock->data[i])*mod[i]);
}
// BACK TO OUTPUT PROCESSING
blockToOutput = allocate();
if (!blockToOutput) return; // skip this update cycle due to failure
memset(blockToOutput->data,0,AUDIO_BLOCK_SAMPLES * sizeof(int16_t));
audio_block_t *blockToRelease = m_memory->addBlock(inputAudioBlock);
// Chorus
float *mod = lfo.getNextVector();
audio_block_t *lfoData = nullptr;
lfoData = allocate();
if (!lfoData) return;
for(uint8_t i=0;i<AUDIO_BLOCK_SAMPLES;i++)
{
//m_memory->getSamples(blockToOutput,m_delaySamples);
m_memory->getSamples(lfoData,float(m_delaySamples)/2+(m_intensity*mod[i]*float(m_delaySamples)/2),3);
if(mod[i]==0.0)
blockToOutput->data[i]=lfoData->data[1];
else if(mod[i]<0.0)
blockToOutput->data[i]=int16_t(((float(lfoData->data[0])-lfoData->data[1])*(1+mod[i]))+lfoData->data[0]+0.5);
else
blockToOutput->data[i]=int16_t(((float(lfoData->data[2])-lfoData->data[1])*mod[i])+lfoData->data[2]+0.5);
}
// perform the wet/dry mix mix
//m_postProcessing(blockToOutput, inputAudioBlock, blockToOutput);
transmit(blockToOutput);
release(inputAudioBlock);
release(m_previousBlock);
release(lfoData);
if(m_previousBlock)
release(m_previousBlock);
m_previousBlock = blockToOutput;
release(blockToOutput);
//if (m_blockToRelease) release(m_blockToRelease);
//m_blockToRelease = blockToRelease;
if (m_blockToRelease)
release(m_blockToRelease);
m_blockToRelease = blockToRelease;
}
void AudioEffectSimpleChorus::delay(float milliseconds)

Loading…
Cancel
Save