# Exploring define with spread #sonicpi

**URL:** <https://in-thread.sonic-pi.net/t/exploring-define-with-spread-sonicpi/8387>\
**Category:** Creations & Ideas\
**Created:** [November 22, 2023, 11:26pm UTC](https://in-thread.sonic-pi.net/t/exploring-define-with-spread-sonicpi/8387 "2023-11-22T23:26:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Relaxnow](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/relaxnow/32/2172_2.png) [@Relaxnow](https://in-thread.sonic-pi.net/u/Relaxnow)\
**Post date:** [November 22, 2023, 11:26pm UTC](https://in-thread.sonic-pi.net/t/exploring-define-with-spread-sonicpi/8387/1 "2023-11-22T23:26:50Z")

</div>

[![](https://img.youtube.com/vi/USOvqXtbcnA/hqdefault.jpg "Exploring define with spread #sonicpi") ](https://www.youtube.com/watch?v=USOvqXtbcnA)

```ruby
# 231123 0027 exploring define with spread
# Saved 231123 0027
# https://youtu.be/USOvqXtbcnA
# https://in-thread.sonic-pi.net/t/exploring-define-with-spread-sonicpi/8387

set_volume! 2
use_bpm 180

define :myspread do |n1,n2,a,b,c|
  play n1 if spread(a,b).look
  play n2 if spread(a,b+c).look
end

#define :myspreadsample do |n1,n2,a,b,c| # not used
#sample n1, amp: 0.7, cutoff: 86 if spread(a,b).look
#sample n2 if spread(a,b+c).look
#end

live_loop :a1 do
  tick
  
  / bass /
  kn = 16
  use_synth_defaults release: [0.15,0.25,0.35].choose, cutoff: [70,80,90,100].look+line(-40,20,steps: 128).look
  use_synth :saw
  n3 = :c2
  myspread(n3,n3+24,5,8,1)
  
  / kick /
  sample :bd_fat, amp: 1 if spread(1,16).look
  sample :bd_fat, amp: 2.5 if spread(1,16).rotate(2).look
  
  / chords /
  with_fx :level, amp: 0.75 do
    with_fx :reverb,room: 0.4 do
      with_fx :ping_pong, mix: [0,1].choose do
        sample :sn_dolf,amp: 1, finish: 0.045 if spread([1,2,1,3].choose,8).rotate(4).look and one_in(2)
        use_synth :saw
        mel =knit(0,16,1,16,2,16,3,16,4,16,1,16).look
        note = :c5-0
        case mel
        when 0
        when 1
          play [note]
        when 2
          play [note,note+7]
        when 3
          play [note,note+3]
        when 4
          play [note-2,note+5]
        end
        
      end
    end
  end
  sleep 0.5
  
end

```

---

<div class="post-metadata">

**Author:** ![jonny](https://avatars.discourse-cdn.com/v4/letter/j/47e85d/32.png) [@jonny](https://in-thread.sonic-pi.net/u/jonny)\
**Post date:** [May 1, 2024, 3:20pm UTC](https://in-thread.sonic-pi.net/t/exploring-define-with-spread-sonicpi/8387/2 "2024-05-01T15:20:17Z")

</div>

This is pretty sick 🤘🏻  
I tried to run but I get timing errors on windows, even with loop `delay` and `set_sched_ahead_time! 5`

Tried with a 15 second delay… and it doesn’t fall over as quick, but I hear it struggling a bit… then it dies.

Will ASIO help? Any other workarounds? Are you using a powerful machine ? Mac/linux?

I found advice from Ethan on timing errors [here](https://in-thread.sonic-pi.net/t/time-error-with-higher-tempo-some-advices/4144/2) and tried commenting out the reverb and seems okay on first run (sched\_ahead and loop delay 30!)

I then took a punt and removed the delays, and broke my sp, restart required!  
reattempt post restart, for me I seem to need a delay of ~10, but think even then I’m merely prolonging the inevitable…

![image](https://europe1.discourse-cdn.com/flex017/uploads/sonic_pi/original/2X/c/c0810eb0e04fa854d6f6c2e76f6adffcae92a663.png)

💡previously I seemed to fix my own timing issues by reducing output (puts) , but this doesn’t appear to be an option here!

---

<div class="post-metadata">

**Author:** ![Davids-Music-Lab](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/davids-music-lab/32/512_2.png) [@Davids-Music-Lab](https://in-thread.sonic-pi.net/u/Davids-Music-Lab)\
**Post date:** [May 1, 2024, 3:40pm UTC](https://in-thread.sonic-pi.net/t/exploring-define-with-spread-sonicpi/8387/3 "2024-05-01T15:40:27Z")

</div>

I have a decent machine, but the process is only using ~1% of one core, this should run fine on most computers.  
What does the Task Manager say about CPU & Memory?

To improve performance, I would probably move the reverb outside the loop. At 180BPM this is creating six new delays and reverbs per second (might lead to a memory problem).
