module Synthesizer.Filter.OneWay where
import Synthesizer.Filter.Basic
import qualified Synthesizer.Plain.Interpolation as Interpolation
import qualified Synthesizer.Plain.Filter.NonRecursive as FiltNR
import Number.Complex(cis)
import qualified Algebra.Module as Module
import qualified Algebra.Ring as Ring
import qualified Algebra.Additive as Additive
import Algebra.Module(linearComb)
import Algebra.Additive(zero)
import PreludeBase
import NumericPrelude
type Signal = []
delay :: (Additive.C v) =>
Int -> Signal v -> Signal v
delay = FiltNR.delayPad zero
delayOnce :: (Additive.C v) =>
Signal v -> Signal v
delayOnce = (zero:)
nonRecursiveFilter :: Module.C a v =>
[a] -> [v] -> [v]
nonRecursiveFilter = FiltNR.generic
nonRecursiveFilterMod :: Module.C a v =>
[[a]] -> [v] -> [v]
nonRecursiveFilterMod ms x =
zipWith linearComb ms (tail (scanl (flip (:)) [] x))
data T t a v =
Mask [a]
| ModMask (Signal [a])
| FracDelay (Interpolation.T t v) t
| ModFracDelay (Interpolation.T t v) (Signal t)
| Delay [v]
instance Filter [] T where
apply (Mask m) = nonRecursiveFilter m
apply (ModMask m) = nonRecursiveFilterMod m
apply (FracDelay ip t) = Interpolation.multiRelativeZeroPad zero
ip (t) (repeat 1)
apply (ModFracDelay ip ts) = Interpolation.multiRelativeZeroPad zero
ip ( head ts) (repeat 1 FiltNR.differentiate ts)
apply (Delay x) = (x++)
transferFunction (Mask m) w = linearComb m (screw (negate w))
transferFunction (FracDelay _ t) w = cis (negate w * t)
transferFunction (Delay x) w = cis (negate w * fromIntegral (length x))
transferFunction _ _ =
error "transfer function can't be computed for modulated filters"