From 33e5d7d15bd8f124306cf4d6c706bf1b3e1b6704 Mon Sep 17 00:00:00 2001 From: PHO Date: Wed, 3 Nov 2010 15:49:50 +0900 Subject: [PATCH] Frame class and Channels class --- EsounD.cabal | 1 + Sound/EsounD.hs | 45 ++++++++++++++++++++++++++++++++++----------- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/EsounD.cabal b/EsounD.cabal index 60e1e5b..4df52be 100644 --- a/EsounD.cabal +++ b/EsounD.cabal @@ -34,6 +34,7 @@ Library Sound.EsounD Extensions: + EmptyDataDecls KindSignatures UnicodeSyntax diff --git a/Sound/EsounD.hs b/Sound/EsounD.hs index ba46305..6adeddf 100644 --- a/Sound/EsounD.hs +++ b/Sound/EsounD.hs @@ -1,43 +1,66 @@ -- | Type-safe bindings to EsounD with monadic regions. module Sound.EsounD - ( Player + ( Frame + + , Channels + , Mono + , Stereo + + , Player , openPlayer ) where +import Bindings.EsounD import Control.Monad.CatchIO import Control.Monad.Trans.Region +import Data.Int import Network import System.IO.SaferFileHandles -{- +class Frame fr where + frameFmt ∷ fr → C'esd_format_t + +instance Frame Int8 where + frameFmt _ = c'ESD_BITS8 + +instance Frame Int16 where + frameFmt _ = c'ESD_BITS16 + +class Channels ch where + channelFmt ∷ ch → C'esd_format_t + data Mono +instance Channels Mono where + channelFmt _ = c'ESD_MONO + data Stereo +instance Channels Stereo where + channelFmt _ = c'ESD_STEREO -data Recorder frame channels -data Filter frame channels -data Sampler --} -- ^ An ESD handle for playing a stream. -data Player frame channels (r ∷ * → *) +data Player fr ch (r ∷ * → *) = Player { plRate ∷ Int , plHandle ∷ RegionalFileHandle WriteMode r } -instance Dup (Player frame channels) where +instance Dup (Player fr ch) where dup pl = do h' ← dup (plHandle pl) return pl { plHandle = h' } --- ^ Open an ESD handle for playing a stream. -openPlayer ∷ MonadCatchIO pr +-- | Open an ESD handle for playing a stream. +openPlayer ∷ ( Frame fr + , Channels ch + , MonadCatchIO pr + ) ⇒ Int -- ^ sample rate for the stream. → HostName -- ^ host to connect to. → Maybe String -- ^ name used to identify this stream to -- ESD (if any). - → RegionT s pr (Player frame channels (RegionT s pr)) + → RegionT s pr (Player fr ch (RegionT s pr)) openPlayer rate host name = return Player { plRate = rate -- 2.40.0