Fix audio crashing after some time.

This commit is contained in:
Luke Curley 2023-05-22 13:49:02 -07:00
parent 3f6ea42380
commit 4132d8db4d
1 changed files with 14 additions and 5 deletions

View File

@ -60,6 +60,12 @@ export class Ring {
} }
} }
// capacity = 1024
// read = 2048
// write = 3072
// startIndex = 0
// readIndex = 0
let startIndex = startPos % this.capacity; let startIndex = startPos % this.capacity;
let endIndex = endPos % this.capacity; let endIndex = endPos % this.capacity;
@ -84,11 +90,13 @@ export class Ring {
frameCount: first.length, frameCount: first.length,
}) })
frame.copyTo(second, { if (second.length > 0) {
planeIndex: i, frame.copyTo(second, {
frameOffset: first.length, planeIndex: i,
frameCount: second.length, frameOffset: first.length,
}) frameCount: second.length,
})
}
} }
} }
@ -142,6 +150,7 @@ export class Ring {
} }
size() { size() {
// TODO is this thread safe?
let readPos = Atomics.load(this.state, STATE.READ_POS) let readPos = Atomics.load(this.state, STATE.READ_POS)
let writePos = Atomics.load(this.state, STATE.WRITE_POS) let writePos = Atomics.load(this.state, STATE.WRITE_POS)