Writing PCM recorded data into a .wav file (java android)

后端 未结 4 492
别跟我提以往
别跟我提以往 2020-11-30 23:33

I\'m using AudioRecord to record 16 bit PCM data in android. After recording the data and saving it to a file, I read it back to save it as .wav file.

The problem is

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-01 00:20

    Are you certain of the byte order? "RIFF", "WAV", "fmt", and "data" look fine but the numbers in the header may need to be a different order (little endian vs. big endian). You also don't need to convert to bytes manually using your intToByteArray method. You could use the writeInt and writeShort methods of DataOutputStream. For the first one, this would look something like:

    outFile.writeInt(Integer.reverseBytes((int)myChunkSize));

    For the shorts it'd be like:

    outFile.writeShort(Short.reverseBytes((short)myFormat))

    This way you also don't need to provide the offset and length (0, 4) numbers. It's nice.

提交回复
热议问题