Skip to content

Commit 1668dec

Browse files
committed
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
1 parent 34f731b commit 1668dec

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

Tone/effect/Convolver.test.ts renamed to Tone/component/filter/Convolver.test.ts

-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { expect } from "chai";
22
import { BasicTests } from "test/helper/Basic";
3-
// import { EffectTests } from "test/helper/EffectTests";
43
import { ToneAudioBuffer } from "Tone/core/context/ToneAudioBuffer";
54
import { Convolver } from "./Convolver";
65

@@ -21,11 +20,6 @@ describe("Convolver", () => {
2120
return ir.load(testFile);
2221
});
2322

24-
// the buffers are set to 44.1 Khz, but i always get this error:
25-
// Error: Failed to set the 'buffer' property on 'ConvolverNode':
26-
// The buffer sample rate of 48000 does not match the context rate of 44100 Hz.
27-
// EffectTests(Convolver, ir);
28-
2923
context("API", () => {
3024

3125
it("can pass in options in the constructor", () => {

Tone/effect/Convolver.ts renamed to Tone/component/filter/Convolver.ts

+22-15
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { ToneAudioBuffer } from "../core/context/ToneAudioBuffer";
2-
import { optionsFromArguments } from "../core/util/Defaults";
3-
import { noOp } from "../core/util/Interface";
4-
import { Effect, EffectOptions } from "./Effect";
1+
import { ToneAudioNode, ToneAudioNodeOptions } from "../../core/context/ToneAudioNode";
2+
import { ToneAudioBuffer } from "../../core/context/ToneAudioBuffer";
3+
import { optionsFromArguments } from "../../core/util/Defaults";
4+
import { Gain } from "../../core/context/Gain";
5+
import { noOp } from "../../core/util/Interface";
56

6-
interface ToneConvolverOptions extends EffectOptions {
7+
export interface ConvolverOptions extends ToneAudioNodeOptions {
78
onload: () => void;
89
normalize: boolean;
910
url?: string | AudioBuffer | ToneAudioBuffer;
@@ -18,12 +19,12 @@ interface ToneConvolverOptions extends EffectOptions {
1819
* @example
1920
* //initializing the convolver with an impulse response
2021
* var convolver = new Convolver("./path/to/ir.wav").toDestination();
21-
* @category Effect
22+
* @category Component
2223
*/
23-
export class Convolver extends Effect<ToneConvolverOptions> {
24+
export class Convolver extends ToneAudioNode<ConvolverOptions> {
2425

2526
readonly name: string = "Convolver";
26-
27+
2728
/**
2829
* The native ConvolverNode
2930
*/
@@ -34,12 +35,15 @@ export class Convolver extends Effect<ToneConvolverOptions> {
3435
*/
3536
private _buffer: ToneAudioBuffer;
3637

38+
readonly input: Gain;
39+
readonly output: Gain;
40+
3741
/**
3842
* @param url The URL of the impulse response or the ToneAudioBuffer containing the impulse response.
3943
* @param onload The callback to invoke when the url is loaded.
4044
*/
4145
constructor(url?: string | AudioBuffer | ToneAudioBuffer, onload?: () => void);
42-
constructor(options?: Partial<ToneConvolverOptions>);
46+
constructor(options?: Partial<ConvolverOptions>);
4347
constructor() {
4448

4549
super(optionsFromArguments(Convolver.getDefaults(), arguments, ["url", "onload"]));
@@ -50,7 +54,10 @@ export class Convolver extends Effect<ToneConvolverOptions> {
5054
options.onload();
5155
});
5256

53-
// set if it's already loaded
57+
this.input = new Gain({ context: this.context });
58+
this.output = new Gain({ context: this.context });
59+
60+
// set if it's already loaded, set it immediately
5461
if (this._buffer.loaded) {
5562
this.buffer = this._buffer;
5663
}
@@ -59,11 +66,11 @@ export class Convolver extends Effect<ToneConvolverOptions> {
5966
this.normalize = options.normalize;
6067

6168
// connect it up
62-
this.connectEffect(this._convolver);
69+
this.input.chain(this._convolver, this.output);
6370
}
6471

65-
static getDefaults(): ToneConvolverOptions {
66-
return Object.assign(Effect.getDefaults(), {
72+
static getDefaults(): ConvolverOptions {
73+
return Object.assign(ToneAudioNode.getDefaults(), {
6774
normalize: true,
6875
onload: noOp,
6976
});
@@ -96,11 +103,11 @@ export class Convolver extends Effect<ToneConvolverOptions> {
96103
// if it's already got a buffer, create a new one
97104
if (this._convolver.buffer) {
98105
// disconnect the old one
99-
this.effectSend.disconnect();
106+
this.input.disconnect();
100107
this._convolver.disconnect();
101108
// create and connect a new one
102109
this._convolver = this.context.createConvolver();
103-
this.connectEffect(this._convolver);
110+
this.input.connect(this._convolver);
104111
}
105112
const buff = this._buffer.get();
106113
this._convolver.buffer = buff ? buff : null;

Tone/component/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ export * from "./dynamics/Compressor";
1111
export * from "./filter/OnePoleFilter";
1212
export * from "./filter/FeedbackCombFilter";
1313
export * from "./filter/LowpassCombFilter";
14+
export * from "./filter/Convolver";

Tone/effect/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export { FeedbackDelay } from "./FeedbackDelay";
2-
export { Convolver } from "./Convolver";
32
export { Reverb } from "./Reverb";

0 commit comments

Comments
 (0)