Raspberry Pi: 2 Beginner's Users Manual (Tech Geek) by Alex Benjamin
Author:Alex Benjamin [Benjamin, Alex]
Language: eng
Format: epub
Published: 2015-06-04T18:30:00+00:00
Click the Run button. If you have hooked up your Raspberry Pi via an HDMI cable and typed in the command correctly, you should be able to hear a fascinating sequence of bells, called Haunted Bells. The code you just typed in is what is producing this sounds. Let’s dissect the code.
The keywords loop do … end form a repetitive loop that will run until you stop the program.
The command sample is used to play a recorded sound file. In this case, it is playing the sound of a perc_bell, or percussive bell.
The rate is how fast the sound plays and at what frequency. In this case, each time the bell is played its speed varies for a random amount of time, between 0.5 to 1.5 seconds. If you set the rate to 0.5, it plays at ½ speed and at an octave down in pitch, or ½ the original frequency. If you set the rate to 2.0, it plays at double speed and twice the original frequency. For those of us not so musically inclined, the higher the number, the higher the bell sounds. Very low numbers cause it to have a deep sound.
The sleep command controls how long before the next command is triggered in beats per minute. In this example, it will wait a random amount of time between 0 and 2 beats before executing the next command.
Press the Start button to hear it. Since this is setup as a loop, it will keep playing random bell sounds until we use the Stop button. It sounds somewhat like a wind chime, doesn’t it?
One of the best ways to learn programming is by experimenting, so before you go on try changing the rate and the sleep to see what happens. Stop the music before you run the next sound. For example, if you set the rate to be a random number between 1.0 and 1.5 there is not much difference in the sound of the bells, and they sound relatively high pitched.
Let’s add a bit more interest to our wind chime effect. Try adding a pan parameter to adjust the position of the sound in stereo: the default is 0, or equally sounding in both ears; a -1 moves the sound to the left ear, and a + 1 moves the sound to the right ear.
loop do
sample :perc_bell, rate: (rrand 0.125, 1.5), pan: (rrand -1,1)
sleep rrand(0, 2)
end
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7763)
Filmora Efficient Editing by Alexander Zacharias(5779)
The Infinite Retina by Robert Scoble Irena Cronin(5256)
Learn Wireshark - Fundamentals of Wireshark. by Lisa Bock(3975)
Linux Device Driver Development Cookbook by Rodolfo Giometti(3935)
Edit Like a Pro with iMovie by Regit(3425)
Linux Administration Best Practices by Scott Alan Miller(2858)
Linux Command Line and Shell Scripting Techniques by Vedran Dakic & Jasmin Redzepagic(2835)
MCSA Windows Server 2016 Study Guide: Exam 70-740 by William Panek(2520)
Mastering PowerShell Scripting - Fourth Edition by Chris Dent(2400)
Docker on Windows by Stoneman Elton(2318)
Kali Linux - An Ethical Hacker's Cookbook: End-to-end penetration testing solutions by Sharma Himanshu(2314)
Creative Projects for Rust Programmers by Carlo Milanesi(2247)
Hands-On AWS Penetration Testing with Kali Linux by Karl Gilbert(2107)
Hands-On Linux for Architects by Denis Salamanca(2051)
Programming in C (4th Edition) (Developer's Library) by Stephen G. Kochan(2004)
Computers For Seniors For Dummies by Nancy C. Muir(1997)
The Old New Thing by Raymond Chen(1940)
Linux Kernel Debugging by Kaiwan N Billimoria(1762)
