mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-16 08:38:00 +00:00
copyToChannel polyfill
This commit is contained in:
parent
84bbdb5c04
commit
5ab8f82d3e
1 changed files with 15 additions and 9 deletions
|
@ -2,6 +2,20 @@ define(["Tone/core/Tone", "Tone/core/Emitter", "Tone/type/Type"], function(Tone)
|
|||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* AudioBuffer.copyToChannel polyfill
|
||||
* @private
|
||||
*/
|
||||
if (window.AudioBuffer && !AudioBuffer.prototype.copyToChannel){
|
||||
AudioBuffer.prototype.copyToChannel = function(dest, chanNum, start){
|
||||
var channel = this.getChannelData(chanNum);
|
||||
start = start || 0;
|
||||
for (var i = start; i < channel.length; i++){
|
||||
channel[i-start] = dest[i];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @class Buffer loading and storage. Tone.Buffer is used internally by all
|
||||
* classes that make requests for audio files such as Tone.Player,
|
||||
|
@ -230,15 +244,7 @@ define(["Tone/core/Tone", "Tone/core/Emitter", "Tone/type/Type"], function(Tone)
|
|||
array = [array];
|
||||
}
|
||||
for (var c = 0; c < channels; c++){
|
||||
if (this.isFunction(buffer.copyToChannel)){
|
||||
buffer.copyToChannel(array[c], c);
|
||||
} else {
|
||||
var channel = buffer.getChannelData(c);
|
||||
var channelArray = array[c];
|
||||
for (var i = 0; i < channelArray.length; i++){
|
||||
channel[i] = channelArray[i];
|
||||
}
|
||||
}
|
||||
buffer.copyToChannel(array[c], c);
|
||||
}
|
||||
this._buffer = buffer;
|
||||
return this;
|
||||
|
|
Loading…
Reference in a new issue