Java:在 XY 网格上绘制 .flac 音频文件的左声道和右声道。 (示波器)
我正在尝试用 Java 创建 XY 示波器,但我陷入了困境。我已通读 jFlac 的所有文档、我用来解码 .flac 音频文件的库以及免费的无损音频编解码器文档
public void processPCM(ByteData pcm) {
byte[] temp = pcm.getData();
line.write(temp, 0, pcm.getLen());
leftAndRight = new int[pcm.getData().length];
for(int i = 0; i < temp.length; i+=2){
leftAndRight[i/2] = (temp[i + 1]<<8) + (temp[i] & 0xff);
}
}
这是我的文件中的示例数据被放入 SourceDataLine 并播放的地方。将数据写入该行后,我希望将左音频和右音频分别转换为单独的整数数组变量 x[] 和 y[]。
这是我正在使用的文件的 StreamInfo:
PCM_SIGNED 44100.0 Hz,16 位,立体声,4 字节/帧,小尾数
从上面的代码来看,pcm.getLen() 返回值 16384,pcm.getData() 返回长度为 90112 的字节数组。这个字节数组,如果我没记错的话,我需要将左通道和右通道分开,然后转换为整数数组。这是我不明白如何完成的部分。
编辑:我将上面的代码更改为我遇到的东西,我认为可能是如何将字节数组转换为整数数组,但我仍然不知道左右通道是如何排列的。
I am trying to create an X-Y Oscilloscope in Java and I have gotten stuck. I have read through all the documentation for jFlac, the library i am using to decode my .flac audio file and the free lossless audio codec documentation here. I cannot seem to find the answer to the problem i am having. Please consider the following.
public void processPCM(ByteData pcm) {
byte[] temp = pcm.getData();
line.write(temp, 0, pcm.getLen());
leftAndRight = new int[pcm.getData().length];
for(int i = 0; i < temp.length; i+=2){
leftAndRight[i/2] = (temp[i + 1]<<8) + (temp[i] & 0xff);
}
}
This is where the sample data from my file is put into the SourceDataLine and is played. After i write the data to the line, i wish to convert the left and right audio into separate integer array variables x[] and y[], respectively.
This is the StreamInfo for the file i am using:
PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian
from the code above, pcm.getLen() returns a value of 16384 and pcm.getData() returns a byte array of length 90112. It's the data in this byte array, if I'm not mistaken, that i need to separate the left and right channels from, and then convert into integer arrays. This is the part that I do not understand how to accomplish.
Edit: I changed the above code to something i came across that i think might be how to get the byte array into an integer array, but i am still clueless to how the left and right channels are arranged.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看
因此,您需要类似的东西:(
警告:代码尚未经过测试并且可能完全由语法错误和错误组成,但希望这个想法足够清晰)。
Looking at the code in http://jflac.cvs.sourceforge.net/viewvc/jflac/jFLAC/src/java/org/kc7bfi/jflac/FLACDecoder.java?revision=1.13&view=markup it appears that the contents of the byte array are: a series of samples, each of which is: a series of channels, each of which is: a series of bytes representing one sample on one channel, least significant byte first. The value of
getLen()
is the number of valid bytes in it; there may be more data than that because the sameByteData
object is reused, it may be overallocated to avoid repeated reallocation, etc.So, you'll want something like:
(warning: code has not been tested and may consist entirely of syntax errors and bugs, but hopefully the idea is clear enough).