module Csound.Typed.Opcode.MathematicalOperations (
    
    
    -- * Arrays.
    cbrt, fmax, fmin, fmod, hypot, limit1,
    
    -- * Comparators and Accumulators.
    clear, vincr,
    
    -- * Amplitude Functions.
    ampdb, ampdbfs, dbamp, dbfsamp,
    
    -- * Random Functions.
    birnd, rnd,
    
    -- * Opcode Equivalents of Functions.
    divz, mac, maca, polynomial, pow, product', sum', taninv2) where

import Control.Monad.Trans.Class
import Control.Monad
import Csound.Dynamic
import Csound.Typed

-- Arrays.

-- | 

--
-- > ires[]  cbrt  iarg
-- > kres[]  cbrt  karg
--
-- csound doc: <https://csound.com/docs/manual/cbrt.html>
cbrt ::  D -> Sig
cbrt :: D -> Sig
cbrt D
b1 =
  GE E -> Sig
Sig (GE E -> Sig) -> GE E -> Sig
forall a b. (a -> b) -> a -> b
$ E -> E
f (E -> E) -> GE E -> GE E
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> D -> GE E
unD D
b1
  where
    f :: E -> E
f E
a1 = Name -> Spec1 -> [E] -> E
opcs Name
"cbrt" [(Rate
Ir,[Rate
Ir]),(Rate
Kr,[Rate
Kr])] [E
a1]

-- | 

--
-- > ires[]  fmax  iarg1[], iarg2[] 
-- > kres[]  fmax  karg1[], karg2[]
-- > ires[]  fmax  iarg1[], iarg2 
-- > kres[]  fmax  karg[], karg2 
--
-- csound doc: <https://csound.com/docs/manual/fmax.html>
fmax ::  D -> Sig
fmax :: D -> Sig
fmax D
b1 =
  GE E -> Sig
Sig (GE E -> Sig) -> GE E -> Sig
forall a b. (a -> b) -> a -> b
$ E -> E
f (E -> E) -> GE E -> GE E
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> D -> GE E
unD D
b1
  where
    f :: E -> E
f E
a1 = Name -> Spec1 -> [E] -> E
opcs Name
"fmax" [(Rate
Ir,[Rate
Ir,Rate
Ir]),(Rate
Kr,[Rate
Kr,Rate
Kr]),(Rate
Ir,[Rate
Ir,Rate
Ir]),(Rate
Kr,[Rate
Kr,Rate
Kr])] [E
a1]

-- | 

--
-- > ires[]  fmin  iarg1[], iarg2[] 
-- > kres[]  fmin  karg1[], karg2[]
-- > ires[]  fmin  iarg1[], iarg2 
-- > kres[]  fmin  karg[], karg2 
--
-- csound doc: <https://csound.com/docs/manual/fmin.html>
fmin ::  D -> Sig
fmin :: D -> Sig
fmin D
b1 =
  GE E -> Sig
Sig (GE E -> Sig) -> GE E -> Sig
forall a b. (a -> b) -> a -> b
$ E -> E
f (E -> E) -> GE E -> GE E
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> D -> GE E
unD D
b1
  where
    f :: E -> E
f E
a1 = Name -> Spec1 -> [E] -> E
opcs Name
"fmin" [(Rate
Ir,[Rate
Ir,Rate
Ir]),(Rate
Kr,[Rate
Kr,Rate
Kr]),(Rate
Ir,[Rate
Ir,Rate
Ir]),(Rate
Kr,[Rate
Kr,Rate
Kr])] [E
a1]

-- | 

--
-- > ires[]  fmod  iarg1[], iarg2[] 
-- > kres[]  fmod  karg1[], karg2[]
-- > ires[]  fmod  iarg1[], iarg2 
-- > kres[]  fmod  karg[], karg2 
--
-- csound doc: <https://csound.com/docs/manual/fmod.html>
fmod ::  D -> Sig
fmod :: D -> Sig
fmod D
b1 =
  GE E -> Sig
