module Sound.ALSA.PCM.Node.File (
Handle,
Time, SampleFreq, Size,
Class.SampleFmt,
open, close,
read, write,
) where
import qualified Sound.ALSA.PCM.Core.Class as Class
import Sound.ALSA.PCM.Parameters.Hardware (Time, SampleFreq, Size, )
import Sound.ALSA.PCM.Core.Handle (arraySize, )
import Control.Monad (liftM, )
import Foreign.Ptr (Ptr, )
import qualified System.IO as IO
import System.IO (IOMode, openBinaryFile, )
import Prelude hiding (read, )
newtype Handle y = Handle IO.Handle
open ::
(Class.SampleFmt y) =>
IOMode -> FilePath -> IO (Handle y)
open mode path =
fmap Handle $ openBinaryFile path mode
close ::
(Class.SampleFmt y) =>
Handle y -> IO ()
close (Handle h) =
IO.hClose h
read ::
(Class.SampleFmt y) =>
Handle y -> Ptr y -> Size -> IO Size
read (Handle h) buf n =
liftM fromIntegral $
liftM (`div` arraySize buf 1) $
IO.hGetBuf h buf (arraySize buf (fromIntegral n))
write ::
(Class.SampleFmt y) =>
Handle y -> Ptr y -> Size -> IO ()
write (Handle h) buf n =
IO.hPutBuf h buf (arraySize buf (fromIntegral n))