Experiment with just intervals on continuous frequency (dynamic scale root / dynamic tuning)

r = [
  1/2.0,
  1/3.0,
  2/3.0,
  2/5.0,
  3/4.0,
  3/5.0,
  3/7.0,
  3/8.0,
  4/5.0,
  4/7.0,
  4/9.0,
  4/11.0,
  4/13.0,
  5/6.0,
  5/7.0,
  5/8.0,
  5/9.0,
  6/7.0,
  6/11.0,
  6/13.0,
  6/17.0,
  7/8.0,
  7/9.0,
  7/10.0,
  7/11.0,
  7/12.0,
  7/13.0,
  7/15.0,
  7/16.0,
  7/17.0,
  7/18.0,
  7/19.0,
  7/20.0,
  ##| 8/9.0,
  ##| 8/11.0,
  ##| 8/13.0,
  ##| 8/15.0,
  ##| 8/17.0,
  ##| 8/19.0,
  ##| 8/21.0,
  ##| 8/23.0,
  1/1.0,
  2/1.0,
  3/1.0,
  3/2.0,
  5/2.0,
  4/3.0,
  5/3.0,
  7/3.0,
  8/3.0,
  5/4.0,
  7/4.0,
  9/4.0,
  11/4.0,
  13/4.0,
  6/5.0,
  7/5.0,
  8/5.0,
  9/5.0,
  7/6.0,
  11/6.0,
  13/6.0,
  17/6.0,
  8/7.0,
  9/7.0,
  10/7.0,
  11/7.0,
  12/7.0,
  13/7.0,
  15/7.0,
  16/7.0,
  17/7.0,
  18/7.0,
  19/7.0,
  20/7.0,
  ##| 9/8.0,
  ##| 11/8.0,
  ##| 13/8.0,
  ##| 15/8.0,
  ##| 17/8.0,
  ##| 19/8.0,
  ##| 21/8.0,
  ##| 23/8.0
]
ru = [
  1/1.0,
  2/1.0,
  3/1.0,
  3/2.0,
  5/2.0,
  4/3.0,
  5/3.0,
  7/3.0,
  8/3.0,
  5/4.0,
  7/4.0,
  9/4.0,
  11/4.0,
  13/4.0,
  6/5.0,
  7/5.0,
  8/5.0,
  9/5.0,
  7/6.0,
  11/6.0,
  13/6.0,
  17/6.0,
  8/7.0,
  9/7.0,
  10/7.0,
  11/7.0,
  12/7.0,
  13/7.0,
  15/7.0,
  16/7.0,
  17/7.0,
  18/7.0,
  19/7.0,
  20/7.0,
  ##| 9/8.0,
  ##| 11/8.0,
  ##| 13/8.0,
  ##| 15/8.0,
  ##| 17/8.0,
  ##| 19/8.0,
  ##| 21/8.0,
  ##| 23/8.0
]
rd = [
  1/1.0,
  1/2.0,
  1/3.0,
  2/3.0,
  2/5.0,
  3/4.0,
  3/5.0,
  3/7.0,
  3/8.0,
  4/5.0,
  4/7.0,
  4/9.0,
  4/11.0,
  4/13.0,
  5/6.0,
  5/7.0,
  5/8.0,
  5/9.0,
  6/7.0,
  6/11.0,
  6/13.0,
  6/17.0,
  7/8.0,
  7/9.0,
  7/10.0,
  7/11.0,
  7/12.0,
  7/13.0,
  7/15.0,
  7/16.0,
  7/17.0,
  7/18.0,
  7/19.0,
  7/20.0,
  ##| 8/9.0,
  ##| 8/11.0,
  ##| 8/13.0,
  ##| 8/15.0,
  ##| 8/17.0,
  ##| 8/19.0,
  ##| 8/21.0,
  ##| 8/23.0
]

use_bpm 26
use_random_seed 1

n = 440
n1 = n

index = 0
extra_sleep = 0


with_fx :reverb, room: 0.7 do
  with_fx :reverb, room: 0.2 do
    live_loop :monochord do
      use_synth :tech_saws
      if n <= 180
        n = n * ru[(index + choose([0,0,-1,0,1,0,0])) % ru.length]
      elsif n >= 720
        n = n * rd[(index + choose([0,0,-1,0,1,0,0])) % rd.length]
      else
        n = n * r[(index + choose([0,0,-1,0,1,0,0])) % r.length]
      end
      play hz_to_midi(n), amp: 0.5, sustain: 0.85 + extra_sleep
      n = n1
      index += 19
      sleep 1 + extra_sleep
      extra_sleep = choose([0,0,0.25,0.5,0.5,1,0.25,-0.5,-0.5,-0.25,
                            0,0,0.25,0.5,0.5,1,0.25,-0.5,-0.5,-0.25,
                            0,0,0.25,0.5,0.5,1,0.25,-0.5,-0.5,-0.25,
                            0,0,0.25,0.5,0.5,1,0.25,-0.5,-0.5,-0.25,
                            0,0,0.25,0.5,0.5,1,0.25,-0.5,-0.5,-0.25,
                            0,0,0.25,0.5,0.5,1,0.25,-0.5,-0.5,-0.25,
                            0,0,0.25,0.5,0.5,1,0.25,-0.5,-0.5,-0.25,1.5,2,3,4,5,6])
    end
  end