Sig (GE E -> Sig) -> GE E -> Sig
forall a b. (a -> b) -> a -> b
$ E -> E
f (E -> E) -> GE E -> GE E
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> D -> GE E
unD D
b1
  where
    f :: E -> E
f E
a1 = Name -> Spec1 -> [E] -> E
opcs Name
"fmod" [(Rate
Ir,[Rate
Ir,Rate
Ir]),(Rate
Kr,[Rate
Kr,Rate
Kr]),(Rate
Ir,[Rate
Ir,Rate
Ir]),(Rate
Kr,[Rate
Kr,Rate
Kr])] [E
a1]

-- | 

--
-- > ires[]  hypot  iarg1[], iarg2[] 
-- > kres[]  hypot  karg1[], karg2[]
--
-- csound doc: <https://csound.com/docs/manual/hypot.html>
hypot ::  D -> Sig
hypot :: D -> Sig
hypot D
b1 =
  GE E -> Sig
Sig (GE E -> Sig) -> GE E -> Sig
forall a b. (a -> b) -> a -> b
$ E -> E
f (E -> E) -> GE E -> GE E
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> D -> GE E
unD D
b1
  where
    f :: E -> E
f E
a1 = Name -> Spec1 -> [E] -> E
opcs Name
"hypot" [(Rate
Ir,[Rate
Ir,Rate
Ir]),(Rate
Kr,[Rate
Kr,Rate
Kr])] [E
a1]

-- | 

--
-- > ires[]  limit1  iarg
-- > kres[]  limit1  karg
--
-- csound doc: <https://csound.com/docs/manual/limit1.html>
limit1 ::  D -> Sig
limit1 :: D -> Sig
limit1 D
b1 =
  GE E -> Sig
Sig (GE E -> Sig) -> GE E -> Sig
forall a b. (a -> b) -> a -> b
$ E -> E
f (E -> E) -> GE E -> GE E
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> D -> GE E
unD D
b1
  where
    f :: E -> E
f E
a1 = Name -> Spec1 -> [E] -> E
opcs Name
"limit1" [(Rate
Ir,[Rate
Ir]),(Rate
Kr,[Rate
Kr])] [E
a1]

-- Comparators and Accumulators.

-- | 
-- Zeroes a list of audio signals.
--
-- clear zeroes a list of audio signals.
--
-- >  clear  avar1 [, avar2] [, avar3] [...]
-- >  clear  avar[]
--
-- csound doc: <https://csound.com/docs/manual/clear.html>
clear ::  [Sig] -> SE ()
clear :: [Sig] -> SE ()
clear [Sig]
b1 =
  Dep () -> SE ()
forall a. Dep a -> SE a
SE (Dep () -> SE ()) -> Dep () -> SE ()
forall a b. (a -> b) -> a -> b
$ DepT GE (Dep ()) -> Dep ()
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (DepT GE (Dep ()) -> Dep ()) -> DepT GE (Dep ()) -> Dep ()
forall a b. (a -> b) -> a -> b
$ [E] -> Dep ()
forall {m :: * -> *}. Monad m => [E] -> DepT m ()
f ([E] -> Dep ()) -> DepT GE [E] -> DepT GE (Dep ())
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Sig -> DepT GE E) -> [Sig] -> DepT GE [E]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (GE E -> DepT GE E
forall (m :: * -> *) a. Monad m => m a -> DepT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (GE E -> DepT GE E) -> (Sig -> GE E) -> Sig -> DepT GE E
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Sig -> GE E
unSig) [Sig]
b1
  where
    f :: [E] -> DepT m ()
f [E]
a1 = Name -> Spec1 -> [E] -> DepT m ()
forall (m :: * -> *). Monad m => Name -> Spec1 -> [E] -> DepT m ()
opcsDep_ Name
"clear" [(Rate
Xr,(Rate -> [Rate]
forall a. a -> [a]
repeat Rate
Ar))] [E]
a1

