byte 数组与 short 数组转换网上有很多方法,
但是在音频流中,因为 byte 数组转换 short 数组,有大小端的问题。
所有大多数的方法都不可用 ,所以特地做一下记录:
public static short[] bytesToShort(byte[] bytes) {
if (bytes == null) {
return null;
}
short[] shorts = new short[bytes.length / 2];
ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().get(shorts);
return shorts;
}