开发者

Writing PCM audio data to audio device from native code

开发者 https://www.devze.com 2023-02-14 08:56 出处:网络
Is it possible to to write PCM samples to audio device under Android directly from native code? I\'ve been able to reproduce PCM samples by sending data to a socket and playing with AudioTra开发者_Sta

Is it possible to to write PCM samples to audio device under Android directly from native code? I've been able to reproduce PCM samples by sending data to a socket and playing with AudioTra开发者_StackOverflow社区ck. Is it possible to avoid all this path to audio device by accessing directly from native code? Thanks!


Yes you can try to use your audio devices directly. The access works over Linux virtual device nodes placed in /dev/.

On my HTC Desire this would be

/dev/msm_pcm_out

I don't know how other devices of different vendors call this device. Its not guaranteed that this device node has the same name after reboot or OS update. So you will have a lot of nasty patching work to do once your application is shipped.

WARNING executing the following commands will produce an infinitely white noise sound unless you kill your "cat" program or reboot your phone

The command (ON A ROOTED PHONE)

su

and

cat /dev/urandom > /dev/msm_pcm_out

will produce white noise come out of the phone speaker. Since cat is a C program you should be able to analyse the source code and adapt it to your program.

The catch is: your device is required to be rooted to make this happen as well as every device your application should run on.

I guess the Android way is a dirty but most portable and comfortable way to play sounds via NDK.


Re-reading this I ask myself why I didn't think of simply using AudioTrack from native code using JNI... That should be the best solution.

0

精彩评论

暂无评论...
验证码 换一张
取 消