Skip to content

Instantly share code, notes, and snippets.

@HViktorTsoi
Created August 7, 2018 13:10
Show Gist options
  • Save HViktorTsoi/d3eebab43a5e6255743858d9a3c615b1 to your computer and use it in GitHub Desktop.
Save HViktorTsoi/d3eebab43a5e6255743858d9a3c615b1 to your computer and use it in GitHub Desktop.
解析16bit位宽PCM时将byte转换为short的方式
/*
* 将raw数据中的二进制转换为实际的音频信号 由于默认音频格式为16bit 小端存储 因此这里只使用high和low两位
* 如果用其他bit宽度需要修改此函数
*
* */
public static int rawAudioDataToShort(byte high, byte low) {
byte[] byteArray = {high, low};
return ByteBuffer.wrap(byteArray).order(ByteOrder.LITTLE_ENDIAN).getShort();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment