EmptyDataDecls
, FlexibleInstances
, MultiParamTypeClasses
- , TypeFamilies
, UnicodeSyntax
#-}
module Sound.EsounD.Internals
, Channels(..)
, Mono
, Stereo
-
- , Mux(..)
+ , interleave
, wrapSocket
, closeSocket
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')
+interleave ∷ Frame fr ⇒ L.Vector fr → L.Vector fr → L.Vector fr
+interleave l r
+ -- THINKME: consider using storablevector-streamfusion
+ = let Just (lFr, l') = L.viewL l
+ Just (rFr, r') = L.viewL r
+ lr' = interleave l' r'
+ in
+ L.cons lFr (L.cons rFr lr')
-- Utility functions
wrapSocket ∷ String → CInt → IO Handle
, MultiParamTypeClasses
, UnicodeSyntax
, ScopedTypeVariables
- , TypeFamilies
#-}
-- | EsounD player streams.
module Sound.EsounD.Player
dup pl = do ch' ← dup (plCloseH pl)
return pl { plCloseH = ch' }
-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)
+instance Frame fr ⇒ Writable (Player fr Mono) (L.Vector fr) where
+ write pl v
+ = liftIO $ sanitizeIOError $ L.hPut (plHandle pl) v
+
+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)
-- | Open an ESD handle for playing a stream.
openPlayer ∷ ∀fr ch s pr.
-- | EsounD stream I/O
module Sound.EsounD.Streams
( Writable(..)
- , Mux(..) -- defined by Internals
)
where
import Control.Monad.IO.Class
import Control.Monad.Trans.Region
-import Sound.EsounD.Internals
class Writable ws dvec where
write ∷ ( AncestorRegion pr cr