From 723ffe14c6334526594dca81f4209df30c36bd01 Mon Sep 17 00:00:00 2001 From: Pierre Krafft Date: Thu, 14 Jul 2022 16:13:28 +0200 Subject: [PATCH 1/2] Use target latency in all send modes Enables moving the scheduling of tidal, back and foreward on the Ableton Link timelime. --- src/Sound/Tidal/Config.hs | 2 +- src/Sound/Tidal/Stream.hs | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Sound/Tidal/Config.hs b/src/Sound/Tidal/Config.hs index 7fac843c2..c9d2e9f00 100644 --- a/src/Sound/Tidal/Config.hs +++ b/src/Sound/Tidal/Config.hs @@ -45,7 +45,7 @@ defaultConfig = Config {cCtrlListen = True, cCtrlBroadcast = False, cFrameTimespan = 1/20, cEnableLink = True, - cProcessAhead = 1/4, + cProcessAhead = 3/10, cTempoAddr = "127.0.0.1", cTempoPort = 9160, cTempoClientPort = 0, -- choose at random diff --git a/src/Sound/Tidal/Stream.hs b/src/Sound/Tidal/Stream.hs index 6044fccdf..db9577e2d 100644 --- a/src/Sound/Tidal/Stream.hs +++ b/src/Sound/Tidal/Stream.hs @@ -551,19 +551,20 @@ setPreviousPatternOrSilence stream = -- Send events live by delaying the thread send :: Maybe O.UDP -> Cx -> Double -> Double -> (Double, Bool, O.Message) -> IO () send listen cx latency extraLatency (time, isBusMsg, m) - | oSchedule target == Pre BundleStamp = sendBndl isBusMsg listen cx $ O.Bundle (time + extraLatency) [m] + | oSchedule target == Pre BundleStamp = sendBndl isBusMsg listen cx $ O.Bundle timeWithLatency [m] | oSchedule target == Pre MessageStamp = sendO isBusMsg listen cx $ addtime m | otherwise = do _ <- forkOS $ do now <- O.time - threadDelay $ floor $ (time - now - latency + extraLatency) * 1000000 + threadDelay $ floor $ (timeWithLatency - now) * 1000000 sendO isBusMsg listen cx m return () where addtime (O.Message mpath params) = O.Message mpath ((O.int32 sec):((O.int32 usec):params)) - ut = O.ntpr_to_ut (time + extraLatency) + ut = O.ntpr_to_ut timeWithLatency sec :: Int sec = floor ut usec :: Int usec = floor $ 1000000 * (ut - (fromIntegral sec)) target = cxTarget cx + timeWithLatency = time - latency + extraLatency -- Interaction From bf700ba424e5996e24f4fbbb0c3042212adaffa3 Mon Sep 17 00:00:00 2001 From: Pierre Krafft Date: Fri, 15 Jul 2022 09:09:47 +0200 Subject: [PATCH 2/2] Adjust superdirtTarget latency As explained in #660, SuperDirt receives the OSC bundles from SuperCollider immediately and is handed a timestamp. SuperDirt uses this timestamp to know when to start the sound synthesis. This timestamp needs to be early on the Link timeline so that the synthesized sound reaches the speakers just in time. 50 milliseconds early appears appropriate, based on experimenting in a Link session with Ableton Live. --- BootTidal.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BootTidal.hs b/BootTidal.hs index dfc574f00..49194c2af 100644 --- a/BootTidal.hs +++ b/BootTidal.hs @@ -6,7 +6,7 @@ import Sound.Tidal.Context import System.IO (hSetEncoding, stdout, utf8) hSetEncoding stdout utf8 -tidal <- startTidal (superdirtTarget {oLatency = 0.1, oAddress = "127.0.0.1", oPort = 57120}) (defaultConfig {cVerbose = True, cFrameTimespan = 1/20}) +tidal <- startTidal (superdirtTarget {oLatency = 0.05, oAddress = "127.0.0.1", oPort = 57120}) (defaultConfig {cVerbose = True, cFrameTimespan = 1/20}) :{ let only = (hush >>)