Previously I posed a question about converting a byte[]
to short[]
and a new problem I encountered is converting/ not converting the data from byte[]
to BigEndian.
Here is what is going on:
TargetDataLine
to read data into a byte[10000]
. AudioFormat
object has BigEndian
set to true, arbitrarily. byte[]
needs to be converted to short[]
so that it can be encoded using Xuggler I don't know whether the AudioFormat
BigEndian should be set to true or false.
I have tried both the cases and I get an Exception in both the cases.
To convert byte[]
to short[]
, I do this:
fromMic.read(tempBufferByte, 0, tempBufferByte.length);
for(int i=0;i<tempBufferShort.length;i++){
tempBufferShort[i] = (short) tempBufferByte[i];
}
where:
fromMic
is TargetDataLine
tempBufferbyte
is byte[10000]
tempBufferShort
is short[10000]
I get the Exception:
java.lang.RuntimeException: failed to write packet: com.xuggle.xuggler.IPacket@90098448[complete:true;dts:12;pts:12;size:72;key:true;flags:1;stream index:1;duration:1;position:-1;time base:9/125;]
Miscellaneous information that may be needed:
writer.addAudioStream(0,1,fmt.getChannels(),(int)fmt.getSampleRate());
writer.encodeAudio(1,tempBufferShort,timeStamp,TimeUnit.NANOSECONDS);
Java Doc on AudioFormat
...In addition to the encoding, the audio format includes other properties that further specify the exact arrangement of the data. These include the number of channels, sample rate, sample size, byte order, frame rate, and frame size...
and
For 16-bit samples (or any other sample size larger than a byte), byte order is important; the bytes in each sample are arranged in either the "little-endian" or "big-endian" style.
Questions:
BigEndian
as true in javax.sound.sampled.AudioFormat
object? I guess I get BigEndian data preformatted by the AudioFormat object.