base == 4.*,
base-unicode-symbols == 0.2.*,
bindings-EsounD == 0.1.*,
+ monad-peel == 0.1.*,
network == 2.3.*,
regions == 0.8.*,
safer-file-handles == 0.9.*,
Exposed-Modules:
Sound.EsounD
Sound.EsounD.Player
+ Sound.EsounD.Streams
Sound.EsounD.Types
Other-Modules:
Sound.EsounD.Internals
- Extensions:
- EmptyDataDecls
- KindSignatures
- ScopedTypeVariables
- UnicodeSyntax
-
GHC-Options:
-Wall
Main-Is: EsdPlayerExample.hs
- Extensions:
- EmptyDataDecls
- KindSignatures
- ScopedTypeVariables
- UnicodeSyntax
-
GHC-Options:
-Wall
+{-# LANGUAGE
+ EmptyDataDecls
+ , UnicodeSyntax
+ #-}
module Sound.EsounD.Internals
( Frame(..)
, withCStrOrNull
)
where
-
import Bindings.EsounD
import Data.Int
import Foreign.C.String
import Foreign.C.Types
import Foreign.Ptr
+import Foreign.Storable
import System.IO
import System.Posix.IO
import System.Posix.Types
-class Frame fr where
+class Storable fr ⇒ Frame fr where
frameFmt ∷ fr → C'esd_format_t
instance Frame Int8 where
instance Channels Stereo where
channelFmt _ = c'ESD_STEREO
-
-wrapSocket :: String -> CInt → IO Handle
+wrapSocket ∷ String → CInt → IO Handle
wrapSocket e (-1) = fail e
wrapSocket _ fd = fdToHandle (Fd fd)
-closeSocket :: Handle → IO ()
+closeSocket ∷ Handle → IO ()
closeSocket h = do (Fd fd) ← handleToFd h
_ ← c'esd_close (fromIntegral fd)
return ()
-withCStrOrNull :: Maybe String → (CString → IO a) → IO a
+withCStrOrNull ∷ Maybe String → (CString → IO a) → IO a
withCStrOrNull Nothing f = f nullPtr
withCStrOrNull (Just s) f = withCString s f
+{-# LANGUAGE
+ FlexibleInstances
+ , KindSignatures
+ , MultiParamTypeClasses
+ , UnicodeSyntax
+ , ScopedTypeVariables
+ #-}
-- | EsounD player streams.
module Sound.EsounD.Player
( Player
, openPlayer
)
where
-
import Bindings.EsounD
import Control.Monad.IO.Class
import Control.Monad.Trans.Region
import Control.Monad.Trans.Region.OnExit
import Control.Monad.Unicode
import Data.Bits
+import Data.StorableVector.Lazy as Lazy
import Foreign.C.String
import Network
import Prelude.Unicode
+import Sound.EsounD.Streams
import Sound.EsounD.Internals
import System.IO
import System.IO.SaferFileHandles.Unsafe
-- ^ An opaque ESD handle for playing a stream.
-data Player fr ch (r ∷ * → *)
+data Player fr ch (r ∷ ★ → ★)
= Player {
plRate ∷ !Int
-- THINKME: We really want to use RegionalFileHandle but we
dup pl = do ch' ← dup (plCloseH pl)
return pl { plCloseH = ch' }
+instance Frame fr ⇒ Writable (Player fr Mono) (Lazy.Vector fr) where
+ write pl v
+ = liftIO $ sanitizeIOError $ Lazy.hPut (plHandle pl) v
+
-- | Open an ESD handle for playing a stream.
openPlayer ∷ ∀fr ch s pr.
( Frame fr
--- /dev/null
+{-# LANGUAGE
+ UnicodeSyntax
+ , MultiParamTypeClasses
+ #-}
+-- | EsounD stream I/O
+module Sound.EsounD.Streams
+ ( Writable(..)
+ )
+ where
+import Control.Monad.IO.Class
+import Control.Monad.Trans.Region
+
+class Writable ws v where
+ write ∷ ( AncestorRegion pr cr
+ , MonadIO cr
+ )
+ ⇒ ws (RegionT s pr) → v → cr ()
+{-# LANGUAGE
+ UnicodeSyntax
+ #-}
module Main where
import Control.Monad.Trans.Region
import Sound.EsounD.Player
main ∷ IO ()
+main = return ()
+{-
main = runRegionT $
do pl ← openPlayer 44100 "localhost" Nothing
fail "FIXME"
-
+-}