We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSound,  Music Libraries › Ess - spectrum data to an integer.
Page Index Toggle Pages: 1
Ess - spectrum data to an integer. (Read 574 times)
Ess - spectrum data to an integer.
May 23rd, 2008, 3:36pm
 
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();
}


Re: Ess - spectrum data to an integer.
Reply #1 - May 23rd, 2008, 6:55pm
 
I think Ess returns values between 0 and 1, so if you need integers, just multiply;

int myHue=getLevel(0)*255;
Re: Ess - spectrum data to an integer.
Reply #2 - May 23rd, 2008, 6:58pm
 
Thanks for the reply. What I'm trying to find out is whether getLevels() is to do with volume or to do with spectrum/pitch?

Thanks
Page Index Toggle Pages: 1