openal.bac

'
' OpenAL definitions based on OpenAL 1.1.
'
' Ported to BaCon INCLUDE file by Peter van Eerten - MIT License 2016.
'
' Version 1.0: Initial release
' Version 1.1: Added 'alc' functions and constants
' Version 1.2: Adjusted variable names to 'AL_' prefix
' Version 1.3: Added functions to open, print and close sound device (API below)
'
'-----------------------------------------------------------------------------------
'
' OPENAL_INIT
'  => Initialize OpenAL on default sound device
'
' OPENAL_INFO
'  => Print some information about the OpenAL version
'
' OPENAL_FREE
'  => Free allocated resources for OpenAL
'
'-----------------------------------------------------------------------------------
' al.h
'-----------------------------------------------------------------------------------

AL_lib$ = "libopenal.so.0"
AL_seq = -1

CATCH GOTO lib_import_retry

LABEL lib_import_retry
    INCR AL_seq
    IF AL_seq > 100 THEN
        PRINT "No OpenAL library found! Exiting."
        END 1
    ENDIF
    AL_lib$ = LEFT$(AL_lib$, INSTRREV(AL_lib$, ".")) & STR$(AL_seq)

IMPORT "alGetString(int)" FROM AL_lib$ TYPE char* ALIAS alGetString$

CATCH RESET

CONST AL_INVALID = (-1)
CONST AL_NONE = 0
CONST AL_FALSE = 0
CONST AL_TRUE = 1
CONST AL_SOURCE_RELATIVE = 0x202
CONST AL_CONE_INNER_ANGLE = 0x1001
CONST AL_CONE_OUTER_ANGLE = 0x1002
CONST AL_PITCH = 0x1003
CONST AL_POSITION = 0x1004
CONST AL_DIRECTION = 0x1005
CONST AL_VELOCITY = 0x1006
CONST AL_LOOPING = 0x1007
CONST AL_BUFFER = 0x1009
CONST AL_GAIN = 0x100A
CONST AL_MIN_GAIN = 0x100D
CONST AL_MAX_GAIN = 0x100E
CONST AL_ORIENTATION = 0x100F
CONST AL_SOURCE_STATE = 0x1010
CONST AL_INITIAL = 0x1011
CONST AL_PLAYING = 0x1012
CONST AL_PAUSED = 0x1013
CONST AL_STOPPED = 0x1014
CONST AL_BUFFERS_QUEUED = 0x1015
CONST AL_BUFFERS_PROCESSED = 0x1016
CONST AL_SEC_OFFSET = 0x1024
CONST AL_SAMPLE_OFFSET = 0x1025
CONST AL_BYTE_OFFSET = 0x1026
CONST AL_SOURCE_TYPE = 0x1027
CONST AL_STATIC = 0x1028
CONST AL_STREAMING = 0x1029
CONST AL_UNDETERMINED = 0x1030
CONST AL_FORMAT_MONO8 = 0x1100
CONST AL_FORMAT_MONO16 = 0x1101
CONST AL_FORMAT_STEREO8 = 0x1102
CONST AL_FORMAT_STEREO16 = 0x1103
CONST AL_REFERENCE_DISTANCE = 0x1020
CONST AL_ROLLOFF_FACTOR = 0x1021
CONST AL_CONE_OUTER_GAIN = 0x1022
CONST AL_MAX_DISTANCE = 0x1023
CONST AL_FREQUENCY = 0x2001
CONST AL_BITS = 0x2002
CONST AL_CHANNELS = 0x2003
CONST AL_SIZE = 0x2004
CONST AL_UNUSED = 0x2010
CONST AL_PENDING = 0x2011
CONST AL_PROCESSED = 0x2012
CONST AL_NO_ERROR = 0
CONST AL_INVALID_NAME = 0xA001
CONST AL_INVALID_ENUM = 0xA002
CONST AL_INVALID_VALUE = 0xA003
CONST AL_INVALID_OPERATION = 0xA004
CONST AL_OUT_OF_MEMORY = 0xA005
CONST AL_VENDOR = 0xB001
CONST AL_VERSION = 0xB002
CONST AL_RENDERER = 0xB003
CONST AL_EXTENSIONS = 0xB004
CONST AL_DOPPLER_FACTOR = 0xC000
CONST AL_DOPPLER_VELOCITY = 0xC001
CONST AL_SPEED_OF_SOUND = 0xC003
CONST AL_DISTANCE_MODEL = 0xD000
CONST AL_INVERSE_DISTANCE = 0xD001
CONST AL_INVERSE_DISTANCE_CLAMPED = 0xD002
CONST AL_LINEAR_DISTANCE = 0xD003
CONST AL_LINEAR_DISTANCE_CLAMPED = 0xD004
CONST AL_EXPONENT_DISTANCE = 0xD005
CONST AL_EXPONENT_DISTANCE_CLAMPED = 0xD006

