Created
July 8, 2017 20:38
-
-
Save xavriley/5d3fc4536b0cd290717e2970f84a0907 to your computer and use it in GitHub Desktop.
Don't Drop the Bass - Source code with comments - Brighton Ruby 2017
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ❤️ Brighton Ruby | |
# This code uses some features from the pre-release of Sonic Pi, | |
# due out later this month (touch wood!). | |
# If you just can't wait for the release but want to try it yourself | |
# you can either build the Sonic Pi master branch from source (pros: free, cons: hard) | |
# or share some love and contribute to the Patreon page to support Sonic Pi's development | |
# https://www.patreon.com/samaaron | |
# That will give to access to the latest pre-release versions | |
# for anything I don't explain (like tick) | |
# click the Help button in Sonic Pi (top right) | |
# and check out the tutorial for more info | |
# four to the floor | |
use_bpm 100 | |
# use_real_time is a new method in SP v2.13 | |
# instead of using a sched_ahead_time to allow events | |
# to be sequenced in time, use_real_time just tried to | |
# schedule the events as quickly as possible. | |
# That means *some* latency, but not much. | |
# Which makes playing along with a real instrument more feasible. | |
# Anything over about 40ms latency and it starts to become really | |
# hard to play along. | |
use_real_time | |
# This live_loop sets up the bass drum | |
live_loop :bd do | |
# lpf = low pass filter | |
# the range.mirror is a kind of poor man's LFO | |
# It's like turning the treble knob up very slowly, | |
# then down very slowly over and over again. | |
# The 80 and 110 are midi notes, corresponding to | |
# roughly 800Hz and 5kHz | |
sample :bd_haus, | |
lpf: range(80, 110, 0.5).mirror.tick(:bd) | |
sleep 1 | |
end | |
# live_sample is a helper method I defined myself | |
# available here: https://gist.github.com/xavriley/b5f925daa1195dc6ef686297a3016c3d | |
# :bass is a label for the sample I'm about to record | |
# dur: 16 means it lasts for 16 beats | |
# sync: :bd means it starts on the next :bd loop | |
# check out cue and sync in the docs for how that works | |
live_sample :bass, dur: 16, sync: :bd | |
live_loop :groove, sync: :bass do | |
# After recording the 16 beat bass loop, | |
# here I was mostly messing around with the slice | |
# and rate params to generate new/random basslines. | |
# The on: param also helps to give it some rhythm | |
# beyond just being a stream of random notes. | |
sample buffer(:bass, 16), | |
slice: rand(2), | |
num_slices: 32, | |
lpf: 90, | |
rate: [1,-1].choose, | |
on: spread(5,64).tick | |
sleep 0.25 | |
end | |
# Here I set up four short loops layered on top of each other | |
# with the following notes | |
# G -> Bb | |
# D -> F | |
# Bb -> C | |
# G -> Bb | |
# This creates a kind of Gm7 chord to work with. | |
# I can then use stretch: 1 and the pitch: param | |
# to pitch shift this to other chords, Cm7 and Dm7 | |
# Cm7 is 5 semitones above the original key of Gm7 | |
# Dm7 is 7 semitones above the original key of Gm7 | |
# knit(...) says don't transpose for 4 loops | |
# then transpose up 5 semitones for 2 loops | |
# then transpose up 7 semitones for 2 loops etc. | |
4.times do |n| | |
name = "cascade#{n}" | |
live_sample name, dur: 4, sync: :bd | |
live_loop "groove#{n}", sync: name do | |
with_fx :slicer, probability: 0.1 do | |
sample buffer(name, 4), | |
amp: 0.75, | |
lpf: 70, | |
rate: -1, | |
stretch: 1, | |
pitch: knit(0,4,5,2,7,2,5,2,7,2).tick | |
sleep 4 | |
end | |
end | |
end | |
# With those chords above (Cm7, Dm7 and Gm7) | |
# they all fit underneath one type of scale - the Bb major scale | |
# Another (fancy) name for that is G minor aeolian | |
# Here I setup the input from the bass using live_audio | |
# and some heavy compression and distortion to get that long | |
# sustaining sound, with some reverb to make it less harsh | |
with_fx :reverb, room: 0.8 do #octaver is good too | |
with_fx :distortion, amp: 0.07, mix: 0.8, distort: 0.99 do | |
with_fx :compressor, pre_amp: 5 do | |
live_audio :basssolo | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment