From d6ea0404a5d1fc5356a5b121b45f277d735359ad Mon Sep 17 00:00:00 2001 From: PHO Date: Sat, 1 Jan 2011 17:07:55 +0900 Subject: [PATCH] openPlayer should accept Nothing for the hostname --- Sound/EsounD/Internals.hs | 1 + Sound/EsounD/Player.hs | 29 +++++++++++++++++++---------- examples/EsdPlayerExample.hs | 15 +++++++++------ 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/Sound/EsounD/Internals.hs b/Sound/EsounD/Internals.hs index ef8c659..8d28ed8 100644 --- a/Sound/EsounD/Internals.hs +++ b/Sound/EsounD/Internals.hs @@ -52,6 +52,7 @@ data Stereo instance Channels Stereo where channelFmt _ = c'ESD_STEREO +{-# INLINE interleave #-} interleave ∷ Frame fr ⇒ L.Vector fr → L.Vector fr → L.Vector fr interleave l r -- THINKME: consider using storablevector-streamfusion diff --git a/Sound/EsounD/Player.hs b/Sound/EsounD/Player.hs index cfb4e31..7f7eb22 100644 --- a/Sound/EsounD/Player.hs +++ b/Sound/EsounD/Player.hs @@ -19,7 +19,6 @@ import Control.Monad.Trans.Region.OnExit import Control.Monad.Unicode import Data.Bits import Data.StorableVector.Lazy as L -import Foreign.C.String import Network import Prelude.Unicode import Sound.EsounD.Streams @@ -57,10 +56,10 @@ openPlayer ∷ ∀fr ch s pr. , Channels ch , MonadIO pr ) - ⇒ Int -- ^ sample rate for the stream. - → HostName -- ^ host to connect to. - → Maybe String -- ^ name used to identify this stream to - -- ESD (if any). + ⇒ 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 @@ -72,17 +71,27 @@ openPlayer rate host name } where fmt :: C'esd_format_t - fmt = frameFmt ((⊥) ∷ fr) .&. - channelFmt ((⊥) ∷ ch) .&. - c'ESD_STREAM .&. + fmt = frameFmt ((⊥) ∷ fr) .|. + channelFmt ((⊥) ∷ ch) .|. + c'ESD_STREAM .|. c'ESD_PLAY openSocket :: IO Handle - openSocket = withCString host $ \hostPtr → + openSocket = withCStrOrNull host $ \hostPtr → withCStrOrNull name $ \namePtr → c'esd_play_stream fmt (fromIntegral rate) hostPtr namePtr - ≫= wrapSocket "esd_play_stream() returned an error" + ≫= wrapSocket + ( "esd_play_stream(" + ⧺ show fmt + ⧺ ", " + ⧺ show rate + ⧺ ", " + ⧺ show host + ⧺ ", " + ⧺ show name + ⧺ ") returned an error" + ) diff --git a/examples/EsdPlayerExample.hs b/examples/EsdPlayerExample.hs index 1d3ec4f..1083e8b 100644 --- a/examples/EsdPlayerExample.hs +++ b/examples/EsdPlayerExample.hs @@ -3,12 +3,15 @@ #-} module Main where import Control.Monad.Trans.Region -import Sound.EsounD.Player +import Data.Int +import Sound.EsounD.Player +import Sound.EsounD.Types main ∷ IO () -main = return () -{- main = runRegionT $ - do pl ← openPlayer 44100 "localhost" Nothing - fail "FIXME" --} + do pl ← openPlayer 44100 Nothing Nothing + playMono16Sine pl + +playMono16Sine ∷ Monad m ⇒ Player Int16 Mono m → m () +playMono16Sine pl + = fail "FIXME" -- 2.40.0