Skip to content

Instantly share code, notes, and snippets.

@xavriley
Created September 9, 2014 12:22
Show Gist options
  • Save xavriley/88fa149163de8f914edc to your computer and use it in GitHub Desktop.
Save xavriley/88fa149163de8f914edc to your computer and use it in GitHub Desktop.
Randomised drum groove

Randomised drum groove

More Sonic Pi experiments with randomisation of grooves.

By choosing the likelihood of certain sounds landing on certain beats we can create grooves that are unique and non-repeating yet not totally random - they maintain some feeling of a style or genre.

I'm looking to develop this idea to express these kinds of patterns in a declarative way. Any feedback to @xavriley on twitter please.

You can download Sonic Pi here: http://sonic-pi.net/get-v2.0

define :randobeat do
# by playing with the "length" of onbeats vs offbeats
# we get different groove feelings
sleep_times = [0.25, 0.25]
sleep_times = [0.23, 0.27] if one_in(4)
sleep_times = [0.27, 0.23] if one_in(8)
(1..16).to_a.each do |i|
sample :drum_bass_hard if i == 1
with_fx :reverb, mix: 0.01 do
synth :cnoise, attack: 0.0, sustain: 0, decay: 0.1, release: 0.05 if i == 9
#synth :cnoise, attack: 0.0, sustain: 0, decay: 0.05, release: 0.12 if (i == 1 and one_in(8))
#synth :cnoise, attack: 0.0, sustain: 0, decay: 0.05, release: 0.12 if (i == 15 and one_in(8))
end
if [1,5,9,13].include? i
# strong beats
sample :drum_cymbal_closed
elsif one_in(3) and [3,7,11,15].include? i
# offbeat 8ths
sample :drum_cymbal_closed
sample :drum_bass_hard if one_in(6)
elsif one_in(5)
# offbeat 16ths
sample :drum_cymbal_closed
sample :drum_bass_hard if one_in(6)
end
sleep sleep_times.first if i.odd?
sleep sleep_times.last if i.even?
end
end
in_thread(name: :beat) do
loop { randobeat }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment