Not sure how to work with Minim's FFT feature

pls check also

i think at first you need to know more about the actual numbers…
so try the code i show later

also i not know about exact differences
between Processing 3.4 Minim
and the P5.js version,

but your comment sounds like
the p5.js version is normalizing the amplitude???
as far as i know,
a FFT gets a series of numbers and spits out
the 2* average and the amplitude of
a sinus what fits in that numbersequences
( and all harmonics. 2,3,4,5… fitting sinus. )
again,
if you give 1024 samples the result is a array of 512 +1
so, why Fourier only counts the first 512 frequencies
he could calculate more, ha? kind of lazy?

the basic idea is, if you do one measurement there is no way to
know if there are frequencies in that signal.
but if you make 2 measurements you can try to fit that to a sinus.
( even it still can be anything else, no way to know )
that is the first problem of any digitizing, sampling of analog signals.
the more samples the more you know
also that says you need min 2 samples to fit a frequency,
that is called the

turn that around and you know why FFT only do 512 sinus in 1024 samples.

and for the correlation to the sound frequencies?
again the FFT does not know frequencies, only samples
the base frequency ( one sinus in the 1024 samples ) you have to
calculate what it really means
by find out how many msecs that 1024 samples mean
that base frequency ( amplitude in fft[1] ) would be 1 / ( sec of 1024 samples )

now to make from that fft information any of that
“today” spectrum show

  • green to red color on amplitude
  • show max of it for some second then fading down…

is sure a challenging coding,
but sounds more like you looking for ready examples or “better” libraries
i would think its out there already but i don’t know

also check google tutorial videos…
Processing Tutorial #5 on Vimeo

// update:
i play little bit and got the idea that we need a common ground
so we can compare data:
i started my raspberry pi, and used the default audio program i install there

audacity

and with this i generated a 440 Hz tone “a”
and export to mp3 file
that i used in the little bit modified

code
import ddf.minim.*;
import ddf.minim.analysis.*;

//String soundfile = "untitled.mp3";
String soundfile = "the_a.mp3";

float amp =1;
float max = -1000;

Minim minim;
AudioPlayer sound;
FFT spectrum;

void setup() {
  size(600, 600);
  noStroke();
  fill(255);
  minim = new Minim(this);
  sound = minim.loadFile(soundfile,1024);
  sound.loop();
  spectrum = new FFT(sound.bufferSize(), sound.sampleRate());
  println("bufferSize() "+sound.bufferSize());
  println("sampleRate() "+sound.sampleRate());
  println("fft.specSize()"+spectrum.specSize());
}

void draw() {
  background(0);
  spectrum.forward(sound.mix);
  if ( keyPressed ) max = -1000;
  for (int i = 0; i < spectrum.specSize(); i++) {
    float x = map(i, 0, spectrum.specSize(), 0, width);
    if ( keyPressed ) if ( spectrum.getBand(i) > max ) max = spectrum.getBand(i);
    //float y = map(spectrum.getBand(i), 0, ???, 0, height);
    rect(x, height-10, width/spectrum.specSize(), -spectrum.getBand(i)*amp);
    if ( keyPressed ) if ( i < 20) print(" i: "+i+" "+nf(spectrum.getBand(i),1,1));
}
if ( keyPressed ) println("\nmax "+nf(max,1,1));
if ( keyPressed ) println("\nnext");

}

and you can get the same audio file from:

http://kll.engineering-news.org/kllfusion01/downloads/the_a.mp3

now using this shows


and press any key

the max amplitude at i=10
ha? can that be related to

sampleRate() 44100.0
and the selected frequency 440Hz

and buffersize 1024

and with buffersize 512
i find the max at i=5

1 Like