Changing Delay time without distortion

Status
Not open for further replies.

Malte

New member
Hello everybody,

this is my first post in this forum.
I've been reading a lot of posts here and always found a solution in the past.
But now I can't find an answer so this is my start here :)

I just bought a teensy and an audio shield because I heard about the audio library and I thought I might use it for my projects.
I'm building a delay right now with pots to control the delay time, feedback and lowpass filtering.
It works but I have a problem and I don't know if there's a good solution for that.
Everytime I change the delay time, the delayed signal gets distorted. The dry signal stays clean and as soon as I stop altering the delay time, there's no distortion anymore.
Is there any way to avoid this distortion? I plan to control the delay time via control voltages from my synths later so it would be pretty annoying then.

Here's my code so far:

Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioInputI2S            i2s2;           //xy=72.85720825195312,227.14288330078125
AudioMixer4              mixer2;         //xy=220,437.1428527832031
AudioEffectDelay         delay1;         //xy=377.142822265625,470.0000915527344
AudioMixer4              mixer1;         //xy=545.7142944335938,438.571533203125
AudioFilterStateVariable filter1;        //xy=665.7142944335938,299.9999694824219
AudioMixer4              mixer3;         //xy=805.7142333984375,157.1428680419922
AudioOutputI2S           i2s1;           //xy=992.857177734375,180
AudioConnection          patchCord1(i2s2, 0, mixer2, 0);
AudioConnection          patchCord2(i2s2, 0, mixer3, 0);
AudioConnection          patchCord3(mixer2, delay1);
AudioConnection          patchCord4(delay1, 0, mixer1, 0);
AudioConnection          patchCord5(mixer1, 0, filter1, 0);
AudioConnection          patchCord6(filter1, 0, mixer3, 1);
AudioConnection          patchCord7(filter1, 0, mixer2, 1);
AudioConnection          patchCord8(mixer3, 0, i2s1, 0);
AudioConnection          patchCord9(mixer3, 0, i2s1, 1);
AudioControlSGTL5000     sgtl5000_1;     //xy=457.1428571428571,628.5714285714286
// GUItool: end automatically generated code

float deltime = 200;

const int numReadings = 100;

int readings[numReadings];    
int readIndex = 0;            
float total = 0;


void setup() {
  Serial.begin(9600);
  AudioMemory(160);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.8);
  sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN);

  
  
  mixer1.gain(0, 0.8);
  mixer2.gain(0, 1);
  mixer2.gain(1, 0.2);
  mixer3.gain(0, 1);
  mixer3.gain(1, 0.8);
  
  
  
  delay1.delay(0, deltime);
  filter1.frequency(1000);
  filter1.resonance(0.7);

  for (int thisReading = 0; thisReading < numReadings; thisReading++) {
    readings[thisReading] = 0;
  }
  
}

void loop() {
  int knob1 = analogRead(A2);
  int knob2 = analogRead(A3) / 3 + 5;
  int knob3 = analogRead(A6);

  //Feedback
  float feedback = (float)knob1 / 800;
  mixer2.gain(1, feedback);
  //Serial.println(feedback);

  //Delay Time
  total = total - readings[readIndex];
  readings[readIndex] = knob2;
  total = total + readings[readIndex];
  readIndex = readIndex + 1;

  if (readIndex >= numReadings) {
    readIndex = 0;
  }

  deltime = total / numReadings;
  
  delay1.delay(0, deltime); 
  Serial.println(deltime);
  delay(1);

  

  //Filter
  float cutoff = pow((float)knob3/10.24, 2);
  filter1.frequency(cutoff);
  //Serial.println(cutoff);
  //float cutlog = pow(cutoff/10.24, 2);
  //Serial.println(cutlog);
  // delay(100);
}

I'd appreciate any help!

Cheers
Malte
 
If you want to be able to change the delay time wile it's running, it requires a slightly different algorithm.

You can read more about the algorithm here:
https://ccrma.stanford.edu/~dattorro/EffectDesignPart2.pdf

