views:

498

answers:

2

I need to be able to stream audio from a custom file format on the C++ side of the Android system. I am working on porting a custom media player and need to be able to open a custom file and stream audio from it. This is important as I do not think porting the whole player to JAVA is feasible from a performance stand point and moving the audio buffers through the JNI interface I believe will be too slow to keep a decent frame rate. I can handle the video on the NDK side through OpenGL ES, but the Audio I have no idea how to make this happen.

+1  A: 

The NDK does not support playing audio frames currently. You have to use the java AudioTrack API to achieve this.

+1  A: 

I recommend you pass the audio through the JNI and see how it actually performs. I've found that the JNI is actually quite efficient (if implemented correctly) and wouldn't be surprised if it is more than fast enough for what you need.

Just a note on implementation, don't get Java to create a buffer each time you want to pass audio through, simply create a buffer in Java (or via the JNI) and then memcpy into it each time you need to update.

Also, you should note that ALL of the audio classes on the Android are currently written in c++ and run through the JNI. If its fast enough to go one way (I'm currently working on a game where we may submit over 0.5mb of audio data from Java to AudioTrack in on some frames without a problem), then it probably won't be too bad to go the other as its basically the same operation, i.e. lock buffer, write, unlock going to the audio, and lock buffer, read, unlock within the audio classes.

Grant Peters