From 4f9cf618c825a4a1833feab423a99c5c751a923f Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sun, 17 Apr 2016 20:38:29 +0200 Subject: Smoothing out discontinuities --- src/Trivmix/Types.hs | 1 + trivmix/Trivmix.hs | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Trivmix/Types.hs b/src/Trivmix/Types.hs index 874eb42..a6a41b9 100644 --- a/src/Trivmix/Types.hs +++ b/src/Trivmix/Types.hs @@ -3,6 +3,7 @@ module Trivmix.Types ( Level , toFloat + , asFloat , Adjustment(..) , doAdjustment , module Data.Default 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 trivmix :: Options -> IO () trivmix Options{..} = do level <- newMVar initialLevel + level' <- newMVar initialLevel + forkIO $ forever $ do -- Smooth out discontinuity + let + fps = 200 + interval = 0.2 + frames = interval * fps + delay = round $ recip fps * 10e6 + linInt x a b = a * (1 - x) + b * x + newLevel <- readMVar level + currentLevel <- readMVar level' + mapM_ (\x -> swapMVar level' (asFloat (linInt x) currentLevel newLevel) >> threadDelay delay) ([0..frames] :: [Float]) let withFiles = foldl (.) id $ map (\f -> onStateFile f (show initialLevel ++ "\n")) levelFiles withFiles $ withINotify $ \inotify -> do handleFiles inotify level levelFiles @@ -126,7 +137,7 @@ trivmix Options{..} = do Just run' -> do (_, _, _, ph) <- createProcess $ (proc run' [client ++ ":" ++ input, client ++ ":" ++ output]) { delegate_ctlc = True } return () - Audio.withProcessMono client' input' (mix level) output' $ + Audio.withProcessMono client' input' (mix level') output' $ Jack.withActivation client' $ Trans.lift Jack.waitForBreak mix :: MVar Level -> CFloat -> IO CFloat -- cgit v1.2.3