synthesizer-0.0.3: src/Synthesizer/Plain/Noise.hs
{-# OPTIONS -fno-implicit-prelude #-}
{- | Noise and random processes. -}
module Synthesizer.Plain.Noise where
import qualified Synthesizer.Plain.Signal as Sig
import qualified Algebra.Real as Real
import qualified Algebra.Ring as Ring
import System.Random (Random, RandomGen, randomRs, mkStdGen, )
import NumericPrelude.List (sliceVert)
import qualified Prelude as P
import PreludeBase
import NumericPrelude
{-|
Deterministic white noise, uniformly distributed between -1 and 1.
That is, variance is 1\/3.
-}
white :: (Ring.C y, Random y) =>
Sig.T y
white = whiteGen (mkStdGen 12354)
whiteGen :: (Ring.C y, Random y, RandomGen g) =>
g -> Sig.T y
whiteGen = randomRs (-1,1)
{- |
Approximates normal distribution with variance 1
by a quadratic B-spline distribution.
-}
whiteQuadraticBSplineGen :: (Ring.C y, Random y, RandomGen g) =>
g -> Sig.T y
whiteQuadraticBSplineGen =
map sum . sliceVert 3 . randomRs (-1,1)
randomPeeks :: (Real.C y, Random y) =>
Sig.T y {- ^ momentary densities, @p@ means that there is about one peak
in the time range of @1\/p@ samples -}
-> Sig.T Bool {- ^ Every occurence of 'True' represents a peak. -}
randomPeeks =
randomPeeksGen (mkStdGen 876)
randomPeeksGen :: (Real.C y, Random y, RandomGen g) =>
g
-> Sig.T y
-> Sig.T Bool
randomPeeksGen =
zipWith (<) . randomRs (0,1)