]> gitweb @ CieloNegro.org - EsounD.git/blob - Sound/EsounD.hs
6adeddf31fcd9128694a176b6621083113a132b3
[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.Int
18 import Network
19 import System.IO.SaferFileHandles
20
21 class Frame fr where
22     frameFmt ∷ fr → C'esd_format_t
23
24 instance Frame Int8 where
25     frameFmt _ = c'ESD_BITS8
26
27 instance Frame Int16 where
28     frameFmt _ = c'ESD_BITS16
29
30 class Channels ch where
31     channelFmt ∷ ch → C'esd_format_t
32
33 data Mono
34 instance Channels Mono where
35     channelFmt _ = c'ESD_MONO
36
37 data Stereo
38 instance Channels Stereo where
39     channelFmt _ = c'ESD_STEREO
40
41
42 -- ^ An ESD handle for playing a stream.
43 data Player fr ch (r ∷ * → *)
44     = Player {
45         plRate   ∷ Int
46       , plHandle ∷ RegionalFileHandle WriteMode r
47       }
48
49 instance Dup (Player fr ch) where
50     dup pl
51         = do h' ← dup (plHandle pl)
52              return pl { plHandle = h' }
53
54 -- | Open an ESD handle for playing a stream.
55 openPlayer ∷ ( Frame fr
56               , Channels ch
57               , MonadCatchIO pr
58               )
59            ⇒ Int          -- ^ sample rate for the stream.
60            → HostName     -- ^ host to connect to.
61            → Maybe String -- ^ name used to identify this stream to
62                            --   ESD (if any).
63            → RegionT s pr (Player fr ch (RegionT s pr))
64 openPlayer rate host name
65     = return Player {
66         plRate   = rate
67       , plHandle = error "FIXME: not implemented"
68       }