convert int16_t into jbytearray
I am using an Native library in android for streaming.
Here is the scenario:
I am passing a url to c file and after lot of processing it writes the data in wav file.
I'm not so much familiar with C but what i could understand is there is a pointer of int16_t
from which wav file is written.
Here is the question.
Is there any way to convert int16_t
to jbytearray
so that i can return a byte array to my java 开发者_如何学Pythoncode?
Thanks
I don't know the first thing about Android, but you might want to look into java.nio.ByteBuffer
- they can be made to allocate their buffer in native memory (allocateDirect()
), so native functions can write directly into it.
You need to allocate a byte[] and then copy the WAV data into it. Alternatively, create a "direct" ByteBuffer that spans the WAV data, and pass that into your Java code.
Read the JNI documentation and the JNI Tips doc for more info. In particular:
SetByteArrayRegion NewDirectByteBuffer
精彩评论