module Synthesizer.Plain.Oscillator where
import qualified Synthesizer.Plain.ToneModulation as ToneMod
import qualified Synthesizer.Basic.Wave as Wave
import qualified Synthesizer.Basic.Phase as Phase
import qualified Synthesizer.Plain.Interpolation as Interpolation
import qualified Synthesizer.Plain.Signal as Sig
import Synthesizer.Plain.ToneModulation (freqsToPhases, )
import qualified Algebra.Transcendental as Trans
import qualified Algebra.RealField as RealField
import qualified Algebra.RealRing as RealRing
import Data.Tuple.HT (mapFst, mapSnd, )
import NumericPrelude.Numeric
import NumericPrelude.Base
type Phase a = a
static :: (RealRing.C a) => Wave.T a b -> (Phase a -> a -> Sig.T b)
static wave phase freq =
map (Wave.apply wave)
(iterate (Phase.increment freq) (Phase.fromRepresentative phase))
freqMod :: (RealRing.C a) => Wave.T a b -> Phase a -> Sig.T a -> Sig.T b
freqMod wave phase freqs =
map (Wave.apply wave)
(freqsToPhases (Phase.fromRepresentative phase) freqs)
phaseMod :: (RealRing.C a) => Wave.T a b -> a -> Sig.T (Phase a) -> Sig.T b
phaseMod wave freq phases =
map (Wave.apply wave) $
zipWith Phase.increment phases (iterate (Phase.increment freq) zero)
shapeMod :: (RealRing.C a) => (c -> Wave.T a b) -> (Phase a) -> a -> Sig.T c -> Sig.T b
shapeMod wave phase freq parameters =
zipWith (Wave.apply . wave) parameters $
iterate (Phase.increment freq) (Phase.fromRepresentative phase)
phaseFreqMod :: (RealRing.C a) => Wave.T a b -> Sig.T (Phase a) -> Sig.T a -> Sig.T b
phaseFreqMod wave phases freqs =
map (Wave.apply wave)
(zipWith Phase.increment phases (freqsToPhases zero freqs))
shapeFreqMod :: (RealRing.C a) => (c -> Wave.T a b) -> Phase a -> Sig.T c -> Sig.T a -> Sig.T b
shapeFreqMod wave phase parameters freqs =
zipWith (Wave.apply . wave) parameters $
freqsToPhases (Phase.fromRepresentative phase) freqs
staticSample :: RealRing.C a => Interpolation.T a b -> [b] -> Phase a -> a -> Sig.T b
staticSample ip wave phase freq =
freqModSample ip wave phase (repeat freq)
freqModSample :: RealRing.C a => Interpolation.T a b -> [b] -> Phase a -> Sig.T a -> Sig.T b
freqModSample ip wave phase freqs =
let len = fromIntegral (length wave)
in Interpolation.multiRelativeCyclicPad
ip (phase*len) (map (len*) freqs) wave
shapeFreqModSample :: (RealRing.C c, RealRing.C b) =>
Interpolation.T c (Wave.T b a) -> [Wave.T b a] -> c -> Phase b -> Sig.T c -> Sig.T b -> Sig.T a
shapeFreqModSample ip waves shape0 phase shapes freqs =
zipWith Wave.apply
(Interpolation.multiRelativeConstantPad ip shape0 shapes waves)
(freqsToPhases (Phase.fromRepresentative phase) freqs)
shapePhaseFreqModSample :: (RealRing.C c, RealRing.C b) =>
Interpolation.T c (Wave.T b a) -> [Wave.T b a] -> c -> Sig.T c -> Sig.T (Phase b) -> Sig.T b -> Sig.T a
shapePhaseFreqModSample ip waves shape0 shapes phases freqs =
zipWith Wave.apply
(Interpolation.multiRelativeConstantPad ip shape0 shapes waves)
(zipWith Phase.increment phases (freqsToPhases zero freqs))
shapeFreqModFromSampledTone :: (RealField.C t) =>
Interpolation.T t y ->
Interpolation.T t y ->
t -> Sig.T y -> t -> t -> Sig.T t -> Sig.T t -> Sig.T y
shapeFreqModFromSampledTone
ipLeap ipStep period sampledTone
shape0 phase shapes freqs =
let periodInt = round period
in map
(uncurry (ToneMod.interpolateCell ipLeap ipStep))
(ToneMod.oscillatorCells
(Interpolation.margin ipLeap) (Interpolation.margin ipStep)
periodInt period sampledTone
(shape0, shapes) (Phase.fromRepresentative phase, freqs))
shapePhaseFreqModFromSampledTone :: (RealField.C t) =>
Interpolation.T t y ->
Interpolation.T t y ->
t -> Sig.T y -> t -> t -> Sig.T t -> Sig.T t -> Sig.T t -> Sig.T y
shapePhaseFreqModFromSampledTone
ipLeap ipStep period sampledTone
shape0 phase shapes phases freqs =
let periodInt = round period
marginLeap = Interpolation.margin ipLeap
marginStep = Interpolation.margin ipStep
in map
(uncurry (ToneMod.interpolateCell ipLeap ipStep) .
ToneMod.seekCell periodInt period) $
zipWith (\p -> mapFst (mapSnd (Phase.increment p))) phases $
ToneMod.oscillatorSuffixes
marginLeap marginStep
periodInt period sampledTone
(shape0, shapes)
(Phase.fromRepresentative phase, freqs)
staticSine :: (Trans.C a, RealRing.C a) => a -> a -> Sig.T a
staticSine = static Wave.sine
freqModSine :: (Trans.C a, RealRing.C a) => a -> Sig.T a -> Sig.T a
freqModSine = freqMod Wave.sine
phaseModSine :: (Trans.C a, RealRing.C a) => a -> Sig.T a -> Sig.T a
phaseModSine = phaseMod Wave.sine
staticSaw :: RealRing.C a => a -> a -> Sig.T a
staticSaw = static Wave.saw
freqModSaw :: RealRing.C a => a -> Sig.T a -> Sig.T a
freqModSaw = freqMod Wave.saw