I need some explanation in a Sam Aaron's piece of code

Hi there, I need an explanation about this:

# Ambient2
# Original coded by Sam Aaron



load_samples(sample_names :guit)
sleep 2

with_fx :reverb, mix: 0.8 do
  live_loop :foo do
    
    sp_name = choose sample_names :guit
    s = sample sp_name, cutoff: rrand(70, 130), rate: 4 * rrand(0.1, 1.0), pan: rrand(-1, 1)
    
    sleep 0.5
  end
end

I have modified the “Ambient” coded by Sam Aaron and why the first “sleep” is at 2 since the other one is at 0.5? Thanks for your help! :grinning:

1 Like

Hi @beryann
The sleep 2 is executed only once, to allow time for all the samples to be loaded into memory, before executing the live loop. The code runs fine on a desktop/laptop without those first two lines of code, as the samples are built-in. The sleep 0.5 could be ‘any’ value.

HTH

PD-Pi

2 Likes

That’s perfectly clear now, thanks a lot Brendan! :nerd_face:@brendanmac

2 Likes

Sam and others may correct me if I’m wrong, but he optimises Sonic Pi code to run on all systems, including Raspberry Pi (with its lower specs), hence the sleep 2.

PD-Pi

1 Like

We hear (and see in the log) that it takes 2 seconds to load them…
Another question, in this example:


use_synth :hollow
with_fx :reverb, mix: 0.7 do
  with_fx :slicer, mix: 0.3, amp: 0.7 do

Is it possible to trigger the slicer effect not in the same time with the reverb one? writing this for instance:

 with_fx :slicer, mix: 0.3, amp: 0.7, delay: 24 do

And in general, is it possible to trigger effects at different time? It would be great :wink:
thanks for your attention!

Hi @beryann
No, delay: won’t work on with_fx. The way I would do it (again, as a non-programmer or relative newcomer to SonicPi) is as follows:

with_fx :bpf, mix: 0, res: 0.1, centre_slide: 4 do |foo|
  live_loop :test do
    val = tick
    control foo, centre: rrand(70, 130)
    control foo, mix: 1 if val >= 8
    sample :loop_amen
    puts val
    sleep sample_duration :loop_amen
  end
end

The with_fx block is given an argument (foo), which will update after 8 loops; the live_loop keeps track of loop iterations via tick. The BPF mix value initialises at zero, but when tick exceeds 7, the mix value is updated to 1, turning the effect mix on (if val >= 8). Not particularly elegant or sophisticated, but it works :wink:

PD-Pi

1 Like

Ok Brendan @brendanmac thanks a lot! I am going to try this and adopt it in my future composition! :wink: I’ll feedback an example…
(what does the centre_slide?)

Hi @beryann
Look in the Help files, for Synths and FX, towards the bottom are all the parameters that can have a slide value.

PD-Pi

1 Like

You are right @brendanmac that’s ok …I was searching at the wrong place, thanks :+1: