home/ atoms/ sonic-pi-beat-stretch

beat_stretch: maps a sample to a specified beat count at the current BPM

The beat_stretch: opt time-stretches (or compresses) a sample so its duration exactly matches N beats at the current BPM. Unlike rate: which changes both speed and pitch, beat_stretch: compensates for tempo so a loop sample plays in sync regardless of BPM setting. Combining beat_stretch: with use_bpm lets you freely change tempo while loops stay locked to the grid. Standard idiom for seamlessly looping break samples in live performance.

Examples

live_loop :amen_break do use_bpm 100 sample :loop_amen, beat_stretch: 2 sleep 2 end

Assessment

Explain why sample :loop_amen, rate: 2, sleep 1 may drift at different BPMs, while beat_stretch: 2, sleep 2 stays locked.

“beat_stretch:` opt to ask Sonic Pi to stretch (or shrink) the sample to match the specified number o”
corpus · sonic-pi-built-in-tutorial · chunk 28