How to improve this code, so Sonic Pi dont crash?

How do I improve this code, so Sonic Pi dont crash during tabla samples? v3.3.1
YoutTube of Crash

#drone 211213 15:33

with_fx :gverb do
  use_synth :fm
  #  play :a5, release: 16, attack: 4, amp: 0.2
  
  #  play :ds4, release: 16, attack: 4, amp: 0.2
  #play :c2+01, release: 16, attack: 4, amp: 0.2
  #  play :c1, release: 32, attack: 4, amp: 0.2
end

live_loop :ambiance do
  use_synth  :dark_ambience
  #  play :c3, release: 24, attack: 4, cutoff: 80
  sleep 16
end

live_loop :noise do
  use_synth  :gnoise
  #  play :c5, release: 24, attack: 4, cutoff: 40, amp: 2
  sleep 16
end

#sample

live_loop :fast do
  with_fx :reverb do
    # sample :tabla_dhec, cutoff: ring(40,50,60,90,110).choose, amp: ring(3,5,1,1).choose+2, pan: ring(-1,1).choose, pitch: ring(0,24,12).choose
    # sample :tabla_ghe6, cutoff: ring(40,50,60,90,110).choose, amp: ring(3,1,1,1).choose+0, pan: ring(-1,1).choose, pitch: ring(0,-12,12).choose
    # sample :tabla_tas2, cutoff: ring(40,50,60,90,110).choose, amp: ring(3,1,1,1).choose+3, pan: ring(-1,1).choose, pitch: ring(0,-12,12).choose
    # sample :tabla_tun2, cutoff: ring(40,50,60,90,110).choose, amp: ring(3,1,5,1).choose+4, pan: ring(-1,1).choose, pitch: ring(0,-24,-12).choose
    sleep ring(0.125).choose
  end
end




live_loop :drums do
  with_fx :reverb do
    with_fx :bitcrusher do
      sleep ring(0.5,0.25,0.75).choose
      #      sample :bd_haus, cutoff: ring(80,90,110,70).choose, amp: 2
    end
  end
end

Hello @Relaxnow,

I’ve taken the liberty of formatting your code nicely. (FYI, you can do this by wrapping code with a line before and after that both have three backticks ``` on them).

Regarding the crashing, details of the issue and several solutions can be found in the in-app tutorial in chapter 6.2, ‘FX in practice’ (also online at Sonic Pi - Tutorial). Have a read and try one of those - let us know if you have any further questions :slightly_smiling_face:

Ty Ethan
With_fx outside live_loop’s seems to have fixed the issue. I can run all code without crashing.
Kind regards
Relaxnow

#drone 211214 15:23 (learned to place with_fx outside live_loop, so Sonic Pi dont crash)

use_sched_ahead_time 1

with_fx :gverb do
  use_synth :saw
  play :a5, release: 16, attack: 4, amp: 0.2
  play :ds4, release: 16, attack: 4, amp: 0.2
  play :c2, release: 16, attack: 4, amp: 0.2, cutoff: 70
  play :c1, release: 32, attack: 4, amp: 0.2
end

live_loop :ambiance do
  use_synth  :dark_ambience
  play :c3, release: 24, attack: 4, cutoff: 80
  sleep 16
end

live_loop :noise do
  use_synth  :gnoise
  play :c5, release: 24, attack: 4, cutoff: 40, amp: 2
  sleep 16
end

#samples
with_fx :reverb do
  live_loop :fast do
    sample :tabla_dhec, cutoff: ring(40,50,60,90,110).choose, amp: ring(3,5,1,1).choose+2, pan: ring(-1,1).choose, pitch: ring(0,24,12).choose
    sample :tabla_ghe6, cutoff: ring(40,50,60,90,110).choose, amp: ring(3,1,1,1).choose+0, pan: ring(-1,1).choose, pitch: ring(0,-12,12).choose
    sample :tabla_tas2, cutoff: ring(40,50,60,90,110).choose, amp: ring(3,1,1,1).choose+3, pan: ring(-1,1).choose, pitch: ring(0,-12,12).choose
    sample :tabla_tun2, cutoff: ring(40,50,60,90,110).choose, amp: ring(3,1,5,1).choose+4, pan: ring(-1,1).choose, pitch: ring(0,-24,-12).choose
    sleep ring(0.125).choose
  end
end



with_fx :reverb do
  with_fx :bitcrusher do
    live_loop :drums do
      sleep ring(0.5,0.25,0.75).choose
      sample :bd_haus, cutoff: ring(80,90,110,70).choose, amp: 4
    end
  end
end
1 Like

You’re welcome - sounds good too btw :slight_smile:

1 Like

Just wondering: Do “with_fx” run when all the samples are uncommented with # inside?

I mean. Do I need to use / / around on a code section that are not active to be on the safe side?

As I understand it, yes, fx will run regardless of whether any sounds inside them are commented out or not.
As to whether this can still become a performance problem, perhaps, but I’d appreciate @samaaron’s confirmation on that :slight_smile: Just like when you have active sounds within the fx block, I’m sure it depends on the amount of time in each cycle of the enclosing live_loop. If there are enough sleeps of the right duration in the live_loop to allow a single fx instance to complete before the next one is triggered for example, then there shouldn’t really be any need to comment anything out I’d say.