【发布时间】:2013-05-31 07:36:47
【问题描述】:
我正在处理音频,我将音频数据保存在短数组中。我想将其转换为字节数组来存储 wav 文件。我不知道将 short[] 转换为 byte[]。你能帮助我吗。 非常感谢。
【问题讨论】:
-
非常感谢。我会试试这段代码: private byte[] shortArrayToByteArray(short[] shortArr) { int index; int 迭代次数 = shortArr.length; ByteBuffer bb = ByteBuffer.allocate(shortArr.length * 2); for(index = 0; index != 迭代次数; ++index){ bb.putShort(shortArr[index]); } 返回 bb.array(); }
-
如果您使用 ByteBuffer,请确保您的系统的字节顺序正确。默认为大端,但许多格式使用小端。
-
哦,非常感谢,我要创建little-endian。