1 | import { BitCrusher } from "./BitCrusher.js";
|
2 | import { FeedbackCombFilter } from "../component/filter/FeedbackCombFilter.js";
|
3 | import { Oscillator } from "../source/oscillator/Oscillator.js";
|
4 | import { BasicTests } from "../../test/helper/Basic.js";
|
5 | import { EffectTests } from "../../test/helper/EffectTests.js";
|
6 | import { CompareToFile } from "../../test/helper/CompareToFile.js";
|
7 | import { expect } from "chai";
|
8 |
|
9 | describe("BitCrusher", () => {
|
10 | BasicTests(BitCrusher);
|
11 | EffectTests(BitCrusher);
|
12 |
|
13 | context("API", () => {
|
14 | it("matches a file", () => {
|
15 | return CompareToFile(
|
16 | () => {
|
17 | const crusher = new BitCrusher({ bits: 4 }).toDestination();
|
18 | const osc = new Oscillator(110).connect(crusher);
|
19 | osc.start(0);
|
20 | },
|
21 | "bitCrusher.wav",
|
22 | 0.01
|
23 | );
|
24 | });
|
25 |
|
26 | it("can pass in options in the constructor", () => {
|
27 | const crusher = new BitCrusher({
|
28 | bits: 3,
|
29 | });
|
30 | expect(crusher.bits.value).to.equal(3);
|
31 | crusher.dispose();
|
32 | });
|
33 |
|
34 | it("can get/set the options", () => {
|
35 | const crusher = new BitCrusher(4);
|
36 | expect(crusher.bits.value).to.equal(4);
|
37 | crusher.set({
|
38 | bits: 5,
|
39 | });
|
40 | expect(crusher.get().bits).to.equal(5);
|
41 | crusher.dispose();
|
42 | });
|
43 | });
|
44 |
|
45 | it("should be usable with the FeedbackCombFilter", (done) => {
|
46 | new BitCrusher(4);
|
47 | new FeedbackCombFilter();
|
48 |
|
49 | const handle = setTimeout(() => {
|
50 | window.onunhandledrejection = null;
|
51 | done();
|
52 | }, 100);
|
53 |
|
54 | window.onunhandledrejection = (event) => {
|
55 | done(event.reason);
|
56 | clearTimeout(handle);
|
57 | };
|
58 | });
|
59 | });
|