module Synthesizer.Generic.Oscillator where
import qualified Synthesizer.State.Oscillator as OsciS
import qualified Synthesizer.Causal.Oscillator as OsciC
import qualified Synthesizer.Causal.Process as Causal
import qualified Synthesizer.Basic.Wave as Wave
import qualified Synthesizer.Basic.Phase as Phase
import qualified Synthesizer.Causal.Interpolation as Interpolation
import qualified Synthesizer.Generic.Signal as SigG
import Control.Arrow ((>>>), )
import qualified Algebra.Transcendental as Trans
import qualified Algebra.RealField as RealField
import NumericPrelude.Numeric
import NumericPrelude.Base
static :: (RealField.C a, SigG.Write sig b) =>
SigG.LazySize ->
Wave.T a b -> (Phase.T a -> a -> sig b)
static size wave phase freq =
SigG.fromState size (OsciS.static wave phase freq)
freqMod :: (RealField.C a, SigG.Transform sig a, SigG.Transform sig b) =>
Wave.T a b -> Phase.T a -> sig a -> sig b
freqMod wave phase =
Causal.apply (OsciC.freqMod wave phase)
phaseMod :: (RealField.C a, SigG.Transform sig a, SigG.Transform sig b) =>
Wave.T a b -> a -> sig a -> sig b
phaseMod wave =
shapeMod (Wave.phaseOffset wave) zero
shapeMod :: (RealField.C a, SigG.Transform sig c, SigG.Transform sig b) =>
(c -> Wave.T a b) -> Phase.T a -> a -> sig c -> sig b
shapeMod wave phase freq =
Causal.apply (OsciC.shapeMod wave phase freq)
phaseFreqMod :: (RealField.C a, SigG.Transform sig a, SigG.Transform sig b) =>
Wave.T a b -> sig a -> sig a -> sig b
phaseFreqMod wave =
shapeFreqMod (Wave.phaseOffset wave) zero
shapeFreqMod ::
(RealField.C a,
SigG.Read sig c, SigG.Transform sig a, SigG.Transform sig b) =>
(c -> Wave.T a b) -> Phase.T a -> sig c -> sig a -> sig b
shapeFreqMod wave phase parameters =
Causal.apply
(Causal.feedGenericFst parameters >>>
OsciC.shapeFreqMod wave phase)
staticSample :: (RealField.C a, SigG.Read wave b, SigG.Write sig b) =>
SigG.LazySize ->
Interpolation.T a b -> wave b -> Phase.T a -> a -> sig b
staticSample size ip wave phase freq =
let len = fromIntegral $ SigG.length wave
in SigG.fromState size $
Interpolation.relativeCyclicPad
ip (len * Phase.toRepresentative phase)
(SigG.toState wave)
`Causal.applyConst`
(freq * len)
freqModSample ::
(RealField.C a,
SigG.Read wave b, SigG.Transform sig a, SigG.Transform sig b) =>
Interpolation.T a b -> wave b -> Phase.T a -> sig a -> sig b
freqModSample ip wave phase freqs =
let len = fromIntegral $ SigG.length wave
in Interpolation.relativeCyclicPad
ip (len * Phase.toRepresentative phase)
(SigG.toState wave)
`Causal.apply`
SigG.map (* len) freqs
staticSine :: (Trans.C a, RealField.C a, SigG.Write sig a) =>
SigG.LazySize ->
Phase.T a -> a -> sig a
staticSine size =
static size Wave.sine
freqModSine :: (Trans.C a, RealField.C a, SigG.Transform sig a) =>
Phase.T a -> sig a -> sig a
freqModSine phase =
Causal.applySameType (OsciC.freqMod Wave.sine phase)
phaseModSine :: (Trans.C a, RealField.C a, SigG.Transform sig a) =>
a -> sig a -> sig a
phaseModSine freq =
Causal.applySameType (OsciC.phaseMod Wave.sine freq)
staticSaw :: (RealField.C a, SigG.Write sig a) =>
SigG.LazySize ->
Phase.T a -> a -> sig a
staticSaw size =
static size Wave.saw
freqModSaw :: (RealField.C a, SigG.Transform sig a) =>
Phase.T a -> sig a -> sig a
freqModSaw phase =
Causal.applySameType (OsciC.freqMod Wave.saw phase)