如果您使用加工的較新版本,看看在FFT example:
import processing.sound.*;
FFT fft;
AudioIn in;
int bands = 512;
float[] spectrum = new float[bands];
void setup() {
size(512, 360);
background(255);
// Create an Input stream which is routed into the Amplitude analyzer
fft = new FFT(this);
in = new AudioIn(this, 0);
// start the Audio Input
in.start();
// patch the AudioIn
fft.input(in, bands);
}
void draw() {
background(255);
fft.analyze(spectrum);
for(int i = 0; i < bands; i++){
// The result of the FFT is normalized
// draw the line for frequency band i scaling it up by 5 to get more amplitude.
line(i, height, i, height - spectrum[i]*height*5);
}
}
處理2及更早版本附帶的Minim library。 看一看的繪製頻譜部分。 此外,爲進一步的處理你可能想看看this post。
在路由音頻播放作爲輸入,你可以看看SoundFlower或JACK。您應該允許您將系統音頻作爲輸入路由。
此外,由於您提到過iTunes,因此iTunes Visualiser的創建者Robert Hodgin提供了Audio-driven landscape(其他許多令人敬畏的內容)。
![iTunes vis1](https://i.stack.imgur.com/AclJG.jpg)
![iTunes vis2](https://i.stack.imgur.com/Flzrc.jpg)
![iTunes vis3](https://i.stack.imgur.com/OIDzR.jpg)
您需要打開並監聽系統音頻端口。看看['AudioSystem'類教程](https://docs.oracle.com/javase/tutorial/sound/accessing.html)。您可以從中嗅出音頻並實時處理它以構建您的可視化工具。 –
僅供參考如果您不想編程您的應用程序來收聽特定程序的音頻,而是將其編程爲從音頻總線上讀取聲音 - 這樣*任何地方正在播放的任何內容都將被捕獲。最難的部分將是確定當前的混音器和輸出設備是哪一個,然後編寫後臺線程,將後臺數據傳輸到可視化過程。 –