From 43af19ba94dae9c9ea72f50164c2128c79a39c02 Mon Sep 17 00:00:00 2001 From: Wanjohi <71614375+wanjohiryan@users.noreply.github.com> Date: Tue, 2 May 2023 15:57:58 +0300 Subject: [PATCH 1/2] Fix for audio breaking after a certain time into the stream After some time into the audio stream, the audio breaks and an error message is displayed in the console stating that the frame offset exceeds the total frames. `` caught RangeError: Failed to execute 'copyTo' on 'AudioData': Frame offset exceeds total frames (1024 >= 1024). `` This is my proposed solution to the issue. I have tested and verified that my fix works and the audio now runs smoothly without any break. Hope it helps :) --- player/src/audio/ring.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/player/src/audio/ring.ts b/player/src/audio/ring.ts index cd796ee..3eaef49 100644 --- a/player/src/audio/ring.ts +++ b/player/src/audio/ring.ts @@ -59,11 +59,15 @@ export class Ring { frameCount: first.length, }) + //For some reason this breaks audio... and this is my temporary fix + //console.log("frame offset", first.length , "frame count", second.length) to test + if (first.length < second.length) { frame.copyTo(second, { planeIndex: i, frameOffset: first.length, frameCount: second.length, }) + } } } @@ -140,4 +144,4 @@ export class RingInit { this.capacity = capacity } -} \ No newline at end of file +} From 14bb3e80b111b4a73fa0b6a4579e6264123c2afe Mon Sep 17 00:00:00 2001 From: Wanjohi <71614375+wanjohiryan@users.noreply.github.com> Date: Mon, 15 May 2023 23:50:17 +0300 Subject: [PATCH 2/2] Fix for endIndex == 0 breaking audio The audio seems to break whenever endIndex goes to O, making "second" variable a ``bash Float32Array [buffer: SharedArrayBuffer(17640), byteLength: 0, byteOffset: 0, length: 0, Symbol(Symbol.toStringTag): 'Float32Array'] buffer:SharedArrayBuffer(17640) byteLength:0 byteOffset:0 length: 0 Symbol(Symbol.toStringTag): "Float32Array" [[Prototype]]:TypedArray `` --- player/src/audio/ring.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/player/src/audio/ring.ts b/player/src/audio/ring.ts index 3eaef49..7c95144 100644 --- a/player/src/audio/ring.ts +++ b/player/src/audio/ring.ts @@ -50,7 +50,9 @@ export class Ring { planeIndex: i, frameCount: count, }) - } else { + //audio seems to be breaking whenever endIndex is 0 + //this works, without "chopiness" + } else if (startIndex >= endIndex && endIndex != 0) { const first = channel.subarray(startIndex) const second = channel.subarray(0, endIndex) @@ -59,15 +61,12 @@ export class Ring { frameCount: first.length, }) - //For some reason this breaks audio... and this is my temporary fix //console.log("frame offset", first.length , "frame count", second.length) to test - if (first.length < second.length) { frame.copyTo(second, { planeIndex: i, frameOffset: first.length, frameCount: second.length, }) - } } }