Skip to content

Commit

Permalink
fix #3200 soundfile dispose error in reference test
Browse files Browse the repository at this point in the history
Thanks, @Spongman, for the fix here: processing/p5.js-sound#320
  • Loading branch information
therewasaguy committed Sep 11, 2018
1 parent 0619818 commit 42dfcc7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
23 changes: 20 additions & 3 deletions lib/addons/p5.sound.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! p5.sound.js v0.3.9 2018-09-08 */
/*! p5.sound.js v0.3.9 2018-09-10 */
/**
* p5.sound extends p5 with <a href="http://caniuse.com/audio-api"
* target="_blank">Web Audio</a> functionality including audio input,
Expand Down Expand Up @@ -1060,15 +1060,21 @@ soundfile = function () {
request.onload = function () {
if (request.status === 200) {
// on sucess loading file:
if (!self.panner)
return;
ac.decodeAudioData(request.response, // success decoding buffer:
function (buff) {
if (!self.panner)
return;
self.buffer = buff;
self.panner.inputChannels(buff.numberOfChannels);
if (callback) {
callback(self);
}
}, // error decoding buffer. "e" is undefined in Chrome 11/22/2015
function () {
if (!self.panner)
return;
var err = new CustomError('decodeAudioData', errorTrace, self.url);
var msg = 'AudioContext error at decodeAudioData for ' + self.url;
if (errorCallback) {
Expand All @@ -1079,6 +1085,8 @@ soundfile = function () {
}
});
} else {
if (!self.panner)
return;
var err = new CustomError('loadSound', errorTrace, self.url);
var msg = 'Unable to load ' + self.url + '. The request status was: ' + request.status + ' (' + request.statusText + ')';
if (errorCallback) {
Expand All @@ -1104,7 +1112,11 @@ soundfile = function () {
} else if (this.file !== undefined) {
var reader = new FileReader();
reader.onload = function () {
if (!self.panner)
return;
ac.decodeAudioData(reader.result, function (buff) {
if (!self.panner)
return;
self.buffer = buff;
self.panner.inputChannels(buff.numberOfChannels);
if (callback) {
Expand All @@ -1113,6 +1125,8 @@ soundfile = function () {
});
};
reader.onerror = function (e) {
if (!self.panner)
return;
if (onerror) {
onerror(e);
}
Expand Down Expand Up @@ -2012,6 +2026,8 @@ soundfile = function () {
// Render the song
// act on the result
offlineContext.oncomplete = function (e) {
if (!self.panner)
return;
var filteredBuffer = e.renderedBuffer;
var bufferData = filteredBuffer.getChannelData(0);
// step 1:
Expand Down Expand Up @@ -2306,9 +2322,10 @@ soundfile = function () {
* <div><code>
* var inp, button, mySound;
* var fileName = 'cool';
* function setup() {
* function preload() {
* mySound = loadSound('assets/doorbell.mp3');
*
* }
* function setup() {
* btn = createButton('click to save file');
* btn.position(0, 0);
* btn.mouseClicked(handleMouseClick);
Expand Down
Loading

0 comments on commit 42dfcc7

Please sign in to comment.