summaryrefslogtreecommitdiff
path: root/trivmix
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2016-04-17 20:38:29 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2016-04-17 20:38:29 +0200
commit4f9cf618c825a4a1833feab423a99c5c751a923f (patch)
tree8af2378e07d2d493f37197f565031493331670f9 /trivmix
parent00ccb93caaebc67e323b3e71f83e546bc950fed2 (diff)
downloadtrivmix-4f9cf618c825a4a1833feab423a99c5c751a923f.tar
trivmix-4f9cf618c825a4a1833feab423a99c5c751a923f.tar.gz
trivmix-4f9cf618c825a4a1833feab423a99c5c751a923f.tar.bz2
trivmix-4f9cf618c825a4a1833feab423a99c5c751a923f.tar.xz
trivmix-4f9cf618c825a4a1833feab423a99c5c751a923f.zip
Smoothing out discontinuities
Diffstat (limited to 'trivmix')
-rw-r--r--trivmix/Trivmix.hs13
1 files changed, 12 insertions, 1 deletions
diff --git a/trivmix/Trivmix.hs b/trivmix/Trivmix.hs
index fe62619..2cd1252 100644
--- a/trivmix/Trivmix.hs
+++ b/trivmix/Trivmix.hs
@@ -113,6 +113,17 @@ main = execParser opts >>= trivmix
113trivmix :: Options -> IO () 113trivmix :: Options -> IO ()
114trivmix Options{..} = do 114trivmix Options{..} = do
115 level <- newMVar initialLevel 115 level <- newMVar initialLevel
116 level' <- newMVar initialLevel
117 forkIO $ forever $ do -- Smooth out discontinuity
118 let
119 fps = 200
120 interval = 0.2
121 frames = interval * fps
122 delay = round $ recip fps * 10e6
123 linInt x a b = a * (1 - x) + b * x
124 newLevel <- readMVar level
125 currentLevel <- readMVar level'
126 mapM_ (\x -> swapMVar level' (asFloat (linInt x) currentLevel newLevel) >> threadDelay delay) ([0..frames] :: [Float])
116 let withFiles = foldl (.) id $ map (\f -> onStateFile f (show initialLevel ++ "\n")) levelFiles 127 let withFiles = foldl (.) id $ map (\f -> onStateFile f (show initialLevel ++ "\n")) levelFiles
117 withFiles $ withINotify $ \inotify -> do 128 withFiles $ withINotify $ \inotify -> do
118 handleFiles inotify level levelFiles 129 handleFiles inotify level levelFiles
@@ -126,7 +137,7 @@ trivmix Options{..} = do
126 Just run' -> do 137 Just run' -> do
127 (_, _, _, ph) <- createProcess $ (proc run' [client ++ ":" ++ input, client ++ ":" ++ output]) { delegate_ctlc = True } 138 (_, _, _, ph) <- createProcess $ (proc run' [client ++ ":" ++ input, client ++ ":" ++ output]) { delegate_ctlc = True }
128 return () 139 return ()
129 Audio.withProcessMono client' input' (mix level) output' $ 140 Audio.withProcessMono client' input' (mix level') output' $
130 Jack.withActivation client' $ Trans.lift Jack.waitForBreak 141 Jack.withActivation client' $ Trans.lift Jack.waitForBreak
131 142
132mix :: MVar Level -> CFloat -> IO CFloat 143mix :: MVar Level -> CFloat -> IO CFloat