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)
#include "delay_module.h"
#include "../Util/audio_utilities.h"
using namespace bkshepherd;
static const char *s_waveBinNames[5] = {"Sine", "Triangle", "Saw", "Ramp",
"Square"}; //, "Poly Tri", "Poly Saw", "Poly Sqr"}; // Horrible loud sound when switching to
// poly tri, not every time, TODO whats going on? (I suspect electro smith broke
// the poly tri osc, the same happens in the tremolo too)
static const char *s_modParamNames[4] = {"None", "DelayTime", "DelayLevel", "DelayPan"};
static const char *s_delayModes[3] = {"Normal", "Triplett", "Dotted 8th"};
static const char *s_delayTypes[6] = {"Forward", "Reverse", "Octave", "ReverseOct", "Dual", "DualOct"};
DelayLineRevOct<float, MAX_DELAY_NORM> DSY_SDRAM_BSS delayLineLeft;
DelayLineRevOct<float, MAX_DELAY_NORM> DSY_SDRAM_BSS delayLineRight;
DelayLineReverse<float, MAX_DELAY_REV> DSY_SDRAM_BSS delayLineRevLeft;
DelayLineReverse<float, MAX_DELAY_REV> DSY_SDRAM_BSS delayLineRevRight;
DelayLine<float, MAX_DELAY_SPREAD> DSY_SDRAM_BSS delayLineSpread;
static const int s_paramCount =
This file has been truncated. show original
and theres another one another here that might have some ideas:
// BasicMultiDelay for Hothouse DIY DSP Platform
// Copyright (C) 2024 Your Name <your@email>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// Ported directly from the 'petal/MultiDelay' example in DaisyExamples. Knobs,
// switches, and pins are directly accessed without enums, so look at hothouse.h
// to decipher the mappings.
This file has been truncated. show original
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