From 12f51ca2bc5471bfe17ccbcd27d9a29889053fc2 Mon Sep 17 00:00:00 2001 From: Luca Stefani Date: Wed, 4 Oct 2023 10:00:46 +0200 Subject: [PATCH] Recorder: Write the actual buffer rather then expected size AudioRecord ensures the 'status' return value is the number of bytes read, while the buffer may contains unwanted data. Change-Id: Id456b1166c717735fbfb40488332fa8303962b24 --- .../org/lineageos/recorder/service/HighQualityRecorder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/lineageos/recorder/service/HighQualityRecorder.java b/app/src/main/java/org/lineageos/recorder/service/HighQualityRecorder.java index 6befb666..fd4e15c9 100644 --- a/app/src/main/java/org/lineageos/recorder/service/HighQualityRecorder.java +++ b/app/src/main/java/org/lineageos/recorder/service/HighQualityRecorder.java @@ -154,7 +154,7 @@ private void recordingThreadImpl() { // Status indicates the number of bytes if (status != 0) { if (mTrackAmplitude.get()) { - for (int i = 0; i < data.length; i = i + 2) { + for (int i = 0; i < status; i = i + 2) { int value = data[i] & 0xff | data[i + 1] << 8; if (value < 0) { value = -value; @@ -164,7 +164,7 @@ private void recordingThreadImpl() { } } } - out.write(data, 0, BUFFER_SIZE_IN_BYTES); + out.write(data, 0, status); } } } catch (IOException e) {