1
- import { Param } from "../core/context/Param" ;
2
1
import { Frequency , NormalRange , Time } from "../core/type/Units" ;
3
2
import { LowpassCombFilter } from "../component/filter/LowpassCombFilter" ;
4
3
import { deepMerge } from "../core/util/Defaults" ;
5
4
import { optionsFromArguments } from "../core/util/Defaults" ;
6
5
import { RecursivePartial } from "../core/util/Interface" ;
7
- import { Signal } from "../signal/Signal" ;
8
6
import { Noise } from "../source/Noise" ;
9
7
import { Instrument , InstrumentOptions } from "./Instrument" ;
10
8
11
9
export interface PluckSynthOptions extends InstrumentOptions {
12
10
attackNoise : number ;
13
11
dampening : Frequency ;
14
12
resonance : NormalRange ;
13
+ release : Time ;
15
14
}
16
15
17
16
/**
18
- * Karplus-String string synthesis. Often out of tune.
19
- *
17
+ * Karplus-String string synthesis.
20
18
* @example
21
19
* var plucky = new Tone.PluckSynth().toDestination();
22
20
* plucky.triggerAttack("C4");
@@ -41,9 +39,14 @@ export class PluckSynth extends Instrument<PluckSynthOptions> {
41
39
attackNoise : number ;
42
40
43
41
/**
44
- * The resonance control .
42
+ * The amount of resonance of the pluck. Also correlates to the sustain duration .
45
43
*/
46
- readonly resonance : Param < NormalRange > ;
44
+ resonance : NormalRange ;
45
+
46
+ /**
47
+ * The release time which corresponds to a resonance ramp down to 0
48
+ */
49
+ release : Time ;
47
50
48
51
constructor ( options ?: RecursivePartial < PluckSynthOptions > )
49
52
constructor ( ) {
@@ -64,7 +67,8 @@ export class PluckSynth extends Instrument<PluckSynthOptions> {
64
67
resonance : options . resonance ,
65
68
} ) ;
66
69
67
- this . resonance = this . _lfcf . resonance ;
70
+ this . resonance = options . resonance ;
71
+ this . release = options . release ;
68
72
69
73
this . _noise . connect ( this . _lfcf ) ;
70
74
this . _lfcf . connect ( this . output ) ;
@@ -75,6 +79,7 @@ export class PluckSynth extends Instrument<PluckSynthOptions> {
75
79
attackNoise : 1 ,
76
80
dampening : 4000 ,
77
81
resonance : 0.7 ,
82
+ release : 1 ,
78
83
} ) ;
79
84
}
80
85
@@ -97,14 +102,16 @@ export class PluckSynth extends Instrument<PluckSynthOptions> {
97
102
this . _lfcf . delayTime . setValueAtTime ( delayAmount , time ) ;
98
103
this . _noise . start ( time ) ;
99
104
this . _noise . stop ( time + delayAmount * this . attackNoise ) ;
105
+ this . _lfcf . resonance . cancelScheduledValues ( time ) ;
106
+ this . _lfcf . resonance . setValueAtTime ( this . resonance , time ) ;
100
107
return this ;
101
108
}
102
109
103
110
/**
104
- * PluckSynths' trigger release method doesn't do anything .
111
+ * Ramp down the [[resonance]] to 0 over the duration of the release time .
105
112
*/
106
- triggerRelease ( ) : this{
107
- // does nothing
113
+ triggerRelease ( time ?: Time ) : this{
114
+ this . _lfcf . resonance . linearRampTo ( 0 , this . release , time ) ;
108
115
return this ;
109
116
}
110
117
0 commit comments