summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2015-06-21 18:30:39 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2015-06-21 18:30:39 +0200
commit88bdbddd537bc3482058d50d84836b555495bdca (patch)
tree27d5a8642c72689793f9c9c779a0d25301b414bf
parent35c13c75bb2e8785765b22e2b86c97a89943d44b (diff)
downloadtrivmix-88bdbddd537bc3482058d50d84836b555495bdca.tar
trivmix-88bdbddd537bc3482058d50d84836b555495bdca.tar.gz
trivmix-88bdbddd537bc3482058d50d84836b555495bdca.tar.bz2
trivmix-88bdbddd537bc3482058d50d84836b555495bdca.tar.xz
trivmix-88bdbddd537bc3482058d50d84836b555495bdca.zip
Optimization work
-rw-r--r--src/Trivmix.hs24
-rw-r--r--trivmix.cabal2
-rw-r--r--trivmix.nix2
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
48 48
49data Level = Lin Float | DB Float 49data Level = Lin Float | DB Float
50 50
51fixedPrecision :: (RealFrac a, Num a) => a -> a 51fixedPrecision :: (RealFrac a, Num a) => a -> a -> a
52fixedPrecision x = (fromInteger $ round $ p * x) / p 52fixedPrecision p x = (fromInteger $ round $ p' * x) / p'
53 where 53 where
54 p = 1e3 54 p' = 1 / p
55 55
56instance Show Level where 56instance Show Level where
57 show (Lin x) = show x 57 show (Lin x) = show x
58 show (DB x) = (show $ fixedPrecision x') ++ "dB" 58 show (DB x) = (show $ fixedPrecision 1e-3 x') ++ "dB"
59 where 59 where
60 x' = 20 * (logBase 10 x) 60 x' = 20 * (logBase 10 x)
61 61
@@ -135,7 +135,7 @@ main = execParser opts >>= trivmix
135 where 135 where
136 opts = info (helper <*> optionParser) 136 opts = info (helper <*> optionParser)
137 ( fullDesc 137 ( fullDesc
138 <> progDesc "Setup a JACK mixing input/output pair controlled by fifos in a state directory" 138 <> progDesc "Setup a JACK mixing input/output pair controlled by files"
139 <> header "Trivmix - A trivial mixer" 139 <> header "Trivmix - A trivial mixer"
140 ) 140 )
141 141
@@ -172,14 +172,12 @@ handleFiles inotify level files = do
172 levelChanges <- (newChan :: IO (Chan Level)) 172 levelChanges <- (newChan :: IO (Chan Level))
173 stderrLock <- newEmptyMVar 173 stderrLock <- newEmptyMVar
174 let 174 let
175 handleFile file = do 175 handleFile file = addWatch inotify watchedAttrs file (const $ readLevel levelChanges level file stderrLock)
176 levelChanges' <- dupChan levelChanges 176 mapM_ handleFile files
177 forkIO $ forever $ do -- Broadcast level changes and update all files 177 forkIO $ forever $ do -- Broadcast level changes and update all files
178 readChan levelChanges' >>= writeLevel file stderrLock 178 levelState <- readChan levelChanges
179 addWatch inotify watchedAttrs file (const $ readLevel levelChanges level file stderrLock) 179 swapMVar level levelState
180 mapM handleFile files 180 mapM_ (\f -> writeLevel f stderrLock levelState) files
181 forkIO $ forever $ do
182 readChan levelChanges >>= swapMVar level
183 return () 181 return ()
184 return () 182 return ()
185 183
diff --git a/trivmix.cabal b/trivmix.cabal
index 92388cc..a5af14d 100644
--- a/trivmix.cabal
+++ b/trivmix.cabal
@@ -2,7 +2,7 @@
2-- documentation, see http://haskell.org/cabal/users-guide/ 2-- documentation, see http://haskell.org/cabal/users-guide/
3 3
4name: trivmix 4name: trivmix
5version: 2.4.4 5version: 2.4.5
6-- synopsis: 6-- synopsis:
7-- description: 7-- description:
8license: PublicDomain 8license: PublicDomain
diff --git a/trivmix.nix b/trivmix.nix
index 7f8d665..7d97c01 100644
--- a/trivmix.nix
+++ b/trivmix.nix
@@ -6,7 +6,7 @@
6 6
7cabal.mkDerivation (self: { 7cabal.mkDerivation (self: {
8 pname = "trivmix"; 8 pname = "trivmix";
9 version = "2.4.4"; 9 version = "2.4.5";
10 src = ./.; 10 src = ./.;
11 isLibrary = false; 11 isLibrary = false;
12 isExecutable = true; 12 isExecutable = true;