Delayline no longer works after being issued a reset command

I have a Daisy Seed powered by a regulated 15 volt supply and I’m using the Arduino IDE for development. I started with the StereoDelay example as a template and added code to use potentiometers for delay time and feedback. The audio was quite distorted and sounded like it was missing samples. I assumed that my code additions were consuming too much time so I modified my code to only process the knobs when they have value changes. The sound improved but was unacceptable when a the delay time knob was being rotated. In an attempt to improve the situation I added a delay.reset() to each delayline. That seems to have broken it somehow. There are no longer any repeats at any setting of the knobs. Removing the reset commands did nothing to fix it. Loading the original Delayline Example plays the tones but there are still no repeats. Did the reset turn off something internally that I am not aware of? Is it permanently damaged? Has anyone seen this before and can it be fixed?

Hmm, I believe the delay line’s reset() function sets the delay size to 0. Which would kill the delay. But, shouldn’t be permanent unless the delay line is not being initialized correctly.

Could you share you sketch so we can try it on our end.

Your daisy should be totally fine, nothing you can do with the code in arduino should damage it in anyway :slight_smile:

Are you still able to run any of the other examples, (including the DaisySP delayline example?)

I found my problem. I had to move all of my variable declarations to the top of the sketch. When you told me that I couldn’t break the unit with bad code in the Aduino environment I cut and paste lines of code from the examples to see what difference it would make in my code. I pretty much immediately noticed that the results were unstable. One time I would get a single repeat, another I would get repeats but wasn’t able to change the delay time. Another hint was that the quality of the audio varied with the delay time. The instabilities that I observered gave me the idea that something was going on behind the scenes that was causing the variables to be invalid or unavailable and possibly crashing the callback routine. That’s when I moved all the declarations to the top of the program and everything fell in line and behaved as expected. That makes all of the variables global in the scope of things and that’s OK by me.

I looked all over this forum to find the proper way to post code and couldn’t find anything except pictures so I included it below. Please let me know the prefered method so I can conform in the future.

// ***********************************************************
// * Daisy Seed Delay With Delay Time and Feedback Knobs
// *
// ***********************************************************

#include "DaisyAudio.h"
#include "DaisyDSP.h"

size_t num_channels;
float sample_rate, prev_knob1val, prev_knob2val;
float knob1val, knob2val, delay_time, feed_back;
float dry_left, dry_right, wet_left, wet_right;

// Instantiate DelayLine
// Set max delay time to 100% of samplerate.
#define MAX_DELAY static_cast<size_t>(48000)
DelayLine<float, MAX_DELAY> del_left, del_right;

// Callback to process audio
void MyCallback(float **in, float **out, size_t size)
{
    // Read Knobs (return range is 0 to 1023)
    knob1val = analogRead(A0);
    knob2val = analogRead(A1);

    // Set Delay Time only when knob position has changed
    if (abs(prev_knob1val - knob1val) > 10)
    {
        Serial.print("Knob1Raw: ");
        Serial.print(knob1val);
        
        prev_knob1val = knob1val;
        knob1val = knob1val / 1023.00f;
        Serial.print("  Scaled: ");
        Serial.print(knob1val);
        
        // Clamp low end of pot
        if (knob1val <= 0.02f)
        {
            knob1val = 0.02f;
        }

        Serial.print(" Clamped: ");
        Serial.print(knob1val);
        Serial.print("  SampleRate: ");
        Serial.print(sample_rate);

        // Reset delaylines
        del_left.Reset();
        del_right.Reset();
        
        // Delay time in number of samples
        delay_time = sample_rate * knob1val;
        del_left.SetDelay(delay_time);
        del_right.SetDelay(delay_time);
        
        Serial.print("  DelayTime: ");
        Serial.println(delay_time);  
    }

    // Set Feedback only when knob position has changed
    if (abs(prev_knob2val - knob2val) > 10)
    {
        Serial.print("Knob2Raw: ");
        Serial.print(knob2val);
        
        prev_knob2val = knob2val;
        feed_back = knob2val / 1023.00f;

        Serial.print("  Scaled: ");
        Serial.println(feed_back);
    }
    
    // Process the effect (using non-interleaved audio) 
    for (size_t i = 0; i < size; i++)
    {
        // ============================================
        // Delayline 
        // ============================================
        
        // Read Dry from I/O
        dry_left = in[0][i];
        dry_right = in[1][i];

        // Read Wet from Delay Lines
        wet_left = del_left.Read();
        wet_right = del_right.Read();
        
        // Write to Delay
        del_left.Write((wet_left * feed_back) + dry_left);
        del_right.Write((wet_right * feed_back) + dry_right);

        // Mix Dry and Wet and send to I/O
        out[0][i] = wet_left + dry_left;
        out[1][i] = wet_right + dry_right;
    }
}

void setup()
{
    // Debug
    Serial.begin(9600);
    
    // Initialize Daisy seed at 48kHz
    num_channels = AUDIO.init(DAISY_SEED, AUDIO_SR_48K);
    sample_rate = AUDIO.get_samplerate();
    
    // Init Delay Lines
    del_left.Init();
    del_right.Init();
    del_left.SetDelay(12000.0f);
    del_right.SetDelay(12000.0f);
    prev_knob1val = 250.0f;
    prev_knob2val = 500.0f;
    
    // Start Audio
    AUDIO.begin(MyCallback);
}

void loop()
{
}
1 Like

Thank you very much for sharing. I’m having a similar issue with the normal Delayline example in Arduino IDE.

Your welcome. I’m happy it helps. Here’s another gem :gem: that I ran into;

In the Arduino Environment using the PassThru sketch from the examples in the Arduino Audio library with DAISY_SEED device in the call back, physical pin 17 = in[0] and physical pin 18 = out[0]. I am only using mono (left channel only) in my current project.

Reply from Electro-Smith
in[0] should be physical pin 16, and out[0] should be physical pin 18. If this is not the case, we’ll look into patching it as it is likely a bug.

Summary

This text will be hidden

2 Likes

Would it be possible to increase delay times beyond 1-2 seconds? I’m imagining a looper with 5-10 seconds of delay time.

This is possible, but support hasn’t been added to arduino yet.

Once we get the sdram support added you’ll be able to have minutes of audio in delay lines/buffers :slight_smile:

We’ll try to get this in ASAP!

2 Likes

I’m hyped! thank you :pray: