Prasham
Prasham

Reputation: 6686

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 code?

Thanks

Upvotes: 2

Views: 1104

Answers (2)

fadden
fadden

Reputation: 52343

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

Upvotes: 0

DevSolar
DevSolar

Reputation: 70333

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.

Upvotes: 1

Related Questions