4 , MultiParamTypeClasses
7 module Sound.EsounD.Internals
20 import Bindings.EsounD
22 import Data.StorableVector.Lazy as L
23 import Foreign.C.String
24 import Foreign.C.Types
26 import Foreign.Storable
28 import System.Posix.IO
29 import System.Posix.Types
31 class Storable fr ⇒ Frame fr where
32 frameFmt ∷ fr → C'esd_format_t
34 instance Frame Int8 where
35 frameFmt _ = c'ESD_BITS8
37 instance Frame Int16 where
38 frameFmt _ = c'ESD_BITS16
40 class Channels ch where
41 channelFmt ∷ ch → C'esd_format_t
46 instance Channels Mono where
47 channelFmt _ = c'ESD_MONO
52 instance Channels Stereo where
53 channelFmt _ = c'ESD_STEREO
55 interleave ∷ Frame fr ⇒ L.Vector fr → L.Vector fr → L.Vector fr
57 -- THINKME: consider using storablevector-streamfusion
58 = let Just (lFr, l') = L.viewL l
59 Just (rFr, r') = L.viewL r
60 lr' = interleave l' r'
62 L.cons lFr (L.cons rFr lr')
65 wrapSocket ∷ String → CInt → IO Handle
66 wrapSocket e (-1) = fail e
67 wrapSocket _ fd = fdToHandle (Fd fd)
69 closeSocket ∷ Handle → IO ()
70 closeSocket h = do (Fd fd) ← handleToFd h
71 _ ← c'esd_close (fromIntegral fd)
74 withCStrOrNull ∷ Maybe String → (CString → IO a) → IO a
75 withCStrOrNull Nothing f = f nullPtr
76 withCStrOrNull (Just s) f = withCString s f