---
title: Synths, Samples & FX
description: Strudel Tutorial
layout: ../../layouts/MainLayout.astro
---

import { MiniRepl } from '../../docs/MiniRepl';
import { JsDoc } from '../../docs/JsDoc';

# Synths, Samples & Effects

Let's take a closer look at how we can control synths, sounds and effects.

## Synths

So far, all the mini notation examples all used the same sound, which is kind of boring.
We can change the sound, using the `s` function:

<MiniRepl client:only="react" tune={`note("c2 <eb2 <g2 g1>>").s('sawtooth')`} />

Here, we are wrapping our notes inside `note` and set the sound using `s`, connected by a dot.

Those functions are only 2 of many ways to alter the properties, or _params_ of a sound.
The power of patterns allows us to sequence any _param_ independently:

<MiniRepl client:only="react" tune={`note("c2 <eb2 <g2 g1>>").s("<sawtooth square triangle>")`} />

Now we not only pattern the notes, but the sound as well!
`sawtooth` `square` and `triangle` are the basic waveforms available in `s`.

### Envelope

You can control the envelope of a synth using the `attack`, `decay`, `sustain` and `release` functions:

<MiniRepl
  client:idle
  tune={`note("c2 <eb2 <g2 g1>>").s('sawtooth')
  .attack(.1).decay(.1).sustain(.2).release(.1)`}
/>

## Samples

Besides Synths, `s` can also play back samples:

<MiniRepl client:only="react" tune={`s("bd sd,hh*8,misc/2")`} />

To know which sounds are available, open the [default sample map](https://strudel.tidalcycles.org/EmuSP12.json)

### Custom Sample Maps

You can load your own sample map like this:

<MiniRepl
  client:idle
  tune={`samples({
  bd: 'bd/BT0AADA.wav',
  sd: 'sd/rytm-01-classic.wav',
  hh: 'hh27/000_hh27closedhh.wav',
}, 'https://raw.githubusercontent.com/tidalcycles/Dirt-Samples/master/');
s("bd sd,hh*8")`}
/>

The `samples` function takes an object that maps sound names to audio file paths.
The second argument is the base URL that comes before each path. Make sure your base URL ends with a slash, while your sample paths do **not** begin with one.

Because github is a popular choice to dump samples, there is a shortcut for that:

<MiniRepl
  client:idle
  tune={`samples({
  bd: 'bd/BT0AADA.wav',
  sd: 'sd/rytm-01-classic.wav',
  hh: 'hh27/000_hh27closedhh.wav',
}, 'github:tidalcycles/Dirt-Samples/master/');
s("bd sd,hh*8")`}
/>

The format is `github:user/repo/branch/`.

### Multiple Samples per Sound

It is also possible, to declare multiple files for one sound, using the array notation:

<MiniRepl
  client:idle
  tune={`samples({
  bd: ['bd/BT0AADA.wav','bd/BT0AAD0.wav'],
  sd: ['sd/rytm-01-classic.wav','sd/rytm-00-hard.wav'],
  hh: ['hh27/000_hh27closedhh.wav','hh/000_hh3closedhh.wav'],
}, 'github:tidalcycles/Dirt-Samples/master/');
s("<bd:0 bd:1>,~ <sd:0 sd:1>,[hh:0 hh:1]*2")`}
/>

The `:0` `:1` etc. are the indices of the array.
The sample number can also be set using `n`:

<MiniRepl
  client:idle
  tune={`samples({
  bd: ['bd/BT0AADA.wav','bd/BT0AAD0.wav'],
  sd: ['sd/rytm-01-classic.wav','sd/rytm-00-hard.wav'],
  hh: ['hh27/000_hh27closedhh.wav','hh/000_hh3closedhh.wav'],
}, 'github:tidalcycles/Dirt-Samples/master/');
s("bd,~ sd,hh*4").n("<0 1>")`}
/>

### Pitched Sounds

For pitched sounds, you can use `note`, just like with synths:

<MiniRepl
  client:idle
  tune={`samples({
  'gtr': 'gtr/0001_cleanC.wav',
}, 'github:tidalcycles/Dirt-Samples/master/');
note("g3 [bb3 c4] <g4 f4 eb4 f3>@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)`:

<MiniRepl
  client:idle
  tune={`samples({
  'gtr': 'gtr/0001_cleanC.wav',
}, 'github:tidalcycles/Dirt-Samples/master/');
note("g3 [bb3 c4] <g4 f4 eb4 f3>@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:

<MiniRepl
  client:idle
  tune={`samples({
  'gtr': 'gtr/0001_cleanC.wav',
  'moog': { 'g3': 'moog/005_Mighty%20Moog%20G3.wav' },
}, 'github:tidalcycles/Dirt-Samples/master/');
note("g3 [bb3 c4] <g4 f4 eb4 f3>@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:

<MiniRepl
  client:idle
  tune={`samples({
  'moog': {
    'g2': 'moog/004_Mighty%20Moog%20G2.wav',
    'g3': 'moog/005_Mighty%20Moog%20G3.wav',
    'g4': 'moog/006_Mighty%20Moog%20G4.wav',
  }}, 'github:tidalcycles/Dirt-Samples/master/');
note("g2!2 <bb2 c3>!2, <c4@3 [<eb4 bb3> g4 f4]>")
  .s('moog').clip(1)
  .gain(.5)`}
/>

The sampler will always pick the closest matching sample for the current note!

## Sampler Effects

### begin

<JsDoc client:idle name="Pattern.begin" h={0} />

### end

<JsDoc client:idle name="Pattern.end" h={0} />

### loopAt

<JsDoc client:idle name="Pattern.loopAt" h={0} />

### chop

<JsDoc client:idle name="Pattern.chop" h={0} />

## Audio Effects

Wether you're using a synth or a sample, you can apply these effects:

### gain

<JsDoc client:idle name="gain" h={0} />

### velocity

<JsDoc client:idle name="velocity" h={0} />

### cutoff

<JsDoc client:idle name="cutoff" h={0} />

### resonance

<JsDoc client:idle name="resonance" h={0} />

### hcutoff

<JsDoc client:idle name="hcutoff" h={0} />

### hresonance

<JsDoc client:idle name="hresonance" h={0} />

### bandf

<JsDoc client:idle name="bandf" h={0} />

### bandq

<JsDoc client:idle name="bandq" h={0} />

### vowel

<JsDoc client:idle name="vowel" h={0} />

### pan

<JsDoc client:idle name="pan" h={0} />

### coarse

<JsDoc client:idle name="coarse" h={0} />

### shape

<JsDoc client:idle name="shape" h={0} />

### crush

<JsDoc client:idle name="crush" h={0} />
