{- | Array variants of "Sound.Sc3.Common.Buffer".
These functions have the same names as the plain forms and are not re-exported by "Sound.Sc3.Common".
-}
module Sound.Sc3.Common.Buffer.Array where

import qualified Data.Array as A {- array -}

import qualified Sound.Sc3.Common.Buffer as  Common.Buffer {- hsc3 -}

-- | 'Common.Buffer.clipAt'.
clipAt :: Int -> A.Array Int a -> a
clipAt :: forall a. Int -> Array Int a -> a
clipAt Int
ix Array Int a
c =
    let (Int
l,Int
r) = forall i e. Array i e -> (i, i)
A.bounds Array Int a
c
        f :: Int -> a
f = forall i e. Ix i => Array i e -> i -> e
(A.!) Array Int a
c
    in if Int
ix forall a. Ord a => a -> a -> Bool
< Int
l then Int -> a
f Int
l else if Int
ix forall a. Ord a => a -> a -> Bool
> Int
r then Int -> a
f Int
r else Int -> a
f Int
ix

{- | 'C.blendAtBy' of 'clipAt'.

> Sound.Sc3.Common.Buffer.Array.blendAt 0 (A.listArray (0,2) [2,5,6]) == 2
> Sound.Sc3.Common.Buffer.Array.blendAt 0.4 (A.listArray (0,2) [2,5,6]) == 3.2
-}
blendAt :: RealFrac a => a -> A.Array Int a -> a
blendAt :: forall a. RealFrac a => a -> Array Int a -> a
blendAt = forall i n t.
(Integral i, RealFrac n) =>
(i -> t -> n) -> n -> t -> n
Common.Buffer.blendAtBy forall a. Int -> Array Int a -> a
clipAt

{- | 'C.resamp1'.

> Sound.Sc3.Common.Buffer.Array.resamp1 12 (A.listArray (0,3) [1,2,3,4])
> Sound.Sc3.Common.Buffer.Array.resamp1 3 (A.listArray (0,3) [1,2,3,4]) == A.listArray (0,2) [1,2.5,4]
-}
resamp1 :: RealFrac n => Int -> A.Array Int n -> A.Array Int n
resamp1 :: forall n. RealFrac n => Int -> Array Int n -> Array Int n
resamp1 Int
n Array Int n
c =
    let (Int
_,Int
r) = forall i e. Array i e -> (i, i)
A.bounds Array Int n
c
        gen :: Int -> n
gen = forall i n t.
(Integral i, RealFrac n) =>
i -> i -> (i -> t -> n) -> t -> i -> n
Common.Buffer.resamp1_gen Int
n (Int
r forall a. Num a => a -> a -> a
+ Int
1) forall a. Int -> Array Int a -> a
clipAt Array Int n
c
        rs :: [n]
rs = forall a b. (a -> b) -> [a] -> [b]
map Int -> n
gen [Int
0 .. Int
n forall a. Num a => a -> a -> a
- Int
1]
    in forall i e. Ix i => (i, i) -> [e] -> Array i e
A.listArray (Int
0,Int
n forall a. Num a => a -> a -> a
- Int
1) [n]
rs