mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-16 00:27:58 +00:00
ability to get buffer values at a given time
This commit is contained in:
parent
b9cef1feb8
commit
f687bb8a11
1 changed files with 17 additions and 3 deletions
|
@ -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)){
|
||||
|
|
Loading…
Reference in a new issue