Simple tremolo or delay DAFX

I have followed JUCE tutorial on how to build an audio player and I was wondering if there is away to include a button in the app that enables and disables a DAFX like a simple tremolo.How does one go about this?

I don’t know how much detail you need. But roughly:

  • Make a loop that processes the samples a chunk at a time
  • Write a simple LFO
  • Use that to vary the volume per-sample

Which tutorial were you following?

JUCE: Tutorial: Build an audio player.
May you please give a more detailed approach.
Am still learning JUCE so I would appreciate your effort.

    {
        if (readerSource.get() == nullptr)
        {
            bufferToFill.clearActiveBufferRegion();
            return;
        }
 
        transportSource.getNextAudioBlock (bufferToFill);
    }

So that’s in the tutorial. After the call to transportSource.getNextAudioBlock (…) you can put your code there. Start by just trying to apply a volume change so you get the idea before working up to an LFO controlling it.

Something approximately like this:

auto & audio = bufferToFill.buffer;
auto & data = audio.getArrayOfWritePointers();

for (int i = bufferToFill.startSample; i < bufferToFill.startSample + bufferToFill.numSamples; ++i+)
{
for (int chan = 0; chan < audio.getNumChannels(); ++chan)
{
   data[chan][i] *= 0.1f;
}
}

Untested - but something like that will hopefully make it very quiet. I’ll leave turning that into a tremolo for you but you just need to vary the 0.1f up and down over time.