Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 116 lines (95 sloc) 3.006 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
(ns example.filters
  (:use overtone.core))

; Filter examples, mostly ported from SC docs

; You might want to bring up the scope while trying the filters out,
; because in at least some instances it can help to understand what
; effect the filter is having.
; (scope)

; Lowpass
(demo 10
  (lpf (* 0.5 (saw 440))
       (mouse-x 10 10000))) ; cutoff frequency

; Resonant Lowpass
(demo 10
  (rlpf (* 0.5 (saw 440))
       (mouse-x 10 10000)
       (mouse-y 0.0001 0.9999))) ; cutoff frequency

; Highpass
(demo 10
  (hpf (* 0.5 (saw 200))
       (mouse-x 100 10000))) ; cutoff frequency

; Bandpass
; - only let a band of frequencies pass through
(demo 10
  (bpf (* 0.5 (saw 200))
       (mouse-x 100 10000) ; center frequency
       (mouse-y 0 1))) ; rq => bandwidth/cutoff

; Band reject
; - the inverse of the bandpass
(demo 10
  (brf (* 0.5 (saw 200))
       (mouse-x 100 10000) ; center frequency
       (mouse-y 0 1))) ; rq => bandwidth/cutoff

; Limiter
; - limit the amplitude
(demo 10
  (limiter (* 0.5 (saw 440))
           (mouse-y 0.01 0.5)))


; Clip
; - limit the amplitude with hi and low thresholds
(demo 10
  (clip:ar (* (sin-osc 440) 0.4)
        -0.01
        0.01))

; Linear to linear
; - converte from one range to another
(demo 10
  (let [freq (lin-lin:kr (mouse-x 0.1 1)
                   0 1 ; source range
                   110 880)] ; destination range
  (* 0.3 (saw freq))))

; Linear to exponential
; - convert from a linear range to an exponential range
(demo 10
  (let [freq (lin-exp:kr (mouse-x 0.1 1)
                   0 1 ; linear range
                   10 10000)] ; exponential range
  (* 0.3 (saw freq))))


; Lag
; - smooths a transition by adjusting input value exponentially
; over the specified lag time
; - used to smooth out control signals
(demo 10
  (* 0.2 (saw (lag:kr
                     (mouse-x 80 10000) ; frequency value
                     3)))) ; lag time

; Lag Up Down
; - allows for different up and down lag times
(demo 10
  (* 0.2 (saw (lag-ud:kr
                     (mouse-x 80 10000) ; frequency value
                     4 2)))) ; lag time


; Ramp
; - like lag, but transitions linearly
(demo 10
  (* 0.2 (saw (ramp:kr
                     (mouse-x 80 10000) ; frequency value
                     3)))) ; lag time

(demo 10
  (klank [(repeatedly 12 #(+ 200.0 (rand 4000)))
          (repeat 12 0.8)
          (repeatedly 12 #(+ 0.1 (rand 2)))]
         (* (clip-noise) 0.01 (decay (impulse 4) 0.03))))

; Amplitude compensation
; - to account for higher pitches seeming louder
; - move the mouse up and down
;
; First a normal saw wave. Careful, the high pitches can be painful
; at high volume so turn your headphones down!
(demo 10
  (let [f (mouse-y 300 15000)]
    (* (saw f) 0.1)))

; notice how with the compensation the higher pitches are less piercing
(demo 10
  (let [f (mouse-y 300 15000)]
    (* (saw f) 0.1 (amp-comp f 300))))
Something went wrong with that request. Please try again.