Hi all, first post. I hope it's not too much trouble! I'm relatively new to processing but enjoying it loads!
Currently, I'm working on a project looking at the relationship between sound and light. I'm using Ess to take information from my sound file and change the background colour based on the current pitch being played. I'm using the HSB colorMode with getLevel(). Although I think this is wrong. Does getLevel() just extract the sound level to an integer? What I'd like is to use the spectrum data to output an int or float. Does getSpectrum() output an array? Is there anyway to either use the largest figure in the array or to average out all the array figures to find a mean (average) int or float?
Here's my code if it helps:
Quote:
/*
* Audio Analysis to Background Colour
*
* Based on code from:
* Audio Analysis
* by R. Luke DuBois.
*
*/
import krister.Ess.*;
AudioChannel myChannel;
FFT myFFT;
void setup() {
size(400,400);
// start up Ess
Ess.start(this);
// load "test.aif" into a new AudioChannel
myChannel=new AudioChannel("test.aif");
// just want the level, so pass nothing
myFFT=new FFT(512);
// myFFT.smooth=true; // Not sure what this does. Leaving it for now.
// start the sound looping forever
myChannel.play(/*Ess.FOREVER*/);
}
void draw() {
// set the background color to a hue based on the level
int bgdColour=(int)(myFFT.getLevel(myChannel)*255);
myFFT.getSpectrum(myChannel);
colorMode(HSB, 50, 50, 50, 50);
background(0,0,0);
// Need to base saturation or brightness based on audio level
fill(bgdColour, 50, bgdColour*2, 50/4);
rect(0,0,width,height);
//println(bgdColour); // Print line for debug
frameRate(25);
}
// we are done, clean up Ess
public void stop() {
Ess.stop();
super.stop();
}