Skip to content

Instantly share code, notes, and snippets.

@emlyn
Last active June 13, 2022 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emlyn/ebdff933d4690e4d9ac990e534627129 to your computer and use it in GitHub Desktop.
Save emlyn/ebdff933d4690e4d9ac990e534627129 to your computer and use it in GitHub Desktop.
Sonic Pi Lissajous synth & Harmonograph figures

Sonic Pi Lissajous synth & Harmonograph figures

This gist contains a custom Sonic Pi synth for generating Lissajous figures, along with some Sonic Pi code to generate the figures in the post on in-thread

The source for the synthdef is in lisa.scsynth, with a compiled version available for download at lisa.scsyndef.

The Sonic Pi code is split into three parts, for the three figures in the post:

  • lateral.rb for the lateral Harmonograph figures,
  • rotary.rb for the rotary Harmonograph figures, and
  • decay.rb for the decaying amplitude figures.
# Decaying Harmonograph figures
# Load the synth, set the default params, and disable any overall filters
load_synthdefs ENV['HOME'] + '/.sonic-pi/synthdefs'
use_synth_defaults note: 72, attack: 0.5, sustain: 5, release: 0.5, amp: 1.8
set_mixer_control! hpf_bypass: 1, lpf_bypass: 1, limiter_bypass: 1, leak_dc_bypass: 1
# Change 'comment' to 'uncomment' in *one* of the following blocks to generate that figure:
######## Near Unison (page 23) ########
comment do
# a (p23)
16.times do
synth :lisa, left_ratio: 1.007, left_phase: 0.75, attack: 0, sustain: 0, release: 0.08
sleep 0.2
end
end
comment do
# b (p23)
16.times do
synth :lisa, left_ratio: 1.012, left_phase: 0.75, attack: 0, sustain: 0, release: 0.08
sleep 0.2
end
end
comment do
# c (p23)
16.times do
synth :lisa, left_ratio: 1.024, left_phase: 0.75, attack: 0, sustain: 0, release: 0.08
sleep 0.2
end
end
comment do
# d (p23)
16.times do
synth :lisa, left_ratio: 1.035, left_phase: 0.75, attack: 0, sustain: 0, release: 0.09
sleep 0.2
end
end
comment do
# e (p23)
16.times do
synth :lisa, left_ratio: 1.05, left_phase: 0.75, attack: 0, sustain: 0, release: 0.09
sleep 0.2
end
end
comment do
# f (p23)
16.times do
synth :lisa, left_ratio: 1.085, left_phase: 0.75, attack: 0, sustain: 0, release: 0.09
sleep 0.2
end
end
######## Amplitude (page 28) ########
use_synth_defaults note: 78, attack: 0, sustain: 0, release: 0.05, env_curve: 1
comment do
# Ratio 2:1 Amps 1:2 (p38)
5.times do
synth :lisa, ratio: 2, right_phase: 0.25, amp: 1.4/2
synth :lisa, ratio: 1, right_phase: -0.25, amp: 1.4
sleep 0.2
end
end
comment do
# Ratio 3:1 Amps 1:3 (p38)
5.times do
synth :lisa, ratio: 3, right_phase: 0.25, amp: 1.5/3
synth :lisa, ratio: 1, right_phase: -0.25, amp: 1.5
sleep 0.2
end
end
comment do
# Ratio 4:1 Amps 1:4 (p38)
5.times do
synth :lisa, ratio: 4, right_phase: 0.25, amp: 1.5/4
synth :lisa, ratio: 1, right_phase: -0.25, amp: 1.5
sleep 0.2
end
end
comment do
# Ratio 2:1 Amps 1:4 (p38)
5.times do
synth :lisa, ratio: 2, right_phase: 0.25, amp: 1.5/4
synth :lisa, ratio: 1, right_phase: -0.25, amp: 1.5
sleep 0.2
end
end
comment do
# Ratio 3:1 Amps 1:9 (p38)
5.times do
synth :lisa, ratio: 3, right_phase: 0.25, amp: 1.5/9
synth :lisa, ratio: 1, right_phase: -0.25, amp: 1.5
sleep 0.2
end
end
comment do
# Ratio 4:1 Amps 1:16 (p38)
5.times do
synth :lisa, ratio: 4, right_phase: 0.25, amp: 1.5/16
synth :lisa, ratio: 1, right_phase: -0.25, amp: 1.5
sleep 0.2
end
end
# Lateral Harmonograph figures
# Load the synth, set the default params, and disable any overall filters
load_synthdefs ENV['HOME'] + '/.sonic-pi/synthdefs'
use_synth_defaults attack: 0.5, sustain: 5, release: 0.5, amp: 1.5
set_mixer_control! hpf_bypass: 1, lpf_bypass: 1, limiter_bypass: 1, leak_dc_bypass: 1
# Change 'comment' to 'uncomment' in *one* of the following blocks to generate that figure:
######## 1 - 1 (page 20) ########
comment do
# 1-1 a (p20)
synth :lisa, right_phase: 0.5
end
comment do
# 1-1 b (p20)
synth :lisa, right_phase: 0.375
end
comment do
# 1-1 c (p20)
synth :lisa, right_phase: 0.25
end
comment do
# 1-1 d (p20)
synth :lisa, right_phase: 0.11
end
comment do
# 1-1 e (p20)
synth :lisa, right_phase: 0.0
end
######## 1 - 2 (page 26) ########
comment do
# 1-2 a (p26)
synth :lisa, left_ratio: 2, left_phase: 0.27
end
comment do
# 1-2 b (p26)
synth :lisa, left_ratio: 2, left_phase: 0.395
end
comment do
# 1-2 c (p26)
synth :lisa, left_ratio: 2, left_phase: 0.52
end
uncomment do
# 1-2 d (p26)
synth :lisa, left_ratio: 2, left_phase: 0.645
end
comment do
# 1-2 e (p26)
synth :lisa, left_ratio: 2, left_phase: 0.77
end
######## 1 - 3 (page 31) ########
comment do
# 1-3 a (p31)
synth :lisa, left_ratio: 3, left_phase: 0.035
end
comment do
# 1-3 b (p31)
synth :lisa, left_ratio: 3, left_phase: 0.160
end
comment do
# 1-3 c (p31)
synth :lisa, left_ratio: 3, left_phase: 0.285
end
comment do
# 1-3 d (p31)
synth :lisa, left_ratio: 3, left_phase: 0.410
end
comment do
# 1-3 e (p31)
synth :lisa, left_ratio: 3, left_phase: 0.535
end
######## 2 - 3 (page 31) ########
comment do
# 2-3 a (p31)
synth :lisa, left_ratio: 3, right_ratio: 2, left_phase: 0.38
end
comment do
# 2-3 b (p31)
synth :lisa, left_ratio: 3, right_ratio: 2, left_phase: 0.3175
end
comment do
# 2-3 c (p31)
synth :lisa, left_ratio: 3, right_ratio: 2, left_phase: 0.255
end
comment do
# 2-3 d (p31)
synth :lisa, left_ratio: 3, right_ratio: 2, left_phase: 0.1925
end
comment do
# 2-3 e (p31)
synth :lisa, left_ratio: 3, right_ratio: 2, left_phase: 0.13
end
######## 3 - 4 (page 34) ########
comment do
# 3-4 a (p34)
synth :lisa, left_ratio: 4, right_ratio: 3, left_phase: 0.752
end
comment do
# 3-4 b (p34)
synth :lisa, left_ratio: 4, right_ratio: 3, left_phase: 0.377
end
comment do
# 3-4 c (p34)
synth :lisa, left_ratio: 4, right_ratio: 3, left_phase: 0.502
end
comment do
# 3-4 d (p34)
synth :lisa, left_ratio: 4, right_ratio: 3, left_phase: 0.627
end
comment do
# 3-4 e (p34)
synth :lisa, left_ratio: 4, right_ratio: 3, left_phase: 0.252
end
######## 4 - 5 (page 15) ########
comment do
# 4-5 a (p15)
synth :lisa, left_ratio: 5, right_ratio: 4, right_phase: 0.25
end
comment do
# 4-5 b (p15)
synth :lisa, left_ratio: 5, right_ratio: 4, right_phase: 0.875
end
comment do
# 4-5 c (p15)
synth :lisa, left_ratio: 5, right_ratio: 4, right_phase: 0.5
end
comment do
# 4-5 d (p15)
synth :lisa, left_ratio: 5, right_ratio: 4, right_phase: 0.375
end
comment do
# 4-5 e (p15)
synth :lisa, left_ratio: 5, right_ratio: 4, right_phase: 0.75
end
######## 5 - 6 (page 15) ########
comment do
# 5-6 a (p15)
synth :lisa, left_ratio: 6, right_ratio: 5, left_phase: 0.25
end
comment do
# 5-6 b (p15)
synth :lisa, left_ratio: 6, right_ratio: 5, left_phase: 0.885
end
comment do
# 5-6 c (p15)
synth :lisa, left_ratio: 5, right_ratio: 6, left_phase: 0.5
end
comment do
# 5-6 d (p15)
synth :lisa, left_ratio: 6, right_ratio: 5, left_phase: 0.385
end
comment do
# 5-6 e (p15)
synth :lisa, left_ratio: 6, right_ratio: 5, left_phase: 0.75
end
(
SynthDef('lisa', {|
note = 52, note_slide = 0, note_slide_shape = 1, note_slide_curve = 0,
ratio = 1, ratio_slide = 0, ratio_slide_shape = 1, ratio_slide_curve = 0,
left_ratio = 1, left_ratio_slide = 0, left_ratio_slide_shape = 1, left_ratio_slide_curve = 0,
right_ratio = 1, right_ratio_slide = 0, right_ratio_slide_shape = 1, right_ratio_slide_curve = 0,
phase = 0, phase_slide = 0, phase_slide_shape = 1, phase_slide_curve = 0,
left_phase = 0, left_phase_slide = 0, left_phase_slide_shape = 1, left_phase_slide_curve = 0,
right_phase = 0, right_phase_slide = 0, right_phase_slide_shape = 1, right_phase_slide_curve = 0,
amp = 1, amp_slide = 0, amp_slide_shape = 1, amp_slide_curve = 0,
left_amp = 1, left_amp_slide = 0, left_amp_slide_shape = 1, left_amp_slide_curve = 0,
right_amp = 1, right_amp_slide = 0, right_amp_slide_shape = 1, right_amp_slide_curve = 0,
left_offset = 0, left_offset_slide = 0, left_offset_slide_shape = 1, left_offset_slide_curve = 0,
right_offset = 0, right_offset_slide = 0, right_offset_slide_shape = 1, right_offset_slide_curve = 0,
attack = 0, decay = 0, sustain = 0, release = 1,
attack_level = 1, decay_level = -1, sustain_level = 1, env_curve = 1,
out_bus = 0 |
var left, right, env;
note = note.varlag(note_slide, note_slide_curve, note_slide_shape);
ratio = ratio.varlag(ratio_slide, ratio_slide_curve, ratio_slide_shape);
left_ratio = left_ratio.varlag(left_ratio_slide, left_ratio_slide_curve, left_ratio_slide_shape);
right_ratio = right_ratio.varlag(right_ratio_slide, right_ratio_slide_curve, right_ratio_slide_shape);
phase = 2pi * phase.varlag(phase_slide, phase_slide_curve, phase_slide_shape);
left_phase = 2pi * left_phase.varlag(left_phase_slide, left_phase_slide_curve, left_phase_slide_shape);
right_phase = 2pi * right_phase.varlag(right_phase_slide, right_phase_slide_curve, right_phase_slide_shape);
amp = amp.varlag(amp_slide, amp_slide_curve, amp_slide_shape);
left_amp = left_amp.varlag(left_amp_slide, left_amp_slide_curve, left_amp_slide_shape);
right_amp = right_amp.varlag(right_amp_slide, right_amp_slide_curve, right_amp_slide_shape);
left_offset = left_offset.varlag(left_offset_slide, left_offset_slide_curve, left_offset_slide_shape);
right_offset = right_offset.varlag(right_offset_slide, right_offset_slide_curve, right_offset_slide_shape);
decay_level = Select.kr(decay_level < 0, [decay_level, sustain_level]);
left = SinOsc.ar(note.midicps * ratio * left_ratio, (phase + left_phase).mod(2pi), amp * left_amp, left_offset);
right = SinOsc.ar(note.midicps * ratio * right_ratio, (phase + right_phase).mod(2pi), amp * right_amp, right_offset);
env = Env.new([0, attack_level, decay_level, sustain_level, 0],
[attack, decay, sustain, release],
env_curve);
Out.ar(out_bus, [left, right] * EnvGen.kr(env, doneAction: 2))}
).writeDefFile("~/.sonic-pi/synthdefs/".asAbsolutePath)
)
# Rotary Harmonograph figures (page 0)
# Load the synth, set the default params, and disable any overall filters
load_synthdefs ENV['HOME'] + '/.sonic-pi/synthdefs'
use_synth_defaults attack: 0.5, sustain: 5, release: 0.5, amp: 1.5
set_mixer_control! hpf_bypass: 1, lpf_bypass: 1, limiter_bypass: 1, leak_dc_bypass: 1
# Change 'comment' to 'uncomment' in *one* of the following blocks to generate that figure:
comment do
# 3:2 equal amp. concurrent (p0)
synth :lisa, ratio: 2, right_phase: 0.25, phase: -0.01
synth :lisa, ratio: 3, right_phase: 0.25, phase: -0.01
end
comment do
# 3:2 inv. amp. concurrent (p0)
synth :lisa, ratio: 2, right_phase: 0.25, phase: -0.01, amp: 1.2
synth :lisa, ratio: 3, right_phase: 0.25, phase: -0.01, amp: 0.8
end
comment do
# 3:2 inv. amp. counterc. (p0)
synth :lisa, ratio: 2, right_phase: 0.25, phase: 0.49, amp: 1.2
synth :lisa, ratio: 3, right_phase: -0.25, phase: 0.49, amp: 0.8
end
comment do
# 2:1 equal amp. concurrent (p0)
synth :lisa, ratio: 1, right_phase: 0.25, phase: 0.98
synth :lisa, ratio: 2, right_phase: 0.25, phase: 0.98
end
comment do
# 2:1 equal amp. counterc. (p0)
synth :lisa, ratio: 1, right_phase: 0.25, phase: 0.48
synth :lisa, ratio: 2, right_phase: -0.25, phase: 0.48
end
comment do
# 2:1 inv. amp. counterc. (p0)
synth :lisa, ratio: 1, right_phase: 0.25, phase: -0.02, amp: 1.2
synth :lisa, ratio: 2, right_phase: -0.25, phase: -0.02, amp: 0.6
end
comment do
# 2:1 inv. amp. concurrent (p0)
synth :lisa, ratio: 1, right_phase: 0.25, phase: 0.98, amp: 1.2
synth :lisa, ratio: 2, right_phase: 0.25, phase: 0.98, amp: 0.6
end
comment do
# 7:3 inv. amp. counterc. (p0)
synth :lisa, ratio: 3, right_phase: 0.25, phase: 0.98, amp: 1.2
synth :lisa, ratio: 7, right_phase: -0.25, phase: 0.98, amp: 0.5
end
comment do
# 5:2 equal amp. counterc (p0)
synth :lisa, ratio: 2, right_phase: 0.25, phase: 0.74
synth :lisa, ratio: 5, right_phase: -0.25, phase: 0.74
end
comment do
# 5:2 inv. amp. counterc. (p0)
synth :lisa, ratio: 2, right_phase: 0.25, phase: 0.49, amp: 1.2
synth :lisa, ratio: 5, right_phase: -0.25, phase: 0.49, amp: 0.5
end
comment do
# 3:1 equal amp. counterc. (p0)
synth :lisa, ratio: 1, right_phase: 0.25, phase: 0.24, amp: 0.9
synth :lisa, ratio: 3, right_phase: -0.25, phase: 0.24, amp: 0.9
end
comment do
# 3:1 equal amp. concurrent (p0)
synth :lisa, ratio: 1, right_phase: 0.25, phase: -0.02, amp: 0.9
synth :lisa, ratio: 3, right_phase: 0.25, phase: -0.02, amp: 0.9
end
comment do
# 3:1 inv. amp. concurrent (p0)
synth :lisa, ratio: 1, right_phase: 0.25, phase: -0.02, amp: 1.2
synth :lisa, ratio: 3, right_phase: 0.25, phase: -0.02, amp: 0.4
end
comment do
# 3:1 inv. amp. counterc. (p0)
synth :lisa, ratio: 1, right_phase: 0.25, phase: 0.23, amp: 1.2
synth :lisa, ratio: 3, right_phase: -0.25, phase: 0.23, amp: 0.4
end
comment do
# 4:1 equal amp. concurrent (p0)
synth :lisa, ratio: 1, right_phase: 0.25, phase: 0.48
synth :lisa, ratio: 4, right_phase: 0.25, phase: 0.48
end
comment do
# 4:1 inv. amp. concurrent (p0)
synth :lisa, ratio: 1, right_phase: 0.25, phase: 0.48, amp: 1.2
synth :lisa, ratio: 4, right_phase: 0.25, phase: 0.48, amp: 0.3
end
comment do
# 5:1 equal amp. concurrent (p0)
synth :lisa, ratio: 1, right_phase: 0.25, phase: 0.48, amp: 0.9
synth :lisa, ratio: 5, right_phase: 0.25, phase: 0.48, amp: 0.9
end
comment do
# 5:1 inv. amp. concurrent (p0)
synth :lisa, ratio: 1, right_phase: 0.25, phase: 0.48, amp: 0.9, amp: 1.2
synth :lisa, ratio: 5, right_phase: 0.25, phase: 0.48, amp: 0.9, amp: 0.25
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment