Skip to content
Snippets Groups Projects
Commit f3c15c40 authored by Paul Kaplan's avatar Paul Kaplan
Browse files

Prevent auto-trim from producing invalid start and stop points

parent 8de8c02f
No related branches found
No related tags found
No related merge requests found
...@@ -96,8 +96,14 @@ class AudioRecorder { ...@@ -96,8 +96,14 @@ class AudioRecorder {
} }
} }
const trimStart = Math.max(2, firstChunkAboveThreshold - 2) / this.buffers.length; let trimStart = Math.max(2, firstChunkAboveThreshold - 2) / this.buffers.length;
const trimEnd = Math.min(this.buffers.length - 2, lastChunkAboveThreshold + 2) / this.buffers.length; let trimEnd = Math.min(this.buffers.length - 2, lastChunkAboveThreshold + 2) / this.buffers.length;
// With very few samples, the automatic trimming can produce invalid values
if (trimStart >= trimEnd) {
trimStart = 0;
trimEnd = 1;
}
const buffer = new Float32Array(this.buffers.length * this.bufferLength); const buffer = new Float32Array(this.buffers.length * this.bufferLength);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment