{-# LANGUAGE Arrows #-}
{-# LANGUAGE TypeFamilies #-}
module FRP.Rhine.ResamplingBuffer.Interpolation where
import Data.VectorSpace
import FRP.Rhine
import FRP.Rhine.ResamplingBuffer.KeepLast
import FRP.Rhine.ResamplingBuffer.Util
linear
:: ( Monad m, Clock m cl1, Clock m cl2
, VectorSpace v
, Groundfield v ~ Diff (TimeDomainOf cl1)
, Groundfield v ~ Diff (TimeDomainOf cl2)
)
=> v
-> v
-> ResamplingBuffer m cl1 cl2 v v
linear initVelocity initPosition
= (derivativeFrom initPosition &&& syncId) &&& timeInfoOf sinceStart
^->> keepLast ((initVelocity, initPosition), 0)
>>-^ proc ((velocity, lastPosition), sinceStart1) -> do
sinceStart2 <- timeInfoOf sinceStart -< ()
let diff = sinceStart2 - sinceStart1
returnA -< lastPosition ^+^ velocity ^* diff