Add Web Audio API support with three procedural audio drivers#51
Draft
KurtGokhan wants to merge 4 commits into
Draft
Add Web Audio API support with three procedural audio drivers#51KurtGokhan wants to merge 4 commits into
KurtGokhan wants to merge 4 commits into
Conversation
Audio plays during stroke animation via a new `sound` engine option and a name-based registry mirroring `registerBundle` / `registerShaper`. Drivers live in a separate `tegaki/audio` entry point so the core renderer stays Web-Audio-free; the three built-ins are fully procedural (no asset bytes). - `tegaki/core` ships the registry, runtime, and types (`registerAudio`, `getAudio`, `TegakiAudioDriver`, etc.) - `tegaki/audio` ships the built-in drivers (`pencilAudio`, `chalkAudio`, `brushAudio`) plus `registerBuiltInAudio()` - engine wires `sound` through play / pause / seek / restart, suspends the AudioContext during pause and reduced motion, and rebuilds stroke events on timeline / font-size changes - all framework adapters forward the new `sound` prop
|
- `TegakiTextPreview` registers `pencil` / `chalk` / `brush` once at module load and forwards a new `sound` prop to the engine. - URL state grows an `sn` key (default `none`); the generator's text controls add a Sound dropdown and `/preview` reads the same key so agents can drive audio via the URL. - Documented in the AGENTS.md URL-state table. Browser autoplay policy keeps the AudioContext suspended until the first user gesture, so visual snapshots stay deterministic.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds comprehensive Web Audio API support to tegaki, enabling sound effects synchronized with stroke rendering. Three fully procedural audio drivers are included (pencil, chalk, brush) that require zero audio assets and work offline.
Key Changes
Audio Registry & Runtime (
audio-registry.ts,audio-runtime.ts)TegakiAudioDriverinterface for pluggable audio implementationsAudioRuntimeclass manages AudioContext lifecycle, stroke event scheduling, and driver instance swappingresolveSoundProp()utility handles multiple sound option formats (string name, object with config, raw driver)Built-in Audio Drivers (
audio/pencil.ts,audio/chalk.ts,audio/brush.ts)Audio Utilities (
audio/utils.ts)createNoiseBuffer(): Generates white/pink noise buffers for reuse across driver instancesclampNumber(): Safe config value validation with defaultsrampParam(): Exponential parameter ramping to avoid clicks/zippersEngine Integration (
engine.ts)AudioRuntimeinstance created per engine, destroyed on cleanupsetSound()called whensoundoption changes; supports hot-swapping driversadvance()called each frame to fire stroke events and tick callbackspause()/resume()suspend/resume AudioContext;silence()on seek/restartrebuildStrokes()recomputes events when timeline/font/fontSize changesFramework Bindings
soundpropTegakiEngine.registerAudio(),unregisterAudio(),getAudio()tegaki/audiowithregisterBuiltInAudio()convenience functionType Exports (
core/index.ts,core/types.ts)TegakiSoundProp,TegakiAudioDriver,TegakiAudioInstance,StrokeAudioInfo,TegakiAudioContextTegakiEngineOptionsextended withsoundfieldNotable Implementation Details
typeof windowcheck; no errors on server.Testing
Comprehensive test suite in
audio-registry.test.tscovers:https://claude.ai/code/session_0137C65gmSdCRy2ZHoKzT7PN