IMPORT "alEnable(int)" FROM AL_lib$ TYPE void
IMPORT "alDisable(int)" FROM AL_lib$ TYPE void
IMPORT "alIsEnabled(int)" FROM AL_lib$ TYPE int
IMPORT "alGetBooleanv(int,void*)" FROM AL_lib$ TYPE void
IMPORT "alGetIntegerv(int,void*)" FROM AL_lib$ TYPE void
IMPORT "alGetFloatv(int,void*)" FROM AL_lib$ TYPE void
IMPORT "alGetDoublev(int,void*)" FROM AL_lib$ TYPE void
IMPORT "alGetBoolean(int)" FROM AL_lib$ TYPE int
IMPORT "alGetInteger(int)" FROM AL_lib$ TYPE int
IMPORT "alGetFloat(int)" FROM AL_lib$ TYPE float
IMPORT "alGetDouble(int)" FROM AL_lib$ TYPE double
IMPORT "alGetError(void)" FROM AL_lib$ TYPE int
IMPORT "alIsExtensionPresent(char*)" FROM AL_lib$ TYPE int
IMPORT "alGetProcAddress(char*)" FROM AL_lib$ TYPE void*
IMPORT "alGetEnumValue(char*)" FROM AL_lib$ TYPE int
IMPORT "alListenerf(int,float)" FROM AL_lib$ TYPE void
IMPORT "alListener3f(int,float,float,float)" FROM AL_lib$ TYPE void
IMPORT "alListenerfv(int,void*)" FROM AL_lib$ TYPE void
IMPORT "alListeneri(int,int)" FROM AL_lib$ TYPE void
IMPORT "alListener3i(int,int,int,int)" FROM AL_lib$ TYPE void
IMPORT "alListeneriv(int,void*)" FROM AL_lib$ TYPE void
IMPORT "alGetListenerf(int,void*)" FROM AL_lib$ TYPE void
IMPORT "alGetListener3f(int,void*,void*,void*)" FROM AL_lib$ TYPE void
IMPORT "alGetListenerfv(int,void*)" FROM AL_lib$ TYPE void
IMPORT "alGetListeneri(int,void*)" FROM AL_lib$ TYPE void
IMPORT "alGetListener3i(int,void*,void*,void*)" FROM AL_lib$ TYPE void
IMPORT "alGetListeneriv(int,void*)" FROM AL_lib$ TYPE void
IMPORT "alGenSources(int,void*)" FROM AL_lib$ TYPE void
IMPORT "alDeleteSources(int,void*)" FROM AL_lib$ TYPE void
IMPORT "alIsSource(int)" FROM AL_lib$ TYPE int
IMPORT "alSourcef(int,int,float)" FROM AL_lib$ TYPE void
IMPORT "alSource3f(int,int,float,float,float)" FROM AL_lib$ TYPE void
IMPORT "alSourcefv(int,int,void*)" FROM AL_lib$ TYPE void
IMPORT "alSourcei(int,int,int)" FROM AL_lib$ TYPE void
IMPORT "alSource3i(int,int,int,int,int)" FROM AL_lib$ TYPE void
IMPORT "alSourceiv(int,int,void*)" FROM AL_lib$ TYPE void
IMPORT "alGetSourcef(int,int,void*)" FROM AL_lib$ TYPE void
IMPORT "alGetSource3f(int,int,void*,void*,void*)" FROM AL_lib$ TYPE void
IMPORT "alGetSourcefv(int,int,void*)" FROM AL_lib$ TYPE void
IMPORT "alGetSourcei(int,int,void*)" FROM AL_lib$ TYPE void
IMPORT "alGetSource3i(int,int,void*,void*,void*)" FROM AL_lib$ TYPE void
IMPORT "alGetSourceiv(int,int,void*)" FROM AL_lib$ TYPE void
IMPORT "alSourcePlayv(int,void*)" FROM AL_lib$ TYPE void
IMPORT "alSourceStopv(int,void*)" FROM AL_lib$ TYPE void
IMPORT "alSourceRewindv(int,void*)" FROM AL_lib$ TYPE void
IMPORT "alSourcePausev(int,void*)" FROM AL_lib$ TYPE void
IMPORT "alSourcePlay(int)" FROM AL_lib$ TYPE void
IMPORT "alSourceStop(int)" FROM AL_lib$ TYPE void
IMPORT "alSourceRewind(int)" FROM AL_lib$ TYPE void
IMPORT "alSourcePause(int)" FROM AL_lib$ TYPE void
IMPORT "alSourceQueueBuffers(int,int,void*)" FROM AL_lib$ TYPE void
IMPORT "alSourceUnqueueBuffers(int,int,void*)" FROM AL_lib$ TYPE void
IMPORT "alGenBuffers(int,void*)" FROM AL_lib$ TYPE void
IMPORT "alDeleteBuffers(int,void*)" FROM AL_lib$ TYPE void
IMPORT "alIsBuffer(int)" FROM AL_lib$ TYPE int
IMPORT "alBufferData(int,int,void*,int,int)" FROM AL_lib$ TYPE void
IMPORT "alBufferf(int,int,float)" FROM AL_lib$ TYPE void
IMPORT "alBuffer3f(int,int,float,float,float)" FROM AL_lib$ TYPE void
IMPORT "alBufferfv(int,int,void*)" FROM AL_lib$ TYPE void
IMPORT "alBufferi(int,int,int)" FROM AL_lib$ TYPE void
IMPORT "alBuffer3i(int,int,int,int,int)" FROM AL_lib$ TYPE void
IMPORT "alBufferiv(int,int,void*)" FROM AL_lib$ TYPE void
IMPORT "alGetBufferf(int,int,void*)" FROM AL_lib$ TYPE void
IMPORT "alGetBuffer3f(int,int,void*,void*,void*)" FROM AL_lib$ TYPE void
IMPORT "alGetBufferfv(int,int,void*)" FROM AL_lib$ TYPE void
IMPORT "alGetBufferi(int,int,void*)" FROM AL_lib$ TYPE void
IMPORT "alGetBuffer3i(int,int,void*,void*,void*)" FROM AL_lib$ TYPE void
IMPORT "alGetBufferiv(int,int,void*)" FROM AL_lib$ TYPE void
IMPORT "alDopplerFactor(float)" FROM AL_lib$ TYPE void
IMPORT "alDopplerVelocity(float)" FROM AL_lib$ TYPE void
IMPORT "alSpeedOfSound(float)" FROM AL_lib$ TYPE void
IMPORT "alDistanceModel(int)" FROM AL_lib$ TYPE void

