I’ve blown the dust off Sonic Pi recently and tried v3.3.1 and can confirm that v3.2.2 performs much better. Some of my old tracks get into timing problems within about 15 seconds on 3.3.1 - Same laptop.
The samples vary in length between 1 - 11s, doesn’t seem to make a difference though.
My assumption is that the ixi_techno effect in the spin loop is taking up too much resource.
Code example:
# Sonic Pi v3.2.2 (Win 10)
# Settings
use_bpm 85
bar_length = 4
use_random_seed 20210712
swing = (ring 0.01, -0.01)
sample_root = "/Samples/"
sample_folder = "/OtherSamples/"
# Scale
mode = :minor
scl = scale(:e1, mode, num_octaves: 4)
# Functions
define :get_pitch_from_note do |note, sample_base_note, fine_tune|
return note - sample_base_note + fine_tune
end
define :bar do |length = 8|
sleep bar_length * length
end
# Loops
define :bass do |length = 8, pattern = 1|
in_thread do
s = sample_root + "twobass.wav"
notes = (ring 7,8,6,5)
((bar_length * length)).times do ; tick
sample s, rpitch: get_pitch_from_note(scl[notes.tick(:n)], 40, 0),
amp: rrand(2, 2.2) if pattern == 1 and bools(1,0,1,0).look
with_synth :square do
play scl[notes.look(:n)],
amp: 0.2,
attack: 0,
sustain: 1,
release: 0
end
sleep 1 + swing.look
end
end
end
define :spin do |length = 8, pattern = 1|
in_thread do
s = sample_root + "spin.wav"
idx = get[:lead_counter]
((bar_length * length * 4)).times do ; tick
with_fx :ixi_techno, phase: (line 8, 1, steps: 128, inclusive: true).mirror[idx] do
sample s, slice: look, amp: rrand(2, 2.2)
end
sleep 0.25 + swing.look
set :lead_counter, idx += 1
end
end
end
define :fart_moves do |length = 8, pattern = 1|
in_thread do
s = sample_root + "fart_moves.wav"
slices = (line 4, 7, steps: 4, inclusive: true).mirror
with_fx :eq, low_note: 42, low: -1 do
((bar_length * length * 4)).times do ; tick
sample s, slice: slices.look, num_slices: 32, amp: rrand(1.8, 2.1)
sleep 0.25 + swing.look
end
end
end
end
define :breakbeat do |length = 8, pattern = 1|
in_thread do
s = sample_folder + "Urban Technologies/STRANGER BREAKS/UT_011_STRNGR BRK_95_A#.wav" #UT_008_STRNGR BRK_90_E.wav"
slices = (line 0, 15, steps: 16, inclusive: true) if pattern == 1
slices = (line 0, 7, steps: 8, inclusive: true) if pattern == 2
slices = (line 0, 15, steps: 16, inclusive: true).shuffle if pattern == 3
sample_rate = 1
sample_rate = 0.5 if pattern == 3
((bar_length * length) * 4).times do ; tick
beat_stretch = 8 #[16,16,16,17].choose
sample s, slice: slices.look, amp: rrand(0.9, 1.2),
##rate: sample_rate, beat_stretch: beat_stretch,
rpitch: 0.02, pan: 1
sample s, slice: slices.look, num_slices: 16, amp: rrand(0.9, 1.2),
#rate: sample_rate, beat_stretch: beat_stretch,
rpitch: -0.02, pan: -1
sleep 0.25 + swing.look
end
end
end
live_loop :metro do
stop
play :c5, amp: 0.2
sleep 1
end
# Reset globals
set :lead_counter, 0
# Structure
#spin ; bar
#breakbeat(8,1) ; bar
#breakbeat(8,1) ; spin ; bar
#breakbeat(8,3) ; fart_moves ; bar
bass ; breakbeat(8,1) ; fart_moves ; spin ; bar