Thread got too far behind time

set :bpm, 127

live_loop :metro do
  use_bpm get[:bpm]
  sleep 4

with_fx :reverb, room: 0.2 do
  live_loop :bass_2, sync: :control do
    use_random_seed 2077
    use_bpm get[:bpm]
    ##| stop
    cp = get[:cp]
    sc = get[:sc]
    n2 = [5,0,0,7, 3,0,0,1, 0,5,0,1, 0,0,0,1].look
    notes = scale(cp, sc).shuffle.look
    notes2 = scale(cp, sc).shuffle.look
    notes3 = scale(cp, sc)[n2]
    num = rrand_i(0, 64)
    num2 = rrand_i(0,64)
    with_fx :eq, high: -0.5, low_shelf: 0.6, high_shelf: 0 do
      if spread(25, 32).rotate(num).look
        with_fx :lpf, cutoff: 60 do
          synth :tb303,
            note: notes3 - 12,
            res: (range 0, 0.9, 0.1).mirror.look,
            cutoff: (range 40, 120, 1).mirror.look,
            pan: (range -1, 1, 0.01).look,
            wave: 0,
            amp: 1, amp_slide: 16,
            release: 0.4
    sleep 0.4
    ##| stop

can someone help me understand why i am getting an error here

It’s quite possible that Sonic Pi is not able to keep up, given the resources available on your device, the combination of fx and the length and timing of the sounds that you are playing.

In case you haven’t read it, chapter 6.2 of the tutorial talks about the things to keep in mind when using fx, particularly if they are resource-intensive. I notice that you’ve placed the :reverb fx outside of the live_loop (which is one of the techniques the chapter describes). If the above code is still having timing issues from the resources being overloaded, then there are a couple of other things you can do to reduce or eliminate this:

  • you could also move the other fx (:eq, :lpf) outside of the live_loop
  • you could play more notes at a time for each cycle of the live_loop (with X.times do ... end).

Hope that helps!

1 Like


in addition to @ethancrawford’s points, if you’re running Sonic Pi on a Windows laptop then you can check whether or not plugging in your power chord helps matters. If it does improve things for you, there’s a good chance your computer’s energy saving settings are getting in the way a little (this is something I’ve observed on a number of different Windows laptops).

Also, you might want to check your audio driver. If there’s an ASIO driver available for your audio hardware, then I would highly recommend you use that. I’ve personally noticed that switching device drivers has had a dramatic effect on Sonic Pi’s ability to keep within time constraints on my Windows laptop.

Good luck!

1 Like

Good tip about placing the effects outside the loop. I did not realize that. It may be why I always run into minor issues with samples triggering out of time while I’m trying to record my jams.

1 Like

It did!! BIG thanks to you and @ethancrawford! I read all of the tutorial, but in my learning have forgotten how important little differences like that can make, and learning to be more conscious of where I place my fx will only help in the long run.

Have a beautiful day!