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 +++++++++++------------- trivmix.cabal | 2 +- trivmix.nix | 2 +- 3 files changed, 13 insertions(+), 15 deletions(-) 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 () diff --git a/trivmix.cabal b/trivmix.cabal index 92388cc..a5af14d 100644 --- a/trivmix.cabal +++ b/trivmix.cabal @@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: trivmix -version: 2.4.4 +version: 2.4.5 -- synopsis: -- description: license: PublicDomain diff --git a/trivmix.nix b/trivmix.nix index 7f8d665..7d97c01 100644 --- a/trivmix.nix +++ b/trivmix.nix @@ -6,7 +6,7 @@ cabal.mkDerivation (self: { pname = "trivmix"; - version = "2.4.4"; + version = "2.4.5"; src = ./.; isLibrary = false; isExecutable = true; -- cgit v1.2.3