{-# LANGUAGE NoImplicitPrelude #-}
module Synthesizer.State.Miscellaneous where

import qualified Synthesizer.State.Signal as Signal

import qualified Algebra.NormedSpace.Euclidean as Euc
-- import qualified Algebra.Module                as Module
-- import qualified Algebra.Transcendental        as Trans
import qualified Algebra.Field                 as Field
-- import qualified Algebra.Ring                  as Ring
-- import qualified Algebra.Additive              as Additive

-- import qualified Prelude as P
-- import PreludeBase
import NumericPrelude

{- * Spatial effects -}

{-| simulate an moving sounding object
   convert the way of the object through 3D space
   into a delay and attenuation information,
   sonicDelay is the reciprocal of the sonic velocity -}
{-# INLINE receive3Dsound #-}
receive3Dsound :: (Field.C a, Euc.C a v) =>
   a -> a -> v -> Signal.T v -> (Signal.T a,Signal.T a)
receive3Dsound att sonicDelay ear way =
   let dists   = Signal.map Euc.norm (Signal.map (subtract ear) way)
       phase   = Signal.map (sonicDelay*) dists
       volumes = Signal.map (\x -> 1/(att+x)^2) dists
   in  (phase, volumes)