From 88bdbddd537bc3482058d50d84836b555495bdca Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sun, 21 Jun 2015 18:30:39 +0200 Subject: Optimization work --- src/Trivmix.hs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/Trivmix.hs b/src/Trivmix.hs index cedc3e3..d95ea46 100644 --- a/src/Trivmix.hs +++ b/src/Trivmix.hs @@ -48,14 +48,14 @@ data Options = Options data Level = Lin Float | DB Float -fixedPrecision :: (RealFrac a, Num a) => a -> a -fixedPrecision x = (fromInteger $ round $ p * x) / p +fixedPrecision :: (RealFrac a, Num a) => a -> a -> a +fixedPrecision p x = (fromInteger $ round $ p' * x) / p' where - p = 1e3 + p' = 1 / p instance Show Level where show (Lin x) = show x - show (DB x) = (show $ fixedPrecision x') ++ "dB" + show (DB x) = (show $ fixedPrecision 1e-3 x') ++ "dB" where x' = 20 * (logBase 10 x) @@ -135,7 +135,7 @@ main = execParser opts >>= trivmix where opts = info (helper <*> optionParser) ( fullDesc - <> progDesc "Setup a JACK mixing input/output pair controlled by fifos in a state directory" + <> progDesc "Setup a JACK mixing input/output pair controlled by files" <> header "Trivmix - A trivial mixer" ) @@ -172,14 +172,12 @@ handleFiles inotify level files = do levelChanges <- (newChan :: IO (Chan Level)) stderrLock <- newEmptyMVar let - handleFile file = do - levelChanges' <- dupChan levelChanges - forkIO $ forever $ do -- Broadcast level changes and update all files - readChan levelChanges' >>= writeLevel file stderrLock - addWatch inotify watchedAttrs file (const $ readLevel levelChanges level file stderrLock) - mapM handleFile files - forkIO $ forever $ do - readChan levelChanges >>= swapMVar level + handleFile file = addWatch inotify watchedAttrs file (const $ readLevel levelChanges level file stderrLock) + mapM_ handleFile files + forkIO $ forever $ do -- Broadcast level changes and update all files + levelState <- readChan levelChanges + swapMVar level levelState + mapM_ (\f -> writeLevel f stderrLock levelState) files return () return () -- cgit v1.2.3