Skip to content

Commit

Permalink
Fix double speed with onTimeElapsed in stereo channel
Browse files Browse the repository at this point in the history
  • Loading branch information
squti committed Apr 12, 2022
1 parent a4e4697 commit 613bd31
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package com.github.squti.androidwaverecorder

import android.annotation.SuppressLint
import android.media.AudioFormat
import android.media.AudioRecord
import android.media.MediaRecorder
import android.media.audiofx.NoiseSuppressor
Expand Down Expand Up @@ -81,6 +82,8 @@ class WaveRecorder(private var filePath: String) {
private var isPaused = false
private lateinit var audioRecorder: AudioRecord
private var noiseSuppressor: NoiseSuppressor? = null
private var channelModulus = 2


/**
* Starts audio recording asynchronously and writes recorded data chunks on storage.
Expand All @@ -100,6 +103,8 @@ class WaveRecorder(private var filePath: String) {
waveConfig.audioEncoding
)
)
if (waveConfig.channels == AudioFormat.CHANNEL_IN_STEREO)
channelModulus = 4

audioSessionId = audioRecorder.audioSessionId

Expand Down Expand Up @@ -141,7 +146,7 @@ class WaveRecorder(private var filePath: String) {
it(calculateAmplitudeMax(data))
}
onTimeElapsed?.let {
val audioLengthInSeconds: Long = file.length() / (2 * waveConfig.sampleRate)
val audioLengthInSeconds: Long = file.length() / (channelModulus * waveConfig.sampleRate)
it(audioLengthInSeconds)
}
}
Expand Down

0 comments on commit 613bd31

Please sign in to comment.