How to control sample length

Hello all,

I’ve been playing with samples more lately and haven’t found a good way to leave a samples sound untouched while changing it’s duration. What is the best way to modify the duration of a sample without changing the sample itself? I’ve been playing with enveloping samples but it’s not consistent for samples of different lengths.

Thanks for your time

You can use begin and finish to somewhat cut your sample. You can use beat_stretch to stretch it for a given duration (the pitch will change too). You can use pitch_stretch to change the pitch of the sample, but be careful, there is some strange audio behaviors waiting ahead. You can use rate to control the playback speed. It can be a negative or positive value and it will alter the pitch too.

Maybe someone could help you to do that, but from what I know of Sonic-Pi so far, I don’t think that there is a smart stretch thing like you can find in your favorite DAW. Maybe I’m wrong.

When I use the Sonic-Pi sampler, I usually try to use sounds that will behave nicely when deformed, stretched, altered, etc…


Thanks for the advice. I was having trouble figuring out how the envelope affected samples. If I understand correctly, do the enveloping commands always affect the sample in terms of seconds, meaning when bpm is changed, the commands giving to sample’s envelopes don’t change their lengths.

I believe sample envelopes don’t respond to the bpm, but there may be an option to change this behaviour in a later release. You can use the bt function to get times scaled by the current bpm as a workaround.


I’m not familiar with the bt function

Just use something like: sample :loop_amen, release: bt(1) to set release to 1 beat (scaled to current bpm) instead of 1 second.
You can look up the documentation for any function by typing it in Sonic Pi and hitting Ctrl + i.

1 Like