Fix sounds example to work in the REPL

`freq` only takes one argument, so switch this to mini-notation
so this can be used in the REPL as indicated in the paragraph below.
Make it so this can be played by the user.

Fix syntax-type typo.
This commit is contained in:
JesCoding 2025-12-24 11:39:28 +01:00 committed by Brian Brazil
parent 7bce739068
commit 8d2bca59c4

View file

@ -13,7 +13,7 @@ Let's take a closer look about how sounds are implemented in the webaudio output
All sounds are registered in the sound map, using the the `registerSound` function: All sounds are registered in the sound map, using the the `registerSound` function:
```ts ```js
function registerSound( function registerSound(
name: string, // The name of the sound that should be given to `s`, e.g. `mysaw` name: string, // The name of the sound that should be given to `s`, e.g. `mysaw`
// The function called by the scheduler to trigger the sound: // The function called by the scheduler to trigger the sound:
@ -35,8 +35,10 @@ When `registerSound` is called, it registers `{ onTrigger, data }` under the giv
This might be a bit abstract, so here is a minimal example: This might be a bit abstract, so here is a minimal example:
```js <MiniRepl
registerSound( client:idle
tune={`
registerSound(
'mysaw', 'mysaw',
(time, value, onended) => { (time, value, onended) => {
let { freq } = value; // destructure control params let { freq } = value; // destructure control params
@ -59,10 +61,10 @@ registerSound(
return { node, stop }; return { node, stop };
}, },
{ type: 'synth' }, { type: 'synth' },
); );
// use the sound // use the sound
freq(220, 440, 330).s('mysaw'); freq("220 440 330").s('mysaw');`}
``` />
You can actually use this code in the [REPL](https://strudel.cc/) and it'll work. You can actually use this code in the [REPL](https://strudel.cc/) and it'll work.
After evaluating the code, you should see `mysaw` in listed in the sounds tab. After evaluating the code, you should see `mysaw` in listed in the sounds tab.