Skip to content

Instantly share code, notes, and snippets.

@sinewalker sinewalker/chiparp.rb
Last active Mar 31, 2019

Embed
What would you like to do?
8-bit retro chip arp "chord" in Sonic Pi
define :chiparp do |notes, duration, c_amp=0.8, c_Hz=30, c_sust_ratio=1, c_step=1|
tx=bt(1) # seconds for 1 beat
in_thread do
use_bpm 60 # normalise bpm to 1 beat per second
c_speed = 1.0/c_Hz #the chip speed is better converted from Hz
count = (duration * tx / c_speed)
use_synth :chiplead
use_synth_defaults amp: c_amp, sustain: c_speed*c_sust_ratio,
attack: 0, decay: 0, release: 0
puts "chip arp!"; puts notes; puts duration; puts count; puts tx
n = 0
with_debug false do
count.times do
play notes[n]
wait c_speed
n = n + c_step
end
end
end
end
define :chiparp_wait do |notes, dur|
# Use defaults
##| chiparp notes, dur
# or override them (amp, speed, sust_ratio, direction)
chiparp notes, dur, 1.6,25,0.8,-1
wait dur
end
#####
# dinky tune - do better!
# but this demonstrates chiparp arpegio rate is independant of the global BPM, yet stretches to fit beats
use_bpm 80
use_synth :chiplead
play_pattern_timed [:Bb4, :D5], [1, 1]
4.times do
chiparp_wait((chord :e5, :minor), 2)
##| chiparp_wait((chord :b4, :minor, invert: 1), 1)
chiparp_wait((chord :a4, :minor), 1)
chiparp_wait((chord :a4, :minor, invert: 1), 1)
end
@sinewalker

This comment has been minimized.

Copy link
Owner Author

sinewalker commented Mar 31, 2019

Params to chiparp:

  • notes: a Ring of notes to apegiate
  • duration: the length to arpegiate (in beats)
  • c_amp: chip amplifiction (default is 0.8)
  • c_Hz: arp frequency (steps per second, bigger is faster) (default is 30Hz)
  • c_sust_ratio: the ration of sound to silence for each step in the arp. Greate than 1 is allowed, it makes the chiparp become smoother, more chord-like (default is 1, meaining 1:0 sound/silence)
  • c_step: the step size through the notes ring. +1 and -1 are most useful (negative makes it arp backwards) (default is +1)

Function chiparp_wait is just a wrapper for chiparp that also waits until the arp has completed it's duration.

The function to use depends on the musical effect you're after

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.