Delay sounds "crunchy", help me improve this

I cobbled together a basic delay. It works but sounds very “crunchy”. Sounds like digital noise on the delay line. The bypass signal sounds fine. There is always some digital noise on the delayed signal.

Here is what I have so far. Any tips or feedback is welcome!

#include "daisysp.h"
#include "daisy_petal.h"
#include "terrarium.h"

using namespace daisy;
using namespace daisysp;
using namespace terrarium;

DaisyPetal petal;
Parameter param_feedback, param_mix;
SmoothedParameter smooth_delay_time;
Led led1, led2;

constexpr size_t MAX_DELAY = 48000 * 2; // 2 seconds max delay
DelayLine<float, MAX_DELAY> delay;
float samplerate;
Tone lp_filter;
bool effect_enabled = true;



void InitParams()
{
    smooth_delay_time.Init(petal.knob[Terrarium::KNOB_1], 0.01f, 2.0f, Parameter::LINEAR);
    param_feedback.Init(petal.knob[Terrarium::KNOB_2], 0.0f, 1.0f, Parameter::LINEAR);
    param_mix.Init(petal.knob[Terrarium::KNOB_3], 0.0f, 1.0f, Parameter::LINEAR);
}

void InitLeds()
{
    led1.Init(petal.seed.GetPin(Terrarium::LED_1), false);
    led2.Init(petal.seed.GetPin(Terrarium::LED_2), false);
}

void AudioCallback(AudioHandle::InputBuffer in, AudioHandle::OutputBuffer out, size_t size)
{
    float delay_time = smooth_delay_time.Process();
    float feedback = param_feedback.Process();
    float mix = param_mix.Process();

    float delay_samples = delay_time * samplerate;
    delay.SetDelay(delay_samples);

    for (size_t i = 0; i < size; i++)
    {
        float dry = in[0][i];
        float delayed = delay.Read();
        float input = dry + delayed * feedback;
        float filtered = lp_filter.Process(input);
        // Clamp to [-1.0, 1.0] before writing to delay
        filtered = fminf(fmaxf(filtered, -1.0f), 1.0f);
        delay.Write(filtered);

        float wet = delayed;
        float mixed = (1.0f - mix) * dry + mix * wet;

        float output = effect_enabled ? mixed : dry;
        out[0][i] = out[1][i] = output;
    }
}

int main(void)
{
    petal.Init();
    lp_filter.Init(petal.AudioSampleRate());
    lp_filter.SetFreq(4000.0f);
    samplerate = petal.AudioSampleRate();

    InitParams();
    InitLeds();

    delay.Init();
    petal.StartAdc();
    petal.StartAudio(AudioCallback);

    while (1)
    {
        petal.ProcessAnalogControls();
        petal.ProcessDigitalControls();

        if (petal.switches[Terrarium::FOOTSWITCH_1].RisingEdge())
        {
            effect_enabled = !effect_enabled;
        }

        // LED1 indicates if effect is enabled
        led1.Set(effect_enabled ? 1.0f : 0.0f);
        led1.Update();

        // LED2 shows mix level from KNOB_3
        led2.Set(param_mix.Process());
        led2.Update();

        System::Delay(10);
    }
}

Your clamping might be hard clipping the delay line input?

I would (and did) also bounce some ideas/code snippets off of chatgpt and it has some good suggestions to try

We also have a delay here ( that might provide some ideas)

and theres another one another here that might have some ideas:

Yes, it might seem old fashioned, but I worked as a software engineer for many years…

I’d start with a minimal program, adding features in small increments until it breaks. Or go in the other direction, removing features until the noise goes away.

I can’t imagine doing this would take longer than waiting for a forum member to debug the code.

Thanks for the replies. I’ve been experimenting, searching the internet, and a little ChatGPT. I got a pretty solution.

I managed to get two 5 sec delay lines and get rid of the noise. I used the internal RAM and filtered the time parameter. Between the noise went away. I took some clues from the examples.

I’m trying to get the delay to play in reverse with a switch. This is mostly working but the controls are a little wonky now.

1 Like

Thanks for coming back with your experience and findings and glad you stuck with it!

Thanks for the encouragement, I’m making progress!

1 Like