-- | Noise generating functions.
module Sound.SC3.Common.Math.Noise where

import Sound.SC3.Common.Math {- hsc3 -}

-- | x(n+1) = a - b * sqrt(|x(n)|)
cusp_f :: Floating t => t -> t -> t -> t
cusp_f :: t -> t -> t -> t
cusp_f t
a t
b t
x = t
a t -> t -> t
forall a. Num a => a -> a -> a
- (t
b t -> t -> t
forall a. Num a => a -> a -> a
* t -> t
forall a. Floating a => a -> a
sqrt (t -> t
forall a. Num a => a -> a
abs t
x))

-- | x(n+1) = sin(im * y(n) + fb * x(n))
--   y(n+1) = (a * y(n) + c) % 2pi
fbSine_f :: (Floating t, RealFrac t) => t -> t -> t -> t -> (t, t) -> (t, t)
fbSine_f :: t -> t -> t -> t -> (t, t) -> (t, t)
fbSine_f t
im t
fb t
a t
c (t
x,t
y) = (t -> t
forall a. Floating a => a -> a
sin ((t
im t -> t -> t
forall a. Num a => a -> a -> a
* t
y) t -> t -> t
forall a. Num a => a -> a -> a
+ (t
fb t -> t -> t
forall a. Num a => a -> a -> a
* t
x)),((t
a t -> t -> t
forall a. Num a => a -> a -> a
* t
y) t -> t -> t
forall a. Num a => a -> a -> a
+ t
c) t -> t -> t
forall n. RealFrac n => n -> n -> n
`sc3_mod` (t
2 t -> t -> t
forall a. Num a => a -> a -> a
* t
forall a. Floating a => a
pi))

-- | x(n+2) = 1 - a * x(n+1)^2 + b * x(n)
henon_f :: Floating t => t -> t -> (t, t) -> (t, t)
henon_f :: t -> t -> (t, t) -> (t, t)
henon_f t
a t
b (t
x1,t
x0) = (t
1 t -> t -> t
forall a. Num a => a -> a -> a
- (t
a t -> t -> t
forall a. Num a => a -> a -> a
* (t
x1 t -> t -> t
forall a. Floating a => a -> a -> a
** t
2)) t -> t -> t
forall a. Num a => a -> a -> a
+ (t
b t -> t -> t
forall a. Num a => a -> a -> a
* t
x0),t
x1)

-- | x(n+1) = sin(b * y(n)) + c * sin(b * x(n))
--   y(n+1) = sin(a * x(n)) + d * sin(a * y(n))
latoocarfian_f :: Floating t => t -> t -> t -> t -> (t, t) -> (t, t)
latoocarfian_f :: t -> t -> t -> t -> (t, t) -> (t, t)
latoocarfian_f t
a t
b t
c t
d (t
x,t
y) = (t -> t
forall a. Floating a => a -> a
sin(t
b t -> t -> t
forall a. Num a => a -> a -> a
* t
y) t -> t -> t
forall a. Num a => a -> a -> a
+ (t
c t -> t -> t
forall a. Num a => a -> a -> a
* t -> t
forall a. Floating a => a -> a
sin (t
b t -> t -> t
forall a. Num a => a -> a -> a
* t
x)),t -> t
forall a. Floating a => a -> a
sin(t
a t -> t -> t
forall a. Num a => a -> a -> a
* t
x) t -> t -> t
forall a. Num a => a -> a -> a
+ (t
d t -> t -> t
forall a. Num a => a -> a -> a
* t -> t
forall a. Floating a => a -> a
sin (t
a t -> t -> t
forall a. Num a => a -> a -> a
* t
y)))

-- | x(n+1) = (a * x(n) + c) % m
linCong_f :: RealFrac t => t -> t -> t -> t -> t
linCong_f :: t -> t -> t -> t -> t
linCong_f t
a t
c t
m t
x = (t
a t -> t -> t
forall a. Num a => a -> a -> a
* t
x t -> t -> t
forall a. Num a => a -> a -> a
+ t
c) t -> t -> t
forall n. RealFrac n => n -> n -> n
`sc3_mod` t
m

-- | x(n+1) = a * x * (1.0 - x)
logistic_f :: Num t => t -> t -> t
logistic_f :: t -> t -> t
logistic_f t
a t
x = t
a t -> t -> t
forall a. Num a => a -> a -> a
* t
x t -> t -> t
forall a. Num a => a -> a -> a
* (t
1 t -> t -> t
forall a. Num a => a -> a -> a
- t
x)

-- | x' = s * (y - x)
--   y' = x * (r - z) - y
--   z' = x * y - b * z
lorenz_f :: Num t => t -> t -> t -> (t, t, t) -> (t, t, t)
lorenz_f :: t -> t -> t -> (t, t, t) -> (t, t, t)
lorenz_f t
s t
r t
b (t
x,t
y,t
z) = (t
s t -> t -> t
forall a. Num a => a -> a -> a
* (t
y t -> t -> t
forall a. Num a => a -> a -> a
- t
x),t
x t -> t -> t
forall a. Num a => a -> a -> a
* (t
r t -> t -> t
forall a. Num a => a -> a -> a
- t
z) t -> t -> t
forall a. Num a => a -> a -> a
- t
y,t
x t -> t -> t
forall a. Num a => a -> a -> a
* t
y t -> t -> t
forall a. Num a => a -> a -> a
- t
b t -> t -> t
forall a. Num a => a -> a -> a
* t
z)

-- | x(n+1) = a * x(n)^2 + b * x(n) + c
quad_f :: Floating t => t -> t -> t -> t -> t
quad_f :: t -> t -> t -> t -> t
quad_f t
a t
b t
c t
x = (t
a t -> t -> t
forall a. Num a => a -> a -> a
* (t
x t -> t -> t
forall a. Floating a => a -> a -> a
** t
2)) t -> t -> t
forall a. Num a => a -> a -> a
+ (t
b t -> t -> t
forall a. Num a => a -> a -> a
* t
x) t -> t -> t
forall a. Num a => a -> a -> a
+ t
c

-- | x(n+1) = (x(n) + y(n+1)) % 2pi
--   y(n+1) = (y(n) + k * sin(x(n))) % 2pi
standard_f :: (RealFrac t, Floating t) => t -> (t, t) -> (t, t)
standard_f :: t -> (t, t) -> (t, t)
standard_f t
k (t
x,t
y) =
  let y' :: t
y' = (t
y t -> t -> t
forall a. Num a => a -> a -> a
+ (t
k t -> t -> t
forall a. Num a => a -> a -> a
* t -> t
forall a. Floating a => a -> a
sin t
x)) t -> t -> t
forall n. RealFrac n => n -> n -> n
`sc3_mod` t
forall a. Floating a => a
two_pi
  in ((t
x t -> t -> t
forall a. Num a => a -> a -> a
+ t
y') t -> t -> t
forall n. RealFrac n => n -> n -> n
`sc3_mod` t
forall a. Floating a => a
two_pi,t
y')