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

**URL:** https://in-thread.sonic-pi.net/t/i-need-some-explanation-in-a-sam-aarons-piece-of-code/9148
**Category:** Support, Help & Resources
**Created:** [August 24, 2024, 9:37am UTC](https://in-thread.sonic-pi.net/t/i-need-some-explanation-in-a-sam-aarons-piece-of-code/9148 "2024-08-24T09:37:40Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![beryann](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/beryann/32/2623_2.png) [@beryann](https://in-thread.sonic-pi.net/u/beryann)
#### Post date: [August 24, 2024, 9:37am UTC](https://in-thread.sonic-pi.net/t/i-need-some-explanation-in-a-sam-aarons-piece-of-code/9148/1 "2024-08-24T09:37:40Z")

</div>

Hi there, I need an explanation about this:

```ruby
# 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! 😀

---

<div class="post-metadata">

### Author: ![brendanmac](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/brendanmac/32/2809_2.png) [@brendanmac](https://in-thread.sonic-pi.net/u/brendanmac)
#### Post date: [August 24, 2024, 10:10am UTC](https://in-thread.sonic-pi.net/t/i-need-some-explanation-in-a-sam-aarons-piece-of-code/9148/2 "2024-08-24T10:10:41Z")

</div>

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

---

<div class="post-metadata">

### Author: ![beryann](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/beryann/32/2623_2.png) [@beryann](https://in-thread.sonic-pi.net/u/beryann)
#### Post date: [August 24, 2024, 12:36pm UTC](https://in-thread.sonic-pi.net/t/i-need-some-explanation-in-a-sam-aarons-piece-of-code/9148/3 "2024-08-24T12:36:45Z")

</div>

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

---

<div class="post-metadata">

### Author: ![brendanmac](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/brendanmac/32/2809_2.png) [@brendanmac](https://in-thread.sonic-pi.net/u/brendanmac)
#### Post date: [August 24, 2024, 12:52pm UTC](https://in-thread.sonic-pi.net/t/i-need-some-explanation-in-a-sam-aarons-piece-of-code/9148/4 "2024-08-24T12:52:41Z")

</div>

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

---

<div class="post-metadata">

### Author: ![beryann](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/beryann/32/2623_2.png) [@beryann](https://in-thread.sonic-pi.net/u/beryann)
#### Post date: [August 24, 2024, 1:17pm UTC](https://in-thread.sonic-pi.net/t/i-need-some-explanation-in-a-sam-aarons-piece-of-code/9148/5 "2024-08-24T13:17:54Z")

</div>

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

```ruby

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:

```ruby
 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 😉  
thanks for your attention!

---

<div class="post-metadata">

### Author: ![brendanmac](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/brendanmac/32/2809_2.png) [@brendanmac](https://in-thread.sonic-pi.net/u/brendanmac)
#### Post date: [August 24, 2024, 4:15pm UTC](https://in-thread.sonic-pi.net/t/i-need-some-explanation-in-a-sam-aarons-piece-of-code/9148/6 "2024-08-24T16:15:27Z")

</div>

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:

```ruby
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 😉

PD-Pi

---

<div class="post-metadata">

### Author: ![beryann](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/beryann/32/2623_2.png) [@beryann](https://in-thread.sonic-pi.net/u/beryann)
#### Post date: [August 25, 2024, 6:20pm UTC](https://in-thread.sonic-pi.net/t/i-need-some-explanation-in-a-sam-aarons-piece-of-code/9148/7 "2024-08-25T18:20:39Z")

</div>

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

---

<div class="post-metadata">

### Author: ![brendanmac](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/brendanmac/32/2809_2.png) [@brendanmac](https://in-thread.sonic-pi.net/u/brendanmac)
#### Post date: [August 25, 2024, 6:55pm UTC](https://in-thread.sonic-pi.net/t/i-need-some-explanation-in-a-sam-aarons-piece-of-code/9148/8 "2024-08-25T18:55:08Z")

</div>

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

---

<div class="post-metadata">

### Author: ![beryann](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/beryann/32/2623_2.png) [@beryann](https://in-thread.sonic-pi.net/u/beryann)
#### Post date: [August 25, 2024, 7:07pm UTC](https://in-thread.sonic-pi.net/t/i-need-some-explanation-in-a-sam-aarons-piece-of-code/9148/9 "2024-08-25T19:07:36Z")

</div>

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