Project in progress
echoTrek - Digital Delay / Echo - Audio Effects with Arduino

echoTrek - Digital Delay / Echo - Audio Effects with Arduino © GPL3+

8Bit Digital Delay / LO-FI Bitcrusher / Reverse Speech DSP Pedal Effects for Guitar, Voice, Synths, etc.

  • 9,055 views
  • 15 comments
  • 31 respects

Components and supplies

Apps and online services

About this project

Tired of flashing LEDs and writing "Hello World" with Arduino? So let's go to something different ...

Since I started using Arduino in my projects, I have always been curious to use it in audio applications, because despite its limitations it has analog-to-digital and digital-to-analog converters, which allow you to do many interesting things in the field of audio.

During the end of last year I decided to put this into practice and wrote a code for the Arduino to be used as an effects module like Digital Delay, Echo, Bitcrusher LO-FI and Speech Reverse. So, here's the project.

In operation video:

Features:

  • Digital Delay with 6 selectable delay times (63 to 300ms).
  • Effect that freezes the sound.
  • Reverse Speech.
  • 8 Bit LO-FI with the authentic retro sound of the 80's games.
  • Effects in real time.
  • Use an Arduino Nano (or UNO).
  • Simple, easy to assemble and inexpensive.

Picture of setup:

How it works:

The operation is analogous to the bucket brigade (BBD) principle used by the famous MN3005 integrated circuit, used in the classic analog pedals of the 70s and 80s.

The audio signal coming from a source, such as a tablet, cell phone, mp3 player, keyboard, mixer, guitar amplifier, etc. goes to the input of circuit and filtered by a capacitor and then applied to the analog pin A0 - 10Bit A/D converter, where it is sampled and converted to bytes (values ​​from 0 to 255). These bytes ​​are stored in Arduino's SRAM memory, through a 1900 bytes buffer (array), which forms a delay line for the original signal.

When this buffer is full, the first byte that entered (and the subsequent bytes) that are stored in the buffer are sent to the 8Bit D/A converter. The 8Bit D/A outputs the audio as PWM that is retrieved at pin D5 of the Arduino where is filtered by a capacitor and the reconstructed audio is ready to go to the output of circuit.

To improve the audio quality, I set the PWM frequency to ~64kHz and Timer 1 to ~16kHz, so we have a pratical sampling rate of ~6.3kHz.

A part of the output signal is applied to the input, creating a feedback, which is responsible for the echo repetitions. The output audio signal must be sent to the line input of an audio amplifier to be heard.

The Arduino status LED lights up to indicate when the push button is pressed and the TX LED lights up to indicate it is in reverse speech mode.

Schematics / Wiring:

Instructions:

  • Open the sketch in the Arduino IDE, connect the Arduino, set the correct port.
  • Compile the sketch and send it to Arduino.
  • Make the circuit assembly following the schematic diagram to make the electrical connections.

Operation:

  • Power the Arduino through the USB port or through a 7 to 9v battery connected to the vin pin.
  • Connect the audio source to the audio input and the output to an audio amplifier, which can be a PC sound amplifier.
  • Press to turn on switches SW2 and SW3.
  • Press the S1 push button sequentially to select the 6 delay times plus the Reverse Speech mode. The delay time values ​​available are: 63ms, 110ms, 158ms, 205ms, 253ms, 300ms and Reverse Speech. The Arduino status LED lights up to indicate when the push button is pressed and the TX LED lights up to indicate it is in reverse speech mode.
  • Press to turn off the SW3 switch to freeze the sound. Then press it again to return.
  • Press to turn off switch SW2 to cut the feedback, that way we will only have the processed signal (wet) to obtain the LO-FI sound of 8Bit, Bitcrusher and reverse speech.

By J. CesarSound - ver 1.0 - Jan / 2021.

Code

8Bit Digital Delay sketchC/C++
Load it to arduino in order to do it work
/*****************************************************************************************************************************
  echoTrek - 8Bit Digital Delay / LO-FI Bitcrusher / Reverse Speech DSP Pedal Effects for Guitar, Voice, Synths, etc.
  Works with Arduino UNO R3 / NANO / PRO MINI - See the schematics for wiring details. By J. CesarSound - ver 1.0 - Jan/2021.
******************************************************************************************************************************/

#define audio_in A0
#define time_selector A3

const unsigned int d_size = 1900; //Delay memory buffer size
unsigned int val, d_val, d_time;
int i, j;
byte count = 2;
bool rev = 0;
char delay_data[d_size + 1] = { NULL };  //Delay memory buffer
char delay_data_1[d_size + 1] = { NULL };  //Delay memory buffer
 

