Skip to content

Commit

Permalink
Fix WAV recording, when it was not worked on some devices.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimowner committed Jan 9, 2020
1 parent 4c9e550 commit dc4ce8e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ext.versions = [

def versionMajor = 0
def versionMinor = 7
def versionPatch = 14
def versionPatch = 15

android {
compileSdkVersion versions.targetSdkVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,9 @@ private void writeAudioDataToFile() {
}

private void setWaveFileHeader(File file, int channels) {
long fileSize = file.length();
long fileSize = file.length() - 8;
long totalSize = fileSize + 36;
long byteRate = sampleRate * channels * 2; //2 byte per 1 sample for 1 channel.
long byteRate = sampleRate * channels * (RECORDER_BPP/8); //2 byte per 1 sample for 1 channel.

try {
final RandomAccessFile wavFile = randomAccessFile(file);
Expand Down Expand Up @@ -301,7 +301,7 @@ private byte[] generateHeader(
header[13] = 'm';
header[14] = 't';
header[15] = ' ';
header[16] = 16; // 4 bytes: size of 'fmt ' chunk
header[16] = 16; //16 for PCM. 4 bytes: size of 'fmt ' chunk
header[17] = 0;
header[18] = 0;
header[19] = 0;
Expand All @@ -317,7 +317,7 @@ private byte[] generateHeader(
header[29] = (byte) ((byteRate >> 8) & 0xff);
header[30] = (byte) ((byteRate >> 16) & 0xff);
header[31] = (byte) ((byteRate >> 24) & 0xff);
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;
Expand Down

0 comments on commit dc4ce8e

Please sign in to comment.