Skip to content

Instantly share code, notes, and snippets.

@akbiggs
Created February 17, 2014 17:43
Show Gist options
  • Save akbiggs/9055413 to your computer and use it in GitHub Desktop.
Save akbiggs/9055413 to your computer and use it in GitHub Desktop.
Random Experiments with Overtone/Quil
(ns groovyclojure.core
(:use [overtone.live]
[overtone.inst.piano]
[overtone.inst.drum])
(:require [quil.core :as q]))
(defn play-chord [instrument chord]
(doseq [note chord] (instrument note)))
(defn play-piano-chord [chord]
(play-chord piano chord))
(odoc demo)
(odoc mouse-button)
(definst trem [freq 440 depth 10 rate 6 length 3]
(* 0.3
(line:kr 0 1 length FREE)
(saw (+ freq (* depth (sin-osc:kr rate))))))
(trem)
(odoc in:kr)
(demo 60
(let [bpm 120
;; create pool of notes as seed for random base line sequence
notes [40 41 28 28 28 27 25 35 78]
;; create an impulse trigger firing once per bar
trig (impulse:kr (/ bpm 120))
;; create frequency generator for a randomly picked note
freq (midicps (lag (demand trig 0 (dxrand notes INF)) 0.25))
;; switch note durations
swr (demand trig 0 (dseq [1 6 6 2 1 2 4 8 3 3] INF))
;; create a sweep curve for filter below
sweep (lin-exp (lf-tri swr) -1 1 40 3000)
;; create a slightly detuned stereo sawtooth oscillator
wob (mix (saw (* freq [0.99 1.01])))
;; apply low pass filter using sweep curve to control cutoff freq
wob (lpf wob sweep)
;; normalize to 80% volume
wob (* 0.8 (normalizer wob))
;; apply band pass filter with resonance at 5kHz
wob (+ wob (bpf wob 1500 2))
;; mix in 20% reverb
wob (+ wob (* 0.2 (g-verb wob 9 0.7 0.7)))
;; create impulse generator from given drum pattern
kickenv (decay (t2a (demand (impulse:kr (/ bpm 30)) 0 (dseq [1 0 0 0 0 0 1 0 1 0 0 1 0 0 0 0] INF))) 0.7)
;; use modulated sine wave oscillator
kick (* (* kickenv 7) (sin-osc (+ 40 (* kickenv kickenv kickenv 200))))
;; clip at max volume to create distortion
kick (clip2 kick 1)
;; snare is just using gated & over-amplified pink noise
snare (* 3 (pink-noise) (apply + (* (decay (impulse (/ bpm 240) 0.5) [0.4 2]) [1 0.05])))
;; send through band pass filter with peak @ 2kHz
snare (+ snare (bpf (* 4 snare) 2000))
;; also clip at max vol to distort
snare (clip2 snare 1)]
;; mixdown & clip
(clip2 (+ wob kick snare) 1)))
(odoc impulse)
(odoc decay)
(definst sin-wave [freq 440 attack 0.01 sustain 0.4 release 0.1 vol 0.4]
(* (env-gen (lin attack sustain release) 1 1 0 1 FREE)
(sin-osc freq)
vol))
(sin-wave)
(demo 30 (bpf (saw 110) (mouse-x 40 5500 EXP) (mouse-button)))
(demo 2 (saw 120))
(stop)
(definst plucked-string [note 60 amp 0.8 dur 2 decay 30 coef 0.3 gate 1]
(let [freq (midicps note)
noize (* 0.8 (white-noise))
dly (/ 1.0 freq)
plk (pluck noize gate dly dly decay coef)
dist (distort plk)
filt (rlpf dist (* 12 freq) 0.6)
clp (clip2 filt 0.8)
reverb (free-verb clp 0.4 0.8 0.2)]
(* amp (env-gen (perc 0.0001 dur) FREE) reverb)))
(plucked-string)
(odoc perc)
(definst oksaw [note 60 velocity 100 gate 1 bass-presence 0]
(let [freq (midicps note)
amp 0.33
snd (sin-osc freq)
env (env-gen (perc 0.0001 gate) gate :action FREE)
del (* (/ 1 (* 2 freq)) (+ 0.25 (* 0.25 (sin-osc 1))))
dfreq1 (* freq (Math/pow 2 (/ 40 1000)))
dfreq2 (* freq (Math/pow 2 (/ 22 1000)))
cutoff-env (env-gen (adsr 0.25 1 1 2) gate)
snd (lpf
(+
(* bass-presence amp (sin-osc (/ freq 2)))
(* amp (saw freq))
(delay-l (* amp (saw dfreq1)) 1 (/ del 2))
(delay-l (* amp (saw dfreq2)) 1 (/ del 3)))
(* 16000 cutoff-env))
snd (b-low-shelf snd 80 1 10)
snd (b-peak-eq snd 800 1 0)
snd (b-hi-shelf snd 2000 1 5)]
(* env snd)))
(defn create-square [row col]
{:row row :col col :synth oksaw})
(def grid
(for [row (range 7)
col (range 7)]
(create-square row col)))
(definst monotron
"Korg Monotron from website diagram:
http://korg.com/services/products/monotron/monotron_Block_diagram.jpg."
[note 60 ; midi note value
volume 0.7 ; gain of the output
mod_pitch_not_cutoff 1 ; use 0 or 1 only to select LFO pitch or cutoff modification
pitch 0.0 ; frequency of the VCO
rate 4.0 ; frequency of the LFO
int 1.0 ; intensity of the LFO
cutoff 1000.0 ; cutoff frequency of the VCF
peak 0.5 ; VCF peak control (resonance)
pan 0 ; stereo panning
]
(let [note_freq (midicps note)
pitch_mod_coef mod_pitch_not_cutoff
cutoff_mod_coef (- 1 mod_pitch_not_cutoff)
LFO (* int (saw rate))
VCO (saw (+ note_freq pitch (* pitch_mod_coef LFO)))
vcf_freq (+ cutoff (* cutoff_mod_coef LFO) note_freq)
VCF (moog-ff VCO vcf_freq peak)
]
;(tap "monotron-volume" 30 VCF)
(out 0 (pan2 (* volume VCF) pan))))
(odoc tap)
(oksaw 67)
(demo 2 (oksaw))
(oksaw 60 100 2 0)
(odoc pluck)
(stop)
(defn play-square [square]
(let [synth (:synth square)
freq (+ 50 (* 2 (:col square)))]
(synth freq)))
(def square1 (create-square 4 3))
(def square2 (create-square 4 12))
(play-square square1)
(play-square square2)
(stop)
(defn create-grid [w h]
(for [row (range h)
col (range w)]
(create-square row col)))
(def my-grid (create-grid 5 5))
(odoc tap)
(defn setup []
(q/smooth)
(q/frame-rate 30)
(q/background 125))
(defn draw-grid [grid]
(q/stroke 255)
(q/stroke-weight 2)
(q/no-fill)
(doseq [square grid]
;(q/fill)
(let [square-size 50
x (* square-size (:col square))
y (* square-size (:row square))]
(q/rect x y square-size square-size))))
(stop)
(defn draw []
(draw-grid my-grid)
(q/fill 100 150 125)
(q/rect 50 50 100 100))
(q/defsketch test
:title "Groovy"
:setup setup
:draw draw
:size [(/ (q/screen-width) 2) (q/screen-height)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment