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)){
|
||||
|
@ -83,7 +97,7 @@ define(["Tone/core/Tone"], function (Tone) {
|
|||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
var array = buffer.toArray();
|
||||
for (i = start; i < end; i++){
|
||||
|
@ -126,7 +140,7 @@ define(["Tone/core/Tone"], function (Tone) {
|
|||
var val;
|
||||
buffer.toMono().forEach(function(sample){
|
||||
if (typeof val === "undefined"){
|
||||
val = sample;
|
||||
val = sample;
|
||||
} else if (Math.abs(val - sample) > 0.0001){
|
||||
throw new Error("multiple values in buffer");
|
||||
}
|
||||
|
@ -134,4 +148,4 @@ define(["Tone/core/Tone"], function (Tone) {
|
|||
return val;
|
||||
};
|
||||
};
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue