Dimowner / AudioRecorder

Audio Recording Android application
Apache License 2.0
759 stars 173 forks source link

In WavRecorder, the wavHeader will overwrite the original PCM data. #117

Closed kresle closed 4 months ago

kresle commented 4 months ago

https://github.com/Dimowner/AudioRecorder/blob/325642afa0c9ff9f1b9535eddf38bf43274bf9b3/app/src/main/java/com/dimowner/audiorecorder/audio/recorder/WavRecorder.java#L260C1-L261C1

In the WavRecorder, the writeAudioDataToFile thread first write all the recorded PCM data to output file, then reopen this file with RandomAccessFile and go to the head with seek(0) and then write the generated wav header.

In most cases, this would be fine. The beginning 44B of the recording typically contains nothing so important. But if the AudioFormat is not PCM16, like PCM24, the overwritten header will cause mis-interpretation for the following PCM data, as 44 cannot be divided by 6 or 3.

Maybe writting a fake wav header in writeAudioDataToFile is a good idea.

Dimowner commented 4 months ago

Fixed in this PR: https://github.com/Dimowner/AudioRecorder/pull/122