Skip to content

Commit

Permalink
Recorder: Always track amplitude
Browse files Browse the repository at this point in the history
Change-Id: I71f593bec4303ff9b31b5e9af4ab414f03142f18
  • Loading branch information
luca020400 committed Nov 5, 2024
1 parent 32a6b1c commit 229da7c
Showing 1 changed file with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class HighQualityRecorder : SoundRecording {
private var file: File? = null
private var maxAmplitude = 0
private var isRecording = false
private var trackAmplitude = false

@RequiresPermission(permission.RECORD_AUDIO)
override fun startRecording(path: Path) {
Expand Down Expand Up @@ -82,9 +81,6 @@ class HighQualityRecorder : SoundRecording {

override val currentAmplitude: Int
get() {
if (!trackAmplitude) {
trackAmplitude = true
}
return maxAmplitude
}

Expand All @@ -99,18 +95,17 @@ class HighQualityRecorder : SoundRecording {
if (read > 0) {
out.write(buffer, 0, read)

if (trackAmplitude) {
maxAmplitude = 0
for (i in 0 until read step 2) {
val sample = ByteBuffer.wrap(buffer, i, 2)
.order(ByteOrder.LITTLE_ENDIAN)
.short
.toInt()
maxAmplitude = maxOf(maxAmplitude, abs(sample))
}
maxAmplitude = 0
for (i in 0 until read step 2) {
val sample = ByteBuffer.wrap(buffer, i, 2)
.order(ByteOrder.LITTLE_ENDIAN)
.short
.toInt()
maxAmplitude = maxOf(maxAmplitude, abs(sample))
}
}
}

PcmConverter.updateWavHeader(out)
}
} catch (e: IOException) {
Expand Down

0 comments on commit 229da7c

Please sign in to comment.