java pcm to wav

前端 未结 5 1700
别跟我提以往
别跟我提以往 2020-12-18 10:32

I have a pcm file, and I want to convert it to a wav file.

Is there any suitable api or code for this?

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-18 11:04

    I cannot yet leave comments, but be aware that the get16BitPcm method in devflow's answer is [oddly] scaling the input data. If you already have 16 bit pcm data to write to the wav file, the method should look something like this:

    public byte[] get16BitPcm(short[] data) {
        byte[] resultData = new byte[2 * data.length];
        int iter = 0;
        for (short sample : data) {
            resultData[iter++] = (byte)(sample & 0x00ff);
            resultData[iter++] = (byte)((sample & 0xff00) >>> 8);
        }
        return resultData;
    }
    

提交回复
热议问题