diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2015-06-21 18:30:39 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2015-06-21 18:30:39 +0200 |
commit | 88bdbddd537bc3482058d50d84836b555495bdca (patch) | |
tree | 27d5a8642c72689793f9c9c779a0d25301b414bf | |
parent | 35c13c75bb2e8785765b22e2b86c97a89943d44b (diff) | |
download | trivmix-88bdbddd537bc3482058d50d84836b555495bdca.tar trivmix-88bdbddd537bc3482058d50d84836b555495bdca.tar.gz trivmix-88bdbddd537bc3482058d50d84836b555495bdca.tar.bz2 trivmix-88bdbddd537bc3482058d50d84836b555495bdca.tar.xz trivmix-88bdbddd537bc3482058d50d84836b555495bdca.zip |
Optimization work
-rw-r--r-- | src/Trivmix.hs | 24 | ||||
-rw-r--r-- | trivmix.cabal | 2 | ||||
-rw-r--r-- | 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 | |||
48 | 48 | ||
49 | data Level = Lin Float | DB Float | 49 | data Level = Lin Float | DB Float |
50 | 50 | ||
51 | fixedPrecision :: (RealFrac a, Num a) => a -> a | 51 | fixedPrecision :: (RealFrac a, Num a) => a -> a -> a |
52 | fixedPrecision x = (fromInteger $ round $ p * x) / p | 52 | fixedPrecision p x = (fromInteger $ round $ p' * x) / p' |
53 | where | 53 | where |
54 | p = 1e3 | 54 | p' = 1 / p |
55 | 55 | ||
56 | instance Show Level where | 56 | instance 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 | ||
4 | name: trivmix | 4 | name: trivmix |
5 | version: 2.4.4 | 5 | version: 2.4.5 |
6 | -- synopsis: | 6 | -- synopsis: |
7 | -- description: | 7 | -- description: |
8 | license: PublicDomain | 8 | license: 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 | ||
7 | cabal.mkDerivation (self: { | 7 | cabal.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; |