鑑於這些說明問題,我非常感激,如果有人可以幫助已瞭解 寫成評論的問題。約拉動波形線(JAVA)
我的目的是建立一個java的音頻工具,其主要功能是: - 在播放音頻文件時顯示信號波形。
非常感謝你much..Ulrike
// here the list lines , does it store points (line coordinates) ???
List<Byte> audioBytes;
List<Line2D.Double> lines;
public void addAudioByte(byte b) {
audioBytes.add(b);
}
public void createWaveForm() {
if (audioBytes.size() == 0) {
return;
}
AudioFormat format = audioInputStream.getFormat();
Dimension d = getSize();
int w = d.width;
int h = d.height - 15;
// calculate number of frames per pixel
int frames_per_pixel = audioBytes.size()/format.getFrameSize()/w;
byte my_byte = 0;
double y_last = 0;
int numChannels = format.getChannels();
for (double x = 0; x < w && audioData != null; x++) {
// here what happens???
int idx = (int) (frames_per_pixel * numChannels * x);
if (format.getSampleSizeInBits() == 8) {
my_byte = (byte) audioData[idx];
} else {
// here what happens???
my_byte = (byte) (128 * audioData[idx]/32768);
}
// does this code draw the line ???
// Y samples values
double y_new = (double) (h * (128 - my_byte)/256);
lines.add(new Line2D.Double(x, y_last, x, y_new));
y_last = y_new;
}
repaint();
}
// does this method draw the lines??? what does it do?
public void paint(Graphics g) {
// component dimensions
Dimension d = getSize();
g.setColor(getBackground());
g.fillRect(0, 0, d.width, d.height);
if (audioBytes.size() == 0) {
return;
}
// I suppose this is where the lines are actually drawn
// The lines (so the waveform) are points and here they get connected based on the content
// of the list lines (declared above) ..is my reasoning correct?
g.setColor(Color.LIGHT_GRAY);
for (int i = 1; i < lines.size(); i++) {
Line2D.Double line = lines.get(i);
g.drawLine((int) line.x1, (int) line.y1, (int) line.x2, (int) line.y2);
}
}
}
你確定她在三年後還想知道嗎? – 2013-04-22 09:38:58