Last active
August 22, 2021 16:08
-
-
Save kindohm/78084da8a17fa9e2eb64 to your computer and use it in GitHub Desktop.
Sonic Pi Breaks
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
# mashing up breakbeats in Sonic Pi | |
# resulting audio: https://soundcloud.com/kindohm/sonic-pi-breaks | |
# this var changes the playback speed of the breaks, | |
# which in turn controls the loop sleep time and overall tempo | |
rate = 1 | |
# samples paths | |
samples = [] | |
samples.push("C:\\tidal-samples\\samples\\akuma\\Half Baked break a.wav") | |
samples.push("C:\\tidal-samples\\samples\\akuma\\Half Baked break b.wav") | |
samples.push("C:\\tidal-samples\\samples\\akuma\\Half Baked break c.wav") | |
samples.push("C:\\tidal-samples\\samples\\akuma\\Half Baked break d.wav") | |
samples.push("C:\\tidal-samples\\samples\\akuma\\Half Baked break e.wav") | |
samples.push("C:\\tidal-samples\\samples\\akuma\\Half Baked break f.wav") | |
# load up first sample | |
# this code should probably be in a class/function or something | |
slices = 16 | |
samp = samples[0] | |
orig_dur = sample_duration samp | |
new_sample_duration = (1 / rate) * orig_dur | |
slice_dur = new_sample_duration/slices | |
sample_idx = 0 | |
idx = 0 | |
single_slice_size = 1/slices.to_f | |
start_times = [] | |
for i in 1..slices-1 | |
time = i.to_f/slices.to_f | |
start_times.push(time) | |
end | |
live_loop :breaks do | |
with_fx :compressor do |c| | |
with_fx :distortion do |d| | |
control c, pre_amp: 1.7 | |
control d, distort: 0.5 | |
# this code should prob go down where the sample is changed, | |
# but I'm too lazy right now to move it | |
orig_dur = sample_duration samp | |
new_sample_duration = (1 / rate) * orig_dur | |
slice_dur = new_sample_duration/slices | |
start = choose(start_times) | |
finish = start + single_slice_size | |
final_rate = rate | |
if one_in(10) | |
final_rate = final_rate * -1 | |
end | |
sample samp, start: start, finish: finish, rate: final_rate | |
sleep slice_dur | |
idx += 1 | |
if idx == 8 | |
sample_idx += 1 | |
if sample_idx > samples.length - 1 | |
sample_idx = 0 | |
end | |
# at this point enough time has passed so we're going to load a new samples | |
# and re-calculate slice duration based on the sample's length, etc. | |
samp = samples[sample_idx] | |
orig_dur = sample_duration samp | |
new_sample_duration = (1 / rate) * orig_dur | |
slice_dur = new_sample_duration/slices | |
idx = 0 | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment