Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert ByteArray to IntArray java

Tags:

java

I have an ByteArrayOutputStream connected with a Dataline from an AudioSource. I need to convert the Stream in some significative values that probally are the sound values taken from source or not ? Well then how can I conver the byteArray (from ByteArrayOutStream.getByteArray()) in a intArray?. I googled it but with no luck .

p.s. the audioFormat that I used is : PCM_SIGNED 192.0Hz 16Bit big endian

like image 786
relu Avatar asked Mar 02 '26 03:03

relu


2 Answers

Use a ByteBuffer. You can convert not only to different array types this way, but also deal with endian issues.

like image 103
toadaly Avatar answered Mar 04 '26 15:03

toadaly


You can try the following:

ByteBuffer.wrap(byteArray).asIntBuffer().array()
like image 35
Oleg Kuybeda Avatar answered Mar 04 '26 17:03

Oleg Kuybeda



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!