Tutorial: Creating a Sonic Pi Sound with Ruby
Love for the shaman
Tutorial: Creating a Sonic Pi Sound with Ruby
Introduction
Sonic Pi is a powerful live coding environment that allows you to create music using code. In this tutorial, we'll explore a simple piece of music using Sonic Pi and explain how to modify it to create your own unique sounds.
Prerequisites
Before we begin, make sure you have Sonic Pi installed on your system. You can download it from the official website: Sonic Pi.
The Code
Here's the Ruby code i wrote:
use_bpm 95
live_loop :bass do
use_synth :fm
play :a2, release: 0.5
sleep 1
play :c3, release: 0.5
sleep 1
play :e3, release: 0.5
sleep 1
play :a3, release: 0.5
sleep 1
play :g2, release: 0.5
sleep 1
play :b2, release: 0.5
sleep 1
play :d3, release: 0.5
sleep 1
play :g3, release: 0.5
sleep 1
end
live_loop :ethereal_keys do
use_synth :prophet
play_chord [:a3, :c4, :e4], release: 2
sleep 4
play_chord [:g3, :b3, :d4], release: 2
sleep 4
end
live_loop :drums do
sample :bd_haus, amp: 2
sleep 1
sample :sn_dolf, amp: 1.5
sleep 1
end
Explanation
Let's break down the code:
Setting the BPM:
use_bpm 95
sets the tempo of our music to 95 beats per minute.Bass Loop:
- We use the
:fm
synth (frequency modulation) to create a bass sound. - The
play
commands specify the notes (e.g.,:a2
,:c3
) and their release times. - The
sleep
commands introduce pauses between notes.
- We use the
Ethereal Keys Loop:
- We use the
:prophet
synth to create ethereal keys. - The
play_chord
commands play chords (e.g.,[:a3, :c4, :e4]
) with a longer release time.
- We use the
Drums Loop:
- We use samples (
:bd_haus
for bass drum and:sn_dolf
for snare) to create a basic drum pattern.
- We use samples (
Experimenting and Customization
Now that you understand the code, feel free to experiment:
- Change the synths (e.g., try
:piano
,:pluck
, or others). - Modify the notes and rhythms.
- Add your own loops or effects.
Conclusion
You've just scratched the surface of what Sonic Pi can do! Keep exploring, and soon you'll be creating your own mesmerizing tunes. 🎵
For inspiration, check out this YouTube video featuring Sonic Pi in action: Sonic Pi Live Coding.
Happy coding! 🎧🎶
Remember to publish using INLEO every once in a while to make the most out of your premium membership!