简体   繁体   中英

Play 4-channel 16bit PCM audio data on android device

I want to play PCM audio data in my android app. There are many examples on the web but only for mono channel and I have 4 channels (as stated in the title of this question).

When I set

AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 48000, AudioFormat.CHANNEL_OUT_QUAD, AudioFormat.ENCODING_PCM_16BIT, bufsize, AudioTrack.MODE_STREAM);

I get an IllegalArgumentException and when I switch back to CHANNEL_OUT_MONO it works. What can I do?

This happens because you need to use a device that supports reproduction of 4-channel audio. Eg if you connect a 4 channel USB audio card, or connect to an 5.1 AV receiver using HDMI, this should work. But regular sound outputs on phones and tablets only support 2 channel (stereo) output.

Otherwise, you have to transform your audio into 2 channel somehow first. The actual procedure will depend on what kind of audio it is. Eg if it's a multitrack studio record, you may need to pan the instruments, or if it's a multichannel consumer record (quadro sound), then you can either downgrade it to stereo by just throwing out extra 2 channels, or try mixing them into the main stereo channels, but then there is a risk of introducing comb filtering.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM