Raspberry Pi For Dummies
Book image
Explore Book Buy On Amazon
Your Raspberry Pi can do all kinds of things when it comes to music. You can add special effects and even synchronize your music with a drumbeat. Let’s check it out.

Adding special effects to music on your Raspberry Pi

You can play a sample and add effects to it, including distortion, echo, and reverb. There is a full list of effects (also known as Fx) in the Help pane, and you can also find them using the autocomplete feature. This is how you add distortion to one of the guitar samples:

with_fx :distortion do

sample :guit_e_fifths

end

You can adjust how the effect is applied to the sound using options. There are several options for distortion, including distort, which controls how much the sound is distorted, and mix, which controls the balance between the original sound and the distorted version. In both cases, the value should be between 0 and 1. Here's how you use them:

with_fx :distortion, distort: 0.9, mix: 0.5 do

sample :guit_e_fifths

end

Try using different values for those options and running the code to see how the sound changes. Experiment with other effects too.

To see the full options for this or any other effect, click Fx in the Help pane, or click the effect name in your code and then use Ctrl+I to jump to its entry (if available) in the Help. You can also use Ctrl+I to get help on commands in your code.

Synchronizing with your drumbeat

You now know how to play a repeating rhythm, and how to play other samples and synth melodies. You can play multiple live loops at the same time. One of the challenges is to synchronize all the different parts of the music so they play in time. To do that, you can provide an option to synchronize the start of a live loop with the name of another live_loop. Here's an example that synchronizes a cymbal beat with the main drum loop:

live_loop :drums do/code>

sample :loop_industrial, beat_stretch: 2/code>

sleep 2/code>

end/code>

live_loop :cymbals, sync: :drums do/code>

4.times do/code>

sample :elec_cymbal/code>

sleep 1/code>

end/code>

sleep 8/code>

end/code>

When you play that example, you'll hear that the cymbal plays four times, in perfect sync with the main drumbeat. It then rests for 8 beats before playing again.

Take care with the colons when setting the sync option for your live loop; otherwise, the program won't work. The first colon (after sync) goes between the option and its parameter and touches the option name, and the second colon (before drums) marks the start of the loop name you want to synchronize with.

About This Article

This article is from the book:

About the book authors:

Sean McManus is an expert technology and business author. His previous books include Mission Python, Coder Academy, and Cool Scratch Projects in Easy Steps.

Mike Cook is a former professor in physics at Manchester Metropolitan University. His other books include Raspberry Pi Projects and Raspberry Pi Projects For Dummies.

Sean McManus is an expert technology and business author. His previous books include Mission Python, Coder Academy, and Cool Scratch Projects in Easy Steps.

Mike Cook is a former professor in physics at Manchester Metropolitan University. His other books include Raspberry Pi Projects and Raspberry Pi Projects For Dummies.

This article can be found in the category: