{-# LANGUAGE NoImplicitPrelude #-}
module Synthesizer.Storable.Oscillator where
import qualified Synthesizer.Basic.Wave as Wave
import qualified Synthesizer.Basic.Phase as Phase
import qualified Synthesizer.Storable.Signal as Signal
import Synthesizer.Storable.Signal (ChunkSize)
import Foreign.Storable (Storable)
import qualified Algebra.Transcendental as Trans
import qualified Algebra.RealRing as RealRing
import NumericPrelude.Numeric
import NumericPrelude.Base
{-# INLINE freqToPhase #-}
freqToPhase :: (RealRing.C a, Storable a) =>
Phase.T a -> Signal.T a -> Signal.T (Phase.T a)
freqToPhase phase freq = Signal.scanL (flip Phase.increment) phase freq
{-# INLINE static #-}
static :: (RealRing.C a, Storable a, Storable b) =>
ChunkSize -> Wave.T a b -> (Phase.T a -> a -> Signal.T b)
static size wave phase freq =
Signal.map (Wave.apply wave) (Signal.iterate size (Phase.increment freq) phase)
phaseMod :: (RealRing.C a, Storable a, Storable b) =>
ChunkSize -> Wave.T a b -> a -> Signal.T a -> Signal.T b
phaseMod size wave = shapeMod size (Wave.phaseOffset wave) zero
shapeMod :: (RealRing.C a, Storable a, Storable b, Storable c) =>
ChunkSize -> (c -> Wave.T a b) -> Phase.T a -> a -> Signal.T c -> Signal.T b
shapeMod size wave phase freq parameters =
Signal.zipWith (Wave.apply . wave) parameters
(Signal.iterate size (Phase.increment freq) phase)
freqMod :: (RealRing.C a, Storable a, Storable b) =>
ChunkSize -> Wave.T a b -> Phase.T a -> Signal.T a -> Signal.T b
freqMod _size wave phase freqs =
Signal.map (Wave.apply wave) (freqToPhase phase freqs)
phaseFreqMod :: (RealRing.C a, Storable a, Storable b) =>
ChunkSize -> Wave.T a b -> Signal.T a -> Signal.T a -> Signal.T b
phaseFreqMod size wave =
shapeFreqMod size (Wave.phaseOffset wave) zero
shapeFreqMod :: (RealRing.C a, Storable a, Storable b, Storable c) =>
ChunkSize -> (c -> Wave.T a b) ->
Phase.T a -> Signal.T c -> Signal.T a -> Signal.T b
shapeFreqMod _size wave phase parameters freqs =
Signal.zipWith (Wave.apply . wave) parameters (freqToPhase phase freqs)
{-# INLINE staticSine #-}
staticSine :: (Trans.C a, RealRing.C a, Storable a) =>
ChunkSize -> Phase.T a -> a -> Signal.T a
staticSine size = static size Wave.sine
{-# INLINE freqModSine #-}
freqModSine :: (Trans.C a, RealRing.C a, Storable a) =>
ChunkSize -> Phase.T a -> Signal.T a -> Signal.T a
freqModSine size = freqMod size Wave.sine
{-# INLINE phaseModSine #-}
phaseModSine :: (Trans.C a, RealRing.C a, Storable a) =>
ChunkSize -> a -> Signal.T a -> Signal.T a
phaseModSine size = phaseMod size Wave.sine
{-# INLINE staticSaw #-}
staticSaw :: (RealRing.C a, Storable a) =>
ChunkSize -> Phase.T a -> a -> Signal.T a
staticSaw size = static size Wave.saw
{-# INLINE freqModSaw #-}
freqModSaw :: (RealRing.C a, Storable a) =>
ChunkSize -> Phase.T a -> Signal.T a -> Signal.T a
freqModSaw size = freqMod size Wave.saw