module Synthesizer.Dimensional.Rate.Dirac where
import qualified Synthesizer.Generic.Cut as Cut
import qualified Synthesizer.Dimensional.Signal.Private as SigA
import qualified Synthesizer.Dimensional.Process as Proc
import qualified Synthesizer.Dimensional.Amplitude as Amp
import qualified Synthesizer.Dimensional.Rate as Rate
import qualified Data.Monoid as Mn
import qualified Data.Semigroup as Sg
import qualified Number.DimensionTerm as DN
import qualified Algebra.DimensionTerm as Dim
import qualified Algebra.Ring as Ring
import Data.Tuple.HT (mapPair, mapSnd, )
import NumericPrelude.Numeric (zero, one, )
newtype T s sig = Cons {decons :: sig Bool}
instance Sg.Semigroup (sig Bool) => Sg.Semigroup (T s sig) where
Cons x <> Cons y = Cons (x Sg.<> y)
instance Mn.Monoid (sig Bool) => Mn.Monoid (T s sig) where
mempty = Cons Mn.mempty
mappend (Cons x) (Cons y) = Cons (Mn.mappend x y)
instance Cut.Read (sig Bool) => Cut.Read (T s sig) where
null = Cut.null . decons
length = Cut.length . decons
instance Cut.Transform (sig Bool) => Cut.Transform (T s sig) where
take n = Cons . Cut.take n . decons
drop n = Cons . Cut.drop n . decons
splitAt n = mapPair (Cons, Cons) . Cut.splitAt n . decons
dropMarginRem n m = mapSnd Cons . Cut.dropMarginRem n m . decons
reverse = Cons . Cut.reverse . decons
toAmplitudeSignal ::
(Ring.C q, Dim.C u, Functor sig) =>
Proc.T s u q
(T s sig ->
SigA.T (Rate.Phantom s) (Amp.Numeric (DN.T (Dim.Recip u) q)) (sig q))
toAmplitudeSignal =
flip fmap Proc.getSampleRate $ \rate ->
SigA.Cons Rate.Phantom (Amp.Numeric rate) .
fmap (\c -> if c then one else zero) .
decons