2007-11-14 02:02:18 +00:00
|
|
|
/**
|
|
|
|
* OpenAL cross platform audio library
|
|
|
|
* Copyright (C) 1999-2007 by authors.
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
* Or go to http://www.gnu.org/copyleft/lgpl.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <memory.h>
|
2008-01-20 04:02:40 +00:00
|
|
|
#include <ctype.h>
|
2007-11-14 02:02:18 +00:00
|
|
|
#include "alMain.h"
|
2007-12-19 02:13:49 +00:00
|
|
|
#include "alSource.h"
|
2007-11-14 02:02:18 +00:00
|
|
|
#include "AL/al.h"
|
|
|
|
#include "AL/alc.h"
|
2007-12-31 09:09:57 +00:00
|
|
|
#include "alThunk.h"
|
|
|
|
#include "alSource.h"
|
2008-07-18 01:38:07 +00:00
|
|
|
#include "alBuffer.h"
|
2007-12-31 09:09:57 +00:00
|
|
|
#include "alExtension.h"
|
2008-01-16 22:01:24 +00:00
|
|
|
#include "alAuxEffectSlot.h"
|
2009-08-16 07:54:08 +00:00
|
|
|
#include "alDatabuffer.h"
|
2008-01-03 14:02:06 +00:00
|
|
|
#include "bs2b.h"
|
2009-01-24 18:38:04 +00:00
|
|
|
#include "alu.h"
|
2007-11-14 02:02:18 +00:00
|
|
|
|
|
|
|
|
2009-08-13 19:28:46 +00:00
|
|
|
#define EmptyFuncs { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
|
2009-09-22 11:42:46 +00:00
|
|
|
typedef struct BackendInfo {
|
2007-11-14 02:02:18 +00:00
|
|
|
const char *name;
|
|
|
|
void (*Init)(BackendFuncs*);
|
2009-08-27 06:45:00 +00:00
|
|
|
void (*Deinit)(void);
|
2009-08-27 13:09:33 +00:00
|
|
|
void (*Probe)(int);
|
2007-11-14 02:02:18 +00:00
|
|
|
BackendFuncs Funcs;
|
2009-09-22 11:42:46 +00:00
|
|
|
} BackendInfo;
|
|
|
|
static BackendInfo BackendList[] = {
|
2010-01-08 09:08:27 +00:00
|
|
|
#ifdef HAVE_PULSEAUDIO
|
|
|
|
{ "pulse", alc_pulse_init, alc_pulse_deinit, alc_pulse_probe, EmptyFuncs },
|
|
|
|
#endif
|
2007-11-14 02:02:18 +00:00
|
|
|
#ifdef HAVE_ALSA
|
2009-08-27 13:09:33 +00:00
|
|
|
{ "alsa", alc_alsa_init, alc_alsa_deinit, alc_alsa_probe, EmptyFuncs },
|
2007-11-14 02:02:18 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_OSS
|
2009-08-27 13:09:33 +00:00
|
|
|
{ "oss", alc_oss_init, alc_oss_deinit, alc_oss_probe, EmptyFuncs },
|
2007-11-14 02:02:18 +00:00
|
|
|
#endif
|
2008-09-07 21:34:14 +00:00
|
|
|
#ifdef HAVE_SOLARIS
|
2009-08-27 13:09:33 +00:00
|
|
|
{ "solaris", alc_solaris_init, alc_solaris_deinit, alc_solaris_probe, EmptyFuncs },
|
2008-09-07 21:34:14 +00:00
|
|
|
#endif
|
2007-11-14 02:02:18 +00:00
|
|
|
#ifdef HAVE_DSOUND
|
2009-08-27 13:09:33 +00:00
|
|
|
{ "dsound", alcDSoundInit, alcDSoundDeinit, alcDSoundProbe, EmptyFuncs },
|
2007-11-14 02:02:18 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_WINMM
|
2009-08-27 13:09:33 +00:00
|
|
|
{ "winmm", alcWinMMInit, alcWinMMDeinit, alcWinMMProbe, EmptyFuncs },
|
2007-11-14 02:02:18 +00:00
|
|
|
#endif
|
2009-03-10 07:55:29 +00:00
|
|
|
#ifdef HAVE_PORTAUDIO
|
2009-08-27 13:09:33 +00:00
|
|
|
{ "port", alc_pa_init, alc_pa_deinit, alc_pa_probe, EmptyFuncs },
|
2009-03-10 07:55:29 +00:00
|
|
|
#endif
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2009-08-27 13:09:33 +00:00
|
|
|
{ "wave", alc_wave_init, alc_wave_deinit, alc_wave_probe, EmptyFuncs },
|
2008-01-11 17:32:22 +00:00
|
|
|
|
2009-08-27 13:09:33 +00:00
|
|
|
{ NULL, NULL, NULL, NULL, EmptyFuncs }
|
2007-11-14 02:02:18 +00:00
|
|
|
};
|
|
|
|
#undef EmptyFuncs
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////
|
|
|
|
|
2007-12-18 00:55:07 +00:00
|
|
|
#define ALC_EFX_MAJOR_VERSION 0x20001
|
|
|
|
#define ALC_EFX_MINOR_VERSION 0x20002
|
|
|
|
#define ALC_MAX_AUXILIARY_SENDS 0x20003
|
2007-11-14 02:02:18 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////
|
|
|
|
// STRING and EXTENSIONS
|
|
|
|
|
|
|
|
typedef struct ALCfunction_struct
|
|
|
|
{
|
|
|
|
ALCchar *funcName;
|
|
|
|
ALvoid *address;
|
|
|
|
} ALCfunction;
|
|
|
|
|
|
|
|
static ALCfunction alcFunctions[] = {
|
|
|
|
{ "alcCreateContext", (ALvoid *) alcCreateContext },
|
|
|
|
{ "alcMakeContextCurrent", (ALvoid *) alcMakeContextCurrent },
|
|
|
|
{ "alcProcessContext", (ALvoid *) alcProcessContext },
|
|
|
|
{ "alcSuspendContext", (ALvoid *) alcSuspendContext },
|
|
|
|
{ "alcDestroyContext", (ALvoid *) alcDestroyContext },
|
|
|
|
{ "alcGetCurrentContext", (ALvoid *) alcGetCurrentContext },
|
|
|
|
{ "alcGetContextsDevice", (ALvoid *) alcGetContextsDevice },
|
|
|
|
{ "alcOpenDevice", (ALvoid *) alcOpenDevice },
|
|
|
|
{ "alcCloseDevice", (ALvoid *) alcCloseDevice },
|
|
|
|
{ "alcGetError", (ALvoid *) alcGetError },
|
|
|
|
{ "alcIsExtensionPresent", (ALvoid *) alcIsExtensionPresent },
|
|
|
|
{ "alcGetProcAddress", (ALvoid *) alcGetProcAddress },
|
|
|
|
{ "alcGetEnumValue", (ALvoid *) alcGetEnumValue },
|
|
|
|
{ "alcGetString", (ALvoid *) alcGetString },
|
|
|
|
{ "alcGetIntegerv", (ALvoid *) alcGetIntegerv },
|
|
|
|
{ "alcCaptureOpenDevice", (ALvoid *) alcCaptureOpenDevice },
|
|
|
|
{ "alcCaptureCloseDevice", (ALvoid *) alcCaptureCloseDevice },
|
|
|
|
{ "alcCaptureStart", (ALvoid *) alcCaptureStart },
|
|
|
|
{ "alcCaptureStop", (ALvoid *) alcCaptureStop },
|
|
|
|
{ "alcCaptureSamples", (ALvoid *) alcCaptureSamples },
|
2009-09-12 23:45:46 +00:00
|
|
|
|
|
|
|
{ "alcMakeCurrent", (ALvoid *) alcMakeCurrent },
|
|
|
|
{ "alcGetThreadContext", (ALvoid *) alcGetThreadContext },
|
|
|
|
|
2007-11-14 02:02:18 +00:00
|
|
|
{ NULL, (ALvoid *) NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static ALenums enumeration[]={
|
|
|
|
// Types
|
|
|
|
{ (ALchar *)"ALC_INVALID", ALC_INVALID },
|
|
|
|
{ (ALchar *)"ALC_FALSE", ALC_FALSE },
|
|
|
|
{ (ALchar *)"ALC_TRUE", ALC_TRUE },
|
|
|
|
|
|
|
|
// ALC Properties
|
|
|
|
{ (ALchar *)"ALC_MAJOR_VERSION", ALC_MAJOR_VERSION },
|
|
|
|
{ (ALchar *)"ALC_MINOR_VERSION", ALC_MINOR_VERSION },
|
|
|
|
{ (ALchar *)"ALC_ATTRIBUTES_SIZE", ALC_ATTRIBUTES_SIZE },
|
|
|
|
{ (ALchar *)"ALC_ALL_ATTRIBUTES", ALC_ALL_ATTRIBUTES },
|
|
|
|
{ (ALchar *)"ALC_DEFAULT_DEVICE_SPECIFIER", ALC_DEFAULT_DEVICE_SPECIFIER },
|
|
|
|
{ (ALchar *)"ALC_DEVICE_SPECIFIER", ALC_DEVICE_SPECIFIER },
|
|
|
|
{ (ALchar *)"ALC_ALL_DEVICES_SPECIFIER", ALC_ALL_DEVICES_SPECIFIER },
|
|
|
|
{ (ALchar *)"ALC_DEFAULT_ALL_DEVICES_SPECIFIER", ALC_DEFAULT_ALL_DEVICES_SPECIFIER },
|
|
|
|
{ (ALchar *)"ALC_EXTENSIONS", ALC_EXTENSIONS },
|
|
|
|
{ (ALchar *)"ALC_FREQUENCY", ALC_FREQUENCY },
|
|
|
|
{ (ALchar *)"ALC_REFRESH", ALC_REFRESH },
|
|
|
|
{ (ALchar *)"ALC_SYNC", ALC_SYNC },
|
|
|
|
{ (ALchar *)"ALC_MONO_SOURCES", ALC_MONO_SOURCES },
|
|
|
|
{ (ALchar *)"ALC_STEREO_SOURCES", ALC_STEREO_SOURCES },
|
|
|
|
{ (ALchar *)"ALC_CAPTURE_DEVICE_SPECIFIER", ALC_CAPTURE_DEVICE_SPECIFIER },
|
2007-12-18 00:55:07 +00:00
|
|
|
{ (ALchar *)"ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER", ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER},
|
2007-11-14 02:02:18 +00:00
|
|
|
{ (ALchar *)"ALC_CAPTURE_SAMPLES", ALC_CAPTURE_SAMPLES },
|
|
|
|
|
2007-12-18 00:55:07 +00:00
|
|
|
// EFX Properties
|
|
|
|
{ (ALchar *)"ALC_EFX_MAJOR_VERSION", ALC_EFX_MAJOR_VERSION },
|
|
|
|
{ (ALchar *)"ALC_EFX_MINOR_VERSION", ALC_EFX_MINOR_VERSION },
|
|
|
|
{ (ALchar *)"ALC_MAX_AUXILIARY_SENDS", ALC_MAX_AUXILIARY_SENDS },
|
|
|
|
|
2007-11-14 02:02:18 +00:00
|
|
|
// ALC Error Message
|
|
|
|
{ (ALchar *)"ALC_NO_ERROR", ALC_NO_ERROR },
|
|
|
|
{ (ALchar *)"ALC_INVALID_DEVICE", ALC_INVALID_DEVICE },
|
|
|
|
{ (ALchar *)"ALC_INVALID_CONTEXT", ALC_INVALID_CONTEXT },
|
|
|
|
{ (ALchar *)"ALC_INVALID_ENUM", ALC_INVALID_ENUM },
|
|
|
|
{ (ALchar *)"ALC_INVALID_VALUE", ALC_INVALID_VALUE },
|
|
|
|
{ (ALchar *)"ALC_OUT_OF_MEMORY", ALC_OUT_OF_MEMORY },
|
|
|
|
{ (ALchar *)NULL, (ALenum)0 }
|
|
|
|
};
|
|
|
|
// Error strings
|
|
|
|
static const ALCchar alcNoError[] = "No Error";
|
|
|
|
static const ALCchar alcErrInvalidDevice[] = "Invalid Device";
|
|
|
|
static const ALCchar alcErrInvalidContext[] = "Invalid Context";
|
|
|
|
static const ALCchar alcErrInvalidEnum[] = "Invalid Enum";
|
|
|
|
static const ALCchar alcErrInvalidValue[] = "Invalid Value";
|
|
|
|
static const ALCchar alcErrOutOfMemory[] = "Out of Memory";
|
|
|
|
|
2009-08-27 10:55:36 +00:00
|
|
|
/* Device lists. Sizes only include the first ending null character, not the
|
|
|
|
* second */
|
|
|
|
static ALCchar *alcDeviceList;
|
2010-03-18 21:21:06 +00:00
|
|
|
static size_t alcDeviceListSize;
|
2009-08-27 10:55:36 +00:00
|
|
|
static ALCchar *alcAllDeviceList;
|
2010-03-18 21:21:06 +00:00
|
|
|
static size_t alcAllDeviceListSize;
|
2009-08-27 10:55:36 +00:00
|
|
|
static ALCchar *alcCaptureDeviceList;
|
2010-03-18 21:21:06 +00:00
|
|
|
static size_t alcCaptureDeviceListSize;
|
2007-11-14 02:02:18 +00:00
|
|
|
// Default is always the first in the list
|
2009-08-27 10:55:36 +00:00
|
|
|
static ALCchar *alcDefaultDeviceSpecifier;
|
|
|
|
static ALCchar *alcDefaultAllDeviceSpecifier;
|
|
|
|
static ALCchar *alcCaptureDefaultDeviceSpecifier;
|
2007-11-14 02:02:18 +00:00
|
|
|
|
|
|
|
|
2010-03-18 02:46:20 +00:00
|
|
|
static const ALCchar alcNoDeviceExtList[] =
|
|
|
|
"ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE "
|
|
|
|
"ALC_EXTX_thread_local_context";
|
2010-02-16 06:01:23 +00:00
|
|
|
static const ALCchar alcExtensionList[] =
|
|
|
|
"ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE "
|
|
|
|
"ALC_EXT_disconnect ALC_EXT_EFX ALC_EXTX_thread_local_context";
|
|
|
|
static const ALCint alcMajorVersion = 1;
|
|
|
|
static const ALCint alcMinorVersion = 1;
|
|
|
|
|
|
|
|
static const ALCint alcEFXMajorVersion = 1;
|
|
|
|
static const ALCint alcEFXMinorVersion = 0;
|
2007-12-18 00:55:07 +00:00
|
|
|
|
2007-11-14 02:02:18 +00:00
|
|
|
///////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////
|
|
|
|
// Global Variables
|
|
|
|
|
2008-01-14 18:39:54 +00:00
|
|
|
static ALCdevice *g_pDeviceList = NULL;
|
|
|
|
static ALCuint g_ulDeviceCount = 0;
|
|
|
|
|
2008-07-18 01:38:07 +00:00
|
|
|
static CRITICAL_SECTION g_csMutex;
|
|
|
|
|
2007-11-14 02:02:18 +00:00
|
|
|
// Context List
|
|
|
|
static ALCcontext *g_pContextList = NULL;
|
|
|
|
static ALCuint g_ulContextCount = 0;
|
|
|
|
|
2009-09-12 23:45:46 +00:00
|
|
|
// Thread-local current context
|
|
|
|
static tls_type LocalContext;
|
|
|
|
|
2007-11-14 02:02:18 +00:00
|
|
|
// Context Error
|
|
|
|
static ALCenum g_eLastContextError = ALC_NO_ERROR;
|
|
|
|
|
2010-01-09 10:48:18 +00:00
|
|
|
// Default context extensions
|
|
|
|
static const ALchar alExtList[] =
|
2010-03-14 05:32:45 +00:00
|
|
|
"AL_EXTX_buffer_sub_data AL_EXT_DOUBLE AL_EXT_EXPONENT_DISTANCE "
|
|
|
|
"AL_EXT_FLOAT32 AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS "
|
2010-03-18 02:15:51 +00:00
|
|
|
"AL_EXT_MULAW AL_EXT_MULAW_MCFORMATS AL_EXT_OFFSET "
|
|
|
|
"AL_EXTX_sample_buffer_object AL_EXT_source_distance_model "
|
|
|
|
"AL_LOKI_quadriphonic";
|
2010-01-09 10:48:18 +00:00
|
|
|
|
2009-12-02 07:15:09 +00:00
|
|
|
// Mixing Priority Level
|
|
|
|
ALint RTPrioLevel;
|
|
|
|
|
2010-01-11 13:37:20 +00:00
|
|
|
// Resampler Quality
|
|
|
|
resampler_t DefaultResampler;
|
|
|
|
|
2007-11-14 02:02:18 +00:00
|
|
|
///////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////
|
|
|
|
// ALC Related helper functions
|
2008-07-18 01:38:07 +00:00
|
|
|
#ifdef _WIN32
|
2009-09-13 00:49:08 +00:00
|
|
|
static void alc_init(void);
|
|
|
|
static void alc_deinit(void);
|
2009-09-13 00:29:35 +00:00
|
|
|
|
2008-07-18 01:38:07 +00:00
|
|
|
BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
|
|
|
|
{
|
|
|
|
(void)lpReserved;
|
|
|
|
|
|
|
|
// Perform actions based on the reason for calling.
|
|
|
|
switch(ul_reason_for_call)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
DisableThreadLibraryCalls(hModule);
|
2009-09-13 00:49:08 +00:00
|
|
|
alc_init();
|
2008-07-18 01:38:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DLL_PROCESS_DETACH:
|
2009-09-13 00:29:35 +00:00
|
|
|
alc_deinit();
|
2008-07-18 01:38:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#ifdef HAVE_GCC_DESTRUCTOR
|
2009-09-13 00:49:08 +00:00
|
|
|
static void alc_init(void) __attribute__((constructor));
|
|
|
|
static void alc_deinit(void) __attribute__((destructor));
|
2009-09-13 00:29:35 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2009-09-13 00:49:08 +00:00
|
|
|
static void alc_init(void)
|
2008-07-18 01:38:07 +00:00
|
|
|
{
|
2009-08-27 06:45:00 +00:00
|
|
|
int i;
|
2009-09-13 00:49:08 +00:00
|
|
|
const char *devs, *str;
|
|
|
|
|
|
|
|
InitializeCriticalSection(&g_csMutex);
|
|
|
|
ALTHUNK_INIT();
|
|
|
|
ReadALConfig();
|
|
|
|
|
|
|
|
tls_create(&LocalContext);
|
|
|
|
|
2009-12-02 07:15:09 +00:00
|
|
|
RTPrioLevel = GetConfigValueInt(NULL, "rt-prio", 0);
|
|
|
|
|
2010-01-11 15:02:29 +00:00
|
|
|
DefaultResampler = GetConfigValueInt(NULL, "resampler", RESAMPLER_DEFAULT);
|
|
|
|
if(DefaultResampler >= RESAMPLER_MAX || DefaultResampler <= RESAMPLER_MIN)
|
|
|
|
DefaultResampler = RESAMPLER_DEFAULT;
|
2010-01-11 13:37:20 +00:00
|
|
|
|
2009-09-13 00:49:08 +00:00
|
|
|
devs = GetConfigValue(NULL, "drivers", "");
|
|
|
|
if(devs[0])
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
size_t len;
|
|
|
|
const char *next = devs;
|
2009-11-22 09:06:05 +00:00
|
|
|
int endlist;
|
2009-09-13 00:49:08 +00:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
do {
|
|
|
|
devs = next;
|
|
|
|
next = strchr(devs, ',');
|
|
|
|
|
|
|
|
if(!devs[0] || devs[0] == ',')
|
2009-11-22 09:06:05 +00:00
|
|
|
{
|
|
|
|
endlist = 0;
|
2009-09-13 00:49:08 +00:00
|
|
|
continue;
|
2009-11-22 09:06:05 +00:00
|
|
|
}
|
|
|
|
endlist = 1;
|
2009-09-13 00:49:08 +00:00
|
|
|
|
|
|
|
len = (next ? ((size_t)(next-devs)) : strlen(devs));
|
|
|
|
for(n = i;BackendList[n].Init;n++)
|
|
|
|
{
|
|
|
|
if(len == strlen(BackendList[n].name) &&
|
|
|
|
strncmp(BackendList[n].name, devs, len) == 0)
|
|
|
|
{
|
2009-11-22 09:06:05 +00:00
|
|
|
BackendInfo Bkp = BackendList[n];
|
|
|
|
while(n > i)
|
|
|
|
{
|
|
|
|
BackendList[n] = BackendList[n-1];
|
|
|
|
--n;
|
|
|
|
}
|
2009-09-22 11:42:46 +00:00
|
|
|
BackendList[n] = Bkp;
|
2009-09-13 00:49:08 +00:00
|
|
|
|
|
|
|
i++;
|
2009-11-22 09:06:05 +00:00
|
|
|
break;
|
2009-09-13 00:49:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} while(next++);
|
|
|
|
|
2009-11-22 09:06:05 +00:00
|
|
|
if(endlist)
|
|
|
|
{
|
|
|
|
BackendList[i].name = NULL;
|
|
|
|
BackendList[i].Init = NULL;
|
|
|
|
BackendList[i].Deinit = NULL;
|
|
|
|
BackendList[i].Probe = NULL;
|
|
|
|
}
|
2009-09-13 00:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0;BackendList[i].Init;i++)
|
|
|
|
BackendList[i].Init(&BackendList[i].Funcs);
|
|
|
|
|
2009-09-16 05:18:13 +00:00
|
|
|
DuplicateStereo = GetConfigValueBool(NULL, "stereodup", 0);
|
2009-09-13 00:49:08 +00:00
|
|
|
|
|
|
|
str = GetConfigValue(NULL, "excludefx", "");
|
|
|
|
if(str[0])
|
|
|
|
{
|
|
|
|
const struct {
|
|
|
|
const char *name;
|
|
|
|
int type;
|
|
|
|
} EffectList[] = {
|
|
|
|
{ "eaxreverb", EAXREVERB },
|
|
|
|
{ "reverb", REVERB },
|
|
|
|
{ "echo", ECHO },
|
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
|
|
|
int n;
|
|
|
|
size_t len;
|
|
|
|
const char *next = str;
|
|
|
|
|
|
|
|
do {
|
|
|
|
str = next;
|
|
|
|
next = strchr(str, ',');
|
2009-08-27 06:45:00 +00:00
|
|
|
|
2009-09-13 00:49:08 +00:00
|
|
|
if(!str[0] || next == str)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
len = (next ? ((size_t)(next-str)) : strlen(str));
|
|
|
|
for(n = 0;EffectList[n].name;n++)
|
|
|
|
{
|
|
|
|
if(len == strlen(EffectList[n].name) &&
|
|
|
|
strncmp(EffectList[n].name, str, len) == 0)
|
|
|
|
DisabledEffects[EffectList[n].type] = AL_TRUE;
|
|
|
|
}
|
|
|
|
} while(next++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void alc_deinit(void)
|
|
|
|
{
|
|
|
|
int i;
|
2008-07-18 01:38:07 +00:00
|
|
|
|
|
|
|
ReleaseALC();
|
2009-08-27 06:45:00 +00:00
|
|
|
|
|
|
|
for(i = 0;BackendList[i].Deinit;i++)
|
|
|
|
BackendList[i].Deinit();
|
|
|
|
|
2009-09-12 23:45:46 +00:00
|
|
|
tls_delete(LocalContext);
|
|
|
|
|
2008-07-18 01:38:07 +00:00
|
|
|
FreeALConfig();
|
|
|
|
ALTHUNK_EXIT();
|
|
|
|
DeleteCriticalSection(&g_csMutex);
|
|
|
|
}
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2009-09-13 00:49:08 +00:00
|
|
|
|
2009-08-27 13:09:33 +00:00
|
|
|
static void ProbeDeviceList()
|
|
|
|
{
|
|
|
|
ALint i;
|
|
|
|
|
|
|
|
free(alcDeviceList); alcDeviceList = NULL;
|
|
|
|
alcDeviceListSize = 0;
|
|
|
|
|
|
|
|
for(i = 0;BackendList[i].Probe;i++)
|
|
|
|
BackendList[i].Probe(DEVICE_PROBE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ProbeAllDeviceList()
|
|
|
|
{
|
|
|
|
ALint i;
|
|
|
|
|
|
|
|
free(alcAllDeviceList); alcAllDeviceList = NULL;
|
|
|
|
alcAllDeviceListSize = 0;
|
|
|
|
|
|
|
|
for(i = 0;BackendList[i].Probe;i++)
|
|
|
|
BackendList[i].Probe(ALL_DEVICE_PROBE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ProbeCaptureDeviceList()
|
|
|
|
{
|
|
|
|
ALint i;
|
|
|
|
|
|
|
|
free(alcCaptureDeviceList); alcCaptureDeviceList = NULL;
|
|
|
|
alcCaptureDeviceListSize = 0;
|
|
|
|
|
|
|
|
for(i = 0;BackendList[i].Probe;i++)
|
|
|
|
BackendList[i].Probe(CAPTURE_DEVICE_PROBE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-27 10:55:36 +00:00
|
|
|
#define DECL_APPEND_LIST_FUNC(type) \
|
|
|
|
void Append##type##List(const ALCchar *name) \
|
|
|
|
{ \
|
2010-03-18 21:21:06 +00:00
|
|
|
size_t len = strlen(name); \
|
2009-08-27 10:55:36 +00:00
|
|
|
void *temp; \
|
|
|
|
\
|
|
|
|
if(len == 0) \
|
|
|
|
return; \
|
|
|
|
\
|
|
|
|
temp = realloc(alc##type##List, alc##type##ListSize + len + 2); \
|
|
|
|
if(!temp) \
|
|
|
|
{ \
|
|
|
|
AL_PRINT("Realloc failed to add %s!\n", name); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
alc##type##List = temp; \
|
|
|
|
sprintf(alc##type##List+alc##type##ListSize, "%s", name); \
|
|
|
|
alc##type##ListSize += len+1; \
|
|
|
|
alc##type##List[alc##type##ListSize] = 0; \
|
2007-11-14 02:02:18 +00:00
|
|
|
}
|
|
|
|
|
2009-08-27 10:55:36 +00:00
|
|
|
DECL_APPEND_LIST_FUNC(Device)
|
|
|
|
DECL_APPEND_LIST_FUNC(AllDevice)
|
|
|
|
DECL_APPEND_LIST_FUNC(CaptureDevice)
|
2007-11-14 02:02:18 +00:00
|
|
|
|
|
|
|
|
2010-01-12 17:05:57 +00:00
|
|
|
void al_print(const char *fname, unsigned int line, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
const char *fn;
|
|
|
|
char str[256];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
fn = strrchr(fname, '/');
|
|
|
|
if(!fn) fn = strrchr(fname, '\\');;
|
|
|
|
if(!fn) fn = fname;
|
|
|
|
else fn += 1;
|
|
|
|
|
|
|
|
i = snprintf(str, sizeof(str), "AL lib: %s:%d: ", fn, line);
|
|
|
|
if(i < (int)sizeof(str) && i > 0)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsnprintf(str+i, sizeof(str)-i, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
str[sizeof(str)-1] = 0;
|
|
|
|
|
|
|
|
fprintf(stderr, "%s", str);
|
|
|
|
}
|
|
|
|
|
2009-12-02 07:15:09 +00:00
|
|
|
void EnableRTPrio(ALint level)
|
|
|
|
{
|
|
|
|
ALboolean failed;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
if(level > 0)
|
|
|
|
failed = !SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
|
|
|
|
else
|
|
|
|
failed = !SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
|
|
|
|
#elif defined(HAVE_PTHREAD_SETSCHEDPARAM)
|
|
|
|
struct sched_param param;
|
|
|
|
|
|
|
|
if(level > 0)
|
|
|
|
{
|
|
|
|
/* Use the minimum real-time priority possible for now (on Linux this
|
|
|
|
* should be 1 for SCHED_RR) */
|
|
|
|
param.sched_priority = sched_get_priority_min(SCHED_RR);
|
|
|
|
failed = !!pthread_setschedparam(pthread_self(), SCHED_RR, ¶m);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
param.sched_priority = 0;
|
|
|
|
failed = !!pthread_setschedparam(pthread_self(), SCHED_OTHER, ¶m);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
/* Real-time priority not available */
|
|
|
|
failed = !!level;
|
|
|
|
#endif
|
|
|
|
if(failed)
|
|
|
|
AL_PRINT("Failed to set priority level for thread\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-15 16:55:08 +00:00
|
|
|
/*
|
|
|
|
IsDevice
|
|
|
|
|
|
|
|
Check pDevice is a valid Device pointer
|
|
|
|
*/
|
|
|
|
static ALCboolean IsDevice(ALCdevice *pDevice)
|
|
|
|
{
|
|
|
|
ALCdevice *pTempDevice;
|
|
|
|
|
|
|
|
SuspendContext(NULL);
|
|
|
|
|
|
|
|
pTempDevice = g_pDeviceList;
|
|
|
|
while(pTempDevice && pTempDevice != pDevice)
|
|
|
|
pTempDevice = pTempDevice->next;
|
|
|
|
|
|
|
|
ProcessContext(NULL);
|
|
|
|
|
|
|
|
return (pTempDevice ? ALC_TRUE : ALC_FALSE);
|
|
|
|
}
|
|
|
|
|
2007-11-14 02:02:18 +00:00
|
|
|
/*
|
|
|
|
IsContext
|
|
|
|
|
|
|
|
Check pContext is a valid Context pointer
|
|
|
|
*/
|
2007-12-07 06:26:52 +00:00
|
|
|
static ALCboolean IsContext(ALCcontext *pContext)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
|
|
|
ALCcontext *pTempContext;
|
|
|
|
|
2009-08-13 19:28:46 +00:00
|
|
|
SuspendContext(NULL);
|
|
|
|
|
2007-11-14 02:02:18 +00:00
|
|
|
pTempContext = g_pContextList;
|
|
|
|
while (pTempContext && pTempContext != pContext)
|
|
|
|
pTempContext = pTempContext->next;
|
|
|
|
|
2009-08-13 19:28:46 +00:00
|
|
|
ProcessContext(NULL);
|
|
|
|
|
2007-11-14 02:02:18 +00:00
|
|
|
return (pTempContext ? ALC_TRUE : ALC_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2009-10-07 11:32:14 +00:00
|
|
|
alcSetError
|
2007-11-14 02:02:18 +00:00
|
|
|
|
|
|
|
Store latest ALC Error
|
|
|
|
*/
|
2009-12-29 07:19:13 +00:00
|
|
|
ALCvoid alcSetError(ALCdevice *device, ALenum errorCode)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
2009-12-29 07:19:13 +00:00
|
|
|
if(IsDevice(device))
|
|
|
|
device->LastError = errorCode;
|
|
|
|
else
|
|
|
|
g_eLastContextError = errorCode;
|
2007-11-14 02:02:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
SuspendContext
|
|
|
|
|
|
|
|
Thread-safe entry
|
|
|
|
*/
|
|
|
|
ALCvoid SuspendContext(ALCcontext *pContext)
|
|
|
|
{
|
|
|
|
(void)pContext;
|
2008-07-18 01:38:07 +00:00
|
|
|
EnterCriticalSection(&g_csMutex);
|
2007-11-14 02:02:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
ProcessContext
|
|
|
|
|
|
|
|
Thread-safe exit
|
|
|
|
*/
|
|
|
|
ALCvoid ProcessContext(ALCcontext *pContext)
|
|
|
|
{
|
|
|
|
(void)pContext;
|
2008-07-18 01:38:07 +00:00
|
|
|
LeaveCriticalSection(&g_csMutex);
|
2007-11-14 02:02:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-16 21:09:23 +00:00
|
|
|
/*
|
|
|
|
GetContextSuspended
|
|
|
|
|
|
|
|
Returns the currently active Context, in a locked state
|
|
|
|
*/
|
|
|
|
ALCcontext *GetContextSuspended(void)
|
|
|
|
{
|
|
|
|
ALCcontext *pContext = NULL;
|
|
|
|
|
|
|
|
SuspendContext(NULL);
|
|
|
|
|
2009-09-12 23:45:46 +00:00
|
|
|
pContext = tls_get(LocalContext);
|
|
|
|
if(pContext && !IsContext(pContext))
|
|
|
|
{
|
|
|
|
tls_set(LocalContext, NULL);
|
|
|
|
pContext = NULL;
|
|
|
|
}
|
|
|
|
if(!pContext)
|
|
|
|
{
|
|
|
|
pContext = g_pContextList;
|
|
|
|
while(pContext && !pContext->InUse)
|
|
|
|
pContext = pContext->next;
|
|
|
|
}
|
2009-08-16 21:09:23 +00:00
|
|
|
if(pContext)
|
|
|
|
SuspendContext(pContext);
|
|
|
|
|
|
|
|
ProcessContext(NULL);
|
|
|
|
|
|
|
|
return pContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-14 02:02:18 +00:00
|
|
|
/*
|
|
|
|
InitContext
|
|
|
|
|
|
|
|
Initialize Context variables
|
|
|
|
*/
|
|
|
|
static ALvoid InitContext(ALCcontext *pContext)
|
|
|
|
{
|
|
|
|
//Initialise listener
|
|
|
|
pContext->Listener.Gain = 1.0f;
|
2007-12-18 03:40:43 +00:00
|
|
|
pContext->Listener.MetersPerUnit = 1.0f;
|
2007-11-14 02:02:18 +00:00
|
|
|
pContext->Listener.Position[0] = 0.0f;
|
|
|
|
pContext->Listener.Position[1] = 0.0f;
|
|
|
|
pContext->Listener.Position[2] = 0.0f;
|
|
|
|
pContext->Listener.Velocity[0] = 0.0f;
|
|
|
|
pContext->Listener.Velocity[1] = 0.0f;
|
|
|
|
pContext->Listener.Velocity[2] = 0.0f;
|
|
|
|
pContext->Listener.Forward[0] = 0.0f;
|
|
|
|
pContext->Listener.Forward[1] = 0.0f;
|
|
|
|
pContext->Listener.Forward[2] = -1.0f;
|
|
|
|
pContext->Listener.Up[0] = 0.0f;
|
|
|
|
pContext->Listener.Up[1] = 1.0f;
|
|
|
|
pContext->Listener.Up[2] = 0.0f;
|
|
|
|
|
|
|
|
//Validate pContext
|
|
|
|
pContext->LastError = AL_NO_ERROR;
|
|
|
|
pContext->InUse = AL_FALSE;
|
2009-12-09 20:14:53 +00:00
|
|
|
pContext->Suspended = AL_FALSE;
|
2007-11-14 02:02:18 +00:00
|
|
|
|
|
|
|
//Set globals
|
|
|
|
pContext->DistanceModel = AL_INVERSE_DISTANCE_CLAMPED;
|
2009-11-28 04:05:21 +00:00
|
|
|
pContext->SourceDistanceModel = AL_FALSE;
|
2007-11-14 02:02:18 +00:00
|
|
|
pContext->DopplerFactor = 1.0f;
|
|
|
|
pContext->DopplerVelocity = 1.0f;
|
|
|
|
pContext->flSpeedOfSound = SPEEDOFSOUNDMETRESPERSEC;
|
|
|
|
|
2010-01-09 10:48:18 +00:00
|
|
|
pContext->ExtensionList = alExtList;
|
2007-11-14 02:02:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
ExitContext
|
|
|
|
|
|
|
|
Clean up Context, destroy any remaining Sources
|
|
|
|
*/
|
|
|
|
static ALCvoid ExitContext(ALCcontext *pContext)
|
|
|
|
{
|
|
|
|
//Invalidate context
|
|
|
|
pContext->LastError = AL_NO_ERROR;
|
|
|
|
pContext->InUse = AL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////
|
|
|
|
// ALC Functions calls
|
|
|
|
|
|
|
|
|
|
|
|
// This should probably move to another c file but for now ...
|
2010-03-19 21:34:18 +00:00
|
|
|
ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName, ALCuint frequency, ALCenum format, ALCsizei SampleSize)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
|
|
|
ALCboolean DeviceFound = ALC_FALSE;
|
2010-03-20 03:49:23 +00:00
|
|
|
ALCdevice *device = NULL;
|
2007-11-14 02:02:18 +00:00
|
|
|
ALCint i;
|
|
|
|
|
2008-10-28 06:37:56 +00:00
|
|
|
if(SampleSize <= 0)
|
2008-10-25 02:58:49 +00:00
|
|
|
{
|
2009-12-29 07:19:13 +00:00
|
|
|
alcSetError(NULL, ALC_INVALID_VALUE);
|
2008-10-25 02:58:49 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-12-27 01:38:42 +00:00
|
|
|
if(deviceName && !deviceName[0])
|
|
|
|
deviceName = NULL;
|
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
device = calloc(1, sizeof(ALCdevice));
|
|
|
|
if(!device)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
2010-03-20 03:49:23 +00:00
|
|
|
alcSetError(NULL, ALC_OUT_OF_MEMORY);
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
//Validate device
|
|
|
|
device->Connected = ALC_TRUE;
|
|
|
|
device->IsCaptureDevice = AL_TRUE;
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
device->szDeviceName = NULL;
|
2009-08-27 09:53:09 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
device->Frequency = frequency;
|
|
|
|
device->Format = format;
|
|
|
|
device->UpdateSize = SampleSize;
|
|
|
|
device->NumUpdates = 1;
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
SuspendContext(NULL);
|
|
|
|
for(i = 0;BackendList[i].Init;i++)
|
|
|
|
{
|
|
|
|
device->Funcs = &BackendList[i].Funcs;
|
|
|
|
if(ALCdevice_OpenCapture(device, deviceName))
|
2008-10-25 02:58:49 +00:00
|
|
|
{
|
2010-03-20 03:49:23 +00:00
|
|
|
device->next = g_pDeviceList;
|
|
|
|
g_pDeviceList = device;
|
|
|
|
g_ulDeviceCount++;
|
2008-01-14 18:39:54 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
DeviceFound = ALC_TRUE;
|
|
|
|
break;
|
2007-11-14 02:02:18 +00:00
|
|
|
}
|
2010-03-20 03:49:23 +00:00
|
|
|
}
|
|
|
|
ProcessContext(NULL);
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
if(!DeviceFound)
|
|
|
|
{
|
|
|
|
alcSetError(NULL, ALC_INVALID_VALUE);
|
|
|
|
free(device);
|
|
|
|
device = NULL;
|
2007-11-14 02:02:18 +00:00
|
|
|
}
|
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
return device;
|
2007-11-14 02:02:18 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 21:34:18 +00:00
|
|
|
ALC_API ALCboolean ALC_APIENTRY alcCaptureCloseDevice(ALCdevice *pDevice)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
2008-01-14 18:39:54 +00:00
|
|
|
ALCdevice **list;
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
if(!IsDevice(pDevice) || !pDevice->IsCaptureDevice)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
2010-03-20 03:49:23 +00:00
|
|
|
alcSetError(pDevice, ALC_INVALID_DEVICE);
|
|
|
|
return ALC_FALSE;
|
|
|
|
}
|
2008-01-14 18:39:54 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
SuspendContext(NULL);
|
2008-01-14 18:39:54 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
list = &g_pDeviceList;
|
|
|
|
while(*list != pDevice)
|
|
|
|
list = &(*list)->next;
|
2008-01-14 18:39:54 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
*list = (*list)->next;
|
|
|
|
g_ulDeviceCount--;
|
2008-01-14 18:39:54 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
ProcessContext(NULL);
|
2009-10-31 20:25:26 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
ALCdevice_CloseCapture(pDevice);
|
2009-08-27 09:53:09 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
free(pDevice->szDeviceName);
|
|
|
|
pDevice->szDeviceName = NULL;
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
free(pDevice);
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
return ALC_TRUE;
|
2007-11-14 02:02:18 +00:00
|
|
|
}
|
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
ALC_API void ALC_APIENTRY alcCaptureStart(ALCdevice *device)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
2010-03-20 03:49:23 +00:00
|
|
|
if(!IsDevice(device) || !device->IsCaptureDevice)
|
2010-03-09 18:14:52 +00:00
|
|
|
{
|
2010-03-20 03:49:23 +00:00
|
|
|
alcSetError(device, ALC_INVALID_DEVICE);
|
|
|
|
return;
|
2010-03-09 18:14:52 +00:00
|
|
|
}
|
2010-03-20 03:49:23 +00:00
|
|
|
SuspendContext(NULL);
|
|
|
|
ALCdevice_StartCapture(device);
|
|
|
|
ProcessContext(NULL);
|
2007-11-14 02:02:18 +00:00
|
|
|
}
|
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
ALC_API void ALC_APIENTRY alcCaptureStop(ALCdevice *device)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
2010-03-20 03:49:23 +00:00
|
|
|
if(!IsDevice(device) || !device->IsCaptureDevice)
|
2010-03-09 18:14:52 +00:00
|
|
|
{
|
2010-03-20 03:49:23 +00:00
|
|
|
alcSetError(device, ALC_INVALID_DEVICE);
|
|
|
|
return;
|
2010-03-09 18:14:52 +00:00
|
|
|
}
|
2010-03-20 03:49:23 +00:00
|
|
|
SuspendContext(NULL);
|
|
|
|
ALCdevice_StopCapture(device);
|
|
|
|
ProcessContext(NULL);
|
2007-11-14 02:02:18 +00:00
|
|
|
}
|
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
ALC_API void ALC_APIENTRY alcCaptureSamples(ALCdevice *device, ALCvoid *buffer, ALCsizei samples)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
2010-03-20 03:49:23 +00:00
|
|
|
if(!IsDevice(device) || !device->IsCaptureDevice)
|
2010-03-09 18:14:52 +00:00
|
|
|
{
|
2010-03-20 03:49:23 +00:00
|
|
|
alcSetError(device, ALC_INVALID_DEVICE);
|
|
|
|
return;
|
2010-03-09 18:14:52 +00:00
|
|
|
}
|
2010-03-20 03:49:23 +00:00
|
|
|
SuspendContext(NULL);
|
|
|
|
ALCdevice_CaptureSamples(device, buffer, samples);
|
|
|
|
ProcessContext(NULL);
|
2007-11-14 02:02:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
alcGetError
|
|
|
|
|
|
|
|
Return last ALC generated error code
|
|
|
|
*/
|
2010-03-19 21:34:18 +00:00
|
|
|
ALC_API ALCenum ALC_APIENTRY alcGetError(ALCdevice *device)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
2009-12-29 07:19:13 +00:00
|
|
|
ALCenum errorCode = ALC_NO_ERROR;
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-01-09 11:25:13 +00:00
|
|
|
if(IsDevice(device))
|
2009-12-29 07:19:13 +00:00
|
|
|
{
|
|
|
|
errorCode = device->LastError;
|
|
|
|
device->LastError = ALC_NO_ERROR;
|
|
|
|
}
|
2009-12-29 07:29:49 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
errorCode = g_eLastContextError;
|
|
|
|
g_eLastContextError = ALC_NO_ERROR;
|
|
|
|
}
|
2007-11-14 02:02:18 +00:00
|
|
|
return errorCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
alcSuspendContext
|
|
|
|
|
|
|
|
Not functional
|
|
|
|
*/
|
2010-03-19 21:34:18 +00:00
|
|
|
ALC_API ALCvoid ALC_APIENTRY alcSuspendContext(ALCcontext *pContext)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
2009-12-09 20:14:53 +00:00
|
|
|
SuspendContext(NULL);
|
|
|
|
if(IsContext(pContext))
|
|
|
|
pContext->Suspended = AL_TRUE;
|
|
|
|
ProcessContext(NULL);
|
2007-11-14 02:02:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
alcProcessContext
|
|
|
|
|
|
|
|
Not functional
|
|
|
|
*/
|
2010-03-19 21:34:18 +00:00
|
|
|
ALC_API ALCvoid ALC_APIENTRY alcProcessContext(ALCcontext *pContext)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
2009-12-09 20:14:53 +00:00
|
|
|
SuspendContext(NULL);
|
|
|
|
if(IsContext(pContext))
|
|
|
|
pContext->Suspended = AL_FALSE;
|
|
|
|
ProcessContext(NULL);
|
2007-11-14 02:02:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
alcGetString
|
|
|
|
|
|
|
|
Returns information about the Device, and error strings
|
|
|
|
*/
|
2010-03-19 21:34:18 +00:00
|
|
|
ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *pDevice,ALCenum param)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
|
|
|
const ALCchar *value = NULL;
|
|
|
|
|
|
|
|
switch (param)
|
|
|
|
{
|
|
|
|
case ALC_NO_ERROR:
|
|
|
|
value = alcNoError;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALC_INVALID_ENUM:
|
|
|
|
value = alcErrInvalidEnum;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALC_INVALID_VALUE:
|
|
|
|
value = alcErrInvalidValue;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALC_INVALID_DEVICE:
|
|
|
|
value = alcErrInvalidDevice;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALC_INVALID_CONTEXT:
|
|
|
|
value = alcErrInvalidContext;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALC_OUT_OF_MEMORY:
|
|
|
|
value = alcErrOutOfMemory;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALC_DEVICE_SPECIFIER:
|
2009-08-15 16:55:08 +00:00
|
|
|
if(IsDevice(pDevice))
|
2007-11-14 02:02:18 +00:00
|
|
|
value = pDevice->szDeviceName;
|
|
|
|
else
|
2009-08-27 13:09:33 +00:00
|
|
|
{
|
|
|
|
ProbeDeviceList();
|
2007-11-14 02:02:18 +00:00
|
|
|
value = alcDeviceList;
|
2009-08-27 13:09:33 +00:00
|
|
|
}
|
2007-11-14 02:02:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ALC_ALL_DEVICES_SPECIFIER:
|
2009-08-27 13:09:33 +00:00
|
|
|
ProbeAllDeviceList();
|
2007-11-14 02:02:18 +00:00
|
|
|
value = alcAllDeviceList;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALC_CAPTURE_DEVICE_SPECIFIER:
|
2009-08-15 16:55:08 +00:00
|
|
|
if(IsDevice(pDevice))
|
2007-11-14 02:02:18 +00:00
|
|
|
value = pDevice->szDeviceName;
|
|
|
|
else
|
2009-08-27 13:09:33 +00:00
|
|
|
{
|
|
|
|
ProbeCaptureDeviceList();
|
2007-11-14 02:02:18 +00:00
|
|
|
value = alcCaptureDeviceList;
|
2009-08-27 13:09:33 +00:00
|
|
|
}
|
2007-11-14 02:02:18 +00:00
|
|
|
break;
|
|
|
|
|
2009-08-28 03:13:35 +00:00
|
|
|
/* Default devices are always first in the list */
|
|
|
|
case ALC_DEFAULT_DEVICE_SPECIFIER:
|
2010-02-11 00:34:43 +00:00
|
|
|
if(!alcDeviceList)
|
|
|
|
ProbeDeviceList();
|
|
|
|
|
2009-08-28 03:13:35 +00:00
|
|
|
free(alcDefaultDeviceSpecifier);
|
|
|
|
alcDefaultDeviceSpecifier = strdup(alcDeviceList ? alcDeviceList : "");
|
|
|
|
if(!alcDefaultDeviceSpecifier)
|
2009-12-29 07:19:13 +00:00
|
|
|
alcSetError(pDevice, ALC_OUT_OF_MEMORY);
|
2009-08-28 03:13:35 +00:00
|
|
|
value = alcDefaultDeviceSpecifier;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALC_DEFAULT_ALL_DEVICES_SPECIFIER:
|
2010-02-11 00:34:43 +00:00
|
|
|
if(!alcAllDeviceList)
|
|
|
|
ProbeAllDeviceList();
|
|
|
|
|
2009-08-28 03:13:35 +00:00
|
|
|
free(alcDefaultAllDeviceSpecifier);
|
|
|
|
alcDefaultAllDeviceSpecifier = strdup(alcAllDeviceList ?
|
|
|
|
alcAllDeviceList : "");
|
|
|
|
if(!alcDefaultAllDeviceSpecifier)
|
2009-12-29 07:19:13 +00:00
|
|
|
alcSetError(pDevice, ALC_OUT_OF_MEMORY);
|
2009-08-28 03:13:35 +00:00
|
|
|
value = alcDefaultAllDeviceSpecifier;
|
|
|
|
break;
|
|
|
|
|
2007-11-14 02:02:18 +00:00
|
|
|
case ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER:
|
2010-02-11 00:34:43 +00:00
|
|
|
if(!alcCaptureDeviceList)
|
|
|
|
ProbeCaptureDeviceList();
|
|
|
|
|
2009-08-28 03:13:35 +00:00
|
|
|
free(alcCaptureDefaultDeviceSpecifier);
|
|
|
|
alcCaptureDefaultDeviceSpecifier = strdup(alcCaptureDeviceList ?
|
|
|
|
alcCaptureDeviceList : "");
|
|
|
|
if(!alcCaptureDefaultDeviceSpecifier)
|
2009-12-29 07:19:13 +00:00
|
|
|
alcSetError(pDevice, ALC_OUT_OF_MEMORY);
|
2007-11-14 02:02:18 +00:00
|
|
|
value = alcCaptureDefaultDeviceSpecifier;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALC_EXTENSIONS:
|
2010-03-18 02:46:20 +00:00
|
|
|
if(IsDevice(pDevice))
|
|
|
|
value = alcExtensionList;
|
|
|
|
else
|
|
|
|
value = alcNoDeviceExtList;
|
2007-11-14 02:02:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2009-12-29 07:19:13 +00:00
|
|
|
alcSetError(pDevice, ALC_INVALID_ENUM);
|
2007-11-14 02:02:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
alcGetIntegerv
|
|
|
|
|
|
|
|
Returns information about the Device and the version of Open AL
|
|
|
|
*/
|
2010-03-19 21:34:18 +00:00
|
|
|
ALC_API ALCvoid ALC_APIENTRY alcGetIntegerv(ALCdevice *device,ALCenum param,ALsizei size,ALCint *data)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
2010-01-08 09:21:57 +00:00
|
|
|
if(size == 0 || data == NULL)
|
|
|
|
{
|
|
|
|
alcSetError(device, ALC_INVALID_VALUE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-15 16:55:08 +00:00
|
|
|
if(IsDevice(device) && device->IsCaptureDevice)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
|
|
|
SuspendContext(NULL);
|
|
|
|
|
|
|
|
// Capture device
|
|
|
|
switch (param)
|
|
|
|
{
|
|
|
|
case ALC_CAPTURE_SAMPLES:
|
2010-01-08 09:21:57 +00:00
|
|
|
*data = ALCdevice_AvailableSamples(device);
|
2007-11-14 02:02:18 +00:00
|
|
|
break;
|
|
|
|
|
2009-08-27 02:15:17 +00:00
|
|
|
case ALC_CONNECTED:
|
2010-01-08 09:21:57 +00:00
|
|
|
*data = device->Connected;
|
2009-08-27 02:15:17 +00:00
|
|
|
break;
|
|
|
|
|
2007-11-14 02:02:18 +00:00
|
|
|
default:
|
2009-12-29 07:19:13 +00:00
|
|
|
alcSetError(device, ALC_INVALID_ENUM);
|
2007-11-14 02:02:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessContext(NULL);
|
2010-01-08 09:21:57 +00:00
|
|
|
return;
|
2007-11-14 02:02:18 +00:00
|
|
|
}
|
2010-01-08 09:21:57 +00:00
|
|
|
|
|
|
|
// Playback Device
|
|
|
|
switch (param)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
2010-01-08 09:21:57 +00:00
|
|
|
case ALC_MAJOR_VERSION:
|
|
|
|
*data = alcMajorVersion;
|
|
|
|
break;
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-01-08 09:21:57 +00:00
|
|
|
case ALC_MINOR_VERSION:
|
|
|
|
*data = alcMinorVersion;
|
|
|
|
break;
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-01-08 09:21:57 +00:00
|
|
|
case ALC_EFX_MAJOR_VERSION:
|
|
|
|
*data = alcEFXMajorVersion;
|
|
|
|
break;
|
2007-12-18 00:55:07 +00:00
|
|
|
|
2010-01-08 09:21:57 +00:00
|
|
|
case ALC_EFX_MINOR_VERSION:
|
|
|
|
*data = alcEFXMinorVersion;
|
|
|
|
break;
|
2007-12-18 00:55:07 +00:00
|
|
|
|
2010-01-08 09:21:57 +00:00
|
|
|
case ALC_MAX_AUXILIARY_SENDS:
|
|
|
|
if(!IsDevice(device))
|
|
|
|
alcSetError(device, ALC_INVALID_DEVICE);
|
|
|
|
else
|
|
|
|
*data = device->NumAuxSends;
|
|
|
|
break;
|
2007-12-18 00:55:07 +00:00
|
|
|
|
2010-01-08 09:21:57 +00:00
|
|
|
case ALC_ATTRIBUTES_SIZE:
|
|
|
|
if(!IsDevice(device))
|
|
|
|
alcSetError(device, ALC_INVALID_DEVICE);
|
|
|
|
else
|
|
|
|
*data = 13;
|
|
|
|
break;
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-01-08 09:21:57 +00:00
|
|
|
case ALC_ALL_ATTRIBUTES:
|
|
|
|
if(!IsDevice(device))
|
|
|
|
alcSetError(device, ALC_INVALID_DEVICE);
|
|
|
|
else if (size < 13)
|
|
|
|
alcSetError(device, ALC_INVALID_VALUE);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int i = 0;
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-01-08 09:21:57 +00:00
|
|
|
SuspendContext(NULL);
|
|
|
|
data[i++] = ALC_FREQUENCY;
|
|
|
|
data[i++] = device->Frequency;
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-01-08 09:21:57 +00:00
|
|
|
data[i++] = ALC_REFRESH;
|
|
|
|
data[i++] = device->Frequency / device->UpdateSize;
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-01-08 09:21:57 +00:00
|
|
|
data[i++] = ALC_SYNC;
|
|
|
|
data[i++] = ALC_FALSE;
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-01-08 09:21:57 +00:00
|
|
|
data[i++] = ALC_MONO_SOURCES;
|
|
|
|
data[i++] = device->lNumMonoSources;
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-01-08 09:21:57 +00:00
|
|
|
data[i++] = ALC_STEREO_SOURCES;
|
|
|
|
data[i++] = device->lNumStereoSources;
|
2007-12-18 00:55:07 +00:00
|
|
|
|
2010-01-08 09:21:57 +00:00
|
|
|
data[i++] = ALC_MAX_AUXILIARY_SENDS;
|
|
|
|
data[i++] = device->NumAuxSends;
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-01-08 09:21:57 +00:00
|
|
|
data[i++] = 0;
|
|
|
|
ProcessContext(NULL);
|
|
|
|
}
|
|
|
|
break;
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-01-08 09:21:57 +00:00
|
|
|
case ALC_FREQUENCY:
|
|
|
|
if(!IsDevice(device))
|
|
|
|
alcSetError(device, ALC_INVALID_DEVICE);
|
|
|
|
else
|
|
|
|
*data = device->Frequency;
|
|
|
|
break;
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-01-08 09:21:57 +00:00
|
|
|
case ALC_REFRESH:
|
|
|
|
if(!IsDevice(device))
|
|
|
|
alcSetError(device, ALC_INVALID_DEVICE);
|
|
|
|
else
|
|
|
|
*data = device->Frequency / device->UpdateSize;
|
|
|
|
break;
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-01-08 09:21:57 +00:00
|
|
|
case ALC_SYNC:
|
|
|
|
if(!IsDevice(device))
|
|
|
|
alcSetError(device, ALC_INVALID_DEVICE);
|
|
|
|
else
|
|
|
|
*data = ALC_FALSE;
|
|
|
|
break;
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-01-08 09:21:57 +00:00
|
|
|
case ALC_MONO_SOURCES:
|
|
|
|
if(!IsDevice(device))
|
|
|
|
alcSetError(device, ALC_INVALID_DEVICE);
|
|
|
|
else
|
|
|
|
*data = device->lNumMonoSources;
|
|
|
|
break;
|
2008-01-10 16:24:23 +00:00
|
|
|
|
2010-01-08 09:21:57 +00:00
|
|
|
case ALC_STEREO_SOURCES:
|
|
|
|
if(!IsDevice(device))
|
|
|
|
alcSetError(device, ALC_INVALID_DEVICE);
|
|
|
|
else
|
|
|
|
*data = device->lNumStereoSources;
|
|
|
|
break;
|
2008-01-10 16:24:23 +00:00
|
|
|
|
2010-01-08 09:21:57 +00:00
|
|
|
case ALC_CONNECTED:
|
|
|
|
if(!IsDevice(device))
|
|
|
|
alcSetError(device, ALC_INVALID_DEVICE);
|
|
|
|
else
|
|
|
|
*data = device->Connected;
|
|
|
|
break;
|
2009-08-27 02:15:17 +00:00
|
|
|
|
2010-01-08 09:21:57 +00:00
|
|
|
default:
|
|
|
|
alcSetError(device, ALC_INVALID_ENUM);
|
|
|
|
break;
|
2007-11-14 02:02:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
alcIsExtensionPresent
|
|
|
|
|
|
|
|
Determines if there is support for a particular extension
|
|
|
|
*/
|
2010-03-19 21:34:18 +00:00
|
|
|
ALC_API ALCboolean ALC_APIENTRY alcIsExtensionPresent(ALCdevice *device, const ALCchar *extName)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
|
|
|
ALCboolean bResult = ALC_FALSE;
|
2010-03-20 03:49:23 +00:00
|
|
|
const char *ptr;
|
|
|
|
size_t len;
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
if(!extName)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
2010-03-20 03:49:23 +00:00
|
|
|
alcSetError(device, ALC_INVALID_VALUE);
|
|
|
|
return ALC_FALSE;
|
|
|
|
}
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
len = strlen(extName);
|
|
|
|
ptr = (IsDevice(device) ? alcExtensionList : alcNoDeviceExtList);
|
|
|
|
while(ptr && *ptr)
|
|
|
|
{
|
|
|
|
if(strncasecmp(ptr, extName, len) == 0 &&
|
|
|
|
(ptr[len] == '\0' || isspace(ptr[len])))
|
2008-01-20 04:02:40 +00:00
|
|
|
{
|
2010-03-20 03:49:23 +00:00
|
|
|
bResult = ALC_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if((ptr=strchr(ptr, ' ')) != NULL)
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
++ptr;
|
|
|
|
} while(isspace(*ptr));
|
2008-01-20 04:02:40 +00:00
|
|
|
}
|
2007-11-14 02:02:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return bResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
alcGetProcAddress
|
|
|
|
|
|
|
|
Retrieves the function address for a particular extension function
|
|
|
|
*/
|
2010-03-19 21:34:18 +00:00
|
|
|
ALC_API ALCvoid* ALC_APIENTRY alcGetProcAddress(ALCdevice *device, const ALCchar *funcName)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
|
|
|
ALsizei i = 0;
|
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
if(!funcName)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
2009-12-29 07:19:13 +00:00
|
|
|
alcSetError(device, ALC_INVALID_VALUE);
|
2010-03-20 03:49:23 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
while(alcFunctions[i].funcName && strcmp(alcFunctions[i].funcName,funcName) != 0)
|
|
|
|
i++;
|
|
|
|
return alcFunctions[i].address;
|
2007-11-14 02:02:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
alcGetEnumValue
|
|
|
|
|
|
|
|
Get the value for a particular ALC Enumerated Value
|
|
|
|
*/
|
2010-03-19 21:34:18 +00:00
|
|
|
ALC_API ALCenum ALC_APIENTRY alcGetEnumValue(ALCdevice *device, const ALCchar *enumName)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
|
|
|
ALsizei i = 0;
|
|
|
|
ALCenum val;
|
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
while(enumeration[i].enumName && strcmp(enumeration[i].enumName,enumName) == 0)
|
2007-11-14 02:02:18 +00:00
|
|
|
i++;
|
|
|
|
val = enumeration[i].value;
|
|
|
|
|
|
|
|
if(!enumeration[i].enumName)
|
2009-12-29 07:19:13 +00:00
|
|
|
alcSetError(device, ALC_INVALID_VALUE);
|
2007-11-14 02:02:18 +00:00
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
alcCreateContext
|
|
|
|
|
|
|
|
Create and attach a Context to a particular Device.
|
|
|
|
*/
|
2010-03-19 21:34:18 +00:00
|
|
|
ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCint *attrList)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
2009-09-24 21:51:40 +00:00
|
|
|
ALuint attrIdx, reqStereoSources;
|
2009-09-24 18:31:01 +00:00
|
|
|
ALCcontext *ALContext;
|
2009-10-20 18:54:04 +00:00
|
|
|
void *temp;
|
2009-10-20 19:53:07 +00:00
|
|
|
ALuint i;
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2009-09-24 18:31:01 +00:00
|
|
|
SuspendContext(NULL);
|
|
|
|
|
|
|
|
if(!IsDevice(device) || device->IsCaptureDevice || !device->Connected)
|
|
|
|
{
|
2009-12-29 07:19:13 +00:00
|
|
|
alcSetError(device, ALC_INVALID_DEVICE);
|
2009-09-24 18:31:01 +00:00
|
|
|
ProcessContext(NULL);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset Context Last Error code
|
2009-12-29 07:19:13 +00:00
|
|
|
device->LastError = ALC_NO_ERROR;
|
2009-09-24 18:31:01 +00:00
|
|
|
|
2009-10-20 19:58:19 +00:00
|
|
|
// If a context is already running on the device, stop playback so the
|
|
|
|
// device attributes can be updated
|
2009-10-20 18:54:04 +00:00
|
|
|
if(device->NumContexts > 0)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
2009-09-24 18:31:01 +00:00
|
|
|
ProcessContext(NULL);
|
2009-10-20 19:58:19 +00:00
|
|
|
ALCdevice_StopPlayback(device);
|
|
|
|
SuspendContext(NULL);
|
2009-09-24 18:31:01 +00:00
|
|
|
}
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2009-09-24 18:31:01 +00:00
|
|
|
// Check for attributes
|
|
|
|
if(attrList)
|
|
|
|
{
|
|
|
|
ALCint level = device->Bs2bLevel;
|
|
|
|
ALCuint freq = device->Frequency;
|
|
|
|
ALCint numMono = device->lNumMonoSources;
|
|
|
|
ALCint numStereo = device->lNumStereoSources;
|
|
|
|
ALCuint numSends = device->NumAuxSends;
|
|
|
|
|
2009-09-24 21:51:40 +00:00
|
|
|
attrIdx = 0;
|
|
|
|
while(attrList[attrIdx])
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
2009-12-28 21:08:15 +00:00
|
|
|
if(attrList[attrIdx] == ALC_FREQUENCY &&
|
|
|
|
!ConfigValueExists(NULL, "frequency"))
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
2009-09-24 21:51:40 +00:00
|
|
|
freq = attrList[attrIdx + 1];
|
2009-12-28 20:47:59 +00:00
|
|
|
if(freq < 8000)
|
|
|
|
freq = 8000;
|
2007-11-14 02:02:18 +00:00
|
|
|
}
|
|
|
|
|
2009-09-24 21:51:40 +00:00
|
|
|
if(attrList[attrIdx] == ALC_STEREO_SOURCES)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
2009-09-24 21:51:40 +00:00
|
|
|
reqStereoSources = attrList[attrIdx + 1];
|
|
|
|
if(reqStereoSources > device->MaxNoOfSources)
|
|
|
|
reqStereoSources = device->MaxNoOfSources;
|
2009-04-14 03:33:41 +00:00
|
|
|
|
2009-09-24 21:51:40 +00:00
|
|
|
numStereo = reqStereoSources;
|
2009-09-24 18:31:01 +00:00
|
|
|
numMono = device->MaxNoOfSources - numStereo;
|
2009-08-13 19:28:46 +00:00
|
|
|
}
|
|
|
|
|
2009-12-28 21:08:15 +00:00
|
|
|
if(attrList[attrIdx] == ALC_MAX_AUXILIARY_SENDS &&
|
|
|
|
!ConfigValueExists(NULL, "sends"))
|
2009-09-22 06:25:26 +00:00
|
|
|
{
|
2009-09-24 21:51:40 +00:00
|
|
|
numSends = attrList[attrIdx + 1];
|
|
|
|
if(numSends > MAX_SENDS)
|
|
|
|
numSends = MAX_SENDS;
|
2009-09-22 06:52:59 +00:00
|
|
|
}
|
2009-09-16 02:06:47 +00:00
|
|
|
|
2009-09-24 21:51:40 +00:00
|
|
|
attrIdx += 2;
|
2007-11-14 02:02:18 +00:00
|
|
|
}
|
2009-09-24 18:31:01 +00:00
|
|
|
|
2010-02-25 02:51:57 +00:00
|
|
|
device->UpdateSize = (ALuint64)device->UpdateSize * freq /
|
|
|
|
device->Frequency;
|
|
|
|
|
2009-12-28 21:08:15 +00:00
|
|
|
device->Bs2bLevel = level;
|
|
|
|
device->Frequency = freq;
|
2009-09-24 18:31:01 +00:00
|
|
|
device->lNumMonoSources = numMono;
|
|
|
|
device->lNumStereoSources = numStereo;
|
2009-12-28 21:08:15 +00:00
|
|
|
device->NumAuxSends = numSends;
|
2009-09-24 18:31:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(ALCdevice_ResetPlayback(device) == ALC_FALSE)
|
|
|
|
{
|
2009-12-29 07:19:13 +00:00
|
|
|
alcSetError(device, ALC_INVALID_DEVICE);
|
2009-09-27 11:58:42 +00:00
|
|
|
aluHandleDisconnect(device);
|
2009-09-24 18:31:01 +00:00
|
|
|
ProcessContext(NULL);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-10-20 19:53:07 +00:00
|
|
|
for(i = 0;i < device->NumContexts;i++)
|
|
|
|
{
|
2009-10-20 20:02:28 +00:00
|
|
|
ALCcontext *context = device->Contexts[i];
|
2009-10-20 19:53:07 +00:00
|
|
|
ALeffectslot *slot;
|
|
|
|
ALsource *source;
|
2009-10-20 20:02:28 +00:00
|
|
|
|
|
|
|
SuspendContext(context);
|
2010-03-16 22:37:41 +00:00
|
|
|
for(slot = context->EffectSlotList;slot != NULL;slot = slot->next)
|
2009-10-20 19:53:07 +00:00
|
|
|
{
|
|
|
|
if(!slot->EffectState)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(ALEffect_DeviceUpdate(slot->EffectState, device) == AL_FALSE)
|
|
|
|
{
|
2009-12-29 07:19:13 +00:00
|
|
|
alcSetError(device, ALC_INVALID_DEVICE);
|
2009-10-20 19:53:07 +00:00
|
|
|
aluHandleDisconnect(device);
|
2009-10-20 20:02:28 +00:00
|
|
|
ProcessContext(context);
|
2009-10-20 19:53:07 +00:00
|
|
|
ProcessContext(NULL);
|
|
|
|
ALCdevice_StopPlayback(device);
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-10-20 20:02:28 +00:00
|
|
|
ALEffect_Update(slot->EffectState, context, &slot->effect);
|
2009-10-20 19:53:07 +00:00
|
|
|
}
|
|
|
|
|
2010-03-16 22:37:41 +00:00
|
|
|
for(source = context->SourceList;source != NULL;source = source->next)
|
2009-10-20 19:53:07 +00:00
|
|
|
{
|
|
|
|
ALuint s = device->NumAuxSends;
|
|
|
|
while(s < MAX_SENDS)
|
|
|
|
{
|
|
|
|
if(source->Send[s].Slot)
|
|
|
|
source->Send[s].Slot->refcount--;
|
|
|
|
source->Send[s].Slot = NULL;
|
|
|
|
source->Send[s].WetFilter.type = 0;
|
|
|
|
source->Send[s].WetFilter.filter = 0;
|
|
|
|
s++;
|
|
|
|
}
|
2009-11-26 00:28:19 +00:00
|
|
|
source->NeedsUpdate = AL_TRUE;
|
2009-10-20 19:53:07 +00:00
|
|
|
}
|
2009-12-27 04:27:14 +00:00
|
|
|
aluInitPanning(context);
|
2009-10-20 20:02:28 +00:00
|
|
|
ProcessContext(context);
|
2009-10-20 19:53:07 +00:00
|
|
|
}
|
|
|
|
|
2009-09-24 18:31:01 +00:00
|
|
|
if(device->Bs2bLevel > 0 && device->Bs2bLevel <= 6)
|
|
|
|
{
|
|
|
|
if(!device->Bs2b)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
2009-09-24 18:31:01 +00:00
|
|
|
device->Bs2b = calloc(1, sizeof(*device->Bs2b));
|
|
|
|
bs2b_clear(device->Bs2b);
|
2007-11-14 02:02:18 +00:00
|
|
|
}
|
2009-09-24 18:31:01 +00:00
|
|
|
bs2b_set_srate(device->Bs2b, device->Frequency);
|
|
|
|
bs2b_set_level(device->Bs2b, device->Bs2bLevel);
|
2007-11-14 02:02:18 +00:00
|
|
|
}
|
|
|
|
else
|
2009-09-24 18:31:01 +00:00
|
|
|
{
|
|
|
|
free(device->Bs2b);
|
|
|
|
device->Bs2b = NULL;
|
|
|
|
}
|
|
|
|
|
2009-10-20 18:54:04 +00:00
|
|
|
temp = realloc(device->Contexts, (device->NumContexts+1) * sizeof(*device->Contexts));
|
|
|
|
if(!temp)
|
|
|
|
{
|
2009-12-29 07:19:13 +00:00
|
|
|
alcSetError(device, ALC_OUT_OF_MEMORY);
|
2009-10-20 18:54:04 +00:00
|
|
|
ProcessContext(NULL);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
device->Contexts = temp;
|
|
|
|
|
2009-09-24 18:31:01 +00:00
|
|
|
ALContext = calloc(1, sizeof(ALCcontext));
|
|
|
|
if(!ALContext)
|
|
|
|
{
|
2009-12-29 07:19:13 +00:00
|
|
|
alcSetError(device, ALC_OUT_OF_MEMORY);
|
2009-09-24 18:31:01 +00:00
|
|
|
ProcessContext(NULL);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-10-20 18:54:04 +00:00
|
|
|
device->Contexts[device->NumContexts++] = ALContext;
|
2009-09-24 18:31:01 +00:00
|
|
|
ALContext->Device = device;
|
|
|
|
|
2009-10-20 18:54:04 +00:00
|
|
|
InitContext(ALContext);
|
2009-12-27 04:27:14 +00:00
|
|
|
aluInitPanning(ALContext);
|
2009-09-24 18:31:01 +00:00
|
|
|
|
|
|
|
ALContext->next = g_pContextList;
|
|
|
|
g_pContextList = ALContext;
|
|
|
|
g_ulContextCount++;
|
|
|
|
|
|
|
|
ProcessContext(NULL);
|
2007-11-14 02:02:18 +00:00
|
|
|
|
|
|
|
return ALContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
alcDestroyContext
|
|
|
|
|
|
|
|
Remove a Context
|
|
|
|
*/
|
2010-03-19 21:34:18 +00:00
|
|
|
ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
2010-03-20 03:49:23 +00:00
|
|
|
ALCdevice *Device;
|
2007-11-14 02:02:18 +00:00
|
|
|
ALCcontext **list;
|
2009-10-20 18:54:04 +00:00
|
|
|
ALuint i;
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
if(!IsContext(context))
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
2010-03-20 03:49:23 +00:00
|
|
|
alcSetError(NULL, ALC_INVALID_CONTEXT);
|
|
|
|
return;
|
|
|
|
}
|
2009-10-20 18:54:04 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
Device = context->Device;
|
2009-10-20 18:54:04 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
if(Device->NumContexts == 1)
|
|
|
|
ALCdevice_StopPlayback(Device);
|
2009-10-20 18:54:04 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
SuspendContext(NULL);
|
|
|
|
|
|
|
|
for(i = 0;i < Device->NumContexts-1;i++)
|
|
|
|
{
|
|
|
|
if(Device->Contexts[i] == context)
|
2009-10-20 18:54:04 +00:00
|
|
|
{
|
2010-03-20 03:49:23 +00:00
|
|
|
Device->Contexts[i] = Device->Contexts[Device->NumContexts-1];
|
|
|
|
break;
|
2009-10-20 18:54:04 +00:00
|
|
|
}
|
2010-03-20 03:49:23 +00:00
|
|
|
}
|
|
|
|
Device->NumContexts--;
|
2009-08-13 19:28:46 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
// Lock context
|
|
|
|
SuspendContext(context);
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
if(context->SourceCount > 0)
|
|
|
|
{
|
2009-08-16 23:11:22 +00:00
|
|
|
#ifdef _DEBUG
|
2010-03-20 03:49:23 +00:00
|
|
|
AL_PRINT("alcDestroyContext(): deleting %d Source(s)\n", context->SourceCount);
|
2009-08-16 23:11:22 +00:00
|
|
|
#endif
|
2010-03-20 03:49:23 +00:00
|
|
|
ReleaseALSources(context);
|
|
|
|
}
|
|
|
|
if(context->EffectSlotCount > 0)
|
|
|
|
{
|
2009-08-16 23:11:22 +00:00
|
|
|
#ifdef _DEBUG
|
2010-03-20 03:49:23 +00:00
|
|
|
AL_PRINT("alcDestroyContext(): deleting %d AuxiliaryEffectSlot(s)\n", context->EffectSlotCount);
|
2009-08-16 23:11:22 +00:00
|
|
|
#endif
|
2010-03-20 03:49:23 +00:00
|
|
|
ReleaseALAuxiliaryEffectSlots(context);
|
|
|
|
}
|
2008-01-16 00:22:39 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
list = &g_pContextList;
|
|
|
|
while(*list != context)
|
|
|
|
list = &(*list)->next;
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
*list = (*list)->next;
|
|
|
|
g_ulContextCount--;
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
// Unlock context
|
|
|
|
ProcessContext(context);
|
|
|
|
ProcessContext(NULL);
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
ExitContext(context);
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
// Free memory (MUST do this after ProcessContext)
|
|
|
|
memset(context, 0, sizeof(ALCcontext));
|
|
|
|
free(context);
|
2007-11-14 02:02:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
alcGetCurrentContext
|
|
|
|
|
|
|
|
Returns the currently active Context
|
|
|
|
*/
|
2010-03-19 21:34:18 +00:00
|
|
|
ALC_API ALCcontext* ALC_APIENTRY alcGetCurrentContext(ALCvoid)
|
2009-09-12 23:45:46 +00:00
|
|
|
{
|
|
|
|
ALCcontext *pContext;
|
|
|
|
|
|
|
|
if((pContext=GetContextSuspended()) != NULL)
|
|
|
|
ProcessContext(pContext);
|
|
|
|
|
|
|
|
return pContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
alcGetThreadContext
|
|
|
|
|
|
|
|
Returns the currently active thread-local Context
|
|
|
|
*/
|
2010-03-19 21:34:18 +00:00
|
|
|
ALCcontext* ALC_APIENTRY alcGetThreadContext(void)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
|
|
|
ALCcontext *pContext = NULL;
|
|
|
|
|
|
|
|
SuspendContext(NULL);
|
|
|
|
|
2009-09-12 23:45:46 +00:00
|
|
|
pContext = tls_get(LocalContext);
|
|
|
|
if(pContext && !IsContext(pContext))
|
|
|
|
{
|
|
|
|
tls_set(LocalContext, NULL);
|
|
|
|
pContext = NULL;
|
|
|
|
}
|
2007-11-14 02:02:18 +00:00
|
|
|
|
|
|
|
ProcessContext(NULL);
|
|
|
|
|
|
|
|
return pContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
alcGetContextsDevice
|
|
|
|
|
|
|
|
Returns the Device that a particular Context is attached to
|
|
|
|
*/
|
2010-03-19 21:34:18 +00:00
|
|
|
ALC_API ALCdevice* ALC_APIENTRY alcGetContextsDevice(ALCcontext *pContext)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
|
|
|
ALCdevice *pDevice = NULL;
|
|
|
|
|
|
|
|
SuspendContext(NULL);
|
2010-03-20 03:49:23 +00:00
|
|
|
if(IsContext(pContext))
|
2007-11-14 02:02:18 +00:00
|
|
|
pDevice = pContext->Device;
|
|
|
|
else
|
2009-12-29 07:19:13 +00:00
|
|
|
alcSetError(NULL, ALC_INVALID_CONTEXT);
|
2007-11-14 02:02:18 +00:00
|
|
|
ProcessContext(NULL);
|
|
|
|
|
|
|
|
return pDevice;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
alcMakeContextCurrent
|
|
|
|
|
|
|
|
Makes the given Context the active Context
|
|
|
|
*/
|
2010-03-19 21:34:18 +00:00
|
|
|
ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
|
|
|
ALCcontext *ALContext;
|
|
|
|
ALboolean bReturn = AL_TRUE;
|
|
|
|
|
|
|
|
SuspendContext(NULL);
|
|
|
|
|
|
|
|
// context must be a valid Context or NULL
|
2009-08-16 21:09:23 +00:00
|
|
|
if(context == NULL || IsContext(context))
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
2010-02-09 00:58:26 +00:00
|
|
|
ALContext = g_pContextList;
|
|
|
|
while(ALContext && !ALContext->InUse)
|
|
|
|
ALContext = ALContext->next;
|
|
|
|
|
|
|
|
if(ALContext != NULL)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
2010-02-09 00:58:26 +00:00
|
|
|
SuspendContext(ALContext);
|
2007-11-14 02:02:18 +00:00
|
|
|
ALContext->InUse=AL_FALSE;
|
|
|
|
ProcessContext(ALContext);
|
|
|
|
}
|
|
|
|
|
2009-08-16 21:09:23 +00:00
|
|
|
if((ALContext=context) != NULL && ALContext->Device)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
|
|
|
SuspendContext(ALContext);
|
|
|
|
ALContext->InUse=AL_TRUE;
|
|
|
|
ProcessContext(ALContext);
|
|
|
|
}
|
2009-09-12 23:45:46 +00:00
|
|
|
|
|
|
|
tls_set(LocalContext, NULL);
|
2007-11-14 02:02:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-29 07:19:13 +00:00
|
|
|
alcSetError(NULL, ALC_INVALID_CONTEXT);
|
2007-11-14 02:02:18 +00:00
|
|
|
bReturn = AL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessContext(NULL);
|
|
|
|
|
|
|
|
return bReturn;
|
|
|
|
}
|
|
|
|
|
2009-09-12 23:45:46 +00:00
|
|
|
/*
|
|
|
|
alcMakeCurrent
|
|
|
|
|
|
|
|
Makes the given Context the active Context for the current thread
|
|
|
|
*/
|
2010-03-19 21:34:18 +00:00
|
|
|
ALCboolean ALC_APIENTRY alcMakeCurrent(ALCcontext *context)
|
2009-09-12 23:45:46 +00:00
|
|
|
{
|
|
|
|
ALboolean bReturn = AL_TRUE;
|
|
|
|
|
|
|
|
SuspendContext(NULL);
|
|
|
|
|
|
|
|
// context must be a valid Context or NULL
|
|
|
|
if(context == NULL || IsContext(context))
|
|
|
|
tls_set(LocalContext, context);
|
|
|
|
else
|
|
|
|
{
|
2009-12-29 07:19:13 +00:00
|
|
|
alcSetError(NULL, ALC_INVALID_CONTEXT);
|
2009-09-12 23:45:46 +00:00
|
|
|
bReturn = AL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessContext(NULL);
|
|
|
|
|
|
|
|
return bReturn;
|
|
|
|
}
|
|
|
|
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2009-12-07 12:19:33 +00:00
|
|
|
// Sets the default channel order used by most non-WaveFormatEx-based APIs
|
|
|
|
void SetDefaultChannelOrder(ALCdevice *device)
|
|
|
|
{
|
|
|
|
switch(aluChannelsFromFormat(device->Format))
|
|
|
|
{
|
2009-12-21 10:59:30 +00:00
|
|
|
case 1: device->DevChannels[0] = FRONT_CENTER; break;
|
|
|
|
|
2009-12-07 12:19:33 +00:00
|
|
|
case 2: device->DevChannels[0] = FRONT_LEFT;
|
|
|
|
device->DevChannels[1] = FRONT_RIGHT; break;
|
|
|
|
|
|
|
|
case 4: device->DevChannels[0] = FRONT_LEFT;
|
|
|
|
device->DevChannels[1] = FRONT_RIGHT;
|
|
|
|
device->DevChannels[2] = BACK_LEFT;
|
|
|
|
device->DevChannels[3] = BACK_RIGHT; break;
|
|
|
|
|
|
|
|
case 6: device->DevChannels[0] = FRONT_LEFT;
|
|
|
|
device->DevChannels[1] = FRONT_RIGHT;
|
|
|
|
device->DevChannels[2] = BACK_LEFT;
|
|
|
|
device->DevChannels[3] = BACK_RIGHT;
|
|
|
|
device->DevChannels[4] = FRONT_CENTER;
|
|
|
|
device->DevChannels[5] = LFE; break;
|
|
|
|
|
|
|
|
case 7: device->DevChannels[0] = FRONT_LEFT;
|
|
|
|
device->DevChannels[1] = FRONT_RIGHT;
|
|
|
|
device->DevChannels[2] = FRONT_CENTER;
|
|
|
|
device->DevChannels[3] = LFE;
|
|
|
|
device->DevChannels[4] = BACK_CENTER;
|
|
|
|
device->DevChannels[5] = SIDE_LEFT;
|
|
|
|
device->DevChannels[6] = SIDE_RIGHT; break;
|
|
|
|
|
|
|
|
case 8: device->DevChannels[0] = FRONT_LEFT;
|
|
|
|
device->DevChannels[1] = FRONT_RIGHT;
|
|
|
|
device->DevChannels[2] = BACK_LEFT;
|
|
|
|
device->DevChannels[3] = BACK_RIGHT;
|
|
|
|
device->DevChannels[4] = FRONT_CENTER;
|
|
|
|
device->DevChannels[5] = LFE;
|
|
|
|
device->DevChannels[6] = SIDE_LEFT;
|
|
|
|
device->DevChannels[7] = SIDE_RIGHT; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Sets the default order used by WaveFormatEx
|
|
|
|
void SetDefaultWFXChannelOrder(ALCdevice *device)
|
|
|
|
{
|
|
|
|
switch(aluChannelsFromFormat(device->Format))
|
|
|
|
{
|
2009-12-21 10:59:30 +00:00
|
|
|
case 1: device->DevChannels[0] = FRONT_CENTER; break;
|
|
|
|
|
2009-12-07 12:19:33 +00:00
|
|
|
case 2: device->DevChannels[0] = FRONT_LEFT;
|
|
|
|
device->DevChannels[1] = FRONT_RIGHT; break;
|
|
|
|
|
|
|
|
case 4: device->DevChannels[0] = FRONT_LEFT;
|
|
|
|
device->DevChannels[1] = FRONT_RIGHT;
|
|
|
|
device->DevChannels[2] = BACK_LEFT;
|
|
|
|
device->DevChannels[3] = BACK_RIGHT; break;
|
|
|
|
|
|
|
|
case 6: device->DevChannels[0] = FRONT_LEFT;
|
|
|
|
device->DevChannels[1] = FRONT_RIGHT;
|
|
|
|
device->DevChannels[2] = FRONT_CENTER;
|
|
|
|
device->DevChannels[3] = LFE;
|
|
|
|
device->DevChannels[4] = BACK_LEFT;
|
|
|
|
device->DevChannels[5] = BACK_RIGHT; break;
|
|
|
|
|
|
|
|
case 7: device->DevChannels[0] = FRONT_LEFT;
|
|
|
|
device->DevChannels[1] = FRONT_RIGHT;
|
|
|
|
device->DevChannels[2] = FRONT_CENTER;
|
|
|
|
device->DevChannels[3] = LFE;
|
|
|
|
device->DevChannels[4] = BACK_CENTER;
|
|
|
|
device->DevChannels[5] = SIDE_LEFT;
|
|
|
|
device->DevChannels[6] = SIDE_RIGHT; break;
|
|
|
|
|
|
|
|
case 8: device->DevChannels[0] = FRONT_LEFT;
|
|
|
|
device->DevChannels[1] = FRONT_RIGHT;
|
|
|
|
device->DevChannels[2] = FRONT_CENTER;
|
|
|
|
device->DevChannels[3] = LFE;
|
|
|
|
device->DevChannels[4] = BACK_LEFT;
|
|
|
|
device->DevChannels[5] = BACK_RIGHT;
|
|
|
|
device->DevChannels[6] = SIDE_LEFT;
|
|
|
|
device->DevChannels[7] = SIDE_RIGHT; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-15 17:32:54 +00:00
|
|
|
static ALenum GetFormatFromString(const char *str)
|
|
|
|
{
|
2009-08-15 20:20:35 +00:00
|
|
|
if(strcasecmp(str, "AL_FORMAT_MONO32") == 0) return AL_FORMAT_MONO_FLOAT32;
|
|
|
|
if(strcasecmp(str, "AL_FORMAT_STEREO32") == 0) return AL_FORMAT_STEREO_FLOAT32;
|
|
|
|
if(strcasecmp(str, "AL_FORMAT_QUAD32") == 0) return AL_FORMAT_QUAD32;
|
|
|
|
if(strcasecmp(str, "AL_FORMAT_51CHN32") == 0) return AL_FORMAT_51CHN32;
|
|
|
|
if(strcasecmp(str, "AL_FORMAT_61CHN32") == 0) return AL_FORMAT_61CHN32;
|
|
|
|
if(strcasecmp(str, "AL_FORMAT_71CHN32") == 0) return AL_FORMAT_71CHN32;
|
|
|
|
|
2009-08-15 17:32:54 +00:00
|
|
|
if(strcasecmp(str, "AL_FORMAT_MONO16") == 0) return AL_FORMAT_MONO16;
|
|
|
|
if(strcasecmp(str, "AL_FORMAT_STEREO16") == 0) return AL_FORMAT_STEREO16;
|
|
|
|
if(strcasecmp(str, "AL_FORMAT_QUAD16") == 0) return AL_FORMAT_QUAD16;
|
|
|
|
if(strcasecmp(str, "AL_FORMAT_51CHN16") == 0) return AL_FORMAT_51CHN16;
|
|
|
|
if(strcasecmp(str, "AL_FORMAT_61CHN16") == 0) return AL_FORMAT_61CHN16;
|
|
|
|
if(strcasecmp(str, "AL_FORMAT_71CHN16") == 0) return AL_FORMAT_71CHN16;
|
|
|
|
|
|
|
|
if(strcasecmp(str, "AL_FORMAT_MONO8") == 0) return AL_FORMAT_MONO8;
|
|
|
|
if(strcasecmp(str, "AL_FORMAT_STEREO8") == 0) return AL_FORMAT_STEREO8;
|
|
|
|
if(strcasecmp(str, "AL_FORMAT_QUAD8") == 0) return AL_FORMAT_QUAD8;
|
|
|
|
if(strcasecmp(str, "AL_FORMAT_51CHN8") == 0) return AL_FORMAT_51CHN8;
|
|
|
|
if(strcasecmp(str, "AL_FORMAT_61CHN8") == 0) return AL_FORMAT_61CHN8;
|
|
|
|
if(strcasecmp(str, "AL_FORMAT_71CHN8") == 0) return AL_FORMAT_71CHN8;
|
|
|
|
|
|
|
|
AL_PRINT("Unknown format: \"%s\"\n", str);
|
|
|
|
return AL_FORMAT_STEREO16;
|
|
|
|
}
|
|
|
|
|
2007-11-14 02:02:18 +00:00
|
|
|
/*
|
|
|
|
alcOpenDevice
|
|
|
|
|
|
|
|
Open the Device specified.
|
|
|
|
*/
|
2010-03-19 21:34:18 +00:00
|
|
|
ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
|
|
|
ALboolean bDeviceFound = AL_FALSE;
|
2010-03-20 03:49:23 +00:00
|
|
|
const ALCchar *fmt;
|
2007-11-14 02:02:18 +00:00
|
|
|
ALCdevice *device;
|
|
|
|
ALint i;
|
|
|
|
|
2007-12-27 01:38:42 +00:00
|
|
|
if(deviceName && !deviceName[0])
|
|
|
|
deviceName = NULL;
|
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
device = calloc(1, sizeof(ALCdevice));
|
|
|
|
if(!device)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
2010-03-20 03:49:23 +00:00
|
|
|
alcSetError(NULL, ALC_OUT_OF_MEMORY);
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
//Validate device
|
|
|
|
device->Connected = ALC_TRUE;
|
|
|
|
device->IsCaptureDevice = AL_FALSE;
|
|
|
|
device->LastError = ALC_NO_ERROR;
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
device->Bs2b = NULL;
|
|
|
|
device->szDeviceName = NULL;
|
2009-08-27 09:53:09 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
device->Contexts = NULL;
|
|
|
|
device->NumContexts = 0;
|
2009-10-20 18:54:04 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
//Set output format
|
|
|
|
device->Frequency = GetConfigValueInt(NULL, "frequency", SWMIXER_OUTPUT_RATE);
|
|
|
|
if(device->Frequency < 8000)
|
|
|
|
device->Frequency = 8000;
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
fmt = GetConfigValue(NULL, "format", "AL_FORMAT_STEREO16");
|
|
|
|
device->Format = GetFormatFromString(fmt);
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
device->NumUpdates = GetConfigValueInt(NULL, "periods", 4);
|
|
|
|
if(device->NumUpdates < 2)
|
|
|
|
device->NumUpdates = 4;
|
2009-09-17 05:58:54 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
i = GetConfigValueInt(NULL, "refresh", 4096);
|
|
|
|
if(i <= 0) i = 4096;
|
2009-09-17 05:58:54 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
device->UpdateSize = GetConfigValueInt(NULL, "period_size", i/device->NumUpdates);
|
|
|
|
if(device->UpdateSize <= 0)
|
|
|
|
device->UpdateSize = i/device->NumUpdates;
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
device->MaxNoOfSources = GetConfigValueInt(NULL, "sources", 256);
|
|
|
|
if((ALint)device->MaxNoOfSources <= 0)
|
|
|
|
device->MaxNoOfSources = 256;
|
2008-01-20 03:28:34 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
device->AuxiliaryEffectSlotMax = GetConfigValueInt(NULL, "slots", 4);
|
|
|
|
if((ALint)device->AuxiliaryEffectSlotMax <= 0)
|
|
|
|
device->AuxiliaryEffectSlotMax = 4;
|
2009-06-07 21:53:22 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
device->lNumStereoSources = 1;
|
|
|
|
device->lNumMonoSources = device->MaxNoOfSources - device->lNumStereoSources;
|
2009-07-06 10:09:01 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
device->NumAuxSends = GetConfigValueInt(NULL, "sends", MAX_SENDS);
|
|
|
|
if(device->NumAuxSends > MAX_SENDS)
|
|
|
|
device->NumAuxSends = MAX_SENDS;
|
2009-07-06 10:09:01 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
device->Bs2bLevel = GetConfigValueInt(NULL, "cf_level", 0);
|
2009-09-16 02:06:47 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
if(aluChannelsFromFormat(device->Format) <= 2)
|
|
|
|
{
|
|
|
|
device->HeadDampen = GetConfigValueFloat(NULL, "head_dampen", DEFAULT_HEAD_DAMPEN);
|
|
|
|
device->HeadDampen = __min(device->HeadDampen, 1.0f);
|
|
|
|
device->HeadDampen = __max(device->HeadDampen, 0.0f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
device->HeadDampen = 0.0f;
|
2009-12-08 22:18:07 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
// Find a playback device to open
|
|
|
|
SuspendContext(NULL);
|
|
|
|
for(i = 0;BackendList[i].Init;i++)
|
|
|
|
{
|
|
|
|
device->Funcs = &BackendList[i].Funcs;
|
|
|
|
if(ALCdevice_OpenPlayback(device, deviceName))
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
2010-03-20 03:49:23 +00:00
|
|
|
device->next = g_pDeviceList;
|
|
|
|
g_pDeviceList = device;
|
|
|
|
g_ulDeviceCount++;
|
2008-01-14 18:39:54 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
bDeviceFound = AL_TRUE;
|
|
|
|
break;
|
2007-11-14 02:02:18 +00:00
|
|
|
}
|
2010-03-20 03:49:23 +00:00
|
|
|
}
|
|
|
|
ProcessContext(NULL);
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
if(!bDeviceFound)
|
|
|
|
{
|
|
|
|
// No suitable output device found
|
|
|
|
alcSetError(NULL, ALC_INVALID_VALUE);
|
|
|
|
free(device);
|
|
|
|
device = NULL;
|
2007-11-14 02:02:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
alcCloseDevice
|
|
|
|
|
|
|
|
Close the specified Device
|
|
|
|
*/
|
2010-03-19 21:34:18 +00:00
|
|
|
ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *pDevice)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
2008-01-14 18:39:54 +00:00
|
|
|
ALCdevice **list;
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
if(!IsDevice(pDevice) || pDevice->IsCaptureDevice)
|
2007-11-14 02:02:18 +00:00
|
|
|
{
|
2010-03-20 03:49:23 +00:00
|
|
|
alcSetError(pDevice, ALC_INVALID_DEVICE);
|
|
|
|
return ALC_FALSE;
|
|
|
|
}
|
2008-01-14 18:39:54 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
SuspendContext(NULL);
|
2008-01-14 18:39:54 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
list = &g_pDeviceList;
|
|
|
|
while(*list != pDevice)
|
|
|
|
list = &(*list)->next;
|
2008-01-14 18:39:54 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
*list = (*list)->next;
|
|
|
|
g_ulDeviceCount--;
|
2008-01-14 18:39:54 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
ProcessContext(NULL);
|
|
|
|
|
|
|
|
if(pDevice->NumContexts > 0)
|
|
|
|
{
|
2008-07-22 21:29:27 +00:00
|
|
|
#ifdef _DEBUG
|
2010-03-20 03:49:23 +00:00
|
|
|
AL_PRINT("alcCloseDevice(): destroying %u Context(s)\n", pDevice->NumContexts);
|
2008-07-22 21:29:27 +00:00
|
|
|
#endif
|
2010-03-20 03:49:23 +00:00
|
|
|
while(pDevice->NumContexts > 0)
|
|
|
|
alcDestroyContext(pDevice->Contexts[0]);
|
|
|
|
}
|
|
|
|
ALCdevice_ClosePlayback(pDevice);
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
if(pDevice->BufferCount > 0)
|
|
|
|
{
|
2009-08-15 16:14:08 +00:00
|
|
|
#ifdef _DEBUG
|
2010-03-20 03:49:23 +00:00
|
|
|
AL_PRINT("alcCloseDevice(): deleting %d Buffer(s)\n", pDevice->BufferCount);
|
2009-08-15 16:14:08 +00:00
|
|
|
#endif
|
2010-03-20 03:49:23 +00:00
|
|
|
ReleaseALBuffers(pDevice);
|
|
|
|
}
|
|
|
|
if(pDevice->EffectCount > 0)
|
|
|
|
{
|
2009-08-15 16:39:18 +00:00
|
|
|
#ifdef _DEBUG
|
2010-03-20 03:49:23 +00:00
|
|
|
AL_PRINT("alcCloseDevice(): deleting %d Effect(s)\n", pDevice->EffectCount);
|
2009-08-15 16:39:18 +00:00
|
|
|
#endif
|
2010-03-20 03:49:23 +00:00
|
|
|
ReleaseALEffects(pDevice);
|
|
|
|
}
|
|
|
|
if(pDevice->FilterCount > 0)
|
|
|
|
{
|
2009-08-15 16:39:18 +00:00
|
|
|
#ifdef _DEBUG
|
2010-03-20 03:49:23 +00:00
|
|
|
AL_PRINT("alcCloseDevice(): deleting %d Filter(s)\n", pDevice->FilterCount);
|
2009-08-15 16:39:18 +00:00
|
|
|
#endif
|
2010-03-20 03:49:23 +00:00
|
|
|
ReleaseALFilters(pDevice);
|
|
|
|
}
|
|
|
|
if(pDevice->DatabufferCount > 0)
|
|
|
|
{
|
2009-08-16 07:54:08 +00:00
|
|
|
#ifdef _DEBUG
|
2010-03-20 03:49:23 +00:00
|
|
|
AL_PRINT("alcCloseDevice(): deleting %d Databuffer(s)\n", pDevice->DatabufferCount);
|
2009-08-16 07:54:08 +00:00
|
|
|
#endif
|
2010-03-20 03:49:23 +00:00
|
|
|
ReleaseALDatabuffers(pDevice);
|
|
|
|
}
|
2009-09-16 02:06:47 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
free(pDevice->Bs2b);
|
|
|
|
pDevice->Bs2b = NULL;
|
2009-10-20 18:54:04 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
free(pDevice->szDeviceName);
|
|
|
|
pDevice->szDeviceName = NULL;
|
2009-08-27 09:53:09 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
free(pDevice->Contexts);
|
|
|
|
pDevice->Contexts = NULL;
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
//Release device structure
|
|
|
|
memset(pDevice, 0, sizeof(ALCdevice));
|
|
|
|
free(pDevice);
|
2007-11-14 02:02:18 +00:00
|
|
|
|
2010-03-20 03:49:23 +00:00
|
|
|
return ALC_TRUE;
|
2007-11-14 02:02:18 +00:00
|
|
|
}
|
2008-01-14 18:54:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
ALCvoid ReleaseALC(ALCvoid)
|
|
|
|
{
|
2009-08-27 10:55:36 +00:00
|
|
|
free(alcDeviceList); alcDeviceList = NULL;
|
|
|
|
alcDeviceListSize = 0;
|
|
|
|
free(alcAllDeviceList); alcAllDeviceList = NULL;
|
|
|
|
alcAllDeviceListSize = 0;
|
|
|
|
free(alcCaptureDeviceList); alcCaptureDeviceList = NULL;
|
|
|
|
alcCaptureDeviceListSize = 0;
|
|
|
|
|
2009-08-28 03:13:35 +00:00
|
|
|
free(alcDefaultDeviceSpecifier);
|
2009-08-27 10:55:36 +00:00
|
|
|
alcDefaultDeviceSpecifier = NULL;
|
2009-08-28 03:13:35 +00:00
|
|
|
free(alcDefaultAllDeviceSpecifier);
|
2009-08-27 10:55:36 +00:00
|
|
|
alcDefaultAllDeviceSpecifier = NULL;
|
2009-08-28 03:13:35 +00:00
|
|
|
free(alcCaptureDefaultDeviceSpecifier);
|
2009-08-27 10:55:36 +00:00
|
|
|
alcCaptureDefaultDeviceSpecifier = NULL;
|
|
|
|
|
2008-01-14 18:54:33 +00:00
|
|
|
#ifdef _DEBUG
|
2008-07-22 21:29:27 +00:00
|
|
|
if(g_ulDeviceCount > 0)
|
|
|
|
AL_PRINT("exit(): closing %u Device%s\n", g_ulDeviceCount, (g_ulDeviceCount>1)?"s":"");
|
2008-01-14 18:54:33 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
while(g_pDeviceList)
|
|
|
|
{
|
2008-02-08 22:44:05 +00:00
|
|
|
if(g_pDeviceList->IsCaptureDevice)
|
|
|
|
alcCaptureCloseDevice(g_pDeviceList);
|
2008-01-14 18:54:33 +00:00
|
|
|
else
|
2008-02-08 22:44:05 +00:00
|
|
|
alcCloseDevice(g_pDeviceList);
|
2008-01-14 18:54:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-14 02:02:18 +00:00
|
|
|
///////////////////////////////////////////////////////
|