-- | 
-- Accumulates audio signals.
--
-- vincr increments one audio variable with another signal, i.e. it accumulates output.
--
-- >  vincr  accum, aincr
--
-- csound doc: <https://csound.com/docs/manual/vincr.html>
vincr ::  Sig -> Sig -> SE ()
vincr :: Sig -> Sig -> SE ()
vincr Sig
b1 Sig
b2 =
  Dep () -> SE ()
forall a. Dep a -> SE a
SE (Dep () -> SE ()) -> Dep () -> SE ()
forall a b. (a -> b) -> a -> b
$ DepT GE (Dep ()) -> Dep ()
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (DepT GE (Dep ()) -> Dep ()) -> DepT GE (Dep ()) -> Dep ()
forall a b. (a -> b) -> a -> b
$ E -> E -> Dep ()
forall {m :: * -> *}. Monad m => E -> E -> DepT m ()
f (E -> E -> Dep ()) -> DepT GE E -> DepT GE (E -> Dep ())
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (GE E -> DepT GE E
forall (m :: * -> *) a. Monad m => m a -> DepT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (GE E -> DepT GE E) -> (Sig -> GE E) -> Sig -> DepT GE E
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Sig -> GE E
unSig) Sig
b1 DepT GE (E -> Dep ()) -> DepT GE E -> DepT GE (Dep ())
forall a b. DepT GE (a -> b) -> DepT GE a -> DepT GE b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (GE E -> DepT GE E
forall (m :: * -> *) a. Monad m => m a -> DepT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (GE E -> DepT GE E) -> (Sig -> GE E) -> Sig -> DepT GE E
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Sig -> GE E
unSig) Sig
b2
  where
    f :: E -> E -> DepT m ()
f E
a1 E
a2 = Name -> Spec1 -> [E] -> DepT m ()
forall (m :: * -> *). Monad m => Name -> Spec1 -> [E] -> DepT m ()
opcsDep_ Name
"vincr" [(Rate
Xr,[Rate
Ar,Rate
Ar])] [E
a1,E
a2]

-- Amplitude Functions.

-- | 
-- Returns the amplitude equivalent of the decibel value x.
--
-- Returns the amplitude equivalent of the decibel value x. Thus:
--
-- >  ampdb (x)  (no rate restriction)
--
-- csound doc: <https://csound.com/docs/manual/ampdb.html>
ampdb :: SigOrD a => a -> a
ampdb :: forall a. SigOrD a => a -> a
ampdb a
b1 =
  GE E -> a
forall a. Val a => GE E -> a
fromGE (GE E -> a) -> GE E -> a
forall a b. (a -> b) -> a -> b
$ E -> E
f (E -> E) -> GE E -> GE E
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> GE E
forall a. Val a => a -> GE E
toGE a
b1
  where
    f :: E -> E
f E
a1 = Name -> E -> E
opr1 Name
"ampdb" E
a1

-- | 
-- Returns the amplitude equivalent (in 16-bit signed integer scale) of the full scale decibel (dB FS) value x.
--
-- Returns the amplitude equivalent of the full scale decibel (dB FS) value x. The logarithmic full scale decibel values will be converted to linear 16-bit signed integer values from −32,768 to +32,767.
--
-- >  ampdbfs (x)  (no rate restriction)
--
-- csound doc: <https://csound.com/docs/manual/ampdbfs.html>
ampdbfs :: SigOrD a => a -> a
ampdbfs :: forall a. SigOrD a => a -> a
ampdbfs a
b1 =
  GE E -> a
forall a. Val a => GE E -> a
fromGE (GE E -> a) -> GE E -> a
forall a b. (a -> b) -> a -> b
$ E -> E
f (E -> E) -> GE E -> GE E
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> GE E
forall a. Val a => a -> GE E
toGE a
b1
  where
    f :: E -> E
f E
a1 = Name -> E -> E
opr1 Name
"ampdbfs" E
a1

