X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Sound%2FEsounD%2FPlayer.hs;h=4d3c719cdf9fe09cd527da7a32e370bc68d1bb45;hb=fe6d90865e38cb96fa33610c1b38d0e8fc86d1e9;hp=7f7eb223a88ddb2c593c7dfd695b58a2076c7f9d;hpb=d6ea0404a5d1fc5356a5b121b45f277d735359ad;p=EsounD.git diff --git a/Sound/EsounD/Player.hs b/Sound/EsounD/Player.hs index 7f7eb22..4d3c719 100644 --- a/Sound/EsounD/Player.hs +++ b/Sound/EsounD/Player.hs @@ -13,7 +13,9 @@ module Sound.EsounD.Player ) where import Bindings.EsounD +import Control.Exception.Control import Control.Monad.IO.Class +import Control.Monad.IO.Control import Control.Monad.Trans.Region import Control.Monad.Trans.Region.OnExit import Control.Monad.Unicode @@ -25,7 +27,7 @@ import Sound.EsounD.Streams import Sound.EsounD.Internals import System.IO import System.IO.SaferFileHandles.Unsafe - +import Text.Printf -- ^ An opaque ESD handle for playing a stream. data Player fr ch (r ∷ ★ → ★) @@ -42,27 +44,37 @@ instance Dup (Player fr ch) where dup pl = do ch' ← dup (plCloseH pl) return pl { plCloseH = ch' } -instance Frame fr ⇒ Writable (Player fr Mono) (L.Vector fr) where - write pl v - = liftIO $ sanitizeIOError $ L.hPut (plHandle pl) v +instance Stream (Player fr ch) where + streamSampleRate = plRate + +instance Frame fr ⇒ WritableStream (Player fr Mono) (L.Vector fr) where + writeFrames pl v + = liftIO $ + sanitizeIOError $ + do L.hPut (plHandle pl) v + hFlush (plHandle pl) -instance Frame fr ⇒ Writable (Player fr Stereo) (L.Vector fr, L.Vector fr) where - write pl (l, r) - = liftIO $ sanitizeIOError $ L.hPut (plHandle pl) (interleave l r) +instance Frame fr ⇒ WritableStream (Player fr Stereo) (L.Vector fr, L.Vector fr) where + writeFrames pl (l, r) + = liftIO $ + sanitizeIOError $ + do L.hPut (plHandle pl) (interleave l r) + hFlush (plHandle pl) -- | Open an ESD handle for playing a stream. openPlayer ∷ ∀fr ch s pr. - ( Frame fr - , Channels ch - , MonadIO pr - ) + ( Frame fr + , Channels ch + , MonadControlIO pr + ) ⇒ Int -- ^ sample rate for the stream. → Maybe HostName -- ^ host to connect to. → Maybe String -- ^ name used to identify this stream to -- ESD (if any). → RegionT s pr (Player fr ch (RegionT s pr)) openPlayer rate host name - = do h ← liftIO openSocket + = mask_ $ + do h ← liftIO openSocket ch ← onExit $ sanitizeIOError $ closeSocket h return Player { plRate = rate @@ -85,13 +97,9 @@ openPlayer rate host name hostPtr namePtr ≫= wrapSocket - ( "esd_play_stream(" - ⧺ show fmt - ⧺ ", " - ⧺ show rate - ⧺ ", " - ⧺ show host - ⧺ ", " - ⧺ show name - ⧺ ") returned an error" + ( printf "esd_play_stream(%s, %s, %s, %s) returned an error" + (show fmt ) + (show rate) + (show host) + (show name) )