void setup() {
  pinMode(time_selector, INPUT_PULLUP);
  DDRD = B00000010;
  DDRB = B11100000;
  InitTimer1();           //Set up timer 1 for 16.384kHz
  setPwmFrequency(5, 1);  //function for setting PWM High frequency 62.475kHz on pin D5
  analogReference(INTERNAL);   //Use 1.1v aref voltage.
  up_time();
}

void loop() {
  if (digitalRead(time_selector) == LOW) {
    up_time();
    PORTB = B11100000;   //make pin 13 high and power on the led when pushbutton is pressed
    while (digitalRead(time_selector) == LOW);
  } else PORTB = B11000000;   //make pin 13 low and power off the led pushbutton is released
  if (rev) PORTD = B00000000; else PORTD = B00000010;   //Reverse speech sampler indication TX Led power on
}

void sampling() {
  val = map(analogRead(audio_in), 0, 900, 0, 255);
  delay_sound();
  analogWrite(5, d_val);
}

void delay_sound() {
  i = i + 1; if (i > d_time) i = 0;
  delay_data[i] = val;
  if (i == d_time) j = 0;
  delay_data_1[i] = delay_data[i];
  j = j + 1; if (j > d_time) j = 0;
  if (!rev) d_val = delay_data_1[j];
  if (rev) d_val = delay_data_1[d_time - j];
}

void up_time() {
  noInterrupts();
  count++;
  if (count > 7)
    count = 1;
  delay(20);

  switch (count)  {
    case 1:
      d_time = 400; rev = 0; //63ms
      break;
    case 2:
      d_time = 700; //110ms
      break;
    case 3:
      d_time = 1000; //158ms
      break;
    case 4:
      d_time = 1300; //205ms
      break;
    case 5:
      d_time = 1600; //253ms
      break;
    case 6:
      d_time = 1900; //300ms
      break;
    case 7:
      d_time = 1500; rev = 1; //Reverse speech
      break;
  } interrupts();
}

//Set up timer 1 for 16.384kHz (975)
void InitTimer1() {
  cli(); //Disable global interrupts
  TCCR1A = 0; //Reset Timer 1 Counter Control Register A
  TCCR1B = 0; //Reset Timer 1 Counter Control Register B
  TCNT1  = 0; //initialize counter value to 0
  OCR1A = 975; //Set Timer 1 to desired frequency: 16384Hz (16,000,000 / 16384) - 1 = 975
  //Turn on CTC (clear timer on compare match) mode:
  TCCR1B |= (1 << WGM12);
  TCCR1B |= (1 << CS10); //CS10 Prescalar = 1 (no prescalar used); CS11 Prescalar = 8
  TIMSK1 |= (1 << OCIE1A); //Enable timer interrupt
  sei(); //Enable interrupts
}

ISR(TIMER1_COMPA_vect) {
  sampling();
}

//PWM 62.475kHz high frequency DAC for pins 5 & 6 (others are 32k)
void setPwmFrequency(int pin, int divisor) {
  byte mode;
  if (pin == 5 || pin == 6 || pin == 9 || pin == 10) {
    switch (divisor) {
      case 1: mode = 0x01; break;
      case 8: mode = 0x02; break;
      case 64: mode = 0x03; break;
      case 256: mode = 0x04; break;
      case 1024: mode = 0x05; break;
      default: return;
    }
    if (pin == 5 || pin == 6) {
      TCCR0B = TCCR0B & 0b11111000 | mode;
    } else {
      TCCR1B = TCCR1B & 0b11111000 | mode;
    }
  } else if (pin == 3 || pin == 11) {
    switch (divisor) {
      case 1: mode = 0x01; break;
      case 8: mode = 0x02; break;
      case 32: mode = 0x03; break;
      case 64: mode = 0x04; break;
      case 128: mode = 0x05; break;
      case 256: mode = 0x06; break;
      case 1024: mode = 0x07; break;
      default: return;
    }
    TCCR2B = TCCR2B & 0b11111000 | mode;
  }
}

Schematics

Schematics wiring
To wire the parts

Comments

Similar projects you might like

Arduino MIDI Poly Synth - MiniSy (Musical Instrument)

Project in progress by CesarSound

  • 7,079 views
  • 6 comments
  • 18 respects

2 x 16-Band Audio Spectrum Analyzer with LCD

by shajeeb and ThomAce

  • 11,849 views
  • 3 comments
  • 12 respects

RGB 32-Band Audio Spectrum Visualizer

Project tutorial by janux

  • 10,610 views
  • 5 comments
  • 9 respects

FHT Audio Spectrum Visualizer

Project tutorial by janux

  • 7,175 views
  • 25 comments
  • 11 respects

32-Band Audio Spectrum Visualizer Analyzer

Project showcase by shajeeb

  • 118,415 views
  • 168 comments
  • 256 respects

DIY Audio Signal Spectrum Analyzer

Project tutorial by Mirko Pavleski

  • 6,431 views
  • 1 comment
  • 10 respects
Add projectSign up / Login