module Synthesizer.Dimensional.Rate.Oscillator (
static,
freqMod,
phaseMod,
phaseFreqMod,
shapeMod,
shapeFreqMod,
staticSample,
freqModSample,
shapeFreqModFromSampledTone,
shapePhaseFreqModFromSampledTone,
) where
import qualified Synthesizer.Dimensional.Causal.Oscillator as OsciC
import qualified Synthesizer.State.Oscillator as Osci
import qualified Synthesizer.State.Signal as Sig
import qualified Synthesizer.Dimensional.Causal.Process as CausalD
import qualified Synthesizer.Dimensional.Causal.Oscillator.Core as OsciCore
import qualified Synthesizer.Dimensional.Map as MapD
import qualified Synthesizer.Dimensional.Sample as Sample
import qualified Synthesizer.Dimensional.Amplitude.Flat as Flat
import qualified Synthesizer.Dimensional.Rate as Rate
import qualified Synthesizer.Dimensional.Wave.Controlled as WaveCtrl
import qualified Synthesizer.Dimensional.Wave as WaveD
import qualified Synthesizer.Basic.Phase as Phase
import qualified Synthesizer.Dimensional.Cyclic.Signal as SigC
import qualified Synthesizer.Dimensional.Signal.Private as SigA
import qualified Synthesizer.Dimensional.Process as Proc
import Synthesizer.Dimensional.Process (toFrequencyScalar, )
import qualified Synthesizer.Interpolation as Interpolation
import qualified Number.DimensionTerm as DN
import qualified Algebra.DimensionTerm as Dim
import qualified Algebra.RealField as RealField
import NumericPrelude.Base as P
type Signal s amp y =
SigA.T (Rate.Phantom s) amp (Sig.T y)
static ::
(RealField.C t, Dim.C u) =>
WaveD.T t (Sample.T amp y)
-> Phase.T t
-> DN.T (Dim.Recip u) t
-> Proc.T s u t (Signal s amp y)
static wave phase freq =
fmap (MapD.apply wave) $
OsciCore.static phase freq
freqMod ::
(RealField.C t, Dim.C u) =>
WaveD.T t (Sample.T amp y)
-> Phase.T t
-> Proc.T s u t (
SigA.R s (Dim.Recip u) t t
-> Signal s amp y)
freqMod wave phase =
fmap CausalD.apply $
OsciC.freqMod wave phase
phaseMod ::
(Flat.C t flat, RealField.C t, Dim.C u) =>
WaveD.T t (Sample.T amp y)
-> DN.T (Dim.Recip u) t
-> Proc.T s u t (
Signal s flat t
-> Signal s amp y)
phaseMod wave freq =
fmap CausalD.applyFlat $
OsciC.phaseMod wave freq
shapeMod ::
(RealField.C t, Dim.C u) =>
WaveCtrl.T (Sample.T cAmp c) t (Sample.T amp y)
-> Phase.T t
-> DN.T (Dim.Recip u) t
-> Proc.T s u t (
Signal s cAmp c
-> Signal s amp y)
shapeMod wave phase freq =
fmap CausalD.apply $
OsciC.shapeMod wave phase freq
phaseFreqMod ::
(Flat.C t flat, RealField.C t, Dim.C u) =>
WaveD.T t (Sample.T amp y)
-> Proc.T s u t (
Signal s flat t
-> SigA.R s (Dim.Recip u) t t
-> Signal s amp y)
phaseFreqMod wave =
flip fmap (OsciC.phaseFreqMod wave) $ \osci phases freqs ->
CausalD.applyFlatFst osci phases
`CausalD.apply`
freqs
shapeFreqMod :: (RealField.C t, Dim.C u) =>
WaveCtrl.T (Sample.T cAmp c) t (Sample.T amp y)
-> Phase.T t
-> Proc.T s u t (
Signal s cAmp c
-> SigA.R s (Dim.Recip u) t t
-> Signal s amp y)
shapeFreqMod wave phase =
flip fmap (OsciC.shapeFreqMod wave phase) $ \osci shapes freqs ->
CausalD.applyFst osci shapes
`CausalD.apply`
freqs
staticSample :: (RealField.C t, Dim.C u) =>
Interpolation.T t y
-> SigA.T rate amp (SigC.T (Sig.T y))
-> Phase.T t
-> DN.T (Dim.Recip u) t
-> Proc.T s u t (Signal s amp y)
staticSample ip wave phase freq =
flip fmap (toFrequencyScalar freq) $
SigA.Cons Rate.Phantom (SigA.amplitude wave) .
Osci.staticSample ip (SigC.toPeriod $ SigA.body wave) phase
freqModSample :: (RealField.C t, Dim.C u) =>
Interpolation.T t y
-> SigA.T rate amp (SigC.T (Sig.T y))
-> Phase.T t
-> Proc.T s u t (
SigA.R s (Dim.Recip u) t t
-> Signal s amp y)
freqModSample ip wave phase =
flip fmap (Proc.withParam toFrequencyScalar) $ \toFreq ->
SigA.Cons Rate.Phantom (SigA.amplitude wave) .
Osci.freqModSample ip (SigC.toPeriod $ SigA.body wave) phase .
SigA.scalarSamples toFreq
shapeFreqModFromSampledTone ::
(RealField.C t, Dim.C u, Flat.C t flat) =>
Interpolation.T t yv
-> Interpolation.T t yv
-> DN.T (Dim.Recip u) t
-> SigA.T (Rate.Dimensional u t) amp (Sig.T yv)
-> t -> Phase.T t
-> Proc.T s u t (
Signal s flat t
-> SigA.R s (Dim.Recip u) t t
-> Signal s amp yv)
shapeFreqModFromSampledTone
ipLeap ipStep srcFreq sampledTone shape0 phase =
flip fmap
(OsciC.shapeFreqModFromSampledTone
ipLeap ipStep srcFreq sampledTone shape0 phase)
(\osci ->
\shapes freqs ->
osci
`CausalD.applyFlatFst`
shapes
`CausalD.apply`
freqs)
shapePhaseFreqModFromSampledTone ::
(RealField.C t, Dim.C u, Flat.C t flatS, Flat.C t flatP) =>
Interpolation.T t yv
-> Interpolation.T t yv
-> DN.T (Dim.Recip u) t
-> SigA.T (Rate.Dimensional u t) amp (Sig.T yv)
-> t -> Phase.T t
-> Proc.T s u t (
Signal s flatS t
-> Signal s flatP t
-> SigA.R s (Dim.Recip u) t t
-> Signal s amp yv)
shapePhaseFreqModFromSampledTone
ipLeap ipStep srcFreq sampledTone shape0 phase =
flip fmap
(OsciC.shapePhaseFreqModFromSampledTone
ipLeap ipStep srcFreq sampledTone shape0 phase)
(\osci ->
\shapes phaseDistort freqs ->
(osci CausalD.<<^ MapD.packTriple)
`CausalD.applyFlatFst`
shapes
`CausalD.applyFlatFst`
phaseDistort
`CausalD.apply`
freqs)