Drums with delay does not work.

Status
Not open for further replies.

nubie

Active member
If I do this, then it works:
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <synth_simple_drum.h>

 
AudioSynthSimpleDrum     drum2;          //xy=142,180
AudioSynthSimpleDrum     drum3;          //xy=167,246
AudioSynthSimpleDrum     drum1;          //xy=174,133
AudioSynthSimpleDrum     drum4;          //xy=207,310
AudioMixer4              mixer1;         //xy=480,201
AudioOutputAnalog        dac1;           //xy=647,197
AudioConnection          patchCord1(drum2, 0, mixer1, 1);
AudioConnection          patchCord2(drum3, 0, mixer1, 2);
AudioConnection          patchCord3(drum1, 0, mixer1, 0);
AudioConnection          patchCord4(drum4, 0, mixer1, 3);
AudioConnection          patchCord5(mixer1, dac1);

AudioControlSGTL5000     sgtl5000_1;     //xy=930,518

static uint32_t next;

void setup() {
  Serial.begin(115200);

  // audio library init
  AudioMemory(15);

  next = millis() + 1000;

  AudioNoInterrupts();

  drum1.frequency(60);
  drum1.length(1500);
  drum1.secondMix(0.0);
  drum1.pitchMod(0.55);
  
  drum2.frequency(60);
  drum2.length(300);
  drum2.secondMix(0.0);
  drum2.pitchMod(1.0);
  
  drum3.frequency(550);
  drum3.length(400);
  drum3.secondMix(1.0);
  drum3.pitchMod(0.5);

  drum4.frequency(1200);
  drum4.length(150);
  drum4.secondMix(0.0);
  drum4.pitchMod(0.0);
  
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.5);

  AudioInterrupts();

}

void loop() {
  static uint32_t num = 0;

  if(millis() == next)
  {
    next = millis() + 1000;

    switch(num % 4)
    {
      case 0:
        drum1.noteOn();
        break;
      case 1:
        drum2.noteOn();
        break;
      case 2:
        drum3.noteOn();
        break;
      case 3:
        drum4.noteOn();
        break;
    }
    num++;

  int knobFreq = analogRead(A11);   // tune
  int knobLength = analogRead(A9);  // fine tune

  drum1.frequency(knobFreq*2);
  drum2.frequency(knobFreq*2);
  drum3.frequency(knobFreq*2);
  drum4.frequency(knobFreq*2);

  drum1.length(knobLength*2);
  drum2.length(knobLength*2);
  drum3.length(knobLength*2);
  drum4.length(knobLength*2);
  
  }
}
If I take a drum away to have an input free in the mixer*** to add a delay, then it does not work anymore (with feedback or not, it does not).
***I tried with 2 mixers but did not work, as it does not work in one anyway, I am doing something else wrong. I can add again the different drums + mixers once I get it to work.

THIS IS NOT WORKING WITH DELAY:
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

#include <synth_simple_drum.h>

AudioSynthSimpleDrum     drum1;          //xy=485.33331298828125,211.66668701171875
AudioSynthSimpleDrum     drum2;          //xy=504,263
AudioSynthSimpleDrum     drum3;          //xy=538,323
AudioMixer4              mixer1;         //xy=791.3333129882812,279.66668701171875
AudioEffectDelay         delay1;         //xy=946.6666666666665,444.99999999999994
AudioOutputAnalog        dac1;           //xy=958.3333129882812,275.66668701171875
AudioConnection          patchCord1(drum1, 0, mixer1, 0);
AudioConnection          patchCord2(drum2, 0, mixer1, 1);
AudioConnection          patchCord3(drum3, 0, mixer1, 2);
AudioConnection          patchCord4(mixer1, delay1);
AudioConnection          patchCord5(delay1, 0, dac1, 0);
AudioConnection          patchCord6(delay1, 0, mixer1, 3);
AudioControlSGTL5000     sgtl5000_1;     //xy=930,518

static uint32_t next;

void setup() {
  Serial.begin(115200);

  // audio library init
  AudioMemory(15);

  mixer1.gain(0, 0.5);
  mixer1.gain(1, 0.5);
  mixer1.gain(2, 0.5);
  mixer1.gain(3, 0.7);
  delay1.delay(0, 400);
  delay(1000);

  next = millis() + 1000;

  AudioNoInterrupts();

  drum1.frequency(60);
  drum1.length(1500);
  drum1.secondMix(0.0);
  drum1.pitchMod(0.55);
  
  drum2.frequency(60);
  drum2.length(300);
  drum2.secondMix(0.0);
  drum2.pitchMod(1.0);
  
  drum3.frequency(550);
  drum3.length(400);
  drum3.secondMix(1.0);
  drum3.pitchMod(0.5);

  sgtl5000_1.enable();
  sgtl5000_1.volume(0.5);

  AudioInterrupts();

}

