我尝试使用处理从麦克风获取频率。我混合了文档中的两个示例,但“最高”并不是真正的赫兹(a 是 440 赫兹)。你知道如何拥有比这更好的东西吗?
import ddf.minim.*;
import ddf.minim.analysis.*;
Minim minim;
AudioInput in;
FFT fft;
int highest=0;
void setup()
{
size(1024, 200, P2D);
minim = new Minim(this);
minim.debugOn();
in = minim.getLineIn(Minim.MONO, 4096, 44100);
fft = new FFT(in.left.size(), 44100);
}
void draw()
{
background(0);
stroke(255);
fft.forward(in.left);
highest=0;
for (int n = 0; n < fft.specSize(); n++) {
// draw the line for frequency band n, scaling it by 4 so we can see it a bit better
line(n/4, height, n/4, height - fft.getBand(n)*4);
//find frequency with highest amplitude
if (fft.getBand(n)>fft.getBand(highest))
highest=n;
}
println(highest);
//println(fft.getFreq(110));
// draw the waveforms
for (int i = 0; i < in.bufferSize() - 1; i++)
{
line(i, 50 + in.left.get(i)*50, i+1, 50 + in.left.get(i+1)*50);
line(i, 150 + in.right.get(i)*50, i+1, 150 + in.right.get(i+1)*50);
}
}
void stop()
{
// always close Minim audio classes when you are done with them
in.close();
minim.stop();
super.stop();
}