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

Loading…
Cancel
Save