Flanger effect for electric guitar project

Rkadio

New member
Hello everyone, I am trying to develop a flanger effect pedal for electric guitar using the Teensy 3.6 board with audio shield. The idea is that the guitar input goes into the Line in of the audio shield and comes out through the mini jack output of the audio shield. Between the guitar and the audio shield I have added a simple preamp with an operational amplifier, in non inverting configuration and with a gain of 10. But when I connect the guitar or a tone with the function generator nothing comes out of the output. I have checked with the oscilloscope that indeed the preamplified signal reaches the input of the audio shield, so I think the fault may be in the teensyduino code, I share here the code in case someone could help me to see something I'm not seeing.

Thanks in advance.

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

// GUItool: begin automatically generated code
AudioInputAnalog         adc1;           //xy=428,291
AudioEffectFlange        flange;        //xy=625,292
AudioMixer4              mixer1;         //xy=752,174
AudioOutputI2S           audioOutput;             //xy=929,262
AudioConnection          patchCord1(adc1, 0, mixer1, 0);
AudioConnection          patchCord2(adc1, flange);
AudioConnection          patchCord3(flange, 0, mixer1, 1);
AudioConnection          patchCord4(mixer1, 0, audioOutput, 0);
AudioControlSGTL5000     audioShield;  
// GUItool: end automatically generated code


// buttons and potentiometers
#define pot0             A13
#define pot1             A12
#define pot2             A20
#define button0          29

// attach button debouncers to input buttons
Bounce db_button0 = Bounce(button0, 30);

// choose mic or line input for audio shield input path

const int inputChSelect = 0;

// audio shield volume
int masterVolume        = 0.7;


// Flange Effect parameters
#define FLANGE_DELAY_LENGTH (6*AUDIO_BLOCK_SAMPLES)  // number of samples in each delay line

short l_delayline[FLANGE_DELAY_LENGTH];              // allocate delay lines for left and right channels
short r_delayline[FLANGE_DELAY_LENGTH];
int    s_idx           = FLANGE_DELAY_LENGTH / 4;
int    s_depth         = FLANGE_DELAY_LENGTH / 4;
double s_freq          = 3;
bool   flangeActive    = false;                      // track if flange effect is on or off

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

  // buttons are inputs with pullups
  pinMode(button0, INPUT_PULLUP);

  // Audio connections require memory to work.  For more
  // detailed information, see the MemoryAndCpuUsage example
  AudioMemory(8);

  // Comment these out if not using the audio adaptor board.
  Serial.print("init audio shield...");
  audioShield.enable();
  audioShield.inputSelect(inputChSelect);  // select mic or line-in for audio shield input source
  audioShield.volume(0.8);
  Serial.println("done.");
  audioShield.lineOutLevel(20);

  mixer1.gain(0, 0.5);
  mixer1.gain(1, 0.5);
  mixer1.gain(2, 0);
  mixer1.gain(3, 0);

  

  
Serial.println("done.");

  Serial.print("init Flange effect...");
  // Set up the flange effect:
  // address of delayline
  // total number of samples in the delay line
  // Index (in samples) into the delay line for the added voice
  // Depth of the flange effect
  // frequency of the flange effect
 flange.begin(l_delayline, FLANGE_DELAY_LENGTH, s_idx, s_depth, s_freq);

  // Initially the effect is off.
 flange.voices(FLANGE_DELAY_PASSTHRU, 0, 0);
 

  Serial.println("done.");

  Serial.println("Waiting for control input...");

  // reset audio resource usage stats.
  // useful if tracking max usage in main program
  AudioProcessorUsageMaxReset();
  AudioMemoryUsageMaxReset();

}


