{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)
-}

#define ENABLE_OVERLOADING (MIN_VERSION_haskell_gi_overloading(1,0,0) \
       && !defined(__HADDOCK_VERSION__))

module GI.GstAudio.Functions
    (

 -- * Methods
-- ** audioBufferClip #method:audioBufferClip#

    audioBufferClip                         ,


-- ** audioBufferReorderChannels #method:audioBufferReorderChannels#

    audioBufferReorderChannels              ,


-- ** audioChannelGetFallbackMask #method:audioChannelGetFallbackMask#

    audioChannelGetFallbackMask             ,


-- ** audioChannelPositionsFromMask #method:audioChannelPositionsFromMask#

    audioChannelPositionsFromMask           ,


-- ** audioChannelPositionsToMask #method:audioChannelPositionsToMask#

    audioChannelPositionsToMask             ,


-- ** audioChannelPositionsToString #method:audioChannelPositionsToString#

    audioChannelPositionsToString           ,


-- ** audioChannelPositionsToValidOrder #method:audioChannelPositionsToValidOrder#

    audioChannelPositionsToValidOrder       ,


-- ** audioCheckValidChannelPositions #method:audioCheckValidChannelPositions#

    audioCheckValidChannelPositions         ,


-- ** audioClippingMetaApiGetType #method:audioClippingMetaApiGetType#

    audioClippingMetaApiGetType             ,


-- ** audioDownmixMetaApiGetType #method:audioDownmixMetaApiGetType#

    audioDownmixMetaApiGetType              ,


-- ** audioFormatInfoGetType #method:audioFormatInfoGetType#

    audioFormatInfoGetType                  ,


-- ** audioGetChannelReorderMap #method:audioGetChannelReorderMap#

    audioGetChannelReorderMap               ,


-- ** audioIec61937FrameSize #method:audioIec61937FrameSize#

    audioIec61937FrameSize                  ,


-- ** audioIec61937Payload #method:audioIec61937Payload#

    audioIec61937Payload                    ,


-- ** audioReorderChannels #method:audioReorderChannels#

    audioReorderChannels                    ,


-- ** bufferAddAudioClippingMeta #method:bufferAddAudioClippingMeta#

    bufferAddAudioClippingMeta              ,


-- ** bufferAddAudioDownmixMeta #method:bufferAddAudioDownmixMeta#

    bufferAddAudioDownmixMeta               ,


-- ** bufferGetAudioDownmixMetaForChannels #method:bufferGetAudioDownmixMetaForChannels#

    bufferGetAudioDownmixMetaForChannels    ,




    ) where

import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P

import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP

