5 module Sound.EsounD.Internals
17 import Bindings.EsounD
19 import Foreign.C.String
20 import Foreign.C.Types
22 import Foreign.Storable
24 import System.Posix.IO
25 import System.Posix.Types
27 class Storable fr ⇒ Frame fr where
28 frameFmt ∷ fr → C'esd_format_t
30 instance Frame Int8 where
31 frameFmt _ = c'ESD_BITS8
33 instance Frame Int16 where
34 frameFmt _ = c'ESD_BITS16
36 class Channels ch where
37 channelFmt ∷ ch → C'esd_format_t
40 instance Channels Mono where
41 channelFmt _ = c'ESD_MONO
44 instance Channels Stereo where
45 channelFmt _ = c'ESD_STEREO
47 wrapSocket ∷ String → CInt → IO Handle
48 wrapSocket e (-1) = fail e
49 wrapSocket _ fd = fdToHandle (Fd fd)
51 closeSocket ∷ Handle → IO ()
52 closeSocket h = do (Fd fd) ← handleToFd h
53 _ ← c'esd_close (fromIntegral fd)
56 withCStrOrNull ∷ Maybe String → (CString → IO a) → IO a
57 withCStrOrNull Nothing f = f nullPtr
58 withCStrOrNull (Just s) f = withCString s f