Category: Sound

Toxi has posted a useful comment on the nature of FFTs over on the Processing forum. It should be of interest to those who have been looking at the SoniaHelper library.

[...] 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.

Toxi wrote the FFT code that is used in Sonia. You can download it here: http://www.toxi.co.uk/p5/fftDebug/.

No Comments »

Update: SoniaHelper should be renamed FFTHelper and integrated into unlekkerLib, but that hasn’t happened yet. The best way to use it right now is to download the code examples from the VJ workshop I did at Cimatics 2007. That has the code you need as well as some examples of practical usage.

I’ve put together a hack for normalizing the FFT analysis values produced by Sonia’s LiveInput.getSpectrum(). It looks at the maximum values produced, and scales them according to the most recent maximum values. That way, quiet sections will produce relative differences according to the current maximum value, so that both quiet and loud sections give dynamic results.

It also allows you to dampen the values so that the rate of change in values can be controlled. This can be used to make the values change appropriately according to the quality of the music, making it easier to use them for visuals that match the music.

Source code

You initialize SoniaHelper like this:

  // SoniaHelper(int _n, int _nbands,boolean doAvg)
  // Start up Sonia
  LiveInput.start(spectrumLength);

  // ...or start up Ess
  Ess.start(this);
   myChannel=new Channel("hello.aiff");
  myChannel.setupFFT(512);

  // init SoniaHelper
  ffthelper=new SoniaHelper(spectrumLength,32,false);
  ffthelper.setMaxLimits(200,2000);
  damperval=0.1f;
  ffthelper.setDamper(damperval); 

Update SoniaHelper inside draw() by passing spectral values from Sonia or Ess:

void draw() {
  ...
  LiveInput.getSpectrum();
  ffthelper.update(LiveInput.spectrum); 

// Ess equivalent
  myChannel.loadSpectrum();
  ffthelper.update(myChannel.spectrum);

  for(int i=0; i< spectrumLength; i++)
	ellipse(i,height/2,
		100*ffthelper.spectrum[i], 100*ffthelper.spectrum[i]);
  ...
}

See the sample code in the ZIP file for more code examples.

Downloads

10 Comments »