module Sound.Sc3.Common.Buffer.Vector where
import qualified Data.Vector.Storable as V
import qualified Sound.Sc3.Common.Buffer as C
clipAt :: V.Storable t => Int -> V.Vector t -> t
clipAt :: forall t. Storable t => Int -> Vector t -> t
clipAt Int
ix Vector t
c =
let r :: Int
r = forall a. Storable a => Vector a -> Int
V.length Vector t
c
f :: Int -> t
f = forall a. Storable a => Vector a -> Int -> a
(V.!) Vector t
c
in if Int
ix forall a. Ord a => a -> a -> Bool
> Int
r forall a. Num a => a -> a -> a
- Int
1 then Int -> t
f (Int
r forall a. Num a => a -> a -> a
- Int
1) else Int -> t
f Int
ix
blendAt :: (V.Storable t,RealFrac t) => t -> V.Vector t -> t
blendAt :: forall t. (Storable t, RealFrac t) => t -> Vector t -> t
blendAt = forall i n t.
(Integral i, RealFrac n) =>
(i -> t -> n) -> n -> t -> n
C.blendAtBy forall t. Storable t => Int -> Vector t -> t
clipAt
from_wavetable :: (V.Storable t,Num t) => V.Vector t -> V.Vector t
from_wavetable :: forall t. (Storable t, Num t) => Vector t -> Vector t
from_wavetable Vector t
wt =
let n :: Int
n = forall a. Storable a => Vector a -> Int
V.length Vector t
wt
f :: Int -> t
f Int
k = let k2 :: Int
k2 = Int
k forall a. Num a => a -> a -> a
* Int
2 in (Vector t
wt forall a. Storable a => Vector a -> Int -> a
V.! Int
k2) forall a. Num a => a -> a -> a
+ (Vector t
wt forall a. Storable a => Vector a -> Int -> a
V.! (Int
k2 forall a. Num a => a -> a -> a
+ Int
1))
in forall a. Storable a => Int -> (Int -> a) -> Vector a
V.generate (Int
n forall a. Integral a => a -> a -> a
`div` Int
2) Int -> t
f
resamp1 :: (V.Storable t,RealFrac t) => Int -> V.Vector t -> V.Vector t
resamp1 :: forall t. (Storable t, RealFrac t) => Int -> Vector t -> Vector t
resamp1 Int
n Vector t
c =
let gen :: Int -> t
gen = forall i n t.
(Integral i, RealFrac n) =>
i -> i -> (i -> t -> n) -> t -> i -> n
C.resamp1_gen Int
n (forall a. Storable a => Vector a -> Int
V.length Vector t
c) forall t. Storable t => Int -> Vector t -> t
clipAt Vector t
c
in forall a. Storable a => Int -> (Int -> a) -> Vector a
V.generate Int
n Int -> t
gen