sample name_or_path (symbol_or_string)
This is the main method for playing back recorded sound files (samples). Sonic Pi comes with lots of great samples included (see the section under help) but you can also load and play .wav
, .wave
, .aif
or .aiff
files from anywhere on your computer too. The rate:
parameter affects both the speed and the pitch of the playback. See the examples for details. Check out the use_sample_pack
and use_sample_pack_as
fns for details on making it easy to work with a whole folder of your own sample files. Note, that on the first trigger of a sample, Sonic Pi has to load the sample which takes some time and may cause timing issues. To preload the samples you wish to work with consider using load_sample
or load_samples
.
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. |
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 |
pan_slide: |
Time to slide the pan value from current to next value on next control |
amp: |
Amplitude of playback |
amp_slide: |
Time to slide the amp value from current to next value on next control |
# Example 1 | |
|
|
# Example 2 | |
|
|
# Example 3 | |
|
|
# Example 4 | |
|
|
# Example 5 | |
|
|
# Example 6 | |
|
|
# Example 7 | |
|
|
# Example 8 | |
|
|