tone 15.5.0 → 15.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/Tone/core/context/OnRunning.test.ts +63 -0
  2. package/Tone/core/context/OnRunning.ts +26 -0
  3. package/Tone/core/context/ToneWithContext.test.ts +82 -0
  4. package/Tone/core/context/ToneWithContext.ts +24 -0
  5. package/Tone/core/util/Interface.ts +8 -2
  6. package/Tone/effect/FrequencyShifter.ts +5 -3
  7. package/Tone/effect/LFOStereoEffect.test.ts +85 -0
  8. package/Tone/effect/LFOStereoEffect.ts +136 -0
  9. package/Tone/effect/Phaser.ts +9 -45
  10. package/Tone/effect/PitchShift.ts +8 -5
  11. package/Tone/effect/StereoWidener.ts +12 -2
  12. package/Tone/effect/Tremolo.test.ts +0 -24
  13. package/Tone/effect/Tremolo.ts +13 -80
  14. package/Tone/effect/Vibrato.ts +5 -3
  15. package/Tone/signal/ToneConstantSource.ts +7 -19
  16. package/Tone/signal/WaveShaper.ts +15 -8
  17. package/Tone/version.ts +1 -1
  18. package/build/Tone.js +1 -1
  19. package/build/Tone.js.map +1 -1
  20. package/build/esm/core/context/OnRunning.d.ts +8 -0
  21. package/build/esm/core/context/OnRunning.js +21 -0
  22. package/build/esm/core/context/OnRunning.js.map +1 -0
  23. package/build/esm/core/context/ToneWithContext.d.ts +14 -0
  24. package/build/esm/core/context/ToneWithContext.js +18 -0
  25. package/build/esm/core/context/ToneWithContext.js.map +1 -1
  26. package/build/esm/core/util/Interface.d.ts +2 -2
  27. package/build/esm/core/util/Interface.js.map +1 -1
  28. package/build/esm/effect/FrequencyShifter.js +5 -3
  29. package/build/esm/effect/FrequencyShifter.js.map +1 -1
  30. package/build/esm/effect/LFOStereoEffect.d.ts +53 -0
  31. package/build/esm/effect/LFOStereoEffect.js +96 -0
  32. package/build/esm/effect/LFOStereoEffect.js.map +1 -0
  33. package/build/esm/effect/Phaser.d.ts +3 -16
  34. package/build/esm/effect/Phaser.js +6 -28
  35. package/build/esm/effect/Phaser.js.map +1 -1
  36. package/build/esm/effect/PitchShift.js +7 -5
  37. package/build/esm/effect/PitchShift.js.map +1 -1
  38. package/build/esm/effect/StereoWidener.d.ts +4 -0
  39. package/build/esm/effect/StereoWidener.js +7 -2
  40. package/build/esm/effect/StereoWidener.js.map +1 -1
  41. package/build/esm/effect/Tremolo.d.ts +4 -32
  42. package/build/esm/effect/Tremolo.js +9 -59
  43. package/build/esm/effect/Tremolo.js.map +1 -1
  44. package/build/esm/effect/Vibrato.js +4 -3
  45. package/build/esm/effect/Vibrato.js.map +1 -1
  46. package/build/esm/signal/ToneConstantSource.d.ts +1 -1
  47. package/build/esm/signal/ToneConstantSource.js +16 -27
  48. package/build/esm/signal/ToneConstantSource.js.map +1 -1
  49. package/build/esm/signal/WaveShaper.d.ts +5 -0
  50. package/build/esm/signal/WaveShaper.js +15 -7
  51. package/build/esm/signal/WaveShaper.js.map +1 -1
  52. package/build/esm/version.js +1 -1
  53. package/package.json +1 -1
@@ -1,13 +1,12 @@
1
1
  import { Gain } from "../core/context/Gain.js";
2
- import { Degrees, Frequency, NormalRange, Time } from "../core/type/Units.js";
2
+ import { Degrees, Frequency, NormalRange } from "../core/type/Units.js";
3
3
  import { optionsFromArguments } from "../core/util/Defaults.js";
4
4
  import { readOnly } from "../core/util/Interface.js";
5
5
  import { Signal } from "../signal/Signal.js";
6
- import { LFO } from "../source/oscillator/LFO.js";
7
6
  import { ToneOscillatorType } from "../source/oscillator/OscillatorInterface.js";
8
- import { StereoEffect, StereoEffectOptions } from "./StereoEffect.js";
7
+ import { LFOStereoEffect, LFOStereoEffectOptions } from "./LFOStereoEffect.js";
9
8
 
