{-# OPTIONS_GHC -funbox-strict-fields -ddump-simpl-stats -O2 #-} {- -dverbose-core2core -ddump-simpl-iterations -ddump-asm -} module Main (main) where import qualified Sound.Frame.Stereo as Stereo import qualified Data.StorableVector as SV import Data.Int (Int16) import GHC.Float (float2Int, ) saw :: SV.Vector Int16 saw = fst $ SV.unfoldrN 10000000 (\x -> let y = mod (succ x) 10000 in Just (x,y)) (0::Int16) fsaw :: SV.Vector Int16 fsaw = fst $ SV.unfoldrN 10000000 (\x0 -> let frac x = x - fromIntegral (float2Int x) x1 = frac (x0+440/44100) y = 2*x0-1 in Just (fromIntegral $ float2Int (y*fromIntegral(maxBound::Int16)), x1)) (0::Float) fstereo :: SV.Vector (Stereo.T Int16) fstereo = fst $ SV.unfoldrN 10000000 (\x0 -> let frac x = x - fromIntegral (float2Int x) x1 = frac (x0+440/44100) y0 = 2*x0-1 toInt16 y = fromIntegral $ float2Int (y*fromIntegral(maxBound::Int16)) in Just (Stereo.cons (toInt16 y0) (toInt16 y0), x1)) (0::Float) fchorus :: SV.Vector (Stereo.T Int16) fchorus = fst $ SV.unfoldrN 10000000 (\(x00,x10,x20,x30) -> let frac x = x - fromIntegral (float2Int x) x01 = frac (x00+441.0/44100) x11 = frac (x10+440.5/44100) x21 = frac (x20+439.5/44100) x31 = frac (x30+439.0/44100) sawWave x = 2*x-1 yl = 0.5 * (sawWave x01 + sawWave x21) yr = 0.5 * (sawWave x11 + sawWave x31) toInt16 y = fromIntegral $ float2Int (y*fromIntegral(maxBound::Int16)) in Just (Stereo.cons (toInt16 yl) (toInt16 yr), (x01,x11,x21,x31))) (0::Float,0.25::Float,0.5::Float,0.75::Float) main :: IO () main = SV.writeFile "speed.sw" fchorus