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" ;
5
6
6
- interface ToneConvolverOptions extends EffectOptions {
7
+ export interface ConvolverOptions extends ToneAudioNodeOptions {
7
8
onload : ( ) => void ;
8
9
normalize : boolean ;
9
10
url ?: string | AudioBuffer | ToneAudioBuffer ;
@@ -18,12 +19,12 @@ interface ToneConvolverOptions extends EffectOptions {
18
19
* @example
19
20
* //initializing the convolver with an impulse response
20
21
* var convolver = new Convolver("./path/to/ir.wav").toDestination();
21
- * @category Effect
22
+ * @category Component
22
23
*/
23
- export class Convolver extends Effect < ToneConvolverOptions > {
24
+ export class Convolver extends ToneAudioNode < ConvolverOptions > {
24
25
25
26
readonly name : string = "Convolver" ;
26
-
27
+
27
28
/**
28
29
* The native ConvolverNode
29
30
*/
@@ -34,12 +35,15 @@ export class Convolver extends Effect<ToneConvolverOptions> {
34
35
*/
35
36
private _buffer : ToneAudioBuffer ;
36
37
38
+ readonly input : Gain ;
39
+ readonly output : Gain ;
40
+
37
41
/**
38
42
* @param url The URL of the impulse response or the ToneAudioBuffer containing the impulse response.
39
43
* @param onload The callback to invoke when the url is loaded.
40
44
*/
41
45
constructor ( url ?: string | AudioBuffer | ToneAudioBuffer , onload ?: ( ) => void ) ;
42
- constructor ( options ?: Partial < ToneConvolverOptions > ) ;
46
+ constructor ( options ?: Partial < ConvolverOptions > ) ;
43
47
constructor ( ) {
44
48
45
49
super ( optionsFromArguments ( Convolver . getDefaults ( ) , arguments , [ "url" , "onload" ] ) ) ;
@@ -50,7 +54,10 @@ export class Convolver extends Effect<ToneConvolverOptions> {
50
54
options . onload ( ) ;
51
55
} ) ;
52
56
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
54
61
if ( this . _buffer . loaded ) {
55
62
this . buffer = this . _buffer ;
56
63
}
@@ -59,11 +66,11 @@ export class Convolver extends Effect<ToneConvolverOptions> {
59
66
this . normalize = options . normalize ;
60
67
61
68
// connect it up
62
- this . connectEffect ( this . _convolver ) ;
69
+ this . input . chain ( this . _convolver , this . output ) ;
63
70
}
64
71
65
- static getDefaults ( ) : ToneConvolverOptions {
66
- return Object . assign ( Effect . getDefaults ( ) , {
72
+ static getDefaults ( ) : ConvolverOptions {
73
+ return Object . assign ( ToneAudioNode . getDefaults ( ) , {
67
74
normalize : true ,
68
75
onload : noOp ,
69
76
} ) ;
@@ -96,11 +103,11 @@ export class Convolver extends Effect<ToneConvolverOptions> {
96
103
// if it's already got a buffer, create a new one
97
104
if ( this . _convolver . buffer ) {
98
105
// disconnect the old one
99
- this . effectSend . disconnect ( ) ;
106
+ this . input . disconnect ( ) ;
100
107
this . _convolver . disconnect ( ) ;
101
108
// create and connect a new one
102
109
this . _convolver = this . context . createConvolver ( ) ;
103
- this . connectEffect ( this . _convolver ) ;
110
+ this . input . connect ( this . _convolver ) ;
104
111
}
105
112
const buff = this . _buffer . get ( ) ;
106
113
this . _convolver . buffer = buff ? buff : null ;
0 commit comments