X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=EsounD.git;a=blobdiff_plain;f=Sound%2FEsounD%2FInternals.hs;h=4c450361571e15fd54e7c14ce562f056c0d84b08;hp=4f57a3b07e694772fc507bd2590041311411e73b;hb=8af725c0cc839ad2493fa17d29ca6becaeb9f600;hpb=2c9350d4762d69bbfcdc58212e27506c3d4f7494 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)