A bit of a mess with prophet cutoff and big reverb


# 240605 2234 A bit of a mess with prophet
# 240605 2234 Saved
# https://in-thread.sonic-pi.net/t/a-bit-of-a-mess-with-prophet/8919

set_volume! 2

with_fx :reverb, room: 0.9 do
  with_fx :krush do |krush|
    
    live_loop :a1 do
      tick
      #control krush, mix: [0,0.1,0.3,0.5].choose
      control krush, mix: [0].choose
      
      / bass /
      use_synth :prophet
      use_synth_defaults cutoff: [60,70,90,100,50].choose
      k = 32-8
      n = :f2+knit(0,k+8,-2,k,-4,k-4).look
      play n, amp: 2, pan: -0.5 if spread(11,32).look
      play n+12, amp: 2, pan: 0.5  if spread(13,32).look
      #      play n-12, amp: 2, pan: 0.5  if spread(13,32).look
      
      / random top melody /
      use_synth :saw
      use_synth_defaults cutoff: 70, release: [0.1,0.2,0.3].choose-0.05
      play scale(:f4, :minor_pentatonic).choose
      play scale(:f5, :minor_pentatonic).choose if spread(3,7).look
      
      sleep 0.25
    end
  end
  
  live_loop :a2 do
    tick
    / drums /
    sample :bd_haus, cutoff: 80, amp: 2 if (bools(1,0,1,0, 0,1,0,1, 0,0,0,0, 0,0,0,0)).look
    sample :sn_generic, finish: [0.01,0.02,0.03].choose, cutoff: [90,100,110,120,130].choose, pan: rdist(0.75) if (spread(3,5)+spread(5,7)).look
    sample :elec_tick, rpitch: 12, amp: [2,2,2,4].look if spread(1,4).rotate(2).look
    sleep 0.25
  end
  
end

2 Likes

Hi! Great music and great patch @Relaxnow !! :smiley:
I’d like to better understand this line :smiley:

sample :sn_generic, finish: [0.01,0.02,0.03].choose, cutoff: [90,100,110,120,130].choose, pan: rdist(0.75) if (spread(3,5)+spread(5,7)).look

and:

if (spread(3,5)+spread(5,7)

What does “rdist” and spread(3,5) + spread(5,7) with the +?
Thanks for your attention!
Cheers

2 Likes

Hi
The OP will give a more precise answer, but rdist is a random distribution around a given centre, like a more sophisticated rrand (you’ll find it described in the Lang helpfile). I’m not 100% certain about the maths behind it, but if, for example, you use rdist(0.75) the random values between -1 and 1 will favour positive values centred on 0.75; rdist(0.1) values will be centred around 0.1.

Adding 2 spread ranges together simply creates a longer slightly more complex ring of true/false values. Stops one irregular spread collection from sounding too repetitive, works really well here!

foo = spread(3,5)
puts foo
sleep 1

bar = spread(1,4)
puts bar
sleep 1

puts foo + bar

PD-Pi

3 Likes

okay Brendan thank you @brendanmac I am going to experiment this :smiley:

1 Like

Is a fast way to randomly pan between values -0.75 and 0.75

10.times do
 puts rdist(0.75)
end

I sometimes use different values for different instruments to spread the sound a bit between spreakers fx kick on rdist(0.25), snare on rdist(0.5), hihat on rdist(0.75)

2 Likes

@Relaxnow Thanks for the explanation about rdist, I am going to use it now in my code and good idea to spread the sounds…I tried this and works well (but is the sleep correct? :face_with_monocle:):

live_loop :rdist do
  sample :ambi_piano, rate: rdist(1.5)
  sleep 1
end
1 Like

Hi @beryann
I’m not sure what your question about the sleep value is, just remember sample playback behaviour may be unexpected, as samples have an individual fixed duration - the sustain opt is a good parameter for controlling sample duration, if that is what you mean?

Also note that some of those rate values will be very, very small, i.e. close to zero, rendering playback almost inaudible, but that may well be what you’re aiming for:

live_loop :rdist do
  rrate = rdist(1.5)
  sample :ambi_piano, rate: rrate, sustain: 0.9
  puts rrate
  sleep 1
end

PD-Pi

2 Likes

In fact, your example with ‘rrate’ answers to my question. Because of the different sound lengths due to this ‘rdist’, the idea was to find a ‘sleep’ adapted to this situation. Your solution with the sustain opt is good! So, I also tried this which is yet another solution and which of course gives a different result:

live_loop :rdist do
  sample :ambi_piano, rate: rdist(1.5)
  sleep rrand(0.1, 1.5)
end
1 Like

Hi again @beryann
reading between the lines (apologies if I misunderstand your question), but there is a fairly simple way to connect the rate value to the sleep value - i.e. make the sleep duration a reciprocal value of playback rate:

/ how to link sleep val to varying rate = maths /

mySamp = :glitch_robot1 # ~ 1s long
sample mySamp
puts sample_duration mySamp
# play the sample once and tell me its duration
sleep 2

#now I can make the sleep value the reciprocal of its playback rate
#caveat emptor, I'm crap at maths ;)

myRate = 1
/ this is the variable value, try 0.5, 3, 0.75, -1 go wild /
/ sample duration div by rate = sleep value /

sample mySamp, rate: myRate

puts "sleep value:"
puts ((sample_duration mySamp) / myRate).abs #in case you use negative rate vals

PD-Pi

1 Like

Hi Brendan @brendanmac it is what I tried to express a:

“way to connect the rate value to the sleep value”

But, I hope that my question (more precisely) doesn’t seem no relevant: is it possible to do the contrary? i.e a way to connect the sleep values to the rate values of rdist?Knowing that with rdist, with each loop I get a different rate like here:?

sample :ambi_piano, rate: rdist(1.5)
Thanks for attention

This doesn’t precisely solve your question, but to make the rate value the reciprocal of sleep requires a similar approach:

mySamp = :glitch_robot1

live_loop :test do
  slp = 2 # this is your variable
  myRate = 1.0/slp
  sample mySamp, rate: myRate
  sleep slp
end

But this currently only allows for positive rate values (because you cannot have negative sleep values). I’ll have a closer look at this later. . .

PD-Pi

2 Likes

Okay very good Brendan! :+1: @brendanmac and yes of course, it’s only correct for positive values…

mySamp = :glitch_robot1

live_loop :test do
  
  myRate = rdist(1.5)
  slp = (1.0/myRate).abs
  puts slp
  sample mySamp, rate: myRate
  sleep slp
end

This works but it will generate some very, VERY long sleep values, when rate is close to zero, so I cannot recommend this method, it’s just here to show you the maths involved. In one instance it generated a sleep value of “Infinity”! Someone else (more experienced) may provide a way to exclude very small rate values.

1 Like

This is VERY hacky, brute force, and there appear to be some sleep overlaps which I can’t track down :frowning: There will be more elegant ways to achieve what you require:

mySamp = :glitch_robot1

excl = [*-5..5] - [*-1..1]

live_loop :test do
  #stop
  tick
  myRate = (excl.shuffle.choose*(rand()+0.1))
  slp = (1.0/myRate).abs
  puts myRate
  sample mySamp, rate: myRate
  sleep slp
end
2 Likes

Sincere apologies to @Relaxnow, we appear to have hijacked your post; we should move it elsewhere

PD-Pi

Np. Love that we figure out how to do stuff in Sonic Pi :slight_smile:

2 Likes

I kinda went down a mini rabbit hole there :wink: