-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Haskell data flow library for audio processing -- -- Haskell data flow library for audio processing. Requires the -- jack-dl host from rju, see -- http://slavepianos.org/rd/?t=rju. @package hdf @version 0.11 -- | Data flow nodes. module Sound.DF.Node -- | Recursion identifer. data R_ID R_ID :: Int -> R_ID -- | Enumeration of types of data on ports. data Type Real_Type :: Type Integer_Type :: Type Boolean_Type :: Type -- | Constant values. data Constant Real_Constant :: Double -> Constant Integer_Constant :: Int -> Constant -- | Port meta data. data Port Port :: Type -> Int -> Port port_data_type :: Port -> Type port_tokens :: Port -> Int -- | Data flow node. data Node S :: Constant -> Node constant :: Node -> Constant A :: String -> [Node] -> [Port] -> Node operator :: Node -> String inputs :: Node -> [Node] outputs :: Node -> [Port] R :: R_ID -> Either Constant (Node, Node) -> Node identifier :: Node -> R_ID input :: Node -> Either Constant (Node, Node) P :: Node -> Int -> Node proxy :: Node -> Node port :: Node -> Int M :: Node -> Node -> Node mleft :: Node -> Node mright :: Node -> Node -- | Node identifier. type NodeID = Int -- | Port identifier. type PortID = Int -- | Multiple root graph (alias for M). mrg :: Node -> Node -> Node -- | Type of a constant value. constant_type :: Constant -> Type -- | Type of a node. node_type :: Node -> Type -- | Lift constant to node. n_real_constant :: Double -> Node -- | Lift constant to node. n_integer_constant :: Int -> Node -- | Unary operator over Real and Integer values. numerical_unary_operator :: String -> Node -> Node -- | Binary operator over Real and Integer values. numerical_binary_operator :: String -> Node -> Node -> Node -- | Unary operator over Real values. real_unary_operator :: String -> Node -> Node -- | Binary operator over Real values. real_binary_operator :: String -> Node -> Node -> Node -- | Addition. n_add :: Node -> Node -> Node -- | Multiplication. n_mul :: Node -> Node -> Node -- | Subtraction. n_sub :: Node -> Node -> Node -- | Negation. n_negate :: Node -> Node -- | Absolute value. n_abs :: Node -> Node -- | Sign of. n_signum :: Node -> Node -- | Division. n_div :: Node -> Node -> Node -- | Reciprocal. n_recip :: Node -> Node -- | Natural exponential. n_exp :: Node -> Node -- | Square root. n_sqrt :: Node -> Node -- | Natural logarithm. n_log :: Node -> Node -- | p to the power of q. n_pow :: Node -> Node -> Node -- | Sine. n_sin :: Node -> Node -- | Cosine. n_cos :: Node -> Node -- | Tangent. n_tan :: Node -> Node -- | Operator from Real or Integer values to a Boolean value. numerical_comparison_operator :: String -> Node -> Node -> Node -- | Less than. n_lt :: Node -> Node -> Node -- | Greater than or equal to. n_gte :: Node -> Node -> Node -- | Greater than. n_gt :: Node -> Node -> Node -- | Less than or equal to. n_lte :: Node -> Node -> Node -- | Maximum. n_max :: Node -> Node -> Node -- | Minimum. n_min :: Node -> Node -> Node -- | Real valued floor. n_floor :: Node -> Node -- | Integer valued floor. n_lrint :: Node -> Node -- | Class of monads generating identifers class Monad m => ID m generateID :: ID m => m Int -- | Introduce backward arc with implicit unit delay. rec_r :: R_ID -> Constant -> (Node -> (Node, Node)) -> Node -- | Monadic variant of rec_r. rec :: ID m => Constant -> (Node -> (Node, Node)) -> m Node -- | Variant or rec with monadic action in backward arc. recm :: ID m => Constant -> (Node -> m (Node, Node)) -> m Node instance Eq R_ID instance Eq Type instance Show Type instance Eq Constant instance Eq Port instance Eq Node instance ID IO instance Ord Node instance Floating Node instance Fractional Node instance Num Node instance Show Node instance Show Constant -- | Data flow node functions, or unit generators. module Sound.DF.UGen -- | Uniform input type operator. uniform_operator :: Type -> Int -> String -> [Node] -> Node -- | Single channel output. out1 :: Node -> Node -- | Two channel output. out2 :: (Node, Node) -> Node -- | Three channel output. out3 :: (Node, Node, Node) -> Node -- | Operating sample rate. sample_rate :: Node -- | Equal to. eq :: Node -> Node -> Node -- | If p then q else r. select2 :: Node -> Node -> Node -> Node -- | Binary boolean valued operator. logical_operator :: String -> Node -> Node -> Node -- | Logical and. n_and :: Node -> Node -> Node -- | Logical or. n_or :: Node -> Node -> Node -- | Buffer read. b_read :: Node -> Node -> Node -- | Buffer write. b_write :: Node -> Node -> Node -> Node -- | White noise (0, 1). white_noise_u :: Node -> Node -- | Linear pan. pan2 :: Node -> Node -> (Node, Node) -- | Reversed tuple constructor, (ie. flip (,)) swap :: a -> b -> (b, a) -- | Duplicate a value into a tuple. split :: a -> (a, a) -- | Single sample delay with indicated initial value. unit_delay :: ID m => Constant -> Node -> m Node -- | Single place infinte impulse response filter with indicated initial -- value. iir1 :: ID m => Constant -> (Node -> Node -> Node) -> Node -> m Node -- | 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)) }
--   
iir2 :: ID m => (Node -> Node -> Node -> Node) -> Node -> m Node -- | Single place finte impulse response filter. fir1 :: ID m => (Node -> Node -> Node) -> Node -> m Node -- | Two place finte impulse response filter. fir2 :: ID m => (Node -> Node -> Node -> Node) -> Node -> m Node -- | Ordinary biquad filter section. biquad :: ID m => (Node -> Node -> Node -> Node -> Node -> Node) -> Node -> m Node -- | Counter from indicated initial value. counter :: ID m => Constant -> Node -> m Node -- | Environment value, equal to two_pi / -- sample_rate. radians_per_sample :: Node -- | r = cycle (two-pi), hz = frequency, sr = sample rate hz_to_incr :: Node -> Node -> Node -> Node -- | Two pi. two_pi :: Floating a => a -- | If 'q >= p' then 'q - p' else q. clipr :: Node -> Node -> Node -- | r = right hand edge, ip = initial phase, x = increment phasor :: ID m => Constant -> Node -> Node -> m Node -- | 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)) }
--   
sin_osc :: ID m => Node -> Double -> m Node -- | 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_saw :: ID m => Node -> Double -> m Node -- | 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) }
--   
lf_pulse :: ID m => Node -> Double -> Node -> m Node -- | Midi note number to cycles per second. midi_cps :: Floating a => a -> a -- | Multiply and add. mul_add :: Num a => a -> a -> a -> a -- | Calculate feedback multipler given delay and decay -- times. calc_fb :: Floating a => a -> a -> a -- | Delay. delay :: ID m => Node -> Node -> Node -> m Node -- | 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) }
--   
buf_comb_n :: ID m => Node -> Node -> Node -> Node -> m Node -- | 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) }
--   
rlpf :: ID m => Node -> Node -> Node -> m Node -- | Constrain p in (-q, q). clip2 :: Node -> Node -> Node -- | White noise (-1, 1). white_noise :: Node -> Node -- | White noise (-1, 1). Generates noise whose spectrum has equal power at -- all frequencies. -- --
--   do { n <- white_noise_m
--      ; audition [] (out1 (n * 0.1)) }
--   
white_noise_m :: ID m => m Node -- | 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)) } }
--   
brown_noise_m :: ID m => m Node -- | Two zero fixed midpass filter. bpz2 :: ID m => Node -> m Node -- | Two zero fixed midcut filter. brz2 :: ID m => Node -> m Node -- | Two point average filter lpz1 :: ID m => Node -> m Node -- | Two zero fixed lowpass filter lpz2 :: ID m => Node -> m Node -- | One pole filter. one_pole :: ID m => Node -> Node -> m Node -- | One zero filter. one_zero :: ID m => Node -> Node -> m Node -- | Second order filter section. sos :: ID m => Node -> Node -> Node -> Node -> Node -> Node -> m Node -- | 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)) }
--   
impulse :: ID m => Node -> Double -> m Node -- | 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) }
--   
resonz :: ID m => Node -> Node -> Node -> m Node -- | 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)) }
--   
latch :: ID m => Node -> Node -> m Node -- | 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_lin :: Fractional a => a -> a -> a -> a -> a -> a -- | 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)) }
--   
lin_exp :: Floating a => a -> a -> a -> a -> a -> a -- | 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)) }
--   
decay :: ID m => Node -> Node -> m Node -- | Exponential decay (equvalent to decay dcy - decay atk). decay2 :: ID m => Node -> Node -> Node -> m Node -- | Single sample delay. delay1 :: ID m => Node -> m Node -- | Two sample delay. delay2 :: ID m => Node -> m Node -- | 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)) } }
--   
lag :: ID m => Node -> Node -> m Node -- | Nested lag filter. lag2 :: ID m => Node -> Node -> m Node -- | Twice nested lag filter. lag3 :: ID m => Node -> Node -> m Node -- | Graph analysis module Sound.DF.Graph -- | List of nodes, in left biased order. nodes :: Node -> [Node] -- | Read label of node. label :: [(NodeID, Node)] -> Node -> NodeID -- | Transform node to source, see through rec_r and proxy and mrg. source :: [(NodeID, Node)] -> Node -> (NodeID, PortID) -- | Edge between ports. type Edge = ((NodeID, PortID), (NodeID, PortID)) -- | List incoming node edges, edges :: [(NodeID, Node)] -> Node -> [Edge] -- | Label nodes and list edges. Proxy and multiple-root nodes are erased. analyse :: [Node] -> [((NodeID, Node), [Edge])] -- | Transform edge into form required by fgl. mod_e :: Edge -> (NodeID, NodeID, (PortID, PortID)) -- | Generate graph. graph :: Node -> Gr Node (PortID, PortID) -- | Topological sort of nodes (via graph). tsort :: Node -> [Node] -- | Graph drawing module Sound.DF.Draw -- | Draw graph using graphviz. view :: Node -> IO () -- | C code generator module Sound.DF.CGen -- | Generate C code for graph. code_gen :: Node -> String -- | Generate C code, write file to disk and call the GNU C compiler to -- build shared library. dl_gen :: FilePath -> Node -> IO () -- | Interaction with jack-dl server module Sound.DF.Audition -- | Allocate buffer. b_alloc :: Int -> Int -> OSC -- | Load graph. g_load :: Int -> String -> OSC -- | Unload graph. g_unload :: Int -> OSC -- | Run action with UDP link to jack-dl. with_jack_dl :: (UDP -> IO a) -> IO a -- | Audition graph after sending initialisation messages. audition :: [OSC] -> Node -> IO () -- | Top level module for hdf. -- --
--   view (lf_pulse 0.09 0.0 0.16)
--   
module Sound.DF