From 5d9387af919e68ef51328352eca3e0bdf3b4989e Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 15 May 2018 17:52:11 +0200 Subject: Make smoothing configurable --- trivmix.cabal | 2 +- trivmix.nix | 2 +- trivmix/Trivmix.hs | 17 ++++++++++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/trivmix.cabal b/trivmix.cabal index 0149fb5..41ba03f 100644 --- a/trivmix.cabal +++ b/trivmix.cabal @@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: trivmix -version: 3.1.4 +version: 3.2.0 -- synopsis: -- description: license: PublicDomain diff --git a/trivmix.nix b/trivmix.nix index 34b430a..8d0ea14 100644 --- a/trivmix.nix +++ b/trivmix.nix @@ -5,7 +5,7 @@ }: mkDerivation { pname = "trivmix"; - version = "3.1.4"; + version = "3.2.0"; src = ./.; isLibrary = true; isExecutable = true; diff --git a/trivmix/Trivmix.hs b/trivmix/Trivmix.hs index 0758921..91dd440 100644 --- a/trivmix/Trivmix.hs +++ b/trivmix/Trivmix.hs @@ -53,6 +53,7 @@ data Options = Options , client :: String , initialLevel :: Level , initialBalance :: Balance + , fps, interval :: Rational , run :: [FilePath] , balanceFiles :: [FilePath] , levelFiles :: [FilePath] @@ -88,6 +89,18 @@ optionParser = Options <> value def <> showDefault ) + <*> option auto ( long "fps" + <> metavar "NUMBER" + <> help "Update level ‘NUMBER’ times per second" + <> value 200 + <> showDefault + ) + <*> option auto ( long "interval" + <> metavar "NUMBER" + <> help "Smooth level transitions over ‘NUMBER’ seconds" + <> value 0.2 + <> showDefault + ) <*> many ( strOption ( long "run" <> metavar "FILE" <> help [str|Execute a file once setup of jacks is done (use this to autoconnect) @@ -168,8 +181,6 @@ trivmix Options{..} = do notifyReady forever $ do -- Smooth out discontinuity let - fps = 200 - interval = 0.2 frames = interval * fps delay = round $ recip fps * 1e6 linInt x a b = a * (1 - x) + b * x @@ -177,7 +188,7 @@ trivmix Options{..} = do mulBalance (bToFloat -> b) x = either error id $ asFloat (*) (Lin . either error id $ refine b) x newLevel <- mulBalance <$> readMVar balance <*> readMVar level currentLevel <- readMVar level' - mapM_ (\x -> swapMVar level' (linInt' x currentLevel newLevel) >> threadDelay delay) ([0,recip frames..1] :: [Float]) + mapM_ (\(fromRational -> x) -> swapMVar level' (linInt' x currentLevel newLevel) >> threadDelay delay) [0,recip frames..1] mix :: MVar Level -> CFloat -> IO CFloat mix level input = do -- cgit v1.2.3