From: PHO Date: Fri, 31 Dec 2010 20:20:14 +0000 (+0900) Subject: save my changes from being lost X-Git-Tag: RELEASE-0.1~14 X-Git-Url: https://git.cielonegro.org/gitweb.cgi?a=commitdiff_plain;h=8af725c0cc839ad2493fa17d29ca6becaeb9f600;p=EsounD.git save my changes from being lost --- diff --git a/Sound/EsounD/Internals.hs b/Sound/EsounD/Internals.hs index 4f57a3b..4c45036 100644 --- a/Sound/EsounD/Internals.hs +++ b/Sound/EsounD/Internals.hs @@ -1,5 +1,8 @@ {-# LANGUAGE EmptyDataDecls + , FlexibleInstances + , MultiParamTypeClasses + , TypeFamilies , UnicodeSyntax #-} module Sound.EsounD.Internals @@ -9,6 +12,8 @@ module Sound.EsounD.Internals , Mono , Stereo + , Mux(..) + , wrapSocket , closeSocket , withCStrOrNull @@ -16,6 +21,7 @@ module Sound.EsounD.Internals where import Bindings.EsounD import Data.Int +import Data.StorableVector.Lazy as L import Foreign.C.String import Foreign.C.Types import Foreign.Ptr @@ -36,14 +42,39 @@ instance Frame Int16 where class Channels ch where channelFmt ∷ ch → C'esd_format_t +class (Frame fr, Channels ch) ⇒ Mux (vec ∷ ★ → ★) fr ch where + type DemuxedVec vec fr ch + mux ∷ DemuxedVec vec fr ch → vec fr + +-- Mono data Mono + instance Channels Mono where channelFmt _ = c'ESD_MONO +instance Frame fr ⇒ Mux vec fr Mono where + type DemuxedVec vec fr Mono = vec fr + mux = id + +-- Stereo data Stereo + instance Channels Stereo where channelFmt _ = c'ESD_STEREO +instance Frame fr ⇒ Mux L.Vector fr Stereo where + type DemuxedVec L.Vector fr Stereo = (L.Vector fr, L.Vector fr) + mux (left, right) = loop left right + where + -- THINKME: consider using storablevector-streamfusion + loop l r + = let Just (lFr, l') = L.viewL l + Just (rFr, r') = L.viewL r + lr' = loop l' r' + in + L.cons lFr (L.cons rFr lr') + +-- Utility functions wrapSocket ∷ String → CInt → IO Handle wrapSocket e (-1) = fail e wrapSocket _ fd = fdToHandle (Fd fd) diff --git a/Sound/EsounD/Player.hs b/Sound/EsounD/Player.hs index 0525a7b..7691672 100644 --- a/Sound/EsounD/Player.hs +++ b/Sound/EsounD/Player.hs @@ -1,9 +1,11 @@ {-# LANGUAGE - FlexibleInstances + FlexibleContexts + , FlexibleInstances , KindSignatures , MultiParamTypeClasses , UnicodeSyntax , ScopedTypeVariables + , TypeFamilies #-} -- | EsounD player streams. module Sound.EsounD.Player @@ -17,11 +19,11 @@ 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 Data.StorableVector.Lazy as L import Foreign.C.String import Network import Prelude.Unicode -import Sound.EsounD.Streams +import Sound.EsounD.Streams import Sound.EsounD.Internals import System.IO import System.IO.SaferFileHandles.Unsafe @@ -42,9 +44,9 @@ instance Dup (Player fr ch) where 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 +instance (Mux L.Vector fr ch, dvec ~ DemuxedVec L.Vector fr ch) ⇒ Writable (Player fr ch) dvec where + write pl dvec + = liftIO $ sanitizeIOError $ L.hPut (plHandle pl) (mux dvec) -- | Open an ESD handle for playing a stream. openPlayer ∷ ∀fr ch s pr. diff --git a/Sound/EsounD/Streams.hs b/Sound/EsounD/Streams.hs index 2be218e..b379afb 100644 --- a/Sound/EsounD/Streams.hs +++ b/Sound/EsounD/Streams.hs @@ -4,14 +4,16 @@ #-} -- | EsounD stream I/O module Sound.EsounD.Streams - ( Writable(..) + ( Writable(..) + , Mux(..) -- defined by Internals ) where -import Control.Monad.IO.Class +import Control.Monad.IO.Class import Control.Monad.Trans.Region +import Sound.EsounD.Internals -class Writable ws v where +class Writable ws dvec where write ∷ ( AncestorRegion pr cr , MonadIO cr ) - ⇒ ws (RegionT s pr) → v → cr () + ⇒ ws (RegionT s pr) → dvec → cr ()