Xuggler中的encodeAudio()
方法具有以下参数:
TargetDataLine
中的javax.sound.sampled
我可以将数据读入byte[]
数组
byte[] tempBuffer = new byte[10000];
fromMic.read(tempBuffer,0,tempBuffer.length);
但问题是samples
参数需要short[]
答案 0 :(得分:9)
你很幸运byte
对short
是“完全可投递”的,所以:
// 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];
然后使用shortArray
。
注意:就原始类型而言,Java总是以大端顺序处理它们,因此转换比如字节ff
将产生短00ff
。