Now that we have successfully learned about synths, we can move on to the next important part of Sonic Pi… samples! Samples are basically clips of prerecorded sounds that you can use to really spice up your music. Many samples come preinstalled with Sonic Pi for you to use and are easy to add to your music!
You should now hear a spacey sound play and then stop. Pretty cool!
And just like with notes you can play multiple samples at the same time…
sample :ambi_lunar_land sample :ambi_drone
…or play them in a sequence using the sleep command, like this:
sample :ambi_lunar_land sleep 1 sample :ambi_drone
You may notice that these samples have some overlap. This is because the first sample is longer than 1 beat. This can be avoided by either making a longer sleep (higher sleep value) find the sample’s note length.
But how do we do that? I don’t see any numbers here like when we learned about ADSR envelopes, do you?
You can use a special command called sample_duration which automatically calculates the length of the sample for you. Try it out!
sample :ambi_lunar_land sleep sample_duration :ambi_lunar_land sample :ambi_drone
By using multiple commands (sleep, sample_duration) with two samples we can program the samples to play in a true sequence without overlap. Cool, huh?
Remember, you can also mix in notes with these sample commands to create something totally unique!
The last thing to note about samples is that there are a ton of them in Sonic Pi. You can easily scroll through all of them by using the auto-complete window that pops up when using the sample command (like with synths).
If you’d prefer to see the list here, take a look!
sample :ambi_ sample :bass_ sample :elec_ sample :perc_ sample :guit_ sample :drum_ sample :misc_ sample :bd_ sample :glitch_ sample :mehackit_ sample :vinyl_ sample :tabla_ sample :loop_ sample :sn_