Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ecbce95b authored by Paul Keith's avatar Paul Keith Committed by Luca Stefani
Browse files

Recorder: Correct WAV header creation

* ByteRate = SampleRate * NumChannels * BitsPerSample/8
* The previous calculation was off by a factor of 10
* BlockAlign = NumChannels * BitsPerSample/8
* The previous calculation was off by a factor of 2
* While we're at it, reorder the byte-rate formula to make more
  logical sense -- NumChannels * SampleRate * BitsPerSample/8
* Source: http://soundfile.sapp.org/doc/WaveFormat/

Change-Id: I579e4b6833044114a594b371167a6087f57c01a5
parent 54706e46
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ class PcmConverter {
    private static final long SAMPLE_RATE = 44100;
    private static final int RECORDER_BPP = 16;
    private static final int CHANNELS = 1;
    private static final long BYTE_RATE = RECORDER_BPP * 441000 * CHANNELS / 8;
    private static final long BYTE_RATE = CHANNELS * SAMPLE_RATE * RECORDER_BPP / 8;
    private static final String TAG = "PcmConverter";

    @SuppressWarnings("SameParameterValue")
@@ -95,7 +95,7 @@ class PcmConverter {
        header[29] = (byte) ((BYTE_RATE >> 8) & 0xff);
        header[30] = (byte) ((BYTE_RATE >> 16) & 0xff);
        header[31] = (byte) (0L);
        header[32] = (byte) (2 * 16 / 8);  // block align
        header[32] = (byte) (CHANNELS * RECORDER_BPP / 8);  // block align
        header[33] = 0;
        header[34] = RECORDER_BPP;  // bits per sample
        header[35] = 0;