diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-17 00:11:20 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-17 12:15:01 -0300 |
| commit | c68a8c9d9efa746e8eaef0392a327888577a05e0 (patch) | |
| tree | db903d320e3f4701845af5f07a4ffc5dc9d80ff8 /README.md | |
| parent | 896855648c3371ede3c672bbfa75175fa3a1e42e (diff) | |
| download | sketchbook-c68a8c9d9efa746e8eaef0392a327888577a05e0.tar.gz sketchbook-c68a8c9d9efa746e8eaef0392a327888577a05e0.zip | |
audio: a voice's rate (its pitch), and groups of voices under one gain
Voice.rate is the voice's playback speed and so its pitch: 2 is an octave
up and half as long, 0 holds it, and changing it does not restart the
voice. The mixer keeps a fractional cursor and resamples by linear
interpolation between a sample and the next (the last toward silence, or
the first when looping): the least code that sounds right, a little dull
far from 1; at rate 1 the samples come out exactly. An infinite or NaN
rate ends the voice instead of crashing the conversion.
Voice.group (0-7) puts a voice under a group's gain, which draw declares
each frame with f.gain(group, value) (Command.gain); a group not given
one plays at 1, so it is declared state and replays like the voices. The
mixer glides each group toward its gain by 1/480 a sample (10 ms for a
full swing), so a gain set in one step does not click. Music ducking
under speech is then the sketch lowering one number; nothing ducks by
itself. The web host ignores gains as it ignores voices.
Test: half and double speed against the interpolated samples, rate 0
holding, an infinite rate ending; a looping voice in group 1 at gain 0.5
gliding there and staying while group 0's is untouched, and going back to
1 when the gain is no longer declared. test-audio also builds the voices
sketch for the web, which compiles the web host's newSound and gain. The
README lists rate, group and f.gain with what they do.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -123,10 +123,10 @@ Session (a trail in an offscreen image) is stale then; repaint it from State. `draw` gets a `Frame`: `clear`, `fill`, `shape`, `shapeColors`, `image`, -`imageAt`, `target`, `blend`, `text`, `print`, `clip`, `canvas`, `cursor`, `voice`, `audio`, `microphone`, `pixels`, `gpu`, +`imageAt`, `target`, `blend`, `text`, `print`, `clip`, `canvas`, `cursor`, `voice`, `gain`, `audio`, `microphone`, `pixels`, `gpu`, `compute`, `upload`, `download`, `openFile`, `run`, `quit`, plus the three allocators and `f.host` (`loadImage`, `decodeImage`, `newImage`, `newBuffer`, `loadSound`, -`decodeSound`, `samples`, `readFile`, `env`, `log`, `textSize`). Commands may be built +`decodeSound`, `newSound`, `samples`, `readFile`, `env`, `log`, `textSize`). Commands may be built from locals: the methods copy what they keep (text, GPU descriptions, uniforms) into scratch. Bulk data (vertices, samples, pixels, uploads) is not copied and must outlive the frame: scratch, session or store memory. @@ -423,10 +423,17 @@ stay on the GPU: a compute shader's output is a later draw's input, with no readback. Each dispatch is its own compute pass, so it sees everything the commands before it wrote. -Sound is declarative. `f.voice(.{ .key, .audio, .serial, .loop, .volume })` -declares a voice that should be sounding. A new key or serial starts it, and -an undeclared key stops it. A finished one-shot stays finished while it is -still declared, so replays and seeks never re-fire sounds. `f.audio(key, +Sound is declarative. `f.voice(.{ .key, .audio, .serial, .loop, .volume, +.fade, .rate, .group })` declares a voice that should be sounding. A new key +or serial starts it, and an undeclared key stops it. A finished one-shot +stays finished while it is still declared, so replays and seeks never +re-fire sounds. `.rate` is its speed and so its pitch (2 is an octave up +and half as long; resampled by linear interpolation, cheap and a little +dull far from 1); changing it does not restart the voice. `.group` (0-7) +puts it under a gain the sketch declares each frame, `f.gain(group, +value)`, 1 when not declared: music ducks under speech by the sketch +lowering one number, and the host glides to a new gain over 10 ms so a +step does not click. `f.audio(key, samples, .{})` streams PCM, and `input.stream(key)` reports what the host has queued and played. `f.microphone()` keeps the default recording device open while declared, and the next frame's `input.microphone` holds what it heard |
