Discrete and continuous Shepard tone

An infinite sequence of ever increasing tones, see Wikipedia article. Maybe it is of interest for some educational purposes.

Here is a discrete version:

use_debug false
use_bpm 100
st = 1

sca = scale :C1, :ionian, num_octaves: 8
sca = sca[0, sca.length - 1]  # omit last note
l = sca.length  # 56 = 8*7
amp_min = 0.4
amp_max = 1.0
steps = l/2
step_size = (amp_max-amp_min)/steps
amp_steps = (range amp_min, amp_max, step_size).mirror


with_synth :fm do
  with_synth_defaults attack: 0.01, sustain: st, release: 0.1 do
    live_loop :sequence do
      tick_set :seq1, 0
      tick_set :seq2, 14
      tick_set :seq3, 28
      tick_set :seq4, 42
      l.times do
        play sca.tick(:seq1), amp: amp_steps[look(:seq1)]
        play sca.tick(:seq2), amp: amp_steps[look(:seq2)]
        play sca.tick(:seq3), amp: amp_steps[look(:seq3)]
        play sca.tick(:seq4), amp: amp_steps[look(:seq4)]
        sleep st
      end
    end
  end
end

… and here the continuous version:

use_debug false
use_bpm 100
st = 1

sca = range 30, 30+8*12, 1  # 8 octaves
l = sca.length
amp_min = 0.4
amp_max = 1.0
steps = l/2
step_size = (amp_max-amp_min)/steps
amp_steps = (range amp_min, amp_max, step_size).mirror


with_synth :beep do
  with_synth_defaults attack: 0.1, sustain: st, release: 0.05, note_slide: st do
    live_loop :sequence do
      tick_set :seq1, 0
      tick_set :seq2, 24
      tick_set :seq3, 48
      tick_set :seq4, 72
      l.times do
        n1 = play sca.tick(:seq1), amp: amp_steps[look(:seq1)]
        n2 = play sca.tick(:seq2), amp: amp_steps[look(:seq2)]
        n3 = play sca.tick(:seq3), amp: amp_steps[look(:seq3)]
        n4 = play sca.tick(:seq4), amp: amp_steps[look(:seq4)]
        control n1, note: sca[look(:seq1) + 1] if look(:seq1) != l - 1
        control n2, note: sca[look(:seq2) + 1] if look(:seq2) != l - 1
        control n3, note: sca[look(:seq3) + 1] if look(:seq3) != l - 1
        control n4, note: sca[look(:seq4) + 1] if look(:seq4) != l - 1
        sleep st
      end
    end
  end
end
3 Likes

Interesting, thanks for sharing!