Kiedy ludzie odkrywają Sonic Pi, jedną z pierwszych rzeczy, których się uczą jest to jak łatwo można z jego pomocą odtwarzać nagrane dźwięki korzystając z funkcji sample
. Na przykład, możesz zagrać w pętli industrialny bęben, usłyszeć dźwięk chóru a nawet dźwięk scratch’ującego winyla za pomocą pojedynczej linii kodu. Niezależnie od tego, wiele z tych osób nie zdaje sobie sprawy z tego, że można zmieniać prędkość z jaką jest odtwarzany dany sampel aby uzyskać różne bardzo dobre efekty i uzyskać zupełnie nowy poziom kontroli nad swoimi nagranymi dźwiękami. Nie czekaj więc tylko odpal swoją kopię Sonic Pi i porozciągajmy jakieś sample!
Aby zmienić tempo odtwarzania sampla musimy użyć opcji rate:
:
sample :guit_em9, rate: 1
Jeśli ustawimy wartość opcji rate:
jako 1
to sampel zostanie zagrany ze normalną szybkością. Jeśli chcemy zagrać go ponownie z prędkością zmniejszoną o połowę, wystarczy że dla opcji rate:
użyjemy wartości 0.5
:
sample :guit_em9, rate: 0.5
Zauważ, że odciśnie to na nasz dźwięk dwa efekty. Po pierwsze sampel będzie miał niższą wysokość dźwięku, po drugie zagranie go zajmie dwa razy tyle czasu co normalnie (zerknij na pasek boczny aby uzyskać wyjaśnienie dlaczego tak się dzieje). Możemy nawet wybierać coraz mniejsze i mniejsze wartości zbliżając się do 0
, i tak szybkość rate:
o wartości 0.25
będzie jedną czwartą prędkości, 0.1
będzie jedną dziesiątą prędkości, itd. Spróbuj pobawić się z różnymi niskimi wartościami opcji rate:
i zobacz czy uda Ci się uzyskać bardzo niskie dudnienie.
Oprócz możliwości sprawiania aby dźwięk był dłuższy i niższy za pomocą niskich wartości tempa, możemy użyć wyższego tempa aby skrócić dźwięk i sprawić by był wyższy. Tym razem spróbujmy wziąć na warsztat pętlę z bębnem. Najpierw posłuchaj jak brzmi ten dźwięk na domyślnym tempie równym 1
:
sample :loop_amen, rate: 1
A teraz, spróbujmy przyśpieszyć go odrobinę:
sample :loop_amen, rate: 1.5
Ha! Właśnie zmieniliśmy gatunek muzyczny z oldschool’owego techno do jungle. Zauważ, że zmieniła się zarówno wysokość każdego uderzenia bębna jak i cały rytm uległ przyśpieszeniu. Teraz, spróbuj wykorzystać jeszcze wyższe tempo i zobacz jak wysoką i jak krótką pętlę z bębnem uda Ci się stworzyć. Na przykład, jeśli użyjesz tempa o wartości 100
, pętla zmieni się w kliknięcie!
Now, I’m sure many of you are thinking the same thing right now… “what if you use a negative number for the rate?”. Great question! Let’s think about this for a moment. If our rate:
opt signifies the speed with which the sample is played back, 1
being normal speed, 2
being double speed, 0.5
being half speed, -1
must mean backwards! Let’s try it on a snare. First, play it back at the normal rate:
sample :elec_filt_snare, rate: 1
Świetnie! Wybrany kawałek jest odtwarzany od końca!
sample :elec_filt_snare, rate: -1
Of course, you can play it backwards twice as fast with a rate of -2
or backwards at half speed with a rate of -0.5
. Now, play around with different negative rates and have fun. It’s particularly amusing with the :misc_burp
sample!
One of the effects of rate modification on samples is that faster rates result in the sample sounding higher in pitch and slower rates result in the sample sounding lower in pitch. Another place you may have heard this effect in every day life is when you’re cycling or driving past a beeping pedestrian crossing - as you’re heading towards the sound source the pitch is higher than when you’re moving away from the sound - the so-called Doppler effect. Why is this?
Let’s consider a simple beep which is represented by a sine wave. If we use an oscilloscope to plot a beep, we’ll see something like Figure A. If we plot a beep an octave higher, we’ll see Figure B and an octave lower will look like Figure C. Notice that the waves of higher notes are more compact and the waves of lower notes are more spread out.
A sample of a beep is nothing more than a lot of numbers (x, y, coordinates) which when plotted onto a graph will re-draw the original curves. See figure D where each circle represents a coordinate. To turn the coordinates back into audio, the computer works through each x value and sends the corresponding y value to the speakers. The trick here is that the rate at which the computer works through the x numbers does not have to be the same as the rate with which they were recorded. In other words, the space (representing an amount of time) between each circle can be stretched or compressed. So, if the computer walks through the x values faster than the original rate, it will have the effect of squashing the circles closer together which will result in a higher sounding beep. It will also make the beep shorter as we will work through all the circles faster. This is shown in Figure E.
Finally, one last thing to know is that a mathematician called Fourier proved that any sound is actually lots and lots of sine waves all combined together. Therefore, when we compress and stretch any recorded sound we’re actually stretching and compressing many sine waves all at the same time in exactly this manner.
As we’ve seen, using a faster rate will make the sound higher in pitch and a slower rate will make the sound lower in pitch. A very simple and useful trick is to know that doubling the rate actually results in the pitch being an octave higher and inversely halving the rate results in the pitch being an octave lower. This means that for melodic samples, playing it alongside itself at double/half rates actually sounds rather nice:
sample :bass_trance_c, rate: 1
sample :bass_trance_c, rate: 2
sample :bass_trance_c, rate: 0.5
However, what if we just want to alter the rate such that the pitch goes up one semitone (one note up on a piano)? Sonic Pi makes this very easy via the rpitch:
opt:
sample :bass_trance_c
sample :bass_trance_c, rpitch: 3
sample :bass_trance_c, rpitch: 7
If you take a look at the log on the right, you’ll notice that an rpitch:
of 3
actually corresponds to a rate of 1.1892
and a rpitch:
of 7
corresponds to a rate of 1.4983
. Finally, we can even combine rate:
and rpitch:
opts:
sample :ambi_choir, rate: 0.25, rpitch: 3
sleep 3
sample :ambi_choir, rate: 0.25, rpitch: 5
sleep 2
sample :ambi_choir, rate: 0.25, rpitch: 6
sleep 1
sample :ambi_choir, rate: 0.25, rpitch: 1
Let’s take a look at a simple piece which combines these ideas. Copy it into an empty Sonic Pi buffer, hit play, listen to it for a while and then use it as a starting point for your own piece. See how much fun it is to manipulate the playback rate of samples. As an added exercise try recording your own sounds and play around with the rate to see what crazy sounds you can make.
sample :guit_em9