首先,我在做一个小项目,从一些声音中看到光谱。
我用麦克风做的:
alt text http://img25.imageshack.us/img25/4271/spectrumanalyzerfourier.png
上面的图片只是我通过麦克风说了几秒钟,大声喊叫。我觉得这个不错。
但是当我试着读一个MP3文件,并制作一个它的spectrogram图像时,它看起来有点不同。我试过Aphex Twin-Windowlicker,在那里你通常可以在光谱图像中看到一张脸,或者至少可以看到一些更暗的颜色。但看起来不太好:
alt text http://img10.imageshack.us/img10/3475/aphextwinhmm.png
以下是我对麦克风所做的:
byte tempBuffer[] = new byte[10000];
ByteArrayOutputStream out = new ByteArrayOutputStream();
counter = 20;
// Microphone
while (counter != 0) {
int count = line.read(tempBuffer, 0, tempBuffer.length);
if (count > 0) {
out.write(tempBuffer, 0, count);
}
counter--;
}
out.close();
// FFT code below ...
byte audio[] = out.toByteArray();
// ...
我是这样用MP3的:
byte tempBuffer[] = new byte[10000];
ByteArrayOutputStream out = new ByteArrayOutputStream();
FileInputStream input = null;
File mp3 = new File("Aphex Twin - Widowlicker.mp3");
input = new FileInputStream(mp3);
int len;
while((len = input.read(tempBuffer)) > 0) {
out.write(tempBuffer, 0, len);
}
out.close();
input.close();
// FFT code below ...
byte audio[] = out.toByteArray();
// ...
-
采样率:44100
-
-
通道:1(单声道)
-
-
大端:没错
(我用的是Java中的AudioFormat)
-
-
顺便问一下:这些设置可以吗?或者我应该使用16bps或立体声,或者10000表示缓冲区太多,或者4096表示小/大?
提前谢谢