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