sample name_or_path (symbol_or_string)
Play back a recorded sound file (sample). Sonic Pi comes with lots of great samples included (see the section under help) but you can also load and play .wav
, .wave
, .aif
, .aiff
or .flac
files from anywhere on your computer too. To play a built-in sample use the corresponding keyword such as sample :bd_haus
. To play any file on your computer use a full path such as sample "/path/to/sample.wav"
.
There are many opts for manipulating the playback. For example, the rate:
opt affects both the speed and the pitch of the playback. To control the rate of the sample in a pitch-meaningful way take a look at the rpitch:
opt.
The sampler synth has three separate envelopes - one for amplitude, one for a low pass filter and another for a high pass filter. These work very similar to the standard synth envelopes except for two major differences. Firstly, the envelope times do not stretch or shrink to match the BPM. Secondly, the sustain time by default stretches to make the envelope fit the length of the sample. This is explained in detail in the tutorial.
Samples are loaded on-the-fly when first requested (and subsequently remembered). If the sample loading process takes longer than the schedule ahead time, the sample trigger will be skipped rather than be played late and out of time. To avoid this you may preload any samples you wish to work with using load_sample
or load_samples
.
Finally, the sampler supports a powerful filtering system to make it easier to work with large folders of samples. The filter commands must be used before the first standard opt. There are six kinds of filter parameters you may use:
"/foo/bar"
- which will add all samples within the folder to the set of candidates."/path/to/sample.wav"
- which will add the specific sample to the set of candidates."foobar"
- which will filter the candidates based on whether the filename contains the string./b[aA]z.*/
- which will filter the candidates based on whether the regular expression matches the filename.:quux
- will filter the candidates based on whether the keyword is a direct match of the filename (without extension).0
- will select the candidate with that index (wrapping round like a ring if necessary).["/foo/bar", "baz", /0-9.*/]
- will recurse down and work through the internal filter parameters as if they were in the top level.By combining commands which add to the candidates and then filtering those candidates it is possible to work with folders full of samples in very powerful ways. Note that the specific ordering of filter parameters is irrelevant with the exception of the numbers - in which case the last number is the index. All the candidates will be gathered first before the filters are applied.
Introduced in v2.0
rate: |
Rate with which to play back the sample. Higher rates mean an increase in pitch and a decrease in duration. Default is 1. |
beat_stretch: |
Stretch (or shrink) the sample to last for exactly the specified number of beats. Please note - this does not keep the pitch constant and is essentially the same as modifying the rate directly. |
pitch_stretch: |
Stretch (or shrink) the sample to last for exactly the specified number of beats. This attempts to keep the pitch constant using the |
attack: |
Time to reach full volume. Default is 0. |
sustain: |
Time to stay at full volume. Default is to stretch to length of sample (minus attack and release times). |
release: |
Time (from the end of the sample) to go from full amplitude to 0. Default is 0. |
start: |
Position in sample as a fraction between 0 and 1 to start playback. Default is 0. |
finish: |
Position in sample as a fraction between 0 and 1 to end playback. Default is 1. |
pan: |
Stereo position of audio. -1 is left ear only, 1 is right ear only, and values in between position the sound accordingly. Default is 0. |
amp: |
Amplitude of playback. |
pre_amp: |
Amplitude multiplier which takes place immediately before any internal FX such as the low pass filter, compressor or pitch modification. Use this opt if you want to overload the compressor. |
norm: |
Normalise the audio (make quieter parts of the sample louder and louder parts quieter) - this is similar to the normaliser FX. This may emphasise any clicks caused by clipping. |
lpf: |
Cutoff value of the built-in low pass filter (lpf) in MIDI notes. Unless specified, the lpf is not added to the signal chain. |
lpf_init_level: |
The initial low pass filter envelope value as a MIDI note. This envelope is bypassed if no lpf env opts are specified. Default value is to match the |
lpf_attack_level: |
The peak lpf cutoff (value of cutoff at peak of attack) as a MIDI note. Default value is to match the |
lpf_decay_level: |
The level of lpf cutoff after the decay phase as a MIDI note. Default value is to match the |
lpf_sustain_level: |
The sustain cutoff (value of lpf cutoff at sustain time) as a MIDI note. Default value is to match the |
lpf_release_level: |
The final value of the low pass filter envelope as a MIDI note. This envelope is bypassed if no lpf env opts are specified. Default value is to match the |
lpf_attack: |
Attack time for lpf cutoff filter. Amount of time (in beats) for sound to reach full cutoff value. Default value is set to match amp envelope’s attack value. |
lpf_decay: |
Decay time for lpf cutoff filter. Amount of time (in beats) for sound to move from full cutoff value (cutoff attack level) to the cutoff sustain level. Default value is set to match amp envelope’s decay value. |
lpf_sustain: |
Amount of time for lpf cutoff value to remain at sustain level in beats. When -1 (the default) will auto-stretch. |
lpf_release: |
Amount of time (in beats) for sound to move from lpf cutoff sustain value to lpf cutoff min value. Default value is set to match amp envelope’s release value. |
lpf_min: |
Starting value of the lpf cutoff envelope. Default is 30. |
lpf_env_curve: |
Select the shape of the curve between levels in the lpf cutoff envelope. 1=linear, 2=exponential, 3=sine, 4=welch, 6=squared, 7=cubed. |
hpf: |
Cutoff value of the built-in high pass filter (hpf) in MIDI notes. Unless specified, the hpf is not added to the signal chain. |
hpf_init_level: |
The initial high pass filter envelope value as a MIDI note. This envelope is bypassed if no hpf env opts are specified. Default value is set to 130. |
hpf_attack_level: |
The peak hpf cutoff (value of cutoff at peak of attack) as a MIDI note. Default value is to match the |
hpf_decay_level: |
The level of hpf cutoff after the decay phase as a MIDI note. Default value is to match the |
hpf_sustain_level: |
The sustain cutoff (value of hpf cutoff at sustain time) as a MIDI note. Default value is to match the |
hpf_release_level: |
The sustain hpf cutoff (value of hpf cutoff at sustain time) as a MIDI note. Default value is to match the |
hpf_attack: |
Attack time for hpf cutoff filter. Amount of time (in beats) for sound to reach full cutoff value. Default value is set to match amp envelope’s attack value. |
hpf_decay: |
Decay time for hpf cutoff filter. Amount of time (in beats) for sound to move from full cutoff value (cutoff attack level) to the cutoff sustain level. Default value is set to match amp envelope’s decay value. |
hpf_sustain: |
Amount of time for hpf cutoff value to remain at sustain level in beats. When -1 (the default) will auto-stretch. |
hpf_release: |
Amount of time (in beats) for sound to move from hpf cutoff sustain value to hpf cutoff min value. Default value is set to match amp envelope’s release value. |
hpf_env_curve: |
Select the shape of the curve between levels in the hpf cutoff envelope. 1=linear, 2=exponential, 3=sine, 4=welch, 6=squared, 7=cubed. |
hpf_max: |
Maximum value of the high pass filter envelope. Default is 200. |
rpitch: |
Rate modified pitch. Multiplies the rate by the appropriate ratio to shift up or down the specified amount in MIDI notes. Please note - this does not keep the duration and rhythmical rate constant and is essentially the same as modifying the rate directly. |
pitch: |
Pitch adjustment in semitones. 1 is up a semitone, 12 is up an octave, -12 is down an octave etc. Maximum upper limit of 24 (up 2 octaves). Lower limit of -72 (down 6 octaves). Decimal numbers can be used for fine tuning. |
window_size: |
Pitch shift-specific opt - only honoured if the |
pitch_dis: |
Pitch shift-specific opt - only honoured if the |
time_dis: |
Pitch shift-specific opt - only honoured if the |
compress: |
Enable the compressor. This sits at the end of the internal FX chain immediately before the |
threshold: |
Threshold value determining the break point between slope_below and slope_above. Only valid if the compressor is enabled by turning on the |
slope_below: |
Slope of the amplitude curve below the threshold. A value of 1 means that the output of signals with amplitude below the threshold will be unaffected. Greater values will magnify and smaller values will attenuate the signal. Only valid if the compressor is enabled by turning on the |
slope_above: |
Slope of the amplitude curve above the threshold. A value of 1 means that the output of signals with amplitude above the threshold will be unaffected. Greater values will magnify and smaller values will attenuate the signal. Only valid if the compressor is enabled by turning on the |
clamp_time: |
Time taken for the amplitude adjustments to kick in fully (in seconds). This is usually pretty small (not much more than 10 milliseconds). Also known as the time of the attack phase. Only valid if the compressor is enabled by turning on the |
relax_time: |
Time taken for the amplitude adjustments to be released. Usually a little longer than clamp_time. If both times are too short, you can get some (possibly unwanted) artefacts. Also known as the time of the release phase. Only valid if the compressor is enabled by turning on the |
slide: |
Default slide time in beats for all slide opts. Individually specified slide opts will override this value. |
# Example 1 | |
|
|
# Example 2 | |
|
|
# Example 3 | |
|
|
# Example 4 | |
|
|
# Example 5 | |
|
|
# Example 6 | |
|
|
# Example 7 | |
|
|
# Example 8 | |
|
|
# Example 9 | |
|
|
# Example 10 | |
|
|
# Example 11 | |
|
|
# Example 12 | |
|
|
# Example 13 | |
|
|
# Example 14 | |
|
|
# Example 15 | |
|
|
# Example 16 | |
|
|
# Example 17 | |
|
|
# Example 18 | |
|
|
# Example 19 | |
|
|
# Example 20 | |
|
|
# Example 21 | |
|
|
# Example 22 | |
|
|
# Example 23 | |
|
|
# Example 24 | |
|
|
# Example 25 | |
|
|
# Example 26 | |
|
|