```{-# LANGUAGE NoImplicitPrelude #-}
module Synthesizer.Causal.Interpolation (
Interpolation.T,

relative,
) where

import qualified Synthesizer.Interpolation.Module as IpExample
import qualified Synthesizer.Interpolation as Interpolation
import qualified Synthesizer.State.Interpolation as InterpolationS

import qualified Synthesizer.Causal.Process as Causal
import qualified Synthesizer.State.Signal   as Sig

import qualified Algebra.Module    as Module
import qualified Algebra.RealField as RealField

import PreludeBase
import NumericPrelude

{-* Interpolation at multiple nodes with various padding methods -}

{- | All values of frequency control must be non-negative. -}
{-# INLINE relative #-}
relative :: (RealField.C t) =>
Interpolation.T t y -> t -> Sig.T y -> Causal.T t y
relative ip phase0 x0 =
Causal.crochetL
(\freq pos ->
let (phase,x) = InterpolationS.skip ip pos
in  Just (Interpolation.func ip phase x, (phase+freq,x)))
(phase0,x0)

y -> Interpolation.T t y -> t -> Sig.T y -> Causal.T t y
relativeZeroPad z ip phase x =
InterpolationS.zeroPad relative z ip phase x

Interpolation.T t y -> t -> Sig.T y -> Causal.T t y

Interpolation.T t y -> t -> Sig.T y -> Causal.T t y

{- |
The extrapolation may miss some of the first and some of the last points
-}
Interpolation.T t y -> t -> Sig.T y -> Causal.T t y
{-
This example shows pikes, although there shouldn't be any:
plotList (take 100 \$ interpolate (Zero (0::Double)) ipCubic (-0.9::Double) (repeat 0.03) [1,0,1,0.8])
-}

{-* All-in-one interpolation functions -}

t -> Sig.T y -> Causal.T t y