Sleep duration bug in Example?

Hello all!

Very new user here… only started playing with Sonic PI 2 days ago.

I used to have some issues with sleep durations (I mean inside Sonic PI, not in real life…) I realized after playing with Sonic PI for the first day that… the sleep duration in a live_loop must be >= to the duration of all synths & samples played. This might be obvious for you all, but it wasn’t for me, so I got very frustrated after I made Sonic PI crash many times in just the first day. But eventually I realized it was my fault.


Given my above observation (the sleep duration must be >= to the duration of the longest sound inside a live_loop)


Given that a synth with attack:6 and release:6 takes 12 measures to play (that is my understanding after reading the section on envelopes in the tutorial 2 times).

Does this mean there is a bug in the “Ambient Experiment” Example? Or did I miss something:

Here is the offending code (copy-pasted from the example):

  live_loop :note1 do
    play choose([:D4,:E4]), attack: 6, release: 6
    sleep 8

Will this code essentially keep playing 12 measure long sounds while only sleeping 8, thus spawning more threads at every iteration?

Hi @ibz,
There is no bug here. The ambient experiment example is designed to deliberately have overlapping sounds :slightly_smiling_face:

Regarding the confusion over loop durations and envelopes, thanks for the feedback. It may well be useful to improve the documentation in this area! I’ll see if there’s a way we can include a note about this somewhere in future.

(Just to clarify/confirm, the effective duration of a live_loop, (which may be determined by sleep values, or intervals between an event of some kind releasing a sync) must be >= to the longest sound within it in order to avoid overlaps. If you are happy with having them, then there is no problem :slightly_smiling_face: ).

Indeed, you are right, it makes sense now.

However, is there any way in which, if the sleep duration is too small relative to the sound duration, the live_loop would keep spawning threads faster than they can finish? Or is that impossible to get into given just synth/samples (with various rate:) and sleeps?

The live loop is a single long-lived thread that does not spawn others when it loops around. It will, however, in the situation where sleeps and syncs cause it to be shorter than the longest sound, create new synth, fx or sample nodes for playback before previous ones have finished.

1 Like