Welcome, Guest
Username: Password: Remember me

TOPIC: Reverb Guitar Effect Pedal.

Reverb Guitar Effect Pedal. 4 months 1 week ago #873

The reverb effect simulates the sound that results from reflections from surrounding walls in a room. To simulate it the guitar signal is delayed several times with different timings, simulating the reflections on the walls.

reverb.gif


In this particular effect 3 different delay buffers are used with different timings, the delay time is quite short to give a more realistic impression.
The code is 95% similar to the echo code, but instead of using 1 echo buffer we use 3.

How to control it:
  • Push-Button 1 (left): Make the delay time shorter (smaller room).
  • Push-Button 2 (right): Make the delay time longer (bigger room)..
  • Led: ON when the effect is activated
  • Toggle Button: not used.
  • Foot-Switch: activate/deactivate the effect.

This code admits plenty of variations, you can change the default delay values (and make them smaller or bigger):
uint32_t Delay_Depth1 = 10000; //default starting delay is 100000 is 0.5 sec approx.
uint32_t Delay_Depth2 = 5000; //default starting delay is 100000 is 0.25 sec approx.
uint32_t Delay_Depth3 = 2500; //default starting delay is 100000 is 0.125 sec approx.


You can also play changing the amount of delay added or subtracted when pushing the buttons, making them bigger smaller or different between them:
if (Delay_Depth1<DELAY_MAX)Delay_Depth1=Delay_Depth1+5000; //50000 adds 25ms approx.
if (Delay_Depth2<DELAY_MAX)Delay_Depth2=Delay_Depth2+5000; //50000 adds 25ms approx.
if (Delay_Depth3<DELAY_MAX)Delay_Depth2=Delay_Depth2+5000; //50000 adds 25ms approx.


This is the complete code:

// CC-by-www.Electrosmash.com Pedal-Pi open-source project.
// reverb audio effect.
 
#include <stdio.h>
#include <bcm2835.h>

// Define Input Pins
#define PUSH1 			RPI_GPIO_P1_08  	//GPIO14
#define PUSH2 			RPI_V2_GPIO_P1_38  	//GPIO20 
#define TOGGLE_SWITCH 	RPI_V2_GPIO_P1_32 	//GPIO12
#define FOOT_SWITCH 	RPI_GPIO_P1_10 		//GPIO15
#define LED   			RPI_V2_GPIO_P1_36 	//GPIO16

//Define Delay Effect parameters MAX_DELAY 800000 is 4 seconds approx.
#define DELAY_MAX 800000
#define DELAY_MIN 0

uint32_t Echo_Buffer1[DELAY_MAX];
uint32_t Echo_Buffer2[DELAY_MAX];
uint32_t Echo_Buffer3[DELAY_MAX];
uint32_t DelayCounter1 = 0;
uint32_t DelayCounter2 = 0;
uint32_t DelayCounter3 = 0;
uint32_t Delay_Depth1 = 10000; //default starting delay is 100000 is 0.5 sec approx.
uint32_t Delay_Depth2 = 5000; //default starting delay is 100000 is 0.25 sec approx.
uint32_t Delay_Depth3 = 2500; //default starting delay is 100000 is 0.125 sec approx.
 
uint32_t input_signal=0;
uint32_t output_signal=0;
uint32_t read_timer;
 
uint8_t FOOT_SWITCH_val;
uint8_t TOGGLE_SWITCH_val;
uint8_t PUSH1_val;
uint8_t PUSH2_val;
 
int main(int argc, char** argv) {
    // Start the BCM2835 Library to access GPIO.
    if (!bcm2835_init())
    {printf("bcm2835_init failed. Are you running as root??\n");
      return 1;}
	// Start the SPI BUS.
	if (!bcm2835_spi_begin())
    {printf("bcm2835_spi_begin failed. Are you running as root??\n");
      return 1;}
 
		//define PWM	
    bcm2835_gpio_fsel(18,BCM2835_GPIO_FSEL_ALT5 ); //PWM0 signal on GPIO18    
    bcm2835_gpio_fsel(13,BCM2835_GPIO_FSEL_ALT0 ); //PWM1 signal on GPIO13    
	bcm2835_pwm_set_clock(2); // Max clk frequency (19.2MHz/2 = 9.6MHz)
    bcm2835_pwm_set_mode(0,1 , 1); //channel 0, markspace mode, PWM enabled. 
	bcm2835_pwm_set_range(0,64);   //channel 0, 64 is max range (6bits): 9.6MHz/64=150KHz switching PWM freq.
    bcm2835_pwm_set_mode(1, 1, 1); //channel 1, markspace mode, PWM enabled.
	bcm2835_pwm_set_range(1,64);   //channel 0, 64 is max range (6bits): 9.6MHz/64=150KHz switching PWM freq.
 
	//define SPI bus configuration
    bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST);      // The default
    bcm2835_spi_setDataMode(BCM2835_SPI_MODE0);                   // The default
    bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_64); 	  // 4MHz clock with _64 
    bcm2835_spi_chipSelect(BCM2835_SPI_CS0);                      // The default
    bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW);      // the default
 
   	uint8_t mosi[10] = { 0x01, 0x00, 0x00 }; //12 bit ADC read 0x08 ch0, - 0c for ch1 
	uint8_t miso[10] = { 0 };
 
    //Define GPIO pins configuration
    bcm2835_gpio_fsel(PUSH1, BCM2835_GPIO_FSEL_INPT); 			//PUSH1 button as input
	bcm2835_gpio_fsel(PUSH2, BCM2835_GPIO_FSEL_INPT); 			//PUSH2 button as input
	bcm2835_gpio_fsel(TOGGLE_SWITCH, BCM2835_GPIO_FSEL_INPT);	//TOGGLE_SWITCH as input
	bcm2835_gpio_fsel(FOOT_SWITCH, BCM2835_GPIO_FSEL_INPT); 	//FOOT_SWITCH as input
	bcm2835_gpio_fsel(LED, BCM2835_GPIO_FSEL_OUTP);				//LED as output
 
    bcm2835_gpio_set_pud(PUSH1, BCM2835_GPIO_PUD_UP);           //PUSH1 pull-up enabled   
	bcm2835_gpio_set_pud(PUSH2, BCM2835_GPIO_PUD_UP);           //PUSH2 pull-up enabled 
	bcm2835_gpio_set_pud(TOGGLE_SWITCH, BCM2835_GPIO_PUD_UP);   //TOGGLE_SWITCH pull-up enabled 
	bcm2835_gpio_set_pud(FOOT_SWITCH, BCM2835_GPIO_PUD_UP);     //FOOT_SWITCH pull-up enabled 
 
 
 while(1) //Main Loop
 {
	//read 12 bits ADC
    bcm2835_spi_transfernb(mosi, miso, 3);
    input_signal = miso[2] + ((miso[1] & 0x0F) << 8); 
 
	//Read the PUSH buttons every 50000 times (0.25s) to save resources.
	read_timer++;
	if (read_timer==50000)
	{
	read_timer=0;
	PUSH1_val = bcm2835_gpio_lev(PUSH1);
	PUSH2_val = bcm2835_gpio_lev(PUSH2);
    TOGGLE_SWITCH_val = bcm2835_gpio_lev(TOGGLE_SWITCH);
	FOOT_SWITCH_val = bcm2835_gpio_lev(FOOT_SWITCH);
	//light the effect when the footswitch is activated.
	bcm2835_gpio_write(LED,!FOOT_SWITCH_val); 
 
	//update volume variable when the PUSH buttons are pushed.
	if (PUSH2_val==0)
		{   bcm2835_delay(100); //100ms delay for buttons debouncing. 
			if (Delay_Depth1<DELAY_MAX)Delay_Depth1=Delay_Depth1+5000; //50000 adds 25ms approx.
			if (Delay_Depth2<DELAY_MAX)Delay_Depth2=Delay_Depth2+5000; //50000 adds 25ms approx.
			if (Delay_Depth3<DELAY_MAX)Delay_Depth2=Delay_Depth2+5000; //50000 adds 25ms approx.
		}
           if (PUSH1_val==0) 
			{ 	
			    bcm2835_delay(100); //100ms delay for buttons debouncing. 
				if (Delay_Depth1>DELAY_MIN)Delay_Depth1=Delay_Depth1-5000;
				if (Delay_Depth2<DELAY_MAX)Delay_Depth2=Delay_Depth2+5000; //50000 adds 25ms approx.
				if (Delay_Depth3<DELAY_MAX)Delay_Depth3=Delay_Depth3+5000; //50000 adds 25ms approx.
			}
 
	}
 
	//**** REVERB EFFECT ***///
	//The echo effect is very similar to the echo, but with 3 Echo_Buffers instead of 1 (Echo_Buffer1/2/3)
 
 
	//Store current readings  
	//the ">>1" makes the echo to decay, if you want a faster decay change it for ">>2" or ">>3" 
 
        Echo_Buffer1[DelayCounter1]  = (input_signal + Echo_Buffer1[DelayCounter1])>>1;
	Echo_Buffer2[DelayCounter2]  = (input_signal + Echo_Buffer2[DelayCounter2])>>1;
	Echo_Buffer3[DelayCounter3]  = (input_signal + Echo_Buffer3[DelayCounter3])>>1;
 
    DelayCounter1++;	
	if(DelayCounter1 >= Delay_Depth1) DelayCounter1 = 0; 
 
	DelayCounter2++;	
	if(DelayCounter2 >= Delay_Depth2) DelayCounter2 = 0; 
 
	DelayCounter3++;	
	if(DelayCounter3 >= Delay_Depth3) DelayCounter3 = 0; 
 
output_signal=(input_signal + (Echo_Buffer1[DelayCounter1])+(Echo_Buffer2[DelayCounter2])+(Echo_Buffer3[DelayCounter3]))>>2;
 
    //generate output PWM signal 6 bits
    bcm2835_pwm_set_data(1,output_signal & 0x3F);
    bcm2835_pwm_set_data(0,output_signal >> 6);
 
 }
 	//close all and exit
	bcm2835_spi_end();
    bcm2835_close();
    return 0;
}
 

File Attachment:

File Name: reverb.zip
File Size: 2 KB
Last Edit: 3 months 6 days ago by ElectroSmash_Team.
The administrator has disabled public write access.
Time to create page: 0.337 seconds
Powered by Kunena Forum
Joomla SEF URLs by Artio