Hi Guys!

**Goal**

I'm making audio reactive visuals. I want to isolate specific frequencies and assign different animations to them. Not sure if relevant, the music for my first project is drum n bass, but I'm interested in creating visuals using various types of beat heavy electronic music, think Autechre, Apparat, Minimal Techno etc.

**Process**

I looked into Beads (read the great "Sonifying Processing" Tutorial) and using getFeatures() - but wasn't able to get the results I was looking for.

I looked into Minim - Beat Detect in Frequency Energy mode wasn't specific & exact enough for me. I spent the entire Easter Weekend searching for information and looking at other's sketches. I learnt about
Averages and more specifically
Logarithmic Averages. Splitting the spectrum into bands makes sense to me. Using this method I arrived at slightly more pleasing results.

I see
amnon.owed says on
this thread that accurate audio detection is pretty hard. >.<

**Result**

I have a sketch using ddf's suggested method as specified in the above link, and am currently using 12 bands. I am using calcAvg() and "if" statements to access the indexes of the frequencies. (I'm using 2 "ranges" at the moment for this exercise)

**A:**Am I going about this the right way? Just because it's kinda working, doesn't leave me convinced that my code is optimised for the best way forward. Are "if" statements on the indexes the "right" way to do this?

**B:**To gain access to more frequencies, I just work with more bands right? I am not blown away with the accuracy of audio - reactiveness but probably need to work on it a bit more.

**C:**I found on the interwebs this sketch that is pretty damn accurate. But it looks so complicated! I don't know if I should try to pick apart & understand the code, and I don't know how to credit this guy, have no idea how I even came across this, would I just add a link to his website at the top of the sketch? Lol.

So what I'm ultimately asking is, how can I make this sketch super audio reactive. I'm looking for Trapcode Form level of accuracy. It would be awesome to create a template that I can share, because I really struggled to find a simplified #noob-level stripped down sketch that does what I want it to!

(I've removed most of my comments but left a few in, might help someone). Also I'm loading a .wav, if anyone copies this, just replace "tricky.wav" with "songname.wav" or "songname.mp3"

Thanks in advance!!!

- import ddf.minim.*;
- import ddf.minim.analysis.*;
- Minim minim;
- AudioPlayer song;
- FFT fft;
- int sampleRate = 44100;
- int timeSize = 1024;
- void setup() {
- size(500, 500);
- smooth();
- minim = new Minim(this);
- song = minim.loadFile("tricky.wav", 2048);
- song.loop();
- fft = new FFT( song.bufferSize(), song.sampleRate() ); // make a new fft
- // calculate averages based on a miminum octave width of 11 Hz
- // split each octave into 1 bands - this should result in 12 averages
- fft.logAverages(11, 1); // results in 12 averages, each corresponding to an octave, the first spanning 0 to 11 Hz.
- }
- void draw() {
- background(0);
- noStroke();
- fft.forward(song.mix); // perform forward FFT on songs mix buffer
- // float bw = fft.getBandWidth(); // returns the width of each frequency band in the spectrum (in Hz).
- // println(bw); // returns 21.5332031 Hz for spectrum [0] & [512]
- for (int i = 0; i < 12; i++) { // 12 is the number of bands
- int lowFreq;
- if ( i == 0 ) {
- lowFreq = 0;
- }
- else {
- lowFreq = (int)((sampleRate/2) / (float)Math.pow(2, 12 - i));
- }
- int hiFreq = (int)((sampleRate/2) / (float)Math.pow(2, 11 - i));
- // we're asking for the index of lowFreq & hiFreq
- int lowBound = fft.freqToIndex(lowFreq); // freqToIndex returns the index of the frequency band that contains the requested frequency
- int hiBound = fft.freqToIndex(hiFreq);
- //println("range " + i + " = " + "Freq: " + lowFreq + " Hz - " + hiFreq + " Hz " + "indexes: " + lowBound + "-" + hiBound);
- // calculate the average amplitude of the frequency band
- float avg = fft.calcAvg(lowBound, hiBound);
- // println(avg);
- if ((lowBound >= 32) && ( hiBound <= 64)) {
- fill(255);
- ellipseMode(CENTER);
- ellipse(250, 250, avg/1, avg/1);
- }
- if ((lowBound >= 256) && ( hiBound <= 512)) {
- noFill();
- stroke(255);
- strokeWeight(2);
- ellipseMode(CENTER);
- ellipse(250, 250, avg*20, avg*20);
- }
- }
- }
- void stop() {
- song.close(); // always close Minim audio classes when you are finished with them
- minim.stop(); // always stop Minim before exiting
- super.stop(); // this closes the sketch
- }

1