{-# LANGUAGE NoImplicitPrelude #-}
{- |
Copyright   :  (c) Henning Thielemann 2008
License     :  GPL

Maintainer  :  synthesizer@henning-thielemann.de
Stability   :  provisional
Portability :  requires multi-parameter type classes

Filter operators from calculus
-}
module Synthesizer.Plain.Filter.Recursive.Integration where

import qualified Synthesizer.Plain.Signal   as Sig

import qualified Algebra.Additive              as Additive

import NumericPrelude.Numeric
import NumericPrelude.Base



{- |
Integrate with initial value zero.
However the first emitted value is the value of the input signal.
It maintains the length of the signal.
-}
{-# INLINE run #-}
run :: Additive.C v => Sig.T v -> Sig.T v
run :: forall v. C v => T v -> T v
run = (v -> v -> v) -> [v] -> [v]
forall a. (a -> a -> a) -> [a] -> [a]
scanl1 v -> v -> v
forall a. C a => a -> a -> a
(+)

{- |
Integrate with initial condition.
First emitted value is the initial condition.
The signal becomes one element longer.
-}
{-# INLINE runInit #-}
runInit :: Additive.C v => v -> Sig.T v -> Sig.T v
runInit :: forall v. C v => v -> T v -> T v
runInit = (v -> v -> v) -> v -> [v] -> [v]
forall b a. (b -> a -> b) -> b -> [a] -> [b]
scanl v -> v -> v
forall a. C a => a -> a -> a
(+)

{- other quadrature methods may follow -}