'-----------------------------------------------------------------------------------

' alc.h

CONST ALC_FALSE = 0
CONST ALC_TRUE = 1
CONST ALC_FREQUENCY = 0x1007
CONST ALC_REFRESH = 0x1008
CONST ALC_SYNC = 0x1009
CONST ALC_MONO_SOURCES = 0x1010
CONST ALC_STEREO_SOURCES = 0x1011
CONST ALC_NO_ERROR = 0
CONST ALC_INVALID_DEVICE = 0xA001
CONST ALC_INVALID_CONTEXT = 0xA002
CONST ALC_INVALID_ENUM = 0xA003
CONST ALC_INVALID_VALUE = 0xA004
CONST ALC_OUT_OF_MEMORY = 0xA005
CONST ALC_DEFAULT_DEVICE_SPECIFIER = 0x1004
CONST ALC_DEVICE_SPECIFIER = 0x1005
CONST ALC_EXTENSIONS = 0x1006
CONST ALC_MAJOR_VERSION = 0x1000
CONST ALC_MINOR_VERSION = 0x1001
CONST ALC_ATTRIBUTES_SIZE = 0x1002
CONST ALC_ALL_ATTRIBUTES = 0x1003
CONST ALC_EXT_CAPTURE = 1
CONST ALC_CAPTURE_DEVICE_SPECIFIER = 0x310
CONST ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER = 0x311
CONST ALC_CAPTURE_SAMPLES = 0x312
CONST ALC_ENUMERATE_ALL_EXT = 1
CONST ALC_DEFAULT_ALL_DEVICES_SPECIFIER = 0x1012
CONST ALC_ALL_DEVICES_SPECIFIER = 0x1013

