From 229da7c812c301096fcbcf4cb884c7a14935d06f Mon Sep 17 00:00:00 2001 From: Luca Stefani Date: Tue, 5 Nov 2024 22:07:00 +0100 Subject: [PATCH] Recorder: Always track amplitude Change-Id: I71f593bec4303ff9b31b5e9af4ab414f03142f18 --- .../recorder/service/HighQualityRecorder.kt | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/org/lineageos/recorder/service/HighQualityRecorder.kt b/app/src/main/java/org/lineageos/recorder/service/HighQualityRecorder.kt index 9b85063d..c71982ff 100644 --- a/app/src/main/java/org/lineageos/recorder/service/HighQualityRecorder.kt +++ b/app/src/main/java/org/lineageos/recorder/service/HighQualityRecorder.kt @@ -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) { @@ -82,9 +81,6 @@ class HighQualityRecorder : SoundRecording { override val currentAmplitude: Int get() { - if (!trackAmplitude) { - trackAmplitude = true - } return maxAmplitude } @@ -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) {