Skip to content

Instantly share code, notes, and snippets.

@zenon
Created March 20, 2017 06:30
Show Gist options
  • Save zenon/41c070ddf85a88a8a4e9302ae8fbbe38 to your computer and use it in GitHub Desktop.
Save zenon/41c070ddf85a88a8a4e9302ae8fbbe38 to your computer and use it in GitHub Desktop.
Shepard tones example for Sonic Pi
# Want to make it better?
# 1. the volume scale should center about a
# frequency, not an octave
# 2. Check why using saw instead of sine doesn't work somehow.
# 3. The scaling with v and s shall make the overall volume
# sounds right AND smooth the ends.
# This should be seperated.
# 4. The smooting may be easier using subtractive synthesis
# 5. Can I create a complete synthesizer this way? What is missing?
define :shepard do |n|
i = (note_info n)
mn = i.midi_note
mnr = mn % 12
for x in [0,1,2,3,4,5,6,7,8,9,10,11]
z = note(mnr + 12 * x)
s = 40.0
v = 0
if x <= 5
v = (x+1) / s
else
v = (11.5 - x)/s
end
synth :sine, note: z, amp: v
end
end
n = (ring :a, :as, :b, :c, :cs, :d, :ds, :e, :f, :fs, :g, :gs).reverse
loop do
tick
shepard n.look
sleep 0.4
end
@mbutz
Copy link

mbutz commented May 25, 2017

Great! Thanks for this example.

@benjaminwand
Copy link

Regarding no. 5, might I have written something like a complete synth here?
https://github.com/benjaminwand/Sonic-Pi-Shepard-tones-function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment