From a73659d5e9b9d07f92e2b6b0a788ee04625b0cc3 Mon Sep 17 00:00:00 2001 From: Andrew Gunnerson Date: Mon, 6 Jun 2022 19:48:47 -0400 Subject: [PATCH] RecorderThread: Make AudioRecord internal buffer less excessively large When the call ends, everything still remaining in AudioRecord's internal buffer is lost because there's no way to read the remaining bytes after recording is stopped. With 20x the buffer size on eg. a device with a 1920 byte minimum buffer size and a sample rate of 8000 Hz, this may cause 1.6 seconds of audio at the end of the call to be lost. This commit should not have a negative effect since the large buffer size was meant to address buffer overruns and the root cause of that problem was addressed in #72. Signed-off-by: Andrew Gunnerson --- app/src/main/java/com/chiller3/bcr/RecorderThread.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/chiller3/bcr/RecorderThread.kt b/app/src/main/java/com/chiller3/bcr/RecorderThread.kt index 0dd53dbe4..33200b6e3 100644 --- a/app/src/main/java/com/chiller3/bcr/RecorderThread.kt +++ b/app/src/main/java/com/chiller3/bcr/RecorderThread.kt @@ -358,8 +358,8 @@ class RecorderThread( CHANNEL_CONFIG, ENCODING, // On some devices, MediaCodec occasionally has sudden spikes in processing time, so use - // a large internal buffer to reduce the chance of overrun on the recording side. - minBufSize * 20, + // a larger internal buffer to reduce the chance of overrun on the recording side. + minBufSize * 6, ) val initialBufSize = audioRecord.bufferSizeInFrames * audioRecord.format.frameSizeInBytesCompat