end


live_loop :krazychord do
  stop
  sleep extra_sleep * 0.5
  use_synth :tri
  if n <= 100
    n = n * choose(ru)
  elsif n >= 600
    n = n * choose(rd)
  else
    n = n * choose(r)
  end
  
  play hz_to_midi(n), amp: 0.5
  play hz_to_midi(n*7/6.0), amp: 0.25
  play hz_to_midi(n*6/5.0), amp: 0.125
  play hz_to_midi(n*5/4.0), amp: 0.0625
  play hz_to_midi(n*4/3.0), amp: 0.03125
  play hz_to_midi(n*3/2.0), amp: 0.015625
  play hz_to_midi(n*2/1.0), amp: 0.0078125
  ##| play hz_to_midi(n*6/7.0), amp: 0.25
  ##| play hz_to_midi(n*5/6.0), amp: 0.125
  ##| play hz_to_midi(n*4/5.0), amp: 0.0625
  ##| play hz_to_midi(n*3/4.0), amp: 0.03125
  ##| play hz_to_midi(n*2/3.0), amp: 0.015625
  ##| play hz_to_midi(n*1/2.0), amp: 0.0078125
  ##| n = n1
  sleep 1 + extra_sleep * 0.5 + choose([0,0.1,0.2,0.3,-0.2,-0.4])
end



n0 = 440

sleep_shift = 0

with_fx :reverb, room: 0.7 do
  with_fx :reverb, room: 0.2 do
    live_loop :bichord do
      use_synth :tech_saws
      if n0 <= 180
        n1 = n1 * ru[index % ru.length]
      elsif n0 >= 720
        n1 = n1 * rd[index % rd.length]
      else
        n1 = n1 * r[index % r.length]
      end
      sleep_shift = choose([0.25,0.5,0.25,0,0,0,0,0])
      sleep sleep_shift
      play hz_to_midi(n0), amp: 0.5, sustain: 0.85 + extra_sleep
      play hz_to_midi(n1), amp: 0.5, sustain: 0.85 + extra_sleep
      n0 = n1
      sleep 1 - sleep_shift + extra_sleep
    end
  end
end

Wow! About to contribute an interval experiment of my own then this came up :+1:t2:

Is asked gpt about your rationale of variable names like ru and rd (I thought it might be ratio up and down!) and also for a refactor…

shaved nearly 200 lines, and sounds the same to my untrained ear!

n = n * ru[index + ...]
Was it “rational up” and “rational down”, as GPT guessed at?

The revision (hope you don’t mind me sharing!)

# Define a function to generate the arrays
def generate_array(start, stop, step)
  (start..stop).step(step).map { |i| Rational(i, i + step) }
end

# Define arrays
r = generate_array(1, 7, 1)
ru = generate_array(1, 20, 1)
rd = generate_array(1, 20, 1).reverse

use_bpm 26
use_random_seed 1

n = 440
n1 = n

index = 0
extra_sleep = 0

with_fx :reverb, room: 0.7 do
  with_fx :reverb, room: 0.2 do
    live_loop :monochord do
      use_synth :tech_saws
      
      n_arr = case n
      when (0..180) then ru
      when (720..) then rd
      else r
      end
      
      n *= n_arr[(index + choose([0,0,-1,0,1,0,0])) % n_arr.length]
      
      play hz_to_midi(n), amp: 0.5, sustain: 0.85 + extra_sleep
      
      index += 19
      sleep 1 + extra_sleep
      extra_sleep = choose([0,0,0.25,0.5,0.5,1,0.25,-0.5,-0.5,-0.25] * 6 + [1.5,2,3,4,5,6])
    end
  end
end

n0 = 440

sleep_shift = 0

with_fx :reverb, room: 0.7 do
  with_fx :reverb, room: 0.2 do
    live_loop :bichord do
      use_synth :tech_saws
      
      n_arr = case n0
      when (0..180) then ru
      when (720..) then rd
      else r
      end
      
      n1 *= n_arr[index % n_arr.length]
      
      sleep_shift = choose([0.25,0.5,0.25,0,0,0,0,0])
      sleep sleep_shift
      
      play hz_to_midi(n0), amp: 0.5, sustain: 0.85 + extra_sleep
      play hz_to_midi(n1), amp: 0.5, sustain: 0.85 + extra_sleep
      
      n0 = n1
      sleep 1 - sleep_shift + extra_sleep
    end
  end
end

credits to you! and the chatbot

1 Like

Yes, ru are values greater than 1 and rd are values smaller than 1. So that tells you if multiplication will increase or decrease the frequency. Sorry for not writing code that’s easier to understand. Especially with Sonic Pi I have a tendency to be terse, but when sharing I could at least include better comments.

Well, not so terse in every sense of the word. You shortened my code, so it’s much shorter and easier to read. The music is not equivalent because my values were specifically chosen, not just a straight sequence.