1
- import { StereoEffect , StereoEffectOptions } from "../effect/StereoEffect " ;
2
- import { Degrees , Frequency , Milliseconds , NormalRange , Seconds } from "../core/type/Units" ;
1
+ import { StereoFeedbackEffect , StereoFeedbackEffectOptions } from "../effect/StereoFeedbackEffect " ;
2
+ import { Degrees , Frequency , Milliseconds , NormalRange , Seconds , Time } from "../core/type/Units" ;
3
3
import { ToneOscillatorType } from "../source/oscillator/OscillatorInterface" ;
4
4
import { optionsFromArguments } from "../core/util/Defaults" ;
5
5
import { LFO } from "../source/oscillator/LFO" ;
6
6
import { Delay } from "../core/context/Delay" ;
7
7
import { Signal } from "../signal/Signal" ;
8
8
import { readOnly } from "../core/util/Interface" ;
9
- import { Gain } from "../core/context/Gain" ;
10
9
11
- export interface ChorusOptions extends StereoEffectOptions {
10
+ export interface ChorusOptions extends StereoFeedbackEffectOptions {
12
11
frequency : Frequency ;
13
12
delayTime : Milliseconds ;
14
13
depth : NormalRange ;
@@ -30,7 +29,7 @@ export interface ChorusOptions extends StereoEffectOptions {
30
29
*
31
30
* @category Effect
32
31
*/
33
- export class Chorus extends StereoEffect < ChorusOptions > {
32
+ export class Chorus extends StereoFeedbackEffect < ChorusOptions > {
34
33
35
34
readonly name : string = "Chorus" ;
36
35
@@ -69,16 +68,6 @@ export class Chorus extends StereoEffect<ChorusOptions> {
69
68
*/
70
69
readonly frequency : Signal < "frequency" >
71
70
72
- /**
73
- * Pass the left signal through
74
- */
75
- private _passThroughL : Gain ;
76
-
77
- /**
78
- * Pass the right signal through
79
- */
80
- private _passThroughR : Gain ;
81
-
82
71
/**
83
72
* @param frequency The frequency of the LFO.
84
73
* @param delayTime The delay of the chorus effect in ms.
@@ -88,8 +77,8 @@ export class Chorus extends StereoEffect<ChorusOptions> {
88
77
constructor ( options ?: Partial < ChorusOptions > ) ;
89
78
constructor ( ) {
90
79
91
- super ( optionsFromArguments ( Chorus . getDefaults ( ) , arguments , [ "order " ] ) ) ;
92
- const options = optionsFromArguments ( Chorus . getDefaults ( ) , arguments , [ "order " ] ) ;
80
+ super ( optionsFromArguments ( Chorus . getDefaults ( ) , arguments , [ "frequency" , "delayTime" , "depth "] ) ) ;
81
+ const options = optionsFromArguments ( Chorus . getDefaults ( ) , arguments , [ "frequency" , "delayTime" , "depth "] ) ;
93
82
94
83
this . _depth = options . depth ;
95
84
this . _delayTime = options . delayTime / 1000 ;
@@ -108,8 +97,6 @@ export class Chorus extends StereoEffect<ChorusOptions> {
108
97
} ) ;
109
98
this . _delayNodeL = new Delay ( { context : this . context } ) ;
110
99
this . _delayNodeR = new Delay ( { context : this . context } ) ;
111
- this . _passThroughL = new Gain ( { context : this . context } ) ;
112
- this . _passThroughR = new Gain ( { context : this . context } ) ;
113
100
this . frequency = this . _lfoL . frequency ;
114
101
readOnly ( this , [ "frequency" ] ) ;
115
102
// have one LFO frequency control the other
@@ -118,28 +105,24 @@ export class Chorus extends StereoEffect<ChorusOptions> {
118
105
// connections
119
106
this . connectEffectLeft ( this . _delayNodeL ) ;
120
107
this . connectEffectRight ( this . _delayNodeR ) ;
121
- // and pass through to make the detune apparent
122
- this . connectEffectLeft ( this . _passThroughL ) ;
123
- this . connectEffectRight ( this . _passThroughR ) ;
124
108
// lfo setup
125
109
this . _lfoL . connect ( this . _delayNodeL . delayTime ) ;
126
110
this . _lfoR . connect ( this . _delayNodeR . delayTime ) ;
127
- // start the lfo
128
- this . _lfoL . start ( ) ;
129
- this . _lfoR . start ( ) ;
130
111
// set the initial values
131
112
this . depth = this . _depth ;
132
113
this . type = options . type ;
133
114
this . spread = options . spread ;
134
115
}
135
116
136
117
static getDefaults ( ) : ChorusOptions {
137
- return Object . assign ( StereoEffect . getDefaults ( ) , {
118
+ return Object . assign ( StereoFeedbackEffect . getDefaults ( ) , {
138
119
frequency : 1.5 ,
139
120
delayTime : 3.5 ,
140
121
depth : 0.7 ,
141
122
type : "sine" as "sine" ,
142
- spread : 180
123
+ spread : 180 ,
124
+ feedback : 0 ,
125
+ wet : 0.5 ,
143
126
} ) ;
144
127
}
145
128
@@ -195,14 +178,48 @@ export class Chorus extends StereoEffect<ChorusOptions> {
195
178
this . _lfoR . phase = ( spread / 2 ) + 90 ;
196
179
}
197
180
181
+ /**
182
+ * Start the effect.
183
+ */
184
+ start ( time ?: Time ) : this {
185
+ this . _lfoL . start ( time ) ;
186
+ this . _lfoR . start ( time ) ;
187
+ return this ;
188
+ }
189
+
190
+ /**
191
+ * Stop the lfo
192
+ */
193
+ stop ( time ?: Time ) : this {
194
+ this . _lfoL . stop ( time ) ;
195
+ this . _lfoR . stop ( time ) ;
196
+ return this ;
197
+ }
198
+
199
+ /**
200
+ * Sync the filter to the transport. See [[LFO.sync]]
201
+ */
202
+ sync ( ) : this {
203
+ this . _lfoL . sync ( ) ;
204
+ this . _lfoR . sync ( ) ;
205
+ return this ;
206
+ }
207
+
208
+ /**
209
+ * Unsync the filter from the transport.
210
+ */
211
+ unsync ( ) : this {
212
+ this . _lfoL . unsync ( ) ;
213
+ this . _lfoR . unsync ( ) ;
214
+ return this ;
215
+ }
216
+
198
217
dispose ( ) : this {
199
218
super . dispose ( ) ;
200
219
this . _lfoL . dispose ( ) ;
201
220
this . _lfoR . dispose ( ) ;
202
221
this . _delayNodeL . dispose ( ) ;
203
222
this . _delayNodeR . dispose ( ) ;
204
- this . _passThroughL . dispose ( ) ;
205
- this . _passThroughR . dispose ( ) ;
206
223
this . frequency . dispose ( ) ;
207
224
return this ;
208
225
}
0 commit comments