module Codec.Audio.FLAC.StreamDecoder.Internal
( withDecoder
, decoderSetMd5Checking
, decoderGetState
, decoderGetBlockSize
, decoderProcessSingle
, decoderProcessUntilEndOfMetadata
, decoderFinish )
where
import Codec.Audio.FLAC.StreamDecoder.Internal.Types
import Codec.Audio.FLAC.Util
import Control.Monad.Catch
import Data.Word
import Foreign.C.Types
withDecoder :: (Decoder -> IO a) -> IO a
withDecoder f = bracket decoderNew (mapM_ decoderDelete) $ \mdecoder ->
case mdecoder of
Nothing -> throwM
(DecoderFailed DecoderStateMemoryAllocationError)
Just x -> f x
decoderNew :: IO (Maybe Decoder)
decoderNew = maybePtr <$> c_decoder_new
foreign import ccall unsafe "FLAC__stream_decoder_new"
c_decoder_new :: IO Decoder
decoderDelete :: Decoder -> IO ()
decoderDelete = c_decoder_delete
foreign import ccall unsafe "FLAC__stream_decoder_delete"
c_decoder_delete :: Decoder -> IO ()
decoderSetMd5Checking :: Decoder -> Bool -> IO Bool
decoderSetMd5Checking = c_decoder_set_md5_checking
foreign import ccall unsafe "FLAC__stream_decoder_set_md5_checking"
c_decoder_set_md5_checking :: Decoder -> Bool -> IO Bool
decoderGetState :: Decoder -> IO DecoderState
decoderGetState = fmap toEnum' . c_decoder_get_state
foreign import ccall unsafe "FLAC__stream_decoder_get_state"
c_decoder_get_state :: Decoder -> IO CUInt
decoderGetBlockSize :: Decoder -> IO Word32
decoderGetBlockSize = fmap fromIntegral . c_decoder_get_blocksize
foreign import ccall unsafe "FLAC__stream_decoder_get_blocksize"
c_decoder_get_blocksize :: Decoder -> IO CUInt
decoderProcessSingle :: Decoder -> IO Bool
decoderProcessSingle = c_decoder_process_single
foreign import ccall unsafe "FLAC__stream_decoder_process_single"
c_decoder_process_single :: Decoder -> IO Bool
decoderProcessUntilEndOfMetadata :: Decoder -> IO Bool
decoderProcessUntilEndOfMetadata = c_decoder_process_until_end_of_metadata
foreign import ccall unsafe "FLAC__stream_decoder_process_until_end_of_metadata"
c_decoder_process_until_end_of_metadata :: Decoder -> IO Bool
decoderFinish :: Decoder -> IO Bool
decoderFinish = c_decoder_finish
foreign import ccall unsafe "FLAC__stream_decoder_finish"
c_decoder_finish :: Decoder -> IO Bool