void loop() {

  // update the button debounce status so falling edges
  // can be detected and processed
  db_button0.update();

 
  // button 0 pressed - toggle Flange effect
  //if (db_button0.fallingEdge()) {
   // if (flangeActive) {
     // flange.voices(FLANGE_DELAY_PASSTHRU, 0, 0);
          // Serial.println("Flange OFF\n");
   // }
    //else {
     // flange.voices(s_idx, s_depth, s_freq);
     // Serial.println("Flange ON");
    //}
    //flangeActive = !flangeActive;
 // }
 if (db_button0.fallingEdge()) {
    flangeActive = !flangeActive;
    if (flangeActive) {
      flange.voices(s_idx, s_depth, s_freq);
      Serial.println("Flanger ON");
    } else {
      flange.voices(FLANGE_DELAY_PASSTHRU, 0, 0);
      Serial.println("Flanger OFF");
    }
  }

  // read volume control pot and set audio shield volume if required
  int vol = analogRead(pot0);
  if (vol != masterVolume) {
    masterVolume = vol;
    audioShield.volume((float)vol / 1023);  // audio shield headphone out volume (optional)
    mixer1.gain(0, (float)vol / 1023);      // software mixer input channel volume
    mixer1.gain(1, (float)vol / 1023);
    Serial.print("Volume: ");
    Serial.println(vol);

  }

  // read Flange control pot and change parameter if required
  if (flangeActive) {
    int reading1 = map(analogRead(pot1), 0, 1023, 1, 10);
    if ((reading1 / 10.0) != s_freq) {
      s_freq = reading1 / 10.0;
      Serial.print("New flange freq: ");
      Serial.println(s_freq);
      flange.voices(s_idx, s_depth, s_freq);
      
    }
       int reading2 = map(analogRead(pot2), 0, 1023, 1, 10);
    if ((reading2 / 1) != s_depth) {
      s_depth = reading2 / 1;
      Serial.print("New flange depth: ");
      Serial.println(s_depth);
      flange.voices(s_idx, s_depth, s_freq);
      
    }
  }
}

I´m using three potentiometers and one button, potentiometers control volumen, depth and frecuency and the button activates flange effect.

The code is a modification of Gadget Reboot's code which shares on his youtube channel and github page a code to apply flanger effect to wav songs put in the teensy from a SD card.
 
Here’s your problem:
Code:
 // GUItool: begin automatically generated code
[COLOR="#FF0000"]AudioInputAnalog[/COLOR]         adc1;           //xy=428,291
AudioEffectFlange        flange;        //xy=625,292
You should have used AudioInputI2S if your signal is going into the audio adaptor line in…
 
Here’s your problem:
Code:
 // GUItool: begin automatically generated code
[COLOR="#FF0000"]AudioInputAnalog[/COLOR]         adc1;           //xy=428,291
AudioEffectFlange        flange;        //xy=625,292
You should have used AudioInputI2S if your signal is going into the audio adaptor line in…

Thanks for your answer, I have made the modification you suggest and I have also removed the mixer because I do not need it, what I want is that the input signal is applied to the effect and this comes out, made the modifications compiles but still no audio output through the mini jack output.
Code:
// GUItool: begin automatically generated code
AudioInputI2S            i2s1;           //xy=118,121
AudioEffectFlange        flange;        //xy=357,118
AudioOutputI2S           AudioOutput;           //xy=598,117
AudioConnection          patchCord1(i2s1, 0, flange, 0);
AudioConnection          patchCord2(flange, 0, AudioOutput, 0);
AudioControlSGTL5000     audioShield;     //xy=137,173
// GUItool: end automatically generated code
  
// GUItool: end automatically generated code


// buttons and potentiometers
#define pot0             A13
#define pot1             A12
#define pot2             A20
#define button0          29

// attach button debouncers to input buttons
Bounce db_button0 = Bounce(button0, 30);

// choose mic or line input for audio shield input path

const int inputChSelect = 0;

// audio shield volume
int masterVolume        = 0.7;


// Flange Effect parameters
#define FLANGE_DELAY_LENGTH (6*AUDIO_BLOCK_SAMPLES)  // number of samples in each delay line

short l_delayline[FLANGE_DELAY_LENGTH];              // allocate delay lines for left and right channels
short r_delayline[FLANGE_DELAY_LENGTH];
int    s_idx           = FLANGE_DELAY_LENGTH / 4;
int    s_depth         = FLANGE_DELAY_LENGTH / 4;
double s_freq          = 3;
bool   flangeActive    = false;                      // track if flange effect is on or off

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

  // buttons are inputs with pullups
  pinMode(button0, INPUT_PULLUP);

  // Audio connections require memory to work.  For more
  // detailed information, see the MemoryAndCpuUsage example
  AudioMemory(8);

  // Comment these out if not using the audio adaptor board.
  Serial.print("init audio shield...");
  audioShield.enable();
  audioShield.inputSelect(inputChSelect);  // select mic or line-in for audio shield input source
  audioShield.volume(0.8);
  Serial.println("done.");
  audioShield.lineOutLevel(20);


