Possible Duplicate:
byte array to short array and back again in java
the encodeAudio()
method in Xuggler has the following parameters:
TargetDataLine
from javax.sound.sampled
I can read the data into a byte[]
array
byte[] tempBuffer = new byte[10000];
fromMic.read(tempBuffer,0,tempBuffer.length);
But the problem is that the samples
argument needs short[]
You are lucky enough that byte
is "fully castable" to short
, so:
// Grab size of the byte array, create an array of shorts of the same size
int size = byteArray.length;
short[] shortArray = new short[size];
for (int index = 0; index < size; index++)
shortArray[index] = (short) byteArray[index];
And then use shortArray
.
Note: as far as primitive type goes, Java always treats them in big endian order, so converting, say, byte ff
will yield short 00ff
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With