I am still a beginner with code and I was hoping to get some help in changing original image to show when there is a loud noise, and the filtered image show when it is quiet. I wasn't really shown how to complete this in my past class and want to learn how to edit it so I know how to in the future. My past teacher didn't really teach it to well.
Here is code I have so far:
// libraries
import processing.sound.*;
// global variables
Amplitude amp; // audio amplifier
AudioIn in; // audio input
PImage original; // original image
PImage filtered; // image that will receive filtering
float volume = 0;
void setup() {
size(740, 920); //was 640, 360
background(0, 255, 255);
// Create an Input stream which is routed into the Amplitude analyzer
amp = new Amplitude(this);
// set the input the mic channel 0
in = new AudioIn(this, 0);
// turn on the mic
in.start();
// feed the mic data to the amp
amp.input(in);
// give image files to the image variables
original = loadImage("Musical Note.png");
filtered = loadImage("Musical Note.png");
}
void draw() {
//Draw normal
if (mousePressed && (mouseButton == LEFT)) {
ellipse(mouseX, mouseY, 40, 40);
fill(random(255), random(255), random(255));
noStroke();
//erases
} else if (mousePressed && (mouseButton == RIGHT)) {
ellipse(mouseX, mouseY, 40, 40);
fill(0, 255, 255);
noStroke();
}
float volume = amp.analyze();
if (volume > 0.5) { // check if volume is above threshold
image(original, 0, 0); // display original image
} else {
// YOUR FILTER CODE GOES HERE
image(filtered, 0, 0); // display filtered image
PImage img;
img = loadImage("Musical Note.png");
image(img, 0, 0);
image(filtered, 0, 0); // display filtered image
}
}