tone 15.5.24 → 15.5.26
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.
- package/Tone/component/analysis/Analyser.test.ts +1 -1
- package/Tone/component/analysis/Analyser.ts +18 -11
- package/Tone/component/analysis/DCMeter.ts +1 -1
- package/Tone/component/analysis/FFT.ts +2 -2
- package/Tone/component/analysis/Meter.test.ts +1 -1
- package/Tone/component/analysis/Meter.ts +15 -11
- package/Tone/component/analysis/MeterBase.ts +3 -2
- package/Tone/component/analysis/Waveform.ts +2 -2
- package/Tone/component/dynamics/Gate.test.ts +2 -2
- package/Tone/signal/ToneConstantSource.test.ts +1 -1
- package/Tone/version.ts +1 -1
- package/build/Tone.js +1 -1
- package/build/Tone.js.map +1 -1
- package/build/esm/component/analysis/Analyser.d.ts +7 -7
- package/build/esm/component/analysis/Analyser.js.map +1 -1
- package/build/esm/component/analysis/DCMeter.d.ts +1 -1
- package/build/esm/component/analysis/DCMeter.js.map +1 -1
- package/build/esm/component/analysis/FFT.d.ts +1 -1
- package/build/esm/component/analysis/FFT.js.map +1 -1
- package/build/esm/component/analysis/Meter.d.ts +7 -7
- package/build/esm/component/analysis/Meter.js.map +1 -1
- package/build/esm/component/analysis/MeterBase.d.ts +2 -2
- package/build/esm/component/analysis/MeterBase.js.map +1 -1
- package/build/esm/component/analysis/Waveform.d.ts +1 -1
- package/build/esm/component/analysis/Waveform.js.map +1 -1
- package/build/esm/version.js +1 -1
- package/package.json +1 -1
|
@@ -12,11 +12,12 @@ import { Split } from "../channel/Split.js";
|
|
|
12
12
|
|
|
13
13
|
export type AnalyserType = "fft" | "waveform";
|
|
14
14
|
|
|
15
|
-
export interface AnalyserOptions extends
|
|
15
|
+
export interface AnalyserOptions<ChannelCount extends number>
|
|
16
|
+
extends ToneAudioNodeOptions {
|
|
16
17
|
size: PowerOfTwo;
|
|
17
18
|
type: AnalyserType;
|
|
18
19
|
smoothing: NormalRange;
|
|
19
|
-
channels:
|
|
20
|
+
channels: ChannelCount;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
/**
|
|
@@ -24,7 +25,9 @@ export interface AnalyserOptions extends ToneAudioNodeOptions {
|
|
|
24
25
|
* Extracts FFT or Waveform data from the incoming signal.
|
|
25
26
|
* @category Component
|
|
26
27
|
*/
|
|
27
|
-
export class Analyser extends ToneAudioNode<
|
|
28
|
+
export class Analyser<ChannelCount extends number = 1> extends ToneAudioNode<
|
|
29
|
+
AnalyserOptions<ChannelCount>
|
|
30
|
+
> {
|
|
28
31
|
readonly name: string = "Analyser";
|
|
29
32
|
|
|
30
33
|
readonly input: InputNode;
|
|
@@ -60,7 +63,7 @@ export class Analyser extends ToneAudioNode<AnalyserOptions> {
|
|
|
60
63
|
* @param size The size of the FFT. This must be a power of two in the range 16 to 16384.
|
|
61
64
|
*/
|
|
62
65
|
constructor(type?: AnalyserType, size?: number);
|
|
63
|
-
constructor(options?: Partial<AnalyserOptions
|
|
66
|
+
constructor(options?: Partial<AnalyserOptions<ChannelCount>>);
|
|
64
67
|
constructor() {
|
|
65
68
|
const options = optionsFromArguments(
|
|
66
69
|
Analyser.getDefaults(),
|
|
@@ -93,12 +96,12 @@ export class Analyser extends ToneAudioNode<AnalyserOptions> {
|
|
|
93
96
|
this.smoothing = options.smoothing;
|
|
94
97
|
}
|
|
95
98
|
|
|
96
|
-
static getDefaults(): AnalyserOptions {
|
|
99
|
+
static getDefaults(): AnalyserOptions<1> {
|
|
97
100
|
return Object.assign(ToneAudioNode.getDefaults(), {
|
|
98
101
|
size: 1024,
|
|
99
102
|
smoothing: 0.8,
|
|
100
103
|
type: "fft" as AnalyserType,
|
|
101
|
-
channels: 1,
|
|
104
|
+
channels: 1 as const,
|
|
102
105
|
});
|
|
103
106
|
}
|
|
104
107
|
|
|
@@ -108,7 +111,7 @@ export class Analyser extends ToneAudioNode<AnalyserOptions> {
|
|
|
108
111
|
* return an array of Float32Arrays where each index in the array
|
|
109
112
|
* represents the analysis done on a channel.
|
|
110
113
|
*/
|
|
111
|
-
getValue(): Float32Array
|
|
114
|
+
getValue(): ChannelCount extends 1 ? Float32Array : Float32Array[] {
|
|
112
115
|
this._analyzers.forEach((analyser, index) => {
|
|
113
116
|
const buffer = this._buffers[index];
|
|
114
117
|
if (this._type === "fft") {
|
|
@@ -118,9 +121,13 @@ export class Analyser extends ToneAudioNode<AnalyserOptions> {
|
|
|
118
121
|
}
|
|
119
122
|
});
|
|
120
123
|
if (this.channels === 1) {
|
|
121
|
-
return this._buffers[0]
|
|
124
|
+
return this._buffers[0] as ChannelCount extends 1
|
|
125
|
+
? Float32Array
|
|
126
|
+
: Float32Array[];
|
|
122
127
|
} else {
|
|
123
|
-
return this._buffers
|
|
128
|
+
return this._buffers as ChannelCount extends 1
|
|
129
|
+
? Float32Array
|
|
130
|
+
: Float32Array[];
|
|
124
131
|
}
|
|
125
132
|
}
|
|
126
133
|
|
|
@@ -141,8 +148,8 @@ export class Analyser extends ToneAudioNode<AnalyserOptions> {
|
|
|
141
148
|
* The number of channels the analyser does the analysis on. Channel
|
|
142
149
|
* separation is done using {@link Split}
|
|
143
150
|
*/
|
|
144
|
-
get channels():
|
|
145
|
-
return this._analyzers.length;
|
|
151
|
+
get channels(): ChannelCount {
|
|
152
|
+
return this._analyzers.length as ChannelCount;
|
|
146
153
|
}
|
|
147
154
|
|
|
148
155
|
/**
|
|
@@ -17,7 +17,7 @@ export type DCMeterOptions = MeterBaseOptions;
|
|
|
17
17
|
* const level = meter.getValue();
|
|
18
18
|
* @category Component
|
|
19
19
|
*/
|
|
20
|
-
export class DCMeter extends MeterBase<DCMeterOptions> {
|
|
20
|
+
export class DCMeter extends MeterBase<DCMeterOptions, 1> {
|
|
21
21
|
readonly name: string = "DCMeter";
|
|
22
22
|
|
|
23
23
|
constructor(options?: Partial<DCMeterOptions>);
|
|
@@ -16,7 +16,7 @@ export interface FFTOptions extends MeterBaseOptions {
|
|
|
16
16
|
* Read more about FFT algorithms on [Wikipedia] (https://en.wikipedia.org/wiki/Fast_Fourier_transform).
|
|
17
17
|
* @category Component
|
|
18
18
|
*/
|
|
19
|
-
export class FFT extends MeterBase<FFTOptions> {
|
|
19
|
+
export class FFT extends MeterBase<FFTOptions, 1> {
|
|
20
20
|
readonly name: string = "FFT";
|
|
21
21
|
|
|
22
22
|
/**
|
|
@@ -55,7 +55,7 @@ export class FFT extends MeterBase<FFTOptions> {
|
|
|
55
55
|
* Returns the frequency data of length {@link size} as a Float32Array of decibel values.
|
|
56
56
|
*/
|
|
57
57
|
getValue(): Float32Array {
|
|
58
|
-
const values = this._analyser.getValue()
|
|
58
|
+
const values = this._analyser.getValue();
|
|
59
59
|
return values.map((v) => (this.normalRange ? dbToGain(v) : v));
|
|
60
60
|
}
|
|
61
61
|
|
|
@@ -5,10 +5,11 @@ import { optionsFromArguments } from "../../core/util/Defaults.js";
|
|
|
5
5
|
import { Analyser } from "./Analyser.js";
|
|
6
6
|
import { MeterBase, MeterBaseOptions } from "./MeterBase.js";
|
|
7
7
|
|
|
8
|
-
export interface MeterOptions extends
|
|
8
|
+
export interface MeterOptions<ChannelCount extends number>
|
|
9
|
+
extends MeterBaseOptions {
|
|
9
10
|
smoothing: NormalRange;
|
|
10
11
|
normalRange: boolean;
|
|
11
|
-
channelCount:
|
|
12
|
+
channelCount: ChannelCount;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
/**
|
|
@@ -29,7 +30,10 @@ export interface MeterOptions extends MeterBaseOptions {
|
|
|
29
30
|
* setInterval(() => console.log(meter.getValue()), 100);
|
|
30
31
|
* @category Component
|
|
31
32
|
*/
|
|
32
|
-
export class Meter extends MeterBase<
|
|
33
|
+
export class Meter<ChannelCount extends number = 1> extends MeterBase<
|
|
34
|
+
MeterOptions<ChannelCount>,
|
|
35
|
+
ChannelCount
|
|
36
|
+
> {
|
|
33
37
|
readonly name: string = "Meter";
|
|
34
38
|
|
|
35
39
|
/**
|
|
@@ -53,7 +57,7 @@ export class Meter extends MeterBase<MeterOptions> {
|
|
|
53
57
|
* @param smoothing The amount of smoothing applied between frames.
|
|
54
58
|
*/
|
|
55
59
|
constructor(smoothing?: NormalRange);
|
|
56
|
-
constructor(options?: Partial<MeterOptions
|
|
60
|
+
constructor(options?: Partial<MeterOptions<ChannelCount>>);
|
|
57
61
|
constructor() {
|
|
58
62
|
const options = optionsFromArguments(Meter.getDefaults(), arguments, [
|
|
59
63
|
"smoothing",
|
|
@@ -67,7 +71,7 @@ export class Meter extends MeterBase<MeterOptions> {
|
|
|
67
71
|
context: this.context,
|
|
68
72
|
size: 256,
|
|
69
73
|
type: "waveform",
|
|
70
|
-
channels: options.channelCount,
|
|
74
|
+
channels: options.channelCount as ChannelCount,
|
|
71
75
|
});
|
|
72
76
|
|
|
73
77
|
this.smoothing = options.smoothing;
|
|
@@ -76,11 +80,11 @@ export class Meter extends MeterBase<MeterOptions> {
|
|
|
76
80
|
this._rms.fill(0);
|
|
77
81
|
}
|
|
78
82
|
|
|
79
|
-
static getDefaults(): MeterOptions {
|
|
83
|
+
static getDefaults(): MeterOptions<1> {
|
|
80
84
|
return Object.assign(MeterBase.getDefaults(), {
|
|
81
85
|
smoothing: 0.8,
|
|
82
86
|
normalRange: false,
|
|
83
|
-
channelCount: 1,
|
|
87
|
+
channelCount: 1 as const,
|
|
84
88
|
});
|
|
85
89
|
}
|
|
86
90
|
|
|
@@ -105,7 +109,7 @@ export class Meter extends MeterBase<MeterOptions> {
|
|
|
105
109
|
* representing the value of the input signal. When {@link channels} > 1,
|
|
106
110
|
* then each channel is returned as a value in a number array.
|
|
107
111
|
*/
|
|
108
|
-
getValue(): number
|
|
112
|
+
getValue(): ChannelCount extends 1 ? number : number[] {
|
|
109
113
|
const aValues = this._analyser.getValue();
|
|
110
114
|
const channelValues =
|
|
111
115
|
this.channels === 1
|
|
@@ -132,16 +136,16 @@ export class Meter extends MeterBase<MeterOptions> {
|
|
|
132
136
|
: gainToDb(this._rms[channel]);
|
|
133
137
|
});
|
|
134
138
|
if (this.channels === 1) {
|
|
135
|
-
return vals[0];
|
|
139
|
+
return vals[0] as ChannelCount extends 1 ? number : number[];
|
|
136
140
|
} else {
|
|
137
|
-
return vals;
|
|
141
|
+
return vals as ChannelCount extends 1 ? number : number[];
|
|
138
142
|
}
|
|
139
143
|
}
|
|
140
144
|
|
|
141
145
|
/**
|
|
142
146
|
* The number of channels of analysis.
|
|
143
147
|
*/
|
|
144
|
-
get channels():
|
|
148
|
+
get channels(): ChannelCount {
|
|
145
149
|
return this._analyser.channels;
|
|
146
150
|
}
|
|
147
151
|
|
|
@@ -14,6 +14,7 @@ export type MeterBaseOptions = ToneAudioNodeOptions;
|
|
|
14
14
|
*/
|
|
15
15
|
export class MeterBase<
|
|
16
16
|
Options extends MeterBaseOptions,
|
|
17
|
+
ChannelCount extends number,
|
|
17
18
|
> extends ToneAudioNode<Options> {
|
|
18
19
|
readonly name: string = "MeterBase";
|
|
19
20
|
|
|
@@ -30,7 +31,7 @@ export class MeterBase<
|
|
|
30
31
|
/**
|
|
31
32
|
* The analyser node for the incoming signal
|
|
32
33
|
*/
|
|
33
|
-
protected _analyser: Analyser
|
|
34
|
+
protected _analyser: Analyser<ChannelCount>;
|
|
34
35
|
|
|
35
36
|
constructor(options?: Partial<MeterBaseOptions>);
|
|
36
37
|
constructor() {
|
|
@@ -39,7 +40,7 @@ export class MeterBase<
|
|
|
39
40
|
this.input =
|
|
40
41
|
this.output =
|
|
41
42
|
this._analyser =
|
|
42
|
-
new Analyser({
|
|
43
|
+
new Analyser<ChannelCount>({
|
|
43
44
|
context: this.context,
|
|
44
45
|
size: 256,
|
|
45
46
|
type: "waveform",
|
|
@@ -13,7 +13,7 @@ export interface WaveformOptions extends MeterBaseOptions {
|
|
|
13
13
|
* Get the current waveform data of the connected audio source.
|
|
14
14
|
* @category Component
|
|
15
15
|
*/
|
|
16
|
-
export class Waveform extends MeterBase<WaveformOptions> {
|
|
16
|
+
export class Waveform extends MeterBase<WaveformOptions, 1> {
|
|
17
17
|
readonly name: string = "Waveform";
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -44,7 +44,7 @@ export class Waveform extends MeterBase<WaveformOptions> {
|
|
|
44
44
|
* represents a sample in the waveform.
|
|
45
45
|
*/
|
|
46
46
|
getValue(): Float32Array {
|
|
47
|
-
return this._analyser.getValue()
|
|
47
|
+
return this._analyser.getValue();
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
/**
|
|
@@ -10,7 +10,7 @@ import { Gate } from "./Gate.js";
|
|
|
10
10
|
describe("Gate", () => {
|
|
11
11
|
BasicTests(Gate);
|
|
12
12
|
|
|
13
|
-
it
|
|
13
|
+
it("matches a file", () => {
|
|
14
14
|
return CompareToFile(
|
|
15
15
|
() => {
|
|
16
16
|
const gate = new Gate(-10, 0.1).toDestination();
|
|
@@ -64,7 +64,7 @@ describe("Gate", () => {
|
|
|
64
64
|
sig.connect(gate);
|
|
65
65
|
gate.toDestination();
|
|
66
66
|
});
|
|
67
|
-
expect(buffer.
|
|
67
|
+
expect(buffer.max()).to.be.above(0);
|
|
68
68
|
});
|
|
69
69
|
});
|
|
70
70
|
});
|
|
@@ -184,7 +184,7 @@ describe("ToneConstantSource", () => {
|
|
|
184
184
|
});
|
|
185
185
|
});
|
|
186
186
|
|
|
187
|
-
context
|
|
187
|
+
context("Suspended AudioContext", () => {
|
|
188
188
|
it("does nothing when AudioContext returns to suspended", () => {
|
|
189
189
|
const context = new Context();
|
|
190
190
|
expect(context.state).to.equal("suspended");
|
package/Tone/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version: string = "15.5.
|
|
1
|
+
export const version: string = "15.5.26";
|