tone 15.2.1 → 15.2.3
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.ts +11 -11
- package/Tone/component/analysis/Follower.test.ts +38 -42
- package/Tone/component/analysis/MeterBase.ts +1 -1
- package/Tone/component/channel/Channel.test.ts +3 -4
- package/Tone/component/channel/Merge.test.ts +5 -6
- package/Tone/component/channel/MidSideSplit.test.ts +21 -25
- package/Tone/component/channel/Mono.test.ts +18 -20
- package/Tone/component/channel/PanVol.test.ts +3 -4
- package/Tone/component/channel/Panner.test.ts +28 -32
- package/Tone/component/channel/Recorder.ts +1 -1
- package/Tone/component/channel/Volume.test.ts +9 -12
- package/Tone/component/dynamics/Gate.test.ts +10 -14
- package/Tone/component/envelope/AmplitudeEnvelope.test.ts +7 -9
- package/Tone/component/envelope/Envelope.test.ts +347 -384
- package/Tone/component/envelope/Envelope.ts +1 -1
- package/Tone/component/filter/BiquadFilter.test.ts +5 -6
- package/Tone/component/filter/Convolver.test.ts +6 -9
- package/Tone/component/filter/FeedbackCombFilter.test.ts +14 -16
- package/Tone/component/filter/Filter.test.ts +5 -6
- package/Tone/component/filter/LowpassCombFilter.test.ts +15 -17
- package/Tone/component/filter/LowpassCombFilter.ts +1 -1
- package/Tone/core/clock/Clock.test.ts +18 -21
- package/Tone/core/clock/TickParam.ts +1 -1
- package/Tone/core/clock/TickSignal.test.ts +24 -27
- package/Tone/core/clock/TickSource.test.ts +1 -1
- package/Tone/core/clock/Transport.test.ts +133 -162
- package/Tone/core/clock/TransportEvent.test.ts +3 -4
- package/Tone/core/clock/TransportRepeatEvent.test.ts +6 -6
- package/Tone/core/context/Context.test.ts +8 -10
- package/Tone/core/context/Context.ts +1 -1
- package/Tone/core/context/Destination.test.ts +3 -4
- package/Tone/core/context/Offline.test.ts +23 -41
- package/Tone/core/context/OfflineContext.test.ts +20 -22
- package/Tone/core/context/Param.test.ts +33 -40
- package/Tone/core/context/ToneAudioBuffer.test.ts +4 -11
- package/Tone/core/context/ToneAudioBuffers.test.ts +10 -14
- package/Tone/core/context/ToneAudioBuffers.ts +2 -2
- package/Tone/core/type/Frequency.test.ts +6 -6
- package/Tone/core/type/Ticks.test.ts +1 -1
- package/Tone/core/type/Time.test.ts +2 -2
- package/Tone/core/type/TransportTime.test.ts +1 -1
- package/Tone/core/util/IntervalTimeline.test.ts +1 -1
- package/Tone/core/util/IntervalTimeline.ts +1 -1
- package/Tone/core/util/StateTimeline.test.ts +2 -2
- package/Tone/core/util/Timeline.test.ts +1 -1
- package/Tone/core/util/Timeline.ts +1 -1
- package/Tone/core/worklet/ToneAudioWorklet.ts +3 -1
- package/Tone/effect/AutoFilter.test.ts +10 -12
- package/Tone/effect/AutoPanner.test.ts +10 -12
- package/Tone/effect/AutoWah.ts +1 -1
- package/Tone/effect/Chorus.test.ts +10 -14
- package/Tone/effect/FrequencyShifter.test.ts +6 -7
- package/Tone/effect/FrequencyShifter.ts +1 -1
- package/Tone/effect/MidSideEffect.ts +1 -1
- package/Tone/effect/Reverb.test.ts +12 -15
- package/Tone/effect/StereoWidener.ts +1 -1
- package/Tone/effect/Tremolo.test.ts +10 -12
- package/Tone/effect/Vibrato.ts +1 -1
- package/Tone/event/Loop.test.ts +29 -36
- package/Tone/event/Part.test.ts +156 -184
- package/Tone/event/Part.ts +5 -5
- package/Tone/event/Pattern.test.ts +16 -20
- package/Tone/event/Sequence.test.ts +88 -103
- package/Tone/event/Sequence.ts +1 -1
- package/Tone/event/ToneEvent.test.ts +60 -70
- package/Tone/instrument/Instrument.ts +1 -1
- package/Tone/instrument/MonoSynth.test.ts +3 -4
- package/Tone/instrument/PolySynth.test.ts +62 -74
- package/Tone/instrument/PolySynth.ts +1 -1
- package/Tone/instrument/Sampler.test.ts +39 -48
- package/Tone/instrument/Synth.test.ts +41 -48
- package/Tone/signal/AudioToGain.test.ts +4 -5
- package/Tone/signal/Multiply.test.ts +1 -1
- package/Tone/signal/Negate.test.ts +2 -2
- package/Tone/signal/Signal.test.ts +120 -143
- package/Tone/signal/Signal.ts +1 -1
- package/Tone/signal/SyncedSignal.test.ts +108 -122
- package/Tone/signal/ToneConstantSource.test.ts +21 -25
- package/Tone/signal/WaveShaper.test.ts +5 -6
- package/Tone/source/Source.test.ts +43 -49
- package/Tone/source/UserMedia.test.ts +1 -2
- package/Tone/source/buffer/GrainPlayer.test.ts +29 -35
- package/Tone/source/buffer/Player.test.ts +162 -191
- package/Tone/source/buffer/Players.test.ts +44 -50
- package/Tone/source/buffer/Players.ts +1 -1
- package/Tone/source/buffer/ToneBufferSource.test.ts +176 -211
- package/Tone/source/oscillator/LFO.test.ts +49 -61
- package/Tone/source/oscillator/OmniOscillator.ts +0 -1
- package/Tone/source/oscillator/Oscillator.test.ts +24 -28
- package/Tone/source/oscillator/PulseOscillator.test.ts +36 -40
- package/Tone/source/oscillator/ToneOscillatorNode.test.ts +25 -29
- 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 +1 -1
- package/build/esm/component/analysis/Analyser.js +11 -11
- package/build/esm/component/analysis/MeterBase.d.ts +1 -1
- package/build/esm/component/channel/Recorder.js.map +1 -1
- package/build/esm/component/envelope/Envelope.d.ts +1 -1
- package/build/esm/component/filter/LowpassCombFilter.d.ts +1 -1
- package/build/esm/core/clock/TickParam.js +1 -1
- package/build/esm/core/clock/TickParam.js.map +1 -1
- package/build/esm/core/context/Context.d.ts +1 -1
- package/build/esm/core/context/Context.js +1 -1
- package/build/esm/core/context/ToneAudioBuffers.d.ts +2 -2
- package/build/esm/core/context/ToneAudioBuffers.js +2 -2
- package/build/esm/core/util/IntervalTimeline.d.ts +1 -1
- package/build/esm/core/util/IntervalTimeline.js +1 -1
- package/build/esm/core/util/Timeline.d.ts +1 -1
- package/build/esm/core/util/Timeline.js +1 -1
- package/build/esm/core/worklet/ToneAudioWorklet.js.map +1 -1
- package/build/esm/effect/AutoWah.d.ts +1 -1
- package/build/esm/effect/FrequencyShifter.d.ts +1 -1
- package/build/esm/effect/FrequencyShifter.js +1 -1
- package/build/esm/effect/MidSideEffect.d.ts +1 -1
- package/build/esm/effect/MidSideEffect.js +1 -1
- package/build/esm/effect/StereoWidener.d.ts +1 -1
- package/build/esm/effect/StereoWidener.js +1 -1
- package/build/esm/effect/Vibrato.js +1 -1
- package/build/esm/effect/Vibrato.js.map +1 -1
- package/build/esm/event/Part.d.ts +2 -2
- package/build/esm/event/Part.js +5 -5
- package/build/esm/event/Part.js.map +1 -1
- package/build/esm/event/Sequence.d.ts +1 -1
- package/build/esm/instrument/Instrument.d.ts +1 -1
- package/build/esm/instrument/PolySynth.d.ts +1 -1
- package/build/esm/instrument/PolySynth.js +1 -1
- package/build/esm/signal/Signal.d.ts +1 -1
- package/build/esm/signal/Signal.js +1 -1
- package/build/esm/source/buffer/Players.d.ts +1 -1
- package/build/esm/source/buffer/Players.js +1 -1
- package/build/esm/source/oscillator/OmniOscillator.js +0 -1
- package/build/esm/source/oscillator/OmniOscillator.js.map +1 -1
- package/build/esm/version.js +1 -1
- package/package.json +3 -1
|
@@ -4,8 +4,8 @@ import { TransportClass } from "./Transport.js";
|
|
|
4
4
|
import { TransportRepeatEvent } from "./TransportRepeatEvent.js";
|
|
5
5
|
|
|
6
6
|
describe("TransportRepeatEvent", () => {
|
|
7
|
-
it("can be created and disposed", () => {
|
|
8
|
-
|
|
7
|
+
it("can be created and disposed", async () => {
|
|
8
|
+
await Offline((context) => {
|
|
9
9
|
const transport = new TransportClass({ context });
|
|
10
10
|
const event = new TransportRepeatEvent(transport, {
|
|
11
11
|
duration: 100,
|
|
@@ -16,8 +16,8 @@ describe("TransportRepeatEvent", () => {
|
|
|
16
16
|
});
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
-
it("generates a unique event ID", () => {
|
|
20
|
-
|
|
19
|
+
it("generates a unique event ID", async () => {
|
|
20
|
+
await Offline((context) => {
|
|
21
21
|
const transport = new TransportClass({ context });
|
|
22
22
|
const event = new TransportRepeatEvent(transport, {
|
|
23
23
|
time: 0,
|
|
@@ -27,8 +27,8 @@ describe("TransportRepeatEvent", () => {
|
|
|
27
27
|
});
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
-
it("is removed from the Transport when disposed", () => {
|
|
31
|
-
|
|
30
|
+
it("is removed from the Transport when disposed", async () => {
|
|
31
|
+
await Offline((context) => {
|
|
32
32
|
const transport = new TransportClass({ context });
|
|
33
33
|
const event = new TransportRepeatEvent(transport, {
|
|
34
34
|
time: 0,
|
|
@@ -279,20 +279,19 @@ describe("Context", () => {
|
|
|
279
279
|
}, 0.01);
|
|
280
280
|
});
|
|
281
281
|
|
|
282
|
-
it("is invoked in the offline context", () => {
|
|
282
|
+
it("is invoked in the offline context", async () => {
|
|
283
283
|
let invocationCount = 0;
|
|
284
|
-
|
|
284
|
+
await Offline((context) => {
|
|
285
285
|
context.setInterval(() => {
|
|
286
286
|
invocationCount++;
|
|
287
287
|
}, 0.01);
|
|
288
|
-
}, 0.051)
|
|
289
|
-
|
|
290
|
-
});
|
|
288
|
+
}, 0.051);
|
|
289
|
+
expect(invocationCount).to.equal(4);
|
|
291
290
|
});
|
|
292
291
|
|
|
293
|
-
it("is invoked
|
|
292
|
+
it("is invoked with the right interval", async () => {
|
|
294
293
|
let numberOfInvocations = 0;
|
|
295
|
-
|
|
294
|
+
await Offline((context) => {
|
|
296
295
|
let intervalTime = context.now();
|
|
297
296
|
context.setInterval(() => {
|
|
298
297
|
expect(context.now() - intervalTime).to.be.closeTo(
|
|
@@ -302,9 +301,8 @@ describe("Context", () => {
|
|
|
302
301
|
intervalTime = context.now();
|
|
303
302
|
numberOfInvocations++;
|
|
304
303
|
}, 0.01);
|
|
305
|
-
}, 0.051)
|
|
306
|
-
|
|
307
|
-
});
|
|
304
|
+
}, 0.051);
|
|
305
|
+
expect(numberOfInvocations).to.equal(4);
|
|
308
306
|
});
|
|
309
307
|
});
|
|
310
308
|
|
|
@@ -394,7 +394,7 @@ export class Context extends BaseContext {
|
|
|
394
394
|
/**
|
|
395
395
|
* How often the interval callback is invoked.
|
|
396
396
|
* This number corresponds to how responsive the scheduling
|
|
397
|
-
* can be. Setting to 0 will result in the lowest
|
|
397
|
+
* can be. Setting to 0 will result in the lowest practical interval
|
|
398
398
|
* based on context properties. context.updateInterval + context.lookAhead
|
|
399
399
|
* gives you the total latency between scheduling an event and hearing it.
|
|
400
400
|
*/
|
|
@@ -26,13 +26,12 @@ describe("Destination", () => {
|
|
|
26
26
|
});
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
it("passes no audio when muted", () => {
|
|
30
|
-
|
|
29
|
+
it("passes no audio when muted", async () => {
|
|
30
|
+
const buffer = await Offline((context) => {
|
|
31
31
|
new Oscillator().toDestination().start(0);
|
|
32
32
|
context.destination.mute = true;
|
|
33
|
-
}).then((buffer) => {
|
|
34
|
-
expect(buffer.isSilent()).to.equal(true);
|
|
35
33
|
});
|
|
34
|
+
expect(buffer.isSilent()).to.equal(true);
|
|
36
35
|
});
|
|
37
36
|
|
|
38
37
|
it("has a master volume control", () => {
|
|
@@ -16,63 +16,45 @@ describe("Offline", () => {
|
|
|
16
16
|
return ret;
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
-
it("generates a buffer", () => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
});
|
|
19
|
+
it("generates a buffer", async () => {
|
|
20
|
+
const buffer = await Offline(noOp, 0.01);
|
|
21
|
+
expect(buffer).to.be.instanceOf(ToneAudioBuffer);
|
|
23
22
|
});
|
|
24
23
|
|
|
25
|
-
it("silent by default", () => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
});
|
|
24
|
+
it("silent by default", async () => {
|
|
25
|
+
const buffer = await Offline(noOp, 0.01, 1);
|
|
26
|
+
const isSilent = buffer.toArray().every((sample) => sample === 0);
|
|
27
|
+
expect(isSilent).to.equal(true);
|
|
30
28
|
});
|
|
31
29
|
|
|
32
|
-
it("records the master output", () => {
|
|
33
|
-
|
|
30
|
+
it("records the master output", async () => {
|
|
31
|
+
const buffer = await Offline(() => {
|
|
34
32
|
new ToneOscillatorNode().toDestination().start();
|
|
35
|
-
}, 0.01)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
});
|
|
33
|
+
}, 0.01);
|
|
34
|
+
const testBuff = new TestAudioBuffer(buffer.get() as AudioBuffer);
|
|
35
|
+
expect(testBuff.isSilent()).is.equal(false);
|
|
39
36
|
});
|
|
40
37
|
|
|
41
|
-
it("returning a promise defers the rendering till the promise resolves", () => {
|
|
38
|
+
it("returning a promise defers the rendering till the promise resolves", async () => {
|
|
42
39
|
let wasInvoked = false;
|
|
43
|
-
|
|
40
|
+
const buffer = await Offline(() => {
|
|
44
41
|
new ToneOscillatorNode().toDestination().start();
|
|
45
42
|
return new Promise((done) => {
|
|
46
43
|
setTimeout(done, 100);
|
|
47
44
|
}).then(() => {
|
|
48
45
|
wasInvoked = true;
|
|
49
46
|
});
|
|
50
|
-
}, 0.01)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
});
|
|
47
|
+
}, 0.01);
|
|
48
|
+
const testBuff = new TestAudioBuffer(buffer.get() as AudioBuffer);
|
|
49
|
+
expect(wasInvoked).is.equal(true);
|
|
50
|
+
expect(testBuff.isSilent()).to.equal(false);
|
|
55
51
|
});
|
|
56
52
|
|
|
57
|
-
it("can schedule specific timing outputs", () => {
|
|
58
|
-
|
|
53
|
+
it("can schedule specific timing outputs", async () => {
|
|
54
|
+
const buffer = await Offline(() => {
|
|
59
55
|
new ToneOscillatorNode().toDestination().start(0.05);
|
|
60
|
-
}, 0.1)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
56
|
+
}, 0.1);
|
|
57
|
+
const testBuff = new TestAudioBuffer(buffer.get() as AudioBuffer);
|
|
58
|
+
expect(testBuff.getTimeOfFirstSound()).to.be.closeTo(0.05, 0.0001);
|
|
64
59
|
});
|
|
65
|
-
|
|
66
|
-
// it("can schedule Transport events", () => {
|
|
67
|
-
// return Offline(function (Transport) {
|
|
68
|
-
// var osc = new Oscillator().toDestination();
|
|
69
|
-
// Transport.schedule(function (time) {
|
|
70
|
-
// osc.start(time);
|
|
71
|
-
// }, 0.05);
|
|
72
|
-
// Transport.start(0);
|
|
73
|
-
// }, 0.1).then((buffer) => {
|
|
74
|
-
// BufferTest(buffer);
|
|
75
|
-
// expect(buffer.getFirstSoundTime()).to.be.closeTo(0.05, 0.001);
|
|
76
|
-
// });
|
|
77
|
-
// });
|
|
78
60
|
});
|
|
@@ -25,39 +25,37 @@ context("OfflineContext", () => {
|
|
|
25
25
|
return ctx.close();
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
it("can render audio", () => {
|
|
28
|
+
it("can render audio", async () => {
|
|
29
29
|
const ctx = new OfflineContext(1, 0.2, 44100);
|
|
30
30
|
const osc = ctx.createOscillator();
|
|
31
31
|
osc.connect(ctx.rawContext.destination);
|
|
32
32
|
osc.start(0.1);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
33
|
+
const buffer = await ctx.render();
|
|
34
|
+
expect(buffer).to.have.property("length");
|
|
35
|
+
expect(buffer).to.have.property("sampleRate");
|
|
36
|
+
const array = buffer.getChannelData(0);
|
|
37
|
+
for (let i = 0; i < array.length; i++) {
|
|
38
|
+
if (array[i] !== 0) {
|
|
39
|
+
expect(i / array.length).to.be.closeTo(0.5, 0.01);
|
|
40
|
+
break;
|
|
42
41
|
}
|
|
43
|
-
}
|
|
42
|
+
}
|
|
44
43
|
});
|
|
45
44
|
|
|
46
|
-
it("can render audio not async", () => {
|
|
45
|
+
it("can render audio not async", async () => {
|
|
47
46
|
const ctx = new OfflineContext(1, 0.2, 44100);
|
|
48
47
|
const osc = ctx.createOscillator();
|
|
49
48
|
osc.connect(ctx.rawContext.destination);
|
|
50
49
|
osc.start(0.1);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
50
|
+
const buffer = await ctx.render(false);
|
|
51
|
+
expect(buffer).to.have.property("length");
|
|
52
|
+
expect(buffer).to.have.property("sampleRate");
|
|
53
|
+
const array = buffer.getChannelData(0);
|
|
54
|
+
for (let i = 0; i < array.length; i++) {
|
|
55
|
+
if (array[i] !== 0) {
|
|
56
|
+
expect(i / array.length).to.be.closeTo(0.5, 0.01);
|
|
57
|
+
break;
|
|
60
58
|
}
|
|
61
|
-
}
|
|
59
|
+
}
|
|
62
60
|
});
|
|
63
61
|
});
|
|
@@ -308,9 +308,9 @@ describe("Param", () => {
|
|
|
308
308
|
});
|
|
309
309
|
|
|
310
310
|
context("apply", () => {
|
|
311
|
-
it("can apply a scheduled curve", () => {
|
|
311
|
+
it("can apply a scheduled curve", async () => {
|
|
312
312
|
let sig;
|
|
313
|
-
|
|
313
|
+
const buffer = await Offline((context) => {
|
|
314
314
|
const signal = new Signal();
|
|
315
315
|
sig = signal;
|
|
316
316
|
signal.setValueAtTime(0, 0);
|
|
@@ -325,20 +325,18 @@ describe("Param", () => {
|
|
|
325
325
|
return atTime(0.4, () => {
|
|
326
326
|
signal.apply(source.offset);
|
|
327
327
|
});
|
|
328
|
-
}, 2)
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
document.body.appendChild(await Plot.signal(buffer));
|
|
336
|
-
});
|
|
328
|
+
}, 2);
|
|
329
|
+
for (let time = 0.41; time < 2; time += 0.1) {
|
|
330
|
+
expect(buffer.getValueAtTime(time)).to.be.closeTo(
|
|
331
|
+
sig.getValueAtTime(time),
|
|
332
|
+
0.01
|
|
333
|
+
);
|
|
334
|
+
}
|
|
337
335
|
});
|
|
338
336
|
|
|
339
|
-
it("can apply a scheduled curve that starts with a setTargetAtTime", () => {
|
|
337
|
+
it("can apply a scheduled curve that starts with a setTargetAtTime", async () => {
|
|
340
338
|
let sig;
|
|
341
|
-
|
|
339
|
+
const buffer = await Offline((context) => {
|
|
342
340
|
const signal = new Signal();
|
|
343
341
|
sig = signal;
|
|
344
342
|
signal.setTargetAtTime(2, 0, 0.2);
|
|
@@ -348,20 +346,18 @@ describe("Param", () => {
|
|
|
348
346
|
return atTime(0.4, () => {
|
|
349
347
|
signal.apply(source.offset);
|
|
350
348
|
});
|
|
351
|
-
}, 2)
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
// document.body.appendChild(await Plot.signal(buffer));
|
|
359
|
-
});
|
|
349
|
+
}, 2);
|
|
350
|
+
for (let time = 0.41; time < 2; time += 0.1) {
|
|
351
|
+
expect(buffer.getValueAtTime(time)).to.be.closeTo(
|
|
352
|
+
sig.getValueAtTime(time),
|
|
353
|
+
0.05
|
|
354
|
+
);
|
|
355
|
+
}
|
|
360
356
|
});
|
|
361
357
|
|
|
362
|
-
it("can apply a scheduled curve that starts with a setTargetAtTime and then schedules other things", () => {
|
|
358
|
+
it("can apply a scheduled curve that starts with a setTargetAtTime and then schedules other things", async () => {
|
|
363
359
|
let sig;
|
|
364
|
-
|
|
360
|
+
const buffer = await Offline((context) => {
|
|
365
361
|
const signal = new Signal();
|
|
366
362
|
sig = signal;
|
|
367
363
|
signal.setTargetAtTime(2, 0, 0.2);
|
|
@@ -373,19 +369,17 @@ describe("Param", () => {
|
|
|
373
369
|
return atTime(0.4, () => {
|
|
374
370
|
signal.apply(source.offset);
|
|
375
371
|
});
|
|
376
|
-
}, 2)
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
// document.body.appendChild(await Plot.signal(buffer));
|
|
384
|
-
});
|
|
372
|
+
}, 2);
|
|
373
|
+
for (let time = 0.41; time < 2; time += 0.1) {
|
|
374
|
+
expect(buffer.getValueAtTime(time)).to.be.closeTo(
|
|
375
|
+
sig.getValueAtTime(time),
|
|
376
|
+
0.05
|
|
377
|
+
);
|
|
378
|
+
}
|
|
385
379
|
});
|
|
386
380
|
|
|
387
|
-
it("can set the param if the Param is marked as swappable", () => {
|
|
388
|
-
|
|
381
|
+
it("can set the param if the Param is marked as swappable", async () => {
|
|
382
|
+
const buffer = await Offline((context) => {
|
|
389
383
|
const constSource = context.createConstantSource();
|
|
390
384
|
const param = new Param({
|
|
391
385
|
swappable: true,
|
|
@@ -398,11 +392,10 @@ describe("Param", () => {
|
|
|
398
392
|
constSource2.start(0);
|
|
399
393
|
param.setParam(constSource2.offset);
|
|
400
394
|
connect(constSource2, context.destination);
|
|
401
|
-
}, 0.5)
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
});
|
|
395
|
+
}, 0.5);
|
|
396
|
+
expect(buffer.getValueAtTime(0.1)).to.be.closeTo(0.1, 0.001);
|
|
397
|
+
expect(buffer.getValueAtTime(0.2)).to.be.closeTo(0.2, 0.001);
|
|
398
|
+
expect(buffer.getValueAtTime(0.3)).to.be.closeTo(0.3, 0.001);
|
|
406
399
|
});
|
|
407
400
|
|
|
408
401
|
it("throws an error if the param is not set to swappable", () => {
|
|
@@ -192,16 +192,9 @@ describe("ToneAudioBuffer", () => {
|
|
|
192
192
|
expect(hadError).to.equal(true);
|
|
193
193
|
});
|
|
194
194
|
|
|
195
|
-
it("instance .load method returns Promise", (
|
|
196
|
-
const
|
|
197
|
-
expect(
|
|
198
|
-
promise.then((buff) => {
|
|
199
|
-
expect(buff).to.be.instanceOf(ToneAudioBuffer);
|
|
200
|
-
done();
|
|
201
|
-
});
|
|
202
|
-
promise.catch(() => {
|
|
203
|
-
throw new Error("shouldn't invoke this function");
|
|
204
|
-
});
|
|
195
|
+
it("instance .load method returns Promise", async () => {
|
|
196
|
+
const buffer = await new ToneAudioBuffer().load(testFile);
|
|
197
|
+
expect(buffer).to.be.instanceOf(ToneAudioBuffer);
|
|
205
198
|
});
|
|
206
199
|
|
|
207
200
|
it("invokes the error callback if the file is corrupt", (done) => {
|
|
@@ -275,7 +268,7 @@ describe("ToneAudioBuffer", () => {
|
|
|
275
268
|
buffer.dispose();
|
|
276
269
|
});
|
|
277
270
|
|
|
278
|
-
it("can convert from a
|
|
271
|
+
it("can convert from a multidimensional array", () => {
|
|
279
272
|
const buffer = new ToneAudioBuffer();
|
|
280
273
|
const arr = [
|
|
281
274
|
new Float32Array(0.5 * buffer.sampleRate),
|
|
@@ -38,7 +38,7 @@ describe("ToneAudioBuffers", () => {
|
|
|
38
38
|
);
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
-
it("throws an error when it tries to get an object that
|
|
41
|
+
it("throws an error when it tries to get an object that doesn't exist", (done) => {
|
|
42
42
|
const buffer = new ToneAudioBuffers(
|
|
43
43
|
{
|
|
44
44
|
sine: testFile,
|
|
@@ -110,18 +110,16 @@ describe("ToneAudioBuffers", () => {
|
|
|
110
110
|
expect(buffer.loaded).to.be.false;
|
|
111
111
|
});
|
|
112
112
|
|
|
113
|
-
it("can load from a base url", (
|
|
113
|
+
it("can load from a base url", async () => {
|
|
114
114
|
const buffer = new ToneAudioBuffers(
|
|
115
115
|
{
|
|
116
116
|
hat: "hh.wav",
|
|
117
117
|
},
|
|
118
|
-
() => {
|
|
119
|
-
expect(buffer.get("hat")).to.be.instanceof(ToneAudioBuffer);
|
|
120
|
-
buffer.dispose();
|
|
121
|
-
done();
|
|
122
|
-
},
|
|
118
|
+
() => {},
|
|
123
119
|
"./test/audio/"
|
|
124
120
|
);
|
|
121
|
+
await ToneAudioBuffer.loaded();
|
|
122
|
+
expect(buffer.get("hat")).to.be.instanceof(ToneAudioBuffer);
|
|
125
123
|
});
|
|
126
124
|
|
|
127
125
|
it("can add a buffer", (done) => {
|
|
@@ -157,13 +155,11 @@ describe("ToneAudioBuffers", () => {
|
|
|
157
155
|
expect(buffer.get("name").get()).to.equal(buff.get());
|
|
158
156
|
});
|
|
159
157
|
|
|
160
|
-
it("can add an AudioBuffer", (
|
|
161
|
-
ToneAudioBuffer.load(testFile)
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
done();
|
|
166
|
-
});
|
|
158
|
+
it("can add an AudioBuffer", async () => {
|
|
159
|
+
const audioBuffer = await ToneAudioBuffer.load(testFile);
|
|
160
|
+
const buffer = new ToneAudioBuffers();
|
|
161
|
+
buffer.add("name", audioBuffer);
|
|
162
|
+
expect(buffer.get("name").get()).to.equal(audioBuffer);
|
|
167
163
|
});
|
|
168
164
|
|
|
169
165
|
it("can be constructed with ToneAudioBuffers", () => {
|
|
@@ -18,7 +18,7 @@ interface ToneAudioBuffersOptions {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
* A data structure for holding multiple buffers in a Map-like
|
|
21
|
+
* A data structure for holding multiple buffers in a Map-like data structure.
|
|
22
22
|
*
|
|
23
23
|
* @example
|
|
24
24
|
* const pianoSamples = new Tone.ToneAudioBuffers({
|
|
@@ -141,7 +141,7 @@ export class ToneAudioBuffers extends Tone {
|
|
|
141
141
|
/**
|
|
142
142
|
* Add a buffer by name and url to the Buffers
|
|
143
143
|
* @param name A unique name to give the buffer
|
|
144
|
-
* @param url Either the url of the
|
|
144
|
+
* @param url Either the url of the buffer, or a buffer which will be added with the given name.
|
|
145
145
|
* @param callback The callback to invoke when the url is loaded.
|
|
146
146
|
* @param onerror Invoked if the buffer can't be loaded
|
|
147
147
|
*/
|
|
@@ -112,27 +112,27 @@ describe("FrequencyClass", () => {
|
|
|
112
112
|
});
|
|
113
113
|
});
|
|
114
114
|
|
|
115
|
-
it("
|
|
115
|
+
it("evaluates hertz", () => {
|
|
116
116
|
expect(Frequency("1hz").valueOf()).to.equal(1);
|
|
117
117
|
expect(Frequency("2hz").valueOf()).to.equal(2);
|
|
118
118
|
expect(Frequency(4, "hz").valueOf()).to.equal(4);
|
|
119
119
|
expect(Frequency("0.25hz").valueOf()).to.equal(0.25);
|
|
120
120
|
});
|
|
121
121
|
|
|
122
|
-
it("
|
|
122
|
+
it("evaluates ticks", () => {
|
|
123
123
|
return Offline(({ transport }) => {
|
|
124
124
|
expect(Frequency(transport.PPQ, "i").valueOf()).to.equal(2);
|
|
125
125
|
expect(Frequency(1, "i").valueOf()).to.equal(transport.PPQ * 2);
|
|
126
126
|
});
|
|
127
127
|
});
|
|
128
128
|
|
|
129
|
-
it("
|
|
129
|
+
it("evaluates transport time", () => {
|
|
130
130
|
expect(Frequency("1:0").valueOf()).to.equal(0.5);
|
|
131
131
|
expect(Frequency("1:4:0").valueOf()).to.equal(0.25);
|
|
132
132
|
// expect(Frequency("2:1:0").valueOf()).to.equal(0.25);
|
|
133
133
|
});
|
|
134
134
|
|
|
135
|
-
it("
|
|
135
|
+
it("evaluates midi", () => {
|
|
136
136
|
expect(Frequency(48, "midi").valueOf()).to.be.closeTo(
|
|
137
137
|
TonalMidi.midiToFreq(48),
|
|
138
138
|
0.0001
|
|
@@ -143,7 +143,7 @@ describe("FrequencyClass", () => {
|
|
|
143
143
|
);
|
|
144
144
|
});
|
|
145
145
|
|
|
146
|
-
it("
|
|
146
|
+
it("evaluates hz", () => {
|
|
147
147
|
expect(Frequency(48, "hz").valueOf()).to.equal(48);
|
|
148
148
|
expect(Frequency(480, "hz").valueOf()).to.equal(480);
|
|
149
149
|
});
|
|
@@ -218,7 +218,7 @@ describe("FrequencyClass", () => {
|
|
|
218
218
|
);
|
|
219
219
|
});
|
|
220
220
|
|
|
221
|
-
it("can
|
|
221
|
+
it("can accommodate different concert tuning", () => {
|
|
222
222
|
FrequencyClass.A4 = 444;
|
|
223
223
|
expect(Frequency("C4").valueOf()).to.be.closeTo(
|
|
224
224
|
TonalMidi.midiToFreq(
|
|
@@ -133,7 +133,7 @@ describe("TicksClass", () => {
|
|
|
133
133
|
});
|
|
134
134
|
});
|
|
135
135
|
|
|
136
|
-
it("can get the next
|
|
136
|
+
it("can get the next subdivision when the transport is started", () => {
|
|
137
137
|
return Offline((context) => {
|
|
138
138
|
const transport = context.transport;
|
|
139
139
|
transport.start();
|
|
@@ -72,7 +72,7 @@ describe("TimeClass", () => {
|
|
|
72
72
|
});
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
-
it("
|
|
75
|
+
it("evaluates objects", () => {
|
|
76
76
|
return Offline(() => {
|
|
77
77
|
expect(Time({ "4n": 3 }).valueOf()).to.equal(1.5);
|
|
78
78
|
expect(Time({ "8t": 2, "1m": 3 }).valueOf()).to.be.closeTo(
|
|
@@ -98,7 +98,7 @@ describe("TimeClass", () => {
|
|
|
98
98
|
expect(Time(2).quantize(8, 0.75).valueOf()).to.equal(0.5);
|
|
99
99
|
});
|
|
100
100
|
|
|
101
|
-
it("can get the next
|
|
101
|
+
it("can get the next subdivision when the transport is started", () => {
|
|
102
102
|
return Offline((context) => {
|
|
103
103
|
const transport = context.transport;
|
|
104
104
|
transport.start(0.1);
|
|
@@ -116,7 +116,7 @@ describe("TransportTimeClass", () => {
|
|
|
116
116
|
});
|
|
117
117
|
});
|
|
118
118
|
|
|
119
|
-
it("can get the next
|
|
119
|
+
it("can get the next subdivision when the transport is started", () => {
|
|
120
120
|
return Offline((context) => {
|
|
121
121
|
const transport = context.transport;
|
|
122
122
|
transport.start();
|
|
@@ -26,7 +26,7 @@ describe("IntervalTimeline", () => {
|
|
|
26
26
|
sched.dispose();
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
it("computes the
|
|
29
|
+
it("computes the length of the timeline correctly after adding events", () => {
|
|
30
30
|
const sched = new IntervalTimeline();
|
|
31
31
|
sched.add({
|
|
32
32
|
duration: 0.2,
|
|
@@ -51,7 +51,7 @@ describe("StateTimeline", () => {
|
|
|
51
51
|
sched.dispose();
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
it("gets the last
|
|
54
|
+
it("gets the last occurrence of the state at or before the given time", () => {
|
|
55
55
|
const sched = new StateTimeline();
|
|
56
56
|
sched.setStateAtTime("started", 0);
|
|
57
57
|
sched.setStateAtTime("stopped", 1);
|
|
@@ -68,7 +68,7 @@ describe("StateTimeline", () => {
|
|
|
68
68
|
sched.dispose();
|
|
69
69
|
});
|
|
70
70
|
|
|
71
|
-
it("gets the next
|
|
71
|
+
it("gets the next occurrence of the state at or before the given time", () => {
|
|
72
72
|
const sched = new StateTimeline();
|
|
73
73
|
sched.setStateAtTime("started", 0);
|
|
74
74
|
sched.setStateAtTime("stopped", 1);
|
|
@@ -348,7 +348,7 @@ export class Timeline<GenericEvent extends TimelineEvent> extends Tone {
|
|
|
348
348
|
|
|
349
349
|
/**
|
|
350
350
|
* Iterate over everything in the array between the startTime and endTime.
|
|
351
|
-
* The
|
|
351
|
+
* The time range is inclusive of the startTime, but exclusive of the endTime.
|
|
352
352
|
* range = [startTime, endTime).
|
|
353
353
|
* @param startTime The time to check if items are before
|
|
354
354
|
* @param endTime The end of the test interval.
|
|
@@ -59,7 +59,9 @@ export abstract class ToneAudioWorklet<
|
|
|
59
59
|
this._dummyParam = this._dummyGain.gain;
|
|
60
60
|
|
|
61
61
|
// Register the processor
|
|
62
|
-
let workletPromise = ToneAudioWorklet._workletPromises.get(
|
|
62
|
+
let workletPromise = ToneAudioWorklet._workletPromises.get(
|
|
63
|
+
this.context
|
|
64
|
+
);
|
|
63
65
|
|
|
64
66
|
if (workletPromise === undefined) {
|
|
65
67
|
workletPromise = this.context.addAudioWorkletModule(blobUrl);
|