Instantly share code, notes, and snippets.

Embed
What would you like to do?
Auto Dubstep example in SonicPi
# Welcome to Sonic Pi v2.0
# SonicPi ish interpretation of
# Dan Stowells' Dubstep Synth:
# All the usual caveats apply - this is just a first attempt at getting it working
# Refinements to follow
@current_bpm = 120.0 # because current_bpm doesn't work for me
use_bpm @current_bpm
define :wob do
use_synth :dsaw
lowcut = note(:E1) # ~ 40Hz
highcut = note(:G8) # ~ 3000Hz
note = [40, 41, 28, 28, 28, 27, 25, 35, 78].choose
duration = 2.0
bpm_scale = (60 / @current_bpm).to_f
# scale the note length based on current tempo
slide_duration = duration * bpm_scale
with_fx :lpf, cutoff: lowcut, cutoff_slide: slide_duration do |c|
play note, attack: 0, sustain: duration, release: 0
wobble_time = [1, 6, 6, 2, 1, 2, 4, 8, 3, 3].choose
c.ctl cutoff_slide: ((duration / wobble_time.to_f) / 2.0)
wobble_time.times do
c.ctl cutoff: highcut
sleep ((duration / wobble_time.to_f) / 2.0)
c.ctl cutoff: lowcut
sleep ((duration / wobble_time.to_f) / 2.0)
end
end
end
in_thread do
loop do
with_fx :reverb do
wob
end
end
end
in_thread do
loop do
[1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0].each do |kick|
sample :drum_heavy_kick if kick == 1
sleep 0.5
end
end
end
in_thread do
loop do
sleep 2
sample :drum_snare_hard
sleep 2
end
end
@samaaron

This comment has been minimized.

samaaron commented May 26, 2014

Some minor additions to the party:

current_bpm = 120.0 
use_bpm current_bpm

define :wob do

  use_synth :dsaw
  lowcut = note(:E1) # ~ 40Hz
  highcut = note(:G8) # ~ 3000Hz
  note = [40, 41, 28, 28, 28, 27, 25, 35].choose
  duration = 2.0
  bpm_scale = (60 / current_bpm).to_f
  distort = rrand(0.2, 0.9)
  # scale the note length based on current tempo
  slide_duration = duration * bpm_scale
  with_fx :distortion, distort: distort do
    with_fx :rlpf, cutoff: lowcut, cutoff_slide: slide_duration do |c|
      play note, attack: 0, sustain: duration, release: 0

      wobble_time = [1, 6, 6, 2, 1, 2, 4, 8, 3, 3, 16].choose
      c.ctl cutoff_slide: ((duration / wobble_time.to_f) / 2.0)

      wobble_time.times do
        c.ctl cutoff: highcut
        sleep ((duration / wobble_time.to_f) / 2.0)
        c.ctl cutoff: lowcut 
        sleep ((duration / wobble_time.to_f) / 2.0)
      end
    end
  end
end

in_thread(name: :wob) do
  with_fx :reverb, mix: 0.5 do
    with_fx :slicer do |sl|
      with_fx :normaliser do
        loop do
          sl.control rate: [1, 2, 4, 8, 16].choose  * [0, 0, 0, 0, 4].choose

          wob
        end
      end
    end
  end
end

in_thread(name: :kick) do
  with_fx :reverb, mix: 0.2 do
    loop do
      sample :ambi_lunar_land, rate: [0.5, 0.75, 1].choose if rand < 0.1
      [1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0].each do |kick|
        sample :drum_heavy_kick if kick == 1
        sleep 0.5
      end
    end
  end
end

in_thread(name: :snare) do
  with_fx :reverb, mix: 0.2 do
    loop do

      with_fx :echo, rate: 1 do
        with_fx :rlpf, cutoff: rrand(80, 120) do
          sample :bass_dnb_f, rate: [0.25, 0.5, 1, 2].choose
        end
      end
      sleep 2
      sample :drum_snare_hard
      sleep 2
    end
  end
end
@samaaron

This comment has been minimized.

samaaron commented May 26, 2014

:-) Much fun! Thanks for this.

@texas845

This comment has been minimized.

texas845 commented Jul 26, 2018

i like it

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