summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md19
1 files changed, 19 insertions, 0 deletions
diff --git a/README.md b/README.md
index f9ad615..6eb24d0 100644
--- a/README.md
+++ b/README.md
@@ -441,6 +441,25 @@ full-scale peak plays at 0.875 and any number of loud voices stays
bounded. Streams are not limited: SDL adds each, as pushed, to the voice
mix and clips the total at ±1.
+A sketch can make its own sounds: `host.newSound(samples)` copies mono
+samples at `input.sample_rate` into the host and returns an `Audio` that
+voices play like a loaded one, so a synthesised one-shot is replay-safe
+too. Like every sound it lives as long as the host: make each once and
+keep the handle in Session. `sk.sfxr` is sfxr, the classic generator of
+game blips, coins, lasers and explosions (`sfxr.Params`, its usual knobs,
+rendered at any rate; at 44.1 kHz to the bit as the original):
+
+```zig
+if (ss.blip == .none) {
+ var buf: [4096]f32 = undefined;
+ const n = sk.sfxr.render(.{ .freq = 0.5, .sustain = 0.05, .decay = 0.1 }, f.in.sample_rate, &buf);
+ ss.blip = f.host.newSound(buf[0..n]);
+}
+if (s.coins != 0) f.voice(.{ .key = 1, .audio = ss.blip, .serial = s.coins });
+```
+
+(`test/voices.zig` is this sketch.)
+
Sounds decode with single-file C libraries in `vendor/` (dr_wav, dr_flac,
stb_vorbis): WAV, FLAC and Ogg Vorbis, chosen by content.