--- title: Notes description: Strudel Tutorial - Notes layout: ../../layouts/MainLayout.astro --- import { MiniRepl } from '../../docs/MiniRepl'; import { JsDoc } from '../../docs/JsDoc'; # Samples Samples are the most common way to make sound with tidal and strudel. A sample is a (commonly short) piece of audio that is used as a basis for sound generation, undergoing various transformations. Music that is based on samples can be thought of as a collage of sound. [Read more about Sampling]() Strudel allows loading samples in the form of audio files of various formats (wav, mp3, ogg) from any publicly available URL. # Default Samples By default, strudel comes with a built-in "sample map", providing a solid base to play with. Here, we are using the `s` function to play back different default samples (`bd`, `sd`, `hh` and `misc`) to get a drum beat. For drum sounds, strudel uses the comprehensive [tidal-drum-machines](https://github.com/ritchse/tidal-drum-machines) library, with the following naming convention: | Drum | Abbreviation | | ----------------------------------- | ------------ | | Bass drum, Kick drum | bd | | Snare drum | sd | | Rimshot | rim | | Clap | cp | | Closed hi-hat | hh | | Open hi-hat | oh | | Crash | cr | | Ride | rd | | Shakers (and maracas, cabasas, etc) | sh | | High tom | ht | | Medium tom | mt | | Low tom | lt | | Cowbell | cb | | Tambourine | tb | | Other percussions | perc | | Miscellaneous samples | misc | | Effects | fx | Furthermore, strudel also loads instrument samples from [VCSL](https://github.com/sgossner/VCSL) by default. To see which sample names are available, open the `samples` tab in the [REPL](https://strudel.tidalcycles.org/). Note that only the sample maps (mapping names to URLs) are loaded initially, while the audio samples itself are not loaded until they are actually played. This behaviour of loading things only when they are needed is also called `lazy loading`. While it saves resources, it can also lead to sounds not being audible the first time they are triggered, because the sound is still loading. [This might be fixed in the future](https://github.com/tidalcycles/strudel/issues/187) # Sound Banks If we look at the `samples` tab, we can see that the drum samples are all prefixed with drum machine names: `RolandTR808_bd`, `RolandTR808_sd`, `RolandTR808_hh` etc.. We _could_ use them like this: ... but thats obviously a bit much to write. Using the `bank` function, we can shorten this to: You could even pattern the bank to switch between different drum machines: ")`} /> Behind the scenes, `bank` will just prepend the drum machine name to the sample name with `_` to get the full name. This of course only works because the name after `_` (`bd`, `sd` etc..) is standardized. Also note that some banks won't have samples for all sounds! # Selecting Sounds If we look again at the `samples` tab, there is also a number behind each name, indicating how many individual samples are available. For example `RolandTR909_hh(4)` means there are 4 samples of a TR909 hihat available. By default, `s` will play the first sample, but we can selecting the other ones using `n`, starting from 0: ")`} /> Numbers that are too high will just wrap around to the beginning ")`} /> Here, 0-3 will play the same sounds as 4-7, because `RolandTR909_hh` only has 4 sounds. Selecting sounds also works inside the mini notation, using "`:`" like this: # Loading Custom Samples You can load your own sample map using the `samples` function. In this example we create a map using sounds from the default sample map: When you load your own samples, you can choose the names that you will then refer to in your pattern string inside the `s` function. Compare with this example which uses the same samples, but with different names. Here we have changed the "map" to include longer sample names. ## The `samples` function The `samples` function has two arguments: - A [JavaScript object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) that maps sound names to audio file paths. - A base URL that comes before each path describing where the sample folder can be found online. - Make sure your base URL ends with a slash, while your sample paths do **not** begin with one! To see how this looks in practice, compare the [DirtSamples GitHub repo](https://github.com/tidalcycles/Dirt-Samples) with the previous sample map example. Because GitHub is a popular place for uploading open source samples, it has its own shortcut: The format is `github:user/repo/branch/`. Let's see another example, this time based on the following GitHub repo: https://github.com/jarmitage/jarmitage.github.io. We can see there are some guitar samples inside the `/samples` folder, so let's try to load them: ## Multiple Samples per Sound It is also possible, to declare multiple files for one sound, using the array notation: ,~ ,[hh:0 hh:1]*2")`} /> The `:0` `:1` etc. are the indices of the array. The sample number can also be set using `n`: ")`} /> In that case, we might load our guitar sample map a different way: And as above, we can choose the sample number using `n` for even more flexibility: ").s("guitar")`} /> ## Pitched Sounds For pitched sounds, you can use `note`, just like with synths: @2").s('gtr').gain(.5)`} /> Here, the guitar samples will overlap, because they always play till the end. If we want them to behave more like a synth, we can add `clip(1)`: @2").s('gtr').clip(1) .gain(.5)`} /> ## Base Pitch If we have 2 samples with different base pitches, we can make them in tune by specifying the pitch like this: @2").s("gtr,moog").clip(1) .gain(.5)`} /> If a sample has no pitch set, `c3` is the default. We can also declare different samples for different regions of the keyboard: !2, g4 f4]>") .s('moog').clip(1) .gain(.5)`} /> The sampler will always pick the closest matching sample for the current note! ## Shabda If you don't want to select samples by hand, there is also the wonderful tool called [shabda](https://shabda.ndre.gr/). With it, you can enter any sample name(s) to query from [freesound.org](https://freesound.org/). Example: # Sampler Effects Sampler effects are functions that can be used to change the behaviour of sample playback. ### begin ### end ### cut ### clip ### loopAt ### chop ### speed