hdf-0.11: Haskell data flow library for audio processing

Sound.DF.UGen

Contents

Description

Data flow node functions, or unit generators.

Synopsis

Primitive unit generators

uniform_operator :: Type -> Int -> String -> [Node] -> NodeSource

Uniform input type operator.

out1 :: Node -> NodeSource

Single channel output.

out2 :: (Node, Node) -> NodeSource

Two channel output.

out3 :: (Node, Node, Node) -> NodeSource

Three channel output.

sample_rate :: NodeSource

Operating sample rate.

eq :: Node -> Node -> NodeSource

Equal to.

select2 :: Node -> Node -> Node -> NodeSource

If p then q else r.

logical_operator :: String -> Node -> Node -> NodeSource

Binary boolean valued operator.

n_and :: Node -> Node -> NodeSource

Logical and.

n_or :: Node -> Node -> NodeSource

Logical or.

b_read :: Node -> Node -> NodeSource

Buffer read.

b_write :: Node -> Node -> Node -> NodeSource

Buffer write.

white_noise_u :: Node -> NodeSource

White noise (0, 1).

Ordinary unit generators

pan2 :: Node -> Node -> (Node, Node)Source

Linear pan.

swap :: a -> b -> (b, a)Source

Reversed tuple constructor, (ie. flip (,))

split :: a -> (a, a)Source

Duplicate a value into a tuple.

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.

counter :: ID m => Constant -> Node -> m NodeSource

Counter from indicated initial value.

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

two_pi :: Floating a => aSource

Two pi.

clipr :: Node -> Node -> NodeSource

If 'q >= p' then 'q - p' else q.

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) }

midi_cps :: Floating a => a -> aSource

Midi note number to cycles per second.

mul_add :: Num a => a -> a -> a -> aSource

Multiply and add.

calc_fb :: Floating a => a -> a -> aSource

Calculate feedback multipler given delay and decay times.

delay :: ID m => Node -> Node -> Node -> m NodeSource

Delay.

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) }

clip2 :: Node -> Node -> NodeSource

Constrain p in (-q, q).

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)) } }

bpz2 :: ID m => Node -> m NodeSource

Two zero fixed midpass filter.

brz2 :: ID m => Node -> m NodeSource

Two zero fixed midcut filter.

lpz1 :: ID m => Node -> m NodeSource

Two point average filter

lpz2 :: ID m => Node -> m NodeSource

Two zero fixed lowpass filter

one_pole :: ID m => Node -> Node -> m NodeSource

One pole filter.

one_zero :: ID m => Node -> Node -> m NodeSource

One zero filter.

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).

delay1 :: ID m => Node -> m NodeSource

Single sample delay.

delay2 :: ID m => Node -> m NodeSource

Two sample delay.

lag :: ID m => Node -> Node -> m NodeSource

Simple averaging filter. Inputs are: i = input signal, t = lag time.

 do { s <- sin_osc 0.05 0.0
    ; let f = lin_lin s (-1.0) 1.0 220.0 440.0
      in do { o <- sin_osc f 0.0
            ; f' <- lag f 1.0
            ; o' <- sin_osc f' 0.0
            ; audition [] (out2 (o * 0.2, o' * 0.2)) } }

lag2 :: ID m => Node -> Node -> m NodeSource

Nested lag filter.

lag3 :: ID m => Node -> Node -> m NodeSource

Twice nested lag filter.