ability to get buffer values at a given time

This commit is contained in:
Yotam Mann 2017-08-27 19:41:47 -04:00
parent b9cef1feb8
commit f687bb8a11

View file

@ -52,6 +52,20 @@ define(["Tone/core/Tone"], function (Tone) {
}
};
//returns the value at the given time
buffer.getValueAtTime = function(time){
var ret = [];
var sample = Math.round(time * buffer.context.sampleRate);
for (let i = 0; i < buffer.numberOfChannels; i++){
ret[i] = buffer.getChannelData(i)[sample];
}
if (ret.length === 1){
return ret[0]
} else {
return ret;
}
};
//return the time when the buffer is silent to the remainer of the buffer
buffer.getLastSoundTime = function(channelNum){
if (Tone.isUndef(channelNum)){