mirror of
https://github.com/whscullin/apple2js.git
synced 2024-01-12 14:14:38 +00:00
Feedback, prevent audio backlog
This commit is contained in:
parent
87e0d38582
commit
bb2b3736bc
|
@ -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 = [];
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user