Feedback, prevent audio backlog

This commit is contained in:
Will Scullin 2021-06-25 15:36:28 -07:00
parent 87e0d38582
commit bb2b3736bc
No known key found for this signature in database
GPG Key ID: 26DCD1042C6638CD
2 changed files with 15 additions and 5 deletions

View File

@ -54,8 +54,8 @@ export class Audio implements OptionHandler {
this.workletNode = new AudioWorkletNode(this.audioContext, 'audio_worker');
io.sampleRate(this.audioContext.sampleRate, QUANTUM_SIZE);
io.addSampleListener((sample: number[]) => {
if (this.sound) {
io.addSampleListener((sample) => {
if (this.sound && this.audioContext.state === 'running') {
this.workletNode.port.postMessage(sample);
}
});
@ -88,8 +88,8 @@ export class Audio implements OptionHandler {
this.audioNode.connect(this.audioContext.destination);
io.sampleRate(this.audioContext.sampleRate, SAMPLE_SIZE);
io.addSampleListener((sample: number[]) => {
if (this.sound) {
io.addSampleListener((sample) => {
if (this.sound && this.audioContext.state === 'running') {
if (this.samples.length < 5) {
this.samples.push(sample);
}
@ -107,7 +107,6 @@ export class Audio implements OptionHandler {
debug('Sound initialized');
}
autoStart = () => {
if (this.audioContext && !this.started) {
this.samples = [];

View File

@ -1,3 +1,13 @@
/* Copyright 2021 Will Scullin <scullin@scullinsteel.com>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation. No representations are made about the suitability of this
* software for any purpose. It is provided "as is" without express or
* implied warranty.
*/
declare global {
interface AudioWorkletProcessor {
@ -40,6 +50,7 @@ export class AppleAudioProcessor extends AudioWorkletProcessor {
}
}
// Keep alive indefinitely.
return true;
}
}