Skip to content

Commit

Permalink
Recorder: Write the actual buffer rather then expected size
Browse files Browse the repository at this point in the history
AudioRecord ensures the 'status' return value is the number of bytes
read, while the buffer may contains unwanted data.

Change-Id: Id456b1166c717735fbfb40488332fa8303962b24
  • Loading branch information
luca020400 authored and luk1337 committed Oct 4, 2023
1 parent 54bf14b commit 12f51ca
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -164,7 +164,7 @@ private void recordingThreadImpl() {
}
}
}
out.write(data, 0, BUFFER_SIZE_IN_BYTES);
out.write(data, 0, status);
}
}
} catch (IOException e) {
Expand Down

0 comments on commit 12f51ca

Please sign in to comment.