Skip to content

Commit 8617144

Browse files
(Gsoc'21)🔨Fixes a bug in soundfile.js
1 parent 3e87433 commit 8617144

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/soundfile.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,11 @@ class SoundFile {
515515
* </code></div>
516516
*/
517517
playMode(str) {
518-
var s = str.toLowerCase();
518+
var s = str.toLowerCase().trim();
519519

520520
// if restart, stop all other sounds from playing
521521
if (s === 'restart' && this.buffer && this.bufferSourceNode) {
522-
for (var i = 0; i < this.bufferSourceNodes.length - 1; i++) {
522+
for (var i = 0; i < this.bufferSourceNodes.length; i++) {
523523
var now = p5sound.audiocontext.currentTime;
524524
this.bufferSourceNodes[i].stop(now);
525525
}
@@ -715,10 +715,9 @@ class SoundFile {
715715
this._paused = false;
716716
} else if (this.buffer && this.bufferSourceNode) {
717717
var now = p5sound.audiocontext.currentTime;
718-
var t = time || 0;
719718
this.pauseTime = 0;
720-
this.bufferSourceNode.stop(now + t);
721-
this._counterNode.stop(now + t);
719+
this.bufferSourceNode.stop(now + time);
720+
this._counterNode.stop(now + time);
722721
this._playing = false;
723722
this._paused = false;
724723
}
@@ -999,7 +998,7 @@ class SoundFile {
999998
* @return {Number} [channels]
1000999
*/
10011000
channels() {
1002-
return this.buffer.numberOfChannels;
1001+
if (this.buffer) return this.buffer.numberOfChannels;
10031002
}
10041003

10051004
/**
@@ -1010,7 +1009,7 @@ class SoundFile {
10101009
* @return {Number} [sampleRate]
10111010
*/
10121011
sampleRate() {
1013-
return this.buffer.sampleRate;
1012+
if (this.buffer) return this.buffer.sampleRate;
10141013
}
10151014

10161015
/**
@@ -1022,7 +1021,7 @@ class SoundFile {
10221021
* @return {Number} [sampleCount]
10231022
*/
10241023
frames() {
1025-
return this.buffer.length;
1024+
if (this.buffer) return this.buffer.length;
10261025
}
10271026

10281027
/**
@@ -1045,7 +1044,7 @@ class SoundFile {
10451044
if (this.buffer) {
10461045
// set length to window's width if no length is provided
10471046
if (!length) {
1048-
length = window.width * 5;
1047+
length = window.innerWidth * 5;
10491048
}
10501049
if (this.buffer) {
10511050
var buffer = this.buffer;

0 commit comments

Comments
 (0)