So, this is my code:
import ddf.minim.*;
import ddf.minim.analysis.*;
Minim minim;
AudioPlayer sound;
FFT spectrum;
void setup() {
size(600, 600);
noStroke();
fill(255);
minim = new Minim(this);
sound = minim.loadFile("untitled.mp3", 1024);
sound.loop();
spectrum = new FFT(sound.bufferSize(), sound.sampleRate());
}
void draw() {
background(0);
spectrum.forward(sound.mix);
for (int i = 0; i < spectrum.specSize(); i++) {
float x = map(i, 0, spectrum.specSize(), 0, width);
//float y = map(spectrum.getBand(i), 0, ???, 0, height);
rect(x, height, width/spectrum.specSize(), -spectrum.getBand(i));
}
}
I’ve even uploaded the sound file online in case you wanna hear it: https://ufile.io/3encm
(It’s just a simple sine wave, rapidly ascending by musical semitones)
So, I have a ton of questions:
-
What is the max amplitude the spectrum.getBand() method can output? I need to know it in order to finish that second map() function (which I’ve commented out). In p5.sound, it was 255. Here, I’m not so sure. A few of the values went all the way past 300.
-
What are the specific frequencies of the 1024 analyzed portions?
-
When I bring the number of portions down (e.g. 64), it starts lagging. Why?
-
Why is the actual number of portions half the size plus 1 than what I’ve specified using the loadFile() function?
-
In p5, the p5.FFT() function can take a parameter which specifies smoothing/averaging. Since my visualization is incredibly erratic, I’d like to add that. Is there a function like that in Minim that would smooth out/average the data? I want to achieve that smooth music visualizer effect that you can find in so many music videos lately.
-
The frequencies of the portions are distributed linearly. This causes the tones from the sound file to appear rising exponentially. Is there a function that would make the analysis exponential? Music, in essence, IS exponential. When we play a linear sequence (100 Hz, 200 Hz, 300 Hz…), the sequence will appear to rise slower and slower. I’d simply like the analyzed data to be distributed more naturally.
-
In case Minim does not have such a function, I will have to resort to an analysis of specific, hand-picked frequencies. Is there a function to get the amplitude of a specific frequency? I know that in p5.sound, it’s p5.FFT.getEnergy().
-
The console seems to be outputting some kind of a non-sketch-breaking error. What’s that all about?