import qualified GI.Gst.Enums as Gst.Enums
import qualified GI.Gst.Structs.Buffer as Gst.Buffer
import qualified GI.Gst.Structs.Segment as Gst.Segment
import {-# SOURCE #-} qualified GI.GstAudio.Enums as GstAudio.Enums
import {-# SOURCE #-} qualified GI.GstAudio.Structs.AudioClippingMeta as GstAudio.AudioClippingMeta
import {-# SOURCE #-} qualified GI.GstAudio.Structs.AudioDownmixMeta as GstAudio.AudioDownmixMeta
import {-# SOURCE #-} qualified GI.GstAudio.Structs.AudioRingBufferSpec as GstAudio.AudioRingBufferSpec

-- function gst_buffer_get_audio_downmix_meta_for_channels
-- Args : [Arg {argCName = "buffer", argType = TInterface (Name {namespace = "Gst", name = "Buffer"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstBuffer", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "to_position", argType = TCArray False (-1) 2 (TInterface (Name {namespace = "GstAudio", name = "AudioChannelPosition"})), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the channel positions of\n  the destination", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "to_channels", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The number of channels of the destination", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : [Arg {argCName = "to_channels", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The number of channels of the destination", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- returnType : Just (TInterface (Name {namespace = "GstAudio", name = "AudioDownmixMeta"}))
-- throws : False
-- Skip return : False

foreign import ccall "gst_buffer_get_audio_downmix_meta_for_channels" gst_buffer_get_audio_downmix_meta_for_channels ::
    Ptr Gst.Buffer.Buffer ->                -- buffer : TInterface (Name {namespace = "Gst", name = "Buffer"})
    Ptr CUInt ->                            -- to_position : TCArray False (-1) 2 (TInterface (Name {namespace = "GstAudio", name = "AudioChannelPosition"}))
    Int32 ->                                -- to_channels : TBasicType TInt
    IO (Ptr GstAudio.AudioDownmixMeta.AudioDownmixMeta)

{- |
Find the 'GI.GstAudio.Structs.AudioDownmixMeta.AudioDownmixMeta' on /@buffer@/ for the given destination
channel positions.
-}
bufferGetAudioDownmixMetaForChannels ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Gst.Buffer.Buffer
    {- ^ /@buffer@/: a 'GI.Gst.Structs.Buffer.Buffer' -}
    -> [GstAudio.Enums.AudioChannelPosition]
    {- ^ /@toPosition@/: the channel positions of
  the destination -}
    -> m GstAudio.AudioDownmixMeta.AudioDownmixMeta
    {- ^ __Returns:__ the 'GI.GstAudio.Structs.AudioDownmixMeta.AudioDownmixMeta' on /@buffer@/. -}
bufferGetAudioDownmixMetaForChannels buffer toPosition = liftIO $ do
    let toChannels = fromIntegral $ length toPosition
    buffer' <- unsafeManagedPtrGetPtr buffer
    let toPosition' = map (fromIntegral . fromEnum) toPosition
    toPosition'' <- packStorableArray toPosition'
    result <- gst_buffer_get_audio_downmix_meta_for_channels buffer' toPosition'' toChannels
    checkUnexpectedReturnNULL "bufferGetAudioDownmixMetaForChannels" result
    result' <- (newPtr GstAudio.AudioDownmixMeta.AudioDownmixMeta) result
    touchManagedPtr buffer
    freeMem toPosition''
    return result'


-- function gst_buffer_add_audio_downmix_meta
-- Args : [Arg {argCName = "buffer", argType = TInterface (Name {namespace = "Gst", name = "Buffer"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstBuffer", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "from_position", argType = TCArray False (-1) 2 (TInterface (Name {namespace = "GstAudio", name = "AudioChannelPosition"})), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the channel positions\n  of the source", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "from_channels", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The number of channels of the source", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "to_position", argType = TCArray False (-1) 4 (TInterface (Name {namespace = "GstAudio", name = "AudioChannelPosition"})), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the channel positions of\n  the destination", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "to_channels", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The number of channels of the destination", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "matrix", argType = TBasicType TFloat, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The matrix coefficients.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : [Arg {argCName = "to_channels", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The number of channels of the destination", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "from_channels", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The number of channels of the source", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- returnType : Just (TInterface (Name {namespace = "GstAudio", name = "AudioDownmixMeta"}))
-- throws : False
-- Skip return : False

foreign import ccall "gst_buffer_add_audio_downmix_meta" gst_buffer_add_audio_downmix_meta ::
    Ptr Gst.Buffer.Buffer ->                -- buffer : TInterface (Name {namespace = "Gst", name = "Buffer"})
    Ptr CUInt ->                            -- from_position : TCArray False (-1) 2 (TInterface (Name {namespace = "GstAudio", name = "AudioChannelPosition"}))
    Int32 ->                                -- from_channels : TBasicType TInt
    Ptr CUInt ->                            -- to_position : TCArray False (-1) 4 (TInterface (Name {namespace = "GstAudio", name = "AudioChannelPosition"}))
    Int32 ->                                -- to_channels : TBasicType TInt
    CFloat ->                               -- matrix : TBasicType TFloat
    IO (Ptr GstAudio.AudioDownmixMeta.AudioDownmixMeta)

{- |
Attaches 'GI.GstAudio.Structs.AudioDownmixMeta.AudioDownmixMeta' metadata to /@buffer@/ with the given parameters.

/@matrix@/ is an two-dimensional array of /@toChannels@/ times /@fromChannels@/
coefficients, i.e. the i-th output channels is constructed by multiplicating
the input channels with the coefficients in /@matrix@/[i] and taking the sum
of the results.
-}
bufferAddAudioDownmixMeta ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Gst.Buffer.Buffer
    {- ^ /@buffer@/: a 'GI.Gst.Structs.Buffer.Buffer' -}
    -> [GstAudio.Enums.AudioChannelPosition]
    {- ^ /@fromPosition@/: the channel positions
  of the source -}
    -> [GstAudio.Enums.AudioChannelPosition]
    {- ^ /@toPosition@/: the channel positions of
  the destination -}
    -> Float
    {- ^ /@matrix@/: The matrix coefficients. -}
    -> m GstAudio.AudioDownmixMeta.AudioDownmixMeta
    {- ^ __Returns:__ the 'GI.GstAudio.Structs.AudioDownmixMeta.AudioDownmixMeta' on /@buffer@/. -}
bufferAddAudioDownmixMeta buffer fromPosition toPosition matrix = liftIO $ do
    let toChannels = fromIntegral $ length toPosition
    let fromChannels = fromIntegral $ length fromPosition
    buffer' <- unsafeManagedPtrGetPtr buffer
    let fromPosition' = map (fromIntegral . fromEnum) fromPosition
    fromPosition'' <- packStorableArray fromPosition'
    let toPosition' = map (fromIntegral . fromEnum) toPosition
    toPosition'' <- packStorableArray toPosition'
    let matrix' = realToFrac matrix
    result <- gst_buffer_add_audio_downmix_meta buffer' fromPosition'' fromChannels toPosition'' toChannels matrix'
    checkUnexpectedReturnNULL "bufferAddAudioDownmixMeta" result
    result' <- (newPtr GstAudio.AudioDownmixMeta.AudioDownmixMeta) result
    touchManagedPtr buffer
    freeMem fromPosition''
    freeMem toPosition''
    return result'


-- function gst_buffer_add_audio_clipping_meta
-- Args : [Arg {argCName = "buffer", argType = TInterface (Name {namespace = "Gst", name = "Buffer"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GstBuffer", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "format", argType = TInterface (Name {namespace = "Gst", name = "Format"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "GstFormat of @start and @stop, GST_FORMAT_DEFAULT is samples", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "start", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "Amount of audio to clip from start of buffer", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "end", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "Amount of  to clip from end of buffer", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "GstAudio", name = "AudioClippingMeta"}))
-- throws : False
-- Skip return : False

foreign import ccall "gst_buffer_add_audio_clipping_meta" gst_buffer_add_audio_clipping_meta ::
    Ptr Gst.Buffer.Buffer ->                -- buffer : TInterface (Name {namespace = "Gst", name = "Buffer"})
    CUInt ->                                -- format : TInterface (Name {namespace = "Gst", name = "Format"})
    Word64 ->                               -- start : TBasicType TUInt64
    Word64 ->                               -- end : TBasicType TUInt64
    IO (Ptr GstAudio.AudioClippingMeta.AudioClippingMeta)

{- |
Attaches 'GI.GstAudio.Structs.AudioClippingMeta.AudioClippingMeta' metadata to /@buffer@/ with the given parameters.

/Since: 1.8/
-}
bufferAddAudioClippingMeta ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Gst.Buffer.Buffer
    {- ^ /@buffer@/: a 'GI.Gst.Structs.Buffer.Buffer' -}
    -> Gst.Enums.Format
    {- ^ /@format@/: GstFormat of /@start@/ and /@stop@/, GST_FORMAT_DEFAULT is samples -}
    -> Word64
    {- ^ /@start@/: Amount of audio to clip from start of buffer -}
    -> Word64
    {- ^ /@end@/: Amount of  to clip from end of buffer -}
    -> m GstAudio.AudioClippingMeta.AudioClippingMeta
    {- ^ __Returns:__ the 'GI.GstAudio.Structs.AudioClippingMeta.AudioClippingMeta' on /@buffer@/. -}
bufferAddAudioClippingMeta buffer format start end = liftIO $ do
    buffer' <- unsafeManagedPtrGetPtr buffer
    let format' = (fromIntegral . fromEnum) format
    result <- gst_buffer_add_audio_clipping_meta buffer' format' start end
    checkUnexpectedReturnNULL "bufferAddAudioClippingMeta" result
    result' <- (newPtr GstAudio.AudioClippingMeta.AudioClippingMeta) result
    touchManagedPtr buffer
    return result'


-- function gst_audio_reorder_channels
-- Args : [Arg {argCName = "data", argType = TCArray False (-1) 1 (TBasicType TUInt8), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The pointer to\n  the memory.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "size", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The size of the memory.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "format", argType = TInterface (Name {namespace = "GstAudio", name = "AudioFormat"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The %GstAudioFormat of the buffer.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "channels", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The number of channels.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "from", argType = TCArray False (-1) (-1) (TInterface (Name {namespace = "GstAudio", name = "AudioChannelPosition"})), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The channel positions in the buffer.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "to", argType = TCArray False (-1) (-1) (TInterface (Name {namespace = "GstAudio", name = "AudioChannelPosition"})), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The channel positions to convert to.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : [Arg {argCName = "size", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The size of the memory.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "gst_audio_reorder_channels" gst_audio_reorder_channels ::
    Ptr Word8 ->                            -- data : TCArray False (-1) 1 (TBasicType TUInt8)
    Word64 ->                               -- size : TBasicType TUInt64
    CUInt ->                                -- format : TInterface (Name {namespace = "GstAudio", name = "AudioFormat"})
    Int32 ->                                -- channels : TBasicType TInt
    Ptr CUInt ->                            -- from : TCArray False (-1) (-1) (TInterface (Name {namespace = "GstAudio", name = "AudioChannelPosition"}))
    Ptr CUInt ->                            -- to : TCArray False (-1) (-1) (TInterface (Name {namespace = "GstAudio", name = "AudioChannelPosition"}))
    IO CInt

{- |
Reorders /@data@/ from the channel positions /@from@/ to the channel
positions /@to@/. /@from@/ and /@to@/ must contain the same number of
positions and the same positions, only in a different order.
-}
audioReorderChannels ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    ByteString
    {- ^ /@data@/: The pointer to
  the memory. -}
    -> GstAudio.Enums.AudioFormat
    {- ^ /@format@/: The @/GstAudioFormat/@ of the buffer. -}
    -> Int32
    {- ^ /@channels@/: The number of channels. -}
    -> [GstAudio.Enums.AudioChannelPosition]
    {- ^ /@from@/: The channel positions in the buffer. -}
    -> [GstAudio.Enums.AudioChannelPosition]
    {- ^ /@to@/: The channel positions to convert to. -}
    -> m Bool
    {- ^ __Returns:__ 'True' if the reordering was possible. -}
audioReorderChannels data_ format channels from to = liftIO $ do
    let size = fromIntegral $ B.length data_
    data_' <- packByteString data_
    let format' = (fromIntegral . fromEnum) format
    let from' = map (fromIntegral . fromEnum) from
    from'' <- packStorableArray from'
    let to' = map (fromIntegral . fromEnum) to
    to'' <- packStorableArray to'
    result <- gst_audio_reorder_channels data_' size format' channels from'' to''
    let result' = (/= 0) result
    freeMem data_'
    freeMem from''
    freeMem to''
    return result'


-- function gst_audio_iec61937_payload
-- Args : [Arg {argCName = "src", argType = TCArray False (-1) 1 (TBasicType TUInt8), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a buffer containing the data to payload", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "src_n", argType = TBasicType TUInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "size of @src in bytes", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "dst", argType = TCArray False (-1) 3 (TBasicType TUInt8), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the destination buffer to store the\n      payloaded contents in. Should not overlap with @src", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "dst_n", argType = TBasicType TUInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "size of @dst in bytes", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "spec", argType = TInterface (Name {namespace = "GstAudio", name = "AudioRingBufferSpec"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the ringbufer spec for @src", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "endianness", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the expected byte order of the payloaded data", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : [Arg {argCName = "dst_n", argType = TBasicType TUInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "size of @dst in bytes", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "src_n", argType = TBasicType TUInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "size of @src in bytes", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "gst_audio_iec61937_payload" gst_audio_iec61937_payload ::
    Ptr Word8 ->                            -- src : TCArray False (-1) 1 (TBasicType TUInt8)
    Word32 ->                               -- src_n : TBasicType TUInt
    Ptr Word8 ->                            -- dst : TCArray False (-1) 3 (TBasicType TUInt8)
    Word32 ->                               -- dst_n : TBasicType TUInt
    Ptr GstAudio.AudioRingBufferSpec.AudioRingBufferSpec -> -- spec : TInterface (Name {namespace = "GstAudio", name = "AudioRingBufferSpec"})
    Int32 ->                                -- endianness : TBasicType TInt
    IO CInt

{- |
Payloads /@src@/ in the form specified by IEC 61937 for the type from /@spec@/ and
stores the result in /@dst@/. /@src@/ must contain exactly one frame of data and
the frame is not checked for errors.
-}
audioIec61937Payload ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    ByteString
    {- ^ /@src@/: a buffer containing the data to payload -}
    -> ByteString
    {- ^ /@dst@/: the destination buffer to store the
      payloaded contents in. Should not overlap with /@src@/ -}
    -> GstAudio.AudioRingBufferSpec.AudioRingBufferSpec
    {- ^ /@spec@/: the ringbufer spec for /@src@/ -}
    -> Int32
    {- ^ /@endianness@/: the expected byte order of the payloaded data -}
    -> m Bool
    {- ^ __Returns:__ transfer-full: 'True' if the payloading was successful, 'False'
otherwise. -}
audioIec61937Payload src dst spec endianness = liftIO $ do
    let dstN = fromIntegral $ B.length dst
    let srcN = fromIntegral $ B.length src
    src' <- packByteString src
    dst' <- packByteString dst
    spec' <- unsafeManagedPtrGetPtr spec
    result <- gst_audio_iec61937_payload src' srcN dst' dstN spec' endianness
    let result' = (/= 0) result
    touchManagedPtr spec
    freeMem src'
    freeMem dst'
    return result'


-- function gst_audio_iec61937_frame_size
-- Args : [Arg {argCName = "spec", argType = TInterface (Name {namespace = "GstAudio", name = "AudioRingBufferSpec"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the ringbufer spec", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUInt)
-- throws : False
-- Skip return : False

foreign import ccall "gst_audio_iec61937_frame_size" gst_audio_iec61937_frame_size ::
    Ptr GstAudio.AudioRingBufferSpec.AudioRingBufferSpec -> -- spec : TInterface (Name {namespace = "GstAudio", name = "AudioRingBufferSpec"})
    IO Word32

{- |
Calculated the size of the buffer expected by 'GI.GstAudio.Functions.audioIec61937Payload' for
payloading type from /@spec@/.
-}
audioIec61937FrameSize ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    GstAudio.AudioRingBufferSpec.AudioRingBufferSpec
    {- ^ /@spec@/: the ringbufer spec -}
    -> m Word32
    {- ^ __Returns:__ the size or 0 if the given /@type@/ is not supported or cannot be
payloaded. -}
audioIec61937FrameSize spec = liftIO $ do
    spec' <- unsafeManagedPtrGetPtr spec
    result <- gst_audio_iec61937_frame_size spec'
    touchManagedPtr spec
    return result


-- function gst_audio_get_channel_reorder_map
-- Args : [Arg {argCName = "channels", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The number of channels.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "from", argType = TCArray False (-1) (-1) (TInterface (Name {namespace = "GstAudio", name = "AudioChannelPosition"})), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The channel positions to reorder from.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "to", argType = TCArray False (-1) (-1) (TInterface (Name {namespace = "GstAudio", name = "AudioChannelPosition"})), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The channel positions to reorder to.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "reorder_map", argType = TCArray False (-1) (-1) (TBasicType TInt), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "Pointer to the reorder map.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "gst_audio_get_channel_reorder_map" gst_audio_get_channel_reorder_map ::
    Int32 ->                                -- channels : TBasicType TInt
    Ptr CUInt ->                            -- from : TCArray False (-1) (-1) (TInterface (Name {namespace = "GstAudio", name = "AudioChannelPosition"}))
    Ptr CUInt ->                            -- to : TCArray False (-1) (-1) (TInterface (Name {namespace = "GstAudio", name = "AudioChannelPosition"}))
    Ptr Int32 ->                            -- reorder_map : TCArray False (-1) (-1) (TBasicType TInt)
    IO CInt

{- |
Returns a reorder map for /@from@/ to /@to@/ that can be used in
custom channel reordering code, e.g. to convert from or to the
GStreamer channel order. /@from@/ and /@to@/ must contain the same
number of positions and the same positions, only in a
different order.

The resulting /@reorderMap@/ can be used for reordering by assigning
channel i of the input to channel reorder_map[i] of the output.
-}
audioGetChannelReorderMap ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Int32
    {- ^ /@channels@/: The number of channels. -}
    -> [GstAudio.Enums.AudioChannelPosition]
    {- ^ /@from@/: The channel positions to reorder from. -}
    -> [GstAudio.Enums.AudioChannelPosition]
    {- ^ /@to@/: The channel positions to reorder to. -}
    -> [Int32]
    {- ^ /@reorderMap@/: Pointer to the reorder map. -}
    -> m Bool
    {- ^ __Returns:__ 'True' if the channel positions are valid and reordering
is possible. -}
audioGetChannelReorderMap channels from to reorderMap = liftIO $ do
    let from' = map (fromIntegral . fromEnum) from
    from'' <- packStorableArray from'
    let to' = map (fromIntegral . fromEnum) to
    to'' <- packStorableArray to'
    reorderMap' <- packStorableArray reorderMap
    result <- gst_audio_get_channel_reorder_map channels from'' to'' reorderMap'
    let result' = (/= 0) result
    freeMem from''
    freeMem to''
    freeMem reorderMap'
    return result'


-- function gst_audio_format_info_get_type
-- Args : []
-- Lengths : []
-- returnType : Just (TBasicType TGType)
-- throws : False
-- Skip return : False

foreign import ccall "gst_audio_format_info_get_type" gst_audio_format_info_get_type ::
    IO CGType

{- |
/No description available in the introspection data./
-}
audioFormatInfoGetType ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m GType
audioFormatInfoGetType  = liftIO $ do
    result <- gst_audio_format_info_get_type
    let result' = GType result
    return result'


-- function gst_audio_downmix_meta_api_get_type
-- Args : []
-- Lengths : []
-- returnType : Just (TBasicType TGType)
-- throws : False
-- Skip return : False

foreign import ccall "gst_audio_downmix_meta_api_get_type" gst_audio_downmix_meta_api_get_type ::
    IO CGType

{- |
/No description available in the introspection data./
-}
audioDownmixMetaApiGetType ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m GType
audioDownmixMetaApiGetType  = liftIO $ do
    result <- gst_audio_downmix_meta_api_get_type
    let result' = GType result
    return result'


-- function gst_audio_clipping_meta_api_get_type
-- Args : []
-- Lengths : []
-- returnType : Just (TBasicType TGType)
-- throws : False
-- Skip return : False

foreign import ccall "gst_audio_clipping_meta_api_get_type" gst_audio_clipping_meta_api_get_type ::
    IO CGType

{- |
/No description available in the introspection data./
-}
audioClippingMetaApiGetType ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m GType
audioClippingMetaApiGetType  = liftIO $ do
    result <- gst_audio_clipping_meta_api_get_type
    let result' = GType result
    return result'


-- function gst_audio_check_valid_channel_positions
-- Args : [Arg {argCName = "position", argType = TCArray False (-1) 1 (TInterface (Name {namespace = "GstAudio", name = "AudioChannelPosition"})), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The %GstAudioChannelPositions\n  to check.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "channels", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The number of channels.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "force_order", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "Only consider the GStreamer channel order.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : [Arg {argCName = "channels", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The number of channels.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "gst_audio_check_valid_channel_positions" gst_audio_check_valid_channel_positions ::
    Ptr CUInt ->                            -- position : TCArray False (-1) 1 (TInterface (Name {namespace = "GstAudio", name = "AudioChannelPosition"}))
    Int32 ->                                -- channels : TBasicType TInt
    CInt ->                                 -- force_order : TBasicType TBoolean
    IO CInt

{- |
Checks if /@position@/ contains valid channel positions for
/@channels@/ channels. If /@forceOrder@/ is 'True' it additionally
checks if the channels are in the order required by GStreamer.
-}
audioCheckValidChannelPositions ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    [GstAudio.Enums.AudioChannelPosition]
    {- ^ /@position@/: The @/GstAudioChannelPositions/@
  to check. -}
    -> Bool
    {- ^ /@forceOrder@/: Only consider the GStreamer channel order. -}
    -> m Bool
    {- ^ __Returns:__ 'True' if the channel positions are valid. -}
audioCheckValidChannelPositions position forceOrder = liftIO $ do
    let channels = fromIntegral $ length position
    let position' = map (fromIntegral . fromEnum) position
    position'' <- packStorableArray position'
    let forceOrder' = (fromIntegral . fromEnum) forceOrder
    result <- gst_audio_check_valid_channel_positions position'' channels forceOrder'
    let result' = (/= 0) result
    freeMem position''
    return result'


-- function gst_audio_channel_positions_to_valid_order
-- Args : [Arg {argCName = "position", argType = TCArray False (-1) 1 (TInterface (Name {namespace = "GstAudio", name = "AudioChannelPosition"})), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The channel positions to\n  reorder to.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "channels", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The number of channels.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : [Arg {argCName = "channels", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The number of channels.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "gst_audio_channel_positions_to_valid_order" gst_audio_channel_positions_to_valid_order ::
    Ptr CUInt ->                            -- position : TCArray False (-1) 1 (TInterface (Name {namespace = "GstAudio", name = "AudioChannelPosition"}))
    Int32 ->                                -- channels : TBasicType TInt
    IO CInt

{- |
Reorders the channel positions in /@position@/ from any order to
the GStreamer channel order.
-}
audioChannelPositionsToValidOrder ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    [GstAudio.Enums.AudioChannelPosition]
    {- ^ /@position@/: The channel positions to
  reorder to. -}
    -> m Bool
    {- ^ __Returns:__ 'True' if the channel positions are valid and reordering
was successful. -}
audioChannelPositionsToValidOrder position = liftIO $ do
    let channels = fromIntegral $ length position
    let position' = map (fromIntegral . fromEnum) position
    position'' <- packStorableArray position'
    result <- gst_audio_channel_positions_to_valid_order position'' channels
    let result' = (/= 0) result
    freeMem position''
    return result'


-- function gst_audio_channel_positions_to_string
-- Args : [Arg {argCName = "position", argType = TCArray False (-1) 1 (TInterface (Name {namespace = "GstAudio", name = "AudioChannelPosition"})), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The %GstAudioChannelPositions\n  to convert.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "channels", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The number of channels.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : [Arg {argCName = "channels", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The number of channels.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "gst_audio_channel_positions_to_string" gst_audio_channel_positions_to_string ::
    Ptr CUInt ->                            -- position : TCArray False (-1) 1 (TInterface (Name {namespace = "GstAudio", name = "AudioChannelPosition"}))
    Int32 ->                                -- channels : TBasicType TInt
    IO CString

{- |
Converts /@position@/ to a human-readable string representation for
debugging purposes.
-}
audioChannelPositionsToString ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    [GstAudio.Enums.AudioChannelPosition]
    {- ^ /@position@/: The @/GstAudioChannelPositions/@
  to convert. -}
    -> m T.Text
    {- ^ __Returns:__ a newly allocated string representing
/@position@/

Since 1.10 -}
audioChannelPositionsToString position = liftIO $ do
    let channels = fromIntegral $ length position
    let position' = map (fromIntegral . fromEnum) position
    position'' <- packStorableArray position'
    result <- gst_audio_channel_positions_to_string position'' channels
    checkUnexpectedReturnNULL "audioChannelPositionsToString" result
    result' <- cstringToText result
    freeMem result
    freeMem position''
    return result'


-- function gst_audio_channel_positions_to_mask
-- Args : [Arg {argCName = "position", argType = TCArray False (-1) 1 (TInterface (Name {namespace = "GstAudio", name = "AudioChannelPosition"})), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The %GstAudioChannelPositions", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "channels", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The number of channels.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "force_order", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "Only consider the GStreamer channel order.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "channel_mask", argType = TBasicType TUInt64, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the output channel mask", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : [Arg {argCName = "channels", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The number of channels.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "gst_audio_channel_positions_to_mask" gst_audio_channel_positions_to_mask ::
    Ptr CUInt ->                            -- position : TCArray False (-1) 1 (TInterface (Name {namespace = "GstAudio", name = "AudioChannelPosition"}))
    Int32 ->                                -- channels : TBasicType TInt
    CInt ->                                 -- force_order : TBasicType TBoolean
    Ptr Word64 ->                           -- channel_mask : TBasicType TUInt64
    IO CInt

{- |
Convert the /@position@/ array of /@channels@/ channels to a bitmask.

If /@forceOrder@/ is 'True' it additionally checks if the channels are
in the order required by GStreamer.
-}
audioChannelPositionsToMask ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    [GstAudio.Enums.AudioChannelPosition]
    {- ^ /@position@/: The @/GstAudioChannelPositions/@ -}
    -> Bool
    {- ^ /@forceOrder@/: Only consider the GStreamer channel order. -}
    -> m ((Bool, Word64))
    {- ^ __Returns:__ 'True' if the channel positions are valid and could be converted. -}
audioChannelPositionsToMask position forceOrder = liftIO $ do
    let channels = fromIntegral $ length position
    let position' = map (fromIntegral . fromEnum) position
    position'' <- packStorableArray position'
    let forceOrder' = (fromIntegral . fromEnum) forceOrder
    channelMask <- allocMem :: IO (Ptr Word64)
    result <- gst_audio_channel_positions_to_mask position'' channels forceOrder' channelMask
    let result' = (/= 0) result
    channelMask' <- peek channelMask
    freeMem position''
    freeMem channelMask
    return (result', channelMask')


-- function gst_audio_channel_positions_from_mask
-- Args : [Arg {argCName = "channels", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The number of channels", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "channel_mask", argType = TBasicType TUInt64, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The input channel_mask", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "position", argType = TCArray False (-1) 0 (TInterface (Name {namespace = "GstAudio", name = "AudioChannelPosition"})), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The\n  %GstAudioChannelPosition<!-- -->s", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : [Arg {argCName = "channels", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The number of channels", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "gst_audio_channel_positions_from_mask" gst_audio_channel_positions_from_mask ::
    Int32 ->                                -- channels : TBasicType TInt
    Word64 ->                               -- channel_mask : TBasicType TUInt64
    Ptr CUInt ->                            -- position : TCArray False (-1) 0 (TInterface (Name {namespace = "GstAudio", name = "AudioChannelPosition"}))
    IO CInt

{- |
Convert the /@channels@/ present in /@channelMask@/ to a /@position@/ array
(which should have at least /@channels@/ entries ensured by caller).
If /@channelMask@/ is set to 0, it is considered as \'not present\' for purpose
of conversion.
A partially valid /@channelMask@/ with less bits set than the number
of channels is considered valid.
-}
audioChannelPositionsFromMask ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Word64
    {- ^ /@channelMask@/: The input channel_mask -}
    -> [GstAudio.Enums.AudioChannelPosition]
    {- ^ /@position@/: The
  @/GstAudioChannelPosition/@\<!-- -->s -}
    -> m Bool
    {- ^ __Returns:__ 'True' if channel and channel mask are valid and could be converted -}
audioChannelPositionsFromMask channelMask position = liftIO $ do
    let channels = fromIntegral $ length position
    let position' = map (fromIntegral . fromEnum) position
    position'' <- packStorableArray position'
    result <- gst_audio_channel_positions_from_mask channels channelMask position''
    let result' = (/= 0) result
    freeMem position''
    return result'


-- function gst_audio_channel_get_fallback_mask
-- Args : [Arg {argCName = "channels", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the number of channels", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUInt64)
-- throws : False
-- Skip return : False

foreign import ccall "gst_audio_channel_get_fallback_mask" gst_audio_channel_get_fallback_mask ::
    Int32 ->                                -- channels : TBasicType TInt
    IO Word64

{- |
Get the fallback channel-mask for the given number of channels.

This function returns a reasonable fallback channel-mask and should be
called as a last resort when the specific channel map is unknown.

/Since: 1.8/
-}
audioChannelGetFallbackMask ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Int32
    {- ^ /@channels@/: the number of channels -}
    -> m Word64
    {- ^ __Returns:__ a fallback channel-mask for /@channels@/ or 0 when there is no
mask and mono. -}
audioChannelGetFallbackMask channels = liftIO $ do
    result <- gst_audio_channel_get_fallback_mask channels
    return result


-- function gst_audio_buffer_reorder_channels
-- Args : [Arg {argCName = "buffer", argType = TInterface (Name {namespace = "Gst", name = "Buffer"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The buffer to reorder.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "format", argType = TInterface (Name {namespace = "GstAudio", name = "AudioFormat"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The %GstAudioFormat of the buffer.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "channels", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The number of channels.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "from", argType = TCArray False (-1) (-1) (TInterface (Name {namespace = "GstAudio", name = "AudioChannelPosition"})), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The channel positions in the buffer.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "to", argType = TCArray False (-1) (-1) (TInterface (Name {namespace = "GstAudio", name = "AudioChannelPosition"})), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The channel positions to convert to.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "gst_audio_buffer_reorder_channels" gst_audio_buffer_reorder_channels ::
    Ptr Gst.Buffer.Buffer ->                -- buffer : TInterface (Name {namespace = "Gst", name = "Buffer"})
    CUInt ->                                -- format : TInterface (Name {namespace = "GstAudio", name = "AudioFormat"})
    Int32 ->                                -- channels : TBasicType TInt
    Ptr CUInt ->                            -- from : TCArray False (-1) (-1) (TInterface (Name {namespace = "GstAudio", name = "AudioChannelPosition"}))
    Ptr CUInt ->                            -- to : TCArray False (-1) (-1) (TInterface (Name {namespace = "GstAudio", name = "AudioChannelPosition"}))
    IO CInt

{- |
Reorders /@buffer@/ from the channel positions /@from@/ to the channel
positions /@to@/. /@from@/ and /@to@/ must contain the same number of
positions and the same positions, only in a different order.
/@buffer@/ must be writable.
-}
audioBufferReorderChannels ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Gst.Buffer.Buffer
    {- ^ /@buffer@/: The buffer to reorder. -}
    -> GstAudio.Enums.AudioFormat
    {- ^ /@format@/: The @/GstAudioFormat/@ of the buffer. -}
    -> Int32
    {- ^ /@channels@/: The number of channels. -}
    -> [GstAudio.Enums.AudioChannelPosition]
    {- ^ /@from@/: The channel positions in the buffer. -}
    -> [GstAudio.Enums.AudioChannelPosition]
    {- ^ /@to@/: The channel positions to convert to. -}
    -> m Bool
    {- ^ __Returns:__ 'True' if the reordering was possible. -}
audioBufferReorderChannels buffer format channels from to = liftIO $ do
    buffer' <- unsafeManagedPtrGetPtr buffer
    let format' = (fromIntegral . fromEnum) format
    let from' = map (fromIntegral . fromEnum) from
    from'' <- packStorableArray from'
    let to' = map (fromIntegral . fromEnum) to
    to'' <- packStorableArray to'
    result <- gst_audio_buffer_reorder_channels buffer' format' channels from'' to''
    let result' = (/= 0) result
    touchManagedPtr buffer
    freeMem from''
    freeMem to''
    return result'


-- function gst_audio_buffer_clip
-- Args : [Arg {argCName = "buffer", argType = TInterface (Name {namespace = "Gst", name = "Buffer"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "The buffer to clip.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything},Arg {argCName = "segment", argType = TInterface (Name {namespace = "Gst", name = "Segment"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "Segment in %GST_FORMAT_TIME or %GST_FORMAT_DEFAULT to which\n          the buffer should be clipped.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "rate", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "sample rate.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "bpf", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "size of one audio frame in bytes. This is the size of one sample *\nnumber of channels.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gst", name = "Buffer"}))
-- throws : False
-- Skip return : False

foreign import ccall "gst_audio_buffer_clip" gst_audio_buffer_clip ::
    Ptr Gst.Buffer.Buffer ->                -- buffer : TInterface (Name {namespace = "Gst", name = "Buffer"})
    Ptr Gst.Segment.Segment ->              -- segment : TInterface (Name {namespace = "Gst", name = "Segment"})
    Int32 ->                                -- rate : TBasicType TInt
    Int32 ->                                -- bpf : TBasicType TInt
    IO (Ptr Gst.Buffer.Buffer)

{- |
Clip the buffer to the given @/GstSegment/@.

After calling this function the caller does not own a reference to
/@buffer@/ anymore.
-}
audioBufferClip ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Gst.Buffer.Buffer
    {- ^ /@buffer@/: The buffer to clip. -}
    -> Gst.Segment.Segment
    {- ^ /@segment@/: Segment in 'GI.Gst.Enums.FormatTime' or 'GI.Gst.Enums.FormatDefault' to which
          the buffer should be clipped. -}
    -> Int32
    {- ^ /@rate@/: sample rate. -}
    -> Int32
    {- ^ /@bpf@/: size of one audio frame in bytes. This is the size of one sample *
number of channels. -}
    -> m Gst.Buffer.Buffer
    {- ^ __Returns:__ 'Nothing' if the buffer is completely outside the configured segment,
otherwise the clipped buffer is returned.

If the buffer has no timestamp, it is assumed to be inside the segment and
is not clipped -}
audioBufferClip buffer segment rate bpf = liftIO $ do
    buffer' <- B.ManagedPtr.disownBoxed buffer
    segment' <- unsafeManagedPtrGetPtr segment
    result <- gst_audio_buffer_clip buffer' segment' rate bpf
    checkUnexpectedReturnNULL "audioBufferClip" result
    result' <- (wrapBoxed Gst.Buffer.Buffer) result
    touchManagedPtr buffer
    touchManagedPtr segment
    return result'