#ifndef __FBS_PLUGOUT_ALSA__
#define __FBS_PLUGOUT_ALSA__

'  ################
' # plug-alsa.bi #
'################
' Copyright 2006-2012 by D.J.Peters (Joshy)
' d.j.peters@web.de

const EIO                     = -5  ' I/O error
const EAGAIN                  = -11 ' Try again
const EPIPE                   = -32 ' Broken pipe
const EBADFD                  = -77 ' File descriptor in bad state
const ESTRPIPE                = -86 ' Streams pipe error

const BLOCK                   = 0
const NONBLOCK                = 1
const ASYNC                   = 2

const SND_PCM_STREAM_PLAYBACK = 0
const SND_PCM_STREAM_CAPTURE  = 1

enum SND_PCM_FORMATS
  ' Signed 8 bit
  SND_PCM_FORMAT_S8 = 0
  ' Unsigned 8 bit
  SND_PCM_FORMAT_U8 = 1
  ' Signed 16 bit Little Endian 
  SND_PCM_FORMAT_S16_LE = 2
end enum

const SND_PCM_ACCESS_RW_INTERLEAVED = 3

type snd_pcm_t           as any ptr
type snd_pcm_hw_params_t as any ptr
type snd_pcm_sw_params_t as any ptr

#define DF(n) declare function n cdecl alias #n
#define DS(n) declare sub      n cdecl alias #n

' PCM
DF(snd_strerror) ( _
byval ecode    as integer) as zstring ptr

DF(snd_pcm_open) ( _
byval pcm      as snd_pcm_t ptr, _
byval device   as string       , _
byval direc    as integer      , _
byval mode     as integer) as integer

DF(snd_pcm_hw_free) ( _
byval pcm      as snd_pcm_t) as integer

DF(snd_pcm_close) ( _
byval pcm      as snd_pcm_t) as integer

DF(snd_pcm_start) ( _
byval pcm      as snd_pcm_t) as integer

DF(snd_pcm_drain) ( _
byval pcm      as snd_pcm_t) as integer

DF(snd_pcm_nonblock) ( _
byval pcm      as snd_pcm_t, _
byval nonblock as integer) as integer

DF(snd_pcm_prepare) ( _
byval pcm  as snd_pcm_t) as integer

DF(snd_pcm_writei) ( _
byval pcm      as snd_pcm_t, _
byval buffer   as any ptr  , _
byval size     as integer) as integer

DF(snd_pcm_avail_update) ( _
byval pcm      as snd_pcm_t) as integer

DF(snd_pcm_wait) ( _
byval pcm      as snd_pcm_t, _
byval msec     as integer) as integer

DF(snd_pcm_resume) ( _
byval pcm      as snd_pcm_t) as integer

'hardware
DF(snd_pcm_hw_params_malloc) ( _
byval hw       as snd_pcm_hw_params_t ptr) as integer

DF(snd_pcm_hw_params_any) ( _
byval pcm      as snd_pcm_t, _
byval hw       as snd_pcm_hw_params_t) as integer

DF(snd_pcm_hw_params_set_access) ( _
byval pcm      as snd_pcm_t          , _
byval hw       as snd_pcm_hw_params_t, _
byval mode     as integer) as integer

DF(snd_pcm_hw_params_set_format) ( _
byval pcm      as snd_pcm_t          , _
byval hw       as snd_pcm_hw_params_t, _
byval fmt      as SND_PCM_FORMATS) as integer

DF(snd_pcm_hw_params_set_channels) ( _
byval pcm      as snd_pcm_t          , _
byval hw       as snd_pcm_hw_params_t, _
byval Channels as integer) as integer

DF(snd_pcm_hw_params_get_channels) ( _
byval hw        as snd_pcm_hw_params_t, _
byval pChannels as integer ptr) as integer

DF(snd_pcm_hw_params_set_rate_near) ( _
byval pcm  as snd_pcm_t, _
byval hw   as snd_pcm_hw_params_t, _
byval pRate    as integer ptr    , _
byval pDir     as integer ptr) as integer

DF(snd_pcm_hw_params_get_periods) ( _
byval hw   as snd_pcm_hw_params_t, _
byval pValue   as integer ptr    , _
byval pDir     as integer ptr) as integer

DF(snd_pcm_hw_params_set_periods) ( _
byval pcm      as snd_pcm_t          , _
byval hw       as snd_pcm_hw_params_t, _
byval Value    as integer            , _
byval Dir      as integer) as integer

DF(snd_pcm_hw_params_set_periods_near) ( _
byval pcm      as snd_pcm_t          , _
byval hw       as snd_pcm_hw_params_t, _
byval pValue   as integer ptr        , _
byval pDir     as integer ptr) as integer

DF(snd_pcm_hw_params_set_period_size) ( _
byval pcm      as snd_pcm_t          , _
byval params   as snd_pcm_hw_params_t, _
byval nFrames  as integer            , _
byval pDir     as integer ptr) as integer

DF(snd_pcm_hw_params_get_period_size) ( _
byval params   as snd_pcm_hw_params_t, _
byval pFrames  as integer ptr        , _
byval pDir     as integer ptr) as integer

DF(snd_pcm_hw_params_set_period_size_near) ( _
byval pcm      as snd_pcm_t          , _
byval hw       as snd_pcm_hw_params_t, _
byval pValue   as integer ptr        , _
byval pDir     as integer ptr) as integer

DF(snd_pcm_hw_params_set_buffer_size) ( _
byval pcm      as snd_pcm_t          , _
byval hw       as snd_pcm_hw_params_t, _
byval Frames   as integer) as integer

DF(snd_pcm_hw_params_set_buffer_size_near) ( _
byval pcm      as snd_pcm_t          , _
byval hw       as snd_pcm_hw_params_t, _
byval pFrames  as integer ptr) as integer

DF(snd_pcm_hw_params_get_buffer_size) ( _
byval hw       as snd_pcm_hw_params_t, _
byval pFrames  as integer ptr) as integer

DF(snd_pcm_hw_params) ( _
byval pcm      as snd_pcm_t, _
byval hw       as snd_pcm_hw_params_t) as integer

DS(snd_pcm_hw_params_free) ( _
byval hw       as snd_pcm_hw_params_t)

' software
DF(snd_pcm_sw_params_malloc) ( _
byval params   as snd_pcm_sw_params_t ptr) as integer

DF(snd_pcm_sw_params_current) ( _
byval pcm      as snd_pcm_t, _
byval params   as snd_pcm_sw_params_t ptr) as integer

DF(snd_pcm_sw_params_set_avail_min) ( _
byval pcm      as snd_pcm_t          , _
byval params   as snd_pcm_sw_params_t, _
byval value    as integer) as integer

DF(snd_pcm_sw_params_set_start_threshold) ( _
byval pcm      as snd_pcm_t          ,  _
byval params   as snd_pcm_sw_params_t, _
byval value    as integer) as integer

DF(snd_pcm_sw_params) ( _
byval pcm      as snd_pcm_t, _
byval params   as snd_pcm_sw_params_t) as integer

DS(snd_pcm_sw_params_free) ( _
byval params   as snd_pcm_sw_params_t)

#inclib "asound"
#endif '__FBS_PLUGOUT_ALSA__
