hn.today

Show HN: A forest's wildlife, synthesized live in Rust, playable in the browser

zaghaghi.github.io7 points0 comments
Screenshot of Show HN: A forest's wildlife, synthesized live in Rust, playable in the browser

A compact sound system that synthesizes an entire forest live in Rust is presented, with the same code compiled to WebAssembly for an in-browser demo. Audio runs in a single CPAL stream and a single real-time callback: a tiny mixer ("desk") reads commands sent over a channel from the rest of the game (Bevy) and renders up to three simultaneous creature calls sample-by-sample. Calls are deterministic seeds from a xorshift RNG and built from three small DSP tools - noise, a topology‑preserving state‑variable filter (Simper/Zavalishin coefficients), and a smooth tapered window envelope - so nothing is pre-recorded or stored. A soft limiter protects the output, the stream is held as a non‑send resource, and the Sound API simply sends commands if audio is available.

Eight creature recipes implement four common steps (source, time shape, filter, place) to produce natural, non‑repeating wildlife: whistles (songbird, cuckoo, tawny owl) use swept sine notes and small harmonics; knocks and buzzes (woodpecker, bumblebee, crickets) use filtered noise, sawtooth buzzes with Doppler and gated chirps; throats (frog, raven) use pulsed glottal clicks and a complex raven patch (low saw raised a fifth then falling, 55 Hz tremolo, formants around 1 kHz and higher). Code excerpts show the window function and per‑voice implementations. The result is a small (~574 lines) live synthesis engine that fits inside the audio deadline and runs both in-game and in the browser demo.

Read on zaghaghi.github.io0 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Web

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.