Serial.println("done.");

  Serial.print("init Flange effect...");
  // Set up the flange effect:
  // address of delayline
  // total number of samples in the delay line
  // Index (in samples) into the delay line for the added voice
  // Depth of the flange effect
  // frequency of the flange effect
 flange.begin(l_delayline, FLANGE_DELAY_LENGTH, s_idx, s_depth, s_freq);

  // Initially the effect is off.
 flange.voices(FLANGE_DELAY_PASSTHRU, 0, 0);
 

  Serial.println("done.");

  Serial.println("Waiting for control input...");

  // reset audio resource usage stats.
  // useful if tracking max usage in main program
  AudioProcessorUsageMaxReset();
  AudioMemoryUsageMaxReset();

}


void loop() {

  // update the button debounce status so falling edges
  // can be detected and processed
  db_button0.update();

 
  // button 0 pressed - toggle Flange effect
  //if (db_button0.fallingEdge()) {
   // if (flangeActive) {
     // flange.voices(FLANGE_DELAY_PASSTHRU, 0, 0);
          // Serial.println("Flange OFF\n");
   // }
    //else {
     // flange.voices(s_idx, s_depth, s_freq);
     // Serial.println("Flange ON");
    //}
    //flangeActive = !flangeActive;
 // }
 if (db_button0.fallingEdge()) {
    flangeActive = !flangeActive;
    if (flangeActive) {
      flange.voices(s_idx, s_depth, s_freq);
      Serial.println("Flanger ON");
    } else {
      flange.voices(FLANGE_DELAY_PASSTHRU, 0, 0);
      Serial.println("Flanger OFF");
    }
  }

  // read volume control pot and set audio shield volume if required
  int vol = analogRead(pot0);
  if (vol != masterVolume) {
    masterVolume = vol;
    audioShield.volume((float)vol / 1023);  // audio shield headphone out volume (optional)
    
    Serial.print("Volume: ");
    Serial.println(vol);

  }

  // read Flange control pot and change parameter if required
  if (flangeActive) {
    int reading1 = map(analogRead(pot1), 0, 1023, 1, 10);
    if ((reading1 / 10.0) != s_freq) {
      s_freq = reading1 / 10.0;
      Serial.print("New flange freq: ");
      Serial.println(s_freq);
      flange.voices(s_idx, s_depth, s_freq);
      
    }
       int reading2 = map(analogRead(pot2), 0, 1023, 1, 10);
    if ((reading2 / 1) != s_depth) {
      s_depth = reading2 / 1;
      Serial.print("New flange depth: ");
      Serial.println(s_depth);
      flange.voices(s_idx, s_depth, s_freq);
      
    }
  }
}
 
I removed your hardware control logic (pots etc), initialized the flanger to defaults, tested on a 4.0 and it does work as expected.

Are you sure you connected your (supposedly) mono signals to the correct input/output channel on the audio board?
 
I removed your hardware control logic (pots etc), initialized the flanger to defaults, tested on a 4.0 and it does work as expected.

Are you sure you connected your (supposedly) mono signals to the correct input/output channel on the audio board?

For the output I am using the female jack connector that comes with the audio shield, for the input I am using the audioinput i2s1 and I have connected it as shown in the attached image. Thank you very much for your answer.
IMAGE1.jpg
 
Ok so your input is mono on Left which is fine of course. Can't see from that image how you connected the output in the headphone jack though.

Just to further rule out L/R channel confusion you can add this one line to get the same output on both L/R channels:

AudioConnection patchCord3(flange, 0, AudioOutput, 1);

Then, unless you are sure that your audio board is working, check the solder joints between the 3.6 and the audio board as some of them look suspect.

After that, maybe check your hw control logic so that you are not repeatedly setting levels to 0 or something like that. Good luck!
 
Last edited:
Ok so your input is mono on Left which is fine of course. Can't see from that image how you connected the output in the headphone jack though.

Just to further rule out L/R channel confusion you can add this one line to get the same output on both L/R channels:

AudioConnection patchCord3(flange, 0, AudioOutput, 1);

Then, unless you are sure that your audio board is working, check the solder joints between the 3.6 and the audio board as some of them look suspect.

After that, maybe check your hw control logic so that you are not repeatedly setting levels to 0 or something like that. Good luck!

Thank you very much for your advice, the jack output I simply plug in some headphones. I will check soldering to make sure everything is OK.
 
Back
Top