Why sample loop with randomized rate is not smooth?

loop do
  sample :loop_amen, rate: rrand(1,1.125)
  sleep sample_duration :loop_amen

in my computer this sounds louzy, in the toturials it is said that this is the way to loop over sample. (I just added the randomized rate)

Hi @nize - welcome to our community!

This is definitely one way to loop over samples - although if you keep reading on through the tutorial, you’ll discover the live_loop which is pretty much always more useful than the plain loop.

The reason it sounds strange is that you are modifying the rate randomly between 1 and 1.125. This will change the speed of the sample to be different every time round the loop to be somewhere between normal speed (1) and slightly faster than normal speed (1.125). However, you’re always waiting for the duration of the sample at normal speed before looping again. This will mean that there will always be a slight gap between loop iterations.

Is there any reason why you wanted to change the rate - or were you just looking to experiment? If it’s the latter, I’d definitely play with options such as cutoff: instead which won’t change the speed of the drums which in turn won’t change the rhythm of the loop.

Hope that this helps!

1 Like

Thank you! for the full answer :slight_smile:
is there a way to alter samples’ pitch while keeping its duration?

Hi @nize,

yes, have a look at the pitch option in sample, such as

sample :loop_amen, pitch: 2 # 2 semitones up

From the manual:

Pitch adjustment in semitones. 1 is up a semitone, 12 is up an octave, -12 is down an octave etc. Maximum upper limit of 24 (up 2 octaves). Lower limit of -72 (down 6 octaves). Decimal numbers can be used for fine tuning.