From 4a49df6f3ec53042bca7b2318288599d78c31bf4 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Tue, 27 Aug 2019 21:04:52 -0400 Subject: [PATCH] audio: clear buffers when stopping in case browser keeps playing anyway --- doc/notes.txt | 1 - src/audio.ts | 8 +++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/doc/notes.txt b/doc/notes.txt index a2e6ce23..30e82cc4 100644 --- a/doc/notes.txt +++ b/doc/notes.txt @@ -178,7 +178,6 @@ TODO: - can't step back twice? - compiler bug in chase - "shared" in URL doesn't work, leave in URL? (also importURL) - - alert when skeleton file loaded or file not found - TypeError: null is not an object (evaluating 'n.destination') https://8bitworkshop.com/v3.4.1/javatari.js/release/javatari/javatari.js diff --git a/src/audio.ts b/src/audio.ts index 75eacf84..6d961e03 100644 --- a/src/audio.ts +++ b/src/audio.ts @@ -383,6 +383,12 @@ export var SampleAudio = function(clockfreq) { idrain = (idrain + 1) % bufferlist.length; } } + + function clearBuffers() { + if (bufferlist) + for (var buf of bufferlist) + buf.fill(0); + } function createContext() { var AudioContext = window['AudioContext'] || window['webkitAudioContext'] || window['mozAudioContext']; @@ -425,7 +431,6 @@ export var SampleAudio = function(clockfreq) { // Chrome autoplay (https://goo.gl/7K7WLu) if (this.context.state == 'suspended') { this.context.resume(); - console.log('AudioContext should resume'); } return; // already created } @@ -447,6 +452,7 @@ export var SampleAudio = function(clockfreq) { this.stop = function() { this.context && this.context.suspend(); + clearBuffers(); // just in case it doesn't stop immediately } this.close = function() {