File tree Expand file tree Collapse file tree 2 files changed +5
-3
lines changed
android-wave-recorder/src/main/java/com/github/squti/androidwaverecorder Expand file tree Collapse file tree 2 files changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -41,5 +41,6 @@ data class WaveConfig(
41
41
internal fun bitPerSample (audioEncoding : Int ) = when (audioEncoding) {
42
42
AudioFormat .ENCODING_PCM_8BIT -> 8
43
43
AudioFormat .ENCODING_PCM_16BIT -> 16
44
+ AudioFormat .ENCODING_PCM_32BIT -> 32
44
45
else -> 16
45
46
}
Original file line number Diff line number Diff line change @@ -82,7 +82,7 @@ class WaveRecorder(private var filePath: String) {
82
82
private var isPaused = false
83
83
private lateinit var audioRecorder: AudioRecord
84
84
private var noiseSuppressor: NoiseSuppressor ? = null
85
- private var channelModulus = 2
85
+ private var timeModulus = 1
86
86
87
87
88
88
/* *
@@ -103,8 +103,9 @@ class WaveRecorder(private var filePath: String) {
103
103
waveConfig.audioEncoding
104
104
)
105
105
)
106
+ timeModulus = bitPerSample(waveConfig.audioEncoding) * waveConfig.sampleRate / 8
106
107
if (waveConfig.channels == AudioFormat .CHANNEL_IN_STEREO )
107
- channelModulus = 4
108
+ timeModulus * = 2
108
109
109
110
audioSessionId = audioRecorder.audioSessionId
110
111
@@ -146,7 +147,7 @@ class WaveRecorder(private var filePath: String) {
146
147
it(calculateAmplitudeMax(data))
147
148
}
148
149
onTimeElapsed?.let {
149
- val audioLengthInSeconds: Long = file.length() / (channelModulus * waveConfig.sampleRate)
150
+ val audioLengthInSeconds: Long = file.length() / timeModulus
150
151
it(audioLengthInSeconds)
151
152
}
152
153
}
You can’t perform that action at this time.
0 commit comments