mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-16 08:38:00 +00:00
can pass in a loaded buffer, and also can set the buffer twice
fixes #392
This commit is contained in:
parent
ea938af717
commit
ec3362f89f
1 changed files with 20 additions and 2 deletions
|
@ -35,10 +35,15 @@ define(["../core/Tone", "../core/Buffer", "../effect/Effect"], function(Tone){
|
|||
* @private
|
||||
*/
|
||||
this._buffer = new Tone.Buffer(options.url, function(buffer){
|
||||
this._convolver.buffer = buffer.get();
|
||||
this.buffer = buffer.get();
|
||||
options.onload();
|
||||
}.bind(this));
|
||||
|
||||
//set if it's already loaded
|
||||
if (this._buffer.loaded){
|
||||
this.buffer = this._buffer;
|
||||
}
|
||||
|
||||
//initially set normalization
|
||||
this.normalize = options.normalize;
|
||||
|
||||
|
@ -65,10 +70,23 @@ define(["../core/Tone", "../core/Buffer", "../effect/Effect"], function(Tone){
|
|||
*/
|
||||
Object.defineProperty(Tone.Convolver.prototype, "buffer", {
|
||||
"get" : function(){
|
||||
return this._buffer.get();
|
||||
if (this._buffer.length){
|
||||
return this._buffer;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
"set" : function(buffer){
|
||||
this._buffer.set(buffer);
|
||||
//if it's already got a buffer, create a new one
|
||||
if (this._convolver.buffer){
|
||||
//disconnect the old one
|
||||
this.effectSend.disconnect();
|
||||
this._convolver.disconnect();
|
||||
//create and connect a new one
|
||||
this._convolver = this.context.createConvolver();
|
||||
this.connectEffect(this._convolver);
|
||||
}
|
||||
this._convolver.buffer = this._buffer.get();
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue