Echo effect - Sound coding

Good morning dear processing users,

sorry to bother you guys, but I am writing to ask for some help related to my project - visualising the sound input from microphone and having the echo delayed effect back from the speaker(of the computer)

But I dont know why there is this noise keep coming out from it, and I sincerely appreciate if someone can give me a hand to fix this - I actually just want a clean echo back from the speaker - it would be nice to have multiple times of this echo tho!

Thank you in advance.

import processing.sound.*;
 
SoundFile soundFile;  
AudioIn in;  
Amplitude amp;
Delay delay;

float lucency = 0;
float ampvalue = 0; 
String path = "";
 
void setup()
{
  //initialize
  size(1300,700);
  surface.setResizable(true);
  pixelDensity(displayDensity());
  
  // load audio file
  soundFile = new SoundFile(this,path);
  // create a delay effect
  delay = new Delay(this);

  // start the input stream
  in = new AudioIn(this,0);
  amp = new Amplitude(this);

  // Patch the delay
  delay.process(in, 0.1);
  // delay layer
  delay.time(0.1); // parameter: delayed time
  delay.time(0.2);
  delay.time(0.3);
  delay.time(0.4);
  delay.time(0.5);
  delay.time(0.25);
  // 
  in.start();
  amp.input(in);
  
  // play the sound file and audio input
  in.play(0.3); // this parameter is the volume

}
 
int lastm = 0;
void draw()
{
  background(#FFFFFF);
  noStroke();
 
  int m = millis();
  if(m/60>lastm)
  {
    ampvalue = amp.analyze();
    lastm = m/60;
  }
  println("millis:"+m);
  println(ampvalue); 
  drawOutsideCircle(ampvalue);
  fill(255);
  ellipse(600,350,400,400);
  noFill();
  fill(0);
  ellipse(600,350,380,380);
  noFill();
  
  drawInsideCircle(ampvalue);
  fill(255);
  ellipse(600,350,50,50);
  noFill();
 
  textSize(32);
  fill(255);
  text(path,30,40);
  noFill();
}
void drawOutsideCircle(float ampvalue)
{
  int wid = 500;
  lucency = ampvalue*10000;
  fill(169,169,169,lucency);
  ellipse(600,350,wid,wid);
  noFill();
  //倒影
  fill(169,169,169,lucency/5);
  ellipse(600,650,wid,wid/10);
  noFill();
}
void drawInsideCircle(float ampvalue)
{
  float wid = 300;
  wid = wid*ampvalue*100 + wid;
  if(wid>680)
  wid = 600;
  fill(50,50,50);
  ellipse(600,350, wid,wid);
  noFill();
  fill(5,0,0,162);
  ellipse(600,650, wid,wid/10);
  noFill();
  
  strokeWeight(5);
  stroke(0);
  ellipse(600,350, 200,200);
  ellipse(600,350, 300,300);
  noStroke();
  
}
1 Like

hi,
could you please format your code?
in the editor header menu is a
</> code button
to paste the code in.
thank you.


for a
microphone – sound card – computer – sound card – speaker

there is a high probability you have a feed back loop
test if that noise reduces when you

  • cover the microphone
  • increase the distance micro - - speaker

but if your code would work,

  • not play the recording directly,
  • only the delay sound

THIS should not happen.

could you try the pure sound lib example first ?

import processing.sound.*;
AudioIn in;
Delay delay;

void setup() {
  in = new AudioIn(this, 0);
  delay = new Delay(this);
  in.play();
  delay.process(in, 5);
  delay.time(0.5);
}      

void draw() {}

3 Likes

thank you very much!!!

I sincerely appreciate this!

import processing.sound.*;
 
SoundFile soundFile;  
AudioIn in;  
Amplitude amp;
Delay delay;

float lucency = 0;
float ampvalue = 0; 
String path = "";
 
void setup()
{
  //initialize
  size(1300,700);
  surface.setResizable(true);
  pixelDensity(displayDensity());
  
  // load audio file
  soundFile = new SoundFile(this,path);
  // create a delay effect
  delay = new Delay(this);

  // start the input stream
  in = new AudioIn(this,0);
  amp = new Amplitude(this);

  // Patch the delay
  delay.process(in, 0.1);
  // delay layer
  delay.time(0.1); // parameter: delayed time
  delay.time(0.2);
  delay.time(0.3);
  delay.time(0.4);
  delay.time(0.5);
  delay.time(0.25);
  // 
  in.start();
  amp.input(in);
  
  // play the sound file and audio input
  in.play(0.3); // this parameter is the volume

}
 
int lastm = 0;
void draw()
{
  background(#FFFFFF);
  noStroke();
 
  int m = millis();
  if(m/60>lastm)
  {
    ampvalue = amp.analyze();
    lastm = m/60;
  }
  println("millis:"+m);
  println(ampvalue); 
  drawOutsideCircle(ampvalue);
  fill(255);
  ellipse(600,350,400,400);
  noFill();
  fill(0);
  ellipse(600,350,380,380);
  noFill();
  
  drawInsideCircle(ampvalue);
  fill(255);
  ellipse(600,350,50,50);
  noFill();
 
  textSize(32);
  fill(255);
  text(path,30,40);
  noFill();
}
void drawOutsideCircle(float ampvalue)
{
  int wid = 500;
  lucency = ampvalue*10000;
  fill(169,169,169,lucency);
  ellipse(600,350,wid,wid);
  noFill();
  //倒影
  fill(169,169,169,lucency/5);
  ellipse(600,650,wid,wid/10);
  noFill();
}
void drawInsideCircle(float ampvalue)
{
  float wid = 300;
  wid = wid*ampvalue*100 + wid;
  if(wid>680)
  wid = 600;
  fill(50,50,50);
  ellipse(600,350, wid,wid);
  noFill();
  fill(5,0,0,162);
  ellipse(600,650, wid,wid/10);
  noFill();
  
  strokeWeight(5);
  stroke(0);
  ellipse(600,350, 200,200);
  ellipse(600,350, 300,300);
  noStroke();
  
}
1 Like