]> gitweb @ CieloNegro.org - EsounD.git/blobdiff - Sound/EsounD/Internals.hs
openPlayer should accept Nothing for the hostname
[EsounD.git] / Sound / EsounD / Internals.hs
index 4f57a3b07e694772fc507bd2590041311411e73b..8d28ed8e346bf2aefcaf54d4459e6ef085f7da9c 100644 (file)
@@ -1,5 +1,7 @@
 {-# LANGUAGE
     EmptyDataDecls
+  , FlexibleInstances
+  , MultiParamTypeClasses
   , UnicodeSyntax
   #-}
 module Sound.EsounD.Internals
@@ -8,6 +10,7 @@ module Sound.EsounD.Internals
     , Channels(..)
     , Mono
     , Stereo
+    , interleave
 
     , wrapSocket
     , closeSocket
@@ -16,6 +19,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 +40,29 @@ instance Frame Int16 where
 class Channels ch where
     channelFmt ∷ ch → C'esd_format_t
 
+-- Mono
 data Mono
+
 instance Channels Mono where
     channelFmt _ = c'ESD_MONO
 
+-- Stereo
 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
+    = 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
 wrapSocket e (-1) = fail e
 wrapSocket _ fd   = fdToHandle (Fd fd)