mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-15 16:17:58 +00:00
feat: Convolver is just a wrapper around the ConvolverNode, no longer an effect
a more basic wrapper around the ConvolverNode which unlike the Convolver effect, does not have a dry/wet knob
This commit is contained in:
parent
34f731bf7b
commit
1668decf70
4 changed files with 23 additions and 22 deletions
|
@ -1,6 +1,5 @@
|
|||
import { expect } from "chai";
|
||||
import { BasicTests } from "test/helper/Basic";
|
||||
// import { EffectTests } from "test/helper/EffectTests";
|
||||
import { ToneAudioBuffer } from "Tone/core/context/ToneAudioBuffer";
|
||||
import { Convolver } from "./Convolver";
|
||||
|
||||
|
@ -21,11 +20,6 @@ describe("Convolver", () => {
|
|||
return ir.load(testFile);
|
||||
});
|
||||
|
||||
// the buffers are set to 44.1 Khz, but i always get this error:
|
||||
// Error: Failed to set the 'buffer' property on 'ConvolverNode':
|
||||
// The buffer sample rate of 48000 does not match the context rate of 44100 Hz.
|
||||
// EffectTests(Convolver, ir);
|
||||
|
||||
context("API", () => {
|
||||
|
||||
it("can pass in options in the constructor", () => {
|
|
@ -1,9 +1,10 @@
|
|||
import { ToneAudioBuffer } from "../core/context/ToneAudioBuffer";
|
||||
import { optionsFromArguments } from "../core/util/Defaults";
|
||||
import { noOp } from "../core/util/Interface";
|
||||
import { Effect, EffectOptions } from "./Effect";
|
||||
import { ToneAudioNode, ToneAudioNodeOptions } from "../../core/context/ToneAudioNode";
|
||||
import { ToneAudioBuffer } from "../../core/context/ToneAudioBuffer";
|
||||
import { optionsFromArguments } from "../../core/util/Defaults";
|
||||
import { Gain } from "../../core/context/Gain";
|
||||
import { noOp } from "../../core/util/Interface";
|
||||
|
||||
interface ToneConvolverOptions extends EffectOptions {
|
||||
export interface ConvolverOptions extends ToneAudioNodeOptions {
|
||||
onload: () => void;
|
||||
normalize: boolean;
|
||||
url?: string | AudioBuffer | ToneAudioBuffer;
|
||||
|
@ -18,12 +19,12 @@ interface ToneConvolverOptions extends EffectOptions {
|
|||
* @example
|
||||
* //initializing the convolver with an impulse response
|
||||
* var convolver = new Convolver("./path/to/ir.wav").toDestination();
|
||||
* @category Effect
|
||||
* @category Component
|
||||
*/
|
||||
export class Convolver extends Effect<ToneConvolverOptions> {
|
||||
export class Convolver extends ToneAudioNode<ConvolverOptions> {
|
||||
|
||||
readonly name: string = "Convolver";
|
||||
|
||||
|
||||
/**
|
||||
* The native ConvolverNode
|
||||
*/
|
||||
|
@ -34,12 +35,15 @@ export class Convolver extends Effect<ToneConvolverOptions> {
|
|||
*/
|
||||
private _buffer: ToneAudioBuffer;
|
||||
|
||||
readonly input: Gain;
|
||||
readonly output: Gain;
|
||||
|
||||
/**
|
||||
* @param url The URL of the impulse response or the ToneAudioBuffer containing the impulse response.
|
||||
* @param onload The callback to invoke when the url is loaded.
|
||||
*/
|
||||
constructor(url?: string | AudioBuffer | ToneAudioBuffer, onload?: () => void);
|
||||
constructor(options?: Partial<ToneConvolverOptions>);
|
||||
constructor(options?: Partial<ConvolverOptions>);
|
||||
constructor() {
|
||||
|
||||
super(optionsFromArguments(Convolver.getDefaults(), arguments, ["url", "onload"]));
|
||||
|
@ -50,7 +54,10 @@ export class Convolver extends Effect<ToneConvolverOptions> {
|
|||
options.onload();
|
||||
});
|
||||
|
||||
// set if it's already loaded
|
||||
this.input = new Gain({ context: this.context });
|
||||
this.output = new Gain({ context: this.context });
|
||||
|
||||
// set if it's already loaded, set it immediately
|
||||
if (this._buffer.loaded) {
|
||||
this.buffer = this._buffer;
|
||||
}
|
||||
|
@ -59,11 +66,11 @@ export class Convolver extends Effect<ToneConvolverOptions> {
|
|||
this.normalize = options.normalize;
|
||||
|
||||
// connect it up
|
||||
this.connectEffect(this._convolver);
|
||||
this.input.chain(this._convolver, this.output);
|
||||
}
|
||||
|
||||
static getDefaults(): ToneConvolverOptions {
|
||||
return Object.assign(Effect.getDefaults(), {
|
||||
static getDefaults(): ConvolverOptions {
|
||||
return Object.assign(ToneAudioNode.getDefaults(), {
|
||||
normalize: true,
|
||||
onload: noOp,
|
||||
});
|
||||
|
@ -96,11 +103,11 @@ export class Convolver extends Effect<ToneConvolverOptions> {
|
|||
// if it's already got a buffer, create a new one
|
||||
if (this._convolver.buffer) {
|
||||
// disconnect the old one
|
||||
this.effectSend.disconnect();
|
||||
this.input.disconnect();
|
||||
this._convolver.disconnect();
|
||||
// create and connect a new one
|
||||
this._convolver = this.context.createConvolver();
|
||||
this.connectEffect(this._convolver);
|
||||
this.input.connect(this._convolver);
|
||||
}
|
||||
const buff = this._buffer.get();
|
||||
this._convolver.buffer = buff ? buff : null;
|
|
@ -11,3 +11,4 @@ export * from "./dynamics/Compressor";
|
|||
export * from "./filter/OnePoleFilter";
|
||||
export * from "./filter/FeedbackCombFilter";
|
||||
export * from "./filter/LowpassCombFilter";
|
||||
export * from "./filter/Convolver";
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
export { FeedbackDelay } from "./FeedbackDelay";
|
||||
export { Convolver } from "./Convolver";
|
||||
export { Reverb } from "./Reverb";
|
||||
|
|
Loading…
Reference in a new issue