3

谁能告诉我如何读取音频文件,将其存储在字节数组中并继续显示其波形?我的Java知识非常基础。如果有人可以将我链接到 Java 音频编程的学习材料,那就太好了。

4

2 回答 2

6

You will need to understand some basics about Pulse Code Modulation, as that is how waves are represented digitally as discrete byte/values. Most waveform formats are just some header/metadata and then a stream of pulse codes.

Here is a primer on digital sampling and pulse code modulation:

http://www.speakingcode.com/2011/12/31/primer-on-digital-audio-and-pulse-code-modulation-pcm/

After that, it's relatively simple. Load the file, read through the meta data so you know the sampling rate, bit depth, etc. and then basically build up an array with the pcm values.. general java file reading techniques will work fine for that, such as described in the Java tutorials, many pages online, and several relevant questions on stack overflow.

http://docs.oracle.com/javase/tutorial/essential/io/

Once you have your array, your values effectively represent the amplitude position of the wave at that point in time... scale those values and translate to an image - there's so many ways to do that, it's really just up to you. Some things to consider are do you care about the time axis, or just the shape of the wave form? if you only care about the shape, it's easier, cause you don't need to appropriately mark time and scale on the x axis (assuming you follow the standard of time on x axis and amplitude on y axis)

于 2012-10-31T21:56:23.350 回答
2

您的两个问题都已在 SO 上得到解答。请参阅我对这些问题的回答:

音频和java基础:

如何在 Java 中创建声音文件

绘制波形和波形概览:

如何从我的 wav 文件中提取声音数据?

于 2012-11-01T15:15:27.563 回答