tone 15.2.0 → 15.2.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.
- package/Tone/component/analysis/Follower.test.ts +38 -42
- 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/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/core/clock/Clock.test.ts +12 -15
- package/Tone/core/clock/TickSignal.test.ts +18 -21
- 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 +8 -4
- 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 +3 -10
- package/Tone/core/context/ToneAudioBuffers.test.ts +9 -13
- 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/Chorus.test.ts +10 -14
- package/Tone/effect/FrequencyShifter.test.ts +6 -7
- package/Tone/effect/Reverb.test.ts +12 -15
- package/Tone/effect/Tremolo.test.ts +10 -12
- package/Tone/event/Loop.test.ts +29 -36
- package/Tone/event/Part.test.ts +152 -180
- package/Tone/event/Pattern.test.ts +16 -20
- package/Tone/event/Sequence.test.ts +86 -101
- package/Tone/event/ToneEvent.test.ts +60 -70
- package/Tone/instrument/MonoSynth.test.ts +3 -4
- package/Tone/instrument/PolySynth.test.ts +62 -74
- package/Tone/instrument/Sampler.test.ts +39 -48
- package/Tone/instrument/Synth.test.ts +40 -47
- package/Tone/signal/AudioToGain.test.ts +4 -5
- package/Tone/signal/Signal.test.ts +120 -143
- 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 +42 -48
- 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/ToneBufferSource.test.ts +176 -211
- package/Tone/source/oscillator/LFO.test.ts +49 -61
- 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/channel/Recorder.js.map +1 -1
- package/build/esm/core/context/Context.js +6 -3
- package/build/esm/core/context/Context.js.map +1 -1
- package/build/esm/core/worklet/ToneAudioWorklet.js.map +1 -1
- package/build/esm/version.js +1 -1
- package/package.json +1 -1
|
@@ -115,97 +115,88 @@ describe("ToneBufferSource", () => {
|
|
|
115
115
|
player.dispose();
|
|
116
116
|
});
|
|
117
117
|
|
|
118
|
-
it("loops the audio", () => {
|
|
119
|
-
|
|
118
|
+
it("loops the audio", async () => {
|
|
119
|
+
const buff = await Offline(() => {
|
|
120
120
|
const player = new ToneBufferSource(buffer);
|
|
121
121
|
player.loop = true;
|
|
122
122
|
player.toDestination();
|
|
123
123
|
player.start(0);
|
|
124
|
-
}, buffer.duration * 2)
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
});
|
|
124
|
+
}, buffer.duration * 2);
|
|
125
|
+
expect(buff.getRmsAtTime(0)).to.be.above(0);
|
|
126
|
+
expect(buff.getRmsAtTime(buffer.duration * 0.5)).to.be.above(0);
|
|
127
|
+
expect(buff.getRmsAtTime(buffer.duration)).to.be.above(0);
|
|
128
|
+
expect(buff.getRmsAtTime(buffer.duration * 1.5)).to.be.above(0);
|
|
130
129
|
});
|
|
131
130
|
|
|
132
|
-
it("loops the audio when loop is set after 'start'", () => {
|
|
133
|
-
|
|
131
|
+
it("loops the audio when loop is set after 'start'", async () => {
|
|
132
|
+
const buff = await Offline(() => {
|
|
134
133
|
const player = new ToneBufferSource(buffer);
|
|
135
134
|
player.start(0);
|
|
136
135
|
player.loop = true;
|
|
137
136
|
player.toDestination();
|
|
138
|
-
}, buffer.duration * 2)
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
});
|
|
137
|
+
}, buffer.duration * 2);
|
|
138
|
+
expect(buff.getRmsAtTime(0)).to.be.above(0);
|
|
139
|
+
expect(buff.getRmsAtTime(buffer.duration * 0.5)).to.be.above(0);
|
|
140
|
+
expect(buff.getRmsAtTime(buffer.duration)).to.be.above(0);
|
|
141
|
+
expect(buff.getRmsAtTime(buffer.duration * 1.5)).to.be.above(0);
|
|
144
142
|
});
|
|
145
143
|
|
|
146
|
-
it("unloops the audio when loop is set after 'start'", () => {
|
|
147
|
-
|
|
144
|
+
it("unloops the audio when loop is set after 'start'", async () => {
|
|
145
|
+
const buff = await Offline(() => {
|
|
148
146
|
const player = new ToneBufferSource(buffer);
|
|
149
147
|
player.loop = true;
|
|
150
148
|
player.start(0);
|
|
151
149
|
player.loop = false;
|
|
152
150
|
player.toDestination();
|
|
153
|
-
}, buffer.duration * 2)
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
0,
|
|
162
|
-
0.001
|
|
163
|
-
);
|
|
164
|
-
});
|
|
151
|
+
}, buffer.duration * 2);
|
|
152
|
+
expect(buff.getRmsAtTime(0)).to.be.above(0);
|
|
153
|
+
expect(buff.getRmsAtTime(buffer.duration * 0.5)).to.be.above(0);
|
|
154
|
+
expect(buff.getRmsAtTime(buffer.duration)).to.be.closeTo(0, 0.001);
|
|
155
|
+
expect(buff.getRmsAtTime(buffer.duration * 1.5)).to.be.closeTo(
|
|
156
|
+
0,
|
|
157
|
+
0.001
|
|
158
|
+
);
|
|
165
159
|
});
|
|
166
160
|
|
|
167
|
-
it("loops the audio for the specific duration", () => {
|
|
161
|
+
it("loops the audio for the specific duration", async () => {
|
|
168
162
|
const playDur = buffer.duration * 1.5;
|
|
169
|
-
|
|
163
|
+
const buff = await Offline(() => {
|
|
170
164
|
const player = new ToneBufferSource(buffer);
|
|
171
165
|
player.loop = true;
|
|
172
166
|
player.toDestination();
|
|
173
167
|
player.start(0, 0, playDur);
|
|
174
|
-
}, buffer.duration * 2)
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
});
|
|
168
|
+
}, buffer.duration * 2);
|
|
169
|
+
expect(buff.getRmsAtTime(0)).to.be.above(0);
|
|
170
|
+
expect(buff.getRmsAtTime(buffer.duration)).to.be.above(0);
|
|
171
|
+
expect(buff.getRmsAtTime(playDur - 0.01)).to.be.above(0);
|
|
172
|
+
expect(buff.getRmsAtTime(playDur + 0.01)).to.equal(0);
|
|
180
173
|
});
|
|
181
174
|
|
|
182
|
-
it("starts at the loop start offset if looping", () => {
|
|
175
|
+
it("starts at the loop start offset if looping", async () => {
|
|
183
176
|
const offsetTime = 0.05;
|
|
184
177
|
const offsetSample =
|
|
185
178
|
buffer.toArray()[Math.floor(offsetTime * sampleRate)];
|
|
186
|
-
|
|
179
|
+
const buff = await Offline(() => {
|
|
187
180
|
const player = new ToneBufferSource(buffer).toDestination();
|
|
188
181
|
player.loop = true;
|
|
189
182
|
player.loopStart = offsetTime;
|
|
190
183
|
player.start(0);
|
|
191
|
-
}, 0.1)
|
|
192
|
-
|
|
193
|
-
});
|
|
184
|
+
}, 0.1);
|
|
185
|
+
expect(buff.getValueAtTime(0)).to.equal(offsetSample);
|
|
194
186
|
});
|
|
195
187
|
|
|
196
|
-
it("the offset is modulo the loopDuration", () => {
|
|
188
|
+
it("the offset is modulo the loopDuration", async () => {
|
|
197
189
|
const testSample = buffer.toArray()[
|
|
198
190
|
Math.floor(0.051 * sampleRate)
|
|
199
191
|
] as number;
|
|
200
|
-
|
|
192
|
+
const buff = await Offline(() => {
|
|
201
193
|
const player = new ToneBufferSource(buffer).toDestination();
|
|
202
194
|
player.loop = true;
|
|
203
195
|
player.loopStart = 0;
|
|
204
196
|
player.loopEnd = 0.1;
|
|
205
197
|
player.start(0, 0.351);
|
|
206
|
-
}, 0.1)
|
|
207
|
-
|
|
208
|
-
});
|
|
198
|
+
}, 0.1);
|
|
199
|
+
expect(buff.getValueAtTime(0)).to.be.closeTo(testSample, 1e-4);
|
|
209
200
|
});
|
|
210
201
|
});
|
|
211
202
|
|
|
@@ -247,42 +238,39 @@ describe("ToneBufferSource", () => {
|
|
|
247
238
|
};
|
|
248
239
|
});
|
|
249
240
|
|
|
250
|
-
it("schedules the onended callback when offline", () => {
|
|
241
|
+
it("schedules the onended callback when offline", async () => {
|
|
251
242
|
let wasInvoked = false;
|
|
252
|
-
|
|
243
|
+
await Offline(() => {
|
|
253
244
|
const player = new ToneBufferSource(buffer).toDestination();
|
|
254
245
|
player.start(0.2).stop(0.4);
|
|
255
246
|
player.onended = () => (wasInvoked = true);
|
|
256
|
-
}, 0.5)
|
|
257
|
-
|
|
258
|
-
});
|
|
247
|
+
}, 0.5);
|
|
248
|
+
expect(wasInvoked).to.equal(true);
|
|
259
249
|
});
|
|
260
250
|
|
|
261
|
-
it("invokes the onended callback when a looped buffer is scheduled to stop", () => {
|
|
251
|
+
it("invokes the onended callback when a looped buffer is scheduled to stop", async () => {
|
|
262
252
|
let wasInvoked = false;
|
|
263
|
-
|
|
253
|
+
await Offline(() => {
|
|
264
254
|
const player = new ToneBufferSource(buffer).toDestination();
|
|
265
255
|
player.loop = true;
|
|
266
256
|
player.start().stop(0.4);
|
|
267
257
|
player.onended = () => {
|
|
268
258
|
wasInvoked = true;
|
|
269
259
|
};
|
|
270
|
-
}, 0.5)
|
|
271
|
-
|
|
272
|
-
});
|
|
260
|
+
}, 0.5);
|
|
261
|
+
expect(wasInvoked).to.equal(true);
|
|
273
262
|
});
|
|
274
263
|
|
|
275
|
-
it("schedules the onended callback when the buffer is done without scheduling stop", () => {
|
|
264
|
+
it("schedules the onended callback when the buffer is done without scheduling stop", async () => {
|
|
276
265
|
let wasInvoked = false;
|
|
277
|
-
|
|
266
|
+
await Offline(() => {
|
|
278
267
|
const player = new ToneBufferSource(buffer).toDestination();
|
|
279
268
|
player.start(0);
|
|
280
269
|
player.onended = () => {
|
|
281
270
|
wasInvoked = true;
|
|
282
271
|
};
|
|
283
|
-
}, buffer.duration * 1.1)
|
|
284
|
-
|
|
285
|
-
});
|
|
272
|
+
}, buffer.duration * 1.1);
|
|
273
|
+
expect(wasInvoked).to.equal(true);
|
|
286
274
|
});
|
|
287
275
|
});
|
|
288
276
|
|
|
@@ -291,8 +279,8 @@ describe("ToneBufferSource", () => {
|
|
|
291
279
|
return buffer.load("./test/audio/sine.wav");
|
|
292
280
|
});
|
|
293
281
|
|
|
294
|
-
it("reports the right state when scheduled to stop", () => {
|
|
295
|
-
|
|
282
|
+
it("reports the right state when scheduled to stop", async () => {
|
|
283
|
+
await Offline(() => {
|
|
296
284
|
const player = new ToneBufferSource(buffer).toDestination();
|
|
297
285
|
player.start(0.2).stop(0.4);
|
|
298
286
|
|
|
@@ -306,8 +294,8 @@ describe("ToneBufferSource", () => {
|
|
|
306
294
|
}, 0.5);
|
|
307
295
|
});
|
|
308
296
|
|
|
309
|
-
it("reports the right state when duration is passed into start method", () => {
|
|
310
|
-
|
|
297
|
+
it("reports the right state when duration is passed into start method", async () => {
|
|
298
|
+
await Offline(() => {
|
|
311
299
|
const player = new ToneBufferSource(buffer).toDestination();
|
|
312
300
|
player.start(0, 0, 0.1);
|
|
313
301
|
|
|
@@ -327,8 +315,8 @@ describe("ToneBufferSource", () => {
|
|
|
327
315
|
return buffer.load("./test/audio/sine.wav");
|
|
328
316
|
});
|
|
329
317
|
|
|
330
|
-
it("can play for a specific duration", () => {
|
|
331
|
-
|
|
318
|
+
it("can play for a specific duration", async () => {
|
|
319
|
+
const rms = await Offline(() => {
|
|
332
320
|
const player = new ToneBufferSource(buffer).toDestination();
|
|
333
321
|
player.start(0).stop(0.1);
|
|
334
322
|
|
|
@@ -337,158 +325,141 @@ describe("ToneBufferSource", () => {
|
|
|
337
325
|
expect(player.state).to.equal("stopped");
|
|
338
326
|
}
|
|
339
327
|
};
|
|
340
|
-
}, 0.4)
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
expect(rms.getRmsAtTime(0.3)).to.equal(0);
|
|
346
|
-
});
|
|
328
|
+
}, 0.4);
|
|
329
|
+
expect(rms.getRmsAtTime(0)).to.be.gt(0);
|
|
330
|
+
expect(rms.getRmsAtTime(0.09)).to.be.gt(0);
|
|
331
|
+
expect(rms.getRmsAtTime(0.11)).to.equal(0);
|
|
332
|
+
expect(rms.getRmsAtTime(0.3)).to.equal(0);
|
|
347
333
|
});
|
|
348
334
|
|
|
349
|
-
it("can be scheduled to stop", () => {
|
|
350
|
-
|
|
335
|
+
it("can be scheduled to stop", async () => {
|
|
336
|
+
const rms = await Offline(() => {
|
|
351
337
|
const player = new ToneBufferSource(buffer).toDestination();
|
|
352
338
|
player.start(0).stop(0.1);
|
|
353
|
-
}, 0.6)
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
});
|
|
339
|
+
}, 0.6);
|
|
340
|
+
expect(rms.getRmsAtTime(0.01)).to.be.gt(0);
|
|
341
|
+
expect(rms.getRmsAtTime(0.08)).to.be.gt(0);
|
|
342
|
+
expect(rms.getRmsAtTime(0.11)).to.equal(0);
|
|
358
343
|
});
|
|
359
344
|
|
|
360
|
-
it("plays correctly when playbackRate is < 1", () => {
|
|
361
|
-
|
|
345
|
+
it("plays correctly when playbackRate is < 1", async () => {
|
|
346
|
+
const rms = await Offline(() => {
|
|
362
347
|
const player = new ToneBufferSource(buffer).toDestination();
|
|
363
348
|
player.start(0);
|
|
364
349
|
player.playbackRate.value = 0.75;
|
|
365
|
-
}, buffer.duration * 1.3)
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
});
|
|
350
|
+
}, buffer.duration * 1.3);
|
|
351
|
+
expect(rms.getRmsAtTime(0.01)).to.be.gt(0);
|
|
352
|
+
expect(rms.getRmsAtTime(0.1)).to.be.gt(0);
|
|
353
|
+
expect(rms.getRmsAtTime(0.2)).to.be.gt(0);
|
|
354
|
+
expect(rms.getRmsAtTime(buffer.duration)).to.be.gt(0);
|
|
371
355
|
});
|
|
372
356
|
|
|
373
|
-
it("plays correctly when playbackRate is > 1", () => {
|
|
374
|
-
|
|
357
|
+
it("plays correctly when playbackRate is > 1", async () => {
|
|
358
|
+
const rms = await Offline(() => {
|
|
375
359
|
const player = new ToneBufferSource(buffer).toDestination();
|
|
376
360
|
player.start(0);
|
|
377
361
|
player.playbackRate.value = 2;
|
|
378
|
-
}, buffer.duration)
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
0.01
|
|
384
|
-
);
|
|
385
|
-
expect(rms.getRmsAtTime(buffer.duration * 0.7)).to.closeTo(
|
|
386
|
-
0,
|
|
387
|
-
0.01
|
|
388
|
-
);
|
|
389
|
-
});
|
|
362
|
+
}, buffer.duration);
|
|
363
|
+
expect(rms.getRmsAtTime(0.03)).to.be.gt(0);
|
|
364
|
+
expect(rms.getRmsAtTime(buffer.duration * 0.45)).to.be.gt(0);
|
|
365
|
+
expect(rms.getRmsAtTime(buffer.duration * 0.5)).to.closeTo(0, 0.01);
|
|
366
|
+
expect(rms.getRmsAtTime(buffer.duration * 0.7)).to.closeTo(0, 0.01);
|
|
390
367
|
});
|
|
391
368
|
|
|
392
|
-
it("can play for a specific duration passed in the 'start' method", () => {
|
|
393
|
-
|
|
369
|
+
it("can play for a specific duration passed in the 'start' method", async () => {
|
|
370
|
+
const rms = await Offline(() => {
|
|
394
371
|
const player = new ToneBufferSource(buffer).toDestination();
|
|
395
372
|
player.start(0, 0, 0.1);
|
|
396
373
|
|
|
397
|
-
return (
|
|
398
|
-
if (
|
|
374
|
+
return (time_1) => {
|
|
375
|
+
if (time_1 > 0.1) {
|
|
399
376
|
expect(player.state).to.equal("stopped");
|
|
400
377
|
}
|
|
401
378
|
};
|
|
402
|
-
}, 0.4)
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
});
|
|
379
|
+
}, 0.4);
|
|
380
|
+
expect(rms.getRmsAtTime(0)).to.be.gt(0);
|
|
381
|
+
expect(rms.getRmsAtTime(0.09)).to.be.gt(0);
|
|
382
|
+
// after stop is scheduled
|
|
383
|
+
expect(rms.getRmsAtTime(0.11)).to.equal(0);
|
|
384
|
+
expect(rms.getRmsAtTime(0.3)).to.equal(0);
|
|
409
385
|
});
|
|
410
386
|
|
|
411
|
-
it("can start at an offset", () => {
|
|
387
|
+
it("can start at an offset", async () => {
|
|
412
388
|
const offsetTime = 0.1;
|
|
413
389
|
const offsetSample =
|
|
414
390
|
buffer.toArray()[Math.floor(offsetTime * sampleRate)];
|
|
415
|
-
|
|
391
|
+
const buff = await Offline(() => {
|
|
416
392
|
const player = new ToneBufferSource(buffer).toDestination();
|
|
417
393
|
player.start(0, offsetTime);
|
|
418
|
-
}, 0.05)
|
|
419
|
-
|
|
420
|
-
});
|
|
394
|
+
}, 0.05);
|
|
395
|
+
expect(buff.getValueAtTime(0)).to.equal(offsetSample);
|
|
421
396
|
});
|
|
422
397
|
|
|
423
|
-
it("can end start ramp early", () => {
|
|
424
|
-
|
|
398
|
+
it("can end start ramp early", async () => {
|
|
399
|
+
const rms = await Offline(() => {
|
|
425
400
|
const player = new ToneBufferSource(buffer);
|
|
426
401
|
player.fadeIn = 0.2;
|
|
427
402
|
player.toDestination();
|
|
428
403
|
player.start(0).stop(0.1);
|
|
429
|
-
}, 0.2)
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
});
|
|
404
|
+
}, 0.2);
|
|
405
|
+
expect(rms.getRmsAtTime(0.0)).to.be.gt(0);
|
|
406
|
+
expect(rms.getRmsAtTime(0.05)).to.be.gt(0);
|
|
407
|
+
expect(rms.getRmsAtTime(0.09)).to.be.gt(0);
|
|
408
|
+
expect(rms.getRmsAtTime(0.1)).to.equal(0);
|
|
409
|
+
expect(rms.getRmsAtTime(0.15)).to.equal(0);
|
|
436
410
|
});
|
|
437
411
|
|
|
438
|
-
it("can end start ramp with a ramp", () => {
|
|
439
|
-
|
|
412
|
+
it("can end start ramp with a ramp", async () => {
|
|
413
|
+
const buff = await Offline(() => {
|
|
440
414
|
const player = new ToneBufferSource(onesBuffer);
|
|
441
415
|
player.fadeIn = 0.2;
|
|
442
416
|
player.fadeOut = 0.1;
|
|
443
417
|
player.loop = true;
|
|
444
418
|
player.toDestination();
|
|
445
419
|
player.start(0).stop(0.1);
|
|
446
|
-
}, 0.3)
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
return Offline(() => {
|
|
420
|
+
}, 0.3);
|
|
421
|
+
// fade in
|
|
422
|
+
expect(buff.getRmsAtTime(0.01)).to.be.gt(0);
|
|
423
|
+
expect(buff.getRmsAtTime(0.05)).to.be.gt(0);
|
|
424
|
+
// fade out
|
|
425
|
+
expect(buff.getRmsAtTime(0.1)).to.be.gt(0);
|
|
426
|
+
expect(buff.getRmsAtTime(0.15)).to.be.gt(0);
|
|
427
|
+
expect(buff.getRmsAtTime(0.19)).to.be.gt(0);
|
|
428
|
+
// end of ramp
|
|
429
|
+
expect(buff.getRmsAtTime(0.21)).to.equal(0);
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
it("can be scheduled to stop with a ramp", async () => {
|
|
433
|
+
const rms = await Offline(() => {
|
|
461
434
|
const player = new ToneBufferSource(buffer).toDestination();
|
|
462
435
|
player.fadeOut = 0.05;
|
|
463
436
|
player.start(0).stop(0.1);
|
|
464
|
-
}, 0.6)
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
return Offline(() => {
|
|
437
|
+
}, 0.6);
|
|
438
|
+
expect(rms.getRmsAtTime(0.01)).to.be.gt(0);
|
|
439
|
+
expect(rms.getRmsAtTime(0.05)).to.be.gt(0);
|
|
440
|
+
expect(rms.getRmsAtTime(0.08)).to.be.gt(0);
|
|
441
|
+
expect(rms.getRmsAtTime(0.1)).to.be.gt(0);
|
|
442
|
+
expect(rms.getRmsAtTime(0.14)).to.be.gt(0);
|
|
443
|
+
expect(rms.getRmsAtTime(0.16)).to.equal(0);
|
|
444
|
+
expect(rms.getRmsAtTime(0.2)).to.equal(0);
|
|
445
|
+
expect(rms.getRmsAtTime(0.3)).to.equal(0);
|
|
446
|
+
expect(rms.getRmsAtTime(0.4)).to.equal(0);
|
|
447
|
+
expect(rms.getRmsAtTime(0.5)).to.equal(0);
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
it("fade is applied after the stop time", async () => {
|
|
451
|
+
const buff = await Offline(() => {
|
|
480
452
|
const player = new ToneBufferSource(onesBuffer).toDestination();
|
|
481
453
|
player.fadeOut = 0.1;
|
|
482
454
|
player.start(0).stop(0.2);
|
|
483
|
-
}, 0.32)
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
});
|
|
455
|
+
}, 0.32);
|
|
456
|
+
expect(buff.getValueAtTime(0)).to.equal(1);
|
|
457
|
+
expect(buff.getValueAtTime(0.1)).to.equal(1);
|
|
458
|
+
expect(buff.getValueAtTime(0.2)).to.equal(1);
|
|
459
|
+
expect(buff.getValueAtTime(0.25)).to.be.closeTo(0.5, 0.01);
|
|
460
|
+
expect(buff.getValueAtTime(0.29)).to.be.closeTo(0.1, 0.01);
|
|
461
|
+
expect(buff.getValueAtTime(0.3)).to.be.closeTo(0, 0.01);
|
|
462
|
+
expect(buff.getValueAtTime(0.31)).to.equal(0);
|
|
492
463
|
});
|
|
493
464
|
|
|
494
465
|
it("can fade with an exponential curve", () => {
|
|
@@ -498,34 +469,32 @@ describe("ToneBufferSource", () => {
|
|
|
498
469
|
player.dispose();
|
|
499
470
|
});
|
|
500
471
|
|
|
501
|
-
it("fades in and out exponentially", () => {
|
|
502
|
-
|
|
472
|
+
it("fades in and out exponentially", async () => {
|
|
473
|
+
const buff = await Offline(() => {
|
|
503
474
|
const player = new ToneBufferSource(onesBuffer).toDestination();
|
|
504
475
|
player.curve = "exponential";
|
|
505
476
|
player.fadeIn = 0.1;
|
|
506
477
|
player.fadeOut = 0.1;
|
|
507
478
|
player.start(0).stop(0.4);
|
|
508
|
-
}, 0.51)
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
});
|
|
479
|
+
}, 0.51);
|
|
480
|
+
expect(buff.getValueAtTime(0)).to.equal(0);
|
|
481
|
+
expect(buff.getValueAtTime(0.05)).to.be.closeTo(0.93, 0.01);
|
|
482
|
+
expect(buff.getValueAtTime(0.1)).to.be.closeTo(1, 0.01);
|
|
483
|
+
expect(buff.getValueAtTime(0.4)).to.be.closeTo(1, 0.01);
|
|
484
|
+
expect(buff.getValueAtTime(0.45)).to.be.closeTo(0.06, 0.01);
|
|
485
|
+
expect(buff.getValueAtTime(0.5)).to.closeTo(0, 0.01);
|
|
516
486
|
});
|
|
517
487
|
|
|
518
|
-
it("can be scheduled to start at a lower gain", () => {
|
|
519
|
-
|
|
488
|
+
it("can be scheduled to start at a lower gain", async () => {
|
|
489
|
+
const buff = await Offline(() => {
|
|
520
490
|
const player = new ToneBufferSource(buffer).toDestination();
|
|
521
491
|
player.start(0, 0, undefined, 0.5);
|
|
522
|
-
}, 0.5)
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
});
|
|
492
|
+
}, 0.5);
|
|
493
|
+
expect(buff.getValueAtTime(0)).to.be.lte(0.5);
|
|
494
|
+
expect(buff.getValueAtTime(0.1)).to.be.lte(0.5);
|
|
495
|
+
expect(buff.getValueAtTime(0.2)).to.be.lte(0.5);
|
|
496
|
+
expect(buff.getValueAtTime(0.3)).to.be.lte(0.5);
|
|
497
|
+
expect(buff.getValueAtTime(0.4)).to.be.lte(0.5);
|
|
529
498
|
});
|
|
530
499
|
|
|
531
500
|
it("cannot be started more than once", () => {
|
|
@@ -537,44 +506,40 @@ describe("ToneBufferSource", () => {
|
|
|
537
506
|
player.dispose();
|
|
538
507
|
});
|
|
539
508
|
|
|
540
|
-
it("stops playing if invoked with 'stop' at a sooner time", () => {
|
|
541
|
-
|
|
509
|
+
it("stops playing if invoked with 'stop' at a sooner time", async () => {
|
|
510
|
+
const buff = await Offline(() => {
|
|
542
511
|
const player = new ToneBufferSource(buffer);
|
|
543
512
|
player.toDestination();
|
|
544
513
|
player.start(0).stop(0.1).stop(0.05);
|
|
545
|
-
}, 0.3)
|
|
546
|
-
|
|
547
|
-
});
|
|
514
|
+
}, 0.3);
|
|
515
|
+
expect(buff.getTimeOfLastSound()).to.be.closeTo(0.05, 0.02);
|
|
548
516
|
});
|
|
549
517
|
|
|
550
|
-
it("does not play if the stop time is at the start time", () => {
|
|
551
|
-
|
|
518
|
+
it("does not play if the stop time is at the start time", async () => {
|
|
519
|
+
const buff = await Offline(() => {
|
|
552
520
|
const player = new ToneBufferSource(buffer);
|
|
553
521
|
player.toDestination();
|
|
554
522
|
player.start(0).stop(0);
|
|
555
|
-
}, 0.3)
|
|
556
|
-
|
|
557
|
-
});
|
|
523
|
+
}, 0.3);
|
|
524
|
+
expect(buff.isSilent()).is.equal(true);
|
|
558
525
|
});
|
|
559
526
|
|
|
560
|
-
it("does not play if the stop time is at before start time", () => {
|
|
561
|
-
|
|
527
|
+
it("does not play if the stop time is at before start time", async () => {
|
|
528
|
+
const buff = await Offline(() => {
|
|
562
529
|
const player = new ToneBufferSource(buffer);
|
|
563
530
|
player.toDestination();
|
|
564
531
|
player.start(0.1).stop(0);
|
|
565
|
-
}, 0.3)
|
|
566
|
-
|
|
567
|
-
});
|
|
532
|
+
}, 0.3);
|
|
533
|
+
expect(buff.isSilent()).is.equal(true);
|
|
568
534
|
});
|
|
569
535
|
|
|
570
|
-
it("stops playing at the last scheduled stop time", () => {
|
|
571
|
-
|
|
536
|
+
it("stops playing at the last scheduled stop time", async () => {
|
|
537
|
+
const buff = await Offline(() => {
|
|
572
538
|
const player = new ToneBufferSource(buffer);
|
|
573
539
|
player.toDestination();
|
|
574
540
|
player.start(0).stop(0.1).stop(0.2);
|
|
575
|
-
}, 0.3)
|
|
576
|
-
|
|
577
|
-
});
|
|
541
|
+
}, 0.3);
|
|
542
|
+
expect(buff.getTimeOfLastSound()).to.be.closeTo(0.2, 0.02);
|
|
578
543
|
});
|
|
579
544
|
});
|
|
580
545
|
});
|