Compare commits
193 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 61122a5093 | |||
| a8a4ff8af1 | |||
| 8a857c35ee | |||
| 89ddd7d8e5 | |||
| 8d0c4ccb3b | |||
| 8ee47d5573 | |||
| 9e88011417 | |||
| f8949ee7a1 | |||
| 62aa2d0ba7 | |||
| ace047d625 | |||
| d6277db209 | |||
| 7ebb28327f | |||
| 86931cbde4 | |||
| 6d7be151dc | |||
| 07227b9806 | |||
| 8348d719cd | |||
| 0fcefd865b | |||
| 57c2e9b5f8 | |||
| 7d7fc39035 | |||
| 351105b3df | |||
| cbfc33215b | |||
| 5a93b56673 | |||
| 1f4c69c17a | |||
| f5b19fad20 | |||
| bc60818e9a | |||
| f82c88f016 | |||
| 98e86decad | |||
| aaf2c0ebd4 | |||
| 778b74cae1 | |||
| 43ee1edd97 | |||
| dd7e23740b | |||
| 1acd6da745 | |||
| 3056f91ec5 | |||
| ed03570e1a | |||
| 2ec0e48d06 | |||
| 8b54d59b8c | |||
| f6a4dbabdd | |||
| a71c291bcb | |||
| 55b9ccc2de | |||
| 67d67a3bf6 | |||
| 591de1ecb4 | |||
| 3dad17c263 | |||
| eefc18170d | |||
| 5f84c5339d | |||
| 2d461379ef | |||
| c8123756ff | |||
| 76c7789ee7 | |||
| 13a2e6ef1f | |||
| 0ecb34b850 | |||
| 1f86c48d95 | |||
| 7e1295df9a | |||
| 482b160c8a | |||
| 181eb95b13 | |||
| c0ccd31a3e | |||
| d72b132c57 | |||
| 506912aed7 | |||
| 670d70d3c9 | |||
| 010f7d12f4 | |||
| da684564ea | |||
| fc4c867f27 | |||
| 9ba30c4e20 | |||
| 15334e56cd | |||
| ffa42ff22c | |||
| a7c62dbabc | |||
| eda1e41152 | |||
| af5a5b76ec | |||
| 87f3a0dc16 | |||
| 2c80a80704 | |||
| 301a4c4a95 | |||
| 8fc4a3b724 | |||
| cb6f040005 | |||
| b91c2e4a99 | |||
| 59a71b1454 | |||
| 36f133a5ae | |||
| 74a58c0d09 | |||
| bfa1107781 | |||
| 11397f7667 | |||
| 6e9e8239ef | |||
| af9932d28b | |||
| 87ff8a65e9 | |||
| 7b6f207790 | |||
| 8672008e43 | |||
| c8cd193346 | |||
| be292e5f0b | |||
| 3863dcc9cb | |||
| a2568409fc | |||
| 6567cdd7b5 | |||
| 5bbf55a401 | |||
| 4a530e2146 | |||
| 27ba8f7b60 | |||
| 6bfdb57a5b | |||
| 26e8ea60a5 | |||
| f4ea188ffa | |||
| 1266580420 | |||
| 16d96eed7b | |||
| fa76168683 | |||
| 5f3329b2c9 | |||
| db541f3cfa | |||
| 3e19ba6ca8 | |||
| ac8c082b89 | |||
| 084df2a229 | |||
| 22557070ec | |||
| f8ef66954c | |||
| ef59901e7c | |||
| cfe620ccb5 | |||
| 453b015225 | |||
| c1cf9ae8f6 | |||
| f1414c650e | |||
| 869b041f2f | |||
| 8621fbb015 | |||
| 597e01153e | |||
| d3e5fcd13e | |||
| 3e0f9cc716 | |||
| c7e49c9f57 | |||
| e2ed8ff2bf | |||
| 559c786d0c | |||
| c3a7480961 | |||
| a75e75aef5 | |||
| d45b1207d0 | |||
| 5a9e24dea1 | |||
| dc8132e965 | |||
| 20bcdc1ef6 | |||
| 93c0f61050 | |||
| 3a8c543f8b | |||
| 9e96156451 | |||
| 19aabd6d02 | |||
| 87b5d7bc7b | |||
| 646714b585 | |||
| eba60c30c5 | |||
| e66bb09156 | |||
| 0042b1f80d | |||
| 6d416ee734 | |||
| 97d3a45aff | |||
| 9e9ff44b17 | |||
| f369be148f | |||
| 3a09e446b3 | |||
| 2d0b12e49e | |||
| 55e2f294ac | |||
| 2a4b467f08 | |||
| 2ae9da696a | |||
| 376997c3ef | |||
| e963782b8c | |||
| 86c01aa62c | |||
| 15783d25e7 | |||
| 3243f69f21 | |||
| 10a87f510c | |||
| ca6feeda29 | |||
| cecf778de3 | |||
| fe79ab351a | |||
| dc0a3a6653 | |||
| fed346c285 | |||
| cad9b367a5 | |||
| 6e86146a25 | |||
| 49d9695ad9 | |||
| e15bc6b9ba | |||
| 28093a6dcb | |||
| 2af5498804 | |||
| 2b42d7fdb8 | |||
| 9b3c4faa34 | |||
| 847b3e8b61 | |||
| b1bdd7c89f | |||
| ffe7a11866 | |||
| 8c3188bc7d | |||
| 880196e5a8 | |||
| d523b440e3 | |||
| f2875d5d13 | |||
| b0720333cc | |||
| c3446a10fa | |||
| fbc869eed7 | |||
| e3e4dbbccf | |||
| 7fda645b16 | |||
| ec7f20644d | |||
| 3d5fa91703 | |||
| e8acfb069c | |||
| 4c38ed272d | |||
| acbb4f8e6c | |||
| 13a3fe8a7a | |||
| 3dd3cd4ceb | |||
| 80fcbc8adc | |||
| 33680accea | |||
| 081e593e2b | |||
| b4ffdfab81 | |||
| 1ea4aac799 | |||
| 4d6c292757 | |||
| 655a83c5c5 | |||
| e8b576bc25 | |||
| 01404ed7af | |||
| ad6237f6f7 | |||
| d06c64e1c4 | |||
| b4ad3186dd | |||
| 5f1c0450b3 | |||
| 04b62f77e3 | |||
| 029dff3f40 |
@@ -33,9 +33,11 @@
|
||||
#include "AL/alc.h"
|
||||
#include "alThunk.h"
|
||||
#include "alSource.h"
|
||||
#include "alBuffer.h"
|
||||
#include "alExtension.h"
|
||||
#include "alAuxEffectSlot.h"
|
||||
#include "bs2b.h"
|
||||
#include "alu.h"
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
// DEBUG INFORMATION
|
||||
@@ -46,7 +48,7 @@ char _alDebug[256];
|
||||
|
||||
|
||||
#define EmptyFuncs { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
|
||||
struct {
|
||||
static struct {
|
||||
const char *name;
|
||||
void (*Init)(BackendFuncs*);
|
||||
BackendFuncs Funcs;
|
||||
@@ -57,12 +59,18 @@ struct {
|
||||
#ifdef HAVE_OSS
|
||||
{ "oss", alc_oss_init, EmptyFuncs },
|
||||
#endif
|
||||
#ifdef HAVE_SOLARIS
|
||||
{ "solaris", alc_solaris_init, EmptyFuncs },
|
||||
#endif
|
||||
#ifdef HAVE_DSOUND
|
||||
{ "dsound", alcDSoundInit, EmptyFuncs },
|
||||
#endif
|
||||
#ifdef HAVE_WINMM
|
||||
{ "winmm", alcWinMMInit, EmptyFuncs },
|
||||
#endif
|
||||
#ifdef HAVE_PORTAUDIO
|
||||
{ "port", alc_pa_init, EmptyFuncs },
|
||||
#endif
|
||||
|
||||
{ "wave", alc_wave_init, EmptyFuncs },
|
||||
|
||||
@@ -182,6 +190,8 @@ static ALCint alcEFXMinorVersion = 0;
|
||||
static ALCdevice *g_pDeviceList = NULL;
|
||||
static ALCuint g_ulDeviceCount = 0;
|
||||
|
||||
static CRITICAL_SECTION g_csMutex;
|
||||
|
||||
// Context List
|
||||
static ALCcontext *g_pContextList = NULL;
|
||||
static ALCuint g_ulContextCount = 0;
|
||||
@@ -189,21 +199,69 @@ static ALCuint g_ulContextCount = 0;
|
||||
// Context Error
|
||||
static ALCenum g_eLastContextError = ALC_NO_ERROR;
|
||||
|
||||
static ALboolean init_done = AL_FALSE;
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
// ALC Related helper functions
|
||||
#ifdef _WIN32
|
||||
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);
|
||||
break;
|
||||
|
||||
case DLL_PROCESS_DETACH:
|
||||
if(!init_done)
|
||||
break;
|
||||
ReleaseALC();
|
||||
ReleaseALBuffers();
|
||||
ReleaseALEffects();
|
||||
ReleaseALFilters();
|
||||
FreeALConfig();
|
||||
ALTHUNK_EXIT();
|
||||
DeleteCriticalSection(&g_csMutex);
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
#else
|
||||
#ifdef HAVE_GCC_DESTRUCTOR
|
||||
static void my_deinit() __attribute__((destructor));
|
||||
static void my_deinit()
|
||||
{
|
||||
static ALenum once = AL_FALSE;
|
||||
if(once || !init_done) return;
|
||||
once = AL_TRUE;
|
||||
|
||||
ReleaseALC();
|
||||
ReleaseALBuffers();
|
||||
ReleaseALEffects();
|
||||
ReleaseALFilters();
|
||||
FreeALConfig();
|
||||
ALTHUNK_EXIT();
|
||||
DeleteCriticalSection(&g_csMutex);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static void InitAL(void)
|
||||
{
|
||||
static int done = 0;
|
||||
if(!done)
|
||||
if(!init_done)
|
||||
{
|
||||
int i;
|
||||
const char *devs;
|
||||
const char *devs, *str;
|
||||
|
||||
InitializeCriticalSection(&_alMutex);
|
||||
init_done = AL_TRUE;
|
||||
|
||||
InitializeCriticalSection(&g_csMutex);
|
||||
ALTHUNK_INIT();
|
||||
ReadALConfig();
|
||||
|
||||
@@ -249,31 +307,82 @@ static void InitAL(void)
|
||||
|
||||
for(i = 0;BackendList[i].Init;i++)
|
||||
BackendList[i].Init(&BackendList[i].Funcs);
|
||||
done = 1;
|
||||
|
||||
str = GetConfigValue(NULL, "stereodup", "false");
|
||||
DuplicateStereo = (strcasecmp(str, "true") == 0 ||
|
||||
strcasecmp(str, "yes") == 0 ||
|
||||
strcasecmp(str, "on") == 0 ||
|
||||
atoi(str) != 0);
|
||||
|
||||
str = GetConfigValue(NULL, "excludefx", "");
|
||||
if(str[0])
|
||||
{
|
||||
const struct {
|
||||
const char *name;
|
||||
int type;
|
||||
} EffectList[] = {
|
||||
{ "reverb", REVERB },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
int n;
|
||||
size_t len;
|
||||
const char *next = str;
|
||||
|
||||
do {
|
||||
str = next;
|
||||
next = strchr(str, ',');
|
||||
|
||||
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++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ALCchar *AppendDeviceList(char *name)
|
||||
{
|
||||
static int pos;
|
||||
static size_t pos;
|
||||
ALCchar *ret = alcDeviceList+pos;
|
||||
pos += snprintf(alcDeviceList+pos, sizeof(alcDeviceList)-pos, "%s", name) + 1;
|
||||
if(pos >= sizeof(alcDeviceList))
|
||||
{
|
||||
AL_PRINT("Not enough room to add %s!\n", name);
|
||||
return alcDeviceList + sizeof(alcDeviceList) - 1;
|
||||
}
|
||||
pos += snprintf(alcDeviceList+pos, sizeof(alcDeviceList)-pos-1, "%s", name) + 1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ALCchar *AppendAllDeviceList(char *name)
|
||||
{
|
||||
static int pos;
|
||||
static size_t pos;
|
||||
ALCchar *ret = alcAllDeviceList+pos;
|
||||
pos += snprintf(alcAllDeviceList+pos, sizeof(alcAllDeviceList)-pos, "%s", name) + 1;
|
||||
if(pos >= sizeof(alcAllDeviceList))
|
||||
{
|
||||
AL_PRINT("Not enough room to add %s!\n", name);
|
||||
return alcAllDeviceList + sizeof(alcAllDeviceList) - 1;
|
||||
}
|
||||
pos += snprintf(alcAllDeviceList+pos, sizeof(alcAllDeviceList)-pos-1, "%s", name) + 1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ALCchar *AppendCaptureDeviceList(char *name)
|
||||
{
|
||||
static int pos;
|
||||
static size_t pos;
|
||||
ALCchar *ret = alcCaptureDeviceList+pos;
|
||||
pos += snprintf(alcCaptureDeviceList+pos, sizeof(alcCaptureDeviceList)-pos, "%s", name) + 1;
|
||||
if(pos >= sizeof(alcCaptureDeviceList))
|
||||
{
|
||||
AL_PRINT("Not enough room to add %s!\n", name);
|
||||
return alcCaptureDeviceList + sizeof(alcCaptureDeviceList) - 1;
|
||||
}
|
||||
pos += snprintf(alcCaptureDeviceList+pos, sizeof(alcCaptureDeviceList)-pos-1, "%s", name) + 1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -313,7 +422,7 @@ ALCvoid SetALCError(ALenum errorCode)
|
||||
ALCvoid SuspendContext(ALCcontext *pContext)
|
||||
{
|
||||
(void)pContext;
|
||||
EnterCriticalSection(&_alMutex);
|
||||
EnterCriticalSection(&g_csMutex);
|
||||
}
|
||||
|
||||
|
||||
@@ -325,7 +434,7 @@ ALCvoid SuspendContext(ALCcontext *pContext)
|
||||
ALCvoid ProcessContext(ALCcontext *pContext)
|
||||
{
|
||||
(void)pContext;
|
||||
LeaveCriticalSection(&_alMutex);
|
||||
LeaveCriticalSection(&g_csMutex);
|
||||
}
|
||||
|
||||
|
||||
@@ -370,7 +479,7 @@ static ALvoid InitContext(ALCcontext *pContext)
|
||||
pContext->lNumStereoSources = 1;
|
||||
pContext->lNumMonoSources = pContext->Device->MaxNoOfSources - pContext->lNumStereoSources;
|
||||
|
||||
strcpy(pContext->ExtensionList, "AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_OFFSET AL_LOKI_quadriphonic");
|
||||
pContext->ExtensionList = "AL_EXTX_buffer_sub_data AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_OFFSET AL_EXTX_source_distance_model AL_LOKI_quadriphonic";
|
||||
|
||||
level = GetConfigValueInt(NULL, "cf_level", 0);
|
||||
if(level > 0 && level <= 6)
|
||||
@@ -379,6 +488,8 @@ static ALvoid InitContext(ALCcontext *pContext)
|
||||
bs2b_set_srate(pContext->bs2b, pContext->Frequency);
|
||||
bs2b_set_level(pContext->bs2b, level);
|
||||
}
|
||||
|
||||
aluInitPanning(pContext);
|
||||
}
|
||||
|
||||
|
||||
@@ -413,48 +524,46 @@ ALCAPI ALCdevice* ALCAPIENTRY alcCaptureOpenDevice(const ALCchar *deviceName, AL
|
||||
|
||||
InitAL();
|
||||
|
||||
if(SampleSize <= 0)
|
||||
{
|
||||
SetALCError(ALC_INVALID_VALUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(deviceName && !deviceName[0])
|
||||
deviceName = NULL;
|
||||
|
||||
pDevice = malloc(sizeof(ALCdevice));
|
||||
if (pDevice)
|
||||
{
|
||||
if (SampleSize > 0)
|
||||
//Initialise device structure
|
||||
memset(pDevice, 0, sizeof(ALCdevice));
|
||||
|
||||
//Validate device
|
||||
pDevice->IsCaptureDevice = AL_TRUE;
|
||||
|
||||
pDevice->Frequency = frequency;
|
||||
pDevice->Format = format;
|
||||
|
||||
for(i = 0;BackendList[i].Init;i++)
|
||||
{
|
||||
//Initialise device structure
|
||||
memset(pDevice, 0, sizeof(ALCdevice));
|
||||
|
||||
//Validate device
|
||||
pDevice->InUse = AL_TRUE;
|
||||
pDevice->IsCaptureDevice = AL_TRUE;
|
||||
|
||||
pDevice->Frequency = frequency;
|
||||
pDevice->Format = format;
|
||||
pDevice->Channels = aluChannelsFromFormat(format);
|
||||
pDevice->FrameSize = aluBytesFromFormat(format) *
|
||||
pDevice->Channels;
|
||||
|
||||
for(i = 0;BackendList[i].Init;i++)
|
||||
pDevice->Funcs = &BackendList[i].Funcs;
|
||||
if(ALCdevice_OpenCapture(pDevice, deviceName, frequency, format, SampleSize))
|
||||
{
|
||||
pDevice->Funcs = &BackendList[i].Funcs;
|
||||
if(ALCdevice_OpenCapture(pDevice, deviceName, frequency, format, SampleSize))
|
||||
{
|
||||
SuspendContext(NULL);
|
||||
pDevice->next = g_pDeviceList;
|
||||
g_pDeviceList = pDevice;
|
||||
g_ulDeviceCount++;
|
||||
ProcessContext(NULL);
|
||||
SuspendContext(NULL);
|
||||
pDevice->next = g_pDeviceList;
|
||||
g_pDeviceList = pDevice;
|
||||
g_ulDeviceCount++;
|
||||
ProcessContext(NULL);
|
||||
|
||||
DeviceFound = ALC_TRUE;
|
||||
break;
|
||||
}
|
||||
DeviceFound = ALC_TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
SetALCError(ALC_INVALID_VALUE);
|
||||
|
||||
if(!DeviceFound)
|
||||
{
|
||||
SetALCError(ALC_INVALID_VALUE);
|
||||
free(pDevice);
|
||||
pDevice = NULL;
|
||||
}
|
||||
@@ -733,7 +842,7 @@ ALCAPI ALCvoid ALCAPIENTRY alcGetIntegerv(ALCdevice *device,ALCenum param,ALsize
|
||||
data[i++] = device->Frequency;
|
||||
|
||||
data[i++] = ALC_REFRESH;
|
||||
data[i++] = device->Frequency / device->UpdateFreq;
|
||||
data[i++] = device->Frequency / device->UpdateSize;
|
||||
|
||||
data[i++] = ALC_SYNC;
|
||||
data[i++] = ALC_FALSE;
|
||||
@@ -771,7 +880,7 @@ ALCAPI ALCvoid ALCAPIENTRY alcGetIntegerv(ALCdevice *device,ALCenum param,ALsize
|
||||
else if(!size)
|
||||
SetALCError(ALC_INVALID_VALUE);
|
||||
else
|
||||
*data = device->Frequency / device->UpdateFreq;
|
||||
*data = device->Frequency / device->UpdateSize;
|
||||
break;
|
||||
|
||||
case ALC_SYNC:
|
||||
@@ -986,6 +1095,8 @@ ALCAPI ALCvoid ALCAPIENTRY alcDestroyContext(ALCcontext *context)
|
||||
{
|
||||
ALCcontext **list;
|
||||
|
||||
InitAL();
|
||||
|
||||
// Lock context list
|
||||
SuspendContext(NULL);
|
||||
|
||||
@@ -1031,6 +1142,8 @@ ALCAPI ALCcontext * ALCAPIENTRY alcGetCurrentContext(ALCvoid)
|
||||
{
|
||||
ALCcontext *pContext = NULL;
|
||||
|
||||
InitAL();
|
||||
|
||||
SuspendContext(NULL);
|
||||
|
||||
pContext = g_pContextList;
|
||||
@@ -1052,6 +1165,8 @@ ALCAPI ALCdevice* ALCAPIENTRY alcGetContextsDevice(ALCcontext *pContext)
|
||||
{
|
||||
ALCdevice *pDevice = NULL;
|
||||
|
||||
InitAL();
|
||||
|
||||
SuspendContext(NULL);
|
||||
if (IsContext(pContext))
|
||||
pDevice = pContext->Device;
|
||||
@@ -1073,6 +1188,8 @@ ALCAPI ALCboolean ALCAPIENTRY alcMakeContextCurrent(ALCcontext *context)
|
||||
ALCcontext *ALContext;
|
||||
ALboolean bReturn = AL_TRUE;
|
||||
|
||||
InitAL();
|
||||
|
||||
SuspendContext(NULL);
|
||||
|
||||
// context must be a valid Context or NULL
|
||||
@@ -1129,7 +1246,6 @@ ALCAPI ALCdevice* ALCAPIENTRY alcOpenDevice(const ALCchar *deviceName)
|
||||
memset(device, 0, sizeof(ALCdevice));
|
||||
|
||||
//Validate device
|
||||
device->InUse = AL_TRUE;
|
||||
device->IsCaptureDevice = AL_FALSE;
|
||||
|
||||
//Set output format
|
||||
@@ -1141,49 +1257,44 @@ ALCAPI ALCdevice* ALCAPIENTRY alcOpenDevice(const ALCchar *deviceName)
|
||||
if(fmt[0])
|
||||
device->Format = alGetEnumValue(fmt);
|
||||
|
||||
device->Channels = aluChannelsFromFormat(device->Format);
|
||||
if(!device->Channels)
|
||||
{
|
||||
if(!aluChannelsFromFormat(device->Format))
|
||||
device->Format = AL_FORMAT_STEREO16;
|
||||
device->Channels = 2;
|
||||
device->FrameSize = 4;
|
||||
}
|
||||
else
|
||||
device->FrameSize = aluBytesFromFormat(device->Format) *
|
||||
device->Channels;
|
||||
|
||||
device->UpdateFreq = GetConfigValueInt(NULL, "refresh", 8192);
|
||||
if((ALint)device->UpdateFreq <= 0)
|
||||
device->UpdateFreq = 8192;
|
||||
device->UpdateSize = GetConfigValueInt(NULL, "refresh", 4096);
|
||||
if((ALint)device->UpdateSize <= 0)
|
||||
device->UpdateSize = 4096;
|
||||
|
||||
device->MaxNoOfSources = GetConfigValueInt(NULL, "sources", 256);
|
||||
if((ALint)device->MaxNoOfSources <= 0)
|
||||
device->MaxNoOfSources = 256;
|
||||
|
||||
// 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))
|
||||
{
|
||||
SuspendContext(NULL);
|
||||
device->next = g_pDeviceList;
|
||||
g_pDeviceList = device;
|
||||
g_ulDeviceCount++;
|
||||
ProcessContext(NULL);
|
||||
|
||||
bDeviceFound = AL_TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ProcessContext(NULL);
|
||||
|
||||
if (!bDeviceFound)
|
||||
{
|
||||
// No suitable output device found
|
||||
SetALCError(ALC_INVALID_VALUE);
|
||||
free(device);
|
||||
device = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
SetALCError(ALC_OUT_OF_MEMORY);
|
||||
|
||||
return device;
|
||||
}
|
||||
@@ -1213,7 +1324,12 @@ ALCAPI ALCboolean ALCAPIENTRY alcCloseDevice(ALCdevice *pDevice)
|
||||
ProcessContext(NULL);
|
||||
|
||||
if(pDevice->Context)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
AL_PRINT("alcCloseDevice(): destroying 1 Context\n");
|
||||
#endif
|
||||
alcDestroyContext(pDevice->Context);
|
||||
}
|
||||
ALCdevice_ClosePlayback(pDevice);
|
||||
|
||||
//Release device structure
|
||||
@@ -1231,21 +1347,17 @@ ALCAPI ALCboolean ALCAPIENTRY alcCloseDevice(ALCdevice *pDevice)
|
||||
|
||||
ALCvoid ReleaseALC(ALCvoid)
|
||||
{
|
||||
ALCdevice *Dev;
|
||||
|
||||
#ifdef _DEBUG
|
||||
if(g_ulContextCount > 0)
|
||||
AL_PRINT("exit() %u device(s) and %u context(s) NOT deleted\n", g_ulDeviceCount, g_ulContextCount);
|
||||
if(g_ulDeviceCount > 0)
|
||||
AL_PRINT("exit(): closing %u Device%s\n", g_ulDeviceCount, (g_ulDeviceCount>1)?"s":"");
|
||||
#endif
|
||||
|
||||
while(g_pDeviceList)
|
||||
{
|
||||
Dev = g_pDeviceList;
|
||||
g_pDeviceList = g_pDeviceList->next;
|
||||
if(Dev->IsCaptureDevice)
|
||||
alcCaptureCloseDevice(Dev);
|
||||
if(g_pDeviceList->IsCaptureDevice)
|
||||
alcCaptureCloseDevice(g_pDeviceList);
|
||||
else
|
||||
alcCloseDevice(Dev);
|
||||
alcCloseDevice(g_pDeviceList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,11 @@
|
||||
|
||||
#include "alMain.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define _WIN32_IE 0x400
|
||||
#include <shlobj.h>
|
||||
#endif
|
||||
|
||||
typedef struct ConfigEntry {
|
||||
char *key;
|
||||
char *value;
|
||||
@@ -201,6 +206,17 @@ void ReadALConfig(void)
|
||||
cfgCount = 1;
|
||||
|
||||
#ifdef _WIN32
|
||||
if(SHGetSpecialFolderPathA(NULL, buffer, CSIDL_APPDATA, FALSE) != FALSE)
|
||||
{
|
||||
int p = strlen(buffer);
|
||||
snprintf(buffer+p, sizeof(buffer)-p, "\\alsoft.ini");
|
||||
f = fopen(buffer, "rt");
|
||||
if(f)
|
||||
{
|
||||
LoadConfigFromFile(f);
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
#else
|
||||
f = fopen("/etc/openal/alsoft.conf", "r");
|
||||
if(!f)
|
||||
@@ -234,6 +250,15 @@ void ReadALConfig(void)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if(getenv("ALSOFT_CONF"))
|
||||
{
|
||||
f = fopen(getenv("ALSOFT_CONF"), "r");
|
||||
if(f)
|
||||
{
|
||||
LoadConfigFromFile(f);
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FreeALConfig(void)
|
||||
|
||||
+660
@@ -0,0 +1,660 @@
|
||||
/**
|
||||
* Reverb for the OpenAL cross platform audio library
|
||||
* Copyright (C) 2008-2009 by Christopher Fitzgerald.
|
||||
* 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 "AL/al.h"
|
||||
#include "AL/alc.h"
|
||||
#include "alMain.h"
|
||||
#include "alAuxEffectSlot.h"
|
||||
#include "alEffect.h"
|
||||
#include "alReverb.h"
|
||||
|
||||
#ifdef HAVE_SQRTF
|
||||
#define aluSqrt(x) ((ALfloat)sqrtf((float)(x)))
|
||||
#else
|
||||
#define aluSqrt(x) ((ALfloat)sqrt((double)(x)))
|
||||
#endif
|
||||
|
||||
// fixes for mingw32.
|
||||
#if defined(max) && !defined(__max)
|
||||
#define __max max
|
||||
#endif
|
||||
#if defined(min) && !defined(__min)
|
||||
#define __min min
|
||||
#endif
|
||||
|
||||
typedef struct DelayLine
|
||||
{
|
||||
// The delay lines use sample lengths that are powers of 2 to allow
|
||||
// bitmasking instead of modulus wrapping.
|
||||
ALuint Mask;
|
||||
ALfloat *Line;
|
||||
} DelayLine;
|
||||
|
||||
struct ALverbState
|
||||
{
|
||||
// All delay lines are allocated as a single buffer to reduce memory
|
||||
// fragmentation and management code.
|
||||
ALfloat *SampleBuffer;
|
||||
// Master effect gain.
|
||||
ALfloat Gain;
|
||||
// Initial effect delay and decorrelation.
|
||||
DelayLine Delay;
|
||||
// The tap points for the initial delay. First tap goes to early
|
||||
// reflections, the last four decorrelate to late reverb.
|
||||
ALuint Tap[5];
|
||||
struct {
|
||||
// Gain for early reflections.
|
||||
ALfloat Gain;
|
||||
// Early reflections are done with 4 delay lines.
|
||||
ALfloat Coeff[4];
|
||||
DelayLine Delay[4];
|
||||
ALuint Offset[4];
|
||||
} Early;
|
||||
struct {
|
||||
// Gain for late reverb.
|
||||
ALfloat Gain;
|
||||
// Attenuation to compensate for modal density and decay rate.
|
||||
ALfloat DensityGain;
|
||||
// The feed-back and feed-forward all-pass coefficient.
|
||||
ALfloat ApFeedCoeff;
|
||||
// Mixing matrix coefficient.
|
||||
ALfloat MixCoeff;
|
||||
// Late reverb has 4 parallel all-pass filters.
|
||||
ALfloat ApCoeff[4];
|
||||
DelayLine ApDelay[4];
|
||||
ALuint ApOffset[4];
|
||||
// In addition to 4 cyclical delay lines.
|
||||
ALfloat Coeff[4];
|
||||
DelayLine Delay[4];
|
||||
ALuint Offset[4];
|
||||
// The cyclical delay lines are low-pass filtered.
|
||||
ALfloat LpCoeff[4][2];
|
||||
ALfloat LpSample[4];
|
||||
} Late;
|
||||
// The current read offset for all delay lines.
|
||||
ALuint Offset;
|
||||
};
|
||||
|
||||
// All delay line lengths are specified in seconds.
|
||||
|
||||
// The lengths of the early delay lines.
|
||||
static const ALfloat EARLY_LINE_LENGTH[4] =
|
||||
{
|
||||
0.0015f, 0.0045f, 0.0135f, 0.0405f
|
||||
};
|
||||
|
||||
// The lengths of the late all-pass delay lines.
|
||||
static const ALfloat ALLPASS_LINE_LENGTH[4] =
|
||||
{
|
||||
0.0151f, 0.0167f, 0.0183f, 0.0200f,
|
||||
};
|
||||
|
||||
// The lengths of the late cyclical delay lines.
|
||||
static const ALfloat LATE_LINE_LENGTH[4] =
|
||||
{
|
||||
0.0211f, 0.0311f, 0.0461f, 0.0680f
|
||||
};
|
||||
|
||||
// The late cyclical delay lines have a variable length dependent on the
|
||||
// effect's density parameter (inverted for some reason) and this multiplier.
|
||||
static const ALfloat LATE_LINE_MULTIPLIER = 4.0f;
|
||||
|
||||
// Input into the late reverb is decorrelated between four channels. Their
|
||||
// timings are dependent on a fraction and multiplier. See VerbUpdate() for
|
||||
// the calculations involved.
|
||||
static const ALfloat DECO_FRACTION = 1.0f / 32.0f;
|
||||
static const ALfloat DECO_MULTIPLIER = 2.0f;
|
||||
|
||||
// The maximum length of initial delay for the master delay line (a sum of
|
||||
// the maximum early reflection and late reverb delays).
|
||||
static const ALfloat MASTER_LINE_LENGTH = 0.3f + 0.1f;
|
||||
|
||||
// Find the next power of 2. Actually, this will return the input value if
|
||||
// it is already a power of 2.
|
||||
static ALuint NextPowerOf2(ALuint value)
|
||||
{
|
||||
ALuint powerOf2 = 1;
|
||||
|
||||
if(value)
|
||||
{
|
||||
value--;
|
||||
while(value)
|
||||
{
|
||||
value >>= 1;
|
||||
powerOf2 <<= 1;
|
||||
}
|
||||
}
|
||||
return powerOf2;
|
||||
}
|
||||
|
||||
// Basic delay line input/output routines.
|
||||
static __inline ALfloat DelayLineOut(DelayLine *Delay, ALuint offset)
|
||||
{
|
||||
return Delay->Line[offset&Delay->Mask];
|
||||
}
|
||||
|
||||
static __inline ALvoid DelayLineIn(DelayLine *Delay, ALuint offset, ALfloat in)
|
||||
{
|
||||
Delay->Line[offset&Delay->Mask] = in;
|
||||
}
|
||||
|
||||
// Delay line output routine for early reflections.
|
||||
static __inline ALfloat EarlyDelayLineOut(ALverbState *State, ALuint index)
|
||||
{
|
||||
return State->Early.Coeff[index] *
|
||||
DelayLineOut(&State->Early.Delay[index],
|
||||
State->Offset - State->Early.Offset[index]);
|
||||
}
|
||||
|
||||
// Given an input sample, this function produces stereo output for early
|
||||
// reflections.
|
||||
static __inline ALvoid EarlyReflection(ALverbState *State, ALfloat in, ALfloat *out)
|
||||
{
|
||||
ALfloat d[4], v, f[4];
|
||||
|
||||
// Obtain the decayed results of each early delay line.
|
||||
d[0] = EarlyDelayLineOut(State, 0);
|
||||
d[1] = EarlyDelayLineOut(State, 1);
|
||||
d[2] = EarlyDelayLineOut(State, 2);
|
||||
d[3] = EarlyDelayLineOut(State, 3);
|
||||
|
||||
/* The following uses a lossless scattering junction from waveguide
|
||||
* theory. It actually amounts to a householder mixing matrix, which
|
||||
* will produce a maximally diffuse response, and means this can probably
|
||||
* be considered a simple feedback delay network (FDN).
|
||||
* N
|
||||
* ---
|
||||
* \
|
||||
* v = 2/N / d_i
|
||||
* ---
|
||||
* i=1
|
||||
*/
|
||||
v = (d[0] + d[1] + d[2] + d[3]) * 0.5f;
|
||||
// The junction is loaded with the input here.
|
||||
v += in;
|
||||
|
||||
// Calculate the feed values for the delay lines.
|
||||
f[0] = v - d[0];
|
||||
f[1] = v - d[1];
|
||||
f[2] = v - d[2];
|
||||
f[3] = v - d[3];
|
||||
|
||||
// Refeed the delay lines.
|
||||
DelayLineIn(&State->Early.Delay[0], State->Offset, f[0]);
|
||||
DelayLineIn(&State->Early.Delay[1], State->Offset, f[1]);
|
||||
DelayLineIn(&State->Early.Delay[2], State->Offset, f[2]);
|
||||
DelayLineIn(&State->Early.Delay[3], State->Offset, f[3]);
|
||||
|
||||
// To decorrelate the output for stereo separation, the two outputs are
|
||||
// obtained from the inner delay lines.
|
||||
// Output is instant by using the inputs to them instead of taking the
|
||||
// result of the two delay lines directly (f[0] and f[3] instead of d[1]
|
||||
// and d[2]).
|
||||
out[0] = State->Early.Gain * f[0];
|
||||
out[1] = State->Early.Gain * f[3];
|
||||
}
|
||||
|
||||
// All-pass input/output routine for late reverb.
|
||||
static __inline ALfloat LateAllPassInOut(ALverbState *State, ALuint index, ALfloat in)
|
||||
{
|
||||
ALfloat out;
|
||||
|
||||
out = State->Late.ApCoeff[index] *
|
||||
DelayLineOut(&State->Late.ApDelay[index],
|
||||
State->Offset - State->Late.ApOffset[index]);
|
||||
out -= (State->Late.ApFeedCoeff * in);
|
||||
DelayLineIn(&State->Late.ApDelay[index], State->Offset,
|
||||
(State->Late.ApFeedCoeff * out) + in);
|
||||
return out;
|
||||
}
|
||||
|
||||
// Delay line output routine for late reverb.
|
||||
static __inline ALfloat LateDelayLineOut(ALverbState *State, ALuint index)
|
||||
{
|
||||
return State->Late.Coeff[index] *
|
||||
DelayLineOut(&State->Late.Delay[index],
|
||||
State->Offset - State->Late.Offset[index]);
|
||||
}
|
||||
|
||||
// Low-pass filter input/output routine for late reverb.
|
||||
static __inline ALfloat LateLowPassInOut(ALverbState *State, ALuint index, ALfloat in)
|
||||
{
|
||||
State->Late.LpSample[index] = (State->Late.LpCoeff[index][0] * in) +
|
||||
(State->Late.LpCoeff[index][1] * State->Late.LpSample[index]);
|
||||
return State->Late.LpSample[index];
|
||||
}
|
||||
|
||||
// Given four decorrelated input samples, this function produces stereo
|
||||
// output for late reverb.
|
||||
static __inline ALvoid LateReverb(ALverbState *State, ALfloat *in, ALfloat *out)
|
||||
{
|
||||
ALfloat d[4], f[4];
|
||||
|
||||
// Obtain the decayed results of the cyclical delay lines, and add the
|
||||
// corresponding input channels attenuated by density. Then pass the
|
||||
// results through the low-pass filters.
|
||||
d[0] = LateLowPassInOut(State, 0, (State->Late.DensityGain * in[0]) +
|
||||
LateDelayLineOut(State, 0));
|
||||
d[1] = LateLowPassInOut(State, 1, (State->Late.DensityGain * in[1]) +
|
||||
LateDelayLineOut(State, 1));
|
||||
d[2] = LateLowPassInOut(State, 2, (State->Late.DensityGain * in[2]) +
|
||||
LateDelayLineOut(State, 2));
|
||||
d[3] = LateLowPassInOut(State, 3, (State->Late.DensityGain * in[3]) +
|
||||
LateDelayLineOut(State, 3));
|
||||
|
||||
// To help increase diffusion, run each line through an all-pass filter.
|
||||
// The order of the all-pass filters is selected so that the shortest
|
||||
// all-pass filter will feed the shortest delay line.
|
||||
d[0] = LateAllPassInOut(State, 1, d[0]);
|
||||
d[1] = LateAllPassInOut(State, 3, d[1]);
|
||||
d[2] = LateAllPassInOut(State, 0, d[2]);
|
||||
d[3] = LateAllPassInOut(State, 2, d[3]);
|
||||
|
||||
/* Late reverb is done with a modified feedback delay network (FDN)
|
||||
* topology. Four input lines are each fed through their own all-pass
|
||||
* filter and then into the mixing matrix. The four outputs of the
|
||||
* mixing matrix are then cycled back to the inputs. Each output feeds
|
||||
* a different input to form a circlular feed cycle.
|
||||
*
|
||||
* The mixing matrix used is a 4D skew-symmetric rotation matrix derived
|
||||
* using a single unitary rotational parameter:
|
||||
*
|
||||
* [ d, a, b, c ] 1 = a^2 + b^2 + c^2 + d^2
|
||||
* [ -a, d, c, -b ]
|
||||
* [ -b, -c, d, a ]
|
||||
* [ -c, b, -a, d ]
|
||||
*
|
||||
* The rotation is constructed from the effect's diffusion parameter,
|
||||
* yielding: 1 = x^2 + 3 y^2; where a, b, and c are the coefficient y
|
||||
* with differing signs, and d is the coefficient x. The matrix is thus:
|
||||
*
|
||||
* [ x, y, -y, y ] x = 1 - (0.5 diffusion^3)
|
||||
* [ -y, x, y, y ] y = sqrt((1 - x^2) / 3)
|
||||
* [ y, -y, x, y ]
|
||||
* [ -y, -y, -y, x ]
|
||||
*
|
||||
* To reduce the number of multiplies, the x coefficient is applied with
|
||||
* the cyclical delay line coefficients. Thus only the y coefficient is
|
||||
* applied when mixing, and is modified to be: y / x.
|
||||
*/
|
||||
f[0] = d[0] + (State->Late.MixCoeff * ( d[1] - d[2] + d[3]));
|
||||
f[1] = d[1] + (State->Late.MixCoeff * (-d[0] + d[2] + d[3]));
|
||||
f[2] = d[2] + (State->Late.MixCoeff * ( d[0] - d[1] + d[3]));
|
||||
f[3] = d[3] + (State->Late.MixCoeff * (-d[0] - d[1] - d[2]));
|
||||
|
||||
// Output is tapped at the input to the shortest two cyclical delay
|
||||
// lines, attenuated by the late reverb gain (which is attenuated by the
|
||||
// mixing coefficient x).
|
||||
out[0] = State->Late.Gain * f[0];
|
||||
out[1] = State->Late.Gain * f[1];
|
||||
|
||||
// The delay lines are fed circularly in the order:
|
||||
// 0 -> 1 -> 3 -> 2 -> 0 ...
|
||||
DelayLineIn(&State->Late.Delay[0], State->Offset, f[2]);
|
||||
DelayLineIn(&State->Late.Delay[1], State->Offset, f[0]);
|
||||
DelayLineIn(&State->Late.Delay[2], State->Offset, f[3]);
|
||||
DelayLineIn(&State->Late.Delay[3], State->Offset, f[1]);
|
||||
}
|
||||
|
||||
// This creates the reverb state. It should be called only when the reverb
|
||||
// effect is loaded into a slot that doesn't already have a reverb effect.
|
||||
ALverbState *VerbCreate(ALCcontext *Context)
|
||||
{
|
||||
ALverbState *State = NULL;
|
||||
ALuint samples, length[13], totalLength, index;
|
||||
|
||||
State = malloc(sizeof(ALverbState));
|
||||
if(!State)
|
||||
return NULL;
|
||||
|
||||
// All line lengths are powers of 2, calculated from their lengths, with
|
||||
// an additional sample in case of rounding errors.
|
||||
|
||||
// See VerbUpdate() for an explanation of the additional calculation
|
||||
// added to the master line length.
|
||||
samples = (ALuint)
|
||||
((MASTER_LINE_LENGTH +
|
||||
(LATE_LINE_LENGTH[0] * (1.0f + LATE_LINE_MULTIPLIER) *
|
||||
(DECO_FRACTION * ((DECO_MULTIPLIER * DECO_MULTIPLIER *
|
||||
DECO_MULTIPLIER) - 1.0f)))) *
|
||||
Context->Frequency) + 1;
|
||||
length[0] = NextPowerOf2(samples);
|
||||
totalLength = length[0];
|
||||
for(index = 0;index < 4;index++)
|
||||
{
|
||||
samples = (ALuint)(EARLY_LINE_LENGTH[index] * Context->Frequency) + 1;
|
||||
length[1 + index] = NextPowerOf2(samples);
|
||||
totalLength += length[1 + index];
|
||||
}
|
||||
for(index = 0;index < 4;index++)
|
||||
{
|
||||
samples = (ALuint)(ALLPASS_LINE_LENGTH[index] * Context->Frequency) + 1;
|
||||
length[5 + index] = NextPowerOf2(samples);
|
||||
totalLength += length[5 + index];
|
||||
}
|
||||
for(index = 0;index < 4;index++)
|
||||
{
|
||||
samples = (ALuint)(LATE_LINE_LENGTH[index] *
|
||||
(1.0f + LATE_LINE_MULTIPLIER) * Context->Frequency) + 1;
|
||||
length[9 + index] = NextPowerOf2(samples);
|
||||
totalLength += length[9 + index];
|
||||
}
|
||||
|
||||
// All lines share a single sample buffer.
|
||||
State->SampleBuffer = malloc(totalLength * sizeof(ALfloat));
|
||||
if(!State->SampleBuffer)
|
||||
{
|
||||
free(State);
|
||||
return NULL;
|
||||
}
|
||||
for(index = 0; index < totalLength;index++)
|
||||
State->SampleBuffer[index] = 0.0f;
|
||||
|
||||
// Each one has its mask and start address calculated one time.
|
||||
State->Gain = 0.0f;
|
||||
State->Delay.Mask = length[0] - 1;
|
||||
State->Delay.Line = &State->SampleBuffer[0];
|
||||
totalLength = length[0];
|
||||
|
||||
State->Tap[0] = 0;
|
||||
State->Tap[1] = 0;
|
||||
State->Tap[2] = 0;
|
||||
State->Tap[3] = 0;
|
||||
State->Tap[4] = 0;
|
||||
|
||||
State->Early.Gain = 0.0f;
|
||||
for(index = 0;index < 4;index++)
|
||||
{
|
||||
State->Early.Coeff[index] = 0.0f;
|
||||
State->Early.Delay[index].Mask = length[1 + index] - 1;
|
||||
State->Early.Delay[index].Line = &State->SampleBuffer[totalLength];
|
||||
totalLength += length[1 + index];
|
||||
|
||||
// The early delay lines have their read offsets calculated once.
|
||||
State->Early.Offset[index] = (ALuint)(EARLY_LINE_LENGTH[index] *
|
||||
Context->Frequency);
|
||||
}
|
||||
|
||||
State->Late.Gain = 0.0f;
|
||||
State->Late.DensityGain = 0.0f;
|
||||
State->Late.ApFeedCoeff = 0.0f;
|
||||
State->Late.MixCoeff = 0.0f;
|
||||
|
||||
for(index = 0;index < 4;index++)
|
||||
{
|
||||
State->Late.ApCoeff[index] = 0.0f;
|
||||
State->Late.ApDelay[index].Mask = length[5 + index] - 1;
|
||||
State->Late.ApDelay[index].Line = &State->SampleBuffer[totalLength];
|
||||
totalLength += length[5 + index];
|
||||
|
||||
// The late all-pass lines have their read offsets calculated once.
|
||||
State->Late.ApOffset[index] = (ALuint)(ALLPASS_LINE_LENGTH[index] *
|
||||
Context->Frequency);
|
||||
}
|
||||
|
||||
for(index = 0;index < 4;index++)
|
||||
{
|
||||
State->Late.Coeff[index] = 0.0f;
|
||||
State->Late.Delay[index].Mask = length[9 + index] - 1;
|
||||
State->Late.Delay[index].Line = &State->SampleBuffer[totalLength];
|
||||
totalLength += length[9 + index];
|
||||
|
||||
State->Late.Offset[index] = 0;
|
||||
|
||||
State->Late.LpCoeff[index][0] = 0.0f;
|
||||
State->Late.LpCoeff[index][1] = 0.0f;
|
||||
State->Late.LpSample[index] = 0.0f;
|
||||
}
|
||||
|
||||
State->Offset = 0;
|
||||
return State;
|
||||
}
|
||||
|
||||
// This destroys the reverb state. It should be called only when the effect
|
||||
// slot has a different (or no) effect loaded over the reverb effect.
|
||||
ALvoid VerbDestroy(ALverbState *State)
|
||||
{
|
||||
if(State)
|
||||
{
|
||||
free(State->SampleBuffer);
|
||||
State->SampleBuffer = NULL;
|
||||
free(State);
|
||||
}
|
||||
}
|
||||
|
||||
// This updates the reverb state. This is called any time the reverb effect
|
||||
// is loaded into a slot.
|
||||
ALvoid VerbUpdate(ALCcontext *Context, ALeffectslot *Slot, ALeffect *Effect)
|
||||
{
|
||||
ALverbState *State = Slot->ReverbState;
|
||||
ALuint index;
|
||||
ALfloat length, mixCoeff, cw, g, lpCoeff;
|
||||
ALfloat hfRatio = Effect->Reverb.DecayHFRatio;
|
||||
|
||||
// Calculate the master gain (from the slot and master effect gain).
|
||||
State->Gain = Slot->Gain * Effect->Reverb.Gain;
|
||||
|
||||
// Calculate the initial delay taps.
|
||||
length = Effect->Reverb.ReflectionsDelay;
|
||||
State->Tap[0] = (ALuint)(length * Context->Frequency);
|
||||
|
||||
length += Effect->Reverb.LateReverbDelay;
|
||||
|
||||
/* The four inputs to the late reverb are decorrelated to smooth the
|
||||
* initial reverb and reduce harsh echos. The timings are calculated as
|
||||
* multiples of a fraction of the smallest cyclical delay time. This
|
||||
* result is then adjusted so that the first tap occurs immediately (all
|
||||
* taps are reduced by the shortest fraction).
|
||||
*
|
||||
* offset[index] = ((FRACTION MULTIPLIER^index) - 1) delay
|
||||
*/
|
||||
for(index = 0;index < 4;index++)
|
||||
{
|
||||
length += LATE_LINE_LENGTH[0] *
|
||||
(1.0f + (Effect->Reverb.Density * LATE_LINE_MULTIPLIER)) *
|
||||
(DECO_FRACTION * (pow(DECO_MULTIPLIER, (ALfloat)index) - 1.0f));
|
||||
State->Tap[1 + index] = (ALuint)(length * Context->Frequency);
|
||||
}
|
||||
|
||||
// Set the early reflections gain.
|
||||
State->Early.Gain = Effect->Reverb.ReflectionsGain;
|
||||
|
||||
// Calculate the gain (coefficient) for each early delay line.
|
||||
for(index = 0;index < 4;index++)
|
||||
State->Early.Coeff[index] = pow(10.0f, EARLY_LINE_LENGTH[index] /
|
||||
Effect->Reverb.LateReverbDelay *
|
||||
-60.0f / 20.0f);
|
||||
|
||||
// Calculate the first mixing matrix coefficient (x).
|
||||
mixCoeff = 1.0f - (0.5f * pow(Effect->Reverb.Diffusion, 3.0f));
|
||||
|
||||
// Set the late reverb gain. Since the output is tapped prior to the
|
||||
// application of the delay line coefficients, this gain needs to be
|
||||
// attenuated by the mix coefficient from above.
|
||||
State->Late.Gain = Effect->Reverb.LateReverbGain * mixCoeff;
|
||||
|
||||
/* To compensate for changes in modal density and decay time of the late
|
||||
* reverb signal, the input is attenuated based on the maximal energy of
|
||||
* the outgoing signal. This is calculated as the ratio between a
|
||||
* reference value and the current approximation of energy for the output
|
||||
* signal.
|
||||
*
|
||||
* Reverb output matches exponential decay of the form Sum(a^n), where a
|
||||
* is the attenuation coefficient, and n is the sample ranging from 0 to
|
||||
* infinity. The signal energy can thus be approximated using the area
|
||||
* under this curve, calculated as: 1 / (1 - a).
|
||||
*
|
||||
* The reference energy is calculated from a signal at the lowest (effect
|
||||
* at 1.0) density with a decay time of one second.
|
||||
*
|
||||
* The coefficient is calculated as the average length of the cyclical
|
||||
* delay lines. This produces a better result than calculating the gain
|
||||
* for each line individually (most likely a side effect of diffusion).
|
||||
*
|
||||
* The final result is the square root of the ratio bound to a maximum
|
||||
* value of 1 (no amplification) and attenuated by 1 / sqrt(2) to
|
||||
* compensate for the four decorrelated inputs.
|
||||
*/
|
||||
length = (LATE_LINE_LENGTH[0] + LATE_LINE_LENGTH[1] +
|
||||
LATE_LINE_LENGTH[2] + LATE_LINE_LENGTH[3]);
|
||||
g = length * (1.0f + LATE_LINE_MULTIPLIER) * 0.25f;
|
||||
g = pow(10.0f, g * -60.0f / 20.0f);
|
||||
g = 1.0f / (1.0f - g);
|
||||
length *= 1.0f + (Effect->Reverb.Density * LATE_LINE_MULTIPLIER) * 0.25f;
|
||||
length = pow(10.0f, length / Effect->Reverb.DecayTime * -60.0f / 20.0f);
|
||||
length = 1.0f / (1.0f - length);
|
||||
State->Late.DensityGain = 0.707106f * __min(aluSqrt(g / length), 1.0f);
|
||||
|
||||
// Calculate the all-pass feed-back and feed-forward coefficient.
|
||||
State->Late.ApFeedCoeff = 0.6f * pow(Effect->Reverb.Diffusion, 3.0f);
|
||||
|
||||
// Calculate the mixing matrix coefficient (y / x).
|
||||
g = aluSqrt((1.0f - (mixCoeff * mixCoeff)) / 3.0f);
|
||||
State->Late.MixCoeff = g / mixCoeff;
|
||||
|
||||
for(index = 0;index < 4;index++)
|
||||
{
|
||||
// Calculate the gain (coefficient) for each all-pass line.
|
||||
State->Late.ApCoeff[index] = pow(10.0f, ALLPASS_LINE_LENGTH[index] /
|
||||
Effect->Reverb.DecayTime *
|
||||
-60.0f / 20.0f);
|
||||
}
|
||||
|
||||
// If the HF limit parameter is flagged, calculate an appropriate limit
|
||||
// based on the air absorption parameter.
|
||||
if(Effect->Reverb.DecayHFLimit && Effect->Reverb.AirAbsorptionGainHF < 1.0f)
|
||||
{
|
||||
ALfloat limitRatio;
|
||||
|
||||
// For each of the cyclical delays, find the attenuation due to air
|
||||
// absorption in dB (converting delay time to meters using the speed
|
||||
// of sound). Then reversing the decay equation, solve for HF ratio.
|
||||
// The delay length is cancelled out of the equation, so it can be
|
||||
// calculated once for all lines.
|
||||
limitRatio = 1.0f / (log10(Effect->Reverb.AirAbsorptionGainHF) *
|
||||
SPEEDOFSOUNDMETRESPERSEC *
|
||||
Effect->Reverb.DecayTime / -60.0f * 20.0f);
|
||||
// Need to limit the result to a minimum of 0.1, just like the HF
|
||||
// ratio parameter.
|
||||
limitRatio = __max(limitRatio, 0.1f);
|
||||
|
||||
// Using the limit calculated above, apply the upper bound to the
|
||||
// HF ratio.
|
||||
hfRatio = __min(hfRatio, limitRatio);
|
||||
}
|
||||
|
||||
// Calculate the filter frequency for low-pass or high-pass depending on
|
||||
// whether the HF ratio is above 1.
|
||||
cw = 2.0f * M_PI * LOWPASSFREQCUTOFF / Context->Frequency;
|
||||
if(hfRatio > 1.0f)
|
||||
cw = M_PI - cw;
|
||||
cw = cos(cw);
|
||||
|
||||
for(index = 0;index < 4;index++)
|
||||
{
|
||||
// Calculate the length (in seconds) of each cyclical delay line.
|
||||
length = LATE_LINE_LENGTH[index] * (1.0f + (Effect->Reverb.Density *
|
||||
LATE_LINE_MULTIPLIER));
|
||||
// Calculate the delay offset for the cyclical delay lines.
|
||||
State->Late.Offset[index] = (ALuint)(length * Context->Frequency);
|
||||
|
||||
// Calculate the gain (coefficient) for each cyclical line.
|
||||
State->Late.Coeff[index] = pow(10.0f, length / Effect->Reverb.DecayTime *
|
||||
-60.0f / 20.0f);
|
||||
|
||||
// Calculate the decay equation for each low-pass filter.
|
||||
g = pow(10.0f, length / (Effect->Reverb.DecayTime * hfRatio) *
|
||||
-60.0f / 20.0f);
|
||||
if (hfRatio > 1.0f)
|
||||
g = State->Late.Coeff[index] / g;
|
||||
else
|
||||
g = g / State->Late.Coeff[index];
|
||||
g = __max(g, 0.1f);
|
||||
g *= g;
|
||||
|
||||
// Calculate the gain (coefficient) for each low-pass filter.
|
||||
lpCoeff = 0.0f;
|
||||
if(g < 0.9999f) // 1-epsilon
|
||||
lpCoeff = (1 - g*cw - aluSqrt(2*g*(1-cw) - g*g*(1 - cw*cw))) / (1 - g);
|
||||
|
||||
// Very low decay times will produce minimal output, so apply an
|
||||
// upper bound to the coefficient.
|
||||
lpCoeff = __min(lpCoeff, 0.98f);
|
||||
|
||||
// Calculate the filter coefficients for high-pass or low-pass
|
||||
// dependent on HF ratio being above 1.
|
||||
if(hfRatio > 1.0f) {
|
||||
State->Late.LpCoeff[index][0] = 1.0f + lpCoeff;
|
||||
State->Late.LpCoeff[index][1] = -lpCoeff;
|
||||
} else {
|
||||
State->Late.LpCoeff[index][0] = 1.0f - lpCoeff;
|
||||
State->Late.LpCoeff[index][1] = lpCoeff;
|
||||
}
|
||||
|
||||
// Attenuate the cyclical line coefficients by the mixing coefficient
|
||||
// (x).
|
||||
State->Late.Coeff[index] *= mixCoeff;
|
||||
}
|
||||
}
|
||||
|
||||
// This processes the reverb state, given the input samples and an output
|
||||
// buffer.
|
||||
ALvoid VerbProcess(ALverbState *State, ALuint SamplesToDo, const ALfloat *SamplesIn, ALfloat (*SamplesOut)[OUTPUTCHANNELS])
|
||||
{
|
||||
ALuint index;
|
||||
ALfloat in[4], early[2], late[2], out[2];
|
||||
|
||||
for(index = 0;index < SamplesToDo;index++)
|
||||
{
|
||||
// Feed the initial delay line.
|
||||
DelayLineIn(&State->Delay, State->Offset, SamplesIn[index]);
|
||||
|
||||
// Calculate the early reflection from the first delay tap.
|
||||
in[0] = DelayLineOut(&State->Delay, State->Offset - State->Tap[0]);
|
||||
EarlyReflection(State, in[0], early);
|
||||
|
||||
// Calculate the late reverb from the last four delay taps.
|
||||
in[0] = DelayLineOut(&State->Delay, State->Offset - State->Tap[1]);
|
||||
in[1] = DelayLineOut(&State->Delay, State->Offset - State->Tap[2]);
|
||||
in[2] = DelayLineOut(&State->Delay, State->Offset - State->Tap[3]);
|
||||
in[3] = DelayLineOut(&State->Delay, State->Offset - State->Tap[4]);
|
||||
LateReverb(State, in, late);
|
||||
|
||||
// Mix early reflections and late reverb.
|
||||
out[0] = State->Gain * (early[0] + late[0]);
|
||||
out[1] = State->Gain * (early[1] + late[1]);
|
||||
|
||||
// Step all delays forward one sample.
|
||||
State->Offset++;
|
||||
|
||||
// Output the results.
|
||||
SamplesOut[index][FRONT_LEFT] += out[0];
|
||||
SamplesOut[index][FRONT_RIGHT] += out[1];
|
||||
SamplesOut[index][SIDE_LEFT] += out[0];
|
||||
SamplesOut[index][SIDE_RIGHT] += out[1];
|
||||
SamplesOut[index][BACK_LEFT] += out[0];
|
||||
SamplesOut[index][BACK_RIGHT] += out[1];
|
||||
}
|
||||
}
|
||||
+7
-2
@@ -70,7 +70,13 @@ void DestroyRingBuffer(RingBuffer *ring)
|
||||
|
||||
ALsizei RingBufferSize(RingBuffer *ring)
|
||||
{
|
||||
return (ring->write_pos-ring->read_pos-1+ring->length) % ring->length;
|
||||
ALsizei s;
|
||||
|
||||
EnterCriticalSection(&ring->cs);
|
||||
s = (ring->write_pos-ring->read_pos-1+ring->length) % ring->length;
|
||||
LeaveCriticalSection(&ring->cs);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len)
|
||||
@@ -115,4 +121,3 @@ void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len)
|
||||
|
||||
LeaveCriticalSection(&ring->cs);
|
||||
}
|
||||
|
||||
|
||||
+12
-11
@@ -28,8 +28,6 @@
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
typedef struct {
|
||||
ALuint (*func)(ALvoid*);
|
||||
ALvoid *ptr;
|
||||
@@ -49,13 +47,14 @@ static DWORD CALLBACK StarterFunc(void *ptr)
|
||||
|
||||
ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr)
|
||||
{
|
||||
DWORD dummy;
|
||||
ThreadInfo *inf = malloc(sizeof(ThreadInfo));
|
||||
if(!inf) return 0;
|
||||
|
||||
inf->func = func;
|
||||
inf->ptr = ptr;
|
||||
|
||||
inf->thread = CreateThread(NULL, 0, StarterFunc, inf, 0, NULL);
|
||||
inf->thread = CreateThread(NULL, 0, StarterFunc, inf, 0, &dummy);
|
||||
if(!inf->thread)
|
||||
{
|
||||
free(inf);
|
||||
@@ -72,6 +71,7 @@ ALuint StopThread(ALvoid *thread)
|
||||
|
||||
WaitForSingleObject(inf->thread, INFINITE);
|
||||
GetExitCodeThread(inf->thread, &ret);
|
||||
CloseHandle(inf->thread);
|
||||
|
||||
free(inf);
|
||||
|
||||
@@ -85,22 +85,21 @@ ALuint StopThread(ALvoid *thread)
|
||||
typedef struct {
|
||||
ALuint (*func)(ALvoid*);
|
||||
ALvoid *ptr;
|
||||
ALuint ret;
|
||||
pthread_t thread;
|
||||
} ThreadInfo;
|
||||
|
||||
static void *StarterFunc(void *ptr)
|
||||
{
|
||||
ThreadInfo *inf = (ThreadInfo*)ptr;
|
||||
ALint ret;
|
||||
|
||||
ret = inf->func(inf->ptr);
|
||||
return (void*)ret;
|
||||
inf->ret = inf->func(inf->ptr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr)
|
||||
{
|
||||
ThreadInfo *inf = malloc(sizeof(ThreadInfo));
|
||||
if(!inf) return 0;
|
||||
if(!inf) return NULL;
|
||||
|
||||
inf->func = func;
|
||||
inf->ptr = ptr;
|
||||
@@ -116,12 +115,14 @@ ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr)
|
||||
ALuint StopThread(ALvoid *thread)
|
||||
{
|
||||
ThreadInfo *inf = thread;
|
||||
void *ret;
|
||||
ALuint ret;
|
||||
|
||||
pthread_join(inf->thread, NULL);
|
||||
ret = inf->ret;
|
||||
|
||||
pthread_join(inf->thread, &ret);
|
||||
free(inf);
|
||||
|
||||
return (ALuint)ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+260
-63
@@ -40,7 +40,10 @@ typedef struct {
|
||||
ALvoid *buffer;
|
||||
ALsizei size;
|
||||
|
||||
int killNow;
|
||||
RingBuffer *ring;
|
||||
int doCapture;
|
||||
|
||||
volatile int killNow;
|
||||
ALvoid *thread;
|
||||
} alsa_data;
|
||||
|
||||
@@ -67,17 +70,20 @@ MAKE_FUNC(snd_pcm_hw_params_set_rate_near);
|
||||
MAKE_FUNC(snd_pcm_hw_params_set_rate);
|
||||
MAKE_FUNC(snd_pcm_hw_params_set_buffer_size_near);
|
||||
MAKE_FUNC(snd_pcm_hw_params_set_buffer_size_min);
|
||||
MAKE_FUNC(snd_pcm_hw_params_get_buffer_size);
|
||||
MAKE_FUNC(snd_pcm_hw_params_get_period_size);
|
||||
MAKE_FUNC(snd_pcm_hw_params_get_access);
|
||||
MAKE_FUNC(snd_pcm_hw_params);
|
||||
MAKE_FUNC(snd_pcm_prepare);
|
||||
MAKE_FUNC(snd_pcm_start);
|
||||
MAKE_FUNC(snd_pcm_resume);
|
||||
MAKE_FUNC(snd_pcm_wait);
|
||||
MAKE_FUNC(snd_pcm_state);
|
||||
MAKE_FUNC(snd_pcm_avail_update);
|
||||
MAKE_FUNC(snd_pcm_areas_silence);
|
||||
MAKE_FUNC(snd_pcm_mmap_begin);
|
||||
MAKE_FUNC(snd_pcm_mmap_commit);
|
||||
MAKE_FUNC(snd_pcm_readi);
|
||||
MAKE_FUNC(snd_pcm_writei);
|
||||
MAKE_FUNC(snd_pcm_drain);
|
||||
MAKE_FUNC(snd_pcm_info_malloc);
|
||||
@@ -97,12 +103,11 @@ MAKE_FUNC(snd_ctl_card_info_get_name);
|
||||
MAKE_FUNC(snd_card_next);
|
||||
#undef MAKE_FUNC
|
||||
|
||||
#define MAX_DEVICES 16
|
||||
#define MAX_ALL_DEVICES 32
|
||||
|
||||
static ALCchar *alsaDevice;
|
||||
static DevMap allDevNameMap[MAX_ALL_DEVICES];
|
||||
static ALCchar *alsaDeviceList[MAX_DEVICES];
|
||||
static ALCchar *alsaCaptureDeviceList[MAX_DEVICES];
|
||||
static DevMap allCaptureDevNameMap[MAX_ALL_DEVICES];
|
||||
|
||||
static int xrun_recovery(snd_pcm_t *handle, int err)
|
||||
{
|
||||
@@ -185,7 +190,8 @@ static ALuint ALSAProc(ALvoid *ptr)
|
||||
break;
|
||||
}
|
||||
}
|
||||
Sleep(1);
|
||||
else if(psnd_pcm_wait(data->pcmHandle, 1000) == 0)
|
||||
AL_PRINT("Wait timeout... buffer size too low?\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -272,12 +278,49 @@ static ALuint ALSANoMMapProc(ALvoid *ptr)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ALuint ALSANoMMapCaptureProc(ALvoid *ptr)
|
||||
{
|
||||
ALCdevice *pDevice = (ALCdevice*)ptr;
|
||||
alsa_data *data = (alsa_data*)pDevice->ExtraData;
|
||||
snd_pcm_sframes_t avail;
|
||||
|
||||
while(!data->killNow)
|
||||
{
|
||||
avail = (snd_pcm_uframes_t)data->size / psnd_pcm_frames_to_bytes(data->pcmHandle, 1);
|
||||
avail = psnd_pcm_readi(data->pcmHandle, data->buffer, avail);
|
||||
switch(avail)
|
||||
{
|
||||
case -EAGAIN:
|
||||
continue;
|
||||
case -ESTRPIPE:
|
||||
while((avail=psnd_pcm_resume(data->pcmHandle)) == -EAGAIN)
|
||||
Sleep(1);
|
||||
break;
|
||||
case -EPIPE:
|
||||
break;
|
||||
default:
|
||||
if (avail >= 0 && data->doCapture)
|
||||
WriteRingBuffer(data->ring, data->buffer, avail);
|
||||
break;
|
||||
}
|
||||
if(avail < 0)
|
||||
{
|
||||
avail = psnd_pcm_prepare(data->pcmHandle);
|
||||
if(avail < 0)
|
||||
AL_PRINT("prepare error: %s\n", psnd_strerror(avail));
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ALCboolean alsa_open_playback(ALCdevice *device, const ALCchar *deviceName)
|
||||
{
|
||||
snd_pcm_uframes_t bufferSizeInFrames;
|
||||
snd_pcm_hw_params_t *p = NULL;
|
||||
snd_pcm_access_t access;
|
||||
unsigned int periods;
|
||||
unsigned int rate;
|
||||
alsa_data *data;
|
||||
char driver[64];
|
||||
const char *str;
|
||||
@@ -305,21 +348,15 @@ static ALCboolean alsa_open_playback(ALCdevice *device, const ALCchar *deviceNam
|
||||
goto open_alsa;
|
||||
}
|
||||
}
|
||||
for(idx = 0;idx < MAX_DEVICES;idx++)
|
||||
if(strcmp(deviceName, alsaDevice) == 0)
|
||||
{
|
||||
if(alsaDeviceList[idx] &&
|
||||
strcmp(deviceName, alsaDeviceList[idx]) == 0)
|
||||
{
|
||||
device->szDeviceName = alsaDeviceList[idx];
|
||||
if(idx > 0)
|
||||
sprintf(driver, "hw:%zd,0", idx-1);
|
||||
goto open_alsa;
|
||||
}
|
||||
device->szDeviceName = alsaDevice;
|
||||
goto open_alsa;
|
||||
}
|
||||
return ALC_FALSE;
|
||||
}
|
||||
else
|
||||
device->szDeviceName = alsaDeviceList[0];
|
||||
device->szDeviceName = alsaDevice;
|
||||
|
||||
open_alsa:
|
||||
data = (alsa_data*)calloc(1, sizeof(alsa_data));
|
||||
@@ -357,7 +394,8 @@ open_alsa:
|
||||
}
|
||||
|
||||
periods = GetConfigValueInt("alsa", "periods", 0);
|
||||
bufferSizeInFrames = device->UpdateFreq;
|
||||
bufferSizeInFrames = device->UpdateSize;
|
||||
rate = device->Frequency;
|
||||
|
||||
str = GetConfigValue("alsa", "mmap", "true");
|
||||
allowmmap = (strcasecmp(str, "true") == 0 ||
|
||||
@@ -375,11 +413,11 @@ open_alsa:
|
||||
/* set format (implicitly sets sample bits) */
|
||||
ok(psnd_pcm_hw_params_set_format(data->pcmHandle, p, data->format), "set format") &&
|
||||
/* set channels (implicitly sets frame bits) */
|
||||
ok(psnd_pcm_hw_params_set_channels(data->pcmHandle, p, device->Channels), "set channels") &&
|
||||
ok(psnd_pcm_hw_params_set_channels(data->pcmHandle, p, aluChannelsFromFormat(device->Format)), "set channels") &&
|
||||
/* set periods (implicitly constrains period/buffer parameters) */
|
||||
(!periods || ok(psnd_pcm_hw_params_set_periods_near(data->pcmHandle, p, &periods, NULL), "set periods near")) &&
|
||||
/* set rate (implicitly constrains period/buffer parameters) */
|
||||
ok(psnd_pcm_hw_params_set_rate_near(data->pcmHandle, p, &device->Frequency, NULL), "set rate near") &&
|
||||
ok(psnd_pcm_hw_params_set_rate_near(data->pcmHandle, p, &rate, NULL), "set rate near") &&
|
||||
/* set buffer size in frame units (implicitly sets period size/bytes/time and buffer time/bytes) */
|
||||
ok(psnd_pcm_hw_params_set_buffer_size_near(data->pcmHandle, p, &bufferSizeInFrames), "set buffer size near") &&
|
||||
/* install and prepare hardware configuration */
|
||||
@@ -413,9 +451,7 @@ open_alsa:
|
||||
|
||||
psnd_pcm_hw_params_free(p);
|
||||
|
||||
device->UpdateFreq = bufferSizeInFrames;
|
||||
|
||||
data->size = psnd_pcm_frames_to_bytes(data->pcmHandle, device->UpdateFreq);
|
||||
data->size = psnd_pcm_frames_to_bytes(data->pcmHandle, device->UpdateSize);
|
||||
if(access == SND_PCM_ACCESS_RW_INTERLEAVED)
|
||||
{
|
||||
data->buffer = malloc(data->size);
|
||||
@@ -447,6 +483,7 @@ open_alsa:
|
||||
data->thread = StartThread(ALSAProc, device);
|
||||
if(data->thread == NULL)
|
||||
{
|
||||
AL_PRINT("Could not create playback thread\n");
|
||||
psnd_pcm_close(data->pcmHandle);
|
||||
device->ExtraData = NULL;
|
||||
free(data->buffer);
|
||||
@@ -454,6 +491,9 @@ open_alsa:
|
||||
return ALC_FALSE;
|
||||
}
|
||||
|
||||
device->UpdateSize = bufferSizeInFrames;
|
||||
device->Frequency = rate;
|
||||
|
||||
return ALC_TRUE;
|
||||
}
|
||||
|
||||
@@ -475,8 +515,11 @@ static ALCboolean alsa_open_capture(ALCdevice *pDevice, const ALCchar *deviceNam
|
||||
snd_pcm_format_t alsaFormat;
|
||||
snd_pcm_hw_params_t *p;
|
||||
snd_pcm_uframes_t bufferSizeInFrames;
|
||||
snd_pcm_access_t access;
|
||||
const char *str;
|
||||
alsa_data *data;
|
||||
char driver[64];
|
||||
int allowmmap;
|
||||
char *err;
|
||||
int i;
|
||||
|
||||
@@ -489,21 +532,21 @@ static ALCboolean alsa_open_capture(ALCdevice *pDevice, const ALCchar *deviceNam
|
||||
{
|
||||
size_t idx;
|
||||
|
||||
for(idx = 0;idx < MAX_DEVICES;idx++)
|
||||
for(idx = 0;idx < MAX_ALL_DEVICES;idx++)
|
||||
{
|
||||
if(alsaCaptureDeviceList[idx] &&
|
||||
strcmp(deviceName, alsaCaptureDeviceList[idx]) == 0)
|
||||
if(allCaptureDevNameMap[idx].name &&
|
||||
strcmp(deviceName, allCaptureDevNameMap[idx].name) == 0)
|
||||
{
|
||||
pDevice->szDeviceName = alsaCaptureDeviceList[idx];
|
||||
pDevice->szDeviceName = allCaptureDevNameMap[idx].name;
|
||||
if(idx > 0)
|
||||
sprintf(driver, "hw:%zd,0", idx-1);
|
||||
sprintf(driver, "plughw:%d,%d", allCaptureDevNameMap[idx].card, allCaptureDevNameMap[idx].dev);
|
||||
goto open_alsa;
|
||||
}
|
||||
}
|
||||
return ALC_FALSE;
|
||||
}
|
||||
else
|
||||
pDevice->szDeviceName = alsaCaptureDeviceList[0];
|
||||
pDevice->szDeviceName = allCaptureDevNameMap[0].name;
|
||||
|
||||
open_alsa:
|
||||
data = (alsa_data*)calloc(1, sizeof(alsa_data));
|
||||
@@ -540,18 +583,24 @@ open_alsa:
|
||||
AL_PRINT("Unknown format?! %x\n", format);
|
||||
}
|
||||
|
||||
bufferSizeInFrames = SampleSize;
|
||||
str = GetConfigValue("alsa", "mmap", "true");
|
||||
allowmmap = (strcasecmp(str, "true") == 0 ||
|
||||
strcasecmp(str, "yes") == 0 ||
|
||||
strcasecmp(str, "on") == 0 ||
|
||||
atoi(str) != 0);
|
||||
|
||||
bufferSizeInFrames = SampleSize;
|
||||
psnd_pcm_hw_params_malloc(&p);
|
||||
#define ok(func, str) (i=(func),((i<0)?(err=(str)),0:1))
|
||||
/* start with the largest configuration space possible */
|
||||
if(!(ok(psnd_pcm_hw_params_any(data->pcmHandle, p), "any") &&
|
||||
if(!(allowmmap &&
|
||||
ok(psnd_pcm_hw_params_any(data->pcmHandle, p), "any") &&
|
||||
/* set interleaved access */
|
||||
ok(psnd_pcm_hw_params_set_access(data->pcmHandle, p, SND_PCM_ACCESS_MMAP_INTERLEAVED), "set access") &&
|
||||
/* set format (implicitly sets sample bits) */
|
||||
ok(psnd_pcm_hw_params_set_format(data->pcmHandle, p, alsaFormat), "set format") &&
|
||||
/* set channels (implicitly sets frame bits) */
|
||||
ok(psnd_pcm_hw_params_set_channels(data->pcmHandle, p, pDevice->Channels), "set channels") &&
|
||||
ok(psnd_pcm_hw_params_set_channels(data->pcmHandle, p, aluChannelsFromFormat(pDevice->Format)), "set channels") &&
|
||||
/* set rate (implicitly constrains period/buffer parameters) */
|
||||
ok(psnd_pcm_hw_params_set_rate(data->pcmHandle, p, frequency, 0), "set rate") &&
|
||||
/* set buffer size in frame units (implicitly sets period size/bytes/time and buffer time/bytes) */
|
||||
@@ -559,31 +608,109 @@ open_alsa:
|
||||
/* install and prepare hardware configuration */
|
||||
ok(psnd_pcm_hw_params(data->pcmHandle, p), "set params")))
|
||||
{
|
||||
AL_PRINT("%s failed: %s\n", err, psnd_strerror(i));
|
||||
if(i < 0)
|
||||
AL_PRINT("%s failed: %s\n", err, psnd_strerror(i));
|
||||
bufferSizeInFrames = SampleSize;
|
||||
if(!(ok(psnd_pcm_hw_params_any(data->pcmHandle, p), "any") &&
|
||||
ok(psnd_pcm_hw_params_set_access(data->pcmHandle, p, SND_PCM_ACCESS_RW_INTERLEAVED), "set access") &&
|
||||
ok(psnd_pcm_hw_params_set_format(data->pcmHandle, p, alsaFormat), "set format") &&
|
||||
ok(psnd_pcm_hw_params_set_channels(data->pcmHandle, p, aluChannelsFromFormat(pDevice->Format)), "set channels") &&
|
||||
ok(psnd_pcm_hw_params_set_rate(data->pcmHandle, p, frequency, 0), "set rate") &&
|
||||
ok(psnd_pcm_hw_params_set_buffer_size_near(data->pcmHandle, p, &bufferSizeInFrames), "set buffer size near") &&
|
||||
ok(psnd_pcm_hw_params(data->pcmHandle, p), "set params")))
|
||||
{
|
||||
AL_PRINT("%s failed: %s\n", err, psnd_strerror(i));
|
||||
psnd_pcm_hw_params_free(p);
|
||||
psnd_pcm_close(data->pcmHandle);
|
||||
free(data);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
}
|
||||
#undef ok
|
||||
|
||||
if((i=psnd_pcm_hw_params_get_access(p, &access)) < 0)
|
||||
{
|
||||
AL_PRINT("get_access failed: %s\n", psnd_strerror(i));
|
||||
psnd_pcm_hw_params_free(p);
|
||||
psnd_pcm_close(data->pcmHandle);
|
||||
free(data);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
#undef ok
|
||||
psnd_pcm_hw_params_free(p);
|
||||
|
||||
i = psnd_pcm_prepare(data->pcmHandle);
|
||||
if(i < 0)
|
||||
if((i=psnd_pcm_hw_params_get_period_size(p, &bufferSizeInFrames, NULL)) < 0)
|
||||
{
|
||||
AL_PRINT("prepare error: %s\n", psnd_strerror(i));
|
||||
AL_PRINT("get size failed: %s\n", psnd_strerror(i));
|
||||
psnd_pcm_hw_params_free(p);
|
||||
psnd_pcm_close(data->pcmHandle);
|
||||
free(data);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
|
||||
pDevice->ExtraData = data;
|
||||
psnd_pcm_hw_params_free(p);
|
||||
|
||||
if(access == SND_PCM_ACCESS_RW_INTERLEAVED)
|
||||
{
|
||||
ALuint frameSize = aluChannelsFromFormat(pDevice->Format);
|
||||
frameSize *= aluBytesFromFormat(pDevice->Format);
|
||||
|
||||
data->ring = CreateRingBuffer(frameSize, SampleSize);
|
||||
if(!data->ring)
|
||||
{
|
||||
AL_PRINT("ring buffer create failed\n");
|
||||
psnd_pcm_close(data->pcmHandle);
|
||||
free(data);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
|
||||
data->size = psnd_pcm_frames_to_bytes(data->pcmHandle, bufferSizeInFrames);
|
||||
data->buffer = malloc(data->size);
|
||||
if(!data->buffer)
|
||||
{
|
||||
AL_PRINT("buffer malloc failed\n");
|
||||
psnd_pcm_close(data->pcmHandle);
|
||||
DestroyRingBuffer(data->ring);
|
||||
free(data);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
|
||||
pDevice->ExtraData = data;
|
||||
data->thread = StartThread(ALSANoMMapCaptureProc, pDevice);
|
||||
if(data->thread == NULL)
|
||||
{
|
||||
AL_PRINT("Could not create capture thread\n");
|
||||
pDevice->ExtraData = NULL;
|
||||
psnd_pcm_close(data->pcmHandle);
|
||||
DestroyRingBuffer(data->ring);
|
||||
free(data->buffer);
|
||||
free(data);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
i = psnd_pcm_prepare(data->pcmHandle);
|
||||
if(i < 0)
|
||||
{
|
||||
AL_PRINT("prepare error: %s\n", psnd_strerror(i));
|
||||
psnd_pcm_close(data->pcmHandle);
|
||||
free(data);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
pDevice->ExtraData = data;
|
||||
}
|
||||
|
||||
return ALC_TRUE;
|
||||
}
|
||||
|
||||
static void alsa_close_capture(ALCdevice *pDevice)
|
||||
{
|
||||
alsa_data *data = (alsa_data*)pDevice->ExtraData;
|
||||
|
||||
if(data->thread)
|
||||
{
|
||||
data->killNow = 1;
|
||||
StopThread(data->thread);
|
||||
DestroyRingBuffer(data->ring);
|
||||
}
|
||||
psnd_pcm_close(data->pcmHandle);
|
||||
|
||||
free(data);
|
||||
@@ -593,13 +720,20 @@ static void alsa_close_capture(ALCdevice *pDevice)
|
||||
static void alsa_start_capture(ALCdevice *pDevice)
|
||||
{
|
||||
alsa_data *data = (alsa_data*)pDevice->ExtraData;
|
||||
psnd_pcm_start(data->pcmHandle);
|
||||
data->doCapture = 1;
|
||||
if(!data->thread)
|
||||
{
|
||||
psnd_pcm_prepare(data->pcmHandle);
|
||||
psnd_pcm_start(data->pcmHandle);
|
||||
}
|
||||
}
|
||||
|
||||
static void alsa_stop_capture(ALCdevice *pDevice)
|
||||
{
|
||||
alsa_data *data = (alsa_data*)pDevice->ExtraData;
|
||||
psnd_pcm_drain(data->pcmHandle);
|
||||
data->doCapture = 0;
|
||||
if(!data->thread)
|
||||
psnd_pcm_drain(data->pcmHandle);
|
||||
}
|
||||
|
||||
static void alsa_capture_samples(ALCdevice *pDevice, ALCvoid *pBuffer, ALCuint lSamples)
|
||||
@@ -608,8 +742,29 @@ static void alsa_capture_samples(ALCdevice *pDevice, ALCvoid *pBuffer, ALCuint l
|
||||
const snd_pcm_channel_area_t *areas = NULL;
|
||||
snd_pcm_sframes_t frames, commitres;
|
||||
snd_pcm_uframes_t size, offset;
|
||||
snd_pcm_state_t state;
|
||||
int err;
|
||||
|
||||
if(data->thread)
|
||||
{
|
||||
if(lSamples <= (ALCuint)RingBufferSize(data->ring))
|
||||
ReadRingBuffer(data->ring, pBuffer, lSamples);
|
||||
else
|
||||
SetALCError(ALC_INVALID_VALUE);
|
||||
return;
|
||||
}
|
||||
|
||||
state = psnd_pcm_state(data->pcmHandle);
|
||||
if(state == SND_PCM_STATE_XRUN)
|
||||
{
|
||||
err = xrun_recovery(data->pcmHandle, -EPIPE);
|
||||
if(err < 0)
|
||||
{
|
||||
AL_PRINT("XRUN recovery failed: %s\n", psnd_strerror(err));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
frames = psnd_pcm_avail_update(data->pcmHandle);
|
||||
if(frames < 0)
|
||||
{
|
||||
@@ -645,7 +800,7 @@ static void alsa_capture_samples(ALCdevice *pDevice, ALCvoid *pBuffer, ALCuint l
|
||||
}
|
||||
|
||||
Pointer = (char*)areas->addr + (offset * areas->step / 8);
|
||||
Count = size * pDevice->FrameSize;
|
||||
Count = psnd_pcm_frames_to_bytes(data->pcmHandle, size);
|
||||
|
||||
memcpy(pBuffer, Pointer, Count);
|
||||
pBuffer = (char*)pBuffer + Count;
|
||||
@@ -665,16 +820,37 @@ static void alsa_capture_samples(ALCdevice *pDevice, ALCvoid *pBuffer, ALCuint l
|
||||
static ALCuint alsa_available_samples(ALCdevice *pDevice)
|
||||
{
|
||||
alsa_data *data = (alsa_data*)pDevice->ExtraData;
|
||||
snd_pcm_sframes_t frames = psnd_pcm_avail_update(data->pcmHandle);
|
||||
snd_pcm_sframes_t frames;
|
||||
snd_pcm_state_t state;
|
||||
int err;
|
||||
|
||||
if(data->thread)
|
||||
return RingBufferSize(data->ring);
|
||||
|
||||
state = psnd_pcm_state(data->pcmHandle);
|
||||
if(state == SND_PCM_STATE_XRUN)
|
||||
{
|
||||
err = xrun_recovery(data->pcmHandle, -EPIPE);
|
||||
if(err >= 0)
|
||||
{
|
||||
if(data->doCapture)
|
||||
err = psnd_pcm_start(data->pcmHandle);
|
||||
}
|
||||
if (err < 0)
|
||||
{
|
||||
AL_PRINT("XRUN recovery failed: %s\n", psnd_strerror(err));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
frames = psnd_pcm_avail_update(data->pcmHandle);
|
||||
if(frames < 0)
|
||||
{
|
||||
int err = xrun_recovery(data->pcmHandle, frames);
|
||||
err = xrun_recovery(data->pcmHandle, frames);
|
||||
if (err < 0)
|
||||
AL_PRINT("available update failed: %s\n", psnd_strerror(err));
|
||||
else
|
||||
frames = psnd_pcm_avail_update(data->pcmHandle);
|
||||
if(frames < 0) /* ew.. */
|
||||
SetALCError(ALC_INVALID_DEVICE);
|
||||
}
|
||||
return max(frames, 0);
|
||||
}
|
||||
@@ -721,7 +897,7 @@ void alc_alsa_init(BackendFuncs *func_list)
|
||||
} while(0)
|
||||
#else
|
||||
str = NULL;
|
||||
alsa_handle = 0xDEADBEEF;
|
||||
alsa_handle = (void*)0xDEADBEEF;
|
||||
#define LOAD_FUNC(f) p##f = f
|
||||
#endif
|
||||
|
||||
@@ -741,17 +917,20 @@ LOAD_FUNC(snd_pcm_hw_params_set_rate_near);
|
||||
LOAD_FUNC(snd_pcm_hw_params_set_rate);
|
||||
LOAD_FUNC(snd_pcm_hw_params_set_buffer_size_near);
|
||||
LOAD_FUNC(snd_pcm_hw_params_set_buffer_size_min);
|
||||
LOAD_FUNC(snd_pcm_hw_params_get_buffer_size);
|
||||
LOAD_FUNC(snd_pcm_hw_params_get_period_size);
|
||||
LOAD_FUNC(snd_pcm_hw_params_get_access);
|
||||
LOAD_FUNC(snd_pcm_hw_params);
|
||||
LOAD_FUNC(snd_pcm_prepare);
|
||||
LOAD_FUNC(snd_pcm_start);
|
||||
LOAD_FUNC(snd_pcm_resume);
|
||||
LOAD_FUNC(snd_pcm_wait);
|
||||
LOAD_FUNC(snd_pcm_state);
|
||||
LOAD_FUNC(snd_pcm_avail_update);
|
||||
LOAD_FUNC(snd_pcm_areas_silence);
|
||||
LOAD_FUNC(snd_pcm_mmap_begin);
|
||||
LOAD_FUNC(snd_pcm_mmap_commit);
|
||||
LOAD_FUNC(snd_pcm_readi);
|
||||
LOAD_FUNC(snd_pcm_writei);
|
||||
LOAD_FUNC(snd_pcm_drain);
|
||||
|
||||
@@ -779,11 +958,9 @@ LOAD_FUNC(snd_card_next);
|
||||
card = -1;
|
||||
if(psnd_card_next(&card) < 0 || card < 0)
|
||||
AL_PRINT("no playback cards found...\n");
|
||||
else
|
||||
{
|
||||
alsaDeviceList[0] = AppendDeviceList("ALSA Software on default");
|
||||
allDevNameMap[0].name = AppendAllDeviceList("ALSA Software on default");
|
||||
}
|
||||
|
||||
alsaDevice = AppendDeviceList("ALSA Software");
|
||||
allDevNameMap[0].name = AppendAllDeviceList("ALSA Software on default");
|
||||
|
||||
while (card >= 0) {
|
||||
sprintf(name, "hw:%d", card);
|
||||
@@ -796,11 +973,6 @@ LOAD_FUNC(snd_card_next);
|
||||
psnd_ctl_close(handle);
|
||||
goto next_card;
|
||||
}
|
||||
if(card < MAX_DEVICES-1) {
|
||||
snprintf(name, sizeof(name), "ALSA Software on %s",
|
||||
psnd_ctl_card_info_get_name(info));
|
||||
alsaDeviceList[card+1] = AppendDeviceList(name);
|
||||
}
|
||||
|
||||
dev = -1;
|
||||
while (idx < MAX_ALL_DEVICES) {
|
||||
@@ -810,6 +982,7 @@ LOAD_FUNC(snd_card_next);
|
||||
AL_PRINT("snd_ctl_pcm_next_device failed\n");
|
||||
if (dev < 0)
|
||||
break;
|
||||
|
||||
psnd_pcm_info_set_device(pcminfo, dev);
|
||||
psnd_pcm_info_set_subdevice(pcminfo, 0);
|
||||
psnd_pcm_info_set_stream(pcminfo, stream);
|
||||
@@ -821,8 +994,8 @@ LOAD_FUNC(snd_card_next);
|
||||
|
||||
cname = psnd_ctl_card_info_get_name(info);
|
||||
dname = psnd_pcm_info_get_name(pcminfo);
|
||||
snprintf(name, sizeof(name), "ALSA Software on %s [%s]",
|
||||
cname, dname);
|
||||
snprintf(name, sizeof(name), "ALSA Software on %s [%s] (hw:%d,%d)",
|
||||
cname, dname, card, dev);
|
||||
allDevNameMap[idx].name = AppendAllDeviceList(name);
|
||||
allDevNameMap[idx].card = card;
|
||||
allDevNameMap[idx].dev = dev;
|
||||
@@ -847,7 +1020,8 @@ next_card:
|
||||
return;
|
||||
}
|
||||
|
||||
alsaCaptureDeviceList[0] = AppendCaptureDeviceList("ALSA Capture on default");
|
||||
allCaptureDevNameMap[0].name = AppendCaptureDeviceList("ALSA Capture on default");
|
||||
idx = 1;
|
||||
|
||||
while (card >= 0) {
|
||||
sprintf(name, "hw:%d", card);
|
||||
@@ -858,11 +1032,34 @@ next_card:
|
||||
if (err >= 0 && (err = psnd_ctl_card_info(handle, info)) < 0) {
|
||||
AL_PRINT("control hardware info (%i): %s\n", card, psnd_strerror(err));
|
||||
}
|
||||
else if (err >= 0 && card < MAX_DEVICES-1)
|
||||
else if (err >= 0)
|
||||
{
|
||||
snprintf(name, sizeof(name), "ALSA Capture on %s",
|
||||
psnd_ctl_card_info_get_name(info));
|
||||
alsaCaptureDeviceList[card+1] = AppendCaptureDeviceList(name);
|
||||
dev = -1;
|
||||
while (idx < MAX_ALL_DEVICES) {
|
||||
const char *cname, *dname;
|
||||
|
||||
if (psnd_ctl_pcm_next_device(handle, &dev)<0)
|
||||
AL_PRINT("snd_ctl_pcm_next_device failed\n");
|
||||
if (dev < 0)
|
||||
break;
|
||||
psnd_pcm_info_set_device(pcminfo, dev);
|
||||
psnd_pcm_info_set_subdevice(pcminfo, 0);
|
||||
psnd_pcm_info_set_stream(pcminfo, stream);
|
||||
if ((err = psnd_ctl_pcm_info(handle, pcminfo)) < 0) {
|
||||
if (err != -ENOENT)
|
||||
AL_PRINT("control digital audio info (%i): %s\n", card, psnd_strerror(err));
|
||||
continue;
|
||||
}
|
||||
|
||||
cname = psnd_ctl_card_info_get_name(info);
|
||||
dname = psnd_pcm_info_get_name(pcminfo);
|
||||
snprintf(name, sizeof(name), "ALSA Capture on %s [%s] (hw:%d,%d)",
|
||||
cname, dname, card, dev);
|
||||
allCaptureDevNameMap[idx].name = AppendCaptureDeviceList(name);
|
||||
allCaptureDevNameMap[idx].card = card;
|
||||
allCaptureDevNameMap[idx].dev = dev;
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
if(handle) psnd_ctl_close(handle);
|
||||
if(psnd_card_next(&card) < 0) {
|
||||
|
||||
+226
-53
@@ -20,18 +20,31 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#define _WIN32_WINNT 0x0500
|
||||
#define INITGUID
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <memory.h>
|
||||
|
||||
#include <windows.h>
|
||||
#include <mmsystem.h>
|
||||
#include <dsound.h>
|
||||
#include <mmreg.h>
|
||||
|
||||
#include "alMain.h"
|
||||
#include "AL/al.h"
|
||||
#include "AL/alc.h"
|
||||
|
||||
#ifndef DSSPEAKER_7POINT1
|
||||
#define DSSPEAKER_7POINT1 7
|
||||
#endif
|
||||
|
||||
DEFINE_GUID(KSDATAFORMAT_SUBTYPE_PCM, 0x00000001, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71);
|
||||
|
||||
static void *ds_handle;
|
||||
static HRESULT (WINAPI *pDirectSoundCreate)(LPCGUID pcGuidDevice, LPDIRECTSOUND *ppDS, LPUNKNOWN pUnkOuter);
|
||||
static HRESULT (WINAPI *pDirectSoundEnumerateA)(LPDSENUMCALLBACKA pDSEnumCallback, LPVOID pContext);
|
||||
|
||||
// Since DSound doesn't report the fragment size, emulate it
|
||||
static int num_frags;
|
||||
|
||||
typedef struct {
|
||||
// DirectSound Playback Device
|
||||
@@ -39,12 +52,16 @@ typedef struct {
|
||||
LPDIRECTSOUNDBUFFER DSpbuffer;
|
||||
LPDIRECTSOUNDBUFFER DSsbuffer;
|
||||
|
||||
int killNow;
|
||||
volatile int killNow;
|
||||
ALvoid *thread;
|
||||
} DSoundData;
|
||||
|
||||
|
||||
static ALCchar *DeviceList[16];
|
||||
typedef struct {
|
||||
ALCchar *name;
|
||||
GUID guid;
|
||||
} DevMap;
|
||||
static DevMap DeviceList[16];
|
||||
|
||||
|
||||
static ALuint DSoundProc(ALvoid *ptr)
|
||||
@@ -53,26 +70,32 @@ static ALuint DSoundProc(ALvoid *ptr)
|
||||
DSoundData *pData = (DSoundData*)pDevice->ExtraData;
|
||||
DWORD LastCursor = 0;
|
||||
DWORD PlayCursor;
|
||||
VOID *WritePtr;
|
||||
DWORD WriteCnt;
|
||||
VOID *WritePtr1, *WritePtr2;
|
||||
DWORD WriteCnt1, WriteCnt2;
|
||||
DWORD BufferSize;
|
||||
DWORD avail;
|
||||
HRESULT err;
|
||||
|
||||
BufferSize = pDevice->UpdateSize * num_frags *
|
||||
aluBytesFromFormat(pDevice->Format) *
|
||||
aluChannelsFromFormat(pDevice->Format);
|
||||
|
||||
while(!pData->killNow)
|
||||
{
|
||||
// Get current play and write cursors
|
||||
IDirectSoundBuffer_GetCurrentPosition(pData->DSsbuffer, &PlayCursor, NULL);
|
||||
avail = (PlayCursor-LastCursor) % (pDevice->UpdateFreq*pDevice->FrameSize);
|
||||
avail = (PlayCursor-LastCursor+BufferSize) % BufferSize;
|
||||
|
||||
if(avail == 0)
|
||||
if(avail < BufferSize/num_frags)
|
||||
{
|
||||
Sleep(1);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Lock output buffer
|
||||
WriteCnt = 0;
|
||||
err = IDirectSoundBuffer_Lock(pData->DSsbuffer, LastCursor, avail, &WritePtr, &WriteCnt, NULL, NULL, 0);
|
||||
WriteCnt1 = 0;
|
||||
WriteCnt2 = 0;
|
||||
err = IDirectSoundBuffer_Lock(pData->DSsbuffer, LastCursor, avail, &WritePtr1, &WriteCnt1, &WritePtr2, &WriteCnt2, 0);
|
||||
|
||||
// If the buffer is lost, restore it, play and lock
|
||||
if(err == DSERR_BUFFERLOST)
|
||||
@@ -81,7 +104,7 @@ static ALuint DSoundProc(ALvoid *ptr)
|
||||
if(SUCCEEDED(err))
|
||||
err = IDirectSoundBuffer_Play(pData->DSsbuffer, 0, 0, DSBPLAY_LOOPING);
|
||||
if(SUCCEEDED(err))
|
||||
err = IDirectSoundBuffer_Lock(pData->DSsbuffer, LastCursor, avail, (LPVOID*)&WritePtr, &WriteCnt, NULL, NULL, 0);
|
||||
err = IDirectSoundBuffer_Lock(pData->DSsbuffer, LastCursor, avail, &WritePtr1, &WriteCnt1, &WritePtr2, &WriteCnt2, 0);
|
||||
}
|
||||
|
||||
// Successfully locked the output buffer
|
||||
@@ -89,18 +112,19 @@ static ALuint DSoundProc(ALvoid *ptr)
|
||||
{
|
||||
// If we have an active context, mix data directly into output buffer otherwise fill with silence
|
||||
SuspendContext(NULL);
|
||||
aluMixData(pDevice->Context, WritePtr, WriteCnt, pDevice->Format);
|
||||
aluMixData(pDevice->Context, WritePtr1, WriteCnt1, pDevice->Format);
|
||||
aluMixData(pDevice->Context, WritePtr2, WriteCnt2, pDevice->Format);
|
||||
ProcessContext(NULL);
|
||||
|
||||
// Unlock output buffer only when successfully locked
|
||||
IDirectSoundBuffer_Unlock(pData->DSsbuffer, WritePtr, WriteCnt, NULL, 0);
|
||||
IDirectSoundBuffer_Unlock(pData->DSsbuffer, WritePtr1, WriteCnt1, WritePtr2, WriteCnt2);
|
||||
}
|
||||
else
|
||||
AL_PRINT("Buffer lock error: %#lx\n", err);
|
||||
|
||||
// Update old write cursor location
|
||||
LastCursor += WriteCnt;
|
||||
LastCursor %= pDevice->UpdateFreq*pDevice->FrameSize;
|
||||
LastCursor += WriteCnt1+WriteCnt2;
|
||||
LastCursor %= BufferSize;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -110,35 +134,35 @@ static ALCboolean DSoundOpenPlayback(ALCdevice *device, const ALCchar *deviceNam
|
||||
{
|
||||
DSBUFFERDESC DSBDescription;
|
||||
DSoundData *pData = NULL;
|
||||
WAVEFORMATEX OutputType;
|
||||
WAVEFORMATEXTENSIBLE OutputType;
|
||||
DWORD frameSize = 0;
|
||||
LPGUID guid = NULL;
|
||||
DWORD speakers;
|
||||
HRESULT hr;
|
||||
|
||||
if(ds_handle == NULL)
|
||||
return ALC_FALSE;
|
||||
|
||||
if(deviceName)
|
||||
{
|
||||
int i;
|
||||
for(i = 0;DeviceList[i];i++)
|
||||
for(i = 0;DeviceList[i].name;i++)
|
||||
{
|
||||
if(strcmp(deviceName, DeviceList[i]) == 0)
|
||||
if(strcmp(deviceName, DeviceList[i].name) == 0)
|
||||
{
|
||||
device->szDeviceName = DeviceList[i];
|
||||
device->szDeviceName = DeviceList[i].name;
|
||||
if(i > 0)
|
||||
guid = &DeviceList[i].guid;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!DeviceList[i])
|
||||
if(!DeviceList[i].name)
|
||||
return ALC_FALSE;
|
||||
}
|
||||
else
|
||||
device->szDeviceName = DeviceList[0];
|
||||
device->szDeviceName = DeviceList[0].name;
|
||||
|
||||
//Platform specific
|
||||
memset(&OutputType, 0, sizeof(WAVEFORMATEX));
|
||||
OutputType.wFormatTag = WAVE_FORMAT_PCM;
|
||||
OutputType.nChannels = device->Channels;
|
||||
OutputType.wBitsPerSample = aluBytesFromFormat(device->Format) * 8;
|
||||
OutputType.nBlockAlign = OutputType.nChannels*OutputType.wBitsPerSample/8;
|
||||
OutputType.nSamplesPerSec = device->Frequency;
|
||||
OutputType.nAvgBytesPerSec = OutputType.nSamplesPerSec*OutputType.nBlockAlign;
|
||||
OutputType.cbSize = 0;
|
||||
memset(&OutputType, 0, sizeof(OutputType));
|
||||
|
||||
//Initialise requested device
|
||||
|
||||
@@ -149,43 +173,141 @@ static ALCboolean DSoundOpenPlayback(ALCdevice *device, const ALCchar *deviceNam
|
||||
return ALC_FALSE;
|
||||
}
|
||||
|
||||
//Init COM
|
||||
CoInitialize(NULL);
|
||||
|
||||
//DirectSound Init code
|
||||
hr = CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectSound, (LPVOID*)&pData->lpDS);
|
||||
if(SUCCEEDED(hr))
|
||||
hr = IDirectSound_Initialize(pData->lpDS, NULL);
|
||||
hr = pDirectSoundCreate(guid, &pData->lpDS, NULL);
|
||||
if(SUCCEEDED(hr))
|
||||
hr = IDirectSound_SetCooperativeLevel(pData->lpDS, GetForegroundWindow(), DSSCL_PRIORITY);
|
||||
|
||||
if(SUCCEEDED(hr))
|
||||
{
|
||||
memset(&DSBDescription,0,sizeof(DSBUFFERDESC));
|
||||
DSBDescription.dwSize=sizeof(DSBUFFERDESC);
|
||||
DSBDescription.dwFlags=DSBCAPS_PRIMARYBUFFER;
|
||||
hr = IDirectSound_CreateSoundBuffer(pData->lpDS, &DSBDescription, &pData->DSpbuffer, NULL);
|
||||
if(*(GetConfigValue(NULL, "format", "")) == 0)
|
||||
hr = IDirectSound_GetSpeakerConfig(pData->lpDS, &speakers);
|
||||
else
|
||||
{
|
||||
if(device->Format == AL_FORMAT_MONO8 || device->Format == AL_FORMAT_MONO16)
|
||||
speakers = DSSPEAKER_COMBINED(DSSPEAKER_MONO, 0);
|
||||
else if(device->Format == AL_FORMAT_STEREO8 || device->Format == AL_FORMAT_STEREO16)
|
||||
speakers = DSSPEAKER_COMBINED(DSSPEAKER_STEREO, 0);
|
||||
else if(device->Format == AL_FORMAT_QUAD8 || device->Format == AL_FORMAT_QUAD16)
|
||||
speakers = DSSPEAKER_COMBINED(DSSPEAKER_QUAD, 0);
|
||||
else if(device->Format == AL_FORMAT_51CHN8 || device->Format == AL_FORMAT_51CHN16)
|
||||
speakers = DSSPEAKER_COMBINED(DSSPEAKER_5POINT1, 0);
|
||||
else if(device->Format == AL_FORMAT_71CHN8 || device->Format == AL_FORMAT_71CHN16)
|
||||
speakers = DSSPEAKER_COMBINED(DSSPEAKER_7POINT1, 0);
|
||||
else
|
||||
hr = IDirectSound_GetSpeakerConfig(pData->lpDS, &speakers);
|
||||
}
|
||||
}
|
||||
if(SUCCEEDED(hr))
|
||||
hr = IDirectSoundBuffer_SetFormat(pData->DSpbuffer,&OutputType);
|
||||
{
|
||||
speakers = DSSPEAKER_CONFIG(speakers);
|
||||
if(speakers == DSSPEAKER_MONO)
|
||||
{
|
||||
if(aluBytesFromFormat(device->Format) == 1)
|
||||
device->Format = AL_FORMAT_MONO8;
|
||||
else
|
||||
device->Format = AL_FORMAT_MONO16;
|
||||
}
|
||||
else if(speakers == DSSPEAKER_STEREO)
|
||||
{
|
||||
if(aluBytesFromFormat(device->Format) == 1)
|
||||
device->Format = AL_FORMAT_STEREO8;
|
||||
else
|
||||
device->Format = AL_FORMAT_STEREO16;
|
||||
}
|
||||
else if(speakers == DSSPEAKER_QUAD)
|
||||
{
|
||||
if(aluBytesFromFormat(device->Format) == 1)
|
||||
device->Format = AL_FORMAT_QUAD8;
|
||||
else
|
||||
device->Format = AL_FORMAT_QUAD16;
|
||||
OutputType.dwChannelMask = SPEAKER_FRONT_LEFT |
|
||||
SPEAKER_FRONT_RIGHT |
|
||||
SPEAKER_BACK_LEFT |
|
||||
SPEAKER_BACK_RIGHT;
|
||||
}
|
||||
else if(speakers == DSSPEAKER_5POINT1)
|
||||
{
|
||||
if(aluBytesFromFormat(device->Format) == 1)
|
||||
device->Format = AL_FORMAT_51CHN8;
|
||||
else
|
||||
device->Format = AL_FORMAT_51CHN16;
|
||||
OutputType.dwChannelMask = SPEAKER_FRONT_LEFT |
|
||||
SPEAKER_FRONT_RIGHT |
|
||||
SPEAKER_FRONT_CENTER |
|
||||
SPEAKER_LOW_FREQUENCY |
|
||||
SPEAKER_BACK_LEFT |
|
||||
SPEAKER_BACK_RIGHT;
|
||||
}
|
||||
else if(speakers == DSSPEAKER_7POINT1)
|
||||
{
|
||||
if(aluBytesFromFormat(device->Format) == 1)
|
||||
device->Format = AL_FORMAT_71CHN8;
|
||||
else
|
||||
device->Format = AL_FORMAT_71CHN16;
|
||||
OutputType.dwChannelMask = SPEAKER_FRONT_LEFT |
|
||||
SPEAKER_FRONT_RIGHT |
|
||||
SPEAKER_FRONT_CENTER |
|
||||
SPEAKER_LOW_FREQUENCY |
|
||||
SPEAKER_BACK_LEFT |
|
||||
SPEAKER_BACK_RIGHT |
|
||||
SPEAKER_SIDE_LEFT |
|
||||
SPEAKER_SIDE_RIGHT;
|
||||
}
|
||||
frameSize = aluBytesFromFormat(device->Format) *
|
||||
aluChannelsFromFormat(device->Format);
|
||||
|
||||
OutputType.Format.wFormatTag = WAVE_FORMAT_PCM;
|
||||
OutputType.Format.nChannels = aluChannelsFromFormat(device->Format);
|
||||
OutputType.Format.wBitsPerSample = aluBytesFromFormat(device->Format) * 8;
|
||||
OutputType.Format.nBlockAlign = OutputType.Format.nChannels*OutputType.Format.wBitsPerSample/8;
|
||||
OutputType.Format.nSamplesPerSec = device->Frequency;
|
||||
OutputType.Format.nAvgBytesPerSec = OutputType.Format.nSamplesPerSec*OutputType.Format.nBlockAlign;
|
||||
OutputType.Format.cbSize = 0;
|
||||
|
||||
device->UpdateSize /= num_frags;
|
||||
}
|
||||
|
||||
if(OutputType.Format.nChannels > 2)
|
||||
{
|
||||
OutputType.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
|
||||
OutputType.Samples.wValidBitsPerSample = OutputType.Format.wBitsPerSample;
|
||||
OutputType.Format.cbSize = 22;
|
||||
OutputType.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(SUCCEEDED(hr))
|
||||
{
|
||||
memset(&DSBDescription,0,sizeof(DSBUFFERDESC));
|
||||
DSBDescription.dwSize=sizeof(DSBUFFERDESC);
|
||||
DSBDescription.dwFlags=DSBCAPS_PRIMARYBUFFER;
|
||||
hr = IDirectSound_CreateSoundBuffer(pData->lpDS, &DSBDescription, &pData->DSpbuffer, NULL);
|
||||
}
|
||||
if(SUCCEEDED(hr))
|
||||
hr = IDirectSoundBuffer_SetFormat(pData->DSpbuffer,&OutputType.Format);
|
||||
}
|
||||
|
||||
if(SUCCEEDED(hr))
|
||||
{
|
||||
memset(&DSBDescription,0,sizeof(DSBUFFERDESC));
|
||||
DSBDescription.dwSize=sizeof(DSBUFFERDESC);
|
||||
DSBDescription.dwFlags=DSBCAPS_GLOBALFOCUS|DSBCAPS_GETCURRENTPOSITION2;
|
||||
DSBDescription.dwBufferBytes=device->UpdateFreq * device->FrameSize;
|
||||
DSBDescription.lpwfxFormat=&OutputType;
|
||||
DSBDescription.dwBufferBytes=device->UpdateSize * num_frags * frameSize;
|
||||
DSBDescription.lpwfxFormat=&OutputType.Format;
|
||||
hr = IDirectSound_CreateSoundBuffer(pData->lpDS, &DSBDescription, &pData->DSsbuffer, NULL);
|
||||
}
|
||||
|
||||
if(SUCCEEDED(hr))
|
||||
hr = IDirectSoundBuffer_Play(pData->DSsbuffer, 0, 0, DSBPLAY_LOOPING);
|
||||
|
||||
device->ExtraData = pData;
|
||||
pData->thread = StartThread(DSoundProc, device);
|
||||
if(!pData->thread)
|
||||
hr = E_FAIL;
|
||||
if(SUCCEEDED(hr))
|
||||
{
|
||||
device->ExtraData = pData;
|
||||
pData->thread = StartThread(DSoundProc, device);
|
||||
if(!pData->thread)
|
||||
hr = E_FAIL;
|
||||
}
|
||||
|
||||
if(FAILED(hr))
|
||||
{
|
||||
@@ -211,12 +333,10 @@ static void DSoundClosePlayback(ALCdevice *device)
|
||||
StopThread(pData->thread);
|
||||
|
||||
IDirectSoundBuffer_Release(pData->DSsbuffer);
|
||||
IDirectSoundBuffer_Release(pData->DSpbuffer);
|
||||
if (pData->DSpbuffer)
|
||||
IDirectSoundBuffer_Release(pData->DSpbuffer);
|
||||
IDirectSound_Release(pData->lpDS);
|
||||
|
||||
//Deinit COM
|
||||
CoUninitialize();
|
||||
|
||||
free(pData);
|
||||
device->ExtraData = NULL;
|
||||
}
|
||||
@@ -272,10 +392,63 @@ BackendFuncs DSoundFuncs = {
|
||||
DSoundAvailableSamples
|
||||
};
|
||||
|
||||
static BOOL CALLBACK DSoundEnumDevices(LPGUID guid, LPCSTR desc, LPCSTR drvname, LPVOID data)
|
||||
{
|
||||
size_t *iter = data;
|
||||
(void)drvname;
|
||||
|
||||
if(guid)
|
||||
{
|
||||
char str[128];
|
||||
snprintf(str, sizeof(str), "DirectSound Software on %s", desc);
|
||||
DeviceList[*iter].name = AppendAllDeviceList(str);
|
||||
DeviceList[*iter].guid = *guid;
|
||||
(*iter)++;
|
||||
}
|
||||
else
|
||||
DeviceList[0].name = AppendDeviceList("DirectSound Software");
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void alcDSoundInit(BackendFuncs *FuncList)
|
||||
{
|
||||
size_t iter = 1;
|
||||
HRESULT hr;
|
||||
|
||||
*FuncList = DSoundFuncs;
|
||||
|
||||
DeviceList[0] = AppendDeviceList("DirectSound Software");
|
||||
AppendAllDeviceList(DeviceList[0]);
|
||||
#ifdef _WIN32
|
||||
ds_handle = LoadLibraryA("dsound.dll");
|
||||
if(ds_handle == NULL)
|
||||
{
|
||||
AL_PRINT("Failed to load dsound.dll\n");
|
||||
return;
|
||||
}
|
||||
|
||||
#define LOAD_FUNC(f) do { \
|
||||
p##f = (void*)GetProcAddress((HMODULE)ds_handle, #f); \
|
||||
if(p##f == NULL) \
|
||||
{ \
|
||||
FreeLibrary(ds_handle); \
|
||||
ds_handle = NULL; \
|
||||
AL_PRINT("Could not load %s from dsound.dll\n", #f); \
|
||||
return; \
|
||||
} \
|
||||
} while(0)
|
||||
#else
|
||||
ds_handle = (void*)0xDEADBEEF;
|
||||
#define LOAD_FUNC(f) p##f = f
|
||||
#endif
|
||||
|
||||
LOAD_FUNC(DirectSoundCreate);
|
||||
LOAD_FUNC(DirectSoundEnumerateA);
|
||||
#undef LOAD_FUNC
|
||||
|
||||
num_frags = GetConfigValueInt("dsound", "periods", 4);
|
||||
if(num_frags < 2) num_frags = 2;
|
||||
|
||||
hr = pDirectSoundEnumerateA(DSoundEnumDevices, &iter);
|
||||
if(FAILED(hr))
|
||||
AL_PRINT("Error enumerating DirectSound devices (%#x)!\n", (unsigned int)hr);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ static char *oss_device_capture;
|
||||
|
||||
typedef struct {
|
||||
int fd;
|
||||
int killNow;
|
||||
volatile int killNow;
|
||||
ALvoid *thread;
|
||||
|
||||
ALubyte *mix_data;
|
||||
@@ -149,6 +149,7 @@ static ALCboolean oss_open_playback(ALCdevice *device, const ALCchar *deviceName
|
||||
int log2FragmentSize;
|
||||
unsigned int periods;
|
||||
audio_buf_info info;
|
||||
ALuint frameSize;
|
||||
char driver[64];
|
||||
int numChannels;
|
||||
oss_data *data;
|
||||
@@ -195,9 +196,11 @@ static ALCboolean oss_open_playback(ALCdevice *device, const ALCchar *deviceName
|
||||
periods = GetConfigValueInt("oss", "periods", 4);
|
||||
if((int)periods <= 0)
|
||||
periods = 4;
|
||||
numChannels = device->Channels;
|
||||
numChannels = aluChannelsFromFormat(device->Format);
|
||||
frameSize = numChannels * aluBytesFromFormat(device->Format);
|
||||
|
||||
ossSpeed = device->Frequency;
|
||||
log2FragmentSize = log2i(device->UpdateFreq * device->FrameSize / periods);
|
||||
log2FragmentSize = log2i(device->UpdateSize * frameSize / periods);
|
||||
|
||||
/* according to the OSS spec, 16 bytes are the minimum */
|
||||
if (log2FragmentSize < 4)
|
||||
@@ -218,11 +221,9 @@ static ALCboolean oss_open_playback(ALCdevice *device, const ALCchar *deviceName
|
||||
}
|
||||
#undef ok
|
||||
|
||||
device->Frequency = ossSpeed;
|
||||
|
||||
if((int)device->Channels != numChannels)
|
||||
if((int)aluChannelsFromFormat(device->Format) != numChannels)
|
||||
{
|
||||
AL_PRINT("Could not set %d channels, got %d instead\n", device->Channels, numChannels);
|
||||
AL_PRINT("Could not set %d channels, got %d instead\n", aluChannelsFromFormat(device->Format), numChannels);
|
||||
close(data->fd);
|
||||
free(data);
|
||||
return ALC_FALSE;
|
||||
@@ -237,9 +238,7 @@ static ALCboolean oss_open_playback(ALCdevice *device, const ALCchar *deviceName
|
||||
return ALC_FALSE;
|
||||
}
|
||||
|
||||
device->UpdateFreq = info.fragsize / device->FrameSize;
|
||||
|
||||
data->data_size = device->UpdateFreq * device->FrameSize;
|
||||
data->data_size = device->UpdateSize * frameSize;
|
||||
data->mix_data = calloc(1, data->data_size);
|
||||
|
||||
device->ExtraData = data;
|
||||
@@ -252,6 +251,9 @@ static ALCboolean oss_open_playback(ALCdevice *device, const ALCchar *deviceName
|
||||
return ALC_FALSE;
|
||||
}
|
||||
|
||||
device->Frequency = ossSpeed;
|
||||
device->UpdateSize = info.fragsize / frameSize;
|
||||
|
||||
return ALC_TRUE;
|
||||
}
|
||||
|
||||
@@ -275,6 +277,7 @@ static ALCboolean oss_open_capture(ALCdevice *device, const ALCchar *deviceName,
|
||||
int log2FragmentSize;
|
||||
unsigned int periods;
|
||||
audio_buf_info info;
|
||||
ALuint frameSize;
|
||||
int numChannels;
|
||||
char driver[64];
|
||||
oss_data *data;
|
||||
@@ -319,9 +322,10 @@ static ALCboolean oss_open_capture(ALCdevice *device, const ALCchar *deviceName,
|
||||
}
|
||||
|
||||
periods = 4;
|
||||
numChannels = device->Channels;
|
||||
numChannels = aluChannelsFromFormat(device->Format);
|
||||
frameSize = numChannels * aluBytesFromFormat(device->Format);
|
||||
ossSpeed = frequency;
|
||||
log2FragmentSize = log2i(device->UpdateFreq * device->FrameSize / periods);
|
||||
log2FragmentSize = log2i(SampleSize * frameSize / periods);
|
||||
|
||||
/* according to the OSS spec, 16 bytes are the minimum */
|
||||
if (log2FragmentSize < 4)
|
||||
@@ -342,55 +346,24 @@ static ALCboolean oss_open_capture(ALCdevice *device, const ALCchar *deviceName,
|
||||
}
|
||||
#undef ok
|
||||
|
||||
device->Channels = numChannels;
|
||||
device->Frequency = ossSpeed;
|
||||
device->Format = 0;
|
||||
if(ossFormat == AFMT_U8)
|
||||
if((int)aluChannelsFromFormat(device->Format) != numChannels)
|
||||
{
|
||||
if(device->Channels == 1)
|
||||
{
|
||||
device->Format = AL_FORMAT_MONO8;
|
||||
device->FrameSize = 1;
|
||||
}
|
||||
else if(device->Channels == 2)
|
||||
{
|
||||
device->Format = AL_FORMAT_STEREO8;
|
||||
device->FrameSize = 2;
|
||||
}
|
||||
else if(device->Channels == 4)
|
||||
{
|
||||
device->Format = AL_FORMAT_QUAD8;
|
||||
device->FrameSize = 4;
|
||||
}
|
||||
}
|
||||
else if(ossFormat == AFMT_S16_NE)
|
||||
{
|
||||
if(device->Channels == 1)
|
||||
{
|
||||
device->Format = AL_FORMAT_MONO16;
|
||||
device->FrameSize = 2;
|
||||
}
|
||||
else if(device->Channels == 2)
|
||||
{
|
||||
device->Format = AL_FORMAT_STEREO16;
|
||||
device->FrameSize = 4;
|
||||
}
|
||||
else if(device->Channels == 4)
|
||||
{
|
||||
device->Format = AL_FORMAT_QUAD16;
|
||||
device->FrameSize = 8;
|
||||
}
|
||||
}
|
||||
|
||||
if(!device->Format)
|
||||
{
|
||||
AL_PRINT("returned unknown format: %#x %d!\n", ossFormat, numChannels);
|
||||
AL_PRINT("Could not set %d channels, got %d instead\n", aluChannelsFromFormat(device->Format), numChannels);
|
||||
close(data->fd);
|
||||
free(data);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
|
||||
data->ring = CreateRingBuffer(device->FrameSize, SampleSize);
|
||||
if(!((ossFormat == AFMT_U8 && aluBytesFromFormat(device->Format) == 1) ||
|
||||
(ossFormat == AFMT_S16_NE && aluBytesFromFormat(device->Format) == 2)))
|
||||
{
|
||||
AL_PRINT("Could not set %d-bit input, got format %#x\n", aluBytesFromFormat(device->Format)*8, ossFormat);
|
||||
close(data->fd);
|
||||
free(data);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
|
||||
data->ring = CreateRingBuffer(frameSize, SampleSize);
|
||||
if(!data->ring)
|
||||
{
|
||||
AL_PRINT("ring buffer create failed\n");
|
||||
@@ -399,9 +372,7 @@ static ALCboolean oss_open_capture(ALCdevice *device, const ALCchar *deviceName,
|
||||
return ALC_FALSE;
|
||||
}
|
||||
|
||||
device->UpdateFreq = info.fragsize / device->FrameSize;
|
||||
|
||||
data->data_size = device->UpdateFreq * device->FrameSize * info.fragments;
|
||||
data->data_size = info.fragsize;
|
||||
data->mix_data = calloc(1, data->data_size);
|
||||
|
||||
device->ExtraData = data;
|
||||
|
||||
+239
@@ -0,0 +1,239 @@
|
||||
/**
|
||||
* 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "alMain.h"
|
||||
#include "AL/al.h"
|
||||
#include "AL/alc.h"
|
||||
#ifdef HAVE_DLFCN_H
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
#include <portaudio.h>
|
||||
|
||||
static void *pa_handle;
|
||||
#define MAKE_FUNC(x) static typeof(x) * p##x
|
||||
MAKE_FUNC(Pa_Initialize);
|
||||
MAKE_FUNC(Pa_GetErrorText);
|
||||
MAKE_FUNC(Pa_StartStream);
|
||||
MAKE_FUNC(Pa_StopStream);
|
||||
MAKE_FUNC(Pa_OpenStream);
|
||||
MAKE_FUNC(Pa_CloseStream);
|
||||
MAKE_FUNC(Pa_GetDefaultOutputDevice);
|
||||
#undef MAKE_FUNC
|
||||
|
||||
|
||||
static char *pa_device;
|
||||
|
||||
typedef struct {
|
||||
PaStream *stream;
|
||||
} pa_data;
|
||||
|
||||
|
||||
static int pa_callback(const void *inputBuffer, void *outputBuffer,
|
||||
unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo,
|
||||
const PaStreamCallbackFlags statusFlags, void *userData)
|
||||
{
|
||||
ALCdevice *device = (ALCdevice*)userData;
|
||||
int frameSize;
|
||||
|
||||
(void)inputBuffer;
|
||||
(void)timeInfo;
|
||||
(void)statusFlags;
|
||||
|
||||
frameSize = aluBytesFromFormat(device->Format);
|
||||
frameSize *= aluChannelsFromFormat(device->Format);
|
||||
|
||||
SuspendContext(NULL);
|
||||
aluMixData(device->Context, outputBuffer, framesPerBuffer*frameSize, device->Format);
|
||||
ProcessContext(NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static ALCboolean pa_open_playback(ALCdevice *device, const ALCchar *deviceName)
|
||||
{
|
||||
PaStreamParameters outParams;
|
||||
pa_data *data;
|
||||
int periods;
|
||||
PaError err;
|
||||
|
||||
if(pa_handle == NULL)
|
||||
return ALC_FALSE;
|
||||
|
||||
if(deviceName)
|
||||
{
|
||||
if(strcmp(deviceName, pa_device) != 0)
|
||||
return ALC_FALSE;
|
||||
}
|
||||
|
||||
device->szDeviceName = pa_device;
|
||||
|
||||
data = (pa_data*)calloc(1, sizeof(pa_data));
|
||||
device->ExtraData = data;
|
||||
|
||||
outParams.device = GetConfigValueInt("port", "device", -1);
|
||||
if(outParams.device < 0)
|
||||
outParams.device = pPa_GetDefaultOutputDevice();
|
||||
outParams.suggestedLatency = (float)device->UpdateSize /
|
||||
(float)device->Frequency;
|
||||
outParams.hostApiSpecificStreamInfo = NULL;
|
||||
|
||||
switch(aluBytesFromFormat(device->Format))
|
||||
{
|
||||
case 1:
|
||||
outParams.sampleFormat = paUInt8;
|
||||
break;
|
||||
case 2:
|
||||
outParams.sampleFormat = paInt16;
|
||||
break;
|
||||
default:
|
||||
outParams.sampleFormat = -1;
|
||||
AL_PRINT("Unknown format?! %x\n", device->Format);
|
||||
}
|
||||
|
||||
periods = GetConfigValueInt("port", "periods", 4);
|
||||
if((int)periods <= 0)
|
||||
periods = 4;
|
||||
outParams.channelCount = aluChannelsFromFormat(device->Format);
|
||||
|
||||
err = pPa_OpenStream(&data->stream, NULL, &outParams, device->Frequency,
|
||||
device->UpdateSize/periods, paNoFlag,
|
||||
pa_callback, device);
|
||||
if(err != paNoError)
|
||||
{
|
||||
AL_PRINT("Pa_OpenStream() returned an error: %s\n", pPa_GetErrorText(err));
|
||||
device->ExtraData = NULL;
|
||||
free(data);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
|
||||
err = pPa_StartStream(data->stream);
|
||||
if(err != paNoError)
|
||||
{
|
||||
AL_PRINT("Pa_StartStream() returned an error: %s\n", pPa_GetErrorText(err));
|
||||
pPa_CloseStream(data->stream);
|
||||
device->ExtraData = NULL;
|
||||
free(data);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
|
||||
device->UpdateSize /= periods;
|
||||
return ALC_TRUE;
|
||||
}
|
||||
|
||||
static void pa_close_playback(ALCdevice *device)
|
||||
{
|
||||
pa_data *data = (pa_data*)device->ExtraData;
|
||||
PaError err;
|
||||
|
||||
err = pPa_StopStream(data->stream);
|
||||
if(err != paNoError)
|
||||
fprintf(stderr, "Error stopping stream: %s\n", pPa_GetErrorText(err));
|
||||
|
||||
err = pPa_CloseStream(data->stream);
|
||||
if(err != paNoError)
|
||||
fprintf(stderr, "Error closing stream: %s\n", pPa_GetErrorText(err));
|
||||
|
||||
free(data);
|
||||
device->ExtraData = NULL;
|
||||
}
|
||||
|
||||
|
||||
static ALCboolean pa_open_capture(ALCdevice *device, const ALCchar *deviceName, ALCuint frequency, ALCenum format, ALCsizei SampleSize)
|
||||
{
|
||||
return ALC_FALSE;
|
||||
(void)device;
|
||||
(void)deviceName;
|
||||
(void)frequency;
|
||||
(void)format;
|
||||
(void)SampleSize;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static const BackendFuncs pa_funcs = {
|
||||
pa_open_playback,
|
||||
pa_close_playback,
|
||||
pa_open_capture,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
void alc_pa_init(BackendFuncs *func_list)
|
||||
{
|
||||
const char *str;
|
||||
PaError err;
|
||||
|
||||
*func_list = pa_funcs;
|
||||
|
||||
#ifdef HAVE_DLFCN_H
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
# define PALIB "libportaudio.2.dylib"
|
||||
#else
|
||||
# define PALIB "libportaudio.so.2"
|
||||
#endif
|
||||
pa_handle = dlopen(PALIB, RTLD_NOW);
|
||||
if(!pa_handle)
|
||||
return;
|
||||
dlerror();
|
||||
|
||||
#define LOAD_FUNC(f) do { \
|
||||
p##f = (typeof(f)*)dlsym(pa_handle, #f); \
|
||||
if((str=dlerror()) != NULL) \
|
||||
{ \
|
||||
dlclose(pa_handle); \
|
||||
pa_handle = NULL; \
|
||||
AL_PRINT("Could not load %s from "PALIB": %s\n", #f, str); \
|
||||
return; \
|
||||
} \
|
||||
} while(0)
|
||||
#else
|
||||
str = NULL;
|
||||
pa_handle = (void*)0xDEADBEEF;
|
||||
#define LOAD_FUNC(f) p##f = f
|
||||
#endif
|
||||
|
||||
LOAD_FUNC(Pa_Initialize);
|
||||
LOAD_FUNC(Pa_GetErrorText);
|
||||
LOAD_FUNC(Pa_StartStream);
|
||||
LOAD_FUNC(Pa_StopStream);
|
||||
LOAD_FUNC(Pa_OpenStream);
|
||||
LOAD_FUNC(Pa_CloseStream);
|
||||
LOAD_FUNC(Pa_GetDefaultOutputDevice);
|
||||
#undef LOAD_FUNC
|
||||
|
||||
if((err=pPa_Initialize()) != paNoError)
|
||||
{
|
||||
AL_PRINT("Pa_Initialize() returned an error: %s\n", pPa_GetErrorText(err));
|
||||
return;
|
||||
}
|
||||
|
||||
pa_device = AppendDeviceList("PortAudio Software");
|
||||
AppendAllDeviceList(pa_device);
|
||||
}
|
||||
+258
@@ -0,0 +1,258 @@
|
||||
/**
|
||||
* 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 <sys/ioctl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <memory.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <math.h>
|
||||
#include "alMain.h"
|
||||
#include "AL/al.h"
|
||||
#include "AL/alc.h"
|
||||
|
||||
#include <sys/audioio.h>
|
||||
|
||||
|
||||
static char *solaris_device;
|
||||
|
||||
typedef struct {
|
||||
int fd;
|
||||
volatile int killNow;
|
||||
ALvoid *thread;
|
||||
|
||||
ALubyte *mix_data;
|
||||
int data_size;
|
||||
} solaris_data;
|
||||
|
||||
|
||||
static ALuint SolarisProc(ALvoid *ptr)
|
||||
{
|
||||
ALCdevice *pDevice = (ALCdevice*)ptr;
|
||||
solaris_data *data = (solaris_data*)pDevice->ExtraData;
|
||||
int remaining = 0;
|
||||
int wrote;
|
||||
|
||||
while(!data->killNow)
|
||||
{
|
||||
int len = data->data_size - remaining;
|
||||
|
||||
if(len > 0)
|
||||
{
|
||||
SuspendContext(NULL);
|
||||
aluMixData(pDevice->Context, data->mix_data+remaining, len, pDevice->Format);
|
||||
ProcessContext(NULL);
|
||||
}
|
||||
|
||||
remaining += len;
|
||||
wrote = write(data->fd, data->mix_data, remaining);
|
||||
if(wrote < 0)
|
||||
{
|
||||
AL_PRINT("write failed: %s\n", strerror(errno));
|
||||
remaining = 0;
|
||||
}
|
||||
else if(wrote > 0)
|
||||
{
|
||||
remaining -= wrote;
|
||||
if(remaining > 0)
|
||||
memmove(data->mix_data, data->mix_data+wrote, remaining);
|
||||
}
|
||||
else
|
||||
Sleep(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static ALCboolean solaris_open_playback(ALCdevice *device, const ALCchar *deviceName)
|
||||
{
|
||||
audio_info_t info;
|
||||
ALuint frameSize;
|
||||
char driver[64];
|
||||
int numChannels;
|
||||
solaris_data *data;
|
||||
|
||||
strncpy(driver, GetConfigValue("solaris", "device", "/dev/audio"), sizeof(driver)-1);
|
||||
driver[sizeof(driver)-1] = 0;
|
||||
if(deviceName)
|
||||
{
|
||||
if(strcmp(deviceName, solaris_device))
|
||||
return ALC_FALSE;
|
||||
device->szDeviceName = solaris_device;
|
||||
}
|
||||
else
|
||||
device->szDeviceName = solaris_device;
|
||||
|
||||
data = (solaris_data*)calloc(1, sizeof(solaris_data));
|
||||
data->killNow = 0;
|
||||
|
||||
data->fd = open(driver, O_WRONLY);
|
||||
if(data->fd == -1)
|
||||
{
|
||||
free(data);
|
||||
AL_PRINT("Could not open %s: %s\n", driver, strerror(errno));
|
||||
return ALC_FALSE;
|
||||
}
|
||||
|
||||
numChannels = aluChannelsFromFormat(device->Format);
|
||||
AUDIO_INITINFO(&info);
|
||||
info.play.sample_rate = device->Frequency;
|
||||
info.play.channels = numChannels;
|
||||
|
||||
switch(aluBytesFromFormat(device->Format))
|
||||
{
|
||||
case 1:
|
||||
info.play.precision = 8;
|
||||
info.play.encoding = AUDIO_ENCODING_LINEAR8;
|
||||
break;
|
||||
case 2:
|
||||
info.play.precision = 16;
|
||||
info.play.encoding = AUDIO_ENCODING_LINEAR;
|
||||
break;
|
||||
default:
|
||||
AL_PRINT("Unknown format?! %x\n", device->Format);
|
||||
}
|
||||
|
||||
frameSize = numChannels * aluBytesFromFormat(device->Format);
|
||||
info.play.buffer_size = device->UpdateSize * frameSize;
|
||||
|
||||
if(ioctl(data->fd, AUDIO_SETINFO, &info) < 0)
|
||||
{
|
||||
AL_PRINT("ioctl failed: %s\n", strerror(errno));
|
||||
close(data->fd);
|
||||
free(data);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
|
||||
device->Frequency = info.play.sample_rate;
|
||||
|
||||
if(aluChannelsFromFormat(device->Format) != info.play.channels)
|
||||
{
|
||||
AL_PRINT("Could not set %d channels, got %d instead\n", aluChannelsFromFormat(device->Format), info.play.channels);
|
||||
close(data->fd);
|
||||
free(data);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
|
||||
if(!((info.play.precision == 8 && aluBytesFromFormat(device->Format) == 1) ||
|
||||
(info.play.precision == 16 && aluBytesFromFormat(device->Format) == 2)))
|
||||
{
|
||||
AL_PRINT("Could not set %d-bit output, got %d\n", aluBytesFromFormat(device->Format)*8, info.play.precision);
|
||||
close(data->fd);
|
||||
free(data);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
|
||||
device->UpdateSize = info.play.buffer_size / 4;
|
||||
|
||||
data->data_size = device->UpdateSize * frameSize;
|
||||
data->mix_data = calloc(1, data->data_size);
|
||||
|
||||
device->ExtraData = data;
|
||||
data->thread = StartThread(SolarisProc, device);
|
||||
if(data->thread == NULL)
|
||||
{
|
||||
device->ExtraData = NULL;
|
||||
free(data->mix_data);
|
||||
free(data);
|
||||
return ALC_FALSE;
|
||||
}
|
||||
|
||||
return ALC_TRUE;
|
||||
}
|
||||
|
||||
static void solaris_close_playback(ALCdevice *device)
|
||||
{
|
||||
solaris_data *data = (solaris_data*)device->ExtraData;
|
||||
data->killNow = 1;
|
||||
StopThread(data->thread);
|
||||
|
||||
close(data->fd);
|
||||
|
||||
free(data->mix_data);
|
||||
free(data);
|
||||
device->ExtraData = NULL;
|
||||
}
|
||||
|
||||
|
||||
static ALCboolean solaris_open_capture(ALCdevice *device, const ALCchar *deviceName, ALCuint frequency, ALCenum format, ALCsizei SampleSize)
|
||||
{
|
||||
(void)device;
|
||||
(void)deviceName;
|
||||
(void)frequency;
|
||||
(void)format;
|
||||
(void)SampleSize;
|
||||
return ALC_FALSE;
|
||||
}
|
||||
|
||||
static void solaris_close_capture(ALCdevice *device)
|
||||
{
|
||||
(void)device;
|
||||
}
|
||||
|
||||
static void solaris_start_capture(ALCdevice *pDevice)
|
||||
{
|
||||
(void)pDevice;
|
||||
}
|
||||
|
||||
static void solaris_stop_capture(ALCdevice *pDevice)
|
||||
{
|
||||
(void)pDevice;
|
||||
}
|
||||
|
||||
static void solaris_capture_samples(ALCdevice *pDevice, ALCvoid *pBuffer, ALCuint lSamples)
|
||||
{
|
||||
(void)pDevice;
|
||||
(void)pBuffer;
|
||||
(void)lSamples;
|
||||
}
|
||||
|
||||
static ALCuint solaris_available_samples(ALCdevice *pDevice)
|
||||
{
|
||||
(void)pDevice;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
BackendFuncs solaris_funcs = {
|
||||
solaris_open_playback,
|
||||
solaris_close_playback,
|
||||
solaris_open_capture,
|
||||
solaris_close_capture,
|
||||
solaris_start_capture,
|
||||
solaris_stop_capture,
|
||||
solaris_capture_samples,
|
||||
solaris_available_samples
|
||||
};
|
||||
|
||||
void alc_solaris_init(BackendFuncs *func_list)
|
||||
{
|
||||
*func_list = solaris_funcs;
|
||||
|
||||
solaris_device = AppendDeviceList("Solaris Software");
|
||||
AppendAllDeviceList(solaris_device);
|
||||
}
|
||||
+6
-5
@@ -35,7 +35,7 @@ typedef struct {
|
||||
ALvoid *buffer;
|
||||
ALuint size;
|
||||
|
||||
int killNow;
|
||||
volatile int killNow;
|
||||
ALvoid *thread;
|
||||
} wave_data;
|
||||
|
||||
@@ -50,6 +50,7 @@ static ALuint WaveProc(ALvoid *ptr)
|
||||
ALuint frameSize;
|
||||
ALuint now, last;
|
||||
size_t WriteCnt;
|
||||
size_t fs;
|
||||
ALuint avail;
|
||||
union {
|
||||
short s;
|
||||
@@ -66,7 +67,7 @@ static ALuint WaveProc(ALvoid *ptr)
|
||||
now = timeGetTime();
|
||||
|
||||
avail = (now-last) * pDevice->Frequency / 1000;
|
||||
if(avail < pDevice->UpdateFreq/4)
|
||||
if(avail < pDevice->UpdateSize/4)
|
||||
{
|
||||
Sleep(1);
|
||||
continue;
|
||||
@@ -89,7 +90,7 @@ static ALuint WaveProc(ALvoid *ptr)
|
||||
fputc(bytes[i^1], data->f);
|
||||
}
|
||||
else
|
||||
fwrite(data->buffer, frameSize, WriteCnt, data->f);
|
||||
fs = fwrite(data->buffer, frameSize, WriteCnt, data->f);
|
||||
if(ferror(data->f))
|
||||
{
|
||||
AL_PRINT("Error writing to file\n");
|
||||
@@ -212,9 +213,9 @@ static ALCboolean wave_open_playback(ALCdevice *device, const ALCchar *deviceNam
|
||||
|
||||
data->DataStart = ftell(data->f);
|
||||
|
||||
device->UpdateFreq = max(device->UpdateFreq, 2048);
|
||||
device->UpdateSize = max(device->UpdateSize, 2048);
|
||||
|
||||
data->size = device->UpdateFreq;
|
||||
data->size = device->UpdateSize;
|
||||
data->buffer = malloc(data->size * channels * bits / 8);
|
||||
if(!data->buffer)
|
||||
{
|
||||
|
||||
+36
-16
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#define _WIN32_WINNT 0x0500
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <memory.h>
|
||||
@@ -65,7 +66,7 @@ static void CALLBACK WaveInProc(HWAVEIN hDevice,UINT uMsg,DWORD_PTR dwInstance,D
|
||||
(void)hDevice;
|
||||
(void)dwParam2;
|
||||
|
||||
if ((uMsg==WIM_DATA) && (pDevice))
|
||||
if ((uMsg==WIM_DATA))
|
||||
{
|
||||
// Decrement number of buffers in use
|
||||
pData->lWaveInBuffersCommitted--;
|
||||
@@ -209,12 +210,13 @@ static ALCboolean WinMMOpenCapture(ALCdevice *pDevice, const ALCchar *deviceName
|
||||
|
||||
memset(&wfexCaptureFormat, 0, sizeof(WAVEFORMATEX));
|
||||
wfexCaptureFormat.wFormatTag = WAVE_FORMAT_PCM;
|
||||
wfexCaptureFormat.nChannels = pDevice->Channels;
|
||||
wfexCaptureFormat.wBitsPerSample = pDevice->FrameSize / pDevice->Channels * 8;
|
||||
wfexCaptureFormat.nBlockAlign = pDevice->FrameSize;
|
||||
wfexCaptureFormat.nChannels = aluChannelsFromFormat(pDevice->Format);
|
||||
wfexCaptureFormat.wBitsPerSample = aluBytesFromFormat(pDevice->Format) * 8;
|
||||
wfexCaptureFormat.nBlockAlign = wfexCaptureFormat.wBitsPerSample *
|
||||
wfexCaptureFormat.nChannels / 8;
|
||||
wfexCaptureFormat.nSamplesPerSec = frequency;
|
||||
wfexCaptureFormat.nAvgBytesPerSec = wfexCaptureFormat.nSamplesPerSec *
|
||||
pDevice->FrameSize;
|
||||
wfexCaptureFormat.nBlockAlign;
|
||||
wfexCaptureFormat.cbSize = 0;
|
||||
|
||||
if (waveInOpen(&pData->hWaveInHandle, lDeviceID, &wfexCaptureFormat, (DWORD_PTR)&WaveInProc, (DWORD_PTR)pDevice, CALLBACK_FUNCTION) != MMSYSERR_NOERROR)
|
||||
@@ -228,10 +230,6 @@ static ALCboolean WinMMOpenCapture(ALCdevice *pDevice, const ALCchar *deviceName
|
||||
if (pData->hWaveInThreadEvent == NULL)
|
||||
goto failure;
|
||||
|
||||
pData->hWaveInThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)CaptureThreadProc, (LPVOID)pDevice, 0, &pData->ulWaveInThreadID);
|
||||
if (pData->hWaveInThread == NULL)
|
||||
goto failure;
|
||||
|
||||
// Allocate circular memory buffer for the captured audio
|
||||
pData->ulCapturedDataSize = SampleSize * wfexCaptureFormat.nBlockAlign;
|
||||
|
||||
@@ -266,15 +264,32 @@ static ALCboolean WinMMOpenCapture(ALCdevice *pDevice, const ALCchar *deviceName
|
||||
pData->ulWriteCapturedDataPos = 0;
|
||||
|
||||
pDevice->ExtraData = pData;
|
||||
|
||||
pData->hWaveInThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)CaptureThreadProc, (LPVOID)pDevice, 0, &pData->ulWaveInThreadID);
|
||||
if (pData->hWaveInThread == NULL)
|
||||
goto failure;
|
||||
|
||||
return ALC_TRUE;
|
||||
|
||||
failure:
|
||||
if (pData->hWaveInThreadEvent)
|
||||
CloseHandle(pData->hWaveInThreadEvent);
|
||||
for (i=0;i<4;i++)
|
||||
{
|
||||
if(pData->WaveInBuffer[i].lpData)
|
||||
{
|
||||
waveInUnprepareHeader(pData->hWaveInHandle, &pData->WaveInBuffer[i], sizeof(WAVEHDR));
|
||||
free(pData->WaveInBuffer[i].lpData);
|
||||
}
|
||||
}
|
||||
|
||||
free(pData->pCapturedSampleData);
|
||||
if(pData->hWaveInHandle)
|
||||
waveInClose(pData->hWaveInHandle);
|
||||
if(pData->hWaveInThread)
|
||||
CloseHandle(pData->hWaveInThread);
|
||||
if (pData->hWaveInHdrEvent)
|
||||
CloseHandle(pData->hWaveInHdrEvent);
|
||||
if (pData->hWaveInHandle)
|
||||
waveInClose(pData->hWaveInHandle);
|
||||
if (pData->hWaveInThreadEvent)
|
||||
CloseHandle(pData->hWaveInThreadEvent);
|
||||
|
||||
free(pData);
|
||||
return ALC_FALSE;
|
||||
@@ -348,16 +363,20 @@ static void WinMMCaptureSamples(ALCdevice *pDevice, ALCvoid *pBuffer, ALCuint lS
|
||||
ALuint ulBytes, ulBytesToCopy;
|
||||
ALuint ulCapturedSamples;
|
||||
ALuint ulReadOffset;
|
||||
ALuint frameSize = aluBytesFromFormat(pDevice->Format) *
|
||||
aluChannelsFromFormat(pDevice->Format);
|
||||
|
||||
// Check that we have the requested numbers of Samples
|
||||
ulCapturedSamples = (pData->ulWriteCapturedDataPos - pData->ulReadCapturedDataPos) / pDevice->FrameSize;
|
||||
ulCapturedSamples = (pData->ulWriteCapturedDataPos -
|
||||
pData->ulReadCapturedDataPos) /
|
||||
frameSize;
|
||||
if(ulSamples > ulCapturedSamples)
|
||||
{
|
||||
SetALCError(ALC_INVALID_VALUE);
|
||||
return;
|
||||
}
|
||||
|
||||
ulBytes = ulSamples * pDevice->FrameSize;
|
||||
ulBytes = ulSamples * frameSize;
|
||||
|
||||
// Get Read Offset
|
||||
ulReadOffset = (pData->ulReadCapturedDataPos % pData->ulCapturedDataSize);
|
||||
@@ -386,7 +405,8 @@ static ALCuint WinMMAvailableSamples(ALCdevice *pDevice)
|
||||
{
|
||||
WinMMData *pData = (WinMMData*)pDevice->ExtraData;
|
||||
ALCuint lCapturedBytes = (pData->ulWriteCapturedDataPos - pData->ulReadCapturedDataPos);
|
||||
return lCapturedBytes / pDevice->FrameSize;
|
||||
return lCapturedBytes / (aluBytesFromFormat(pDevice->Format) *
|
||||
aluChannelsFromFormat(pDevice->Format));
|
||||
}
|
||||
|
||||
|
||||
|
||||
+127
-43
@@ -1,5 +1,11 @@
|
||||
# CMake build file list for OpenAL
|
||||
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
|
||||
|
||||
IF(COMMAND CMAKE_POLICY)
|
||||
CMAKE_POLICY(SET CMP0003 NEW)
|
||||
ENDIF(COMMAND CMAKE_POLICY)
|
||||
|
||||
INCLUDE(CheckFunctionExists)
|
||||
INCLUDE(CheckLibraryExists)
|
||||
INCLUDE(CheckIncludeFile)
|
||||
@@ -9,7 +15,7 @@ INCLUDE(CheckCSourceCompiles)
|
||||
INCLUDE(CheckTypeSize)
|
||||
|
||||
|
||||
PROJECT(OpenAL)
|
||||
PROJECT(OpenAL C)
|
||||
|
||||
|
||||
SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)
|
||||
@@ -17,18 +23,32 @@ SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)
|
||||
|
||||
OPTION(ALSA "Check for ALSA backend" ON)
|
||||
OPTION(OSS "Check for OSS backend" ON)
|
||||
OPTION(SOLARIS "Check for Solaris backend" ON)
|
||||
OPTION(DSOUND "Check for DirectSound backend" ON)
|
||||
OPTION(WINMM "Check for Windows Multimedia backend" ON)
|
||||
OPTION(PORTAUDIO "Check for PortAudio backend" ON)
|
||||
|
||||
OPTION(DLOPEN "Check for the dlopen API for loading optional libs" ON)
|
||||
|
||||
OPTION(WERROR "Treat compile warnings as errors" OFF)
|
||||
OPTION(WERROR "Treat compile warnings as errors" OFF)
|
||||
|
||||
OPTION(EXAMPLES "Build example programs" ON)
|
||||
|
||||
|
||||
IF(WIN32)
|
||||
SET(LIBNAME OpenAL32)
|
||||
ADD_DEFINITIONS("-D_WIN32")
|
||||
ELSE()
|
||||
SET(LIBNAME openal)
|
||||
ENDIF()
|
||||
|
||||
SET(LIB_MAJOR_VERSION "1")
|
||||
SET(LIB_MINOR_VERSION "2")
|
||||
SET(LIB_BUILD_VERSION "218")
|
||||
SET(LIB_MINOR_VERSION "7")
|
||||
SET(LIB_BUILD_VERSION "411")
|
||||
SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_BUILD_VERSION}")
|
||||
IF(NOT DEFINED LIB_INSTALL_DIR)
|
||||
SET(LIB_INSTALL_DIR "lib")
|
||||
ENDIF(NOT DEFINED LIB_INSTALL_DIR)
|
||||
|
||||
|
||||
CHECK_TYPE_SIZE("long" SIZEOF_LONG)
|
||||
@@ -45,6 +65,11 @@ IF(NOT CMAKE_BUILD_TYPE)
|
||||
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
|
||||
FORCE)
|
||||
ENDIF()
|
||||
IF(NOT CMAKE_DEBUG_POSTFIX)
|
||||
SET(CMAKE_DEBUG_POSTFIX "" CACHE STRING
|
||||
"Library postfix for debug builds. Normally left blank."
|
||||
FORCE)
|
||||
ENDIF()
|
||||
|
||||
IF(MSVC)
|
||||
# ???
|
||||
@@ -55,7 +80,7 @@ IF(MSVC)
|
||||
ELSE()
|
||||
ADD_DEFINITIONS(-Wall)
|
||||
CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
|
||||
IF("${HAVE_W_EXTRA}")
|
||||
IF(HAVE_W_EXTRA)
|
||||
ADD_DEFINITIONS(-Wextra)
|
||||
ENDIF()
|
||||
|
||||
@@ -76,36 +101,37 @@ ELSE()
|
||||
"Flags used by the compiler during debug builds."
|
||||
FORCE)
|
||||
|
||||
# The mixer doesn't like GCC's strict aliasing optimizations. Make sure
|
||||
# it's turned off
|
||||
CHECK_C_COMPILER_FLAG(-fstrict-aliasing HAVE_STRICT_ALIASING)
|
||||
IF("${HAVE_STRICT_ALIASING}")
|
||||
ADD_DEFINITIONS(-fno-strict-aliasing)
|
||||
ENDIF()
|
||||
|
||||
# Set visibility options if available
|
||||
IF(NOT WIN32)
|
||||
CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
|
||||
int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
|
||||
|
||||
CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_SWITCH)
|
||||
IF("${HAVE_VISIBILITY_SWITCH}")
|
||||
IF(HAVE_VISIBILITY_SWITCH)
|
||||
CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
|
||||
int main() {return 0;}" HAVE_GCC_VISIBILITY)
|
||||
IF("${HAVE_GCC_VISIBILITY}")
|
||||
IF(HAVE_GCC_VISIBILITY)
|
||||
ADD_DEFINITIONS(-fvisibility=hidden -DHAVE_GCC_VISIBILITY)
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
CHECK_INCLUDE_FILE(fenv.h HAVE_FENV_H)
|
||||
CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_H)
|
||||
|
||||
CHECK_LIBRARY_EXISTS(m sqrtf "" HAVE_SQRTF)
|
||||
CHECK_LIBRARY_EXISTS(m acosf "" HAVE_ACOSF)
|
||||
IF(HAVE_SQRTF OR HAVE_ACOSF)
|
||||
CHECK_LIBRARY_EXISTS(m atanf "" HAVE_ATANF)
|
||||
CHECK_LIBRARY_EXISTS(m fabsf "" HAVE_FABSF)
|
||||
IF(HAVE_FENV_H)
|
||||
CHECK_LIBRARY_EXISTS(m fesetround "" HAVE_FESETROUND)
|
||||
ENDIF()
|
||||
IF(HAVE_SQRTF OR HAVE_ACOSF OR HAVE_ATANF OR HAVE_FABSF OR HAVE_FESETROUND)
|
||||
SET(EXTRA_LIBS m ${EXTRA_LIBS})
|
||||
ENDIF()
|
||||
CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
|
||||
CHECK_FUNCTION_EXISTS(_controlfp HAVE__CONTROLFP)
|
||||
|
||||
CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
|
||||
IF(NOT HAVE_STRCASECMP)
|
||||
@@ -149,7 +175,7 @@ IF(DLOPEN)
|
||||
ENDIF()
|
||||
|
||||
# Check if we have Windows headers
|
||||
CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H)
|
||||
CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0500)
|
||||
IF(NOT HAVE_WINDOWS_H)
|
||||
CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
|
||||
IF(NOT HAVE_GETTIMEOFDAY)
|
||||
@@ -167,6 +193,9 @@ IF(NOT HAVE_WINDOWS_H)
|
||||
MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
|
||||
ENDIF()
|
||||
|
||||
# Some systems need pthread_np.h to get recursive mutexes
|
||||
CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
|
||||
|
||||
# _GNU_SOURCE is needed on some systems for extra attributes, and
|
||||
# _REENTRANT is needed for libc thread-safety
|
||||
ADD_DEFINITIONS(-D_GNU_SOURCE=1 -D_REENTRANT)
|
||||
@@ -180,7 +209,8 @@ ENDIF()
|
||||
CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
|
||||
IF(NOT HAVE_STDINT_H)
|
||||
IF(HAVE_WINDOWS_H)
|
||||
CHECK_C_SOURCE_COMPILES("\#include <windows.h>
|
||||
CHECK_C_SOURCE_COMPILES("\#define _WIN32_WINNT 0x0500
|
||||
\#include <windows.h>
|
||||
__int64 foo;
|
||||
int main() {return 0;}" HAVE___INT64)
|
||||
ENDIF()
|
||||
@@ -204,11 +234,11 @@ SET(OPENAL_OBJS OpenAL32/alAuxEffectSlot.c
|
||||
OpenAL32/alSource.c
|
||||
OpenAL32/alState.c
|
||||
OpenAL32/alThunk.c
|
||||
OpenAL32/OpenAL32.c
|
||||
)
|
||||
SET(ALC_OBJS Alc/ALc.c
|
||||
Alc/ALu.c
|
||||
Alc/alcConfig.c
|
||||
Alc/alcReverb.c
|
||||
Alc/alcRing.c
|
||||
Alc/alcThread.c
|
||||
Alc/bs2b.c
|
||||
@@ -245,31 +275,37 @@ IF(OSS)
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
# Check DSound/MMSystem backend
|
||||
IF(HAVE_WINDOWS_H)
|
||||
SET(CMAKE_REQUIRED_LIBRARIES ole32)
|
||||
CHECK_C_SOURCE_COMPILES("int main() {return 0;}" HAVE_LIBOLE32)
|
||||
SET(CMAKE_REQUIRED_LIBRARIES "")
|
||||
# CHECK_LIBRARY_EXISTS(ole32 CoInitialize "" HAVE_LIBOLE32)
|
||||
IF(HAVE_LIBOLE32)
|
||||
SET(EXTRA_LIBS ole32 ${EXTRA_LIBS})
|
||||
# Check Solaris backend
|
||||
IF(SOLARIS)
|
||||
CHECK_INCLUDE_FILE(sys/audioio.h HAVE_SYS_AUDIOIO_H)
|
||||
IF(HAVE_SYS_AUDIOIO_H)
|
||||
SET(HAVE_SOLARIS 1)
|
||||
SET(ALC_OBJS ${ALC_OBJS} Alc/solaris.c)
|
||||
SET(BACKENDS "${BACKENDS} Solaris,")
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
IF(DSOUND)
|
||||
CHECK_INCLUDE_FILE(dsound.h HAVE_DSOUND_H)
|
||||
IF(HAVE_DSOUND_H)
|
||||
# Check DSound/MMSystem backend
|
||||
IF(DSOUND)
|
||||
CHECK_INCLUDE_FILE(dsound.h HAVE_DSOUND_H)
|
||||
IF(HAVE_DSOUND_H)
|
||||
CHECK_LIBRARY_EXISTS(dsound DirectSoundCreate "" HAVE_LIBDSOUND)
|
||||
IF(HAVE_LIBDSOUND OR WIN32)
|
||||
SET(HAVE_DSOUND 1)
|
||||
SET(ALC_OBJS ${ALC_OBJS} Alc/dsound.c)
|
||||
SET(BACKENDS "${BACKENDS} DirectSound,")
|
||||
|
||||
CHECK_LIBRARY_EXISTS(dxguid IID_IDirectSound "" HAVE_LIBDXGUID)
|
||||
IF(HAVE_LIBDXGUID)
|
||||
SET(EXTRA_LIBS dxguid ${EXTRA_LIBS})
|
||||
IF(WIN32)
|
||||
SET(BACKENDS "${BACKENDS} DirectSound,")
|
||||
ELSE()
|
||||
SET(BACKENDS "${BACKENDS} DirectSound \(linked\),")
|
||||
SET(EXTRA_LIBS dsound ${EXTRA_LIBS})
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
IF(HAVE_WINDOWS_H)
|
||||
IF(WINMM)
|
||||
CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H)
|
||||
CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0500)
|
||||
IF(HAVE_MMSYSTEM_H)
|
||||
SET(HAVE_WINMM 1)
|
||||
SET(ALC_OBJS ${ALC_OBJS} Alc/winmm.c)
|
||||
@@ -286,24 +322,51 @@ IF(HAVE_WINDOWS_H)
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
# Check PortAudio backend
|
||||
IF(PORTAUDIO)
|
||||
CHECK_INCLUDE_FILE(portaudio.h HAVE_PORTAUDIO_H)
|
||||
IF(HAVE_PORTAUDIO_H)
|
||||
CHECK_LIBRARY_EXISTS(portaudio Pa_Initialize "" HAVE_LIBPORTAUDIO)
|
||||
IF(HAVE_LIBPORTAUDIO)
|
||||
SET(HAVE_PORTAUDIO 1)
|
||||
SET(ALC_OBJS ${ALC_OBJS} Alc/portaudio.c)
|
||||
IF(HAVE_DLFCN_H)
|
||||
SET(BACKENDS "${BACKENDS} PortAudio,")
|
||||
ELSE()
|
||||
SET(BACKENDS "${BACKENDS} PortAudio \(linked\),")
|
||||
SET(EXTRA_LIBS portaudio ${EXTRA_LIBS})
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
# This is always available
|
||||
SET(BACKENDS "${BACKENDS} WaveFile")
|
||||
|
||||
# Needed for openal.pc.in
|
||||
SET(prefix ${CMAKE_INSTALL_PREFIX})
|
||||
SET(exec_prefix "\${prefix}")
|
||||
SET(libdir "\${exec_prefix}/${LIB_INSTALL_DIR}")
|
||||
SET(bindir "\${exec_prefix}/bin")
|
||||
SET(includedir "\${prefix}/include")
|
||||
SET(PACKAGE_VERSION "${LIB_VERSION}")
|
||||
|
||||
# End configuration
|
||||
CONFIGURE_FILE(
|
||||
"${OpenAL_SOURCE_DIR}/config.h.in"
|
||||
"${OpenAL_BINARY_DIR}/config.h")
|
||||
CONFIGURE_FILE(
|
||||
"${OpenAL_SOURCE_DIR}/admin/pkgconfig/openal.pc.in"
|
||||
"${OpenAL_BINARY_DIR}/admin/pkgconfig/openal.pc"
|
||||
@ONLY)
|
||||
|
||||
ADD_DEFINITIONS(-DAL_BUILD_LIBRARY)
|
||||
|
||||
# Build a shared library
|
||||
IF(WIN32)
|
||||
SET(LIBNAME openal32)
|
||||
ELSE()
|
||||
SET(LIBNAME openal)
|
||||
# Build a library
|
||||
IF(NOT LIBTYPE)
|
||||
SET(LIBTYPE SHARED)
|
||||
ENDIF()
|
||||
|
||||
ADD_LIBRARY(${LIBNAME} SHARED ${OPENAL_OBJS} ${ALC_OBJS})
|
||||
ADD_LIBRARY(${LIBNAME} ${LIBTYPE} ${OPENAL_OBJS} ${ALC_OBJS})
|
||||
SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES VERSION ${LIB_VERSION}
|
||||
SOVERSION ${LIB_MAJOR_VERSION})
|
||||
IF(WIN32)
|
||||
@@ -315,15 +378,36 @@ TARGET_LINK_LIBRARIES(${LIBNAME} ${EXTRA_LIBS})
|
||||
# Add an install target here
|
||||
INSTALL(TARGETS ${LIBNAME}
|
||||
RUNTIME DESTINATION bin
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib
|
||||
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
|
||||
ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
|
||||
)
|
||||
INSTALL(FILES include/AL/al.h
|
||||
include/AL/alc.h
|
||||
include/AL/alext.h
|
||||
DESTINATION include/AL
|
||||
)
|
||||
INSTALL(FILES "${OpenAL_BINARY_DIR}/admin/pkgconfig/openal.pc"
|
||||
DESTINATION "${LIB_INSTALL_DIR}/pkgconfig")
|
||||
|
||||
IF(EXAMPLES)
|
||||
ADD_EXECUTABLE(openal-info examples/openal-info.c)
|
||||
TARGET_LINK_LIBRARIES(openal-info ${LIBNAME})
|
||||
INSTALL(TARGETS openal-info
|
||||
RUNTIME DESTINATION bin
|
||||
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
|
||||
ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
|
||||
)
|
||||
ENDIF()
|
||||
|
||||
MESSAGE(STATUS "")
|
||||
MESSAGE(STATUS "Building OpenAL with support for the following backends:")
|
||||
MESSAGE(STATUS " ${BACKENDS}")
|
||||
MESSAGE(STATUS "")
|
||||
|
||||
IF(WIN32)
|
||||
IF(NOT HAVE_DSOUND)
|
||||
MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
|
||||
MESSAGE(STATUS " This is probably NOT what you want!")
|
||||
MESSAGE(STATUS "")
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#ifndef _AL_AUXEFFECTSLOT_H_
|
||||
#define _AL_AUXEFFECTSLOT_H_
|
||||
|
||||
#include "alEffect.h"
|
||||
#include "AL/al.h"
|
||||
#include "alEffect.h"
|
||||
#include "alFilter.h"
|
||||
#include "alReverb.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -21,14 +23,7 @@ typedef struct ALeffectslot
|
||||
ALfloat Gain;
|
||||
ALboolean AuxSendAuto;
|
||||
|
||||
ALfloat *ReverbBuffer;
|
||||
// in frames!
|
||||
ALuint ReverbLength;
|
||||
ALuint ReverbPos;
|
||||
ALuint ReverbReflectPos;
|
||||
ALuint ReverbLatePos;
|
||||
ALfloat ReverbDecayGain;
|
||||
ALfloat LastDecaySample;
|
||||
ALverbState *ReverbState;
|
||||
|
||||
ALuint refcount;
|
||||
|
||||
@@ -38,19 +33,19 @@ typedef struct ALeffectslot
|
||||
struct ALeffectslot *next;
|
||||
} ALeffectslot;
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots);
|
||||
AL_API ALvoid AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots);
|
||||
AL_API ALboolean AL_APIENTRY alIsAuxiliaryEffectSlot(ALuint effectslot);
|
||||
ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots);
|
||||
ALvoid AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots);
|
||||
ALboolean AL_APIENTRY alIsAuxiliaryEffectSlot(ALuint effectslot);
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSloti(ALuint effectslot, ALenum param, ALint iValue);
|
||||
AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotiv(ALuint effectslot, ALenum param, ALint *piValues);
|
||||
AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotf(ALuint effectslot, ALenum param, ALfloat flValue);
|
||||
AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotfv(ALuint effectslot, ALenum param, ALfloat *pflValues);
|
||||
ALvoid AL_APIENTRY alAuxiliaryEffectSloti(ALuint effectslot, ALenum param, ALint iValue);
|
||||
ALvoid AL_APIENTRY alAuxiliaryEffectSlotiv(ALuint effectslot, ALenum param, ALint *piValues);
|
||||
ALvoid AL_APIENTRY alAuxiliaryEffectSlotf(ALuint effectslot, ALenum param, ALfloat flValue);
|
||||
ALvoid AL_APIENTRY alAuxiliaryEffectSlotfv(ALuint effectslot, ALenum param, ALfloat *pflValues);
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSloti(ALuint effectslot, ALenum param, ALint *piValue);
|
||||
AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotiv(ALuint effectslot, ALenum param, ALint *piValues);
|
||||
AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotf(ALuint effectslot, ALenum param, ALfloat *pflValue);
|
||||
AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotfv(ALuint effectslot, ALenum param, ALfloat *pflValues);
|
||||
ALvoid AL_APIENTRY alGetAuxiliaryEffectSloti(ALuint effectslot, ALenum param, ALint *piValue);
|
||||
ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotiv(ALuint effectslot, ALenum param, ALint *piValues);
|
||||
ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotf(ALuint effectslot, ALenum param, ALfloat *pflValue);
|
||||
ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotfv(ALuint effectslot, ALenum param, ALfloat *pflValues);
|
||||
|
||||
ALvoid ReleaseALAuxiliaryEffectSlots(ALCcontext *Context);
|
||||
|
||||
|
||||
@@ -18,11 +18,14 @@ typedef struct ALbuffer_struct
|
||||
ALshort *data;
|
||||
ALsizei size;
|
||||
ALsizei frequency;
|
||||
ALsizei padding;
|
||||
ALenum state;
|
||||
ALuint refcount; // Number of sources using this buffer (deletion can only occur when this is 0)
|
||||
struct ALbuffer_struct *next;
|
||||
} ALbuffer;
|
||||
|
||||
ALvoid ALAPIENTRY alBufferSubDataEXT(ALuint buffer,ALenum format,const ALvoid *data,ALsizei offset,ALsizei length);
|
||||
|
||||
ALvoid ReleaseALBuffers(ALvoid);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
+18
-11
@@ -38,6 +38,13 @@ extern "C" {
|
||||
#define AL_REVERB_DECAY_HFLIMIT 0x000D
|
||||
|
||||
|
||||
enum {
|
||||
REVERB = 0,
|
||||
MAX_EFFECTS
|
||||
};
|
||||
extern ALboolean DisabledEffects[MAX_EFFECTS];
|
||||
|
||||
|
||||
typedef struct ALeffect_struct
|
||||
{
|
||||
// Effect type (AL_EFFECT_NULL, ...)
|
||||
@@ -66,19 +73,19 @@ typedef struct ALeffect_struct
|
||||
struct ALeffect_struct *next;
|
||||
} ALeffect;
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects);
|
||||
AL_API ALvoid AL_APIENTRY alDeleteEffects(ALsizei n, ALuint *effects);
|
||||
AL_API ALboolean AL_APIENTRY alIsEffect(ALuint effect);
|
||||
ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects);
|
||||
ALvoid AL_APIENTRY alDeleteEffects(ALsizei n, ALuint *effects);
|
||||
ALboolean AL_APIENTRY alIsEffect(ALuint effect);
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alEffecti(ALuint effect, ALenum param, ALint iValue);
|
||||
AL_API ALvoid AL_APIENTRY alEffectiv(ALuint effect, ALenum param, ALint *piValues);
|
||||
AL_API ALvoid AL_APIENTRY alEffectf(ALuint effect, ALenum param, ALfloat flValue);
|
||||
AL_API ALvoid AL_APIENTRY alEffectfv(ALuint effect, ALenum param, ALfloat *pflValues);
|
||||
ALvoid AL_APIENTRY alEffecti(ALuint effect, ALenum param, ALint iValue);
|
||||
ALvoid AL_APIENTRY alEffectiv(ALuint effect, ALenum param, ALint *piValues);
|
||||
ALvoid AL_APIENTRY alEffectf(ALuint effect, ALenum param, ALfloat flValue);
|
||||
ALvoid AL_APIENTRY alEffectfv(ALuint effect, ALenum param, ALfloat *pflValues);
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alGetEffecti(ALuint effect, ALenum param, ALint *piValue);
|
||||
AL_API ALvoid AL_APIENTRY alGetEffectiv(ALuint effect, ALenum param, ALint *piValues);
|
||||
AL_API ALvoid AL_APIENTRY alGetEffectf(ALuint effect, ALenum param, ALfloat *pflValue);
|
||||
AL_API ALvoid AL_APIENTRY alGetEffectfv(ALuint effect, ALenum param, ALfloat *pflValues);
|
||||
ALvoid AL_APIENTRY alGetEffecti(ALuint effect, ALenum param, ALint *piValue);
|
||||
ALvoid AL_APIENTRY alGetEffectiv(ALuint effect, ALenum param, ALint *piValues);
|
||||
ALvoid AL_APIENTRY alGetEffectf(ALuint effect, ALenum param, ALfloat *pflValue);
|
||||
ALvoid AL_APIENTRY alGetEffectfv(ALuint effect, ALenum param, ALfloat *pflValues);
|
||||
|
||||
ALvoid ReleaseALEffects(ALvoid);
|
||||
|
||||
|
||||
+17
-11
@@ -2,11 +2,17 @@
|
||||
#define _AL_FILTER_H_
|
||||
|
||||
#include "AL/al.h"
|
||||
#include "alu.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
ALfloat history[OUTPUTCHANNELS*2];
|
||||
ALfloat coeff;
|
||||
} FILTER;
|
||||
|
||||
#define AL_FILTER_TYPE 0x8001
|
||||
|
||||
#define AL_FILTER_NULL 0x0000
|
||||
@@ -32,19 +38,19 @@ typedef struct ALfilter_struct
|
||||
struct ALfilter_struct *next;
|
||||
} ALfilter;
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters);
|
||||
AL_API ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, ALuint *filters);
|
||||
AL_API ALboolean AL_APIENTRY alIsFilter(ALuint filter);
|
||||
ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters);
|
||||
ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, ALuint *filters);
|
||||
ALboolean AL_APIENTRY alIsFilter(ALuint filter);
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alFilteri(ALuint filter, ALenum param, ALint iValue);
|
||||
AL_API ALvoid AL_APIENTRY alFilteriv(ALuint filter, ALenum param, ALint *piValues);
|
||||
AL_API ALvoid AL_APIENTRY alFilterf(ALuint filter, ALenum param, ALfloat flValue);
|
||||
AL_API ALvoid AL_APIENTRY alFilterfv(ALuint filter, ALenum param, ALfloat *pflValues);
|
||||
ALvoid AL_APIENTRY alFilteri(ALuint filter, ALenum param, ALint iValue);
|
||||
ALvoid AL_APIENTRY alFilteriv(ALuint filter, ALenum param, ALint *piValues);
|
||||
ALvoid AL_APIENTRY alFilterf(ALuint filter, ALenum param, ALfloat flValue);
|
||||
ALvoid AL_APIENTRY alFilterfv(ALuint filter, ALenum param, ALfloat *pflValues);
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alGetFilteri(ALuint filter, ALenum param, ALint *piValue);
|
||||
AL_API ALvoid AL_APIENTRY alGetFilteriv(ALuint filter, ALenum param, ALint *piValues);
|
||||
AL_API ALvoid AL_APIENTRY alGetFilterf(ALuint filter, ALenum param, ALfloat *pflValue);
|
||||
AL_API ALvoid AL_APIENTRY alGetFilterfv(ALuint filter, ALenum param, ALfloat *pflValues);
|
||||
ALvoid AL_APIENTRY alGetFilteri(ALuint filter, ALenum param, ALint *piValue);
|
||||
ALvoid AL_APIENTRY alGetFilteriv(ALuint filter, ALenum param, ALint *piValues);
|
||||
ALvoid AL_APIENTRY alGetFilterf(ALuint filter, ALenum param, ALfloat *pflValue);
|
||||
ALvoid AL_APIENTRY alGetFilterfv(ALuint filter, ALenum param, ALfloat *pflValues);
|
||||
|
||||
ALvoid ReleaseALFilters(ALvoid);
|
||||
|
||||
|
||||
+42
-43
@@ -6,14 +6,24 @@
|
||||
|
||||
#include "alu.h"
|
||||
|
||||
#ifdef HAVE_FENV_H
|
||||
#include <fenv.h>
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#ifndef _WIN32_WINNT
|
||||
#define _WIN32_WINNT 0x0500
|
||||
#endif
|
||||
#include <windows.h>
|
||||
|
||||
#else
|
||||
|
||||
#include <assert.h>
|
||||
#include <pthread.h>
|
||||
#ifdef HAVE_PTHREAD_NP_H
|
||||
#include <pthread_np.h>
|
||||
#endif
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
@@ -42,6 +52,10 @@ static inline void InitializeCriticalSection(CRITICAL_SECTION *cs)
|
||||
assert(ret == 0);
|
||||
|
||||
ret = pthread_mutexattr_settype(&attrib, PTHREAD_MUTEX_RECURSIVE);
|
||||
#ifdef HAVE_PTHREAD_NP_H
|
||||
if(ret != 0)
|
||||
ret = pthread_mutexattr_setkind_np(&attrib, PTHREAD_MUTEX_RECURSIVE);
|
||||
#endif
|
||||
assert(ret == 0);
|
||||
ret = pthread_mutex_init(cs, &attrib);
|
||||
assert(ret == 0);
|
||||
@@ -84,59 +98,40 @@ static inline void Sleep(ALuint t)
|
||||
#define max(x,y) (((x)>(y))?(x):(y))
|
||||
#endif
|
||||
|
||||
#include "AL/al.h"
|
||||
#include "AL/alc.h"
|
||||
#include "AL/alext.h"
|
||||
#include "alListener.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern CRITICAL_SECTION _alMutex;
|
||||
|
||||
extern char _alDebug[256];
|
||||
|
||||
#define AL_PRINT(...) do { \
|
||||
int _al_print_i; \
|
||||
char *_al_print_fn = strrchr(__FILE__, '/'); \
|
||||
if(!_al_print_fn) _al_print_fn = __FILE__; \
|
||||
else _al_print_fn += 1; \
|
||||
#define AL_PRINT(...) do { \
|
||||
int _al_print_i; \
|
||||
const char *_al_print_fn = strrchr(__FILE__, '/'); \
|
||||
if(!_al_print_fn) _al_print_fn = __FILE__; \
|
||||
else _al_print_fn += 1; \
|
||||
_al_print_i = snprintf(_alDebug, sizeof(_alDebug), "AL lib: %s:%d: ", _al_print_fn, __LINE__); \
|
||||
if(_al_print_i < (int)sizeof(_alDebug) && _al_print_i > 0) \
|
||||
if(_al_print_i < (int)sizeof(_alDebug) && _al_print_i > 0) \
|
||||
snprintf(_alDebug+_al_print_i, sizeof(_alDebug)-_al_print_i, __VA_ARGS__); \
|
||||
_alDebug[sizeof(_alDebug)-1] = 0; \
|
||||
fprintf(stderr, "%s", _alDebug); \
|
||||
_alDebug[sizeof(_alDebug)-1] = 0; \
|
||||
fprintf(stderr, "%s", _alDebug); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define AL_FORMAT_MONO_FLOAT32 0x10010
|
||||
#define AL_FORMAT_STEREO_FLOAT32 0x10011
|
||||
|
||||
#define AL_FORMAT_MONO_IMA4 0x1300
|
||||
#define AL_FORMAT_STEREO_IMA4 0x1301
|
||||
|
||||
#define AL_FORMAT_QUAD8_LOKI 0x10004
|
||||
#define AL_FORMAT_QUAD16_LOKI 0x10005
|
||||
|
||||
#define AL_FORMAT_51CHN8 0x120A
|
||||
#define AL_FORMAT_51CHN16 0x120B
|
||||
#define AL_FORMAT_51CHN32 0x120C
|
||||
#define AL_FORMAT_61CHN8 0x120D
|
||||
#define AL_FORMAT_61CHN16 0x120E
|
||||
#define AL_FORMAT_61CHN32 0x120F
|
||||
#define AL_FORMAT_71CHN8 0x1210
|
||||
#define AL_FORMAT_71CHN16 0x1211
|
||||
#define AL_FORMAT_71CHN32 0x1212
|
||||
#define AL_FORMAT_QUAD8 0x1204
|
||||
#define AL_FORMAT_QUAD16 0x1205
|
||||
#define AL_FORMAT_QUAD32 0x1206
|
||||
#define AL_FORMAT_REAR8 0x1207
|
||||
#define AL_FORMAT_REAR16 0x1208
|
||||
#define AL_FORMAT_REAR32 0x1209
|
||||
|
||||
#define SWMIXER_OUTPUT_RATE 44100
|
||||
|
||||
#define SPEEDOFSOUNDMETRESPERSEC (343.3f)
|
||||
#define AIRABSORBGAINHF (0.994f)
|
||||
#define AIRABSORBGAINDBHF (-0.05f)
|
||||
|
||||
#define LOWPASSFREQCUTOFF (5000)
|
||||
|
||||
#define QUADRANT_NUM 128
|
||||
#define LUT_NUM (4 * QUADRANT_NUM)
|
||||
|
||||
|
||||
typedef struct {
|
||||
ALCboolean (*OpenPlayback)(ALCdevice*, const ALCchar*);
|
||||
@@ -152,20 +147,19 @@ typedef struct {
|
||||
|
||||
void alc_alsa_init(BackendFuncs *func_list);
|
||||
void alc_oss_init(BackendFuncs *func_list);
|
||||
void alc_solaris_init(BackendFuncs *func_list);
|
||||
void alcDSoundInit(BackendFuncs *func_list);
|
||||
void alcWinMMInit(BackendFuncs *FuncList);
|
||||
void alc_pa_init(BackendFuncs *func_list);
|
||||
void alc_wave_init(BackendFuncs *func_list);
|
||||
|
||||
|
||||
struct ALCdevice_struct
|
||||
{
|
||||
ALboolean InUse;
|
||||
ALboolean IsCaptureDevice;
|
||||
|
||||
ALuint Frequency;
|
||||
ALuint UpdateFreq;
|
||||
ALuint FrameSize;
|
||||
ALuint Channels;
|
||||
ALuint UpdateSize;
|
||||
ALenum Format;
|
||||
|
||||
ALCchar *szDeviceName;
|
||||
@@ -215,8 +209,13 @@ struct ALCcontext_struct
|
||||
ALint lNumMonoSources;
|
||||
ALint lNumStereoSources;
|
||||
|
||||
ALfloat PanningLUT[OUTPUTCHANNELS * LUT_NUM];
|
||||
ALint NumChan;
|
||||
|
||||
ALfloat ChannelMatrix[OUTPUTCHANNELS][OUTPUTCHANNELS];
|
||||
|
||||
ALCdevice *Device;
|
||||
ALCchar ExtensionList[1024];
|
||||
const ALCchar *ExtensionList;
|
||||
|
||||
struct bs2b *bs2b;
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef _AL_REVERB_H_
|
||||
#define _AL_REVERB_H_
|
||||
|
||||
#include "AL/al.h"
|
||||
#include "AL/alc.h"
|
||||
#include "alMain.h"
|
||||
#include "alAuxEffectSlot.h"
|
||||
#include "alEffect.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct ALverbState ALverbState;
|
||||
|
||||
ALverbState *VerbCreate(ALCcontext *Context);
|
||||
ALvoid VerbDestroy(ALverbState *State);
|
||||
ALvoid VerbUpdate(ALCcontext *Context, struct ALeffectslot *Slot, ALeffect *Effect);
|
||||
ALvoid VerbProcess(ALverbState *State, ALuint SamplesToDo, const ALfloat *SamplesIn, ALfloat (*SamplesOut)[OUTPUTCHANNELS]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#define MAX_SENDS 1
|
||||
|
||||
#include "alFilter.h"
|
||||
#include "alu.h"
|
||||
#include "AL/al.h"
|
||||
|
||||
#define AL_DIRECT_FILTER 0x20005
|
||||
@@ -47,6 +48,7 @@ typedef struct ALsource
|
||||
ALfloat vOrientation[3];
|
||||
ALboolean bHeadRelative;
|
||||
ALboolean bLooping;
|
||||
ALenum DistanceModel;
|
||||
|
||||
ALuint ulBufferID;
|
||||
|
||||
@@ -55,44 +57,48 @@ typedef struct ALsource
|
||||
ALenum state;
|
||||
ALuint position;
|
||||
ALuint position_fraction;
|
||||
|
||||
struct ALbufferlistitem *queue; // Linked list of buffers in queue
|
||||
ALuint BuffersInQueue; // Number of buffers in queue
|
||||
ALuint BuffersProcessed; // Number of buffers already processed (played)
|
||||
|
||||
ALuint TotalBufferDataSize; // Total amount of data contained in the buffers queued for this source
|
||||
ALuint BuffersPlayed; // Number of buffers played on this loop
|
||||
ALuint BufferPosition; // Read position in audio data of current buffer
|
||||
|
||||
ALfilter DirectFilter;
|
||||
|
||||
struct {
|
||||
struct ALeffectslot *Slot;
|
||||
ALfilter WetFilter;
|
||||
FILTER iirFilter;
|
||||
} Send[MAX_SENDS];
|
||||
|
||||
ALfloat LastDrySample;
|
||||
ALfloat LastWetSample;
|
||||
|
||||
ALboolean DryGainHFAuto;
|
||||
ALboolean WetGainAuto;
|
||||
ALboolean WetGainHFAuto;
|
||||
ALfloat OuterGainHF;
|
||||
|
||||
FILTER iirFilter;
|
||||
|
||||
ALfloat AirAbsorptionFactor;
|
||||
|
||||
ALfloat RoomRolloffFactor;
|
||||
|
||||
ALfloat DopplerFactor;
|
||||
|
||||
// Index to itself
|
||||
ALuint source;
|
||||
|
||||
ALint lBytesPlayed;
|
||||
|
||||
ALint lOffset;
|
||||
ALint lOffsetType;
|
||||
|
||||
// Source Type (Static, Streaming, or Undetermined)
|
||||
ALint lSourceType;
|
||||
|
||||
// Current gains, which are ramped while mixed
|
||||
ALfloat DryGains[OUTPUTCHANNELS];
|
||||
ALfloat WetGain;
|
||||
ALboolean FirstStart;
|
||||
|
||||
struct ALsource *next;
|
||||
} ALsource;
|
||||
|
||||
|
||||
@@ -8,8 +8,25 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum {
|
||||
FRONT_LEFT = 0,
|
||||
FRONT_RIGHT,
|
||||
FRONT_CENTER,
|
||||
SIDE_LEFT,
|
||||
SIDE_RIGHT,
|
||||
BACK_LEFT,
|
||||
BACK_RIGHT,
|
||||
BACK_CENTER,
|
||||
LFE,
|
||||
|
||||
OUTPUTCHANNELS
|
||||
};
|
||||
|
||||
extern ALboolean DuplicateStereo;
|
||||
|
||||
__inline ALuint aluBytesFromFormat(ALenum format);
|
||||
__inline ALuint aluChannelsFromFormat(ALenum format);
|
||||
ALvoid aluInitPanning(ALCcontext *Context);
|
||||
ALvoid aluMixData(ALCcontext *context,ALvoid *buffer,ALsizei size,ALenum format);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
/**
|
||||
* 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 "alMain.h"
|
||||
#include "alBuffer.h"
|
||||
#include "alFilter.h"
|
||||
#include "alEffect.h"
|
||||
#include "alAuxEffectSlot.h"
|
||||
#include "alThunk.h"
|
||||
|
||||
CRITICAL_SECTION _alMutex;
|
||||
|
||||
#ifdef _WIN32
|
||||
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);
|
||||
break;
|
||||
|
||||
case DLL_PROCESS_DETACH:
|
||||
ReleaseALC();
|
||||
ReleaseALBuffers();
|
||||
ReleaseALEffects();
|
||||
ReleaseALFilters();
|
||||
FreeALConfig();
|
||||
ALTHUNK_EXIT();
|
||||
DeleteCriticalSection(&_alMutex);
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
#else
|
||||
#ifdef HAVE_GCC_DESTRUCTOR
|
||||
static void my_deinit() __attribute__((destructor));
|
||||
static void my_deinit()
|
||||
{
|
||||
static ALenum once = AL_FALSE;
|
||||
if(once) return;
|
||||
once = AL_TRUE;
|
||||
|
||||
ReleaseALC();
|
||||
ReleaseALBuffers();
|
||||
ReleaseALEffects();
|
||||
ReleaseALFilters();
|
||||
FreeALConfig();
|
||||
ALTHUNK_EXIT();
|
||||
DeleteCriticalSection(&_alMutex);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
+21
-50
@@ -29,12 +29,13 @@
|
||||
#include "alAuxEffectSlot.h"
|
||||
#include "alThunk.h"
|
||||
#include "alError.h"
|
||||
#include "alReverb.h"
|
||||
|
||||
|
||||
static ALvoid InitializeEffect(ALCcontext *Context, ALeffectslot *ALEffectSlot, ALeffect *effect);
|
||||
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots)
|
||||
ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
ALsizei i;
|
||||
@@ -92,7 +93,7 @@ AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslo
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots)
|
||||
ALvoid AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
ALeffectslot *ALAuxiliaryEffectSlot;
|
||||
@@ -148,7 +149,7 @@ AL_API ALvoid AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, ALuint *effect
|
||||
*list = (*list)->next;
|
||||
ALTHUNK_REMOVEENTRY(ALAuxiliaryEffectSlot->effectslot);
|
||||
|
||||
free(ALAuxiliaryEffectSlot->ReverbBuffer);
|
||||
VerbDestroy(ALAuxiliaryEffectSlot->ReverbState);
|
||||
|
||||
memset(ALAuxiliaryEffectSlot, 0, sizeof(ALeffectslot));
|
||||
free(ALAuxiliaryEffectSlot);
|
||||
@@ -164,7 +165,7 @@ AL_API ALvoid AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, ALuint *effect
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
AL_API ALboolean AL_APIENTRY alIsAuxiliaryEffectSlot(ALuint effectslot)
|
||||
ALboolean AL_APIENTRY alIsAuxiliaryEffectSlot(ALuint effectslot)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
ALeffectslot **list;
|
||||
@@ -186,7 +187,7 @@ AL_API ALboolean AL_APIENTRY alIsAuxiliaryEffectSlot(ALuint effectslot)
|
||||
return (*list ? AL_TRUE : AL_FALSE);
|
||||
}
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSloti(ALuint effectslot, ALenum param, ALint iValue)
|
||||
ALvoid AL_APIENTRY alAuxiliaryEffectSloti(ALuint effectslot, ALenum param, ALint iValue)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
|
||||
@@ -232,7 +233,7 @@ AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSloti(ALuint effectslot, ALenum param
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotiv(ALuint effectslot, ALenum param, ALint *piValues)
|
||||
ALvoid AL_APIENTRY alAuxiliaryEffectSlotiv(ALuint effectslot, ALenum param, ALint *piValues)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
|
||||
@@ -264,7 +265,7 @@ AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotiv(ALuint effectslot, ALenum para
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotf(ALuint effectslot, ALenum param, ALfloat flValue)
|
||||
ALvoid AL_APIENTRY alAuxiliaryEffectSlotf(ALuint effectslot, ALenum param, ALfloat flValue)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
|
||||
@@ -300,7 +301,7 @@ AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotf(ALuint effectslot, ALenum param
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotfv(ALuint effectslot, ALenum param, ALfloat *pflValues)
|
||||
ALvoid AL_APIENTRY alAuxiliaryEffectSlotfv(ALuint effectslot, ALenum param, ALfloat *pflValues)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
|
||||
@@ -331,7 +332,7 @@ AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotfv(ALuint effectslot, ALenum para
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSloti(ALuint effectslot, ALenum param, ALint *piValue)
|
||||
ALvoid AL_APIENTRY alGetAuxiliaryEffectSloti(ALuint effectslot, ALenum param, ALint *piValue)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
|
||||
@@ -368,7 +369,7 @@ AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSloti(ALuint effectslot, ALenum pa
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotiv(ALuint effectslot, ALenum param, ALint *piValues)
|
||||
ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotiv(ALuint effectslot, ALenum param, ALint *piValues)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
|
||||
@@ -400,7 +401,7 @@ AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotiv(ALuint effectslot, ALenum p
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotf(ALuint effectslot, ALenum param, ALfloat *pflValue)
|
||||
ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotf(ALuint effectslot, ALenum param, ALfloat *pflValue)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
|
||||
@@ -433,7 +434,7 @@ AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotf(ALuint effectslot, ALenum pa
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotfv(ALuint effectslot, ALenum param, ALfloat *pflValues)
|
||||
ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotfv(ALuint effectslot, ALenum param, ALfloat *pflValues)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
|
||||
@@ -467,50 +468,20 @@ AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotfv(ALuint effectslot, ALenum p
|
||||
|
||||
static ALvoid InitializeEffect(ALCcontext *Context, ALeffectslot *ALEffectSlot, ALeffect *effect)
|
||||
{
|
||||
ALfloat *ptr = NULL;
|
||||
|
||||
if(!effect)
|
||||
{
|
||||
memset(&ALEffectSlot->effect, 0, sizeof(ALEffectSlot->effect));
|
||||
goto done;
|
||||
VerbDestroy(ALEffectSlot->ReverbState);
|
||||
ALEffectSlot->ReverbState = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
if(effect->type == AL_EFFECT_REVERB)
|
||||
{
|
||||
ALuint size;
|
||||
ALfloat reverbwait;
|
||||
|
||||
reverbwait = (1.0f-effect->Reverb.Density)*(0.1f-0.075f) + 0.075f;
|
||||
|
||||
size = (ALuint)((ALfloat)Context->Frequency *
|
||||
(effect->Reverb.ReflectionsDelay +
|
||||
effect->Reverb.LateReverbDelay +
|
||||
reverbwait)) + 1;
|
||||
|
||||
ptr = calloc(size, sizeof(ALfloat));
|
||||
if(!ptr)
|
||||
{
|
||||
alSetError(AL_OUT_OF_MEMORY);
|
||||
return;
|
||||
}
|
||||
ALEffectSlot->ReverbLength = size;
|
||||
ALEffectSlot->ReverbPos = 0;
|
||||
ALEffectSlot->ReverbReflectPos = (ALuint)(ALEffectSlot->ReverbLength -
|
||||
((ALfloat)Context->Frequency *
|
||||
effect->Reverb.ReflectionsDelay)) %
|
||||
ALEffectSlot->ReverbLength;
|
||||
ALEffectSlot->ReverbLatePos = (ALuint)(ALEffectSlot->ReverbLength -
|
||||
((ALfloat)Context->Frequency *
|
||||
(effect->Reverb.LateReverbDelay +
|
||||
effect->Reverb.ReflectionsDelay))) %
|
||||
ALEffectSlot->ReverbLength;
|
||||
ALEffectSlot->ReverbDecayGain = pow(1.0/32768.0, 1.0/(effect->Reverb.DecayTime/reverbwait));
|
||||
if(!ALEffectSlot->ReverbState)
|
||||
ALEffectSlot->ReverbState = VerbCreate(Context);
|
||||
VerbUpdate(Context, ALEffectSlot, effect);
|
||||
}
|
||||
|
||||
memcpy(&ALEffectSlot->effect, effect, sizeof(*effect));
|
||||
done:
|
||||
free(ALEffectSlot->ReverbBuffer);
|
||||
ALEffectSlot->ReverbBuffer = ptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -518,7 +489,7 @@ ALvoid ReleaseALAuxiliaryEffectSlots(ALCcontext *Context)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if(Context->AuxiliaryEffectSlotCount > 0)
|
||||
AL_PRINT("alcDestroyContext(): %d AuxiliaryEffectSlot(s) NOT deleted\n", Context->AuxiliaryEffectSlotCount);
|
||||
AL_PRINT("alcDestroyContext(): deleting %d AuxiliaryEffectSlot(s)\n", Context->AuxiliaryEffectSlotCount);
|
||||
#endif
|
||||
|
||||
while(Context->AuxiliaryEffectSlot)
|
||||
@@ -527,7 +498,7 @@ ALvoid ReleaseALAuxiliaryEffectSlots(ALCcontext *Context)
|
||||
Context->AuxiliaryEffectSlot = Context->AuxiliaryEffectSlot->next;
|
||||
|
||||
// Release effectslot structure
|
||||
free(temp->ReverbBuffer);
|
||||
VerbDestroy(temp->ReverbState);
|
||||
ALTHUNK_REMOVEENTRY(temp->effectslot);
|
||||
|
||||
memset(temp, 0, sizeof(ALeffectslot));
|
||||
|
||||
+329
-345
@@ -34,6 +34,9 @@
|
||||
|
||||
|
||||
static void LoadData(ALbuffer *ALBuf, const ALubyte *data, ALsizei size, ALuint freq, ALenum OrigFormat, ALenum NewFormat);
|
||||
static void ConvertData(ALshort *dst, const ALvoid *src, ALint origBytes, ALsizei len);
|
||||
static void ConvertDataRear(ALshort *dst, const ALvoid *src, ALint origBytes, ALsizei len);
|
||||
static void ConvertDataIMA4(ALshort *dst, const ALvoid *src, ALint origChans, ALsizei len);
|
||||
|
||||
/*
|
||||
* AL Buffer Functions
|
||||
@@ -142,63 +145,59 @@ ALAPI ALvoid ALAPIENTRY alDeleteBuffers(ALsizei n, const ALuint *puiBuffers)
|
||||
// Check we are actually Deleting some Buffers
|
||||
if (n >= 0)
|
||||
{
|
||||
if ((ALuint)n <= g_uiBufferCount)
|
||||
// Check that all the buffers are valid and can actually be deleted
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
// Check that all the buffers are valid and can actually be deleted
|
||||
for (i = 0; i < n; i++)
|
||||
// Check for valid Buffer ID (can be NULL buffer)
|
||||
if (alIsBuffer(puiBuffers[i]))
|
||||
{
|
||||
// Check for valid Buffer ID (can be NULL buffer)
|
||||
if (alIsBuffer(puiBuffers[i]))
|
||||
// If not the NULL buffer, check that the reference count is 0
|
||||
ALBuf = ((ALbuffer *)ALTHUNK_LOOKUPENTRY(puiBuffers[i]));
|
||||
if (ALBuf)
|
||||
{
|
||||
// If not the NULL buffer, check that the reference count is 0
|
||||
ALBuf = ((ALbuffer *)ALTHUNK_LOOKUPENTRY(puiBuffers[i]));
|
||||
if (ALBuf)
|
||||
if (ALBuf->refcount != 0)
|
||||
{
|
||||
if (ALBuf->refcount != 0)
|
||||
{
|
||||
// Buffer still in use, cannot be deleted
|
||||
alSetError(AL_INVALID_OPERATION);
|
||||
bFailed = AL_TRUE;
|
||||
}
|
||||
// Buffer still in use, cannot be deleted
|
||||
alSetError(AL_INVALID_OPERATION);
|
||||
bFailed = AL_TRUE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Invalid Buffer
|
||||
alSetError(AL_INVALID_NAME);
|
||||
bFailed = AL_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
// If all the Buffers were valid (and have Reference Counts of 0), then we can delete them
|
||||
if (!bFailed)
|
||||
else
|
||||
{
|
||||
for (i = 0; i < n; i++)
|
||||
// Invalid Buffer
|
||||
alSetError(AL_INVALID_NAME);
|
||||
bFailed = AL_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
// If all the Buffers were valid (and have Reference Counts of 0), then we can delete them
|
||||
if (!bFailed)
|
||||
{
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
if (puiBuffers[i] && alIsBuffer(puiBuffers[i]))
|
||||
{
|
||||
ALbuffer **list = &g_pBuffers;
|
||||
|
||||
ALBuf=((ALbuffer *)ALTHUNK_LOOKUPENTRY(puiBuffers[i]));
|
||||
if (ALBuf)
|
||||
{
|
||||
ALbuffer **list = &g_pBuffers;
|
||||
while(*list && *list != ALBuf)
|
||||
list = &(*list)->next;
|
||||
while(*list && *list != ALBuf)
|
||||
list = &(*list)->next;
|
||||
|
||||
if(*list)
|
||||
*list = (*list)->next;
|
||||
if(*list)
|
||||
*list = (*list)->next;
|
||||
|
||||
// Release the memory used to store audio data
|
||||
free(ALBuf->data);
|
||||
// Release the memory used to store audio data
|
||||
free(ALBuf->data);
|
||||
|
||||
// Release buffer structure
|
||||
ALTHUNK_REMOVEENTRY(puiBuffers[i]);
|
||||
memset(ALBuf, 0, sizeof(ALbuffer));
|
||||
g_uiBufferCount--;
|
||||
free(ALBuf);
|
||||
}
|
||||
// Release buffer structure
|
||||
ALTHUNK_REMOVEENTRY(puiBuffers[i]);
|
||||
memset(ALBuf, 0, sizeof(ALbuffer));
|
||||
g_uiBufferCount--;
|
||||
free(ALBuf);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
alSetError(AL_INVALID_NAME);
|
||||
}
|
||||
else
|
||||
alSetError(AL_INVALID_VALUE);
|
||||
@@ -259,14 +258,10 @@ ALAPI ALboolean ALAPIENTRY alIsBuffer(ALuint uiBuffer)
|
||||
*/
|
||||
ALAPI ALvoid ALAPIENTRY alBufferData(ALuint buffer,ALenum format,const ALvoid *data,ALsizei size,ALsizei freq)
|
||||
{
|
||||
ALuint *IMAData,IMACode;
|
||||
ALCcontext *Context;
|
||||
ALint Sample,Index;
|
||||
ALint LeftSample,LeftIndex;
|
||||
ALint RightSample,RightIndex;
|
||||
ALuint LeftIMACode,RightIMACode;
|
||||
ALsizei padding = 2;
|
||||
ALbuffer *ALBuf;
|
||||
ALsizei i,j,k;
|
||||
ALvoid *temp;
|
||||
|
||||
Context = alcGetCurrentContext();
|
||||
SuspendContext(Context);
|
||||
@@ -298,107 +293,35 @@ ALAPI ALvoid ALAPIENTRY alBufferData(ALuint buffer,ALenum format,const ALvoid *d
|
||||
ALuint OrigBytes = ((format==AL_FORMAT_REAR8) ? 1 :
|
||||
((format==AL_FORMAT_REAR16) ? 2 :
|
||||
4));
|
||||
ALsizei i;
|
||||
|
||||
assert(aluBytesFromFormat(NewFormat) == 2);
|
||||
|
||||
if ((size%(OrigBytes*2)) != 0)
|
||||
if((size%(OrigBytes*2)) != 0)
|
||||
{
|
||||
alSetError(AL_INVALID_VALUE);
|
||||
break;
|
||||
}
|
||||
|
||||
switch(OrigBytes)
|
||||
size /= OrigBytes;
|
||||
size *= 2;
|
||||
|
||||
// Samples are converted to 16 bit here
|
||||
temp = realloc(ALBuf->data, (padding*NewChannels + size) * sizeof(ALshort));
|
||||
if(temp)
|
||||
{
|
||||
case 1:
|
||||
size /= sizeof(ALubyte);
|
||||
size *= 2;
|
||||
ALBuf->data = temp;
|
||||
ConvertDataRear(ALBuf->data, data, OrigBytes, size);
|
||||
|
||||
// 8bit Samples are converted to 16 bit here
|
||||
// Allocate 8 extra samples
|
||||
ALBuf->data = realloc(ALBuf->data, (8*NewChannels + size) * (1*sizeof(ALshort)));
|
||||
if (ALBuf->data)
|
||||
{
|
||||
for (i = 0;i < size;i+=4)
|
||||
{
|
||||
ALBuf->data[i+0] = 0;
|
||||
ALBuf->data[i+1] = 0;
|
||||
ALBuf->data[i+2] = (ALshort)((((ALubyte*)data)[i/2+0]-128) << 8);
|
||||
ALBuf->data[i+3] = (ALshort)((((ALubyte*)data)[i/2+1]-128) << 8);
|
||||
}
|
||||
memset(&(ALBuf->data[size]), 0, 16*NewChannels);
|
||||
memset(&(ALBuf->data[size]), 0, padding*NewChannels*sizeof(ALshort));
|
||||
|
||||
ALBuf->format = NewFormat;
|
||||
ALBuf->eOriginalFormat = format;
|
||||
ALBuf->size = size*1*sizeof(ALshort);
|
||||
ALBuf->frequency = freq;
|
||||
}
|
||||
else
|
||||
alSetError(AL_OUT_OF_MEMORY);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
size /= sizeof(ALshort);
|
||||
size *= 2;
|
||||
|
||||
// Allocate 8 extra samples
|
||||
ALBuf->data = realloc(ALBuf->data, (8*NewChannels + size) * (1*sizeof(ALshort)));
|
||||
if (ALBuf->data)
|
||||
{
|
||||
for (i = 0;i < size;i+=4)
|
||||
{
|
||||
ALBuf->data[i+0] = 0;
|
||||
ALBuf->data[i+1] = 0;
|
||||
ALBuf->data[i+2] = ((ALshort*)data)[i/2+0];
|
||||
ALBuf->data[i+3] = ((ALshort*)data)[i/2+1];
|
||||
}
|
||||
memset(&(ALBuf->data[size]), 0, 16*NewChannels);
|
||||
|
||||
ALBuf->format = NewFormat;
|
||||
ALBuf->eOriginalFormat = format;
|
||||
ALBuf->size = size*1*sizeof(ALshort);
|
||||
ALBuf->frequency = freq;
|
||||
}
|
||||
else
|
||||
alSetError(AL_OUT_OF_MEMORY);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
size /= sizeof(ALfloat);
|
||||
size *= 2;
|
||||
|
||||
// Allocate 8 extra samples
|
||||
ALBuf->data = realloc(ALBuf->data, (8*NewChannels + size) * (1*sizeof(ALshort)));
|
||||
if (ALBuf->data)
|
||||
{
|
||||
ALint smp;
|
||||
for (i = 0;i < size;i+=4)
|
||||
{
|
||||
ALBuf->data[i+0] = 0;
|
||||
ALBuf->data[i+1] = 0;
|
||||
smp = (((ALfloat*)data)[i/2+0] * 32767.5f - 0.5);
|
||||
smp = min(smp, 32767);
|
||||
smp = max(smp, -32768);
|
||||
ALBuf->data[i+2] = (ALshort)smp;
|
||||
smp = (((ALfloat*)data)[i/2+1] * 32767.5f - 0.5);
|
||||
smp = min(smp, 32767);
|
||||
smp = max(smp, -32768);
|
||||
ALBuf->data[i+3] = (ALshort)smp;
|
||||
}
|
||||
memset(&(ALBuf->data[size]), 0, 16*NewChannels);
|
||||
|
||||
ALBuf->format = NewFormat;
|
||||
ALBuf->eOriginalFormat = format;
|
||||
ALBuf->size = size*1*sizeof(ALshort);
|
||||
ALBuf->frequency = freq;
|
||||
}
|
||||
else
|
||||
alSetError(AL_OUT_OF_MEMORY);
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
ALBuf->format = NewFormat;
|
||||
ALBuf->eOriginalFormat = format;
|
||||
ALBuf->size = size*sizeof(ALshort);
|
||||
ALBuf->frequency = freq;
|
||||
ALBuf->padding = padding;
|
||||
}
|
||||
else
|
||||
alSetError(AL_OUT_OF_MEMORY);
|
||||
} break;
|
||||
|
||||
case AL_FORMAT_QUAD8_LOKI:
|
||||
@@ -428,157 +351,39 @@ ALAPI ALvoid ALAPIENTRY alBufferData(ALuint buffer,ALenum format,const ALvoid *d
|
||||
break;
|
||||
|
||||
case AL_FORMAT_MONO_IMA4:
|
||||
case AL_FORMAT_STEREO_IMA4: {
|
||||
int OrigChans = ((format==AL_FORMAT_MONO_IMA4) ? 1 : 2);
|
||||
|
||||
// Here is where things vary:
|
||||
// nVidia and Apple use 64+1 samples per block => block_size=36 bytes
|
||||
// Most PC sound software uses 2040+1 samples per block -> block_size=1024 bytes
|
||||
if ((size%36) == 0)
|
||||
// nVidia and Apple use 64+1 samples per channel per block => block_size=36*chans bytes
|
||||
// Most PC sound software uses 2040+1 samples per channel per block -> block_size=1024*chans bytes
|
||||
if((size%(36*OrigChans)) != 0)
|
||||
{
|
||||
// Allocate 8 extra samples (16 bytes)
|
||||
ALBuf->data=realloc(ALBuf->data,16+(size/36)*(65*sizeof(ALshort)));
|
||||
if (ALBuf->data)
|
||||
{
|
||||
ALBuf->format = AL_FORMAT_MONO16;
|
||||
ALBuf->eOriginalFormat = AL_FORMAT_MONO_IMA4;
|
||||
IMAData=(ALuint *)data;
|
||||
for (i=0;i<size/36;i++)
|
||||
{
|
||||
Sample=((ALshort *)IMAData)[0];
|
||||
Index=((ALshort *)IMAData)[1];
|
||||
|
||||
Index=Index<0?0:Index;
|
||||
Index=Index>88?88:Index;
|
||||
|
||||
ALBuf->data[i*65]=(short)Sample;
|
||||
|
||||
IMAData++;
|
||||
|
||||
for (j=1;j<65;j+=8)
|
||||
{
|
||||
IMACode=*IMAData;
|
||||
for (k=0;k<8;k+=2)
|
||||
{
|
||||
Sample+=((g_IMAStep_size[Index]*g_IMACodeword_4[IMACode&15])/8);
|
||||
Index+=g_IMAIndex_adjust_4[IMACode&15];
|
||||
if (Sample<-32768) Sample=-32768;
|
||||
else if (Sample>32767) Sample=32767;
|
||||
if (Index<0) Index=0;
|
||||
else if (Index>88) Index=88;
|
||||
ALBuf->data[i*65+j+k]=(short)Sample;
|
||||
IMACode>>=4;
|
||||
|
||||
Sample+=((g_IMAStep_size[Index]*g_IMACodeword_4[IMACode&15])/8);
|
||||
Index+=g_IMAIndex_adjust_4[IMACode&15];
|
||||
if (Sample<-32768) Sample=-32768;
|
||||
else if (Sample>32767) Sample=32767;
|
||||
if (Index<0) Index=0;
|
||||
else if (Index>88) Index=88;
|
||||
ALBuf->data[i*65+j+k+1]=(short)Sample;
|
||||
IMACode>>=4;
|
||||
}
|
||||
IMAData++;
|
||||
}
|
||||
}
|
||||
memset(&(ALBuf->data[(size/36*65)]), 0, 16);
|
||||
ALBuf->size=size/36*65*sizeof(ALshort);
|
||||
ALBuf->frequency=freq;
|
||||
}
|
||||
else
|
||||
alSetError(AL_OUT_OF_MEMORY);
|
||||
}
|
||||
else
|
||||
alSetError(AL_INVALID_VALUE);
|
||||
break;
|
||||
|
||||
case AL_FORMAT_STEREO_IMA4:
|
||||
// Here is where things vary:
|
||||
// nVidia and Apple use 64+1 samples per channel per block => block_size=72 bytes
|
||||
// Most PC sound software uses 2040+1 samples per channel per block -> block_size=2048 bytes
|
||||
if ((size%72) == 0)
|
||||
{
|
||||
// Allocate 8 extra samples (32 bytes)
|
||||
ALBuf->data=realloc(ALBuf->data,32+(size/72)*(2*65*sizeof(ALshort)));
|
||||
if (ALBuf->data)
|
||||
{
|
||||
ALBuf->format = AL_FORMAT_STEREO16;
|
||||
ALBuf->eOriginalFormat = AL_FORMAT_STEREO_IMA4;
|
||||
IMAData=(ALuint *)data;
|
||||
for (i=0;i<size/72;i++)
|
||||
{
|
||||
LeftSample=((ALshort *)IMAData)[0];
|
||||
LeftIndex=((ALshort *)IMAData)[1];
|
||||
|
||||
LeftIndex=LeftIndex<0?0:LeftIndex;
|
||||
LeftIndex=LeftIndex>88?88:LeftIndex;
|
||||
|
||||
ALBuf->data[i*2*65]=(short)LeftSample;
|
||||
|
||||
IMAData++;
|
||||
|
||||
RightSample=((ALshort *)IMAData)[0];
|
||||
RightIndex=((ALshort *)IMAData)[1];
|
||||
|
||||
RightIndex=RightIndex<0?0:RightIndex;
|
||||
RightIndex=RightIndex>88?88:RightIndex;
|
||||
|
||||
ALBuf->data[i*2*65+1]=(short)RightSample;
|
||||
|
||||
IMAData++;
|
||||
|
||||
for (j=2;j<130;j+=16)
|
||||
{
|
||||
LeftIMACode=IMAData[0];
|
||||
RightIMACode=IMAData[1];
|
||||
for (k=0;k<16;k+=4)
|
||||
{
|
||||
LeftSample+=((g_IMAStep_size[LeftIndex]*g_IMACodeword_4[LeftIMACode&15])/8);
|
||||
LeftIndex+=g_IMAIndex_adjust_4[LeftIMACode&15];
|
||||
if (LeftSample<-32768) LeftSample=-32768;
|
||||
else if (LeftSample>32767) LeftSample=32767;
|
||||
if (LeftIndex<0) LeftIndex=0;
|
||||
else if (LeftIndex>88) LeftIndex=88;
|
||||
ALBuf->data[i*2*65+j+k]=(short)LeftSample;
|
||||
LeftIMACode>>=4;
|
||||
|
||||
RightSample+=((g_IMAStep_size[RightIndex]*g_IMACodeword_4[RightIMACode&15])/8);
|
||||
RightIndex+=g_IMAIndex_adjust_4[RightIMACode&15];
|
||||
if (RightSample<-32768) RightSample=-32768;
|
||||
else if (RightSample>32767) RightSample=32767;
|
||||
if (RightIndex<0) RightIndex=0;
|
||||
else if (RightIndex>88) RightIndex=88;
|
||||
ALBuf->data[i*2*65+j+k+1]=(short)RightSample;
|
||||
RightIMACode>>=4;
|
||||
|
||||
LeftSample+=((g_IMAStep_size[LeftIndex]*g_IMACodeword_4[LeftIMACode&15])/8);
|
||||
LeftIndex+=g_IMAIndex_adjust_4[LeftIMACode&15];
|
||||
if (LeftSample<-32768) LeftSample=-32768;
|
||||
else if (LeftSample>32767) LeftSample=32767;
|
||||
if (LeftIndex<0) LeftIndex=0;
|
||||
else if (LeftIndex>88) LeftIndex=88;
|
||||
ALBuf->data[i*2*65+j+k+2]=(short)LeftSample;
|
||||
LeftIMACode>>=4;
|
||||
|
||||
RightSample+=((g_IMAStep_size[RightIndex]*g_IMACodeword_4[RightIMACode&15])/8);
|
||||
RightIndex+=g_IMAIndex_adjust_4[RightIMACode&15];
|
||||
if (RightSample<-32768) RightSample=-32768;
|
||||
else if (RightSample>32767) RightSample=32767;
|
||||
if (RightIndex<0) RightIndex=0;
|
||||
else if (RightIndex>88) RightIndex=88;
|
||||
ALBuf->data[i*2*65+j+k+3]=(short)RightSample;
|
||||
RightIMACode>>=4;
|
||||
}
|
||||
IMAData+=2;
|
||||
}
|
||||
}
|
||||
memset(&(ALBuf->data[(size/72*2*65)]), 0, 32);
|
||||
ALBuf->size=size/72*2*65*sizeof(ALshort);
|
||||
ALBuf->frequency=freq;
|
||||
}
|
||||
else
|
||||
alSetError(AL_OUT_OF_MEMORY);
|
||||
}
|
||||
else
|
||||
alSetError(AL_INVALID_VALUE);
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
size /= 36;
|
||||
size *= 65;
|
||||
|
||||
// Allocate extra padding samples
|
||||
temp = realloc(ALBuf->data, (padding*OrigChans + size)*sizeof(ALshort));
|
||||
if(temp)
|
||||
{
|
||||
ALBuf->data = temp;
|
||||
ConvertDataIMA4(ALBuf->data, data, OrigChans, size/65);
|
||||
|
||||
memset(&(ALBuf->data[size]), 0, padding*sizeof(ALshort)*OrigChans);
|
||||
|
||||
ALBuf->format = ((OrigChans==1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16);
|
||||
ALBuf->eOriginalFormat = format;
|
||||
ALBuf->size = size*sizeof(ALshort);
|
||||
ALBuf->frequency = freq;
|
||||
ALBuf->padding = padding;
|
||||
}
|
||||
else
|
||||
alSetError(AL_OUT_OF_MEMORY);
|
||||
} break;
|
||||
|
||||
default:
|
||||
alSetError(AL_INVALID_ENUM);
|
||||
@@ -600,6 +405,110 @@ ALAPI ALvoid ALAPIENTRY alBufferData(ALuint buffer,ALenum format,const ALvoid *d
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
/*
|
||||
* alBufferSubDataEXT(ALuint buffer,ALenum format,ALvoid *data,ALsizei offset,ALsizei length)
|
||||
*
|
||||
* Fill buffer with audio data
|
||||
*/
|
||||
ALvoid ALAPIENTRY alBufferSubDataEXT(ALuint buffer,ALenum format,const ALvoid *data,ALsizei offset,ALsizei length)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
ALbuffer *ALBuf;
|
||||
|
||||
Context = alcGetCurrentContext();
|
||||
SuspendContext(Context);
|
||||
|
||||
if(alIsBuffer(buffer) && buffer != 0)
|
||||
{
|
||||
ALBuf = (ALbuffer*)ALTHUNK_LOOKUPENTRY(buffer);
|
||||
if(ALBuf->data == NULL)
|
||||
{
|
||||
// buffer does not have any data
|
||||
alSetError(AL_INVALID_NAME);
|
||||
}
|
||||
else if(length < 0 || offset < 0 || (length > 0 && data == NULL))
|
||||
{
|
||||
// data is NULL or offset/length is negative
|
||||
alSetError(AL_INVALID_VALUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(format)
|
||||
{
|
||||
case AL_FORMAT_REAR8:
|
||||
case AL_FORMAT_REAR16:
|
||||
case AL_FORMAT_REAR32: {
|
||||
ALuint OrigBytes = ((format==AL_FORMAT_REAR8) ? 1 :
|
||||
((format==AL_FORMAT_REAR16) ? 2 :
|
||||
4));
|
||||
|
||||
if(ALBuf->eOriginalFormat != AL_FORMAT_REAR8 &&
|
||||
ALBuf->eOriginalFormat != AL_FORMAT_REAR16 &&
|
||||
ALBuf->eOriginalFormat != AL_FORMAT_REAR32)
|
||||
{
|
||||
alSetError(AL_INVALID_ENUM);
|
||||
break;
|
||||
}
|
||||
|
||||
if(ALBuf->size/4/sizeof(ALshort) < (ALuint)offset+length)
|
||||
{
|
||||
alSetError(AL_INVALID_VALUE);
|
||||
break;
|
||||
}
|
||||
|
||||
ConvertDataRear(&ALBuf->data[offset*4], data, OrigBytes, length*2);
|
||||
} break;
|
||||
|
||||
case AL_FORMAT_MONO_IMA4:
|
||||
case AL_FORMAT_STEREO_IMA4: {
|
||||
int Channels = aluChannelsFromFormat(ALBuf->format);
|
||||
|
||||
if(ALBuf->eOriginalFormat != format)
|
||||
{
|
||||
alSetError(AL_INVALID_ENUM);
|
||||
break;
|
||||
}
|
||||
|
||||
if((offset%65) != 0 || (length%65) != 0 ||
|
||||
ALBuf->size/Channels/sizeof(ALshort) < (ALuint)offset+length)
|
||||
{
|
||||
alSetError(AL_INVALID_VALUE);
|
||||
break;
|
||||
}
|
||||
|
||||
ConvertDataIMA4(&ALBuf->data[offset*Channels], data, Channels, length/65*Channels);
|
||||
} break;
|
||||
|
||||
default: {
|
||||
ALuint Channels = aluChannelsFromFormat(format);
|
||||
ALuint Bytes = aluBytesFromFormat(format);
|
||||
|
||||
if(Channels != aluChannelsFromFormat(ALBuf->format))
|
||||
{
|
||||
alSetError(AL_INVALID_ENUM);
|
||||
break;
|
||||
}
|
||||
|
||||
if(ALBuf->size/Channels/sizeof(ALshort) < (ALuint)offset+length)
|
||||
{
|
||||
alSetError(AL_INVALID_VALUE);
|
||||
break;
|
||||
}
|
||||
|
||||
ConvertData(&ALBuf->data[offset*Channels], data, Bytes, length*Channels);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Invalid Buffer Name
|
||||
alSetError(AL_INVALID_NAME);
|
||||
}
|
||||
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
|
||||
ALAPI void ALAPIENTRY alBufferf(ALuint buffer, ALenum eParam, ALfloat flValue)
|
||||
{
|
||||
@@ -997,7 +906,8 @@ static void LoadData(ALbuffer *ALBuf, const ALubyte *data, ALsizei size, ALuint
|
||||
ALuint NewChannels = aluChannelsFromFormat(NewFormat);
|
||||
ALuint OrigBytes = aluBytesFromFormat(OrigFormat);
|
||||
ALuint OrigChannels = aluChannelsFromFormat(OrigFormat);
|
||||
ALsizei i;
|
||||
ALsizei padding = 2;
|
||||
ALvoid *temp;
|
||||
|
||||
assert(aluBytesFromFormat(NewFormat) == 2);
|
||||
assert(NewChannels == OrigChannels);
|
||||
@@ -1008,79 +918,153 @@ static void LoadData(ALbuffer *ALBuf, const ALubyte *data, ALsizei size, ALuint
|
||||
return;
|
||||
}
|
||||
|
||||
switch(OrigBytes)
|
||||
// Samples are converted to 16 bit here
|
||||
size /= OrigBytes;
|
||||
temp = realloc(ALBuf->data, (padding*NewChannels + size) * sizeof(ALshort));
|
||||
if(temp)
|
||||
{
|
||||
case 1:
|
||||
size /= sizeof(ALubyte);
|
||||
ALBuf->data = temp;
|
||||
ConvertData(ALBuf->data, data, OrigBytes, size);
|
||||
|
||||
// 8bit Samples are converted to 16 bit here
|
||||
// Allocate 8 extra samples
|
||||
ALBuf->data = realloc(ALBuf->data, (8*NewChannels + size) * (1*sizeof(ALshort)));
|
||||
if (ALBuf->data)
|
||||
{
|
||||
for (i = 0;i < size;i++)
|
||||
ALBuf->data[i] = (ALshort)((data[i]-128) << 8);
|
||||
memset(&(ALBuf->data[size]), 0, 16*NewChannels);
|
||||
memset(&(ALBuf->data[size]), 0, padding*NewChannels*sizeof(ALshort));
|
||||
|
||||
ALBuf->format = NewFormat;
|
||||
ALBuf->eOriginalFormat = OrigFormat;
|
||||
ALBuf->size = size*1*sizeof(ALshort);
|
||||
ALBuf->frequency = freq;
|
||||
}
|
||||
else
|
||||
alSetError(AL_OUT_OF_MEMORY);
|
||||
break;
|
||||
ALBuf->format = NewFormat;
|
||||
ALBuf->eOriginalFormat = OrigFormat;
|
||||
ALBuf->size = size*sizeof(ALshort);
|
||||
ALBuf->frequency = freq;
|
||||
ALBuf->padding = padding;
|
||||
}
|
||||
else
|
||||
alSetError(AL_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
case 2:
|
||||
size /= sizeof(ALshort);
|
||||
static void ConvertData(ALshort *dst, const ALvoid *src, ALint origBytes, ALsizei len)
|
||||
{
|
||||
ALsizei i;
|
||||
switch(origBytes)
|
||||
{
|
||||
case 1:
|
||||
for(i = 0;i < len;i++)
|
||||
dst[i] = ((ALshort)((ALubyte*)src)[i] - 128) << 8;
|
||||
break;
|
||||
|
||||
// Allocate 8 extra samples
|
||||
ALBuf->data = realloc(ALBuf->data, (8*NewChannels + size) * (1*sizeof(ALshort)));
|
||||
if (ALBuf->data)
|
||||
{
|
||||
memcpy(ALBuf->data, data, size*1*sizeof(ALshort));
|
||||
memset(&(ALBuf->data[size]), 0, 16*NewChannels);
|
||||
case 2:
|
||||
memcpy(dst, src, len*sizeof(ALshort));
|
||||
break;
|
||||
|
||||
ALBuf->format = NewFormat;
|
||||
ALBuf->eOriginalFormat = OrigFormat;
|
||||
ALBuf->size = size*1*sizeof(ALshort);
|
||||
ALBuf->frequency = freq;
|
||||
}
|
||||
else
|
||||
alSetError(AL_OUT_OF_MEMORY);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
size /= sizeof(ALfloat);
|
||||
|
||||
// Allocate 8 extra samples
|
||||
ALBuf->data = realloc(ALBuf->data, (8*NewChannels + size) * (1*sizeof(ALshort)));
|
||||
if (ALBuf->data)
|
||||
{
|
||||
ALint smp;
|
||||
for (i = 0;i < size;i++)
|
||||
case 4:
|
||||
for(i = 0;i < len;i++)
|
||||
{
|
||||
smp = (((ALfloat*)data)[i] * 32767.5f - 0.5f);
|
||||
ALint smp;
|
||||
smp = (((ALfloat*)src)[i] * 32767.5f - 0.5f);
|
||||
smp = min(smp, 32767);
|
||||
smp = max(smp, -32768);
|
||||
ALBuf->data[i] = (ALshort)smp;
|
||||
dst[i] = (ALshort)smp;
|
||||
}
|
||||
memset(&(ALBuf->data[size]), 0, 16*NewChannels);
|
||||
break;
|
||||
|
||||
ALBuf->format = NewFormat;
|
||||
ALBuf->eOriginalFormat = OrigFormat;
|
||||
ALBuf->size = size*1*sizeof(ALshort);
|
||||
ALBuf->frequency = freq;
|
||||
}
|
||||
else
|
||||
alSetError(AL_OUT_OF_MEMORY);
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
static void ConvertDataRear(ALshort *dst, const ALvoid *src, ALint origBytes, ALsizei len)
|
||||
{
|
||||
ALsizei i;
|
||||
switch(origBytes)
|
||||
{
|
||||
case 1:
|
||||
for(i = 0;i < len;i+=4)
|
||||
{
|
||||
dst[i+0] = 0;
|
||||
dst[i+1] = 0;
|
||||
dst[i+2] = ((ALshort)((ALubyte*)src)[i/2+0] - 128) << 8;
|
||||
dst[i+3] = ((ALshort)((ALubyte*)src)[i/2+1] - 128) << 8;
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
for(i = 0;i < len;i+=4)
|
||||
{
|
||||
dst[i+0] = 0;
|
||||
dst[i+1] = 0;
|
||||
dst[i+2] = ((ALshort*)src)[i/2+0];
|
||||
dst[i+3] = ((ALshort*)src)[i/2+1];
|
||||
}
|
||||
break;
|
||||
|
||||
case 4:
|
||||
for(i = 0;i < len;i+=4)
|
||||
{
|
||||
ALint smp;
|
||||
dst[i+0] = 0;
|
||||
dst[i+1] = 0;
|
||||
smp = (((ALfloat*)src)[i/2+0] * 32767.5f - 0.5);
|
||||
smp = min(smp, 32767);
|
||||
smp = max(smp, -32768);
|
||||
dst[i+2] = (ALshort)smp;
|
||||
smp = (((ALfloat*)src)[i/2+1] * 32767.5f - 0.5);
|
||||
smp = min(smp, 32767);
|
||||
smp = max(smp, -32768);
|
||||
dst[i+3] = (ALshort)smp;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
static void ConvertDataIMA4(ALshort *dst, const ALvoid *src, ALint origChans, ALsizei len)
|
||||
{
|
||||
const ALuint *IMAData;
|
||||
ALint Sample[2],Index[2];
|
||||
ALuint IMACode[2];
|
||||
ALsizei i,j,k,c;
|
||||
|
||||
assert(origChans <= 2);
|
||||
|
||||
IMAData = src;
|
||||
for(i = 0;i < len/origChans;i++)
|
||||
{
|
||||
for(c = 0;c < origChans;c++)
|
||||
{
|
||||
Sample[c] = ((ALshort*)IMAData)[0];
|
||||
Index[c] = ((ALshort*)IMAData)[1];
|
||||
|
||||
Index[c] = ((Index[c]<0) ? 0 : Index[c]);
|
||||
Index[c] = ((Index[c]>88) ? 88 : Index[c]);
|
||||
|
||||
dst[i*65*origChans + c] = (ALshort)Sample[c];
|
||||
|
||||
IMAData++;
|
||||
}
|
||||
|
||||
for(j = 1;j < 65;j += 8)
|
||||
{
|
||||
for(c = 0;c < origChans;c++)
|
||||
IMACode[c] = *(IMAData++);
|
||||
|
||||
for(k = 0;k < 8;k++)
|
||||
{
|
||||
for(c = 0;c < origChans;c++)
|
||||
{
|
||||
Sample[c] += ((g_IMAStep_size[Index[c]]*g_IMACodeword_4[IMACode[c]&15])/8);
|
||||
Index[c] += g_IMAIndex_adjust_4[IMACode[c]&15];
|
||||
|
||||
if(Sample[c] < -32768) Sample[c] = -32768;
|
||||
else if(Sample[c] > 32767) Sample[c] = 32767;
|
||||
|
||||
if(Index[c]<0) Index[c] = 0;
|
||||
else if(Index[c]>88) Index[c] = 88;
|
||||
|
||||
dst[(i*65+j+k)*origChans + c] = (ALshort)Sample[c];
|
||||
IMACode[c] >>= 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* ReleaseALBuffers()
|
||||
@@ -1094,7 +1078,7 @@ ALvoid ReleaseALBuffers(ALvoid)
|
||||
|
||||
#ifdef _DEBUG
|
||||
if(g_uiBufferCount > 0)
|
||||
AL_PRINT("exit() %d Buffer(s) NOT deleted\n", g_uiBufferCount);
|
||||
AL_PRINT("exit(): deleting %d Buffer(s)\n", g_uiBufferCount);
|
||||
#endif
|
||||
|
||||
ALBuffer = g_pBuffers;
|
||||
|
||||
+20
-14
@@ -29,13 +29,17 @@
|
||||
#include "alThunk.h"
|
||||
#include "alError.h"
|
||||
|
||||
|
||||
ALboolean DisabledEffects[MAX_EFFECTS];
|
||||
|
||||
|
||||
static ALeffect *g_EffectList;
|
||||
static ALuint g_EffectCount;
|
||||
|
||||
static void InitEffectParams(ALeffect *effect, ALenum type);
|
||||
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects)
|
||||
ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
ALsizei i;
|
||||
@@ -79,7 +83,7 @@ AL_API ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects)
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alDeleteEffects(ALsizei n, ALuint *effects)
|
||||
ALvoid AL_APIENTRY alDeleteEffects(ALsizei n, ALuint *effects)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
ALeffect *ALEffect;
|
||||
@@ -135,7 +139,7 @@ AL_API ALvoid AL_APIENTRY alDeleteEffects(ALsizei n, ALuint *effects)
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
AL_API ALboolean AL_APIENTRY alIsEffect(ALuint effect)
|
||||
ALboolean AL_APIENTRY alIsEffect(ALuint effect)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
ALeffect **list;
|
||||
@@ -152,7 +156,7 @@ AL_API ALboolean AL_APIENTRY alIsEffect(ALuint effect)
|
||||
return ((*list || !effect) ? AL_TRUE : AL_FALSE);
|
||||
}
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alEffecti(ALuint effect, ALenum param, ALint iValue)
|
||||
ALvoid AL_APIENTRY alEffecti(ALuint effect, ALenum param, ALint iValue)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
|
||||
@@ -165,8 +169,10 @@ AL_API ALvoid AL_APIENTRY alEffecti(ALuint effect, ALenum param, ALint iValue)
|
||||
|
||||
if(param == AL_EFFECT_TYPE)
|
||||
{
|
||||
if(iValue == AL_EFFECT_NULL ||
|
||||
iValue == AL_EFFECT_REVERB)
|
||||
ALboolean isOk = (iValue == AL_EFFECT_NULL ||
|
||||
(iValue == AL_EFFECT_REVERB && !DisabledEffects[REVERB]));
|
||||
|
||||
if(isOk)
|
||||
InitEffectParams(ALEffect, iValue);
|
||||
else
|
||||
alSetError(AL_INVALID_VALUE);
|
||||
@@ -196,7 +202,7 @@ AL_API ALvoid AL_APIENTRY alEffecti(ALuint effect, ALenum param, ALint iValue)
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alEffectiv(ALuint effect, ALenum param, ALint *piValues)
|
||||
ALvoid AL_APIENTRY alEffectiv(ALuint effect, ALenum param, ALint *piValues)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
|
||||
@@ -233,7 +239,7 @@ AL_API ALvoid AL_APIENTRY alEffectiv(ALuint effect, ALenum param, ALint *piValue
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alEffectf(ALuint effect, ALenum param, ALfloat flValue)
|
||||
ALvoid AL_APIENTRY alEffectf(ALuint effect, ALenum param, ALfloat flValue)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
|
||||
@@ -346,7 +352,7 @@ AL_API ALvoid AL_APIENTRY alEffectf(ALuint effect, ALenum param, ALfloat flValue
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alEffectfv(ALuint effect, ALenum param, ALfloat *pflValues)
|
||||
ALvoid AL_APIENTRY alEffectfv(ALuint effect, ALenum param, ALfloat *pflValues)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
|
||||
@@ -390,7 +396,7 @@ AL_API ALvoid AL_APIENTRY alEffectfv(ALuint effect, ALenum param, ALfloat *pflVa
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alGetEffecti(ALuint effect, ALenum param, ALint *piValue)
|
||||
ALvoid AL_APIENTRY alGetEffecti(ALuint effect, ALenum param, ALint *piValue)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
|
||||
@@ -427,7 +433,7 @@ AL_API ALvoid AL_APIENTRY alGetEffecti(ALuint effect, ALenum param, ALint *piVal
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alGetEffectiv(ALuint effect, ALenum param, ALint *piValues)
|
||||
ALvoid AL_APIENTRY alGetEffectiv(ALuint effect, ALenum param, ALint *piValues)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
|
||||
@@ -464,7 +470,7 @@ AL_API ALvoid AL_APIENTRY alGetEffectiv(ALuint effect, ALenum param, ALint *piVa
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alGetEffectf(ALuint effect, ALenum param, ALfloat *pflValue)
|
||||
ALvoid AL_APIENTRY alGetEffectf(ALuint effect, ALenum param, ALfloat *pflValue)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
|
||||
@@ -541,7 +547,7 @@ AL_API ALvoid AL_APIENTRY alGetEffectf(ALuint effect, ALenum param, ALfloat *pfl
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alGetEffectfv(ALuint effect, ALenum param, ALfloat *pflValues)
|
||||
ALvoid AL_APIENTRY alGetEffectfv(ALuint effect, ALenum param, ALfloat *pflValues)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
|
||||
@@ -590,7 +596,7 @@ ALvoid ReleaseALEffects(ALvoid)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if(g_EffectCount > 0)
|
||||
AL_PRINT("exit() %d Effect(s) NOT deleted\n", g_EffectCount);
|
||||
AL_PRINT("exit(): deleting %d Effect(s)\n", g_EffectCount);
|
||||
#endif
|
||||
|
||||
while(g_EffectList)
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "alEffect.h"
|
||||
#include "alAuxEffectSlot.h"
|
||||
#include "alSource.h"
|
||||
#include "alBuffer.h"
|
||||
#include "AL/al.h"
|
||||
#include "AL/alc.h"
|
||||
|
||||
@@ -144,6 +145,8 @@ static ALfunction function[]= {
|
||||
{ "alGetAuxiliaryEffectSlotf", (ALvoid *) alGetAuxiliaryEffectSlotf },
|
||||
{ "alGetAuxiliaryEffectSlotfv", (ALvoid *) alGetAuxiliaryEffectSlotfv},
|
||||
|
||||
{ "alBufferSubDataEXT", (ALvoid *) alBufferSubDataEXT },
|
||||
|
||||
{ NULL, (ALvoid *) NULL } };
|
||||
|
||||
static ALenums enumeration[]={
|
||||
|
||||
+93
-91
@@ -35,7 +35,7 @@ static ALuint g_FilterCount;
|
||||
static void InitFilterParams(ALfilter *filter, ALenum type);
|
||||
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters)
|
||||
ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
ALsizei i;
|
||||
@@ -79,7 +79,7 @@ AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters)
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, ALuint *filters)
|
||||
ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, ALuint *filters)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
ALfilter *ALFilter;
|
||||
@@ -135,7 +135,7 @@ AL_API ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, ALuint *filters)
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
AL_API ALboolean AL_APIENTRY alIsFilter(ALuint filter)
|
||||
ALboolean AL_APIENTRY alIsFilter(ALuint filter)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
ALfilter **list;
|
||||
@@ -152,7 +152,7 @@ AL_API ALboolean AL_APIENTRY alIsFilter(ALuint filter)
|
||||
return ((*list || !filter) ? AL_TRUE : AL_FALSE);
|
||||
}
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alFilteri(ALuint filter, ALenum param, ALint iValue)
|
||||
ALvoid AL_APIENTRY alFilteri(ALuint filter, ALenum param, ALint iValue)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
|
||||
@@ -184,7 +184,7 @@ AL_API ALvoid AL_APIENTRY alFilteri(ALuint filter, ALenum param, ALint iValue)
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alFilteriv(ALuint filter, ALenum param, ALint *piValues)
|
||||
ALvoid AL_APIENTRY alFilteriv(ALuint filter, ALenum param, ALint *piValues)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
|
||||
@@ -210,7 +210,7 @@ AL_API ALvoid AL_APIENTRY alFilteriv(ALuint filter, ALenum param, ALint *piValue
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alFilterf(ALuint filter, ALenum param, ALfloat flValue)
|
||||
ALvoid AL_APIENTRY alFilterf(ALuint filter, ALenum param, ALfloat flValue)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
|
||||
@@ -221,26 +221,29 @@ AL_API ALvoid AL_APIENTRY alFilterf(ALuint filter, ALenum param, ALfloat flValue
|
||||
{
|
||||
ALfilter *ALFilter = (ALfilter*)ALTHUNK_LOOKUPENTRY(filter);
|
||||
|
||||
switch(param)
|
||||
switch(ALFilter->type)
|
||||
{
|
||||
case AL_LOWPASS_GAIN:
|
||||
if(ALFilter->type == AL_FILTER_LOWPASS)
|
||||
case AL_FILTER_LOWPASS:
|
||||
switch(param)
|
||||
{
|
||||
case AL_LOWPASS_GAIN:
|
||||
if(flValue >= 0.0f && flValue <= 1.0f)
|
||||
ALFilter->Gain = flValue;
|
||||
}
|
||||
else
|
||||
alSetError(AL_INVALID_ENUM);
|
||||
break;
|
||||
else
|
||||
alSetError(AL_INVALID_VALUE);
|
||||
break;
|
||||
|
||||
case AL_LOWPASS_GAINHF:
|
||||
if(ALFilter->type == AL_FILTER_LOWPASS)
|
||||
{
|
||||
case AL_LOWPASS_GAINHF:
|
||||
if(flValue >= 0.0f && flValue <= 1.0f)
|
||||
ALFilter->GainHF = flValue;
|
||||
}
|
||||
else
|
||||
else
|
||||
alSetError(AL_INVALID_VALUE);
|
||||
break;
|
||||
|
||||
default:
|
||||
alSetError(AL_INVALID_ENUM);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -254,7 +257,7 @@ AL_API ALvoid AL_APIENTRY alFilterf(ALuint filter, ALenum param, ALfloat flValue
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alFilterfv(ALuint filter, ALenum param, ALfloat *pflValues)
|
||||
ALvoid AL_APIENTRY alFilterfv(ALuint filter, ALenum param, ALfloat *pflValues)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
|
||||
@@ -265,14 +268,9 @@ AL_API ALvoid AL_APIENTRY alFilterfv(ALuint filter, ALenum param, ALfloat *pflVa
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case AL_LOWPASS_GAIN:
|
||||
case AL_LOWPASS_GAINHF:
|
||||
default:
|
||||
alFilterf(filter, param, pflValues[0]);
|
||||
break;
|
||||
|
||||
default:
|
||||
alSetError(AL_INVALID_ENUM);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -281,55 +279,7 @@ AL_API ALvoid AL_APIENTRY alFilterfv(ALuint filter, ALenum param, ALfloat *pflVa
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alGetFilteri(ALuint filter, ALenum param, ALint *piValue)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
|
||||
(void)piValue;
|
||||
|
||||
Context = alcGetCurrentContext();
|
||||
SuspendContext(Context);
|
||||
|
||||
if (filter && alIsFilter(filter))
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
alSetError(AL_INVALID_ENUM);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
alSetError(AL_INVALID_NAME);
|
||||
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alGetFilteriv(ALuint filter, ALenum param, ALint *piValues)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
|
||||
(void)piValues;
|
||||
|
||||
Context = alcGetCurrentContext();
|
||||
SuspendContext(Context);
|
||||
|
||||
if (filter && alIsFilter(filter))
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
alSetError(AL_INVALID_ENUM);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
alSetError(AL_INVALID_NAME);
|
||||
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alGetFilterf(ALuint filter, ALenum param, ALfloat *pflValue)
|
||||
ALvoid AL_APIENTRY alGetFilteri(ALuint filter, ALenum param, ALint *piValue)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
|
||||
@@ -342,18 +292,8 @@ AL_API ALvoid AL_APIENTRY alGetFilterf(ALuint filter, ALenum param, ALfloat *pfl
|
||||
|
||||
switch(param)
|
||||
{
|
||||
case AL_LOWPASS_GAIN:
|
||||
if(ALFilter->type == AL_FILTER_LOWPASS)
|
||||
*pflValue = ALFilter->Gain;
|
||||
else
|
||||
alSetError(AL_INVALID_ENUM);
|
||||
break;
|
||||
|
||||
case AL_LOWPASS_GAINHF:
|
||||
if(ALFilter->type == AL_FILTER_LOWPASS)
|
||||
*pflValue = ALFilter->GainHF;
|
||||
else
|
||||
alSetError(AL_INVALID_ENUM);
|
||||
case AL_FILTER_TYPE:
|
||||
*piValue = ALFilter->type;
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -367,7 +307,7 @@ AL_API ALvoid AL_APIENTRY alGetFilterf(ALuint filter, ALenum param, ALfloat *pfl
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
AL_API ALvoid AL_APIENTRY alGetFilterfv(ALuint filter, ALenum param, ALfloat *pflValues)
|
||||
ALvoid AL_APIENTRY alGetFilteriv(ALuint filter, ALenum param, ALint *piValues)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
|
||||
@@ -378,9 +318,8 @@ AL_API ALvoid AL_APIENTRY alGetFilterfv(ALuint filter, ALenum param, ALfloat *pf
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
case AL_LOWPASS_GAIN:
|
||||
case AL_LOWPASS_GAINHF:
|
||||
alGetFilterf(filter, param, pflValues);
|
||||
case AL_FILTER_TYPE:
|
||||
alGetFilteri(filter, param, piValues);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -394,12 +333,75 @@ AL_API ALvoid AL_APIENTRY alGetFilterfv(ALuint filter, ALenum param, ALfloat *pf
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
ALvoid AL_APIENTRY alGetFilterf(ALuint filter, ALenum param, ALfloat *pflValue)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
|
||||
Context = alcGetCurrentContext();
|
||||
SuspendContext(Context);
|
||||
|
||||
if (filter && alIsFilter(filter))
|
||||
{
|
||||
ALfilter *ALFilter = (ALfilter*)ALTHUNK_LOOKUPENTRY(filter);
|
||||
|
||||
switch(ALFilter->type)
|
||||
{
|
||||
case AL_FILTER_LOWPASS:
|
||||
switch(param)
|
||||
{
|
||||
case AL_LOWPASS_GAIN:
|
||||
*pflValue = ALFilter->Gain;
|
||||
break;
|
||||
|
||||
case AL_LOWPASS_GAINHF:
|
||||
*pflValue = ALFilter->GainHF;
|
||||
break;
|
||||
|
||||
default:
|
||||
alSetError(AL_INVALID_ENUM);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
alSetError(AL_INVALID_ENUM);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
alSetError(AL_INVALID_NAME);
|
||||
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
ALvoid AL_APIENTRY alGetFilterfv(ALuint filter, ALenum param, ALfloat *pflValues)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
|
||||
Context = alcGetCurrentContext();
|
||||
SuspendContext(Context);
|
||||
|
||||
if (filter && alIsFilter(filter))
|
||||
{
|
||||
switch(param)
|
||||
{
|
||||
default:
|
||||
alGetFilterf(filter, param, pflValues);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
alSetError(AL_INVALID_NAME);
|
||||
|
||||
ProcessContext(Context);
|
||||
}
|
||||
|
||||
|
||||
ALvoid ReleaseALFilters(ALvoid)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if(g_FilterCount > 0)
|
||||
AL_PRINT("exit() %d Filter(s) NOT deleted\n", g_FilterCount);
|
||||
AL_PRINT("exit(): deleting %d Filter(s)\n", g_FilterCount);
|
||||
#endif
|
||||
|
||||
while(g_FilterList)
|
||||
|
||||
+192
-122
@@ -32,8 +32,8 @@
|
||||
#include "alThunk.h"
|
||||
#include "alAuxEffectSlot.h"
|
||||
|
||||
static ALvoid InitSourceParams(ALsource *pSource);
|
||||
static ALboolean GetSourceOffset(ALsource *pSource, ALenum eName, ALfloat *pflOffset);
|
||||
static ALvoid InitSourceParams(ALCcontext *Context, ALsource *pSource);
|
||||
static ALboolean GetSourceOffset(ALsource *pSource, ALenum eName, ALfloat *pflOffset, ALuint updateSize);
|
||||
static ALvoid ApplyOffset(ALsource *pSource, ALboolean bUpdateContext);
|
||||
static ALint GetByteOffset(ALsource *pSource);
|
||||
|
||||
@@ -78,7 +78,7 @@ ALAPI ALvoid ALAPIENTRY alGenSources(ALsizei n,ALuint *sources)
|
||||
sources[i] = (ALuint)ALTHUNK_ADDENTRY(*list);
|
||||
(*list)->source = sources[i];
|
||||
|
||||
InitSourceParams(*list);
|
||||
InitSourceParams(Context, *list);
|
||||
Context->SourceCount++;
|
||||
i++;
|
||||
|
||||
@@ -137,73 +137,64 @@ ALAPI ALvoid ALAPIENTRY alDeleteSources(ALsizei n, const ALuint *sources)
|
||||
|
||||
if (Device)
|
||||
{
|
||||
if ((ALuint)n <= Context->SourceCount)
|
||||
// Check that all Sources are valid (and can therefore be deleted)
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
// Check that all Sources are valid (and can therefore be deleted)
|
||||
for (i = 0; i < n; i++)
|
||||
if (!alIsSource(sources[i]))
|
||||
{
|
||||
if (!alIsSource(sources[i]))
|
||||
{
|
||||
alSetError(AL_INVALID_NAME);
|
||||
bSourcesValid = AL_FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (bSourcesValid)
|
||||
{
|
||||
// All Sources are valid, and can be deleted
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
// Recheck that the Source is valid, because there could be duplicated Source names
|
||||
if (alIsSource(sources[i]))
|
||||
{
|
||||
ALSource=((ALsource *)ALTHUNK_LOOKUPENTRY(sources[i]));
|
||||
alSourceStop((ALuint)ALSource->source);
|
||||
|
||||
// For each buffer in the source's queue, decrement its reference counter and remove it
|
||||
while (ALSource->queue != NULL)
|
||||
{
|
||||
ALBufferList = ALSource->queue;
|
||||
// Decrement buffer's reference counter
|
||||
if (ALBufferList->buffer != 0)
|
||||
((ALbuffer*)(ALTHUNK_LOOKUPENTRY(ALBufferList->buffer)))->refcount--;
|
||||
// Update queue to point to next element in list
|
||||
ALSource->queue = ALBufferList->next;
|
||||
// Release memory allocated for buffer list item
|
||||
free(ALBufferList);
|
||||
}
|
||||
|
||||
for(j = 0;j < MAX_SENDS;++j)
|
||||
{
|
||||
if(ALSource->Send[j].Slot)
|
||||
ALSource->Send[j].Slot->refcount--;
|
||||
ALSource->Send[j].Slot = NULL;
|
||||
}
|
||||
|
||||
// Decrement Source count
|
||||
Context->SourceCount--;
|
||||
|
||||
// Remove Source from list of Sources
|
||||
list = &Context->Source;
|
||||
while(*list && *list != ALSource)
|
||||
list = &(*list)->next;
|
||||
|
||||
if(*list)
|
||||
*list = (*list)->next;
|
||||
ALTHUNK_REMOVEENTRY(ALSource->source);
|
||||
|
||||
memset(ALSource,0,sizeof(ALsource));
|
||||
free(ALSource);
|
||||
}
|
||||
}
|
||||
|
||||
alSetError(AL_INVALID_NAME);
|
||||
bSourcesValid = AL_FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if (bSourcesValid)
|
||||
{
|
||||
// Trying to delete more Sources than have been generated
|
||||
alSetError(AL_INVALID_NAME);
|
||||
// All Sources are valid, and can be deleted
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
// Recheck that the Source is valid, because there could be duplicated Source names
|
||||
if (alIsSource(sources[i]))
|
||||
{
|
||||
ALSource=((ALsource *)ALTHUNK_LOOKUPENTRY(sources[i]));
|
||||
alSourceStop((ALuint)ALSource->source);
|
||||
|
||||
// For each buffer in the source's queue, decrement its reference counter and remove it
|
||||
while (ALSource->queue != NULL)
|
||||
{
|
||||
ALBufferList = ALSource->queue;
|
||||
// Decrement buffer's reference counter
|
||||
if (ALBufferList->buffer != 0)
|
||||
((ALbuffer*)(ALTHUNK_LOOKUPENTRY(ALBufferList->buffer)))->refcount--;
|
||||
// Update queue to point to next element in list
|
||||
ALSource->queue = ALBufferList->next;
|
||||
// Release memory allocated for buffer list item
|
||||
free(ALBufferList);
|
||||
}
|
||||
|
||||
for(j = 0;j < MAX_SENDS;++j)
|
||||
{
|
||||
if(ALSource->Send[j].Slot)
|
||||
ALSource->Send[j].Slot->refcount--;
|
||||
ALSource->Send[j].Slot = NULL;
|
||||
}
|
||||
|
||||
// Decrement Source count
|
||||
Context->SourceCount--;
|
||||
|
||||
// Remove Source from list of Sources
|
||||
list = &Context->Source;
|
||||
while(*list && *list != ALSource)
|
||||
list = &(*list)->next;
|
||||
|
||||
if(*list)
|
||||
*list = (*list)->next;
|
||||
ALTHUNK_REMOVEENTRY(ALSource->source);
|
||||
|
||||
memset(ALSource,0,sizeof(ALsource));
|
||||
free(ALSource);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -368,12 +359,19 @@ ALAPI ALvoid ALAPIENTRY alSourcef(ALuint source, ALenum eParam, ALfloat flValue)
|
||||
break;
|
||||
|
||||
case AL_ROOM_ROLLOFF_FACTOR:
|
||||
if (flValue >= 0.0f && flValue <= 1.0f)
|
||||
if (flValue >= 0.0f && flValue <= 10.0f)
|
||||
pSource->RoomRolloffFactor = flValue;
|
||||
else
|
||||
alSetError(AL_INVALID_VALUE);
|
||||
break;
|
||||
|
||||
case AL_DOPPLER_FACTOR:
|
||||
if (flValue >= 0.0f && flValue <= 1.0f)
|
||||
pSource->DopplerFactor = flValue;
|
||||
else
|
||||
alSetError(AL_INVALID_VALUE);
|
||||
break;
|
||||
|
||||
case AL_SEC_OFFSET:
|
||||
case AL_SAMPLE_OFFSET:
|
||||
case AL_BYTE_OFFSET:
|
||||
@@ -634,9 +632,6 @@ ALAPI ALvoid ALAPIENTRY alSourcei(ALuint source,ALenum eParam,ALint lValue)
|
||||
pSource->lSourceType = AL_UNDETERMINED;
|
||||
}
|
||||
|
||||
// Set Buffers Processed
|
||||
pSource->BuffersProcessed = 0;
|
||||
|
||||
// Update AL_BUFFER parameter
|
||||
pSource->ulBufferID = lValue;
|
||||
}
|
||||
@@ -709,6 +704,19 @@ ALAPI ALvoid ALAPIENTRY alSourcei(ALuint source,ALenum eParam,ALint lValue)
|
||||
alSetError(AL_INVALID_VALUE);
|
||||
break;
|
||||
|
||||
case AL_DISTANCE_MODEL:
|
||||
if(lValue == AL_NONE ||
|
||||
lValue == AL_INVERSE_DISTANCE ||
|
||||
lValue == AL_INVERSE_DISTANCE_CLAMPED ||
|
||||
lValue == AL_LINEAR_DISTANCE ||
|
||||
lValue == AL_LINEAR_DISTANCE_CLAMPED ||
|
||||
lValue == AL_EXPONENT_DISTANCE ||
|
||||
lValue == AL_EXPONENT_DISTANCE_CLAMPED)
|
||||
pSource->DistanceModel = lValue;
|
||||
else
|
||||
alSetError(AL_INVALID_VALUE);
|
||||
break;
|
||||
|
||||
default:
|
||||
alSetError(AL_INVALID_ENUM);
|
||||
break;
|
||||
@@ -824,6 +832,7 @@ ALAPI void ALAPIENTRY alSourceiv(ALuint source, ALenum eParam, const ALint* plVa
|
||||
case AL_DIRECT_FILTER_GAINHF_AUTO:
|
||||
case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO:
|
||||
case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO:
|
||||
case AL_DISTANCE_MODEL:
|
||||
alSourcei(source, eParam, plValues[0]);
|
||||
break;
|
||||
|
||||
@@ -858,7 +867,7 @@ ALAPI ALvoid ALAPIENTRY alGetSourcef(ALuint source, ALenum eParam, ALfloat *pflV
|
||||
{
|
||||
ALCcontext *pContext;
|
||||
ALsource *pSource;
|
||||
ALfloat flOffset;
|
||||
ALfloat flOffset[2];
|
||||
|
||||
pContext = alcGetCurrentContext();
|
||||
if (pContext)
|
||||
@@ -908,8 +917,20 @@ ALAPI ALvoid ALAPIENTRY alGetSourcef(ALuint source, ALenum eParam, ALfloat *pflV
|
||||
case AL_SEC_OFFSET:
|
||||
case AL_SAMPLE_OFFSET:
|
||||
case AL_BYTE_OFFSET:
|
||||
if (GetSourceOffset(pSource, eParam, &flOffset))
|
||||
*pflValue = flOffset;
|
||||
if(GetSourceOffset(pSource, eParam, flOffset, pContext->Device->UpdateSize))
|
||||
*pflValue = flOffset[0];
|
||||
else
|
||||
alSetError(AL_INVALID_OPERATION);
|
||||
break;
|
||||
|
||||
case AL_SEC_RW_OFFSETS_EXT:
|
||||
case AL_SAMPLE_RW_OFFSETS_EXT:
|
||||
case AL_BYTE_RW_OFFSETS_EXT:
|
||||
if(GetSourceOffset(pSource, eParam, flOffset, pContext->Device->UpdateSize))
|
||||
{
|
||||
pflValue[0] = flOffset[0];
|
||||
pflValue[1] = flOffset[1];
|
||||
}
|
||||
else
|
||||
alSetError(AL_INVALID_OPERATION);
|
||||
break;
|
||||
@@ -934,6 +955,10 @@ ALAPI ALvoid ALAPIENTRY alGetSourcef(ALuint source, ALenum eParam, ALfloat *pflV
|
||||
*pflValue = pSource->RoomRolloffFactor;
|
||||
break;
|
||||
|
||||
case AL_DOPPLER_FACTOR:
|
||||
*pflValue = pSource->DopplerFactor;
|
||||
break;
|
||||
|
||||
default:
|
||||
alSetError(AL_INVALID_ENUM);
|
||||
break;
|
||||
@@ -1034,6 +1059,7 @@ ALAPI ALvoid ALAPIENTRY alGetSourcefv(ALuint source, ALenum eParam, ALfloat *pfl
|
||||
case AL_MAX_GAIN:
|
||||
case AL_MAX_DISTANCE:
|
||||
case AL_ROLLOFF_FACTOR:
|
||||
case AL_DOPPLER_FACTOR:
|
||||
case AL_CONE_OUTER_GAIN:
|
||||
case AL_SEC_OFFSET:
|
||||
case AL_SAMPLE_OFFSET:
|
||||
@@ -1089,7 +1115,7 @@ ALAPI ALvoid ALAPIENTRY alGetSourcei(ALuint source, ALenum eParam, ALint *plValu
|
||||
{
|
||||
ALCcontext *pContext;
|
||||
ALsource *pSource;
|
||||
ALfloat flOffset;
|
||||
ALfloat flOffset[2];
|
||||
|
||||
pContext = alcGetCurrentContext();
|
||||
if (pContext)
|
||||
@@ -1152,7 +1178,7 @@ ALAPI ALvoid ALAPIENTRY alGetSourcei(ALuint source, ALenum eParam, ALint *plValu
|
||||
*plValue = 0;
|
||||
}
|
||||
else
|
||||
*plValue = pSource->BuffersProcessed;
|
||||
*plValue = pSource->BuffersPlayed;
|
||||
break;
|
||||
|
||||
case AL_SOURCE_TYPE:
|
||||
@@ -1162,8 +1188,20 @@ ALAPI ALvoid ALAPIENTRY alGetSourcei(ALuint source, ALenum eParam, ALint *plValu
|
||||
case AL_SEC_OFFSET:
|
||||
case AL_SAMPLE_OFFSET:
|
||||
case AL_BYTE_OFFSET:
|
||||
if (GetSourceOffset(pSource, eParam, &flOffset))
|
||||
*plValue = (ALint)flOffset;
|
||||
if(GetSourceOffset(pSource, eParam, flOffset, pContext->Device->UpdateSize))
|
||||
*plValue = (ALint)flOffset[0];
|
||||
else
|
||||
alSetError(AL_INVALID_OPERATION);
|
||||
break;
|
||||
|
||||
case AL_SEC_RW_OFFSETS_EXT:
|
||||
case AL_SAMPLE_RW_OFFSETS_EXT:
|
||||
case AL_BYTE_RW_OFFSETS_EXT:
|
||||
if(GetSourceOffset(pSource, eParam, flOffset, pContext->Device->UpdateSize))
|
||||
{
|
||||
plValue[0] = (ALint)flOffset[0];
|
||||
plValue[1] = (ALint)flOffset[1];
|
||||
}
|
||||
else
|
||||
alSetError(AL_INVALID_OPERATION);
|
||||
break;
|
||||
@@ -1184,6 +1222,14 @@ ALAPI ALvoid ALAPIENTRY alGetSourcei(ALuint source, ALenum eParam, ALint *plValu
|
||||
*plValue = pSource->WetGainHFAuto;
|
||||
break;
|
||||
|
||||
case AL_DOPPLER_FACTOR:
|
||||
*plValue = (ALint)pSource->DopplerFactor;
|
||||
break;
|
||||
|
||||
case AL_DISTANCE_MODEL:
|
||||
*plValue = pSource->DistanceModel;
|
||||
break;
|
||||
|
||||
default:
|
||||
alSetError(AL_INVALID_ENUM);
|
||||
break;
|
||||
@@ -1291,12 +1337,14 @@ ALAPI void ALAPIENTRY alGetSourceiv(ALuint source, ALenum eParam, ALint* plValue
|
||||
case AL_BYTE_OFFSET:
|
||||
case AL_MAX_DISTANCE:
|
||||
case AL_ROLLOFF_FACTOR:
|
||||
case AL_DOPPLER_FACTOR:
|
||||
case AL_REFERENCE_DISTANCE:
|
||||
case AL_SOURCE_TYPE:
|
||||
case AL_DIRECT_FILTER:
|
||||
case AL_DIRECT_FILTER_GAINHF_AUTO:
|
||||
case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO:
|
||||
case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO:
|
||||
case AL_DISTANCE_MODEL:
|
||||
alGetSourcei(source, eParam, plValues);
|
||||
break;
|
||||
|
||||
@@ -1351,7 +1399,7 @@ ALAPI ALvoid ALAPIENTRY alSourcePlayv(ALsizei n, const ALuint *pSourceList)
|
||||
ALbufferlistitem *ALBufferList;
|
||||
ALboolean bSourcesValid = AL_TRUE;
|
||||
ALboolean bPlay;
|
||||
ALsizei i;
|
||||
ALsizei i, j;
|
||||
|
||||
pContext = alcGetCurrentContext();
|
||||
if (pContext)
|
||||
@@ -1394,6 +1442,10 @@ ALAPI ALvoid ALAPIENTRY alSourcePlayv(ALsizei n, const ALuint *pSourceList)
|
||||
|
||||
if (bPlay)
|
||||
{
|
||||
for(j = 0;j < OUTPUTCHANNELS;j++)
|
||||
pSource->DryGains[j] = 0.0f;
|
||||
pSource->WetGain = 0.0f;
|
||||
|
||||
if (pSource->state != AL_PAUSED)
|
||||
{
|
||||
pSource->state = AL_PLAYING;
|
||||
@@ -1401,10 +1453,8 @@ ALAPI ALvoid ALAPIENTRY alSourcePlayv(ALsizei n, const ALuint *pSourceList)
|
||||
pSource->play = AL_TRUE;
|
||||
pSource->position = 0;
|
||||
pSource->position_fraction = 0;
|
||||
pSource->BuffersProcessed = 0;
|
||||
pSource->BuffersPlayed = 0;
|
||||
pSource->BufferPosition = 0;
|
||||
pSource->lBytesPlayed = 0;
|
||||
pSource->FirstStart = AL_TRUE;
|
||||
|
||||
pSource->ulBufferID = pSource->queue->buffer;
|
||||
|
||||
@@ -1421,6 +1471,7 @@ ALAPI ALvoid ALAPIENTRY alSourcePlayv(ALsizei n, const ALuint *pSourceList)
|
||||
pSource->state = AL_PLAYING;
|
||||
pSource->inuse = AL_TRUE;
|
||||
pSource->play = AL_TRUE;
|
||||
pSource->FirstStart = AL_FALSE;
|
||||
}
|
||||
|
||||
// Check if an Offset has been set
|
||||
@@ -1437,7 +1488,7 @@ ALAPI ALvoid ALAPIENTRY alSourcePlayv(ALsizei n, const ALuint *pSourceList)
|
||||
ALBufferList = ALBufferList->next;
|
||||
}
|
||||
|
||||
pSource->BuffersPlayed = pSource->BuffersProcessed = pSource->BuffersInQueue;
|
||||
pSource->BuffersPlayed = pSource->BuffersInQueue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1561,7 +1612,7 @@ ALAPI ALvoid ALAPIENTRY alSourceStopv(ALsizei n, const ALuint *sources)
|
||||
{
|
||||
Source->state=AL_STOPPED;
|
||||
Source->inuse=AL_FALSE;
|
||||
Source->BuffersPlayed = Source->BuffersProcessed = Source->BuffersInQueue;
|
||||
Source->BuffersPlayed = Source->BuffersInQueue;
|
||||
ALBufferListItem= Source->queue;
|
||||
while (ALBufferListItem != NULL)
|
||||
{
|
||||
@@ -1633,7 +1684,7 @@ ALAPI ALvoid ALAPIENTRY alSourceRewindv(ALsizei n, const ALuint *sources)
|
||||
Source->inuse=AL_FALSE;
|
||||
Source->position=0;
|
||||
Source->position_fraction=0;
|
||||
Source->BuffersProcessed = 0;
|
||||
Source->BuffersPlayed = 0;
|
||||
ALBufferListItem= Source->queue;
|
||||
while (ALBufferListItem != NULL)
|
||||
{
|
||||
@@ -1906,7 +1957,6 @@ ALAPI ALvoid ALAPIENTRY alSourceUnqueueBuffers( ALuint source, ALsizei n, ALuint
|
||||
// Release memory for buffer list item
|
||||
free(ALBufferList);
|
||||
ALSource->BuffersInQueue--;
|
||||
ALSource->BuffersProcessed--;
|
||||
}
|
||||
|
||||
if (ALSource->state != AL_PLAYING)
|
||||
@@ -1920,10 +1970,7 @@ ALAPI ALvoid ALAPIENTRY alSourceUnqueueBuffers( ALuint source, ALsizei n, ALuint
|
||||
}
|
||||
|
||||
if((ALuint)n > ALSource->BuffersPlayed)
|
||||
{
|
||||
ALSource->BuffersPlayed = 0;
|
||||
ALSource->BufferPosition = 0;
|
||||
}
|
||||
else
|
||||
ALSource->BuffersPlayed -= n;
|
||||
}
|
||||
@@ -1951,7 +1998,7 @@ ALAPI ALvoid ALAPIENTRY alSourceUnqueueBuffers( ALuint source, ALsizei n, ALuint
|
||||
}
|
||||
|
||||
|
||||
static ALvoid InitSourceParams(ALsource *pSource)
|
||||
static ALvoid InitSourceParams(ALCcontext *Context, ALsource *pSource)
|
||||
{
|
||||
pSource->flInnerAngle = 360.0f;
|
||||
pSource->flOuterAngle = 360.0f;
|
||||
@@ -1980,6 +2027,9 @@ static ALvoid InitSourceParams(ALsource *pSource)
|
||||
pSource->WetGainHFAuto = AL_TRUE;
|
||||
pSource->AirAbsorptionFactor = 0.0f;
|
||||
pSource->RoomRolloffFactor = 0.0f;
|
||||
pSource->DopplerFactor = 1.0f;
|
||||
|
||||
pSource->DistanceModel = Context->DistanceModel;
|
||||
|
||||
pSource->state = AL_INITIAL;
|
||||
pSource->lSourceType = AL_UNDETERMINED;
|
||||
@@ -1994,12 +2044,13 @@ static ALvoid InitSourceParams(ALsource *pSource)
|
||||
Gets the current playback position in the given Source, in the appropriate format (Bytes, Samples or MilliSeconds)
|
||||
The offset is relative to the start of the queue (not the start of the current buffer)
|
||||
*/
|
||||
static ALboolean GetSourceOffset(ALsource *pSource, ALenum eName, ALfloat *pflOffset)
|
||||
static ALboolean GetSourceOffset(ALsource *pSource, ALenum eName, ALfloat *pflOffset, ALuint updateSize)
|
||||
{
|
||||
ALbufferlistitem *pBufferList;
|
||||
ALbuffer *pBuffer;
|
||||
ALfloat flBufferFreq;
|
||||
ALint lBytesPlayed, lChannels;
|
||||
ALint lChannels;
|
||||
ALint readPos, writePos;
|
||||
ALenum eOriginalFormat;
|
||||
ALboolean bReturn = AL_TRUE;
|
||||
ALint lTotalBufferDataSize;
|
||||
@@ -2013,15 +2064,20 @@ static ALboolean GetSourceOffset(ALsource *pSource, ALenum eName, ALfloat *pflOf
|
||||
lChannels = aluChannelsFromFormat(pBuffer->format);
|
||||
|
||||
// Get Current BytesPlayed
|
||||
lBytesPlayed = pSource->position * lChannels * 2; // NOTE : This is the byte offset into the *current* buffer
|
||||
readPos = pSource->position * lChannels * 2; // NOTE : This is the byte offset into the *current* buffer
|
||||
// Add byte length of any processed buffers in the queue
|
||||
pBufferList = pSource->queue;
|
||||
while ((pBufferList) && (pBufferList->bufferstate == PROCESSED))
|
||||
{
|
||||
lBytesPlayed += ((ALbuffer*)ALTHUNK_LOOKUPENTRY(pBufferList->buffer))->size;
|
||||
readPos += ((ALbuffer*)ALTHUNK_LOOKUPENTRY(pBufferList->buffer))->size;
|
||||
pBufferList = pBufferList->next;
|
||||
}
|
||||
|
||||
if(pSource->state == AL_PLAYING)
|
||||
writePos = readPos + (updateSize * lChannels * 2);
|
||||
else
|
||||
writePos = readPos;
|
||||
|
||||
lTotalBufferDataSize = 0;
|
||||
pBufferList = pSource->queue;
|
||||
while (pBufferList)
|
||||
@@ -2033,64 +2089,88 @@ static ALboolean GetSourceOffset(ALsource *pSource, ALenum eName, ALfloat *pflOf
|
||||
|
||||
if (pSource->bLooping)
|
||||
{
|
||||
if (lBytesPlayed < 0)
|
||||
lBytesPlayed = 0;
|
||||
if(readPos < 0)
|
||||
readPos = 0;
|
||||
else
|
||||
lBytesPlayed = lBytesPlayed % lTotalBufferDataSize;
|
||||
readPos %= lTotalBufferDataSize;
|
||||
if(writePos < 0)
|
||||
writePos = 0;
|
||||
else
|
||||
writePos %= lTotalBufferDataSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Clamp BytesPlayed to within 0 and lTotalBufferDataSize
|
||||
if(lBytesPlayed < 0)
|
||||
lBytesPlayed = 0;
|
||||
if(lBytesPlayed > lTotalBufferDataSize)
|
||||
lBytesPlayed = lTotalBufferDataSize;
|
||||
if(readPos < 0)
|
||||
readPos = 0;
|
||||
else if(readPos > lTotalBufferDataSize)
|
||||
readPos = lTotalBufferDataSize;
|
||||
if(writePos < 0)
|
||||
writePos = 0;
|
||||
else if(writePos > lTotalBufferDataSize)
|
||||
writePos = lTotalBufferDataSize;
|
||||
}
|
||||
|
||||
switch (eName)
|
||||
{
|
||||
case AL_SEC_OFFSET:
|
||||
*pflOffset = ((ALfloat)lBytesPlayed / (lChannels * 2.0f * flBufferFreq));
|
||||
case AL_SEC_RW_OFFSETS_EXT:
|
||||
pflOffset[0] = (ALfloat)readPos / (lChannels * 2.0f * flBufferFreq);
|
||||
pflOffset[1] = (ALfloat)writePos / (lChannels * 2.0f * flBufferFreq);
|
||||
break;
|
||||
case AL_SAMPLE_OFFSET:
|
||||
*pflOffset = (ALfloat)(lBytesPlayed / (lChannels * 2));
|
||||
case AL_SAMPLE_RW_OFFSETS_EXT:
|
||||
pflOffset[0] = (ALfloat)(readPos / (lChannels * 2));
|
||||
pflOffset[1] = (ALfloat)(writePos / (lChannels * 2));
|
||||
break;
|
||||
case AL_BYTE_OFFSET:
|
||||
case AL_BYTE_RW_OFFSETS_EXT:
|
||||
// Take into account the original format of the Buffer
|
||||
if ((eOriginalFormat == AL_FORMAT_MONO_IMA4) ||
|
||||
(eOriginalFormat == AL_FORMAT_STEREO_IMA4))
|
||||
{
|
||||
// Compression rate of the ADPCM supported is 3.6111 to 1
|
||||
lBytesPlayed = (ALint)((ALfloat)lBytesPlayed / 3.6111f);
|
||||
// Round down to nearest ADPCM block
|
||||
*pflOffset = (ALfloat)((lBytesPlayed / (36 * lChannels)) * 36 * lChannels);
|
||||
pflOffset[0] = (ALfloat)((readPos / (65 * 2 * lChannels)) * 36 * lChannels);
|
||||
if(pSource->state == AL_PLAYING)
|
||||
{
|
||||
// Round up to nearest ADPCM block
|
||||
pflOffset[1] = (ALfloat)(((writePos + (65 * 2 * lChannels) - 1) / (65 * 2 * lChannels)) * 36 * lChannels);
|
||||
}
|
||||
else
|
||||
pflOffset[1] = pflOffset[0];
|
||||
}
|
||||
else if (eOriginalFormat == AL_FORMAT_REAR8)
|
||||
{
|
||||
*pflOffset = (ALfloat)(lBytesPlayed >> 2);
|
||||
pflOffset[0] = (ALfloat)(readPos >> 2);
|
||||
pflOffset[1] = (ALfloat)(writePos >> 2);
|
||||
}
|
||||
else if (eOriginalFormat == AL_FORMAT_REAR16)
|
||||
{
|
||||
*pflOffset = (ALfloat)(lBytesPlayed >> 1);
|
||||
pflOffset[0] = (ALfloat)(readPos >> 1);
|
||||
pflOffset[1] = (ALfloat)(writePos >> 1);
|
||||
}
|
||||
else if (aluBytesFromFormat(eOriginalFormat) == 1)
|
||||
{
|
||||
*pflOffset = (ALfloat)(lBytesPlayed >> 1);
|
||||
pflOffset[0] = (ALfloat)(readPos >> 1);
|
||||
pflOffset[1] = (ALfloat)(writePos >> 1);
|
||||
}
|
||||
else if (aluBytesFromFormat(eOriginalFormat) == 4)
|
||||
{
|
||||
*pflOffset = (ALfloat)(lBytesPlayed << 1);
|
||||
pflOffset[0] = (ALfloat)(readPos << 1);
|
||||
pflOffset[1] = (ALfloat)(writePos << 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
*pflOffset = (ALfloat)lBytesPlayed;
|
||||
pflOffset[0] = (ALfloat)readPos;
|
||||
pflOffset[1] = (ALfloat)writePos;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*pflOffset = 0.0f;
|
||||
pflOffset[0] = 0.0f;
|
||||
pflOffset[1] = 0.0f;
|
||||
}
|
||||
|
||||
return bReturn;
|
||||
@@ -2120,7 +2200,6 @@ static void ApplyOffset(ALsource *pSource, ALboolean bUpdateContext)
|
||||
pBufferList = pSource->queue;
|
||||
lTotalBufferSize = 0;
|
||||
pSource->BuffersPlayed = 0;
|
||||
pSource->BuffersProcessed = 0;
|
||||
while (pBufferList)
|
||||
{
|
||||
pBuffer = ALTHUNK_LOOKUPENTRY(pBufferList->buffer);
|
||||
@@ -2133,10 +2212,7 @@ static void ApplyOffset(ALsource *pSource, ALboolean bUpdateContext)
|
||||
pSource->BuffersPlayed++;
|
||||
|
||||
if (!pSource->bLooping)
|
||||
{
|
||||
pBufferList->bufferstate = PROCESSED;
|
||||
pSource->BuffersProcessed++;
|
||||
}
|
||||
}
|
||||
else if (lTotalBufferSize <= lByteOffset)
|
||||
{
|
||||
@@ -2146,14 +2222,8 @@ static void ApplyOffset(ALsource *pSource, ALboolean bUpdateContext)
|
||||
// Set Current Buffer ID
|
||||
pSource->ulBufferID = pBufferList->buffer;
|
||||
|
||||
// Set current position in this buffer
|
||||
pSource->BufferPosition = lByteOffset - lTotalBufferSize;
|
||||
|
||||
// Set Total Bytes Played to Offset
|
||||
pSource->lBytesPlayed = lByteOffset;
|
||||
|
||||
// SW Mixer Positions are in Samples
|
||||
pSource->position = pSource->BufferPosition /
|
||||
pSource->position = (lByteOffset - lTotalBufferSize) /
|
||||
aluBytesFromFormat(pBuffer->format) /
|
||||
aluChannelsFromFormat(pBuffer->format);
|
||||
}
|
||||
@@ -2288,7 +2358,7 @@ ALvoid ReleaseALSources(ALCcontext *Context)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if(Context->SourceCount > 0)
|
||||
AL_PRINT("alcDestroyContext(): %d Source(s) NOT deleted\n", Context->SourceCount);
|
||||
AL_PRINT("alcDestroyContext(): deleting %d Source(s)\n", Context->SourceCount);
|
||||
#endif
|
||||
|
||||
while(Context->Source)
|
||||
|
||||
+5
-1
@@ -24,10 +24,11 @@
|
||||
#include "alMain.h"
|
||||
#include "AL/alc.h"
|
||||
#include "alError.h"
|
||||
#include "alSource.h"
|
||||
#include "alState.h"
|
||||
|
||||
static const ALchar alVendor[] = "OpenAL Community";
|
||||
static const ALchar alVersion[] = "1.1";
|
||||
static const ALchar alVersion[] = "1.1 ALSOFT "ALSOFT_VERSION;
|
||||
static const ALchar alRenderer[] = "OpenAL Soft";
|
||||
|
||||
// Error Messages
|
||||
@@ -644,6 +645,7 @@ ALAPI ALvoid ALAPIENTRY alSpeedOfSound(ALfloat flSpeedOfSound)
|
||||
ALAPI ALvoid ALAPIENTRY alDistanceModel(ALenum value)
|
||||
{
|
||||
ALCcontext *Context;
|
||||
ALsource *Source;
|
||||
|
||||
Context=alcGetCurrentContext();
|
||||
if (Context)
|
||||
@@ -660,6 +662,8 @@ ALAPI ALvoid ALAPIENTRY alDistanceModel(ALenum value)
|
||||
case AL_EXPONENT_DISTANCE:
|
||||
case AL_EXPONENT_DISTANCE_CLAMPED:
|
||||
Context->DistanceModel = value;
|
||||
for(Source = Context->Source;Source != NULL;Source = Source->next)
|
||||
Source->DistanceModel = value;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
# Cross-compiling requires CMake 2.6 or newer. To cross-compile, first modify
|
||||
# this file to set the proper settings and paths. Then use it from CMakeConf/
|
||||
# like:
|
||||
# cmake .. -DCMAKE_TOOLCHAIN_FILE=../XCompile.txt \
|
||||
# -DCMAKE_INSTALL_PREFIX=/usr/mingw32/mingw
|
||||
# If you already have a toolchain file setup, you may use that instead of this
|
||||
# file.
|
||||
|
||||
# the name of the target operating system
|
||||
SET(CMAKE_SYSTEM_NAME Windows)
|
||||
|
||||
# which compilers to use for C and C++
|
||||
SET(CMAKE_C_COMPILER mingw32-gcc)
|
||||
SET(CMAKE_CXX_COMPILER mingw32-g++)
|
||||
|
||||
# here is the target environment located
|
||||
SET(CMAKE_FIND_ROOT_PATH /usr/mingw32/mingw)
|
||||
|
||||
# adjust the default behaviour of the FIND_XXX() commands:
|
||||
# search headers and libraries in the target environment, search
|
||||
# programs in the host environment
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
@@ -0,0 +1,11 @@
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
libdir=@libdir@
|
||||
includedir=@includedir@
|
||||
|
||||
Name: OpenAL
|
||||
Description: OpenAL is a cross-platform 3D audio API
|
||||
Requires: @PKG_CONFIG_REQUIRES@
|
||||
Version: @PACKAGE_VERSION@
|
||||
Libs: -L${libdir} -l@LIBNAME@ @PKG_CONFIG_LIBS@
|
||||
Cflags: -I${includedir}
|
||||
+66
-3
@@ -4,6 +4,9 @@
|
||||
# specified.
|
||||
# The system-wide settings can be put in /etc/openal/alsoft.conf and user-
|
||||
# specific override settings in ~/.alsoftrc.
|
||||
# For Windows, these settings should go into %AppData%\alsoft.ini
|
||||
# The environment variable ALSOFT_CONF can be used to specify another config
|
||||
# override
|
||||
|
||||
# Option and block names are case-insenstive. The supplied values are only
|
||||
# hints and may not be honored (though generally it'll try to get as close as
|
||||
@@ -37,18 +40,68 @@ cf_level = 0 # Sets the crossfeed level for stereo output. Valid values are:
|
||||
|
||||
frequency = 44100 # Sets the output frequency. Default is 44100
|
||||
|
||||
refresh = 8192 # Sets the buffer size, in frames. Default is 8192. Note that
|
||||
refresh = 4096 # Sets the buffer size, in frames. Default is 4096. Note that
|
||||
# the actual granularity may or may not be less than this.
|
||||
|
||||
sources = 256 # Sets the maximum number of allocatable sources. Lower values
|
||||
# may help for systems with apps that try to play more sounds
|
||||
# than the CPU can handle. Default is 256
|
||||
|
||||
stereodup = # Sets whether to duplicate stereo sounds on the rear and side
|
||||
# speakers for 4+ channel output. This can make stereo sources
|
||||
# substantially louder than mono or even 4+ channel sources, but
|
||||
# provides a "fuller" playback quality. True, yes, on, and non-0
|
||||
# values will duplicate stereo sources. 0 and anything else will
|
||||
# cause stereo sounds to only play out the front speakers.
|
||||
# Default is false
|
||||
|
||||
drivers = # Sets the backend driver list order, comma-seperated. Unknown
|
||||
# backends and duplicated names are ignored, and unlisted backends
|
||||
# won't be considered for use. An empty list means the default.
|
||||
# Default is:
|
||||
# alsa,oss,dsound,winmm,wave
|
||||
# alsa,oss,solaris,dsound,winmm,port,wave
|
||||
|
||||
excludefx = # Sets which effects to exclude, preventing apps from using them.
|
||||
# This can help for apps that try to use effects which are too CPU
|
||||
# intensive for the system to handle. Available effects are:
|
||||
# reverb
|
||||
# Default is empty (all available effects enabled)
|
||||
|
||||
layout_STEREO = # Sets the speaker layout when using stereo output. Values are
|
||||
specified in degrees, where 0 is straight in front, negative
|
||||
goes left, and positive goes right. The values must define a
|
||||
circular pattern, starting with the back-left at the most
|
||||
negative, around the front to back-center. Unspecified
|
||||
speakers will remain at their default position. Available
|
||||
speakers are front-left(fl) and front-right(fr).
|
||||
The default is:
|
||||
fl=-90, fr=90
|
||||
|
||||
layout_QUAD = # Sets the speaker layout when using quadriphonic output.
|
||||
Available speakers are back-left(bl), front-left(fl),
|
||||
front-right(fr), and back-right(br).
|
||||
The default is:
|
||||
bl=-135, fl=-45, fr=45, br=135
|
||||
|
||||
layout_51CHN = # Sets the speaker layout when using 5.1 output. Available
|
||||
speakers are back-left(bl), front-left(fl), front-center(fc),
|
||||
front-right(fr), and back-right(br).
|
||||
The default is:
|
||||
bl=-110, fl=-30, fc=0, fr=30, br=110
|
||||
|
||||
layout_61CHN = # Sets the speaker layout when using 6.1 output. Available
|
||||
speakers are side-left(sl), front-left(fl), front-center(fc),
|
||||
front-right(fr), side-right(sr), and back-center(bc).
|
||||
The default is:
|
||||
sl=-90, fl=-30, fc=0, fr=30, sr=90, bc=180
|
||||
|
||||
layout_71CHN = # Sets the speaker layout when using 7.1 output. Available
|
||||
speakers are back-left(bl), side-left(sl), front-left(fl),
|
||||
front-center(fc), front-right(fr), side-right(sr), and
|
||||
back-right(br).
|
||||
The default is:
|
||||
bl=-150, sl=-90, fl=-30, fc=0, fr=30, sr=90 br=150
|
||||
|
||||
|
||||
[alsa] # ALSA backend stuff
|
||||
device = default # Sets the device name for the default playback device.
|
||||
@@ -73,12 +126,22 @@ periods = 4 # Sets the number of update buffers. Default is 4
|
||||
|
||||
capture = /dev/dsp # Sets the device name for OSS capture. Default is /dev/dsp
|
||||
|
||||
[solaris] # Solaris backend stuff
|
||||
device = /dev/audio # Sets the device name for Solaris output. Default is
|
||||
# /dev/audio
|
||||
|
||||
[dsound] # DirectSound backend stuff
|
||||
# Nothing yet...
|
||||
periods = 4 # Sets the number of updates for the output buffer. Default is 4
|
||||
|
||||
[winmm] # Windows Multimedia backend stuff
|
||||
# Nothing yet...
|
||||
|
||||
[port] # PortAudio backend stuff
|
||||
device = -1 # Sets the device index for output. Negative values will use the
|
||||
# default as given by PortAudio itself. Default is -1
|
||||
|
||||
periods = 4 # Sets the number of update buffers. Default is 4
|
||||
|
||||
[wave] # Wave File Writer stuff
|
||||
file = # Sets the filename of the wave file to write to. An empty name
|
||||
# prevents the backend from opening, even when explicitly requested.
|
||||
|
||||
+30
@@ -1,18 +1,27 @@
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
/* Define to the library version */
|
||||
#define ALSOFT_VERSION "${LIB_VERSION}"
|
||||
|
||||
/* Define if we have the ALSA backend */
|
||||
#cmakedefine HAVE_ALSA
|
||||
|
||||
/* Define if we have the OSS backend */
|
||||
#cmakedefine HAVE_OSS
|
||||
|
||||
/* Define if we have the Solaris backend */
|
||||
#cmakedefine HAVE_SOLARIS
|
||||
|
||||
/* Define if we have the DSound backend */
|
||||
#cmakedefine HAVE_DSOUND
|
||||
|
||||
/* Define if we have the Windows Multimedia backend */
|
||||
#cmakedefine HAVE_WINMM
|
||||
|
||||
/* Define if we have the PortAudio backend */
|
||||
#cmakedefine HAVE_PORTAUDIO
|
||||
|
||||
/* Define if we have dlfcn.h */
|
||||
#cmakedefine HAVE_DLFCN_H
|
||||
|
||||
@@ -22,6 +31,12 @@
|
||||
/* Define if we have the acosf function */
|
||||
#cmakedefine HAVE_ACOSF
|
||||
|
||||
/* Define if we have the atanf function */
|
||||
#cmakedefine HAVE_ATANF
|
||||
|
||||
/* Define if we have the fabsf function */
|
||||
#cmakedefine HAVE_FABSF
|
||||
|
||||
/* Define if we have the strtof function */
|
||||
#cmakedefine HAVE_STRTOF
|
||||
|
||||
@@ -46,4 +61,19 @@
|
||||
/* Define if we have GCC's destructor attribute */
|
||||
#cmakedefine HAVE_GCC_DESTRUCTOR
|
||||
|
||||
/* Define if we have pthread_np.h */
|
||||
#cmakedefine HAVE_PTHREAD_NP_H
|
||||
|
||||
/* Define if we have float.h */
|
||||
#cmakedefine HAVE_FLOAT_H
|
||||
|
||||
/* Define if we have fenv.h */
|
||||
#cmakedefine HAVE_FENV_H
|
||||
|
||||
/* Define if we have fesetround() */
|
||||
#cmakedefine HAVE_FESETROUND
|
||||
|
||||
/* Define if we have _controlfp() */
|
||||
#cmakedefine HAVE__CONTROLFP
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,294 @@
|
||||
/*
|
||||
* openal-info: Display information about ALC and AL.
|
||||
*
|
||||
* Idea based on glxinfo for OpenGL.
|
||||
* Initial OpenAL version by Erik Hofman <erik@ehofman.com>.
|
||||
* Further hacked by Sven Panne <sven.panne@aedion.de>.
|
||||
* More work (clean up) by Chris Robinson <chris.kcat@gmail.com>.
|
||||
*
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "AL/alc.h"
|
||||
#include "AL/al.h"
|
||||
#include "AL/alext.h"
|
||||
|
||||
#ifndef ALC_EXT_EFX
|
||||
#define AL_FILTER_TYPE 0x8001
|
||||
#define AL_EFFECT_TYPE 0x8001
|
||||
#define AL_FILTER_NULL 0x0000
|
||||
#define AL_FILTER_LOWPASS 0x0001
|
||||
#define AL_FILTER_HIGHPASS 0x0002
|
||||
#define AL_FILTER_BANDPASS 0x0003
|
||||
#define AL_EFFECT_NULL 0x0000
|
||||
#define AL_EFFECT_EAXREVERB 0x8000
|
||||
#define AL_EFFECT_REVERB 0x0001
|
||||
#define AL_EFFECT_CHORUS 0x0002
|
||||
#define AL_EFFECT_DISTORTION 0x0003
|
||||
#define AL_EFFECT_ECHO 0x0004
|
||||
#define AL_EFFECT_FLANGER 0x0005
|
||||
#define AL_EFFECT_FREQUENCY_SHIFTER 0x0006
|
||||
#define AL_EFFECT_VOCAL_MORPHER 0x0007
|
||||
#define AL_EFFECT_PITCH_SHIFTER 0x0008
|
||||
#define AL_EFFECT_RING_MODULATOR 0x0009
|
||||
#define AL_EFFECT_AUTOWAH 0x000A
|
||||
#define AL_EFFECT_COMPRESSOR 0x000B
|
||||
#define AL_EFFECT_EQUALIZER 0x000C
|
||||
#define ALC_EFX_MAJOR_VERSION 0x20001
|
||||
#define ALC_EFX_MINOR_VERSION 0x20002
|
||||
#define ALC_MAX_AUXILIARY_SENDS 0x20003
|
||||
#endif
|
||||
ALvoid (AL_APIENTRY *p_alGenFilters)(ALsizei,ALuint*);
|
||||
ALvoid (AL_APIENTRY *p_alDeleteFilters)(ALsizei,ALuint*);
|
||||
ALvoid (AL_APIENTRY *p_alFilteri)(ALuint,ALenum,ALint);
|
||||
ALvoid (AL_APIENTRY *p_alGenEffects)(ALsizei,ALuint*);
|
||||
ALvoid (AL_APIENTRY *p_alDeleteEffects)(ALsizei,ALuint*);
|
||||
ALvoid (AL_APIENTRY *p_alEffecti)(ALuint,ALenum,ALint);
|
||||
|
||||
static const int indentation = 4;
|
||||
static const int maxmimumWidth = 79;
|
||||
|
||||
static void printChar(int c, int *width)
|
||||
{
|
||||
putchar(c);
|
||||
*width = ((c == '\n') ? 0 : ((*width) + 1));
|
||||
}
|
||||
|
||||
static void indent(int *width)
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < indentation; i++)
|
||||
printChar(' ', width);
|
||||
}
|
||||
|
||||
static void printExtensions(const char *header, char separator, const char *extensions)
|
||||
{
|
||||
int width = 0, start = 0, end = 0;
|
||||
|
||||
printf("%s:\n", header);
|
||||
if(extensions == NULL || extensions[0] == '\0')
|
||||
return;
|
||||
|
||||
indent(&width);
|
||||
while (1)
|
||||
{
|
||||
if(extensions[end] == separator || extensions[end] == '\0')
|
||||
{
|
||||
if(width + end - start + 2 > maxmimumWidth)
|
||||
{
|
||||
printChar('\n', &width);
|
||||
indent(&width);
|
||||
}
|
||||
while(start < end)
|
||||
{
|
||||
printChar(extensions[start], &width);
|
||||
start++;
|
||||
}
|
||||
if(extensions[end] == '\0')
|
||||
break;
|
||||
start++;
|
||||
end++;
|
||||
if(extensions[end] == '\0')
|
||||
break;
|
||||
printChar(',', &width);
|
||||
printChar(' ', &width);
|
||||
}
|
||||
end++;
|
||||
}
|
||||
printChar('\n', &width);
|
||||
}
|
||||
|
||||
static void die(const char *kind, const char *description)
|
||||
{
|
||||
fprintf(stderr, "%s error %s occured\n", kind, description);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static void checkForErrors(void)
|
||||
{
|
||||
{
|
||||
ALCdevice *device = alcGetContextsDevice(alcGetCurrentContext());
|
||||
ALCenum error = alcGetError(device);
|
||||
if(error != ALC_NO_ERROR)
|
||||
die("ALC", (const char*)alcGetString(device, error));
|
||||
}
|
||||
{
|
||||
ALenum error = alGetError();
|
||||
if(error != AL_NO_ERROR)
|
||||
die("AL", (const char*)alGetString(error));
|
||||
}
|
||||
}
|
||||
|
||||
static void printDevices(ALCenum which, const char *kind)
|
||||
{
|
||||
const char *s = alcGetString(NULL, which);
|
||||
checkForErrors();
|
||||
|
||||
printf("Available %sdevices:\n", kind);
|
||||
while(*s != '\0')
|
||||
{
|
||||
printf(" %s\n", s);
|
||||
while(*s++ != '\0')
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
static void printALCInfo (void)
|
||||
{
|
||||
ALCint major, minor;
|
||||
ALCdevice *device;
|
||||
|
||||
if(alcIsExtensionPresent(NULL, (const ALCchar*)"ALC_ENUMERATION_EXT") == AL_TRUE)
|
||||
{
|
||||
if(alcIsExtensionPresent(NULL, (const ALCchar*)"ALC_ENUMERATE_ALL_EXT") == AL_TRUE)
|
||||
printDevices(ALC_ALL_DEVICES_SPECIFIER, "playback ");
|
||||
else
|
||||
printDevices(ALC_DEVICE_SPECIFIER, "playback ");
|
||||
printDevices(ALC_CAPTURE_DEVICE_SPECIFIER, "capture ");
|
||||
}
|
||||
else
|
||||
printf("No device enumeration available\n");
|
||||
|
||||
device = alcGetContextsDevice(alcGetCurrentContext());
|
||||
checkForErrors();
|
||||
|
||||
printf("Default device: %s\n",
|
||||
alcGetString(device, ALC_DEFAULT_DEVICE_SPECIFIER));
|
||||
|
||||
printf("Default capture device: %s\n",
|
||||
alcGetString(device, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER));
|
||||
|
||||
alcGetIntegerv(device, ALC_MAJOR_VERSION, 1, &major);
|
||||
alcGetIntegerv(device, ALC_MINOR_VERSION, 1, &minor);
|
||||
checkForErrors();
|
||||
printf("ALC version: %d.%d\n", (int)major, (int)minor);
|
||||
|
||||
printExtensions("ALC extensions", ' ',
|
||||
alcGetString(device, ALC_EXTENSIONS));
|
||||
checkForErrors();
|
||||
}
|
||||
|
||||
static void printALInfo(void)
|
||||
{
|
||||
printf("OpenAL vendor string: %s\n", alGetString(AL_VENDOR));
|
||||
printf("OpenAL renderer string: %s\n", alGetString(AL_RENDERER));
|
||||
printf("OpenAL version string: %s\n", alGetString(AL_VERSION));
|
||||
printExtensions("OpenAL extensions", ' ', alGetString(AL_EXTENSIONS));
|
||||
checkForErrors();
|
||||
}
|
||||
|
||||
static void printEFXInfo(void)
|
||||
{
|
||||
ALCint major, minor, sends;
|
||||
ALCdevice *device;
|
||||
ALuint obj;
|
||||
int i;
|
||||
const struct {
|
||||
ALenum type;
|
||||
const char *name;
|
||||
} effects[] = {
|
||||
{ AL_EFFECT_EAXREVERB, "EAX Reverb" },
|
||||
{ AL_EFFECT_REVERB, "Standard Reverb" },
|
||||
{ AL_EFFECT_CHORUS, "Chorus" },
|
||||
{ AL_EFFECT_DISTORTION, "Distortion" },
|
||||
{ AL_EFFECT_ECHO, "Echo" },
|
||||
{ AL_EFFECT_FLANGER, "Flanger" },
|
||||
{ AL_EFFECT_FREQUENCY_SHIFTER, "Frequency Shifter" },
|
||||
{ AL_EFFECT_VOCAL_MORPHER, "Vocal Morpher" },
|
||||
{ AL_EFFECT_PITCH_SHIFTER, "Pitch Shifter" },
|
||||
{ AL_EFFECT_RING_MODULATOR, "Ring Modulator" },
|
||||
{ AL_EFFECT_AUTOWAH, "Autowah" },
|
||||
{ AL_EFFECT_COMPRESSOR, "Compressor" },
|
||||
{ AL_EFFECT_EQUALIZER, "Equalizer" },
|
||||
{ AL_EFFECT_NULL, NULL }
|
||||
};
|
||||
const struct {
|
||||
ALenum type;
|
||||
const char *name;
|
||||
} filters[] = {
|
||||
{ AL_FILTER_LOWPASS, "Low-pass" },
|
||||
{ AL_FILTER_HIGHPASS, "High-pass" },
|
||||
{ AL_FILTER_BANDPASS, "Band-pass" },
|
||||
{ AL_FILTER_NULL, NULL }
|
||||
};
|
||||
|
||||
device = alcGetContextsDevice(alcGetCurrentContext());
|
||||
|
||||
if(alcIsExtensionPresent(device, (const ALCchar*)"ALC_EXT_EFX") == AL_FALSE)
|
||||
{
|
||||
printf("EFX not available\n");
|
||||
return;
|
||||
}
|
||||
|
||||
alcGetIntegerv(device, ALC_EFX_MAJOR_VERSION, 1, &major);
|
||||
alcGetIntegerv(device, ALC_EFX_MINOR_VERSION, 1, &minor);
|
||||
checkForErrors();
|
||||
printf("EFX version: %d.%d\n", (int)major, (int)minor);
|
||||
|
||||
alcGetIntegerv(device, ALC_MAX_AUXILIARY_SENDS, 1, &sends);
|
||||
checkForErrors();
|
||||
printf("Max auxiliary sends: %d\n", (int)sends);
|
||||
|
||||
p_alGenFilters = alGetProcAddress("alGenFilters");
|
||||
p_alDeleteFilters = alGetProcAddress("alDeleteFilters");
|
||||
p_alFilteri = alGetProcAddress("alFilteri");
|
||||
p_alGenEffects = alGetProcAddress("alGenEffects");
|
||||
p_alDeleteEffects = alGetProcAddress("alDeleteEffects");
|
||||
p_alEffecti = alGetProcAddress("alEffecti");
|
||||
checkForErrors();
|
||||
if(!p_alGenEffects || !p_alDeleteEffects || !p_alEffecti ||
|
||||
!p_alGenFilters || !p_alDeleteFilters || !p_alFilteri)
|
||||
{
|
||||
printf("Missing EFX functions!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
p_alGenFilters(1, &obj);
|
||||
checkForErrors();
|
||||
printf("Available filters:\n");
|
||||
for(i = 0;filters[i].type != AL_FILTER_NULL;i++)
|
||||
{
|
||||
p_alFilteri(obj, AL_FILTER_TYPE, filters[i].type);
|
||||
if(alGetError() == AL_NO_ERROR)
|
||||
printf(" %s\n", filters[i].name);
|
||||
}
|
||||
p_alDeleteFilters(1, &obj);
|
||||
checkForErrors();
|
||||
|
||||
p_alGenEffects(1, &obj);
|
||||
checkForErrors();
|
||||
printf("Available effects:\n");
|
||||
for(i = 0;effects[i].type != AL_EFFECT_NULL;i++)
|
||||
{
|
||||
p_alEffecti(obj, AL_EFFECT_TYPE, effects[i].type);
|
||||
if(alGetError() == AL_NO_ERROR)
|
||||
printf(" %s\n", effects[i].name);
|
||||
}
|
||||
p_alDeleteEffects(1, &obj);
|
||||
checkForErrors();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ALCdevice *device = alcOpenDevice(NULL);
|
||||
ALCcontext *context = alcCreateContext(device, NULL);
|
||||
alcMakeContextCurrent(context);
|
||||
checkForErrors();
|
||||
|
||||
printALCInfo();
|
||||
printALInfo();
|
||||
printEFXInfo();
|
||||
checkForErrors();
|
||||
|
||||
alcMakeContextCurrent(NULL);
|
||||
alcDestroyContext(context);
|
||||
alcCloseDevice(device);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -166,11 +166,6 @@ typedef void ALCvoid;
|
||||
#define ALC_ATTRIBUTES_SIZE 0x1002
|
||||
#define ALC_ALL_ATTRIBUTES 0x1003
|
||||
|
||||
/**
|
||||
* ALC_ENUMERATE_ALL_EXT enums
|
||||
*/
|
||||
#define ALC_DEFAULT_ALL_DEVICES_SPECIFIER 0x1012
|
||||
#define ALC_ALL_DEVICES_SPECIFIER 0x1013
|
||||
|
||||
/**
|
||||
* Capture extension
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
/**
|
||||
* OpenAL cross platform audio library
|
||||
* Copyright (C) 2008 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
|
||||
*/
|
||||
|
||||
#ifndef AL_ALEXT_H
|
||||
#define AL_ALEXT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef AL_LOKI_IMA_ADPCM_format
|
||||
#define AL_LOKI_IMA_ADPCM_format 1
|
||||
#define AL_FORMAT_IMA_ADPCM_MONO16_EXT 0x10000
|
||||
#define AL_FORMAT_IMA_ADPCM_STEREO16_EXT 0x10001
|
||||
#endif
|
||||
|
||||
#ifndef AL_LOKI_WAVE_format
|
||||
#define AL_LOKI_WAVE_format 1
|
||||
#define AL_FORMAT_WAVE_EXT 0x10002
|
||||
#endif
|
||||
|
||||
#ifndef AL_EXT_vorbis
|
||||
#define AL_EXT_vorbis 1
|
||||
#define AL_FORMAT_VORBIS_EXT 0x10003
|
||||
#endif
|
||||
|
||||
#ifndef AL_LOKI_quadriphonic
|
||||
#define AL_LOKI_quadriphonic 1
|
||||
#define AL_FORMAT_QUAD8_LOKI 0x10004
|
||||
#define AL_FORMAT_QUAD16_LOKI 0x10005
|
||||
#endif
|
||||
|
||||
#ifndef AL_EXT_float32
|
||||
#define AL_EXT_float32 1
|
||||
#define AL_FORMAT_MONO_FLOAT32 0x10010
|
||||
#define AL_FORMAT_STEREO_FLOAT32 0x10011
|
||||
#endif
|
||||
|
||||
#ifndef ALC_LOKI_audio_channel
|
||||
#define ALC_LOKI_audio_channel 1
|
||||
#define ALC_CHAN_MAIN_LOKI 0x500001
|
||||
#define ALC_CHAN_PCM_LOKI 0x500002
|
||||
#define ALC_CHAN_CD_LOKI 0x500003
|
||||
#endif
|
||||
|
||||
#ifndef ALC_ENUMERATE_ALL_EXT
|
||||
#define ALC_ENUMERATE_ALL_EXT 1
|
||||
#define ALC_DEFAULT_ALL_DEVICES_SPECIFIER 0x1012
|
||||
#define ALC_ALL_DEVICES_SPECIFIER 0x1013
|
||||
#endif
|
||||
|
||||
#ifndef AL_EXT_MCFORMATS
|
||||
#define AL_EXT_MCFORMATS 1
|
||||
#define AL_FORMAT_QUAD8 0x1204
|
||||
#define AL_FORMAT_QUAD16 0x1205
|
||||
#define AL_FORMAT_QUAD32 0x1206
|
||||
#define AL_FORMAT_REAR8 0x1207
|
||||
#define AL_FORMAT_REAR16 0x1208
|
||||
#define AL_FORMAT_REAR32 0x1209
|
||||
#define AL_FORMAT_51CHN8 0x120A
|
||||
#define AL_FORMAT_51CHN16 0x120B
|
||||
#define AL_FORMAT_51CHN32 0x120C
|
||||
#define AL_FORMAT_61CHN8 0x120D
|
||||
#define AL_FORMAT_61CHN16 0x120E
|
||||
#define AL_FORMAT_61CHN32 0x120F
|
||||
#define AL_FORMAT_71CHN8 0x1210
|
||||
#define AL_FORMAT_71CHN16 0x1211
|
||||
#define AL_FORMAT_71CHN32 0x1212
|
||||
#endif
|
||||
|
||||
#ifndef AL_EXT_IMA4
|
||||
#define AL_EXT_IMA4 1
|
||||
#define AL_FORMAT_MONO_IMA4 0x1300
|
||||
#define AL_FORMAT_STEREO_IMA4 0x1301
|
||||
#endif
|
||||
|
||||
#ifndef AL_EXT_buffer_sub_data
|
||||
#define AL_EXT_buffer_sub_data 1
|
||||
#define AL_BYTE_RW_OFFSETS_EXT 0x1031
|
||||
#define AL_SAMPLE_RW_OFFSETS_EXT 0x1032
|
||||
#define AL_SEC_RW_OFFSETS_EXT 0x1033
|
||||
typedef ALvoid (AL_APIENTRY*PFNALBUFFERSUBDATAEXTPROC)(ALuint,ALenum,const ALvoid*,ALsizei,ALsizei);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user