Safe Haskell | None |
---|---|
Language | Haskell98 |
Faust signal processing block diagram model.
- type Rec_Id = (Id, Id, TypeRep)
- data BD
- bd_id :: BD -> Maybe Id
- bd_req_id :: BD -> Id
- bd_pp :: BD -> String
- bd_signature :: BD -> ([TypeRep], [TypeRep])
- bd_ty :: BD -> [TypeRep]
- bd_ty_uniform :: BD -> Maybe TypeRep
- bd_ty1 :: BD -> Maybe TypeRep
- (~~) :: BD -> BD -> BD
- (~.) :: BD -> BD -> BD
- (~:) :: BD -> BD -> BD
- (~<:) :: BD -> BD -> BD
- (~:>) :: BD -> BD -> BD
- bd_foldl :: (t -> BD -> t) -> t -> BD -> t
- bd_traverse :: (st -> BD -> (st, BD)) -> st -> BD -> (st, BD)
- rec_ids :: Id -> Int -> [TypeRep] -> [Rec_Id]
- bd_set_id :: BD -> (Id, BD)
- type Degree = (Int, Int)
- degree :: BD -> Degree
- in_degree :: BD -> Int
- out_degree :: BD -> Int
- type Port_Index = Int
- data Port
- = Input_Port {
- port_bd :: BD
- port_index :: Port_Index
- | Output_Port { }
- = Input_Port {
- ports :: BD -> ([Port], [Port])
- port_ty :: Port -> TypeRep
- data Wire_Ty
- type Wire = (Port, Port, Wire_Ty)
- normal_wires :: [Port] -> [Port] -> [Wire]
- rec_back_wires :: [Rec_Id] -> [Port] -> [Port] -> [Wire]
- wires_immed :: BD -> [Wire]
- wires :: BD -> [Wire]
- wire_coheres :: Wire -> Bool
- bd_non_coherent :: BD -> [Wire]
- bd_is_coherent :: BD -> Bool
- data Node
- = N_Constant {
- n_constant_id :: Id
- n_constant_k :: K
- | N_Prim { }
- = N_Constant {
- actual_id :: Either Id (Id, Id) -> Id
- node_ty :: Node -> Maybe TypeRep
- node_id :: Node -> Id
- node_lift_id :: Node -> (Id, Node)
- node_pp :: Node -> String
- type Edge = (Id, Id, (Port_Index, Wire_Ty))
- type Graph = ([Node], [Edge])
- edge_is_implicit_backward :: Edge -> Bool
- rec_nodes :: [Rec_Id] -> [Node]
- nodes :: Bool -> BD -> [Node]
- wire_to_edges :: Bool -> Wire -> [Edge]
- wires_to_edges :: Bool -> [Wire] -> [Edge]
- edges :: Bool -> BD -> [Edge]
- graph' :: Bool -> BD -> Graph
- graph :: BD -> Graph
- type Gr = Gr Node (Port_Index, Wire_Ty)
- gr :: BD -> Gr
- tsort :: BD -> Graph
- gr_dot :: BD -> String
- gr_draw :: BD -> IO ()
- dot_node :: Node -> String
- wire_colour :: Wire_Ty -> String
- dot_edge :: Edge -> String
- dot_graph :: Graph -> [String]
- draw_dot :: String -> IO ()
- draw :: Graph -> IO ()
- par_l :: [BD] -> BD
- bd_sum :: [BD] -> BD
- split_r :: BD -> BD -> Bool
- split_m :: BD -> BD -> Maybe BD
- split :: BD -> BD -> BD
- merge_degree :: BD -> BD -> Maybe Int
- merge_m :: BD -> BD -> Maybe BD
- merge :: BD -> BD -> BD
- rec_r :: BD -> BD -> Bool
- rec_m :: BD -> BD -> Maybe BD
- rec :: BD -> BD -> BD
- i_constant :: Int -> BD
- r_constant :: Float -> BD
- u_prim :: TypeRep -> String -> Int -> BD
- i_prim :: String -> Int -> BD
- r_prim :: String -> Int -> BD
- i_add :: BD
- r_add :: BD
- i_sub :: BD
- r_sub :: BD
- i_mul :: BD
- r_mul :: BD
- i_div :: BD
- r_div :: BD
- i_abs :: BD
- r_abs :: BD
- i_negate :: BD
- r_negate :: BD
- i_identity :: BD
- r_identity :: BD
- float_to_int32 :: BD
- int32_to_float :: BD
- i32_to_normal_f32 :: BD
- out1 :: BD
- ty_uop :: (BD -> Maybe TypeRep) -> t -> t -> BD -> t
- ty_binop :: (BD -> Maybe TypeRep) -> t -> t -> BD -> BD -> t
- ty_add :: BD -> BD -> BD
- ty_div :: BD -> BD -> BD
- ty_mul :: BD -> BD -> BD
- ty_sub :: BD -> BD -> BD
- ty_add1 :: BD -> BD -> BD
- ty_div1 :: BD -> BD -> BD
- ty_mul1 :: BD -> BD -> BD
- cg_k :: [Node] -> [(Id, K)]
- cg_node_var :: Node -> Maybe Var
- node_output :: Node -> Maybe (Var_Ty, Id)
- node_inputs :: [Edge] -> Node -> [(Var_Ty, Id)]
- cg_node_c_call :: [Edge] -> Node -> Maybe C_Call
- bd_instructions :: BD -> Instructions
- audition_rju :: [Message] -> BD -> IO ()
- fig_3_2 :: BD
- fig_3_3 :: BD
- fig_3_4 :: BD
- fig_3_5 :: BD
- fig_3_6 :: BD
- fig_3_6' :: BD
- i_counter :: BD
- adjacent :: [t] -> [(t, t)]
- bimap :: (a -> b) -> (c -> d) -> (a, c) -> (b, d)
Block diagram data type
Block diagram.
Identifiers
Pretty printing
Diagram types and signature
Operator synonyms
(~.) :: BD -> BD -> BD infixl 3 Source
Faust uses comma, which is reserved by Data.Tuple, and indeed
~,
is not legal either.
(~:>) :: BD -> BD -> BD infixl 1 Source
Faust uses :>
, however :
is not allowed as a prefix.
draw (graph (par_l [1,2,3,4] ~:> i_mul)) draw (graph (par_l [1,2,3] ~:> i_negate))
Fold and traverse
bd_traverse :: (st -> BD -> (st, BD)) -> st -> BD -> (st, BD) Source
Traversal with state, signature as mapAccumL
.
Introduce node identifiers
Degree
Ports
type Port_Index = Int Source
The index of an Input_Port
, all outputs are unary.
Port (input or output) at block diagram.
Wires
Enumeration of wire types.
Normal | Normal forward edge. |
Backward Rec_Id | Backward edge. |
Implicit_Normal | Implicit wire from recRd to node. |
Implicit_Rec | Implicit wire from node to recWr. |
Implicit_Backward | Implicit wire from recWr to recRd. |
wires_immed :: BD -> [Wire] Source
Immediate internal wires of a block diagram.
Coherence
wire_coheres :: Wire -> Bool Source
A wire coheres if the port_ty
of the left and right hand sides
are equal.
bd_non_coherent :: BD -> [Wire] Source
The set of non-coherent wires at diagram.
bd_is_coherent :: BD -> Bool Source
Coherence predicate, ie. is bd_non_coherent
empty.
Graph
Primitive block diagram elements.
N_Constant | |
| |
N_Prim | |
type Edge = (Id, Id, (Port_Index, Wire_Ty)) Source
Primitive edge, left hand Id
, right hand side Id
, right hand
Port_Index
and edge type.
edge_is_implicit_backward :: Edge -> Bool Source
Is Wire_Ty
of Edge
Implicit_Backward
.
wire_to_edges :: Bool -> Wire -> [Edge] Source
wires_to_edges :: Bool -> [Wire] -> [Edge] Source
graph' :: Bool -> BD -> Graph Source
Construct Graph
of block diagram, either with or without
implicit edges.
Construct Graph
of block diagram without implicit edges.
This graph will include backward arcs if the graph contains recs.
Gr
Drawing
wire_colour :: Wire_Ty -> String Source
Wires are coloured according to type.
Composition
Fold of Par
.
degree (par_l [1,2,3,4]) == (0,4) draw (graph (par_l [1,2,3,4] ~:> i_mul))
merge_degree :: BD -> BD -> Maybe Int Source
If merge is legal, the number of in-edges per port at q.
merge_degree (par_l [1,2,3]) i_negate == Just 3 merge_degree (par_l [1,2,3,4]) i_mul == Just 2
merge_m :: BD -> BD -> Maybe BD Source
merge if diagrams cohere.
merge_m (par_l [1,2,3]) i_negate merge_m (par_l [1,2,3,4]) i_mul
Constants
i_constant :: Int -> BD Source
Integer constant.
r_constant :: Float -> BD Source
Real constant.
Primitives
Division, ie. /
of Fractional
.
i_identity :: BD Source
Identity diagram.
r_identity :: BD Source
Identity diagram.
i32_to_normal_f32 :: BD Source
int32_to_float
and then scale to be in (-1,1).
Type following primitives
ty_add :: BD -> BD -> BD Source
Type following math operator, uniform types.
1.0 `ty_add` 2.0 == r_add (1 ~. 2) `ty_add` (3 ~. 4) == i_add 1.0 `ty_add` 2 == _|_ draw (graph ((1 ~. 2) - (3 ~. 4)))
ty_div :: BD -> BD -> BD Source
Type following math operator, uniform types.
1.0 `ty_add` 2.0 == r_add (1 ~. 2) `ty_add` (3 ~. 4) == i_add 1.0 `ty_add` 2 == _|_ draw (graph ((1 ~. 2) - (3 ~. 4)))
ty_mul :: BD -> BD -> BD Source
Type following math operator, uniform types.
1.0 `ty_add` 2.0 == r_add (1 ~. 2) `ty_add` (3 ~. 4) == i_add 1.0 `ty_add` 2 == _|_ draw (graph ((1 ~. 2) - (3 ~. 4)))
ty_sub :: BD -> BD -> BD Source
Type following math operator, uniform types.
1.0 `ty_add` 2.0 == r_add (1 ~. 2) `ty_add` (3 ~. 4) == i_add 1.0 `ty_add` 2 == _|_ draw (graph ((1 ~. 2) - (3 ~. 4)))
ty_add1 :: BD -> BD -> BD Source
Type following math operator, singular types.
1.0 `ty_add1` 2.0 == r_add 1.0 `ty_add1` 2 == _|_
ty_div1 :: BD -> BD -> BD Source
Type following math operator, singular types.
1.0 `ty_add1` 2.0 == r_add 1.0 `ty_add1` 2 == _|_
ty_mul1 :: BD -> BD -> BD Source
Type following math operator, singular types.
1.0 `ty_add1` 2.0 == r_add 1.0 `ty_add1` 2 == _|_
Code Gen
bd_instructions :: BD -> Instructions Source
Generate CGen Instructions
for BD
.
Audition
audition_rju :: [Message] -> BD -> IO () Source
Audition graph after sending initialisation messages.
Figures from Quick Reference
Figure illustrating ~:
.
degree fig_3_3 == (4,1) bd_signature fig_3_3 draw (graph fig_3_3)
Variant generating audible graph.
draw (graph fig_3_6') gr_draw fig_3_6' audition [] fig_3_6'
A counter, illustrating identity diagram.
draw (graph (i_counter ~: i_negate)) gr_draw (i_counter ~: i_negate)