void loop() {
  static uint32_t num = 0;

  if(millis() == next)
  {
    next = millis() + 1000;

    switch(num % 3)
    {
      case 0:
        drum1.noteOn();
        break;
      case 1:
        drum2.noteOn();
        break;
      case 2:
        drum3.noteOn();
        break;
    }
    num++;

  int knobFreq = analogRead(A11);   // tune
  int knobLength = analogRead(A9);  // fine tune

  drum1.frequency(knobFreq*2);
  drum2.frequency(knobFreq*2);
  drum3.frequency(knobFreq*2);

  drum1.length(knobLength*2);
  drum2.length(knobLength*2);
  drum3.length(knobLength*2);
  
  }
}
Do you know why?
 
Try increasing AudioMemory() delay uses lots of memory.

From the GUI:
Memory for the delayed signal is take from the memory pool allocated by AudioMemory(). Each block allows about 2.9 milliseconds of delay, so AudioMemory should be increased to allow for the longest delay tap.

Each board has a maximum possible delay.

Board Maximum
Teensy 3.0 139.26 ms
Teensy 3.1 449.39 ms
Teensy 3.2 449.39 ms
Teensy 3.5 1671.19 ms
Teensy 3.6 2413.94 ms
 
No matter what value I set (up to the max - up to 99%), I don't get any sound out. I guess I am doing something else wrong.
Here even if I simplify with only 1 drum sound (which does not btw affect memory usage - as it's the delay which has more affect), it still does not work:
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

#include <synth_simple_drum.h>

// GUItool: begin automatically generated code
AudioSynthSimpleDrum     drum1;          //xy=485.33331298828125,211.66668701171875
AudioMixer4              mixer1;         //xy=791.3333129882812,279.66668701171875
AudioEffectDelay         delay1;         //xy=946.6666666666665,444.99999999999994
AudioOutputAnalog        dac1;           //xy=958.3333129882812,275.66668701171875
AudioConnection          patchCord1(drum1, 0, mixer1, 0);
AudioConnection          patchCord2(mixer1, delay1);
AudioConnection          patchCord3(delay1, 0, dac1, 0);
AudioConnection          patchCord4(delay1, 0, mixer1, 3);
// GUItool: end automatically generated code

AudioControlSGTL5000     sgtl5000_1;     //xy=930,518

static uint32_t next;

void setup() {
  Serial.begin(115200);

  // audio library init
  AudioMemory(150);

  mixer1.gain(0, 0.5);
  mixer1.gain(3, 0.7);
  delay1.delay(0, 400);
  delay(1000);

  next = millis() + 1000;

  AudioNoInterrupts();

  drum1.frequency(60);
  drum1.length(1500);
  drum1.secondMix(0.0);
  drum1.pitchMod(0.55);
  

  sgtl5000_1.enable();
  sgtl5000_1.volume(0.5);

  AudioInterrupts();

}

void loop() {

  if(millis() == next)
  {
    next = millis() + 1000;
    drum1.noteOn();
    
    int knobFreq = analogRead(A11);   // tune
    int knobLength = analogRead(A9);  // fine tune
  
    drum1.frequency(knobFreq*2);
    drum1.length(knobLength*2);
  
  }
}
 
@nubie I tried your code with a Teensy 3.6 with the Audioboard. I changed the dac for an i2s output and it works fine (sounds good!).

I don't have the dac set up for audio out so can't test that, can you post a picture of what you've got connected and what sort of teensy you are using.
 
@nubie I tried your code with a Teensy 3.6 with the Audioboard. I changed the dac for an i2s output and it works fine (sounds good!).

I don't have the dac set up for audio out so can't test that, can you post a picture of what you've got connected and what sort of teensy you are using.
I am using Teensy 3.2. It's inside a module I use to play samples or synth sounds depending which firmware I use.
DAC out is connected to A14.

It's only when a delay is added, that it does not work.

If I try this simple example, there's no delay either.

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

// GUItool: begin automatically generated code
AudioSynthWaveformSine   sine1;          //xy=158,74
AudioEffectEnvelope      envelope1;      //xy=232,156
AudioEffectDelay         delay1;         //xy=393,238
AudioMixer4              mixer1;         //xy=532,205
AudioOutputAnalog        dac1;
AudioConnection          patchCord1(sine1, envelope1);
AudioConnection          patchCord2(envelope1, delay1);
AudioConnection          patchCord3(envelope1, 0, dac1, 0);
AudioConnection          patchCord4(delay1, 0, mixer1, 0);
AudioConnection          patchCord5(delay1, 1, mixer1, 1);
AudioConnection          patchCord6(delay1, 2, mixer1, 2);
AudioConnection          patchCord7(delay1, 3, mixer1, 3);
AudioConnection          patchCord8(mixer1, 0, dac1, 1);
AudioControlSGTL5000     sgtl5000_1;     //xy=195,272
// GUItool: end automatically generated code

void setup() {
  // allocate enough memory for the delay
  AudioMemory(120);
  
  // configure a sine wave for the chirp
  // the original is turned on/off by an envelope effect
  // and output directly on the left channel
  sine1.frequency(1000);
  sine1.amplitude(0.5);

  // create 3 delay taps, which connect through a
  // mixer to the right channel output
  delay1.delay(0, 110);
  delay1.delay(1, 220);
  delay1.delay(2, 330);
}

void loop() {
  envelope1.noteOn();
  delay(36);
  envelope1.noteOff();
  delay(4000);
}

Is the delay also supposed to work with the analog output of the Teensy (DAC)?
 
Hi,

I wired up a Teensy 3.2 with the DAC and the first two examples above work fine.

The last one (#5) doesn't work because you've got two connections to the dac (which only has one port) so all you hear is the signal straight out the envelope.

If I change it as below I hear the signal delayed 3 times (also you don't need the AudioControlSGTL5000 control object if not using the audio board) . Can you try that and see if it works

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

// GUItool: begin automatically generated code
AudioSynthWaveformSine   sine1;          //xy=484,324
AudioEffectEnvelope      envelope1;      //xy=558,406
AudioEffectDelay         delay1;         //xy=719,488
AudioMixer4              mixer1;         //xy=860,455
AudioOutputAnalog        dac1;           //xy=1120,454
AudioConnection          patchCord1(sine1, envelope1);
AudioConnection          patchCord2(envelope1, delay1);
AudioConnection          patchCord3(delay1, 0, mixer1, 0);
AudioConnection          patchCord4(delay1, 1, mixer1, 1);
AudioConnection          patchCord5(delay1, 2, mixer1, 2);
AudioConnection          patchCord6(delay1, 3, mixer1, 3);
AudioConnection          patchCord7(mixer1, dac1);
// Don't need this if not using Audio Board -- AudioControlSGTL5000     sgtl5000_1;     //xy=521,522
// GUItool: end automatically generated code

void setup() {
  // allocate enough memory for the delay
  AudioMemory(120);
  
  // configure a sine wave for the chirp
  // the original is turned on/off by an envelope effect
  // and output directly on the left channel
  sine1.frequency(1000);
  sine1.amplitude(0.5);

  // create 3 delay taps, which connect through a
  // mixer to the right channel output
  delay1.delay(0, 110);
  delay1.delay(1, 220);
  delay1.delay(2, 330);
}
 
Thanks. The fact that there's a noteON in the loop simply confused me. Like not hearing a delay, but simply repeating noteOn.
So I made some tweaks to understand it. Also added feeback.
And it works.
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

AudioSynthWaveformSine   sine1;          //xy=76.85716247558594,112.85713195800781
AudioEffectEnvelope      envelope1;      //xy=220.85714721679688,114.85714721679688
AudioEffectDelay         delay1;         //xy=368.4285888671875,341.2856750488281
AudioMixer4              mixer1;         //xy=383.8571472167969,128.99996948242188
AudioMixer4              mixer2;         //xy=609,280
AudioOutputAnalog        dac1;           //xy=807.4286499023438,340.5714416503906
AudioConnection          patchCord1(sine1, envelope1);
AudioConnection          patchCord2(envelope1, 0, mixer1, 0);
AudioConnection          patchCord3(delay1, 0, mixer1, 1);
AudioConnection          patchCord4(delay1, 0, mixer2, 0);
AudioConnection          patchCord5(mixer1, delay1);
AudioConnection          patchCord6(mixer2, dac1);

void setup() {
  // allocate enough memory for the delay
  AudioMemory(120);
  
  sine1.frequency(1000);
  sine1.amplitude(0.5);

  mixer1.gain(0, 0.5);
  mixer1.gain(1, 0.7);
  delay1.delay(0, 1000);

  envelope1.noteOn();
  delay(36);
  envelope1.noteOff();
  
}

void loop() {
  int knob = analogRead(A5);
  float feedback = (float)knob / 1050.0;
  mixer1.gain(1, feedback);
}

Now that I know how to do by learning here from my previous posts (and your great help), I'll add next a pot to set delay time and have a gate signal or a switch shooting a sound.
 
Status
Not open for further replies.
Back
Top