10
- export interface TremoloOptions extends StereoEffectOptions {
9
+ export interface TremoloOptions extends LFOStereoEffectOptions {
11
10
  frequency: Frequency;
12
11
  type: ToneOscillatorType;
13
12
  depth: NormalRange;
@@ -26,19 +25,9 @@ export interface TremoloOptions extends StereoEffectOptions {
26
25
  *
27
26
  * @category Effect
28
27
  */
29
- export class Tremolo extends StereoEffect<TremoloOptions> {
28
+ export class Tremolo extends LFOStereoEffect<TremoloOptions> {
30
29
  readonly name: string = "Tremolo";
31
30
 
32
- /**
33
- * The tremolo LFO in the left channel
34
- */
35
- private _lfoL: LFO;
36
-
37
- /**
38
- * The tremolo LFO in the left channel
39
- */
40
- private _lfoR: LFO;
41
-
42
31
  /**
43
32
  * Where the gain is multiplied
44
33
  */
@@ -49,11 +38,6 @@ export class Tremolo extends StereoEffect<TremoloOptions> {
49
38
  */
50
39
  private _amplitudeR: Gain;
51
40
 
52
- /**
53
- * The frequency of the tremolo.
54
- */
55
- readonly frequency: Signal<"frequency">;
56
-
57
41
  /**
58
42
  * The depth of the effect. A depth of 0, has no effect
59
43
  * on the amplitude, and a depth of 1 makes the amplitude
@@ -74,25 +58,16 @@ export class Tremolo extends StereoEffect<TremoloOptions> {
74
58
  ]);
75
59
  super(options);
76
60
 
77
- this._lfoL = new LFO({
78
- context: this.context,
79
- type: options.type,
80
- min: 1,
81
- max: 0,
82
- });
83
- this._lfoR = new LFO({
84
- context: this.context,
85
- type: options.type,
86
- min: 1,
87
- max: 0,
88
- });
61
+ // invert the lfo min/max so it moves from full gain to 0 gain
62
+ this._lfoL.min = 1;
63
+ this._lfoL.max = 0;
64
+ this._lfoR.min = 1;
65
+ this._lfoR.max = 0;
66
+ this.type = options.type;
67
+
89
68
  this._amplitudeL = new Gain({ context: this.context });
90
69
  this._amplitudeR = new Gain({ context: this.context });
91
- this.frequency = new Signal({
92
- context: this.context,
93
- value: options.frequency,
94
- units: "frequency",
95
- });
70
+
96
71
  this.depth = new Signal({
97
72
  context: this.context,
98
73
  value: options.depth,
@@ -104,13 +79,12 @@ export class Tremolo extends StereoEffect<TremoloOptions> {
104
79
  this.connectEffectRight(this._amplitudeR);
105
80
  this._lfoL.connect(this._amplitudeL.gain);
106
81
  this._lfoR.connect(this._amplitudeR.gain);
107
- this.frequency.fan(this._lfoL.frequency, this._lfoR.frequency);
108
82
  this.depth.fan(this._lfoR.amplitude, this._lfoL.amplitude);
109
83
  this.spread = options.spread;
110
84
  }
111
85
 
112
86
  static getDefaults(): TremoloOptions {
113
- return Object.assign(StereoEffect.getDefaults(), {
87
+ return Object.assign(LFOStereoEffect.getDefaults(), {
114
88
  frequency: 10,
115
89
  type: "sine" as const,
116
90
  depth: 0.5,
@@ -118,44 +92,6 @@ export class Tremolo extends StereoEffect<TremoloOptions> {
118
92
  });
119
93
  }
120
94
 
121
- /**
122
- * Start the tremolo.
123
- */
124
- start(time?: Time): this {
125
- this._lfoL.start(time);
126
- this._lfoR.start(time);
127
- return this;
128
- }
129
-
130
- /**
131
- * Stop the tremolo.
132
- */
133
- stop(time?: Time): this {
134
- this._lfoL.stop(time);
135
- this._lfoR.stop(time);
136
- return this;
137
- }
138
-
139
- /**
140
- * Sync the effect to the transport.
141
- */
142
- sync(): this {
143
- this._lfoL.sync();
144
- this._lfoR.sync();
145
- this.context.transport.syncSignal(this.frequency);
146
- return this;
147
- }
148
-
149
- /**
150
- * Unsync the filter from the transport
151
- */
152
- unsync(): this {
153
- this._lfoL.unsync();
154
- this._lfoR.unsync();
155
- this.context.transport.unsyncSignal(this.frequency);
156
- return this;
157
- }
158
-
159
95
  /**
160
96
  * The oscillator type.
161
97
  */
@@ -181,11 +117,8 @@ export class Tremolo extends StereoEffect<TremoloOptions> {
181
117
 
182
118
  dispose(): this {
183
119
  super.dispose();
184
- this._lfoL.dispose();
185
- this._lfoR.dispose();
186
120
  this._amplitudeL.dispose();
187
121
  this._amplitudeR.dispose();
188
- this.frequency.dispose();
189
122
  this.depth.dispose();
190
123
  return this;
191
124
  }
@@ -66,15 +66,17 @@ export class Vibrato extends Effect<VibratoOptions> {
66
66
  max: options.maxDelay,
67
67
  frequency: options.frequency,
68
68
  phase: -90, // offset the phase so the resting position is in the center
69
- })
70
- .start()
71
- .connect(this._delayNode.delayTime);
69
+ }).connect(this._delayNode.delayTime);
72
70
  this.frequency = this._lfo.frequency;
73
71
  this.depth = this._lfo.amplitude;
74
72
 
75
73
  this.depth.value = options.depth;
76
74
  readOnly(this, ["frequency", "depth"]);
77
75
  this.effectSend.chain(this._delayNode, this.effectReturn);
76
+
77
+ this._onContextRunning(() => {
78
+ this._lfo.start();
79
+ });
78
80
  }
79
81
 
80
82
  static getDefaults(): VibratoOptions {
@@ -49,24 +49,16 @@ export class ToneConstantSource<
49
49
  );
50
50
  super(options);
51
51
 
52
- const isSuspended =
53
- !this.context.isOffline && this.context.state !== "running";
54
-
55
- if (!isSuspended) {
56
- this._source = this.context.createConstantSource();
57
- connect(this._source, this._gainNode);
58
- } else {
59
- this.context.on("statechange", this._contextStarted);
60
- }
52
+ this._onContextRunning(() => this._contextStarted());
61
53
 
62
54
  this.offset = new Param({
63
55
  context: this.context,
64
56
  convert: options.convert,
65
- param: isSuspended
57
+ param: !this._source
66
58
  ? // placeholder param until the context is started
67
59
  this.context.createGain().gain
68
- : this._source?.offset,
69
- swappable: isSuspended,
60
+ : this._source.offset,
61
+ swappable: !this._source,
70
62
  units: options.units,
71
63
  value: options.offset,
72
64
  minValue: options.minValue,
@@ -85,17 +77,14 @@ export class ToneConstantSource<
85
77
  /**
86
78
  * Once the context is started, kick off source.
87
79
  */
88
- private readonly _contextStarted = (state: AudioContextState) => {
89
- if (state !== "running") {
90
- return;
91
- }
80
+ private _contextStarted() {
92
81
  this._source = this.context.createConstantSource();
93
82
  connect(this._source, this._gainNode);
94
- this.offset.setParam(this._source.offset);
83
+ this.offset?.setParam(this._source.offset);
95
84
  if (this.state === "started") {
96
85
  this._source.start(0);
97
86
  }
98
- };
87
+ }
99
88
 
100
89
  /**
101
90
  * Start the source node at the given time
@@ -123,7 +112,6 @@ export class ToneConstantSource<
123
112
  }
124
113
  this._source?.disconnect();
125
114
  this.offset.dispose();
126
- this.context.off("statechange", this._contextStarted);
127
115
  return this;
128
116
  }
129
117
  }
@@ -66,14 +66,9 @@ export class WaveShaper extends SignalOperator<WaveShaperOptions> {
66
66
  );
67
67
  super(options);
68
68
 
69
- if (
70
- isArray(options.mapping) ||
71
- options.mapping instanceof Float32Array
72
- ) {
73
- this.curve = Float32Array.from(options.mapping);
74
- } else if (isFunction(options.mapping)) {
75
- this.setMap(options.mapping, options.length);
76
- }
69
+ this._onContextRunning(() => {
70
+ this.initCurve(options.mapping, options.length);
71
+ });
77
72
  }
78
73
 
79
74
  static getDefaults(): WaveShaperOptions {
@@ -82,6 +77,18 @@ export class WaveShaper extends SignalOperator<WaveShaperOptions> {
82
77
  });
83
78
  }
84
79
 
80
+ /**
81
+ * Set the curve for the first time. This is run only after the audio context is
82
+ * running to avoid any context warnings.
83
+ */
84
+ private initCurve(mapping?: WaveShaperMapping, length?: number): void {
85
+ if (isArray(mapping) || mapping instanceof Float32Array) {
86
+ this.curve = Float32Array.from(mapping);
87
+ } else if (isFunction(mapping)) {
88
+ this.setMap(mapping, length);
89
+ }
90
+ }
91
+
85
92
  /**
86
93
  * Uses a mapping function to set the value of the curve.
87
94
  * @param mapping The function used to define the values.
package/Tone/version.ts CHANGED
@@ -1 +1 @@
1
- export const version: string = "15.5.0";
1
+ export const version: string = "15.5.2";