#ifndef __alconsole_h_
#define __alconsole_h_

#include "../al.h"

#ifdef _XBOX
#include <xtl.h>
#include <x3daudio.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif

#if defined(_WIN32) && !defined(_XBOX)
 /* _OPENAL32LIB is deprecated */
 #if defined(AL_BUILD_LIBRARY) || defined (_OPENAL32LIB)
  #define AL_API __declspec(dllexport)
 #else
  #define AL_API __declspec(dllimport)
 #endif
#else
 #define AL_API extern
#endif

#if defined(_WIN32)
 #define AL_APIENTRY __cdecl
#else
 #define AL_APIENTRY
#endif

#if TARGET_OS_MAC
 #pragma export on
#endif

/* The OPENAL, ALAPI, and ALAPIENTRY macros are deprecated, but are included for applications porting code
   from AL 1.0 */
#define OPENAL
#define ALAPI AL_API
#define ALAPIENTRY AL_APIENTRY


/**
 * Context definitions to be used with alcCreateContext.
 */
#define ALC_CONSOLE_MAJOR_VERSION       0x30001
#define ALC_CONSOLE_MINOR_VERSION       0x30002

/**
 * Memory overriding definitions
 */
typedef void*   ( *ALMEMALLOCFN )		( ALuint cbSize );
typedef void    ( *ALMEMFREEFN )		( ALvoid* pvMem );

/**
 * XMA Decoder callback function definitions
 */
typedef void    ( *ALXMAERRORFN )       ( ALuint Status, ALuint Source, ALuint Buffer );

/**
 * X3DAudioCalc override function
 *
 * iUserData allows the source to pass user-defined meta-data to the callback, for example to help identity a specific voice.
 */

#ifdef _XBOX
typedef void    ( *ALX3DAUDIOCALCFN )   (   const X3DAUDIO_HANDLE Instance,         // X3DAudio instance
                                            const ALint iUserData,                  // User-defined token
                                            const X3DAUDIO_LISTENER *pListener,     // XAudio structs
                                            const X3DAUDIO_EMITTER *pEmitter,
                                            unsigned int Flags,       
                                            X3DAUDIO_DSP_SETTINGS *pDSPSettings );  // Speaker coefficients
#endif


#ifndef AL_NO_PROTOTYPES

/* Set the custom memory allocation functions to use */
ALAPI void ALAPIENTRY alMemoryAllocFns( ALMEMALLOCFN pAllocFn, ALMEMFREEFN pFreeFn ); 

/* Configure buffer data through a format-defined parameter descriptor */
ALAPI void ALAPIENTRY alBufferDataDesc( ALuint buffer, ALenum format, const ALvoid* pDesc, const ALvoid* data, ALsizei size ); 

/* Configure buffer data, pointing to actual memory to source data from */
ALAPI void ALAPIENTRY alBufferDataStatic( ALuint buffer, ALenum format, const ALvoid* data, ALsizei size, ALsizei freq );

/* Configure buffer data through a format-defined parameter descriptor, pointing to actual memory to source data from */
ALAPI void ALAPIENTRY alBufferDataDescStatic( ALuint buffer, ALenum format, const ALvoid* pDesc, const ALvoid* data, ALsizei size );

/* Flag a source as playing background music (XAudio can then auto-silence when game-player overrides game music) */
ALAPI void ALAPIENTRY alSourceSetTypeMusic( ALuint source, ALboolean bMusic );

/* Flag a source as ZERO CENTER (see X3DAUDIO_CALCULATE_ZEROCENTER) */
ALAPI void ALAPIENTRY alSourceSetZeroCenter( ALuint source, ALboolean bCenter );

/* Set XAudio threading */
ALAPI void ALAPIENTRY alSetXAudioThreadUsage( ALuint flags );

/* Set XMA Decoder error detection callback */
ALAPI void ALAPIENTRY alSetXMAErrorCallback( ALXMAERRORFN pXMAErrorFn );

#ifdef _XBOX
/* Set the custom 3D calculation function to use in place of X3DAudioCalculate */
ALAPI void ALAPIENTRY alSetX3DAudioCalcFn( ALX3DAUDIOCALCFN pCalcFn );
#endif

#else /* AL_NO_PROTOTYPES */

/* Set the custom memory allocation functions to use */
void        (*alMemAllocFns)            ( ALMEMALLOCFN pAllocFn, ALMEMFREEFN pFreeFn ); 

/* Configure buffer data through a format-defined parameter descriptor */
void        (*alBufferDataDesc)         ( ALuint buffer, ALenum format, const ALvoid* pDesc, const ALvoid* data, ALsizei size );

/* Configure buffer data, pointing to actual memory to source data from */
void        (*alBufferDataStatic)       ( ALuint buffer, ALenum format, const ALvoid* data, ALsizei size, ALsizei freq );

/* Configure buffer data through a format-defined parameter descriptor, pointing to actual memory to source data from */
void        (*alBufferDataDescStatic)   ( ALuint buffer, ALenum format, const ALvoid* pDesc, const ALvoid* data, ALsizei size );

/* Flag a source as playing background music (XAudio can then auto-silence when game-player overrides game music) */
void        (*alSourceSetTypeMusic)     ( ALuint source, ALboolean bMusic );

/* Flag a source as ZERO CENTER (see X3DAUDIO_CALCULATE_ZEROCENTER) */
void		(*alSourceSetZeroCenter)	( ALuint source, ALboolean bCenter );

/* Set XAudio threading */
void		(*alSetXAudioThreadUsage)	( ALuint flags );

/* Set XMA Decoder error detection callback */
void        (*alSetXMAErrorCallback)    ( ALXMAERRORFN pXMAErrorFn );

#ifdef _XBOX
/* Set the custom 3D calculation function to use in place of X3DAudioCalculate */
void        (*alSetX3DAudioCalcFn)      ( ALX3DAUDIOCALCFN pCalcFn );
#endif

#endif /* AL_NO_PROTOTYPES */


#ifdef TARGET_OS_MAC
#if TARGET_OS_MAC
#pragma export off
#endif /* TARGET_OS_MAC */
#endif /* TARGET_OS_MAC */


#ifdef __cplusplus
}  /* extern "C" */
#endif

#endif /* __alconsole_h_ */
