I am working on a project in Processing 3 where visuals are modulated by the amplitude of a song. However, I want to take it further. I would like to be able to play any song, or even have a band play in a mic'd room, and have my visuals respond while its playing. Right now, I have to tell the computer what song to use from the Sketch Folder but obviously that is not what I want to do.
The end goal is to project my visuals onto a wall in a club setting. To avoid picking up the crowd noise, I thought it would make sense to send the signal from the DJ booth to the computer(probably using an audio interface). I don't know if thats necessarily important for writing the code, but that is where my head is at. (Ik this might be a bit different from programming the aforementioned band idea...)
Anyway, if anyone has any good examples or information on how to do this, it would be greatly appreciated. I have attached a screenshot of my code right now. Eventually, I'll make the visuals more complex, but you get the point.
import processing.sound.*;
SoundFile sample;
Amplitude rms;
float smoothingFactor = 0.06;
float sum;
float x, y;
float xStep = 40;
float yStep = 200;
float a, a_;
int num = 400;
void setup(){
size(1400,1000);
sample = new SoundFile(this, "prettylights.mp3"); //to run code, load an audio file here
sample.loop();
rms = new Amplitude(this);
rms.input(sample);
}
void draw(){
background(20,20,30);
strokeCap(CORNER);
strokeWeight(xStep);
sum += (rms.analyze() - sum) * smoothingFactor;
float rms_scaled = sum * (height/2) * 3;
int n=0;
while (n<num) {
stroke(255-255*cos(radians(a)),25,25,230-255*sin(radians(a)));
line(x, y, x, y+yStep);
//line(x, y,rms_scaled, rms_scaled);
x+=xStep;
if (x>width){
x=xStep/2;
y+=yStep;
}
if (y>=height){
y=0;
a=rms_scaled;
//a=0;
}
n++;
a+=a_;
}
a_+=0.1;
}
I figured it out! I just needed to use the AudioIn class.