From 193f66fd2d4c81fa9dd32cdef33b897effdb13c9 Mon Sep 17 00:00:00 2001 From: System Administrator Date: Thu, 7 Dec 2017 16:27:28 -0800 Subject: [PATCH 1/3] Limit sound concurrency to 1 --- libs/music/sounds.ts | 4 ++++ sim/state/sounds.ts | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libs/music/sounds.ts b/libs/music/sounds.ts index 44c7cef0..dd8a1344 100644 --- a/libs/music/sounds.ts +++ b/libs/music/sounds.ts @@ -257,7 +257,11 @@ namespace sounds { namespace music { let numSoundsPlaying = 0; +<<<<<<< Updated upstream let soundsLimit = 3; +======= + const soundsLimit = 1; +>>>>>>> Stashed changes /** * Plays a sound diff --git a/sim/state/sounds.ts b/sim/state/sounds.ts index 4aa21738..e0c39dd4 100644 --- a/sim/state/sounds.ts +++ b/sim/state/sounds.ts @@ -6,6 +6,8 @@ namespace pxsim.music { } namespace pxsim.SoundMethods { + let numSoundsPlaying = 0; + const soundsLimit = 1; export function buffer(buf: RefBuffer) { return incr(buf) @@ -20,12 +22,17 @@ namespace pxsim.SoundMethods { } export function play(buf: RefBuffer, volume: number) { + if (numSoundsPlaying >= soundsLimit) { + return Promise.resolve(); + } return new Promise(resolve => { let url = "data:audio/wav;base64," + btoa(uint8ArrayToString(buf.data)) let audio = new Audio(url) audio.onended = () => { - resolve() + resolve(); + numSoundsPlaying--; } + numSoundsPlaying++; audio.play() }) } From 2d7a108e793cdbda23542549727e52597174800f Mon Sep 17 00:00:00 2001 From: System Administrator Date: Thu, 7 Dec 2017 16:28:30 -0800 Subject: [PATCH 2/3] Fix merge conflict --- libs/music/sounds.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libs/music/sounds.ts b/libs/music/sounds.ts index dd8a1344..8fe1a906 100644 --- a/libs/music/sounds.ts +++ b/libs/music/sounds.ts @@ -257,11 +257,7 @@ namespace sounds { namespace music { let numSoundsPlaying = 0; -<<<<<<< Updated upstream - let soundsLimit = 3; -======= const soundsLimit = 1; ->>>>>>> Stashed changes /** * Plays a sound From e87e1767b560b6d5fb23aeb8cfcd4ac70ebfcf9b Mon Sep 17 00:00:00 2001 From: Caitlin Hennessy Date: Fri, 8 Dec 2017 11:16:47 -0800 Subject: [PATCH 3/3] Null check --- sim/state/sounds.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sim/state/sounds.ts b/sim/state/sounds.ts index e0c39dd4..a43aacde 100644 --- a/sim/state/sounds.ts +++ b/sim/state/sounds.ts @@ -22,7 +22,7 @@ namespace pxsim.SoundMethods { } export function play(buf: RefBuffer, volume: number) { - if (numSoundsPlaying >= soundsLimit) { + if (!buf || numSoundsPlaying >= soundsLimit) { return Promise.resolve(); } return new Promise(resolve => {