]> gitweb @ CieloNegro.org - EsounD.git/blob - Sound/EsounD.hs
a088e9072c79e8fbac137a5250c1f1fb769d87ee
[EsounD.git] / Sound / EsounD.hs
1 -- | Type-safe bindings to EsounD with monadic regions.
2 module Sound.EsounD
3     ( Frame
4
5     , Channels
6     , Mono
7     , Stereo
8
9     , Player
10     , openPlayer
11     )
12     where
13
14 import Bindings.EsounD
15 import Control.Monad.CatchIO
16 import Control.Monad.Trans.Region
17 import Data.Bits
18 import Data.Int
19 import Network
20 import Prelude.Unicode
21 import System.IO.SaferFileHandles
22
23 class Frame fr where
24     frameFmt ∷ fr → C'esd_format_t
25
26 instance Frame Int8 where
27     frameFmt _ = c'ESD_BITS8
28
29 instance Frame Int16 where
30     frameFmt _ = c'ESD_BITS16
31
32 class Channels ch where
33     channelFmt ∷ ch → C'esd_format_t
34
35 data Mono
36 instance Channels Mono where
37     channelFmt _ = c'ESD_MONO
38
39 data Stereo
40 instance Channels Stereo where
41     channelFmt _ = c'ESD_STEREO
42
43
44 -- ^ An ESD handle for playing a stream.
45 data Player fr ch (r ∷ * → *)
46     = Player {
47         plRate   ∷ Int
48       , plHandle ∷ RegionalFileHandle WriteMode r
49       }
50
51 instance Dup (Player fr ch) where
52     dup pl
53         = do h' ← dup (plHandle pl)
54              return pl { plHandle = h' }
55
56 -- | Open an ESD handle for playing a stream.
57 openPlayer ∷ ∀ fr ch s pr.
58                ( Frame fr
59                , Channels ch
60                , MonadCatchIO pr
61                )
62            ⇒ Int          -- ^ sample rate for the stream.
63            → HostName     -- ^ host to connect to.
64            → Maybe String -- ^ name used to identify this stream to
65                            --   ESD (if any).
66            → RegionT s pr (Player fr ch (RegionT s pr))
67 openPlayer rate host name
68     = do let fmt = frameFmt   ((⊥) ∷ fr) .&.
69                    channelFmt ((⊥) ∷ ch) .&.
70                    c'ESD_STREAM            .&.
71                    c'ESD_PLAY
72          return Player {
73                       plRate   = rate
74                     , plHandle = error "FIXME: not implemented"
75                     }