{- | 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) = Array Int a -> (Int, Int)
forall i e. Array i e -> (i, i)
A.bounds Array Int a
c
      f :: Int -> a
f = Array Int a -> Int -> a
forall i e. Ix i => Array i e -> i -> e
(A.!) Array Int a
c
  in if Int
ix Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
l then Int -> a
f Int
l else if Int
ix Int -> Int -> Bool
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 = (Int -> Array Int a -> a) -> a -> Array Int a -> a
forall i n t.
(Integral i, RealFrac n) =>
(i -> t -> n) -> n -> t -> n
Common.Buffer.blendAtBy Int -> Array Int a -> a
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) = Array Int n -> (Int, Int)
forall i e. Array i e -> (i, i)
A.bounds Array Int n
c
      gen :: Int -> n
gen = Int -> Int -> (Int -> Array Int n -> n) -> Array Int n -> Int -> n
forall i n t.
(Integral i, RealFrac n) =>
i -> i -> (i -> t -> n) -> t -> i -> n
Common.Buffer.resamp1_gen Int
n (Int
r Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Int -> Array Int n -> n
forall a. Int -> Array Int a -> a
clipAt Array Int n
c
      rs :: [n]
rs = (Int -> n) -> [Int] -> [n]
forall a b. (a -> b) -> [a] -> [b]
map Int -> n
gen [Int
0 .. Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1]
  in (Int, Int) -> [n] -> Array Int n
forall i e. Ix i => (i, i) -> [e] -> Array i e
A.listArray (Int
0, Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) [n]
rs