-- | 
-- Returns the decibel equivalent of the raw amplitude x.
--
-- >  dbamp (x)  (init-rate or control-rate args only)
--
-- csound doc: <https://csound.com/docs/manual/dbamp.html>
dbamp :: SigOrD a => a -> a
dbamp :: forall a. SigOrD a => a -> a
dbamp a
b1 =
  GE E -> a
forall a. Val a => GE E -> a
fromGE (GE E -> a) -> GE E -> a
forall a b. (a -> b) -> a -> b
$ E -> E
f (E -> E) -> GE E -> GE E
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> GE E
forall a. Val a => a -> GE E
toGE a
b1
  where
    f :: E -> E
f E
a1 = Name -> E -> E
opr1k Name
"dbamp" E
a1

-- | 
-- Returns the decibel equivalent of the raw amplitude x, relative to full scale amplitude.
--
-- Returns the decibel equivalent of the raw amplitude x, relative to full scale amplitude. Full scale is assumed to be 16 bit. New is Csound version 4.10.
--
-- >  dbfsamp (x)  (init-rate or control-rate args only)
--
-- csound doc: <https://csound.com/docs/manual/dbfsamp.html>
dbfsamp :: SigOrD a => a -> a
dbfsamp :: forall a. SigOrD a => a -> a
dbfsamp a
b1 =
  GE E -> a
forall a. Val a => GE E -> a
fromGE (GE E -> a) -> GE E -> a
forall a b. (a -> b) -> a -> b
$ E -> E
f (E -> E) -> GE E -> GE E
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> GE E
forall a. Val a => a -> GE E
toGE a
b1
  where
    f :: E -> E
f E
a1 = Name -> E -> E
opr1k Name
"dbfsamp" E
a1

-- Random Functions.

-- | 
-- Returns a random number in a bi-polar range.
--
-- >  birnd (x) (init- or control-rate only)
--
-- csound doc: <https://csound.com/docs/manual/birnd.html>
birnd :: SigOrD a => a -> SE a
birnd :: forall a. SigOrD a => a -> SE a
birnd a
b1 =
  (E -> a) -> SE E -> SE a
forall a b. (a -> b) -> SE a -> SE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ( GE E -> a
forall a. Val a => GE E -> a
fromGE (GE E -> a) -> (E -> GE E) -> E -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. E -> GE E
forall a. a -> GE a
forall (m :: * -> *) a. Monad m => a -> m a
return) (SE E -> SE a) -> SE E -> SE a
forall a b. (a -> b) -> a -> b
$ DepT GE E -> SE E
forall a. Dep a -> SE a
SE (DepT GE E -> SE E) -> DepT GE E -> SE E
forall a b. (a -> b) -> a -> b
$ DepT GE (DepT GE E) -> DepT GE E
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (DepT GE (DepT GE E) -> DepT GE E)
-> DepT GE (DepT GE E) -> DepT GE E
forall a b. (a -> b) -> a -> b
$ E -> DepT GE E
forall {m :: * -> *}. Monad m => E -> DepT m E
f (E -> DepT GE E) -> DepT GE E -> DepT GE (DepT GE E)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (GE E -> DepT GE E
forall (m :: * -> *) a. Monad m => m a -> DepT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (GE E -> DepT GE E) -> (a -> GE E) -> a -> DepT GE E
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> GE E
forall a. Val a => a -> GE E
toGE) a
b1
  where
    f :: E -> DepT m E
f E
a1 = Name -> E -> DepT m E
forall (m :: * -> *). Monad m => Name -> E -> DepT m E
opr1kDep Name
"birnd" E
a1

-- | 
-- Returns a random number in a unipolar range at the rate given by the input argument.
--
-- >  rnd (x) (init- or control-rate only)
--
-- csound doc: <https://csound.com/docs/manual/rnd.html>
rnd :: SigOrD a => a -> SE a
rnd :: forall a. SigOrD a => a -> SE a
rnd a
b1 =
  (E -> a) -> SE E -> SE a
