jevstrudel.git / website / src / pages / learn / sounds.mdx
sounds.mdx40 lines · 1.7 KB · raw
1---
2title: Sounds
3layout: ../../layouts/MainLayout.astro
4---
5
6import { MiniRepl } from '../../docs/MiniRepl';
7import { JsDoc } from '../../docs/JsDoc';
8
9# Sounds
10
11We can play sounds with `s`, in two different ways:
12
13- `s` can trigger audio samples, where a sound file is loaded in the background and played back:
14  <MiniRepl client:idle tune={`s("bd hh sd hh")`} />
15- `s` can trigger audio synthesisers, which are synthesised in real-time using code also running in the background:
16  <MiniRepl client:idle tune={`s("sawtooth square triangle sine")`} />
17
18You can learn more about both of these approaches in the pages [Synths](/learn/synths) and [Samples](/learn/samples).
19
20# Combining notes and sounds
21
22In both of the above cases, we are no longer directly controlling the `note`/`freq` of the sound heard via `s`, as we were in the [Notes](/workshop/first-notes/) page.
23
24So how can we both control the sound and the pitch? We can _combine_ `note`/`freq` with `s` to change the sound of our pitches:
25
26<MiniRepl client:idle tune={`note("a3 c#4 e4 a4").s("sawtooth")`} />
27
28<MiniRepl client:idle tune={`note("57 61 64 69").s("sine")`} />
29
30<MiniRepl client:idle tune={`freq("220 275 330 440").s("triangle")`} />
31
32The last example will actually sound the same with or without `s`, because `triangle` is the default value for `s`.
33
34What about combining different notes with different sounds at the same time?
35
36<MiniRepl client:idle tune={`freq("220 275 330 440 550").s("triangle sawtooth sine")`} />
37
38Hmm, something interesting is going on there, related to there being five notes and three sounds.
39
40Let's now take a step back and think about the Strudel [Code](/learn/code/) we've been hearing so far.