module Synthesizer.Dimensional.RateAmplitude.Noise
(white, whiteBandEnergy, randomPeeks,
whiteGen, whiteBandEnergyGen, randomPeeksGen,
) where
import qualified Synthesizer.State.NoiseCustom as Noise
import qualified Synthesizer.State.Signal as Sig
import qualified Synthesizer.RandomKnuth as Knuth
import qualified Synthesizer.Dimensional.Signal.Private as SigA
import qualified Synthesizer.Dimensional.Rate.Dirac as Dirac
import qualified Synthesizer.Dimensional.Process as Proc
import Synthesizer.Dimensional.Process (($#), )
import qualified Number.DimensionTerm as DN
import qualified Algebra.DimensionTerm as Dim
import Number.DimensionTerm ((&*&))
import qualified Algebra.Algebraic as Algebraic
import qualified Algebra.Field as Field
import System.Random (Random, RandomGen, mkStdGen)
import NumericPrelude.Numeric
import NumericPrelude.Base as P
white :: (Field.C yv, Random yv, Algebraic.C q, Dim.C u, Dim.C v) =>
DN.T (Dim.Recip u) q
-> DN.T v q
-> Proc.T s u q (SigA.R s v q yv)
white =
whiteGen (Knuth.cons 6746)
whiteGen ::
(Field.C yv, Random yv, RandomGen g, Algebraic.C q, Dim.C u, Dim.C v) =>
g
-> DN.T (Dim.Recip u) q
-> DN.T v q
-> Proc.T s u q (SigA.R s v q yv)
whiteGen gen bandWidth volume =
flip fmap (Proc.toFrequencyScalar bandWidth) $ \bw ->
SigA.fromBody
(DN.scale (sqrt $ 3 / bw) volume)
(Noise.whiteGen gen)
whiteBandEnergy :: (Field.C yv, Random yv, Algebraic.C q, Dim.C u, Dim.C v) =>
DN.T (Dim.Mul u (Dim.Sqr v)) q
-> Proc.T s u q (SigA.R s v q yv)
whiteBandEnergy = whiteBandEnergyGen (mkStdGen 6746)
whiteBandEnergyGen ::
(Field.C yv, Random yv, RandomGen g, Algebraic.C q, Dim.C u, Dim.C v) =>
g
-> DN.T (Dim.Mul u (Dim.Sqr v)) q
-> Proc.T s u q (SigA.R s v q yv)
whiteBandEnergyGen gen energy =
flip fmap Proc.getSampleRate $ \rate ->
SigA.fromBody
(DN.sqrt $ DN.scale 3 $
DN.rewriteDimension
(Dim.identityLeft . Dim.applyLeftMul Dim.cancelLeft .
Dim.associateLeft) $
rate &*& energy)
(Noise.whiteGen gen)
randomPeeks ::
(Field.C q, Random q, Ord q, Dim.C u) =>
Proc.T s u q (
SigA.R s (Dim.Recip u) q q
-> SigA.R s (Dim.Recip u) q q)
randomPeeks =
randomPeeksGen (mkStdGen 876)
randomPeeksGen ::
(Field.C q, Random q, Ord q, Dim.C u,
RandomGen g) =>
g
-> Proc.T s u q (
SigA.R s (Dim.Recip u) q q
-> SigA.R s (Dim.Recip u) q q)
randomPeeksGen g =
Proc.withParam $ \ dens ->
do freq <- Proc.toFrequencyScalar (SigA.actualAmplitude dens)
Dirac.toAmplitudeSignal $#
(Dirac.Cons $
Sig.zipWith (<)
(Noise.randomRs (0, recip freq) g)
(SigA.body dens))