Skip to content

Commit

Permalink
Add early return for zero duration sounds (#932)
Browse files Browse the repository at this point in the history
* Add early return for zero duration sounds

* Change guard clause to include all non-positive durations
  • Loading branch information
iskandarzulkarnaien authored and geshuming committed Sep 13, 2019
1 parent ceaec63 commit 42bede0
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions public/externalLibs/sound/sounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ function play_unsafe(sound) {
// If a sound is already playing, terminate execution
} else if (_playing || _safeplaying) {
throw new Error("play: audio system still playing previous sound");
} else if (get_duration(sound) <= 0) {
return sound;
} else {
// Declaring duration and wave variables
var wave = get_wave(sound);
Expand Down Expand Up @@ -308,6 +310,8 @@ function play(sound) {
// If a sound is already playing, terminate execution.
if (_safeplaying || _playing) {
throw new Error("play: audio system still playing previous sound");
} else if (get_duration(sound) <= 0) {
return sound;
} else {
// Discretize the input sound
var data = discretize(get_wave(sound), get_duration(sound));
Expand Down

0 comments on commit 42bede0

Please sign in to comment.