Can anyone explain why these two loops do different things?

hello! Just working on sample slicing and saw this loop from the tutorial appendix section:

live_loop :samp_slicer do
  n = 8
  s = line(0,1, steps: n).choose
  f = s+ (1.0/n)
  sample :loop_amen, beat_stretch: 2, start: s, finish: f
  sleep 2.0/n
end

It works wonderfully of course, but I assumed it would work the same as the following live loop which I use in my songs, but when I compared them they sound different - the first is constantly changing (with some slice repeats), and the second live loop (below) chooses one slice out of the n1 = 8 possible slices and then plays this same slice every iteration. I assumed that it would choose a new slice each loop, why is this not the case?

live_loop :samp_slicer2 do
  n1 = 8
  sample :loop_amen, beat_stretch: 2, num_slices: n1, slice: choose
  sleep 2.0/n1
end

Warmly,
Halloworld :smiley:

Hi @halloworld
I’m not getting repeating slices, your 2nd example works as expected - choosing a different slice number each iteration. Even if I change some opts and var names, it works fine. This would suggest there is something elsewhere in your code that is throwing this off.

live_loop :samp_slicer2 do
  num = 4
  sample :loop_amen, num_slices: num, slice: choose
  sleep 2.0/num
end

PD-Pi

. . . and here’s the proof:

live_loop :proof do
  tick
  num = 8
  sample :loop_amen, beat_stretch: 2, num_slices: num, slice: look
  sleep 2.0/num
end

Hey thanks so much!

I restarted Sonic Pi and then behaved as I expected, I appreciate you testing it!

1 Like