Skip to content

Instantly share code, notes, and snippets.

View xavriley's full-sized avatar

Xavier Riley xavriley

View GitHub Profile
@xavriley
xavriley / README.md
Last active February 26, 2019 13:56
Designing a DSL for slicing samples in Sonic Pi

Sample slicing DSL in Sonic Pi

I'm stealing/playing around with ideas from the tidal language here.

Tidal is more focussed on creating loop based music and manipulating samples. It has a good (although initially scary looking) DSL for this purpose.

  every 6 (density 2) $ jux (iter 8) $ every 8 rev $ 
  every 5 (0.25 <~) $ sound "[808a/4*16, 808a/2 [808a/3 ~ ~ 808b] [~ 808b/3 808b/3 ~] [~],  [~ ~ ~ [~ 808b/2]]/2]"
 |+| speed "[1 1 1 [1.5 0.8] 1 1 1 [1 0.5]]/8"
@xavriley
xavriley / README.md
Last active November 15, 2022 19:34
Using Sonic Pi to practice guitar

Using Sonic Pi to practice guitar

This is an implementation of a scale exercise widely used in jazz teaching. It's sometimes known as the "big scale" exercise.

Explanation

Let's say you practice the saxophone and you want to make sure you know all your major scales. One way to test this would be to play the scale within the limits of your instrument - saxophones have a lowest note and a highest note (from :Db3 to :A5 at concert pitch in Sonic-Pi speak - see here http://en.wikipedia.org/wiki/Alto_saxophone#Range - assuming you don't get fancy with harmonics!)

Playing an Eb major scale over the whole range of the instrument would mean playing from :D3 to Ab5 (concert) as the lowest and highest notes available don't appear in the scale (:Db3 and :A5 respectively). When you hit the upper or lower limit you just reverse the direction and carry on going.

@xavriley
xavriley / README.md
Created September 9, 2014 12:22
Randomised drum groove

Randomised drum groove

More Sonic Pi experiments with randomisation of grooves.

By choosing the likelihood of certain sounds landing on certain beats we can create grooves that are unique and non-repeating yet not totally random - they maintain some feeling of a style or genre.

I'm looking to develop this idea to express these kinds of patterns in a declarative way. Any feedback to @xavriley on twitter please.

You can download Sonic Pi here: http://sonic-pi.net/get-v2.0

@xavriley
xavriley / README.md
Last active December 30, 2023 12:17
Original NES Mario Theme for Sonic Pi

Making Chiptune Music using Sonic Pi v2.0

Warning: this might not work on a RaspberryPi yet

I was curious about making retro gaming sounds using Sonic Pi. A couple of months and a lot of Googling later, here's the original Mario Bros theme as it was heard on the NES console.

I'm (just about) old enough to remember rushing home from school to play this game at Philip Boucher's house, sitting cross-legged in front of the TV till my feet got pins and needles. Working out how to recreate it for Sonic Pi was a lot of fun!

Getting the sounds of the NES chip

# Live coding example for Retune conference 2014
# 1) Press Run (Cmd+R) to start
# 2) Make changes (e.g. comment in/out various lines in :beats & :amen)
# 3) Press Run again (changes will only be audible from next queue point)
# compute loop length (4 bars), bar & quarter note durations
dur = sample_duration :loop_compus
bar = dur / 4
quart = dur / 16
@xavriley
xavriley / avishai.rb
Created February 5, 2015 10:32
Avishai Cohen's Pinzin Kinzin in Sonic Pi 2.3-dev
use_bpm 130
use_synth :saw
use_synth_defaults release: 0.4
bassline = (knit :a3, 4,
:e3, 5,
:f3, 4,
:d3, 5,
:b2, 4,
:c3, 5,
@xavriley
xavriley / texture_fx.rb
Created February 18, 2015 16:37
Ring mod, bitcrusher, reverb, compression - oh my!
use_bpm 110
live_loop(:dr) do
with_fx :compressor, pre_amp: 10 do
with_fx :reverb, mix: 0.1, room: 1 do
with_fx :ring, freq: scale(:eb4, :minor_pentatonic).choose, mix: 0.4 do
"100100101110".chars.map(&:to_i).each.with_index do |beat, i|
sample :bd_808 if beat == 1
sample :bd_808 if beat != 1 and one_in(12)
with_fx :bitcrusher, bits: 8 do
sample :elec_blip, pan: -> {rrand(0,1)}.call, amp: 5 if [4,13].include? i
@xavriley
xavriley / drop_2.rb
Last active August 29, 2015 14:15
Prototype drop-ii harmoniser in Sonic Pi
c_bebop = [60,62,64,65,67,68,69,71]
current_scale = (c_bebop.map {|x| x - 12 } + \
c_bebop + \
c_bebop.map {|x| x + 12 } + \
c_bebop.map {|x| x + 24 }).flatten
def chord_tones(n, scale)
return n if n.nil?
idx = scale.to_a.index(note(n).to_i)
@xavriley
xavriley / pad_times.rb
Created March 12, 2015 18:24
Melody maker in sonic pi
uncomment do
define :pad_times do |target_length, time_values|
if time_values.reduce(:+) < target_length
return time_values << (target_length - time_values.reduce(:+))
else
truncated_times = time_values.take_while.with_index {|x,i|
time_values[0..i].reduce(:+) < target_length
}
return truncated_times << (target_length - truncated_times.reduce(:+))
end
@xavriley
xavriley / bath_ruby_piece.rb
Created March 14, 2015 01:19
Bath Ruby piece
live_loop :dr do |c|
with_fx :reverb do
synth :zawa, note: (knit :c2, 32, :a1, 8)[c], release: 3, phase: 0.25, wave: 1, phase_offset: 0.5 if factor?(c, 16)
end
with_fx :echo, mix: 0.3 do
synth :pulse, pan: Math.sin(vt), note: (scale :a3, :minor_pentatonic).choose, release: 0.1 if spread(7,16)[c]
end
sample :bd_haus if spread(5,8)[c]