[Haskell-cafe] Precise timing
Jeffrey Brown
jeffbrown.the at gmail.com
Wed Oct 22 03:14:28 UTC 2014
On a separate thread
<http://haskell.1045720.n5.nabble.com/How-to-send-a-string-somewhere-via-UDP-td5758418.html>,
Rohan Drape showed me how to send OSC. The following test, which simplifies
the old one and replaces printf with OSC, demonstrates timing as perfect as
my ears are able to distinguish.
import Control.Concurrent
import Control.Monad
import System.IO
import Sound.OSC
main = do
hSetBuffering stdout NoBuffering
mapM_ note (cycle [1,1,2])
withMax = withTransport (openUDP "127.0.0.1" 9000)
beat = 60000 -- 60 ms, measured in µs
note :: Int -> IO ()
note n = do
withMax (sendMessage (Message "sin0 frq 100" []))
-- set sine wave 0 to frequency 100
withMax (sendMessage (Message "sin0 amp 1" []))
-- set sine wave 0 to amplitude 1
threadDelay $ beat * n
withMax (sendMessage (Message "sin0 amp 0" []))
-- set sine wave 0 to amplitude 0
threadDelay $ beat * n
This means I can use Haskell instead of Python or SuperCollider. I am
beside myself with excitement.
Thanks again, everyone!
On Tue, Oct 21, 2014 at 2:24 AM, Brandon Allbery <allbery.b at gmail.com>
wrote:
> On Tue, Oct 21, 2014 at 4:05 AM, Heinrich Apfelmus <
> apfelmus at quantentunnel.de> wrote:
>
>> I would be hesitant to attribute your problem to the scheduler. An
>> alternative explanation could be the following: The sound file played by
>> the terminal when it encounters the \BEL character is longer than 100ms. A
>> new sound will be played only when the previous sound has finished playing,
>
>
> On most systems I've used, this isn't true; they're either suppressed or
> they overlap, depending on system. (I've had to work around this.)
>
> --
> brandon s allbery kf8nh sine nomine
> associates
> allbery.b at gmail.com
> ballbery at sinenomine.net
> unix, openafs, kerberos, infrastructure, xmonad
> http://sinenomine.net
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20141021/52973106/attachment.html>
More information about the Haskell-Cafe
mailing list