-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add audio node interface to BasePlayback (#16)
Add comprehensive audio node connectivity support to the BasePlayback class and its mixins. This change enables direct connection management between audio nodes and parameters. Key changes: - Add connect/disconnect methods to BasePlayback for audio routing - Add inputNode/outputNode abstract getters for connection points - Implement node access in Volume, Panner, and Oscillator mixins - Add error handling for node access after cleanup - Add comprehensive test coverage for node connections This improvement allows for: - Direct connection to Web Audio nodes and parameters - Flexible audio routing between components - Better error handling for node lifecycle management
- Loading branch information
Showing
8 changed files
with
251 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { vi, expect, describe, it, beforeEach } from "vitest"; | ||
import { audioContextMock } from "./setupTests"; | ||
import { BasePlayback } from "./basePlayback"; | ||
import { Sound } from "./sound"; | ||
|
||
// Create a concrete implementation of BasePlayback for testing | ||
class TestPlayback extends BasePlayback { | ||
constructor( | ||
public source?: AudioNode, | ||
public gainNode?: GainNode, | ||
public panner?: AudioNode | ||
) { | ||
super(); | ||
} | ||
|
||
play(): [this] { return [this]; } | ||
pause(): void {} | ||
stop(): void {} | ||
cleanup(): void { | ||
this.source = undefined; | ||
this.gainNode = undefined; | ||
this.panner = undefined; | ||
} | ||
} | ||
|
||
describe("BasePlayback Audio Node Interface", () => { | ||
let playback: TestPlayback; | ||
let destination: AudioNode; | ||
let param: AudioParam; | ||
|
||
beforeEach(() => { | ||
const source = audioContextMock.createOscillator(); | ||
const gainNode = audioContextMock.createGain(); | ||
const panner = audioContextMock.createStereoPanner(); | ||
playback = new TestPlayback(source, gainNode, panner); | ||
destination = audioContextMock.createGain(); | ||
param = destination.gain; | ||
}); | ||
|
||
describe("Connection Methods", () => { | ||
it("can connect to other nodes", () => { | ||
const connectSpy = vi.spyOn(playback.outputNode, 'connect'); | ||
playback.connect(destination); | ||
expect(connectSpy).toHaveBeenCalledWith(destination); | ||
}); | ||
|
||
it("can connect to audio params", () => { | ||
const connectSpy = vi.spyOn(playback.outputNode, 'connect'); | ||
playback.connect(param); | ||
expect(connectSpy).toHaveBeenCalledWith(param); | ||
}); | ||
|
||
it("can disconnect all outputs", () => { | ||
const disconnectSpy = vi.spyOn(playback.outputNode, 'disconnect'); | ||
playback.disconnect(); | ||
expect(disconnectSpy).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe("Error Handling", () => { | ||
it("throws when accessing nodes after cleanup", () => { | ||
playback.cleanup(); | ||
expect(() => playback.connect(destination)).toThrow(); | ||
expect(() => playback.disconnect()).toThrow(); | ||
}); | ||
}); | ||
}); |
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
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