Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 9 of 9

Thread: Teensy 4.1: Delay - audio cuts out when introducing feedback loop

  1. #1
    Junior Member
    Join Date
    Apr 2022
    Posts
    4

    Teensy 4.1: Delay - audio cuts out when introducing feedback loop

    Hi,
    I have a problem I can't quite figure out - I'm using a Teensy 4.1 to take audio from an audio jack (AudioInputAnalog), add a delay effect, then pass it back out through another audio jack (AudioOutputMQS). I also pass through a dry version of the input straight to the output.

    This works great.

    I'm not using any audio adaptor boards (quality is not too important as the source will be lo-fi tones).

    I'm able to control the length of delay with a potentiometer successfully.

    The problem comes when I introduce a feedback loop, with the intention of runaway feedback, to be controlled with a pot attenuating the AudioAmplifier named feedbackController. I can hear the feedback loop start up (as the gain goes over 1), but then the audio quickly cuts and I get silence. If I bring the feedbackController gain back down below 1, the audio will restart.

    I'm feeding the output of the first delay channel back into itself through a mixer (preMixer).

    I guess I may be having some sort of out of memory error, but I was under the impression that having just one Delay channel in use, and simply feeding the previous delay into the next one, wouldn't use any more memory than without the feedback, but I guess I may be likely to be incorrect there!

    As you can see I've made an attempt to check on memory usage, and have experimented with various AudioMemory(x) values.

    Many thanks in advance.

    Click image for larger version. 

Name:	Screenshot 2022-04-10 at 20.21.20.jpg 
Views:	16 
Size:	49.2 KB 
ID:	28082

    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    // GUItool: begin automatically generated code
    AudioInputAnalog inputJack; // xy=98,144
    AudioEffectDelay delay1;    // xy=393,238
    AudioMixer4 preMixer;       // xy=532,205
    AudioMixer4 mixer1;         // xy=532,205
    AudioOutputMQS outputJack;  // xy=1093,382
    AudioAmplifier inputToPremixer;        // xy=950,449
    AudioAmplifier feedbackController;        // xy=950,449
    AudioConnection patchCord1(inputJack, 0, inputToPremixer, 0);
    AudioConnection patchCord2(inputToPremixer, 0, preMixer, 0);
    AudioConnection patchCord3(preMixer, 0, delay1, 0);
    AudioConnection patchCord4(inputJack, 0, mixer1, 0);
    AudioConnection patchCord5(delay1, 0, feedbackController, 0);
    AudioConnection patchCord6(feedbackController, 0, preMixer, 1);
    AudioConnection patchCord7(delay1, 0, mixer1, 1);
    AudioConnection patchCord8(mixer1, 0, outputJack, 1);
    
    int pot1;
    
    const int OldRange = 1024;
    const float NewRange = 2;
    float wetDry;
    
    //  GUItool: end automatically generated code
    
    void setup()
    {
        // allocate enough memory for the delay
        AudioMemory(250);
        delay1.delay(0, 600);
        preMixer.gain(1, 1);
        inputToPremixer.gain(0.85);
        feedbackController.gain(0.7);
        mixer1.gain(1, 0.7)
        Serial.println("Playing....");
    }
    
    void loop()
    {
        pot1 = analogRead(1);
        if (pot1 == 0)
        {
            wetDry = 0;
        }
        else
        {
            wetDry = ((pot1 * NewRange) / OldRange);
        }
        Serial.print("wetdry = ");
        Serial.print(wetDry);
        Serial.println("max");
        Serial.print(AudioMemoryUsage());
        feedbackController.gain(wetDry);
    }

  2. #2
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,748
    The audio library is DC coupled, I think you've simply driven the signal all the way to +1 or -1 (saturation) with the feedback loop. Add a DC blocking filter if you don't want this, ie a high-pass in the feedback path.

  3. #3
    Senior Member
    Join Date
    Apr 2021
    Location
    Cambridgeshire, UK
    Posts
    379
    Agree, pretty sure I've seen this happen with AudioEffectDelayExternal. @MarkT, is there an "opportunity" here for a cheap high-pass filter audio block? i.e., one that doesn't use much CPU, isn't theoretically great, but is just good enough to avoid this sort of thing without degrading the audio too much?

  4. #4
    Junior Member
    Join Date
    Apr 2022
    Posts
    4
    Many thanks both, I will give a high pass filter a try. I guess the AudioFilterBiquad is my first port of call? A cheaper one sounds good though, the requirement for my project is simple tone based sounds.

  5. #5
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,748
    I think AudioFilterStateVariable is supposed to be better for very low cutoff frequencies. Filtering at 20Hz in a 44100SPS system represents a severe test of an IIR filter due to the large ratio between them.

  6. #6
    Senior Member houtson's Avatar
    Join Date
    Aug 2015
    Location
    Scotland
    Posts
    232
    @teensytwo - what sort of circuit are you using for the input?

  7. #7
    Junior Member
    Join Date
    Apr 2022
    Posts
    4
    Many thanks for that. An AudioFilterStateVariable seems to have solved the cutting out issue. The feedback loop now works, but I am now having quite a lot of noise, which nearly eclipses the source (an analogue siren).

    I've ordered the bits to add the input circuit in the docs (https://www.pjrc.com/teensy/gui/inde...dioInputAnalog) - I'm currently connecting it direct to the input pins.

    Will the input circuit likely reduce the noise I'm experiencing?

    Thanks

  8. #8
    Senior Member houtson's Avatar
    Join Date
    Aug 2015
    Location
    Scotland
    Posts
    232
    The circuit will likely fix your feedback problem (without needing the filter).

    What is the source that you are trying to connect ?

  9. #9
    Junior Member
    Join Date
    Apr 2022
    Posts
    4
    Many thanks for that, I have now connected the recommended input circuit.

    The noise is reduced, but still quite loud. The source is an analogue siren circuit board (a DIY kit for reggae sound systems). I successfully run this siren into an analogue delay circuit board (which I am attempting to emulate on the teensy), and there is almost no noise.

    The teensy, siren and speaker are battery powered in my testing.

    Is the teensy audio shield likely to reduce the noise any further?

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •