1 module Sound.EsounD.Internals
14 import Bindings.EsounD
16 import Foreign.C.String
17 import Foreign.C.Types
20 import System.Posix.IO
21 import System.Posix.Types
24 frameFmt ∷ fr → C'esd_format_t
26 instance Frame Int8 where
27 frameFmt _ = c'ESD_BITS8
29 instance Frame Int16 where
30 frameFmt _ = c'ESD_BITS16
32 class Channels ch where
33 channelFmt ∷ ch → C'esd_format_t
36 instance Channels Mono where
37 channelFmt _ = c'ESD_MONO
40 instance Channels Stereo where
41 channelFmt _ = c'ESD_STEREO
44 wrapSocket :: String -> CInt → IO Handle
45 wrapSocket e (-1) = fail e
46 wrapSocket _ fd = fdToHandle (Fd fd)
48 closeSocket :: Handle → IO ()
49 closeSocket h = do (Fd fd) ← handleToFd h
50 _ ← c'esd_close (fromIntegral fd)
53 withCStrOrNull :: Maybe String → (CString → IO a) → IO a
54 withCStrOrNull Nothing f = f nullPtr
55 withCStrOrNull (Just s) f = withCString s f