module Sound.ALSA.Sequencer.RealTime
( RealTime.T(..)
, fromDouble, fromFractional, fromInteger
, toDouble, toFractional, toInteger
) where
import qualified Sound.ALSA.Sequencer.Marshal.RealTime as RealTime
import Prelude hiding (fromInteger, toInteger, )
nanoPerSecond :: Num a => a
nanoPerSecond = 10^(9::Int)
fromInteger :: Integer -> RealTime.T
fromInteger t =
let (s,n) = divMod t nanoPerSecond
in RealTime.Cons (fromIntegral s) (fromIntegral n)
fromDouble :: Double -> RealTime.T
fromDouble = fromFractional
fromFractional :: (RealFrac a) => a -> RealTime.T
fromFractional t =
let (s,n) = properFraction t
in RealTime.Cons s (floor $ n * nanoPerSecond)
toInteger :: RealTime.T -> Integer
toInteger (RealTime.Cons s n) =
fromIntegral s * nanoPerSecond + fromIntegral n
toDouble :: RealTime.T -> Double
toDouble = toFractional
toFractional :: (RealFrac a) => RealTime.T -> a
toFractional (RealTime.Cons s n) =
fromIntegral s + fromIntegral n / nanoPerSecond