module Synthesizer.Dimensional.Causal.Oscillator (
freqMod,
phaseMod,
phaseFreqMod,
shapeMod,
shapeFreqMod,
shapeFreqModFromSampledTone,
shapePhaseFreqModFromSampledTone,
) where
import qualified Synthesizer.Dimensional.Causal.Oscillator.Core as OsciCore
import qualified Synthesizer.Dimensional.Causal.Process as CausalD
import Control.Arrow ((<<^), (<<<), second, )
import qualified Synthesizer.Dimensional.Sample as Sample
import qualified Synthesizer.Dimensional.Amplitude as Amp
import qualified Synthesizer.Dimensional.Rate as Rate
import qualified Synthesizer.Causal.Oscillator as Osci
import Synthesizer.Causal.Filter.NonRecursive (amplify, )
import qualified Synthesizer.Generic.Signal as SigG
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.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.Numeric
import NumericPrelude.Base as P
type Frequency u t = Amp.Numeric (DN.T (Dim.Recip u) t)
type SampleFrequency u t = Sample.T (Frequency u t) t
freqMod :: (RealField.C t, Dim.C u) =>
WaveD.T t y
-> Phase.T t
-> Proc.T s u t
(CausalD.T s (SampleFrequency u t) y)
freqMod wave phase =
fmap (wave CausalD.^<<) $ OsciCore.freqMod phase
phaseMod :: (RealField.C t, Dim.C u) =>
WaveD.T t y
-> DN.T (Dim.Recip u) t
-> Proc.T s u t
(CausalD.T s (Sample.Flat t) y)
phaseMod wave freq =
fmap (wave CausalD.^<<) $
OsciCore.phaseMod freq
shapeMod :: (RealField.C t, Dim.C u) =>
WaveCtrl.T c t y
-> Phase.T t
-> DN.T (Dim.Recip u) t
-> Proc.T s u t
(CausalD.T s c y)
shapeMod wave phase freq =
fmap (wave CausalD.^<<) $
fmap CausalD.feedSnd $
OsciCore.static phase freq
phaseFreqMod :: (RealField.C t, Dim.C u) =>
WaveD.T t y
-> Proc.T s u t
(CausalD.T s (Sample.Flat t, SampleFrequency u t) y)
phaseFreqMod wave =
fmap (wave CausalD.^<<) $
OsciCore.phaseFreqMod
shapeFreqMod :: (RealField.C t, Dim.C u) =>
WaveCtrl.T c t y
-> Phase.T t
-> Proc.T s u t
(CausalD.T s (c, SampleFrequency u t) y)
shapeFreqMod wave phase =
fmap (wave CausalD.^<<) $
fmap second $
OsciCore.freqMod phase
shapeFreqModFromSampledTone ::
(RealField.C t, SigG.Transform sig yv, Dim.C u) =>
Interpolation.T t yv
-> Interpolation.T t yv
-> DN.T (Dim.Recip u) t
-> SigA.T (Rate.Dimensional u t) amp (sig yv)
-> t -> Phase.T t
-> Proc.T s u t
(CausalD.T s
(Sample.Flat t, SampleFrequency u t)
(Sample.T amp yv))
shapeFreqModFromSampledTone
ipLeap ipStep srcFreq sampledTone shape0 phase =
let SigA.Cons (Rate.Actual srcRate) amp samples = sampledTone
in flip fmap (Proc.withParam toFrequencyScalar) $ \toFreq ->
CausalD.consFlip $ \(Amp.Flat, Amp.Numeric freqAmp) ->
(amp,
Osci.shapeFreqModFromSampledTone
ipLeap ipStep
(DN.divToScalar srcRate srcFreq)
samples
shape0 phase
<<< second (amplify (toFreq freqAmp)))
shapePhaseFreqModFromSampledTone ::
(RealField.C t, SigG.Transform sig yv, Dim.C u) =>
Interpolation.T t yv
-> Interpolation.T t yv
-> DN.T (Dim.Recip u) t
-> SigA.T (Rate.Dimensional u t) amp (sig yv)
-> t -> Phase.T t
-> Proc.T s u t
(CausalD.T s
(Sample.Flat t, Sample.Flat t, SampleFrequency u t)
(Sample.T amp yv))
shapePhaseFreqModFromSampledTone
ipLeap ipStep srcFreq sampledTone shape0 phase =
let SigA.Cons (Rate.Actual srcRate) amp samples = sampledTone
in flip fmap (Proc.withParam toFrequencyScalar) $ \toFreq ->
CausalD.consFlip $ \(Amp.Flat, Amp.Flat, Amp.Numeric freqAmp) ->
(amp,
Osci.shapePhaseFreqModFromSampledTone
ipLeap ipStep
(DN.divToScalar srcRate srcFreq)
samples
shape0 phase
<<^
(\(s,p,f) -> (s,p, toFreq freqAmp * f)))