summaryrefslogtreecommitdiff
path: root/src
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 /src
parent35c13c75bb2e8785765b22e2b86c97a89943d44b (diff)
downloadtrivmix-88bdbddd537bc3482058d50d84836b555495bdca.tar
trivmix-88bdbddd537bc3482058d50d84836b555495bdca.tar.gz
trivmix-88bdbddd537bc3482058d50d84836b555495bdca.tar.bz2
trivmix-88bdbddd537bc3482058d50d84836b555495bdca.tar.xz
trivmix-88bdbddd537bc3482058d50d84836b555495bdca.zip
Optimization work
Diffstat (limited to 'src')
-rw-r--r--src/Trivmix.hs24
1 files changed, 11 insertions, 13 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