I've taken a stab at a variation of it here:
https://github.com/Jacquot-SFE/Synth-drum/tree/master/teensy-based/fx/cosmic-delay-sketch

I see... Well that's a lot to read for me :)
I'm just starting with teensy so I don't understand most of what you're doing there.
So I guess there's no way around writing a new delay class (or using the one you're working on)?
 
You should be able to use mine without too much hassle. If you grab all the files in that directory, and put them in a folder with the same name as the *.ino file, they should complie.

There are a couple changes you'd need to make the the *.ino file, to match your system.

First, take a look at the analog pins being read in param_update(), and reassign to match your controls.

With that done, you could be able to load the sketch and hear my test tones.

The second part would be to remove my test tone, and use the i2s input in it's place. For my testing, that sketch generates it's own tone bursts, so I can test the delay without any external hardware.
 
Ok, I'll try that. Thanks for sharing!

After reassigning the analog inputs I tried compiling it but I'm getting an error:

Code:
Arduino: 1.6.5 (Mac OS X), TD: 1.28, Platine: "Teensy 3.2 / 3.1, Serial, 96 MHz optimized (overclock), US English"

cosmic-delay-sketch.ino: In function 'void loop()':
cosmic-delay-sketch.ino:132:15: warning: unused variable 'next_on' [-Wunused-variable]
/Applications/Arduino.app/Contents/Java/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld: /var/folders/_h/qpytz40964s27zvnk2g_5smh0000gn/T/build940337902619145166.tmp/cosmic-delay-sketch.cpp.elf section `.bss' will not fit in region `RAM'
/Applications/Arduino.app/Contents/Java/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld: region `RAM' overflowed by 692 bytes
collect2: error: ld returned 1 exit status

Do I need to have any extra memory for this?
 
I'm just using the internal processor memory. This algorithm doesn't translate to the external SPI memory very well, because those devices are optimized for sequential reading, but the modulated delay line doesn't guarantee that extraction is sequential.

I just tried building using your settings, and I get a similar error.

Try setting the tools for a non-optimized build. I can build without overflowing at 72 or 96 MHz, but only non optimized. I get a warning abut the low memory, but it works.

If that doesn't work for you, reduce the size of LEN a bit -- try 0x6000.
 
Would be GREAT to have a variable delay object in the audio library with an input for the modulation. Like the state variable filter filter object.
Can your code be used for that? Licenses etc..
 
The overall intent was always to release these as MIT-licensed, I've just been slack about putting it in the files.

I just updated the files in that directory with the license block. Have at 'em.

I can't make any promises about getting the files back to the mainline audio library - pull requests seem to be moving slowly.

I may need to reorganize my audio module files as a secondary library, because I've been pasting them into each sketch that needs them. It's getting hard to know where the canonical source is kept.
 
I'm just using the internal processor memory. This algorithm doesn't translate to the external SPI memory very well, because those devices are optimized for sequential reading, but the modulated delay line doesn't guarantee that extraction is sequential.

I just tried building using your settings, and I get a similar error.

Try setting the tools for a non-optimized build. I can build without overflowing at 72 or 96 MHz, but only non optimized. I get a warning abut the low memory, but it works.

If that doesn't work for you, reduce the size of LEN a bit -- try 0x6000.

I tried it out and it works now, thanks!
It needs a lot of RAM though. I tried to reduce the buffer but that lead to some weird popping noises.
Yeah, it would be nice to make this an audio library object!
 
The overall intent was always to release these as MIT-licensed, I've just been slack about putting it in the files.

I just updated the files in that directory with the license block. Have at 'em.

I can't make any promises about getting the files back to the mainline audio library - pull requests seem to be moving slowly.

I may need to reorganize my audio module files as a secondary library, because I've been pasting them into each sketch that needs them. It's getting hard to know where the canonical source is kept.

That is good! As long as you want the MIT license its fine. This block is great for many effects, like octave, chourus with modulation and other modulation effects! Will try to get some time testing soon..
 
Status
Not open for further replies.
Back
Top