-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
5,890 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,28 @@ | ||
import { SVFilter, SVFilterType } from "./filter"; | ||
import { SVFilter } from "./filter"; | ||
|
||
describe("SVFilter", () => { | ||
it("filters the signal", () => { | ||
const filter = SVFilter(20, SVFilterType.LowPass); | ||
const filter = SVFilter(20); | ||
const input = new Float32Array(20); | ||
const output = new Float32Array(20); | ||
|
||
for (let i = 0; i < input.length; i++) { | ||
input[i] = i % 2 ? 1 : -1; | ||
} | ||
expect(input).toMatchSnapshot(); | ||
const output = new Float32Array(20); | ||
filter.fill(input, output, { | ||
filter.update({ | ||
filterType: [1], | ||
frequency: [10], | ||
resonance: [0.5], | ||
}); | ||
filter.fill(input, output); | ||
expect(output).toMatchSnapshot(); | ||
filter.fill(input, output, { | ||
filter.update({ | ||
filterType: [1], | ||
frequency: [5], | ||
resonance: [0.5], | ||
}); | ||
filter.fill(input, output); | ||
expect(output).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { | ||
createStateVariableFilter, | ||
registerStateVariableFilterWorkletOnce, | ||
} from "./index"; | ||
|
||
describe("PolyblepOscillator", () => { | ||
it("registers only once", () => { | ||
const context = new AudioContextMock(); | ||
|
||
registerStateVariableFilterWorkletOnce(context.asAudioContext()); | ||
expect(context.audioWorklet?.addModule).toHaveBeenCalledTimes(1); | ||
registerStateVariableFilterWorkletOnce(context.asAudioContext()); | ||
expect(context.audioWorklet?.addModule).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it("creates the worklet node with default parameters", () => { | ||
// @ts-ignore | ||
global.AudioWorkletNode = AudioWorkletNodeMock; | ||
const node = createStateVariableFilter( | ||
new AudioContextMock().asAudioContext() | ||
); | ||
expect(node.frequency.value).toBe(4000); | ||
expect(node.filterType.value).toBe(1); | ||
expect(node.type).toEqual("lowpass"); | ||
}); | ||
|
||
it("changes the waveform using type property", () => { | ||
// @ts-ignore | ||
global.AudioWorkletNode = AudioWorkletNodeMock; | ||
const node = createStateVariableFilter( | ||
new AudioContextMock().asAudioContext() | ||
); | ||
expect(node.filterType.value).toBe(1); | ||
node.type = "highpass"; | ||
expect(node.filterType.value).toBe(3); | ||
}); | ||
}); | ||
|
||
class AudioContextMock { | ||
audioWorklet?: { addModule: jest.Mock<any, any, any> }; | ||
|
||
constructor(worklets = true) { | ||
if (worklets) { | ||
this.audioWorklet = { | ||
addModule: jest.fn(), | ||
}; | ||
} | ||
} | ||
|
||
asAudioContext(): AudioContext { | ||
return this as unknown as AudioContext; | ||
} | ||
} | ||
|
||
class AudioWorkletNodeMock { | ||
params: Record<string, ParamMock>; | ||
parameters: { get(name: string): void }; | ||
disconnect = jest.fn(); | ||
|
||
constructor( | ||
public context: any, | ||
public processorName: any, | ||
public options: any | ||
) { | ||
this.params = { | ||
frequency: new ParamMock(), | ||
resonance: new ParamMock(), | ||
filterType: new ParamMock(), | ||
}; | ||
|
||
const get = (name: string): ParamMock => { | ||
return this.params[name]; | ||
}; | ||
|
||
this.parameters = { | ||
get, | ||
}; | ||
} | ||
} | ||
|
||
class ParamMock { | ||
value = 0; | ||
values: { value: number; time: number }[] = []; | ||
|
||
setValueAtTime(value: number, time: number) { | ||
this.values.push({ value, time }); | ||
if (time === 0) this.value = value; | ||
} | ||
} |
Oops, something went wrong.