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 spectral analysis speed
Page Index Toggle Pages: 1
Ess spectral analysis speed (Read 2048 times)
Ess spectral analysis speed
May 15th, 2006, 9:34pm
 
hi all

i want to do some simple lip syncing animation with processing, just volumes of samples in realtime controlling the size of a shape(mouth). I have the code below which analyses the level of one frequency band and varies the height of a rect.

the problem is that it updates the value too quickly and I don't want to slow down the framerate of the sketch. short of monitoring the system clock to decide when to redraw the shape is there perhaps a convenient way to set the resolution of this info in ess? i don't want to change the sample rate as i want the sound to remain intact

any advice greatly appreciated.

////////////////////////////////////////////

import krister.Ess.*;
Channel voice1;

void setup() {
 // start up Ess:
 Ess.start(this);
 
 // set up sound:
 voice1=new Channel("sample.wav");
 voice1.normalize();
 voice1.setupFFT(2);//1 frequency band is average amplitude

}

void draw() {
 background(255);
 drawMouth();
}

void drawMouth() {
 // get amplitude:
 voice1.loadSpectrum();
 float temp=voice1.spectrum[0]*10;
 // draw amplitude:
 noStroke();
 fill(0);
 rect(25,50,50,temp+.5);
 
}

// click plays once:
void mousePressed() {
 if (voice1.state!=Ess.PLAYING) {
   voice1.play(1);
 }
}

// clean up Ess before exiting:
public void stop() {
 Ess.stop();
 super.stop();
}
Re: Ess spectral analysis speed
Reply #1 - May 15th, 2006, 10:10pm
 
Hi Nay, you'll be pleased to know I have just the thing for you. I had the same issue with Sonia when creating a visual performance recently, so I created a library called (for now) SoniaHelper.

It lets you dampen the values to slow them down, but more importantly it also keeps your values normalized (i.e. between 0 and 1) so that they are easy to use for visuals. SoniaHelper tracks the current maximum spectral values and scales your results accordingly, so that quiet sections will still have dynamic output and loud sections will be scaled down to a manageable level.

Have a look here: SoniaHelper 0.1. There are sample files included in the ZIP.

I'm talking to Amit about integrating this code into Sonia, we'll see how that goes. For now the Java source is in the ZIP file.
Re: Ess spectral analysis speed
Reply #2 - May 16th, 2006, 10:39pm
 
thanks watz, works perfectly except that i can't get it to work with just one frequency band, which is all i need

if i initialise both ess (or sonia) and soniahelper with one freq band i still get an array out of bounds exception at
ffthelper.update(myChannel.spectrum);

is there a way around this apart from something silly like:
float[] array = new float[256];
 array[0] = myChannel.spectrum[0];
 ffthelper.update(array);
//then just use ffthelper.spectrum[0]

Re: Ess spectral analysis speed
Reply #3 - May 16th, 2006, 11:05pm
 
You mean that you want it to look only at one specific band and ignore all the others? A single band is rarely precise in representing a sound, unless your sound is extremely synthetic.

The code currently does not support looking at limited areas of the FFT. It wouldn't be hard to add. But in my experience it is good to use the global maximum values to scale the FFT, since that most closely mirrors how the listeners experiences changes in the sound. At one point I had an option for letting local bands have local maxima, but it made them scale in a way that was not consistent with the total sound.
Re: Ess spectral analysis speed
Reply #4 - May 17th, 2006, 12:23pm
 
Few comments and questions about the single band issue...

What's the reason for you using only a single frequency band Saying a "single" band is pretty meaningless without telling us any desired width of this band Even if you're thinking of analyzing only the range of formants of human voices you can work with ONE frequency band, but please don't mix this up with the spectrum bins returned by the FFT... In most cases speaking about a band of frequencies will refer to a whole collection of bins. Escpecially if you want to target/analyze the behaviour of a specific frequency bin, you'll need as many bins as possible to start with. In theory a spectrum of only one bin would cover the whole frequency range 0 Hz < f < 1/2 the sampling freq...

Since the FFT is attempting to break down the signal into a series of sinoids, at least 2 samples are required in order to work out the contributing frequencies of this signal (It's mathematically impossible to do it with one only).

Running danger of becoming too mathematical, the number of frequency bins required directly relates to the number of samples analyzed. In other words, the fewer bins you want in your spectrum the shorter (in time) the chunk of signal analyzed and so the poorer the quality/precision of the computed spectrum as well. For most applications a spectrum of anything under 128 bins will be pretty unusable since the related time window is too short (<3ms) and you might be better off just working with the average volume of the samples by using Ess's equivalent of Sonia's LiveInput.getLevel() method.
Re: Ess spectral analysis speed
Reply #5 - May 17th, 2006, 8:59pm
 
thanks for all the feedback - sorry i didn't give enough detail. getLevel() is all i need. the reason that i went the roundabout way of using one freq band as wide as the entire spectrum (i hope thats what i did by intialising ess to 2 bands) was because i didn't find a getlevel equivalent in ess. i would prefer to use ess so that people don't need to install the jsyn plugin to run the sketch and i won't be doing more complex audio stuff in these sketches anyway (educational games). but even if i do use sonias getlevel i am back to the same problem of needing to dampen the data.
Re: Ess spectral analysis speed
Reply #6 - May 18th, 2006, 2:43pm
 
Thank you for the clarification, Toxi, I have to admit I am a bit hazy on the science myself. I took the liberty of blogging your post over on code & form, hope you don't mind.
Re: Ess spectral analysis speed
Reply #7 - May 19th, 2006, 2:07am
 
Hi, I am working on something using spectral as well, i knew toxi have written some code, could you post some here, cause i visit the web www.toxi.co.uk, the example code seem not working there, thanks. And do i need to do our graphic? or i can have other people graphic code?
Re: Ess spectral analysis speed
Reply #8 - May 19th, 2006, 12:32pm
 
Krushxy, not sure what you are trying to do, posting code might help. Toxi's FFT code does work if you pass it some appropriate data.
Re: Ess spectral analysis speed
Reply #9 - May 19th, 2006, 3:31pm
 
hi watz, what i want to do is something like Unlekker video. http://www.unlekker.net/proj/cronica021/index.html, he said he got some FFT code from toxi, and i didn't know where do i have to start first, if i would make something like that. Thanks if ya can gimme a hand.
Re: Ess spectral analysis speed
Reply #10 - May 19th, 2006, 7:36pm
 
Well, the person who made that video was me, and the code I used was the one from Toxi: http://www.toxi.co.uk/p5/fftDebug/. I used the javax.sound.sampled.* API to get sound samples from an AIFF sound file and feed it through the FFT code.

It's not too hard if you know what you're doing, but I think it would be easier to use Ess and load MP3s for analysis.
Page Index Toggle Pages: 1