forall a b. (a -> b) -> SE a -> SE b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ( GE E -> a
forall a. Val a => GE E -> a
fromGE (GE E -> a) -> (E -> GE E) -> E -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. E -> GE E
forall a. a -> GE a
forall (m :: * -> *) a. Monad m => a -> m a
return) (SE E -> SE a) -> SE E -> SE a
forall a b. (a -> b) -> a -> b
$ DepT GE E -> SE E
forall a. Dep a -> SE a
SE (DepT GE E -> SE E) -> DepT GE E -> SE E
forall a b. (a -> b) -> a -> b
$ DepT GE (DepT GE E) -> DepT GE E
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (DepT GE (DepT GE E) -> DepT GE E)
-> DepT GE (DepT GE E) -> DepT GE E
forall a b. (a -> b) -> a -> b
$ E -> DepT GE E
forall {m :: * -> *}. Monad m => E -> DepT m E
f (E -> DepT GE E) -> DepT GE E -> DepT GE (DepT GE E)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (GE E -> DepT GE E
forall (m :: * -> *) a. Monad m => m a -> DepT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (GE E -> DepT GE E) -> (a -> GE E) -> a -> DepT GE E
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> GE E
forall a. Val a => a -> GE E
toGE) a
b1
  where
    f :: E -> DepT m E
f E
a1 = Name -> E -> DepT m E
forall (m :: * -> *). Monad m => Name -> E -> DepT m E
opr1kDep Name
"rnd" E
a1

-- Opcode Equivalents of Functions.

-- | 
-- Safely divides two numbers.
--
-- > ares  divz  xa, xb, ksubst
-- > ires  divz  ia, ib, isubst
-- > kres  divz  ka, kb, ksubst
-- > ... divz (ka, kb, ksubst)... (no rate restriction)
--
-- csound doc: <https://csound.com/docs/manual/divz.html>
divz :: SigOrD a => a -> a -> a
divz :: forall a. SigOrD a => a -> a -> a
divz a
b1 a
b2 =
  GE E -> a
forall a. Val a => GE E -> a
fromGE (GE E -> a) -> GE E -> a
forall a b. (a -> b) -> a -> b
$ E -> E -> E
f (E -> E -> E) -> GE E -> GE (E -> E)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> GE E
forall a. Val a => a -> GE E
toGE a
b1 GE (E -> E) -> GE E -> GE E
forall a b. GE (a -> b) -> GE a -> GE b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> GE E
forall a. Val a => a -> GE E
toGE a
b2
  where
    f :: E -> E -> E
f E
a1 E
a2 = Name -> Spec1 -> [E] -> E
opcs Name
"divz" [(Rate
Ar,[Rate
Xr,Rate
Xr]),(Rate
Kr,[Rate
Kr,Rate
Kr]),(Rate
Ir,[Rate
Ir,Rate
Ir])] [E
a1,E
a2]

-- | 
-- Multiplies and accumulates a- and k-rate signals.
--
-- > ares  mac  ksig1, asig1 [, ksig2] [, asig2] [, ksig3] [, asig3] [...]
--
-- csound doc: <https://csound.com/docs/manual/mac.html>
mac ::  [Sig] -> Sig
mac :: [Sig] -> Sig
mac [Sig]
b1 =
  GE E -> Sig
Sig (GE E -> Sig) -> GE E -> Sig
forall a b. (a -> b) -> a -> b
$ [E] -> E
f ([E] -> E) -> GE [E] -> GE E
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Sig -> GE E) -> [Sig] -> GE [E]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Sig -> GE E
unSig [Sig]
b1
  where
    f :: [E] -> E
f [E]
a1 = Name -> Spec1 -> [E] -> E
opcs Name
"mac" [(Rate
Ar,[Rate
Kr,Rate
Ar,Rate
Kr,Rate
Ar,Rate
Kr] [Rate] -> [Rate] -> [Rate]
forall a. [a] -> [a] -> [a]
++ (Rate -> [Rate]
forall a. a -> [a]
repeat Rate
Ar))] [E]
a1