IMPORT "alcCreateContext(void*,void*)" FROM AL_lib$ TYPE void*
IMPORT "alcMakeContextCurrent(void*)" FROM AL_lib$ TYPE int
IMPORT "alcProcessContext(void*)" FROM AL_lib$ TYPE void
IMPORT "alcSuspendContext(void*)" FROM AL_lib$ TYPE void
IMPORT "alcDestroyContext(void*)" FROM AL_lib$ TYPE void
IMPORT "alcGetCurrentContext(void)" FROM AL_lib$ TYPE void*
IMPORT "alcGetContextsDevice(void*)" FROM AL_lib$ TYPE void*
IMPORT "alcOpenDevice(void*)" FROM AL_lib$ TYPE void*
IMPORT "alcCloseDevice(void*)" FROM AL_lib$ TYPE int
IMPORT "alcGetError(void*)" FROM AL_lib$ TYPE int
IMPORT "alcIsExtensionPresent(void*,char*)" FROM AL_lib$ TYPE int
IMPORT "alcGetProcAddress(void*,char*)" FROM AL_lib$ TYPE void*
IMPORT "alcGetEnumValue(void*,char*)" FROM AL_lib$ TYPE int
IMPORT "alcGetString(void*,int)" FROM AL_lib$ TYPE char* ALIAS alcGetString$
IMPORT "alcGetIntegerv(void*,int,int,void*)" FROM AL_lib$ TYPE void
IMPORT "alcCaptureOpenDevice(void*,int,int,int)" FROM AL_lib$ TYPE void*
IMPORT "alcCaptureCloseDevice(void*)" FROM AL_lib$ TYPE int
IMPORT "alcCaptureStart(void*)" FROM AL_lib$ TYPE void
IMPORT "alcCaptureStop(void*)" FROM AL_lib$ TYPE void
IMPORT "alcCaptureSamples(void*,void*,int)" FROM AL_lib$ TYPE void

'-----------------------------------------------------------------------------------

RECORD OPENAL
    LOCAL device, context TYPE void*
END RECORD

SUB OPENAL_INIT

    OPENAL.device = alcOpenDevice(NULL)                         : ' Open sound device

    IF OPENAL.device THEN
        OPENAL.context = alcCreateContext(OPENAL.device, NULL)  : ' OpenAL context
        alcMakeContextCurrent(OPENAL.context)
    ELSE
        PRINT "Cannot open OpenAL device. Exiting."
        END 1
    ENDIF

END SUB

SUB OPENAL_INFO

    PRINT alGetString(AL_VENDOR) FORMAT "Vendor string: '%s'.\n"
    PRINT alGetString(AL_VERSION) FORMAT "Version string: '%s'.\n"
    PRINT alGetString(AL_RENDERER) FORMAT "Renderer: '%s'.\n"
    PRINT alcGetString(OPENAL.device, ALC_DEVICE_SPECIFIER) FORMAT "Using '%s' device.\n"

END SUB

SUB OPENAL_FREE

    alcMakeContextCurrent(NULL)
    alcDestroyContext(OPENAL.context)
    alcCloseDevice(OPENAL.device)

END SUB

Generated by GNU Enscript 1.6.5.90.