JavaSound: Extract one channel of stereo audio

时光毁灭记忆、已成空白 提交于 2019-12-11 12:06:57

问题


I have a stereo wave file that I need to read and play back only the selected channel. What is the best way to accomplish this?


回答1:


When you bring the wav file in via an AudioInputStream, use the AudioFileFormat info to convert the bytes to PCM. The data for the right and left alternates. So, if the line is 16-bit, you will have 4 bytes per frame. The first two will be assembled into the left channel and the second two will be assembled into the right channel. (Or vice versa--I have trouble keeping straight in my mind which channel is left or right.)

Here's a good tutorial with example on how to read a line: http://docs.oracle.com/javase/tutorial/sound/converters.html

Some of the earlier tutorials in the trail might be needed to help clarify. Also, if you have questions about converting bytes to PCM and back, there are several explanations already on StackOverflow to reference. Should not be too hard to find them.



来源:https://stackoverflow.com/questions/25776803/javasound-extract-one-channel-of-stereo-audio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!