Skip to main content


Showing posts from April, 2008

functional music, honorable mention of new composer C.W. Boese

just after the previous post a talented composer (Boese) used the small framework for functional music in haskell for one of his compisitions. His work balances harmony and disharmony in an unbalanced way and thereby balances the unbalancing and balancing forces driving the excellent piece of modern algorithmic music. with his silent permission the source as well the interpretation is attached to this post.

Here's the interpretation using an artifical Clarinet: play.

Here's the source:

boeseboese = Rest (2/4) :+: (hochlauf (-2) 3 boese) :=: (hochlauf (2) 3 boese) :+: boese
boese = rpt 3 freak :=: rpt 3 ghoul :=: rpt 3 funk
grund = (Note (Cis,5) 1)
freak = rptm (Trans (round (abs (duration ghoul)))) 3 funk
ghoul = akkord grund 0
funk = Trans terz grund :=: rptm (Trans quinte) 4 ghoul

just append that to the previous program and adapt the main function.

Maybe it's also worth mentioning, that this was the first piece of haskell code written by him.
Haskell syntax helps to create framewo…

Learning Haskell, functional music

As you might have realized, I started to learn Haskell. One of the most fun things to do in any programming language is creating some kind of audible side effects with a program.
Already back in the days when I started programming, I always played around with audio when toying around with a new language.

I have found a wonderful set of lecture slides about haskell and multimedia programming, called school of expression. Inspired by the slides about functional music I implemented a little song. Ahh ... and yes it is intended to sound slightly strange.

I used the synthesis toolkit to transform the music to real noise, simply by piping skini message to std-out.

I used this command line to achieve the results audible in the table:

sven@hhi1214a:~/Mukke$ ghc -o test1 test1.hs && ./test1 | stk-demo Plucked -n 16 -or -ip

Sound samples:

Whistle(attention very crazy!)play

As always the source...

stueck = anfang :+: mitte :+: ende

anfang = groovy :+: (Trans (-5) trickie)

Haskell Thread Ring Benchmark

Not as fast as the erlang version coming soon:

import Control.Monad
import Control.Concurrent
import System.Environment
import System.CPUTime

fork_ring_elem prev_mvar _ = do
next_mvar <- newEmptyMVar
forkIO (ring_elem prev_mvar next_mvar)
return next_mvar

ring_elem :: MVar Int -> MVar Int -> IO ()
ring_elem prev_mv next_mv = run
where run = do
token <- takeMVar prev_mv
putMVar next_mv (token - 1)
when ( token > 0 ) run

first_ring_elem :: MVar Int -> MVar Int -> IO ()
first_ring_elem prev_mv next_mv = run
where run = do
token <- takeMVar prev_mv
putMVar next_mv (token - 1)
putStrLn "."
when ( token > 0 ) run

main = do
(procsArg:roundsArg:_) <- getArgs
first_mvar <- newMVar ((read procsArg) * (read roundsArg))
t1 <- getCPUTime
last_mvar <- foldM fork_ring_elem first_mvar [2..(read procsArg)]
t2 <- getCPUTime
putStrLn ("forked processes in " ++ (…