10.4 Zufallssong

„Normale“ Songs beinhalten eigentlich keine Zufallselemente und klingen daher oft recht statisch – wie aus der Konserve. Kleine zufällige Abweichungen kennen wir von Liveauftritten von Bands oder einzelnen Musikern.

In Sonic Pi ist das gut nachvollziehbar. Ein Beispiel ist Code 25. Beim Hören erscheint die Musik ungewohnt, ja auch unhandlich für das Ohr. Dies ändert sich beim mehrmaligen Hören. Dann offenbart sich der eigene Charme dieser Methode.

Wenn Du herausfinden willst, wo im Song überall Zufälle eingebaut sind, dann Suche nach der Zeichenfolge „rand“.

################################
# Random Song
# Hans Gruendel
# 18.09.2015
################################

 

define :my_loop do
use_synth :tb303
sample :drum_bass_hard, rate: rrand(1, 2)
sleep 0.25

sample :drum_bass_hard, rate: rrand(1, 3)
sample :drum_cymbal_closed, rate: rrand(0.5, 1)
sleep 0.2
sample :drum_cymbal_closed, rate: rrand(1, 2)
sleep 0.3
sample :drum_cymbal_closed, rate: rrand(2, 3)
play choose(chord(:c2, :major)), release: 1.75, cutoff: rrand(60, 110),amp:0.2
sleep 0.25
end
define :choir do

2.times do |idx1|
pan_around= -1 + idx1*0.1
sample :ambi_choir, rate: 1.1, amp: 0.4, pan: pan_around
sleep 0.25
idx1 += 0.1
end
4.times do |idx1|
pan_around= -1 + idx1*0.1
sample :ambi_choir, rate: rrand(1, 1.2), amp: 1.5, pan: pan_around
sleep 0.5
idx1 += 0.1
end
end

 

define :harmonics do |num, tonics, co=80, res=0.1, amp=1|
use_synth :fm
num.times do
play chord(tonics.choose, :m11).choose, res: res, cutoff: rrand(co – 40, co + 20), amp: 0.5 * amp, attack: 0, release: rrand(0.5, 1.5), pan: rrand(-0.7, 0.7)
sleep [0.25, 0.5, 0.5, 0.5, 1, 1].choose
end
end

 

in_thread(name: :looper1) do
loop do
harmonics(6, [:f2, :f3, :f1, :e2, :e4, :e3])
end
end

 
in_thread(name: :looper) do
loop do
my_loop
end
end

in_thread(name: :looper2) do
loop do
choir
end
end

define :sound1 do |num|
use_synth :fm
play num
use_synth :pretty_bell
play num
use_synth :sine
play num
use_synth :tri
play num
end
in_thread(name: :looper1) do
loop do
sound1(:c2)
sleep 1
sound1(:g2)
sleep 1
sound1(:f2)
sleep 1
sound1(:c2)
sleep 1
end
end

Code 25. Zufallssong