Sound.DF.UGen
Description
Data flow node functions, or unit generators.
- uniform_operator :: Type -> Int -> String -> [Node] -> Node
- out1 :: Node -> Node
- out2 :: (Node, Node) -> Node
- out3 :: (Node, Node, Node) -> Node
- sample_rate :: Node
- eq :: Node -> Node -> Node
- select2 :: Node -> Node -> Node -> Node
- logical_operator :: String -> Node -> Node -> Node
- n_and :: Node -> Node -> Node
- n_or :: Node -> Node -> Node
- b_read :: Node -> Node -> Node
- b_write :: Node -> Node -> Node -> Node
- white_noise_u :: Node -> Node
- pan2 :: Node -> Node -> (Node, Node)
- swap :: a -> b -> (b, a)
- split :: a -> (a, a)
- unit_delay :: ID m => Constant -> Node -> m Node
- iir1 :: ID m => Constant -> (Node -> Node -> Node) -> Node -> m Node
- iir2 :: ID m => (Node -> Node -> Node -> Node) -> Node -> m Node
- fir1 :: ID m => (Node -> Node -> Node) -> Node -> m Node
- fir2 :: ID m => (Node -> Node -> Node -> Node) -> Node -> m Node
- biquad :: ID m => (Node -> Node -> Node -> Node -> Node -> Node) -> Node -> m Node
- counter :: ID m => Constant -> Node -> m Node
- radians_per_sample :: Node
- hz_to_incr :: Node -> Node -> Node -> Node
- two_pi :: Floating a => a
- clipr :: Node -> Node -> Node
- phasor :: ID m => Constant -> Node -> Node -> m Node
- sin_osc :: ID m => Node -> Double -> m Node
- lf_saw :: ID m => Node -> Double -> m Node
- lf_pulse :: ID m => Node -> Double -> Node -> m Node
- midi_cps :: Floating a => a -> a
- mul_add :: Num a => a -> a -> a -> a
- calc_fb :: Floating a => a -> a -> a
- delay :: ID m => Node -> Node -> Node -> m Node
- buf_comb_n :: ID m => Node -> Node -> Node -> Node -> m Node
- rlpf :: ID m => Node -> Node -> Node -> m Node
- clip2 :: Node -> Node -> Node
- white_noise :: Node -> Node
- white_noise_m :: ID m => m Node
- brown_noise_m :: ID m => m Node
- bpz2 :: ID m => Node -> m Node
- brz2 :: ID m => Node -> m Node
- lpz1 :: ID m => Node -> m Node
- lpz2 :: ID m => Node -> m Node
- one_pole :: ID m => Node -> Node -> m Node
- one_zero :: ID m => Node -> Node -> m Node
- sos :: ID m => Node -> Node -> Node -> Node -> Node -> Node -> m Node
- impulse :: ID m => Node -> Double -> m Node
- resonz :: ID m => Node -> Node -> Node -> m Node
- latch :: ID m => Node -> Node -> m Node
- lin_lin :: Fractional a => a -> a -> a -> a -> a -> a
- lin_exp :: Floating a => a -> a -> a -> a -> a -> a
- decay :: ID m => Node -> Node -> m Node
- decay2 :: ID m => Node -> Node -> Node -> m Node
- delay1 :: ID m => Node -> m Node
- delay2 :: ID m => Node -> m Node
- lag :: ID m => Node -> Node -> m Node
- lag2 :: ID m => Node -> Node -> m Node
- lag3 :: ID m => Node -> Node -> m Node
Primitive unit generators
Operating sample rate.
white_noise_u :: Node -> NodeSource
White noise (0, 1).
Ordinary unit generators
unit_delay :: ID m => Constant -> Node -> m NodeSource
Single sample delay with indicated initial value.
iir1 :: ID m => Constant -> (Node -> Node -> Node) -> Node -> m NodeSource
Single place infinte impulse response filter with indicated initial value.
iir2 :: ID m => (Node -> Node -> Node -> Node) -> Node -> m NodeSource
Two place infinte impulse response filter. Inputs are: f=
function (x0 y1 y2 -> y0), i = input signal.
do { c1 <- iir2 (\x y1 _ -> x + y1) 0.001
; o1 <- sin_osc (c1 + 220.0) 0
; c2 <- iir2 (\x _ y2 -> x + y2) 0.001
; o2 <- sin_osc (c2 + 220.0) 0
; audition [] (out2 (o1 * 0.1, o2 * 0.1)) }
fir1 :: ID m => (Node -> Node -> Node) -> Node -> m NodeSource
Single place finte impulse response filter.
fir2 :: ID m => (Node -> Node -> Node -> Node) -> Node -> m NodeSource
Two place finte impulse response filter.
biquad :: ID m => (Node -> Node -> Node -> Node -> Node -> Node) -> Node -> m NodeSource
Ordinary biquad filter section.
radians_per_sample :: NodeSource
Environment value, equal to .
two_pi / sample_rate
hz_to_incr :: Node -> Node -> Node -> NodeSource
r = cycle (two-pi), hz = frequency, sr = sample rate
phasor :: ID m => Constant -> Node -> Node -> m NodeSource
r = right hand edge, ip = initial phase, x = increment
sin_osc :: ID m => Node -> Double -> m NodeSource
Sine oscillator. Inputs are: f = frequency (in hz), ip = initial phase.
do { o <- sin_osc 440.0 0.0
; audition [] (out1 (o * 0.1)) }
Used as both Oscillator and LFO.
do { f <- sin_osc 4.0 0.0
; o <- sin_osc (f * 400.0 + 400.0) 0.0
; audition [] (out1 (o * 0.1)) }
Cancellation.
do { o1 <- sin_osc 440.0 0.0
; o2 <- sin_osc 440.0 pi
; audition [] (out1 (o1 + o2)) }
lf_saw :: ID m => Node -> Double -> m NodeSource
Non-band limited sawtooth oscillator. Output ranges from -1 to +1. Inputs are: f = frequency (in hertz), ip = initial phase (0,2).
do { o <- lf_saw 500.0 1.0
; audition [] (out1 (o * 0.1)) }
Used as both Oscillator and LFO.
do { f <- lf_saw 4.0 0.0
; o <- lf_saw (f * 400.0 + 400.0) 0.0
; audition [] (out1 (o * 0.1)) }
lf_pulse :: ID m => Node -> Double -> Node -> m NodeSource
Non-band-limited pulse oscillator. Outputs a high value of one and a low value of zero. Inputs are: f = frequency (in hertz), ip = initial phase (0, 1), w = pulse width duty cycle (0, 1).
do { o1 <- fmap (\x -> x * 200.0 + 200.0) (lf_pulse 3.0 0.0 0.3)
; o2 <- fmap (\x -> x * 0.1) (lf_pulse o1 0.0 0.2)
; audition [] (out1 o2) }
buf_comb_n :: ID m => Node -> Node -> Node -> Node -> m NodeSource
Non-interpolating comb filter. Inputs are: b = buffer index, i = input signal, dl = delay time, dc = decay time.
All times are in seconds. The decay time is the time for the
echoes to decay by 60 decibels. If this time is negative then the
feedback coefficient will be negative, thus emphasizing only odd
harmonics at an octave lower.
Comb used as a resonator. The resonant fundamental is equal to reciprocal of the delay time.
do { n <- white_noise_m
; dt <- let f x = lin_exp (x + 2.0) 1.0 2.0 0.0001 0.01
in fmap f (lf_saw 0.1 0.0)
; c <- buf_comb_n 0 (n * 0.1) dt 0.2
; audition [b_alloc 0 44100] (out1 c) }
Comb used as an echo.
do { i <- impulse 0.5 0.0
; n <- white_noise_m
; e <- decay (i * 0.5) 0.2
; c <- buf_comb_n 0 (e * n) 0.2 3.0
; audition [b_alloc 0 44100] (out1 c) }
rlpf :: ID m => Node -> Node -> Node -> m NodeSource
Resonant low pass filter. Inputs are: i = input signal, f = frequency (hertz), rq = reciprocal of Q (resonance).
do { n <- white_noise_m
; f <- fmap (\x -> x * 40.0 + 220.0) (sin_osc 0.5 0.0)
; r <- rlpf n f 0.1
; audition [] (out1 r) }
white_noise :: Node -> NodeSource
White noise (-1, 1).
white_noise_m :: ID m => m NodeSource
White noise (-1, 1). Generates noise whose spectrum has equal power at all frequencies.
do { n <- white_noise_m
; audition [] (out1 (n * 0.1)) }
brown_noise_m :: ID m => m NodeSource
Brown noise (-1, 1). Generates noise whose spectrum falls off in power by 6 dB per octave.
do { n <- brown_noise_m
; audition [] (out1 (n * 0.1)) }
do { n <- brown_noise_m
; let f = lin_exp n (-1.0) 1.0 64.0 9600.0
in do { o <- sin_osc f 0
; audition [] (out1 (o * 0.1)) } }
sos :: ID m => Node -> Node -> Node -> Node -> Node -> Node -> m NodeSource
Second order filter section.
impulse :: ID m => Node -> Double -> m NodeSource
Impulse oscillator (non band limited). Outputs non band limited single sample impulses. Inputs are: f = frequency (in hertz), ip = phase offset (0..1)
do { o <- impulse 800.0 0.0
; audition [] (out1 (o * 0.1)) }
do { f <- fmap (\x -> x * 2500.0 + 2505.0) (sin_osc 0.25 0.0)
; o <- impulse f 0.0
; audition [] (out1 (o * 0.1)) }
resonz :: ID m => Node -> Node -> Node -> m NodeSource
A two pole resonant filter with zeroes at z = +/- 1. Based on K. Steiglitz, "A Note on Constant-Gain Digital Resonators", Computer Music Journal, vol 18, no. 4, pp. 8-10, Winter 1994. The reciprocal of Q is used rather than Q because it saves a divide operation inside the unit generator.
Inputs are: i = input signal, f = resonant frequency (in hertz), rq = bandwidth ratio (reciprocal of Q); where rq = bandwidth / centerFreq.
do { n <- white_noise_m
; r <- resonz (n * 0.5) 440.0 0.1
; audition [] (out1 r) }
Modulate frequency
do { n <- white_noise_m
; f <- fmap (\x -> x * 3500.0 + 4500.0) (lf_saw 0.1 0.0)
; r <- resonz (n * 0.5) f 0.05
; audition [] (out1 r) }
latch :: ID m => Node -> Node -> m NodeSource
Sample and hold. Holds input signal value when triggered. Inputs are: i = input signal, t = trigger (non-positive to positive).
do { n <- white_noise_m
; i <- impulse 9.0 0.0
; l <- latch n i
; o <- sin_osc (l * 400.0 + 500.0) 0.0
; audition [] (out1 (o * 0.2)) }
lin_lin :: Fractional a => a -> a -> a -> a -> a -> aSource
Linear range conversion.
map (\i -> lin_lin i (-1) 1 0 1) [-1, -0.9 .. 1.0]
do { s <- lf_saw 1.0 0.0
; o <- sin_osc (lin_lin s (-1.0) 1.0 220.0 440.0) 0.0
; audition [] (out1 (o * 0.1)) }
lin_exp :: Floating a => a -> a -> a -> a -> a -> aSource
Exponential range conversion.
map (\i -> lin_exp i 1 2 1 3) [1, 1.1 .. 2]
do { s <- lf_saw 0.25 0.0
; o <- sin_osc (lin_exp (s + 1.0) 0.0 2.0 220.0 440.0) 0.0
; audition [] (out1 (o * 0.1)) }
decay :: ID m => Node -> Node -> m NodeSource
Exponential decay. Inputs are: i = input signal, t = decay time. This is essentially the same as Integrator except that instead of supplying the coefficient directly, it is caculated from a 60 dB decay time. This is the time required for the integrator to lose 99.9 % of its value or -60dB. This is useful for exponential decaying envelopes triggered by impulses.
Used as an envelope.
do { n <- brown_noise_m
; f <- lf_saw 0.1 0.0
; i <- impulse (lin_lin f (-1.0) 1.0 2.0 5.0) 0.25
; e <- decay i 0.2
; audition [] (out1 (e * n)) }
decay2 :: ID m => Node -> Node -> Node -> m NodeSource
Exponential decay (equvalent to decay dcy - decay atk).