Skip to content

Commit

Permalink
use Seq for accumulating samples
Browse files Browse the repository at this point in the history
  • Loading branch information
astro committed Dec 15, 2010
1 parent 7fbeae3 commit dfeed35
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src-hs/Synth.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import Data.Bits
import Data.Word
import Control.Monad.State.Lazy
import Data.List (foldl')
import Data.Sequence (Seq, (|>))
import qualified Data.Sequence as Seq
import qualified Data.Foldable as F


data ChannelState = Release | Attack | Hold
Expand Down Expand Up @@ -78,13 +81,15 @@ play s = do synth <- readIORef s
putStrLn $ "play " ++ show synth
let pulse = synthPulse synth
(synth', samples) = foldl' (\(synth, samples) _ ->
let (synth', l, r) = mix synth
in (synth', samples ++ [l, r])
) (synth, []) [1..(synthFrameSize synth)]
putStrLn $ show (length samples) ++ " samples"
simpleWrite pulse samples
writeIORef s synth'
let (synth', l, r) = {-# SCC "mix" #-} mix synth
in (synth', {-# SCC "sampleConcat" #-} samples |> l |> r)
) (synth, Seq.empty) [1..(synthFrameSize synth)]
putStrLn $ show (Seq.length samples) ++
" samples, min: " ++ show (F.minimum samples) ++
", max: " ++ show (F.maximum samples)
simpleDrain pulse
simpleWrite pulse $ F.toList samples
writeIORef s synth'

mix :: Synthesizer -> (Synthesizer, Double, Double)
mix synth = let channels = synthChannels synth
Expand Down

0 comments on commit dfeed35

Please sign in to comment.