byte[]
转换为short[]
,我遇到的新问题是将数据从byte[]
转换/不转换为BigEndian。以下是正在发生的事情:
TargetDataLine
将数据读入byte[10000]
中。 AudioFormat
对象将BigEndian
设置为true,任意设置。 byte[]
需要转换为short[]
,以便可以使用Xuggler进行编码。我不知道AudioFormat
BigEndian应该设置为true还是false。
我尝试了这两种情况,但在两种情况下都会出现异常。
要将byte[]
转换为short[]
,我这样做:
fromMic.read(tempBufferByte, 0, tempBufferByte.length);
for(int i=0;i<tempBufferShort.length;i++){
tempBufferShort[i] = (short) tempBufferByte[i];
}
其中:
fromMic
是 TargetDataLine
tempBufferbyte
是 byte[10000]
tempBufferShort
是 short[10000]
我收到了异常:
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;]
可能需要的其他信息:
writer.addAudioStream(0,1,fmt.getChannels(),(int)fmt.getSampleRate());
我如何执行编码
writer.encodeAudio(1,tempBufferShort,timeStamp,TimeUnit.NANOSECONDS);
AudioFormat中的Java Doc
除了编码之外,音频格式还包括其他属性,进一步指定数据的确切排列方式。这些属性包括通道数、采样率、采样大小、字节顺序、帧速率和帧大小。
以及
对于16位样本(或任何比一个字节更大的样本大小),字节顺序非常重要;每个样本中的字节都按“小端”或“大端”样式排列。
问题:
javax.sound.sampled.AudioFormat
对象中,我需要将BigEndian
保留为true吗?我猜AudioFormat对象预先格式化了BigEndian数据。
System.out.println(e)
来获取它包含的内容。我得到了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;]
。 - An SO User