1 回答
TA贡献1804条经验 获得超7个赞
通过阅读本文,我能够知道如何将PCM缓冲区格式化为可播放的音频字节 https://github.com/philfrei/AudioCue/blob/master/src/main/java/com/adonax/audiocue/AudioCue.java,这是我使用的片段:
public static byte[] fromBufferToAudioBytes(byte[] audioBytes, float[] buffer)
{
for (int i = 0, n = buffer.length; i < n; i++)
{
buffer[i] *= 32767;
audioBytes[i*2] = (byte) buffer[i];
audioBytes[i*2 + 1] = (byte)((int)buffer[i] >> 8 );
}
return audioBytes;
}
这是我在代码中更新的内容
pcm8 := make([]byte, frameSize * 2)
for i := 0; i < frameSize; i++ {
//pcm[i] *= 32767 // uncomment when pcm array is float insteand of int16
pcm8[i*2] = byte(uint16(pcm[i]))
pcm8[i*2 + 1] = byte(uint16(pcm[i]) >> 8)
}
- 1 回答
- 0 关注
- 155 浏览
添加回答
举报