Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for passing audio data as an ArrayBuffer #1647

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/howler.core.min.js

Large diffs are not rendered by default.

36 changes: 25 additions & 11 deletions dist/howler.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@
self._rate = o.rate || 1;
self._sprite = o.sprite || {};
self._src = (typeof o.src !== 'string') ? o.src : [o.src];
self._arraybuffer = o.arraybuffer || null;
self._volume = o.volume !== undefined ? o.volume : 1;
self._xhr = {
method: o.xhr && o.xhr.method ? o.xhr.method : 'GET',
Expand Down Expand Up @@ -2167,6 +2168,10 @@
var self = this;
var isIOS = Howler._navigator && Howler._navigator.vendor.indexOf('Apple') >= 0;

if (!node.bufferSource) {
return self;
}

if (Howler._scratchBuffer && node.bufferSource) {
node.bufferSource.onended = null;
node.bufferSource.disconnect(0);
Expand Down Expand Up @@ -2378,6 +2383,7 @@
*/
var loadBuffer = function(self) {
var url = self._src;
var arraybuffer = self._arraybuffer;

// Check if the buffer has already been cached and use it instead.
if (cache[url]) {
Expand All @@ -2390,6 +2396,12 @@
return;
}

if(arraybuffer !== null)
{
decodeAudioData(arraybuffer, self);
return;
}

if (/^data:[^;]+;base64,/.test(url)) {
// Decode the base64 data URI without XHR, since some browsers don't support it.
var data = atob(url.split(',')[1]);
Expand Down Expand Up @@ -3099,26 +3111,28 @@
panningModel: typeof o.panningModel !== 'undefined' ? o.panningModel : pa.panningModel
};

// Update the panner values or create a new panner if none exists.
// Create a new panner node if one doesn't already exist.
var panner = sound._panner;
if (panner) {
panner.coneInnerAngle = pa.coneInnerAngle;
panner.coneOuterAngle = pa.coneOuterAngle;
panner.coneOuterGain = pa.coneOuterGain;
panner.distanceModel = pa.distanceModel;
panner.maxDistance = pa.maxDistance;
panner.refDistance = pa.refDistance;
panner.rolloffFactor = pa.rolloffFactor;
panner.panningModel = pa.panningModel;
} else {
if (!panner) {
// Make sure we have a position to setup the node with.
if (!sound._pos) {
sound._pos = self._pos || [0, 0, -0.5];
}

// Create a new panner node.
setupPanner(sound, 'spatial');
panner = sound._panner
}

// Update the panner values or create a new panner if none exists.
panner.coneInnerAngle = pa.coneInnerAngle;
panner.coneOuterAngle = pa.coneOuterAngle;
panner.coneOuterGain = pa.coneOuterGain;
panner.distanceModel = pa.distanceModel;
panner.maxDistance = pa.maxDistance;
panner.refDistance = pa.refDistance;
panner.rolloffFactor = pa.rolloffFactor;
panner.panningModel = pa.panningModel;
}
}

Expand Down
4 changes: 2 additions & 2 deletions dist/howler.min.js

Large diffs are not rendered by default.

Loading