-- | 
-- Multiply and accumulate a-rate signals only.
--
-- > ares  maca  asig1 , asig2 [, asig3] [, asig4] [, asig5] [...]
--
-- csound doc: <https://csound.com/docs/manual/maca.html>
maca ::  [Sig] -> Sig
maca :: [Sig] -> Sig
maca [Sig]
b1 =
  GE E -> Sig
Sig (GE E -> Sig) -> GE E -> Sig
forall a b. (a -> b) -> a -> b
$ [E] -> E
f ([E] -> E) -> GE [E] -> GE E
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Sig -> GE E) -> [Sig] -> GE [E]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Sig -> GE E
unSig [Sig]
b1
  where
    f :: [E] -> E
f [E]
a1 = Name -> Spec1 -> [E] -> E
opcs Name
"maca" [(Rate
Ar,(Rate -> [Rate]
forall a. a -> [a]
repeat Rate
Ar))] [E]
a1

-- | 
-- Efficiently evaluates a polynomial of arbitrary order.
--
-- The polynomial opcode calculates a polynomial with a single a-rate input variable.  The polynomial is a sum of any number of terms in the form kn*x^n where kn is the nth coefficient of the expression.  These coefficients are k-rate values.
--
-- > aout  polynomial  ain, k0 [, k1 [, k2 [...]]]
--
-- csound doc: <https://csound.com/docs/manual/polynomial.html>
polynomial ::  Sig -> [Sig] -> Sig
polynomial :: Sig -> [Sig] -> Sig
polynomial Sig
b1 [Sig]
b2 =
  GE E -> Sig
Sig (GE E -> Sig) -> GE E -> Sig
forall a b. (a -> b) -> a -> b
$ E -> [E] -> E
f (E -> [E] -> E) -> GE E -> GE ([E] -> E)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Sig -> GE E
unSig Sig
b1 GE ([E] -> E) -> GE [E] -> GE E
forall a b. GE (a -> b) -> GE a -> GE b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Sig -> GE E) -> [Sig] -> GE [E]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Sig -> GE E
unSig [Sig]
b2
  where
    f :: E -> [E] -> E
f E
a1 [E]
a2 = Name -> Spec1 -> [E] -> E
opcs Name
"polynomial" [(Rate
Ar,[Rate
Ar] [Rate] -> [Rate] -> [Rate]
forall a. [a] -> [a] -> [a]
++ (Rate -> [Rate]
forall a. a -> [a]
repeat Rate
Kr))] ([E
a1] [E] -> [E] -> [E]
forall a. [a] -> [a] -> [a]
++ [E]
a2)

-- | 
-- Computes one argument to the power of another argument.
--
-- Computes xarg to the power of kpow (or ipow) and scales the result by inorm.
--
-- > ares  pow  aarg, kpow [, inorm]
-- > ires  pow  iarg, ipow [, inorm]
-- > kres  pow  karg, kpow [, inorm]
-- > ires[]  pow  iarg[], ipow[] 
-- > kres[]  pow  karg[], kpow[]
-- > ires[]  pow  iarg[], ipow 
-- > kres[]  pow  karg[], kpow 
--
-- csound doc: <https://csound.com/docs/manual/pow.html>
pow ::  Sig -> Sig -> Sig
pow :: Sig -> Sig -> Sig
pow Sig
b1 Sig
b2 =
  GE E -> Sig
Sig (GE E -> Sig) -> GE E -> Sig
forall a b. (a -> b) -> a -> b
$ E -> E -> E
f (E -> E -> E) -> GE E -> GE (E -> E)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Sig -> GE E
unSig Sig
b1 GE (E -> E) -> GE E -> GE E
forall a b. GE (a -> b) -> GE a -> GE b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Sig -> GE E
unSig Sig
b2
  where
    f :: E -> E -> E
