From 7f148b5c34b5b88856183de3f1f8fa86f565ece6 Mon Sep 17 00:00:00 2001 From: Yotam Mann Date: Wed, 25 Oct 2017 23:01:26 -0400 Subject: [PATCH] moving shim to another file --- Tone/core/Buffer.js | 25 ++----------------------- Tone/shim/AudioBuffer.js | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 23 deletions(-) create mode 100644 Tone/shim/AudioBuffer.js diff --git a/Tone/core/Buffer.js b/Tone/core/Buffer.js index 10d52fc3..3773deed 100644 --- a/Tone/core/Buffer.js +++ b/Tone/core/Buffer.js @@ -1,28 +1,7 @@ -define(["Tone/core/Tone", "Tone/core/Emitter", "Tone/type/Type"], function(Tone){ +define(["Tone/core/Tone", "Tone/core/Emitter", "Tone/type/Type", "Tone/shim/AudioBuffer"], function(Tone){ "use strict"; - /** - * AudioBuffer.copyToChannel polyfill - * @private - */ - if (window.AudioBuffer && !AudioBuffer.prototype.copyToChannel){ - AudioBuffer.prototype.copyToChannel = function(src, chanNum, start){ - var channel = this.getChannelData(chanNum); - start = start || 0; - for (var i = 0; i < channel.length; i++){ - channel[i+start] = src[i]; - } - }; - AudioBuffer.prototype.copyFromChannel = function(dest, chanNum, start){ - var channel = this.getChannelData(chanNum); - start = start || 0; - for (var i = 0; i < dest.length; i++){ - dest[i] = channel[i+start]; - } - }; - } - /** * @class Buffer loading and storage. Tone.Buffer is used internally by all * classes that make requests for audio files such as Tone.Player, @@ -371,7 +350,7 @@ define(["Tone/core/Tone", "Tone/core/Emitter", "Tone/type/Type"], function(Tone) //statically inherits Emitter methods Tone.Emitter.mixin(Tone.Buffer); - + /** * the static queue for all of the xhr requests * @type {Array} diff --git a/Tone/shim/AudioBuffer.js b/Tone/shim/AudioBuffer.js new file mode 100644 index 00000000..67e9847f --- /dev/null +++ b/Tone/shim/AudioBuffer.js @@ -0,0 +1,26 @@ +define(["Tone/core/Tone"], function(Tone){ + + /** + * AudioBuffer.copyTo/FromChannel polyfill + * @private + */ + if (Tone.supported){ + if(!AudioBuffer.prototype.copyToChannel){ + AudioBuffer.prototype.copyToChannel = function(src, chanNum, start){ + var channel = this.getChannelData(chanNum); + start = start || 0; + for (var i = 0; i < channel.length; i++){ + channel[i+start] = src[i]; + } + }; + AudioBuffer.prototype.copyFromChannel = function(dest, chanNum, start){ + var channel = this.getChannelData(chanNum); + start = start || 0; + for (var i = 0; i < dest.length; i++){ + dest[i] = channel[i+start]; + } + }; + } + } + +});