File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed
android-wave-recorder/src/main/java/com/github/squti/androidwaverecorder Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change 25
25
package com.github.squti.androidwaverecorder
26
26
27
27
import android.annotation.SuppressLint
28
+ import android.media.AudioFormat
28
29
import android.media.AudioRecord
29
30
import android.media.MediaRecorder
30
31
import android.media.audiofx.NoiseSuppressor
@@ -81,6 +82,8 @@ class WaveRecorder(private var filePath: String) {
81
82
private var isPaused = false
82
83
private lateinit var audioRecorder: AudioRecord
83
84
private var noiseSuppressor: NoiseSuppressor ? = null
85
+ private var channelModulus = 2
86
+
84
87
85
88
/* *
86
89
* Starts audio recording asynchronously and writes recorded data chunks on storage.
@@ -100,6 +103,8 @@ class WaveRecorder(private var filePath: String) {
100
103
waveConfig.audioEncoding
101
104
)
102
105
)
106
+ if (waveConfig.channels == AudioFormat .CHANNEL_IN_STEREO )
107
+ channelModulus = 4
103
108
104
109
audioSessionId = audioRecorder.audioSessionId
105
110
@@ -141,7 +146,7 @@ class WaveRecorder(private var filePath: String) {
141
146
it(calculateAmplitudeMax(data))
142
147
}
143
148
onTimeElapsed?.let {
144
- val audioLengthInSeconds: Long = file.length() / (2 * waveConfig.sampleRate)
149
+ val audioLengthInSeconds: Long = file.length() / (channelModulus * waveConfig.sampleRate)
145
150
it(audioLengthInSeconds)
146
151
}
147
152
}
You can’t perform that action at this time.
0 commit comments