module Synthesizer.Plain.Builder (
T, Put, put, run,
signalToBinary, signalToBinaryMono, signalToBinaryStereo,
) where
import qualified Synthesizer.Basic.Binary as BinSmp
import Data.Monoid (Monoid, mempty, mappend, mconcat, Endo(Endo), appEndo, )
import qualified Algebra.ToInteger as ToInteger
import qualified Algebra.RealField as RealField
import qualified Prelude as P98
import NumericPrelude.Base
import NumericPrelude.Numeric
newtype T a = Cons {decons :: Endo [a]}
type Put a = a -> T a
instance Monoid (T a) where
mempty = Cons mempty
mappend x y = Cons $ decons x `mappend` decons y
put :: Put a
put = Cons . Endo . (:)
run :: T a -> [a]
run = flip appEndo [] . decons
signalToBinary ::
(BinSmp.C v, ToInteger.C int, Bounded int) =>
[v] -> [int]
signalToBinary =
run . mconcat . map (BinSmp.outputFromCanonical put)
signalToBinaryMono ::
(RealField.C a, ToInteger.C int, Bounded int) =>
[a] -> [int]
signalToBinaryMono =
map (BinSmp.fromCanonicalWith round)
signalToBinaryStereo ::
(RealField.C a, ToInteger.C int, Bounded int) =>
[(a,a)] -> [int]
signalToBinaryStereo =
concatMap (\(l,r) ->
[BinSmp.fromCanonicalWith round l,
BinSmp.fromCanonicalWith round r])