{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Synthesizer.Dimensional.Causal.Filter (
amplify,
amplifyDimension,
amplifyScalarDimension,
negate,
envelope,
envelopeScalarDimension,
envelopeVector,
envelopeVectorDimension,
differentiate,
integrate,
) where
import qualified Synthesizer.Dimensional.Map.Filter as FiltM
import qualified Synthesizer.Dimensional.Process as Proc
import qualified Synthesizer.Dimensional.Sample as Sample
import qualified Synthesizer.Dimensional.Amplitude as Amp
import qualified Synthesizer.Dimensional.Causal.Process as CausalD
import qualified Synthesizer.Causal.Process as Causal
import Control.Arrow ((^<<), (&&&), )
import Synthesizer.Dimensional.Process (DimensionGradient, )
import qualified Synthesizer.State.Filter.Recursive.Integration as Integrate
import qualified Number.DimensionTerm as DN
import qualified Algebra.DimensionTerm as Dim
import Number.DimensionTerm ((&*&), )
import qualified Algebra.Field as Field
import qualified Algebra.Ring as Ring
import qualified Algebra.Additive as Additive
import qualified Algebra.Module as Module
import NumericPrelude.Numeric hiding (negate)
import NumericPrelude.Base as P
import Prelude ()
{-# INLINE amplify #-}
amplify :: (Module.C y amp) =>
y ->
Proc.T s u t (CausalD.Single s (Amp.Numeric amp) (Amp.Numeric amp) yv yv)
amplify :: forall y amp s u t yv.
C y amp =>
y -> T s u t (Single s (Numeric amp) (Numeric amp) yv yv)
amplify y
volume =
forall a s u t. a -> T s u t a
Proc.pure forall a b. (a -> b) -> a -> b
$ forall y amp (arrow :: * -> * -> *) yv.
(C y amp, Arrow arrow) =>
y -> Single arrow (Numeric amp) (Numeric amp) yv yv
FiltM.amplify y
volume
{-# INLINE amplifyDimension #-}
amplifyDimension :: (Ring.C y, Dim.C u, Dim.C v0, Dim.C v1) =>
DN.T v0 y ->
Proc.T s u t
(CausalD.Single s
(Amp.Dimensional v1 y) (Amp.Dimensional (Dim.Mul v0 v1) y)
yv yv)
amplifyDimension :: forall y u v0 v1 s t yv.
(C y, C u, C v0, C v1) =>
T v0 y
-> T s
u
t
(Single s (Dimensional v1 y) (Dimensional (Mul v0 v1) y) yv yv)
amplifyDimension T v0 y
volume =
forall a s u t. a -> T s u t a
Proc.pure forall a b. (a -> b) -> a -> b
$ forall y v0 v1 (arrow :: * -> * -> *) yv.
(C y, C v0, C v1, Arrow arrow) =>
T v0 y
-> Single
arrow (Dimensional v1 y) (Dimensional (Mul v0 v1) y) yv yv
FiltM.amplifyDimension T v0 y
volume
{-# INLINE amplifyScalarDimension #-}
amplifyScalarDimension :: (Ring.C y, Dim.C u, Dim.C v) =>
DN.T v y ->
Proc.T s u t
(CausalD.Single s
(Amp.Dimensional Dim.Scalar y) (Amp.Dimensional v y)
yv yv)
amplifyScalarDimension :: forall y u v s t yv.
(C y, C u, C v) =>
T v y
-> T s
u
t
(Single s (Dimensional Scalar y) (Dimensional v y) yv yv)
amplifyScalarDimension T v y
volume =
forall a s u t. a -> T s u t a
Proc.pure forall a b. (a -> b) -> a -> b
$ forall y v (arrow :: * -> * -> *) yv.
(C y, C v, Arrow arrow) =>
T v y
-> Single arrow (Dimensional Scalar y) (Dimensional v y) yv yv
FiltM.amplifyScalarDimension T v y
volume
{-# INLINE negate #-}
negate :: (Additive.C (Sample.Displacement sample)) =>
Proc.T s u t (CausalD.T s sample sample)
negate :: forall sample s u t.
C (Displacement sample) =>
T s u t (T s sample sample)
negate =
forall a s u t. a -> T s u t a
Proc.pure forall a b. (a -> b) -> a -> b
$ forall sample (arrow :: * -> * -> *).
(C (Displacement sample), Arrow arrow) =>
T arrow sample sample
FiltM.negate
{-# INLINE envelope #-}
envelope :: (Ring.C y) =>
Proc.T s u t (CausalD.T s (Sample.Flat y, Sample.Numeric amp y) (Sample.Numeric amp y))
envelope :: forall y s u t amp.
C y =>
T s u t (T s (Flat y, Numeric amp y) (Numeric amp y))
envelope =
forall a s u t. a -> T s u t a
Proc.pure forall a b. (a -> b) -> a -> b
$ forall y (arrow :: * -> * -> *) amp.
(C y, Arrow arrow) =>
T arrow (Flat y, Numeric amp y) (Numeric amp y)
FiltM.envelope
{-# INLINE envelopeScalarDimension #-}
envelopeScalarDimension ::
(Ring.C y, Dim.C u, Dim.C v) =>
Proc.T s u t
(CausalD.T s
(Sample.Dimensional Dim.Scalar y y, Sample.Dimensional v y y)
(Sample.Dimensional v y y))
envelopeScalarDimension :: forall y u v s t.
(C y, C u, C v) =>
T s
u
t
(T s
(Dimensional Scalar y y, Dimensional v y y)
(Dimensional v y y))
envelopeScalarDimension =
forall a s u t. a -> T s u t a
Proc.pure forall a b. (a -> b) -> a -> b
$ forall y v (arrow :: * -> * -> *).
(C y, C v, Arrow arrow) =>
T arrow
(Dimensional Scalar y y, Dimensional v y y)
(Dimensional v y y)
FiltM.envelopeScalarDimension
{-# INLINE envelopeVector #-}
envelopeVector :: (Module.C y (Sample.Displacement sample)) =>
Proc.T s u t (CausalD.T s (Sample.Flat y, sample) sample)
envelopeVector :: forall y sample s u t.
C y (Displacement sample) =>
T s u t (T s (Flat y, sample) sample)
envelopeVector =
forall a s u t. a -> T s u t a
Proc.pure forall a b. (a -> b) -> a -> b
$ forall y sample (arrow :: * -> * -> *).
(C y (Displacement sample), Arrow arrow) =>
T arrow (Flat y, sample) sample
FiltM.envelopeVector
{-# INLINE envelopeVectorDimension #-}
envelopeVectorDimension ::
(Module.C y0 yv, Ring.C y, Dim.C u, Dim.C v0, Dim.C v1) =>
Proc.T s u t
(CausalD.T s
(Sample.Dimensional v0 y y0, Sample.Dimensional v1 y yv)
(Sample.Dimensional (Dim.Mul v0 v1) y yv))
envelopeVectorDimension :: forall y0 yv y u v0 v1 s t.
(C y0 yv, C y, C u, C v0, C v1) =>
T s
u
t
(T s
(Dimensional v0 y y0, Dimensional v1 y yv)
(Dimensional (Mul v0 v1) y yv))
envelopeVectorDimension =
forall a s u t. a -> T s u t a
Proc.pure forall a b. (a -> b) -> a -> b
$ forall y0 yv y v0 v1 (arrow :: * -> * -> *).
(C y0 yv, C y, C v0, C v1, Arrow arrow) =>
T arrow
(Dimensional v0 y y0, Dimensional v1 y yv)
(Dimensional (Mul v0 v1) y yv)
FiltM.envelopeVectorDimension
{-# INLINE differentiate #-}
differentiate :: (Additive.C yv, Ring.C q, Dim.C u, Dim.C v) =>
Proc.T s u q
(CausalD.Single s
(Amp.Dimensional v q) (Amp.Dimensional (DimensionGradient u v) q) yv yv)
differentiate :: forall yv q u v s.
(C yv, C q, C u, C v) =>
T s
u
q
(Single
s (Dimensional v q) (Dimensional (DimensionGradient u v) q) yv yv)
differentiate =
forall a b c. (a -> b -> c) -> b -> a -> c
flip forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall u s t. C u => T s u t (T (Recip u) t)
Proc.getSampleRate forall a b. (a -> b) -> a -> b
$ \T (Recip u) q
rate ->
forall sample0 sample1 s.
(Amplitude sample0
-> (Amplitude sample1,
T (Displacement sample0) (Displacement sample1)))
-> T s sample0 sample1
CausalD.consFlip forall a b. (a -> b) -> a -> b
$ \ (Amp.Numeric T v q
amp) ->
(forall amp. amp -> Numeric amp
Amp.Numeric forall a b. (a -> b) -> a -> b
$ T (Recip u) q
rate forall u v a. (C u, C v, C a) => T u a -> T v a -> T (Mul u v) a
&*& T v q
amp,
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry (-) forall (a :: * -> * -> *) c d b.
Arrow a =>
(c -> d) -> a b c -> a b d
^<< forall a. T a a
Causal.id forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& forall x. x -> T x x
Causal.consInit forall a. C a => a
zero)
{-# INLINE integrate #-}
integrate :: (Additive.C yv, Field.C q, Dim.C u, Dim.C v) =>
Proc.T s u q
(CausalD.T s (Sample.Dimensional v q yv) (Sample.Dimensional (Dim.Mul u v) q yv))
integrate :: forall yv q u v s.
(C yv, C q, C u, C v) =>
T s u q (T s (Dimensional v q yv) (Dimensional (Mul u v) q yv))
integrate =
forall a b c. (a -> b -> c) -> b -> a -> c
flip forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall u s t. C u => T s u t (T (Recip u) t)
Proc.getSampleRate forall a b. (a -> b) -> a -> b
$ \T (Recip u) q
rate ->
forall sample0 sample1 s.
(Amplitude sample0
-> (Amplitude sample1,
T (Displacement sample0) (Displacement sample1)))
-> T s sample0 sample1
CausalD.consFlip forall a b. (a -> b) -> a -> b
$ \ (Amp.Numeric T v q
amp) ->
(forall amp. amp -> Numeric amp
Amp.Numeric forall a b. (a -> b) -> a -> b
$
forall u a. (C u, C a) => T (Recip u) a -> T u a
DN.unrecip T (Recip u) q
rate forall u v a. (C u, C v, C a) => T u a -> T v a -> T (Mul u v) a
&*& T v q
amp,
forall v. C v => T v v
Integrate.causal)