Android plays raw audio from C ++ side

I need to be able to stream audio from a custom format on the C ++ side of an Android system. I am working on porting a custom media player and should be able to open a custom file and stream audio from it. This is important as I don't think porting an entire player to JAVA is possible in terms of performance and moving audio buffers through the JNI. Too slow in my opinion to maintain a decent frame rate. I can handle video on the NDK side via OpenGL ES, but Audio I have no idea how to do.

+2


source to share


2 answers


I recommend that you stream the audio over JNI and see how it actually gets done. I've found that JNI is actually quite efficient (if executed correctly) and wouldn't be surprised if it's fast enough for what you need.

Just pay attention to the implementation, don't force Java to create a buffer every time you want to stream audio, just create a buffer in Java (or via JNI) and then memcpy into it every time you need to update.



Also, you should notice that ALL sound classes on Android are currently written in C ++ and go through JNI. If it's fast enough to go one way (I'm currently working on a game where we can present over 0.5MB of audio from Java to AudioTrack in some frames without issue) then it probably won't be that bad to move on to something else as your main operation i.e. blocking the buffer, writing, unlocking going to audio, and locking the buffer, reading, unlocking in audio classes.

+2


source


The NDK does not currently support audio playback. To do this, you need to use the java AudioTrack API.



+1


source







All Articles