f E
a1 E
a2 = Name -> Spec1 -> [E] -> E
opcs Name
"pow" [(Rate
Ar,[Rate
Ar,Rate
Kr,Rate
Ir])
                         ,(Rate
Ir,[Rate
Ir,Rate
Ir,Rate
Ir])
                         ,(Rate
Kr,[Rate
Kr,Rate
Kr,Rate
Ir])
                         ,(Rate
Ir,[Rate
Ir,Rate
Ir])
                         ,(Rate
Kr,[Rate
Kr,Rate
Kr])
                         ,(Rate
Ir,[Rate
Ir,Rate
Ir])
                         ,(Rate
Kr,[Rate
Kr,Rate
Kr])] [E
a1,E
a2]

-- | 
-- Multiplies any number of a-rate signals.
--
-- > ares  product  asig1, asig2 [, asig3] [...]
--
-- csound doc: <https://csound.com/docs/manual/product.html>
product' ::  [Sig] -> Sig
product' :: [Sig] -> Sig
product' [Sig]
b1 =
  GE E -> Sig
Sig (GE E -> Sig) -> GE E -> Sig
forall a b. (a -> b) -> a -> b
$ [E] -> E
f ([E] -> E) -> GE [E] -> GE E
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Sig -> GE E) -> [Sig] -> GE [E]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Sig -> GE E
unSig [Sig]
b1
  where
    f :: [E] -> E
f [E]
a1 = Name -> Spec1 -> [E] -> E
opcs Name
"product" [(Rate
Ar,(Rate -> [Rate]
forall a. a -> [a]
repeat Rate
Ar))] [E]
a1

-- | 
-- Sums any number of a-rate signals, or array elements.
--
-- > ares  sum  asig1 [, asig2] [, asig3] [...]
-- > kres  sum  karr
-- > ires  sum  iarr
--
-- csound doc: <https://csound.com/docs/manual/sum.html>
sum' ::  [Sig] -> Sig
sum' :: [Sig] -> Sig
sum' [Sig]
b1 =
  GE E -> Sig
Sig (GE E -> Sig) -> GE E -> Sig
forall a b. (a -> b) -> a -> b
$ [E] -> E
f ([E] -> E) -> GE [E] -> GE E
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Sig -> GE E) -> [Sig] -> GE [E]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Sig -> GE E
unSig [Sig]
b1
  where
    f :: [E] -> E
f [E]
a1 = Name -> Spec1 -> [E] -> E
opcs Name
"sum" [(Rate
Ar,(Rate -> [Rate]
forall a. a -> [a]
repeat Rate
Ar)),(Rate
Kr,[Rate
Kr]),(Rate
Ir,[Rate
Ir])] [E]
a1

-- | 
-- Returns an arctangent.
--
-- Returns the arctangent of iy/ix, ky/kx, or ay/ax.
--
-- > ares  taninv2  ay, ax
-- > ires  taninv2  iy, ix
-- > kres  taninv2  ky, kx
-- > ... taninv2 (ky, kx)... (no rate restriction)
--
-- csound doc: <https://csound.com/docs/manual/taninv2.html>
taninv2 :: SigOrD a => a -> a -> a
taninv2 :: forall a. SigOrD a => a -> a -> a
taninv2 a
b1 a
b2 =
  GE E -> a
forall a. Val a => GE E -> a
fromGE (GE E -> a) -> GE E -> a
forall a b. (a -> b) -> a -> b
$ E -> E -> E
f (E -> E -> E) -> GE E -> GE (E -> E)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> GE E
forall a. Val a => a -> GE E
toGE a
b1 GE (E -> E) -> GE E -> GE E
forall a b. GE (a -> b) -> GE a -> GE b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> GE E
forall a. Val a => a -> GE E
toGE a
b2
  where
    f :: E -> E -> E
f E
a1 E
a2 = Name -> Spec1 -> [E] -> E
opcs Name
"taninv2" [(Rate
Ar,[Rate
Ar,Rate
Ar]),(Rate
Kr,[Rate
Kr,Rate
Kr]),(Rate
Ir,[Rate
Ir,Rate
Ir])] [E
a1,E
a2]