2005-11-13 18:58:14 +00:00
|
|
|
/*
|
|
|
|
===========================================================================
|
|
|
|
Copyright (C) 1999-2005 Id Software, Inc.
|
|
|
|
Copyright (C) 2005 Stuart Dalton (badcdev@gmail.com)
|
|
|
|
|
|
|
|
This file is part of Quake III Arena source code.
|
|
|
|
|
|
|
|
Quake III Arena source code is free software; you can redistribute it
|
|
|
|
and/or modify it under the terms of the GNU General Public License as
|
|
|
|
published by the Free Software Foundation; either version 2 of the License,
|
|
|
|
or (at your option) any later version.
|
|
|
|
|
|
|
|
Quake III Arena source code 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 General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Quake III Arena source code; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
===========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "snd_local.h"
|
|
|
|
#include "snd_codec.h"
|
|
|
|
#include "client.h"
|
|
|
|
|
2007-09-22 20:32:11 +00:00
|
|
|
#ifdef USE_OPENAL
|
2005-11-13 18:58:14 +00:00
|
|
|
|
|
|
|
#include "qal.h"
|
|
|
|
|
|
|
|
// Console variables specific to OpenAL
|
|
|
|
cvar_t *s_alPrecache;
|
|
|
|
cvar_t *s_alGain;
|
|
|
|
cvar_t *s_alSources;
|
|
|
|
cvar_t *s_alDopplerFactor;
|
|
|
|
cvar_t *s_alDopplerSpeed;
|
|
|
|
cvar_t *s_alMinDistance;
|
2006-11-03 08:22:38 +00:00
|
|
|
cvar_t *s_alMaxDistance;
|
2005-11-13 18:58:14 +00:00
|
|
|
cvar_t *s_alRolloff;
|
2006-11-03 08:22:38 +00:00
|
|
|
cvar_t *s_alGraceDistance;
|
2005-11-13 18:58:14 +00:00
|
|
|
cvar_t *s_alDriver;
|
2006-08-19 11:02:20 +00:00
|
|
|
cvar_t *s_alDevice;
|
2011-03-08 01:39:34 +00:00
|
|
|
cvar_t *s_alInputDevice;
|
2006-08-19 11:02:20 +00:00
|
|
|
cvar_t *s_alAvailableDevices;
|
2011-03-08 01:39:34 +00:00
|
|
|
cvar_t *s_alAvailableInputDevices;
|
2005-11-13 18:58:14 +00:00
|
|
|
|
2011-03-09 23:34:15 +00:00
|
|
|
static qboolean enumeration_ext = qfalse;
|
2011-03-09 12:59:25 +00:00
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_Format
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
ALuint S_AL_Format(int width, int channels)
|
|
|
|
{
|
|
|
|
ALuint format = AL_FORMAT_MONO16;
|
|
|
|
|
|
|
|
// Work out format
|
|
|
|
if(width == 1)
|
|
|
|
{
|
|
|
|
if(channels == 1)
|
|
|
|
format = AL_FORMAT_MONO8;
|
|
|
|
else if(channels == 2)
|
|
|
|
format = AL_FORMAT_STEREO8;
|
|
|
|
}
|
|
|
|
else if(width == 2)
|
|
|
|
{
|
|
|
|
if(channels == 1)
|
|
|
|
format = AL_FORMAT_MONO16;
|
|
|
|
else if(channels == 2)
|
|
|
|
format = AL_FORMAT_STEREO16;
|
|
|
|
}
|
|
|
|
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_ErrorMsg
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static const char *S_AL_ErrorMsg(ALenum error)
|
2005-11-13 18:58:14 +00:00
|
|
|
{
|
|
|
|
switch(error)
|
|
|
|
{
|
|
|
|
case AL_NO_ERROR:
|
|
|
|
return "No error";
|
|
|
|
case AL_INVALID_NAME:
|
|
|
|
return "Invalid name";
|
|
|
|
case AL_INVALID_ENUM:
|
|
|
|
return "Invalid enumerator";
|
|
|
|
case AL_INVALID_VALUE:
|
|
|
|
return "Invalid value";
|
|
|
|
case AL_INVALID_OPERATION:
|
|
|
|
return "Invalid operation";
|
|
|
|
case AL_OUT_OF_MEMORY:
|
|
|
|
return "Out of memory";
|
|
|
|
default:
|
|
|
|
return "Unknown error";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-13 15:23:17 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_ClearError
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
static void S_AL_ClearError( qboolean quiet )
|
|
|
|
{
|
|
|
|
int error = qalGetError();
|
|
|
|
|
|
|
|
if( quiet )
|
|
|
|
return;
|
|
|
|
if(error != AL_NO_ERROR)
|
2009-10-27 11:13:33 +00:00
|
|
|
{
|
2009-10-13 15:23:17 +00:00
|
|
|
Com_Printf(S_COLOR_YELLOW "WARNING: unhandled AL error: %s\n",
|
|
|
|
S_AL_ErrorMsg(error));
|
2009-10-27 11:13:33 +00:00
|
|
|
}
|
2009-10-13 15:23:17 +00:00
|
|
|
}
|
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct alSfx_s
|
|
|
|
{
|
2005-12-03 00:19:27 +00:00
|
|
|
char filename[MAX_QPATH];
|
|
|
|
ALuint buffer; // OpenAL buffer
|
2009-10-23 23:32:52 +00:00
|
|
|
snd_info_t info; // information for this sound like rate, sample count..
|
|
|
|
|
2009-10-23 12:18:49 +00:00
|
|
|
qboolean isDefault; // Couldn't be loaded - use default FX
|
2010-08-29 18:11:15 +00:00
|
|
|
qboolean isDefaultChecked; // Sound has been check if it isDefault
|
2005-12-03 00:19:27 +00:00
|
|
|
qboolean inMemory; // Sound is stored in memory
|
|
|
|
qboolean isLocked; // Sound is locked (can not be unloaded)
|
|
|
|
int lastUsedTime; // Time last used
|
2009-10-23 12:18:49 +00:00
|
|
|
|
|
|
|
int loopCnt; // number of loops using this sfx
|
2009-10-23 23:32:52 +00:00
|
|
|
int loopActiveCnt; // number of playing loops using this sfx
|
2009-10-23 12:18:49 +00:00
|
|
|
int masterLoopSrc; // All other sources looping this buffer are synced to this master src
|
2005-11-13 18:58:14 +00:00
|
|
|
} alSfx_t;
|
|
|
|
|
|
|
|
static qboolean alBuffersInitialised = qfalse;
|
|
|
|
|
|
|
|
// Sound effect storage, data structures
|
|
|
|
#define MAX_SFX 4096
|
|
|
|
static alSfx_t knownSfx[MAX_SFX];
|
2005-12-01 18:22:42 +00:00
|
|
|
static int numSfx = 0;
|
2005-11-13 18:58:14 +00:00
|
|
|
|
|
|
|
static sfxHandle_t default_sfx;
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_BufferFindFree
|
|
|
|
|
|
|
|
Find a free handle
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
static sfxHandle_t S_AL_BufferFindFree( void )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i = 0; i < MAX_SFX; i++)
|
|
|
|
{
|
|
|
|
// Got one
|
|
|
|
if(knownSfx[i].filename[0] == '\0')
|
2006-11-25 13:35:23 +00:00
|
|
|
{
|
2006-11-26 11:12:35 +00:00
|
|
|
if(i >= numSfx)
|
2006-11-25 13:35:23 +00:00
|
|
|
numSfx = i + 1;
|
2005-11-13 18:58:14 +00:00
|
|
|
return i;
|
2006-11-25 13:35:23 +00:00
|
|
|
}
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Shit...
|
|
|
|
Com_Error(ERR_FATAL, "S_AL_BufferFindFree: No free sound handles");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_BufferFind
|
|
|
|
|
|
|
|
Find a sound effect if loaded, set up a handle otherwise
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
static sfxHandle_t S_AL_BufferFind(const char *filename)
|
|
|
|
{
|
2005-12-01 18:22:42 +00:00
|
|
|
// Look it up in the table
|
2005-11-13 18:58:14 +00:00
|
|
|
sfxHandle_t sfx = -1;
|
|
|
|
int i;
|
|
|
|
|
2006-11-25 13:35:23 +00:00
|
|
|
for(i = 0; i < numSfx; i++)
|
2005-11-13 18:58:14 +00:00
|
|
|
{
|
|
|
|
if(!Q_stricmp(knownSfx[i].filename, filename))
|
|
|
|
{
|
|
|
|
sfx = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-01 18:22:42 +00:00
|
|
|
// Not found in table?
|
2005-11-13 18:58:14 +00:00
|
|
|
if(sfx == -1)
|
|
|
|
{
|
|
|
|
alSfx_t *ptr;
|
|
|
|
|
|
|
|
sfx = S_AL_BufferFindFree();
|
|
|
|
|
|
|
|
// Clear and copy the filename over
|
|
|
|
ptr = &knownSfx[sfx];
|
|
|
|
memset(ptr, 0, sizeof(*ptr));
|
2009-10-23 23:32:52 +00:00
|
|
|
ptr->masterLoopSrc = -1;
|
2005-11-13 18:58:14 +00:00
|
|
|
strcpy(ptr->filename, filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the handle
|
|
|
|
return sfx;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_BufferUseDefault
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
static void S_AL_BufferUseDefault(sfxHandle_t sfx)
|
|
|
|
{
|
|
|
|
if(sfx == default_sfx)
|
|
|
|
Com_Error(ERR_FATAL, "Can't load default sound effect %s\n", knownSfx[sfx].filename);
|
|
|
|
|
2005-11-30 01:57:53 +00:00
|
|
|
Com_Printf( S_COLOR_YELLOW "WARNING: Using default sound for %s\n", knownSfx[sfx].filename);
|
2005-11-13 18:58:14 +00:00
|
|
|
knownSfx[sfx].isDefault = qtrue;
|
|
|
|
knownSfx[sfx].buffer = knownSfx[default_sfx].buffer;
|
|
|
|
}
|
|
|
|
|
2005-12-03 00:19:27 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_BufferUnload
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
static void S_AL_BufferUnload(sfxHandle_t sfx)
|
|
|
|
{
|
|
|
|
ALenum error;
|
|
|
|
|
|
|
|
if(knownSfx[sfx].filename[0] == '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(!knownSfx[sfx].inMemory)
|
|
|
|
return;
|
|
|
|
|
2009-10-13 15:23:17 +00:00
|
|
|
// Delete it
|
|
|
|
S_AL_ClearError( qfalse );
|
2005-12-03 00:19:27 +00:00
|
|
|
qalDeleteBuffers(1, &knownSfx[sfx].buffer);
|
|
|
|
if((error = qalGetError()) != AL_NO_ERROR)
|
|
|
|
Com_Printf( S_COLOR_RED "ERROR: Can't delete sound buffer for %s\n",
|
|
|
|
knownSfx[sfx].filename);
|
|
|
|
|
|
|
|
knownSfx[sfx].inMemory = qfalse;
|
|
|
|
}
|
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_BufferEvict
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
static qboolean S_AL_BufferEvict( void )
|
|
|
|
{
|
2005-12-03 00:19:27 +00:00
|
|
|
int i, oldestBuffer = -1;
|
|
|
|
int oldestTime = Sys_Milliseconds( );
|
|
|
|
|
2006-11-25 13:35:23 +00:00
|
|
|
for( i = 0; i < numSfx; i++ )
|
2005-12-03 00:19:27 +00:00
|
|
|
{
|
|
|
|
if( !knownSfx[ i ].filename[ 0 ] )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( !knownSfx[ i ].inMemory )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( knownSfx[ i ].lastUsedTime < oldestTime )
|
|
|
|
{
|
|
|
|
oldestTime = knownSfx[ i ].lastUsedTime;
|
|
|
|
oldestBuffer = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( oldestBuffer >= 0 )
|
|
|
|
{
|
|
|
|
S_AL_BufferUnload( oldestBuffer );
|
|
|
|
return qtrue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return qfalse;
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_BufferLoad
|
|
|
|
=================
|
|
|
|
*/
|
2010-08-29 18:11:15 +00:00
|
|
|
static void S_AL_BufferLoad(sfxHandle_t sfx, qboolean cache)
|
2005-11-13 18:58:14 +00:00
|
|
|
{
|
|
|
|
ALenum error;
|
2009-10-23 23:32:52 +00:00
|
|
|
ALuint format;
|
2005-11-13 18:58:14 +00:00
|
|
|
|
|
|
|
void *data;
|
|
|
|
snd_info_t info;
|
2009-10-23 23:32:52 +00:00
|
|
|
alSfx_t *curSfx = &knownSfx[sfx];
|
2005-11-13 18:58:14 +00:00
|
|
|
|
|
|
|
// Nothing?
|
2009-10-23 23:32:52 +00:00
|
|
|
if(curSfx->filename[0] == '\0')
|
2005-11-13 18:58:14 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Player SFX
|
2009-10-23 23:32:52 +00:00
|
|
|
if(curSfx->filename[0] == '*')
|
2005-11-13 18:58:14 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Already done?
|
2010-08-29 18:11:15 +00:00
|
|
|
if((curSfx->inMemory) || (curSfx->isDefault) || (!cache && curSfx->isDefaultChecked))
|
2005-11-13 18:58:14 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Try to load
|
2009-10-23 23:32:52 +00:00
|
|
|
data = S_CodecLoad(curSfx->filename, &info);
|
2005-11-13 18:58:14 +00:00
|
|
|
if(!data)
|
|
|
|
{
|
|
|
|
S_AL_BufferUseDefault(sfx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-29 18:11:15 +00:00
|
|
|
curSfx->isDefaultChecked = qtrue;
|
|
|
|
|
|
|
|
if (!cache)
|
|
|
|
{
|
|
|
|
// Don't create AL cache
|
|
|
|
Z_Free(data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
format = S_AL_Format(info.width, info.channels);
|
|
|
|
|
|
|
|
// Create a buffer
|
2009-10-13 15:23:17 +00:00
|
|
|
S_AL_ClearError( qfalse );
|
2009-10-23 23:32:52 +00:00
|
|
|
qalGenBuffers(1, &curSfx->buffer);
|
2005-11-13 18:58:14 +00:00
|
|
|
if((error = qalGetError()) != AL_NO_ERROR)
|
|
|
|
{
|
|
|
|
S_AL_BufferUseDefault(sfx);
|
|
|
|
Z_Free(data);
|
2005-11-30 01:57:53 +00:00
|
|
|
Com_Printf( S_COLOR_RED "ERROR: Can't create a sound buffer for %s - %s\n",
|
2009-10-23 23:32:52 +00:00
|
|
|
curSfx->filename, S_AL_ErrorMsg(error));
|
2005-11-13 18:58:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fill the buffer
|
2005-11-30 01:57:53 +00:00
|
|
|
if( info.size == 0 )
|
|
|
|
{
|
|
|
|
// We have no data to buffer, so buffer silence
|
|
|
|
byte dummyData[ 2 ] = { 0 };
|
|
|
|
|
2009-10-23 23:32:52 +00:00
|
|
|
qalBufferData(curSfx->buffer, AL_FORMAT_MONO16, (void *)dummyData, 2, 22050);
|
2005-11-30 01:57:53 +00:00
|
|
|
}
|
|
|
|
else
|
2009-10-23 23:32:52 +00:00
|
|
|
qalBufferData(curSfx->buffer, format, data, info.size, info.rate);
|
2005-11-30 01:57:53 +00:00
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
error = qalGetError();
|
|
|
|
|
|
|
|
// If we ran out of memory, start evicting the least recently used sounds
|
|
|
|
while(error == AL_OUT_OF_MEMORY)
|
|
|
|
{
|
2005-12-03 00:19:27 +00:00
|
|
|
if( !S_AL_BufferEvict( ) )
|
2005-11-13 18:58:14 +00:00
|
|
|
{
|
|
|
|
S_AL_BufferUseDefault(sfx);
|
|
|
|
Z_Free(data);
|
2009-10-23 23:32:52 +00:00
|
|
|
Com_Printf( S_COLOR_RED "ERROR: Out of memory loading %s\n", curSfx->filename);
|
2005-11-13 18:58:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try load it again
|
2009-10-23 23:32:52 +00:00
|
|
|
qalBufferData(curSfx->buffer, format, data, info.size, info.rate);
|
2005-11-13 18:58:14 +00:00
|
|
|
error = qalGetError();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Some other error condition
|
|
|
|
if(error != AL_NO_ERROR)
|
|
|
|
{
|
|
|
|
S_AL_BufferUseDefault(sfx);
|
|
|
|
Z_Free(data);
|
2005-11-30 01:57:53 +00:00
|
|
|
Com_Printf( S_COLOR_RED "ERROR: Can't fill sound buffer for %s - %s\n",
|
2009-10-23 23:32:52 +00:00
|
|
|
curSfx->filename, S_AL_ErrorMsg(error));
|
2005-11-13 18:58:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-23 23:32:52 +00:00
|
|
|
curSfx->info = info;
|
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
// Free the memory
|
|
|
|
Z_Free(data);
|
|
|
|
|
|
|
|
// Woo!
|
2009-10-23 23:32:52 +00:00
|
|
|
curSfx->inMemory = qtrue;
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_BufferUse
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
void S_AL_BufferUse(sfxHandle_t sfx)
|
|
|
|
{
|
|
|
|
if(knownSfx[sfx].filename[0] == '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
if((!knownSfx[sfx].inMemory) && (!knownSfx[sfx].isDefault))
|
2010-08-29 18:11:15 +00:00
|
|
|
S_AL_BufferLoad(sfx, qtrue);
|
2005-12-03 00:19:27 +00:00
|
|
|
knownSfx[sfx].lastUsedTime = Sys_Milliseconds();
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_BufferInit
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
qboolean S_AL_BufferInit( void )
|
|
|
|
{
|
|
|
|
if(alBuffersInitialised)
|
|
|
|
return qtrue;
|
|
|
|
|
|
|
|
// Clear the hash table, and SFX table
|
|
|
|
memset(knownSfx, 0, sizeof(knownSfx));
|
|
|
|
numSfx = 0;
|
|
|
|
|
|
|
|
// Load the default sound, and lock it
|
|
|
|
default_sfx = S_AL_BufferFind("sound/feedback/hit.wav");
|
|
|
|
S_AL_BufferUse(default_sfx);
|
|
|
|
knownSfx[default_sfx].isLocked = qtrue;
|
|
|
|
|
|
|
|
// All done
|
|
|
|
alBuffersInitialised = qtrue;
|
|
|
|
return qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_BufferShutdown
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
void S_AL_BufferShutdown( void )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if(!alBuffersInitialised)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Unlock the default sound effect
|
|
|
|
knownSfx[default_sfx].isLocked = qfalse;
|
|
|
|
|
|
|
|
// Free all used effects
|
2006-11-25 13:35:23 +00:00
|
|
|
for(i = 0; i < numSfx; i++)
|
2005-11-13 18:58:14 +00:00
|
|
|
S_AL_BufferUnload(i);
|
|
|
|
|
|
|
|
// Clear the tables
|
|
|
|
memset(knownSfx, 0, sizeof(knownSfx));
|
|
|
|
|
|
|
|
// All undone
|
|
|
|
alBuffersInitialised = qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_RegisterSound
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
sfxHandle_t S_AL_RegisterSound( const char *sample, qboolean compressed )
|
|
|
|
{
|
|
|
|
sfxHandle_t sfx = S_AL_BufferFind(sample);
|
|
|
|
|
2010-08-29 18:11:15 +00:00
|
|
|
if((!knownSfx[sfx].inMemory) && (!knownSfx[sfx].isDefault))
|
|
|
|
S_AL_BufferLoad(sfx, s_alPrecache->integer);
|
2005-12-03 00:19:27 +00:00
|
|
|
knownSfx[sfx].lastUsedTime = Com_Milliseconds();
|
2005-11-13 18:58:14 +00:00
|
|
|
|
2010-08-29 18:11:15 +00:00
|
|
|
if (knownSfx[sfx].isDefault) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
return sfx;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_BufferGet
|
|
|
|
|
|
|
|
Return's an sfx's buffer
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
ALuint S_AL_BufferGet(sfxHandle_t sfx)
|
|
|
|
{
|
|
|
|
return knownSfx[sfx].buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct src_s
|
|
|
|
{
|
2009-10-23 23:32:52 +00:00
|
|
|
ALuint alSource; // OpenAL source object
|
|
|
|
sfxHandle_t sfx; // Sound effect in use
|
2005-11-13 18:58:14 +00:00
|
|
|
|
2009-10-23 23:32:52 +00:00
|
|
|
int lastUsedTime; // Last time used
|
2005-11-13 18:58:14 +00:00
|
|
|
alSrcPriority_t priority; // Priority
|
2009-10-23 23:32:52 +00:00
|
|
|
int entity; // Owning entity (-1 if none)
|
|
|
|
int channel; // Associated channel (-1 if none)
|
2005-11-13 18:58:14 +00:00
|
|
|
|
2009-10-23 23:32:52 +00:00
|
|
|
qboolean isActive; // Is this source currently in use?
|
|
|
|
qboolean isPlaying; // Is this source currently playing, or stopped?
|
|
|
|
qboolean isLocked; // This is locked (un-allocatable)
|
|
|
|
qboolean isLooping; // Is this a looping effect (attached to an entity)
|
|
|
|
qboolean isTracking; // Is this object tracking its owner
|
2006-11-03 08:22:38 +00:00
|
|
|
|
2009-10-23 23:32:52 +00:00
|
|
|
float curGain; // gain employed if source is within maxdistance.
|
|
|
|
float scaleGain; // Last gain value for this source. 0 if muted.
|
|
|
|
|
2009-10-24 08:33:12 +00:00
|
|
|
float lastTimePos; // On stopped loops, the last position in the buffer
|
2009-10-23 23:32:52 +00:00
|
|
|
int lastSampleTime; // Time when this was stopped
|
2009-10-26 05:02:18 +00:00
|
|
|
vec3_t loopSpeakerPos; // Origin of the loop speaker
|
2009-10-23 23:32:52 +00:00
|
|
|
|
|
|
|
qboolean local; // Is this local (relative to the cam)
|
2005-11-13 18:58:14 +00:00
|
|
|
} src_t;
|
|
|
|
|
2006-08-03 03:15:24 +00:00
|
|
|
#ifdef MACOS_X
|
2008-05-10 18:51:02 +00:00
|
|
|
#define MAX_SRC 64
|
2006-08-03 03:15:24 +00:00
|
|
|
#else
|
2008-05-10 18:51:02 +00:00
|
|
|
#define MAX_SRC 128
|
2006-08-03 03:15:24 +00:00
|
|
|
#endif
|
2005-11-13 18:58:14 +00:00
|
|
|
static src_t srcList[MAX_SRC];
|
|
|
|
static int srcCount = 0;
|
2009-10-27 11:13:33 +00:00
|
|
|
static int srcActiveCnt = 0;
|
2005-11-13 18:58:14 +00:00
|
|
|
static qboolean alSourcesInitialised = qfalse;
|
2006-01-22 21:09:55 +00:00
|
|
|
static vec3_t lastListenerOrigin = { 0.0f, 0.0f, 0.0f };
|
2005-11-13 18:58:14 +00:00
|
|
|
|
|
|
|
typedef struct sentity_s
|
|
|
|
{
|
2005-12-01 18:22:42 +00:00
|
|
|
vec3_t origin;
|
|
|
|
|
2009-10-23 23:32:52 +00:00
|
|
|
qboolean srcAllocated; // If a src_t has been allocated to this entity
|
2005-12-01 18:22:42 +00:00
|
|
|
int srcIndex;
|
2005-11-13 18:58:14 +00:00
|
|
|
|
2005-12-01 18:22:42 +00:00
|
|
|
qboolean loopAddedThisFrame;
|
|
|
|
alSrcPriority_t loopPriority;
|
|
|
|
sfxHandle_t loopSfx;
|
|
|
|
qboolean startLoopingSound;
|
2005-11-13 18:58:14 +00:00
|
|
|
} sentity_t;
|
|
|
|
|
|
|
|
static sentity_t entityList[MAX_GENTITIES];
|
|
|
|
|
2006-01-19 17:25:55 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_SanitiseVector
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
#define S_AL_SanitiseVector(v) _S_AL_SanitiseVector(v,__LINE__)
|
|
|
|
static void _S_AL_SanitiseVector( vec3_t v, int line )
|
|
|
|
{
|
2006-01-19 20:28:12 +00:00
|
|
|
if( Q_isnan( v[ 0 ] ) || Q_isnan( v[ 1 ] ) || Q_isnan( v[ 2 ] ) )
|
|
|
|
{
|
|
|
|
Com_DPrintf( S_COLOR_YELLOW "WARNING: vector with one or more NaN components "
|
|
|
|
"being passed to OpenAL at %s:%d -- zeroing\n", __FILE__, line );
|
|
|
|
VectorClear( v );
|
|
|
|
}
|
2006-01-19 17:25:55 +00:00
|
|
|
}
|
|
|
|
|
2006-02-28 21:52:25 +00:00
|
|
|
|
|
|
|
#define AL_THIRD_PERSON_THRESHOLD_SQ (48.0f*48.0f)
|
|
|
|
|
2009-11-10 01:08:15 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_Gain
|
|
|
|
Set gain to 0 if muted, otherwise set it to given value.
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void S_AL_Gain(ALuint source, float gainval)
|
|
|
|
{
|
|
|
|
if(s_muted->integer)
|
|
|
|
qalSourcef(source, AL_GAIN, 0.0f);
|
|
|
|
else
|
|
|
|
qalSourcef(source, AL_GAIN, gainval);
|
|
|
|
}
|
|
|
|
|
2006-11-03 08:22:38 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_ScaleGain
|
|
|
|
Adapt the gain if necessary to get a quicker fadeout when the source is too far away.
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void S_AL_ScaleGain(src_t *chksrc, vec3_t origin)
|
|
|
|
{
|
|
|
|
float distance;
|
2007-01-24 21:23:21 +00:00
|
|
|
|
|
|
|
if(!chksrc->local)
|
2006-11-03 08:22:38 +00:00
|
|
|
distance = Distance(origin, lastListenerOrigin);
|
2007-01-24 21:23:21 +00:00
|
|
|
|
2006-11-03 08:22:38 +00:00
|
|
|
// If we exceed a certain distance, scale the gain linearly until the sound
|
|
|
|
// vanishes into nothingness.
|
2007-01-24 21:23:21 +00:00
|
|
|
if(!chksrc->local && (distance -= s_alMaxDistance->value) > 0)
|
2006-11-03 08:22:38 +00:00
|
|
|
{
|
|
|
|
float scaleFactor;
|
|
|
|
|
|
|
|
if(distance >= s_alGraceDistance->value)
|
|
|
|
scaleFactor = 0.0f;
|
|
|
|
else
|
|
|
|
scaleFactor = 1.0f - distance / s_alGraceDistance->value;
|
|
|
|
|
|
|
|
scaleFactor *= chksrc->curGain;
|
|
|
|
|
2011-01-27 07:00:35 +00:00
|
|
|
if(chksrc->scaleGain != scaleFactor)
|
2006-11-03 08:22:38 +00:00
|
|
|
{
|
|
|
|
chksrc->scaleGain = scaleFactor;
|
2009-11-10 01:08:15 +00:00
|
|
|
S_AL_Gain(chksrc->alSource, chksrc->scaleGain);
|
2006-11-03 08:22:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(chksrc->scaleGain != chksrc->curGain)
|
|
|
|
{
|
|
|
|
chksrc->scaleGain = chksrc->curGain;
|
2009-11-10 01:08:15 +00:00
|
|
|
S_AL_Gain(chksrc->alSource, chksrc->scaleGain);
|
2006-11-03 08:22:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-28 21:52:25 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_HearingThroughEntity
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
static qboolean S_AL_HearingThroughEntity( int entityNum )
|
|
|
|
{
|
|
|
|
float distanceSq;
|
|
|
|
|
|
|
|
if( clc.clientNum == entityNum )
|
|
|
|
{
|
|
|
|
// FIXME: <tim@ngus.net> 28/02/06 This is an outrageous hack to detect
|
|
|
|
// whether or not the player is rendering in third person or not. We can't
|
|
|
|
// ask the renderer because the renderer has no notion of entities and we
|
|
|
|
// can't ask cgame since that would involve changing the API and hence mod
|
|
|
|
// compatibility. I don't think there is any way around this, but I'll leave
|
|
|
|
// the FIXME just in case anyone has a bright idea.
|
|
|
|
distanceSq = DistanceSquared(
|
|
|
|
entityList[ entityNum ].origin,
|
|
|
|
lastListenerOrigin );
|
|
|
|
|
|
|
|
if( distanceSq > AL_THIRD_PERSON_THRESHOLD_SQ )
|
|
|
|
return qfalse; //we're the player, but third person
|
|
|
|
else
|
|
|
|
return qtrue; //we're the player
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return qfalse; //not the player
|
|
|
|
}
|
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_SrcInit
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
qboolean S_AL_SrcInit( void )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int limit;
|
|
|
|
ALenum error;
|
|
|
|
|
|
|
|
// Clear the sources data structure
|
|
|
|
memset(srcList, 0, sizeof(srcList));
|
|
|
|
srcCount = 0;
|
2009-10-27 11:13:33 +00:00
|
|
|
srcActiveCnt = 0;
|
2005-11-13 18:58:14 +00:00
|
|
|
|
2005-12-01 18:22:42 +00:00
|
|
|
// Cap s_alSources to MAX_SRC
|
2005-11-13 18:58:14 +00:00
|
|
|
limit = s_alSources->integer;
|
|
|
|
if(limit > MAX_SRC)
|
|
|
|
limit = MAX_SRC;
|
|
|
|
else if(limit < 16)
|
|
|
|
limit = 16;
|
2009-10-13 15:23:17 +00:00
|
|
|
|
|
|
|
S_AL_ClearError( qfalse );
|
2005-11-13 18:58:14 +00:00
|
|
|
// Allocate as many sources as possible
|
|
|
|
for(i = 0; i < limit; i++)
|
|
|
|
{
|
2005-12-01 18:22:42 +00:00
|
|
|
qalGenSources(1, &srcList[i].alSource);
|
2005-11-13 18:58:14 +00:00
|
|
|
if((error = qalGetError()) != AL_NO_ERROR)
|
|
|
|
break;
|
|
|
|
srcCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// All done. Print this for informational purposes
|
|
|
|
Com_Printf( "Allocated %d sources.\n", srcCount);
|
|
|
|
alSourcesInitialised = qtrue;
|
|
|
|
return qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_SrcShutdown
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
void S_AL_SrcShutdown( void )
|
|
|
|
{
|
|
|
|
int i;
|
2009-10-27 11:13:33 +00:00
|
|
|
src_t *curSource;
|
2005-11-13 18:58:14 +00:00
|
|
|
|
|
|
|
if(!alSourcesInitialised)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Destroy all the sources
|
|
|
|
for(i = 0; i < srcCount; i++)
|
|
|
|
{
|
2009-10-27 11:13:33 +00:00
|
|
|
curSource = &srcList[i];
|
|
|
|
|
|
|
|
if(curSource->isLocked)
|
2005-11-30 01:57:53 +00:00
|
|
|
Com_DPrintf( S_COLOR_YELLOW "WARNING: Source %d is locked\n", i);
|
2005-11-13 18:58:14 +00:00
|
|
|
|
2009-10-27 11:13:33 +00:00
|
|
|
if(curSource->entity > 0)
|
|
|
|
entityList[curSource->entity].srcAllocated = qfalse;
|
|
|
|
|
2005-12-01 18:22:42 +00:00
|
|
|
qalSourceStop(srcList[i].alSource);
|
|
|
|
qalDeleteSources(1, &srcList[i].alSource);
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
memset(srcList, 0, sizeof(srcList));
|
|
|
|
|
|
|
|
alSourcesInitialised = qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_SrcSetup
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
static void S_AL_SrcSetup(srcHandle_t src, sfxHandle_t sfx, alSrcPriority_t priority,
|
|
|
|
int entity, int channel, qboolean local)
|
|
|
|
{
|
|
|
|
ALuint buffer;
|
2006-11-03 08:22:38 +00:00
|
|
|
src_t *curSource;
|
2005-11-13 18:58:14 +00:00
|
|
|
|
|
|
|
// Mark the SFX as used, and grab the raw AL buffer
|
|
|
|
S_AL_BufferUse(sfx);
|
|
|
|
buffer = S_AL_BufferGet(sfx);
|
|
|
|
|
|
|
|
// Set up src struct
|
2006-11-03 08:22:38 +00:00
|
|
|
curSource = &srcList[src];
|
|
|
|
|
|
|
|
curSource->lastUsedTime = Sys_Milliseconds();
|
|
|
|
curSource->sfx = sfx;
|
|
|
|
curSource->priority = priority;
|
|
|
|
curSource->entity = entity;
|
|
|
|
curSource->channel = channel;
|
2009-10-23 23:32:52 +00:00
|
|
|
curSource->isPlaying = qfalse;
|
2006-11-03 08:22:38 +00:00
|
|
|
curSource->isLocked = qfalse;
|
|
|
|
curSource->isLooping = qfalse;
|
|
|
|
curSource->isTracking = qfalse;
|
|
|
|
curSource->curGain = s_alGain->value * s_volume->value;
|
|
|
|
curSource->scaleGain = curSource->curGain;
|
|
|
|
curSource->local = local;
|
2005-11-13 18:58:14 +00:00
|
|
|
|
|
|
|
// Set up OpenAL source
|
2006-11-03 08:22:38 +00:00
|
|
|
qalSourcei(curSource->alSource, AL_BUFFER, buffer);
|
|
|
|
qalSourcef(curSource->alSource, AL_PITCH, 1.0f);
|
2009-11-10 01:08:15 +00:00
|
|
|
S_AL_Gain(curSource->alSource, curSource->curGain);
|
2006-11-03 08:22:38 +00:00
|
|
|
qalSourcefv(curSource->alSource, AL_POSITION, vec3_origin);
|
|
|
|
qalSourcefv(curSource->alSource, AL_VELOCITY, vec3_origin);
|
|
|
|
qalSourcei(curSource->alSource, AL_LOOPING, AL_FALSE);
|
|
|
|
qalSourcef(curSource->alSource, AL_REFERENCE_DISTANCE, s_alMinDistance->value);
|
2005-11-13 18:58:14 +00:00
|
|
|
|
|
|
|
if(local)
|
|
|
|
{
|
2006-11-03 08:22:38 +00:00
|
|
|
qalSourcei(curSource->alSource, AL_SOURCE_RELATIVE, AL_TRUE);
|
|
|
|
qalSourcef(curSource->alSource, AL_ROLLOFF_FACTOR, 0.0f);
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-11-03 08:22:38 +00:00
|
|
|
qalSourcei(curSource->alSource, AL_SOURCE_RELATIVE, AL_FALSE);
|
|
|
|
qalSourcef(curSource->alSource, AL_ROLLOFF_FACTOR, s_alRolloff->value);
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-23 12:18:49 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_NewLoopMaster
|
|
|
|
Remove given source as loop master if it is the master and hand off master status to another source in this case.
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
|
2009-10-27 11:13:33 +00:00
|
|
|
static void S_AL_SaveLoopPos(src_t *dest, ALuint alSource)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
S_AL_ClearError(qfalse);
|
|
|
|
|
|
|
|
qalGetSourcef(alSource, AL_SEC_OFFSET, &dest->lastTimePos);
|
|
|
|
if((error = qalGetError()) != AL_NO_ERROR)
|
|
|
|
{
|
|
|
|
// Old OpenAL implementations don't support AL_SEC_OFFSET
|
|
|
|
|
|
|
|
if(error != AL_INVALID_ENUM)
|
|
|
|
{
|
|
|
|
Com_Printf(S_COLOR_YELLOW "WARNING: Could not get time offset for alSource %d: %s\n",
|
|
|
|
alSource, S_AL_ErrorMsg(error));
|
|
|
|
}
|
|
|
|
|
|
|
|
dest->lastTimePos = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
dest->lastSampleTime = Sys_Milliseconds();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_NewLoopMaster
|
|
|
|
Remove given source as loop master if it is the master and hand off master status to another source in this case.
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
|
2009-10-23 23:32:52 +00:00
|
|
|
static void S_AL_NewLoopMaster(src_t *rmSource, qboolean iskilled)
|
2009-10-23 12:18:49 +00:00
|
|
|
{
|
|
|
|
int index;
|
2009-10-23 23:32:52 +00:00
|
|
|
src_t *curSource = NULL;
|
2009-10-23 12:18:49 +00:00
|
|
|
alSfx_t *curSfx;
|
|
|
|
|
|
|
|
curSfx = &knownSfx[rmSource->sfx];
|
2009-10-23 23:32:52 +00:00
|
|
|
|
2009-10-24 08:33:12 +00:00
|
|
|
if(rmSource->isPlaying)
|
|
|
|
curSfx->loopActiveCnt--;
|
2009-10-23 23:32:52 +00:00
|
|
|
if(iskilled)
|
|
|
|
curSfx->loopCnt--;
|
2009-10-23 12:18:49 +00:00
|
|
|
|
2009-10-23 23:32:52 +00:00
|
|
|
if(curSfx->loopCnt)
|
2009-10-23 12:18:49 +00:00
|
|
|
{
|
2009-10-27 11:13:33 +00:00
|
|
|
if(rmSource->priority == SRCPRI_ENTITY)
|
|
|
|
{
|
|
|
|
if(!iskilled && rmSource->isPlaying)
|
|
|
|
{
|
|
|
|
// only sync ambient loops...
|
|
|
|
// It makes more sense to have sounds for weapons/projectiles unsynced
|
|
|
|
S_AL_SaveLoopPos(rmSource, rmSource->alSource);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(rmSource == &srcList[curSfx->masterLoopSrc])
|
2009-10-23 12:18:49 +00:00
|
|
|
{
|
2009-10-23 23:32:52 +00:00
|
|
|
int firstInactive = -1;
|
|
|
|
|
|
|
|
// Only if rmSource was the master and if there are still playing loops for
|
|
|
|
// this sound will we need to find a new master.
|
2009-10-23 12:18:49 +00:00
|
|
|
|
2009-10-23 23:32:52 +00:00
|
|
|
if(iskilled || curSfx->loopActiveCnt)
|
2009-10-23 12:18:49 +00:00
|
|
|
{
|
2009-10-23 23:32:52 +00:00
|
|
|
for(index = 0; index < srcCount; index++)
|
|
|
|
{
|
|
|
|
curSource = &srcList[index];
|
|
|
|
|
|
|
|
if(curSource->sfx == rmSource->sfx && curSource != rmSource &&
|
2009-10-27 11:13:33 +00:00
|
|
|
curSource->isActive && curSource->isLooping && curSource->priority == SRCPRI_AMBIENT)
|
2009-10-23 23:32:52 +00:00
|
|
|
{
|
|
|
|
if(curSource->isPlaying)
|
|
|
|
{
|
|
|
|
curSfx->masterLoopSrc = index;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if(firstInactive < 0)
|
|
|
|
firstInactive = index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!curSfx->loopActiveCnt)
|
|
|
|
{
|
|
|
|
if(firstInactive < 0)
|
2009-10-27 11:13:33 +00:00
|
|
|
{
|
|
|
|
if(iskilled)
|
|
|
|
{
|
|
|
|
curSfx->masterLoopSrc = -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
curSource = rmSource;
|
|
|
|
}
|
2009-10-23 23:32:52 +00:00
|
|
|
else
|
|
|
|
curSource = &srcList[firstInactive];
|
|
|
|
|
2009-10-24 08:33:12 +00:00
|
|
|
if(rmSource->isPlaying)
|
|
|
|
{
|
|
|
|
// this was the last not stopped source, save last sample position + time
|
2009-10-27 11:13:33 +00:00
|
|
|
S_AL_SaveLoopPos(curSource, rmSource->alSource);
|
2009-10-24 08:33:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// second case: all loops using this sound have stopped due to listener being of of range,
|
|
|
|
// and now the inactive master gets deleted. Just move over the soundpos settings to the
|
|
|
|
// new master.
|
|
|
|
curSource->lastTimePos = rmSource->lastTimePos;
|
|
|
|
curSource->lastSampleTime = rmSource->lastSampleTime;
|
|
|
|
}
|
2009-10-23 12:18:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-10-23 23:32:52 +00:00
|
|
|
else
|
|
|
|
curSfx->masterLoopSrc = -1;
|
2009-10-23 12:18:49 +00:00
|
|
|
}
|
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_SrcKill
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
static void S_AL_SrcKill(srcHandle_t src)
|
|
|
|
{
|
2009-10-23 12:18:49 +00:00
|
|
|
src_t *curSource = &srcList[src];
|
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
// I'm not touching it. Unlock it first.
|
2009-10-23 12:18:49 +00:00
|
|
|
if(curSource->isLocked)
|
2005-11-13 18:58:14 +00:00
|
|
|
return;
|
|
|
|
|
2009-10-23 12:18:49 +00:00
|
|
|
// Remove the entity association and loop master status
|
|
|
|
if(curSource->isLooping)
|
2005-11-13 18:58:14 +00:00
|
|
|
{
|
2009-10-23 12:18:49 +00:00
|
|
|
curSource->isLooping = qfalse;
|
|
|
|
|
|
|
|
if(curSource->entity != -1)
|
|
|
|
{
|
|
|
|
sentity_t *curEnt = &entityList[curSource->entity];
|
|
|
|
|
|
|
|
curEnt->srcAllocated = qfalse;
|
|
|
|
curEnt->srcIndex = -1;
|
|
|
|
curEnt->loopAddedThisFrame = qfalse;
|
|
|
|
curEnt->startLoopingSound = qfalse;
|
|
|
|
}
|
|
|
|
|
2009-10-23 23:32:52 +00:00
|
|
|
S_AL_NewLoopMaster(curSource, qtrue);
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
|
2009-10-23 23:32:52 +00:00
|
|
|
// Stop it if it's playing
|
2009-10-24 08:33:12 +00:00
|
|
|
if(curSource->isPlaying)
|
|
|
|
{
|
2009-10-23 23:32:52 +00:00
|
|
|
qalSourceStop(curSource->alSource);
|
2009-10-24 08:33:12 +00:00
|
|
|
curSource->isPlaying = qfalse;
|
|
|
|
}
|
2009-10-23 23:32:52 +00:00
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
// Remove the buffer
|
2009-10-23 12:18:49 +00:00
|
|
|
qalSourcei(curSource->alSource, AL_BUFFER, 0);
|
|
|
|
|
|
|
|
curSource->sfx = 0;
|
|
|
|
curSource->lastUsedTime = 0;
|
|
|
|
curSource->priority = 0;
|
|
|
|
curSource->entity = -1;
|
|
|
|
curSource->channel = -1;
|
2009-10-27 11:13:33 +00:00
|
|
|
if(curSource->isActive)
|
|
|
|
{
|
|
|
|
curSource->isActive = qfalse;
|
|
|
|
srcActiveCnt--;
|
|
|
|
}
|
2009-10-23 12:18:49 +00:00
|
|
|
curSource->isLocked = qfalse;
|
|
|
|
curSource->isTracking = qfalse;
|
|
|
|
curSource->local = qfalse;
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_SrcAlloc
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
srcHandle_t S_AL_SrcAlloc( alSrcPriority_t priority, int entnum, int channel )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int empty = -1;
|
|
|
|
int weakest = -1;
|
|
|
|
int weakest_time = Sys_Milliseconds();
|
|
|
|
int weakest_pri = 999;
|
2009-10-27 11:13:33 +00:00
|
|
|
float weakest_gain = 1000.0;
|
2009-10-26 23:20:05 +00:00
|
|
|
qboolean weakest_isplaying = qtrue;
|
|
|
|
int weakest_numloops = 0;
|
|
|
|
src_t *curSource;
|
2005-11-13 18:58:14 +00:00
|
|
|
|
|
|
|
for(i = 0; i < srcCount; i++)
|
|
|
|
{
|
2009-10-26 23:20:05 +00:00
|
|
|
curSource = &srcList[i];
|
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
// If it's locked, we aren't even going to look at it
|
2009-10-26 23:20:05 +00:00
|
|
|
if(curSource->isLocked)
|
2005-11-13 18:58:14 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Is it empty or not?
|
2009-10-26 23:20:05 +00:00
|
|
|
if(!curSource->isActive)
|
|
|
|
{
|
2005-11-13 18:58:14 +00:00
|
|
|
empty = i;
|
2009-10-26 23:20:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(curSource->isPlaying)
|
2005-11-13 18:58:14 +00:00
|
|
|
{
|
2009-10-26 23:20:05 +00:00
|
|
|
if(weakest_isplaying && curSource->priority < priority &&
|
2009-10-27 11:13:33 +00:00
|
|
|
(curSource->priority < weakest_pri ||
|
|
|
|
(!curSource->isLooping && (curSource->scaleGain < weakest_gain || curSource->lastUsedTime < weakest_time))))
|
2009-10-26 23:20:05 +00:00
|
|
|
{
|
2009-10-27 11:13:33 +00:00
|
|
|
// If it has lower priority, is fainter or older, flag it as weak
|
|
|
|
// the last two values are only compared if it's not a looping sound, because we want to prevent two
|
|
|
|
// loops (loops are added EVERY frame) fighting for a slot
|
2009-10-26 23:20:05 +00:00
|
|
|
weakest_pri = curSource->priority;
|
|
|
|
weakest_time = curSource->lastUsedTime;
|
2009-10-27 11:13:33 +00:00
|
|
|
weakest_gain = curSource->scaleGain;
|
2009-10-26 23:20:05 +00:00
|
|
|
weakest = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
weakest_isplaying = qfalse;
|
|
|
|
|
2009-10-27 11:13:33 +00:00
|
|
|
if(weakest < 0 ||
|
|
|
|
knownSfx[curSource->sfx].loopCnt > weakest_numloops ||
|
2009-10-26 23:20:05 +00:00
|
|
|
curSource->priority < weakest_pri ||
|
|
|
|
curSource->lastUsedTime < weakest_time)
|
2005-11-13 18:58:14 +00:00
|
|
|
{
|
2009-10-26 23:20:05 +00:00
|
|
|
// Sources currently not playing of course have lowest priority
|
|
|
|
// also try to always keep at least one loop master for every loop sound
|
|
|
|
weakest_pri = curSource->priority;
|
|
|
|
weakest_time = curSource->lastUsedTime;
|
|
|
|
weakest_numloops = knownSfx[curSource->sfx].loopCnt;
|
2005-11-13 18:58:14 +00:00
|
|
|
weakest = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-02 00:14:24 +00:00
|
|
|
// The channel system is not actually adhered to by baseq3, and not
|
|
|
|
// implemented in snd_dma.c, so while the following is strictly correct, it
|
|
|
|
// causes incorrect behaviour versus defacto baseq3
|
|
|
|
#if 0
|
2005-11-13 18:58:14 +00:00
|
|
|
// Is it an exact match, and not on channel 0?
|
2009-10-26 23:20:05 +00:00
|
|
|
if((curSource->entity == entnum) && (curSource->channel == channel) && (channel != 0))
|
2005-11-13 18:58:14 +00:00
|
|
|
{
|
|
|
|
S_AL_SrcKill(i);
|
|
|
|
return i;
|
|
|
|
}
|
2005-12-02 00:14:24 +00:00
|
|
|
#endif
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
|
2009-10-27 11:13:33 +00:00
|
|
|
if(empty == -1)
|
|
|
|
empty = weakest;
|
|
|
|
|
|
|
|
if(empty >= 0)
|
2005-11-13 18:58:14 +00:00
|
|
|
{
|
2009-10-27 11:13:33 +00:00
|
|
|
S_AL_SrcKill(empty);
|
|
|
|
srcList[empty].isActive = qtrue;
|
|
|
|
srcActiveCnt++;
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
|
2009-10-27 11:13:33 +00:00
|
|
|
return empty;
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_SrcFind
|
|
|
|
|
|
|
|
Finds an active source with matching entity and channel numbers
|
|
|
|
Returns -1 if there isn't one
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
#if 0
|
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
srcHandle_t S_AL_SrcFind(int entnum, int channel)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < srcCount; i++)
|
|
|
|
{
|
|
|
|
if(!srcList[i].isActive)
|
|
|
|
continue;
|
|
|
|
if((srcList[i].entity == entnum) && (srcList[i].channel == channel))
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2005-11-19 14:53:46 +00:00
|
|
|
#endif
|
2005-11-13 18:58:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_SrcLock
|
|
|
|
|
|
|
|
Locked sources will not be automatically reallocated or managed
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
void S_AL_SrcLock(srcHandle_t src)
|
|
|
|
{
|
|
|
|
srcList[src].isLocked = qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_SrcUnlock
|
|
|
|
|
|
|
|
Once unlocked, the source may be reallocated again
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
void S_AL_SrcUnlock(srcHandle_t src)
|
|
|
|
{
|
|
|
|
srcList[src].isLocked = qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_UpdateEntityPosition
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
void S_AL_UpdateEntityPosition( int entityNum, const vec3_t origin )
|
|
|
|
{
|
2008-05-10 18:51:02 +00:00
|
|
|
vec3_t sanOrigin;
|
|
|
|
|
|
|
|
VectorCopy( origin, sanOrigin );
|
|
|
|
S_AL_SanitiseVector( sanOrigin );
|
2005-11-13 18:58:14 +00:00
|
|
|
if ( entityNum < 0 || entityNum > MAX_GENTITIES )
|
|
|
|
Com_Error( ERR_DROP, "S_UpdateEntityPosition: bad entitynum %i", entityNum );
|
2008-05-10 18:51:02 +00:00
|
|
|
VectorCopy( sanOrigin, entityList[entityNum].origin );
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
|
2006-11-25 13:35:23 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_CheckInput
|
|
|
|
Check whether input values from mods are out of range.
|
|
|
|
Necessary for i.g. Western Quake3 mod which is buggy.
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
static qboolean S_AL_CheckInput(int entityNum, sfxHandle_t sfx)
|
|
|
|
{
|
|
|
|
if (entityNum < 0 || entityNum > MAX_GENTITIES)
|
2009-10-27 11:13:33 +00:00
|
|
|
Com_Error(ERR_DROP, "ERROR: S_AL_CheckInput: bad entitynum %i", entityNum);
|
2006-11-25 13:35:23 +00:00
|
|
|
|
|
|
|
if (sfx < 0 || sfx >= numSfx)
|
|
|
|
{
|
2006-12-30 12:32:54 +00:00
|
|
|
Com_Printf(S_COLOR_RED "ERROR: S_AL_CheckInput: handle %i out of range\n", sfx);
|
2008-05-10 18:51:02 +00:00
|
|
|
return qtrue;
|
|
|
|
}
|
2006-11-25 13:35:23 +00:00
|
|
|
|
|
|
|
return qfalse;
|
|
|
|
}
|
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_StartLocalSound
|
|
|
|
|
|
|
|
Play a local (non-spatialized) sound effect
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
void S_AL_StartLocalSound(sfxHandle_t sfx, int channel)
|
|
|
|
{
|
2007-01-07 16:03:19 +00:00
|
|
|
srcHandle_t src;
|
|
|
|
|
2006-11-25 13:35:23 +00:00
|
|
|
if(S_AL_CheckInput(0, sfx))
|
|
|
|
return;
|
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
// Try to grab a source
|
2007-01-07 16:03:19 +00:00
|
|
|
src = S_AL_SrcAlloc(SRCPRI_LOCAL, -1, channel);
|
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
if(src == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Set up the effect
|
|
|
|
S_AL_SrcSetup(src, sfx, SRCPRI_LOCAL, -1, channel, qtrue);
|
|
|
|
|
|
|
|
// Start it playing
|
2009-10-23 23:32:52 +00:00
|
|
|
srcList[src].isPlaying = qtrue;
|
2005-12-01 18:22:42 +00:00
|
|
|
qalSourcePlay(srcList[src].alSource);
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_StartSound
|
|
|
|
|
|
|
|
Play a one-shot sound effect
|
|
|
|
=================
|
|
|
|
*/
|
2009-10-27 11:13:33 +00:00
|
|
|
static void S_AL_StartSound( vec3_t origin, int entnum, int entchannel, sfxHandle_t sfx )
|
2005-11-13 18:58:14 +00:00
|
|
|
{
|
|
|
|
vec3_t sorigin;
|
2007-01-07 16:03:19 +00:00
|
|
|
srcHandle_t src;
|
2009-10-27 11:13:33 +00:00
|
|
|
src_t *curSource;
|
|
|
|
|
|
|
|
if(origin)
|
|
|
|
{
|
|
|
|
if(S_AL_CheckInput(0, sfx))
|
|
|
|
return;
|
|
|
|
|
|
|
|
VectorCopy(origin, sorigin);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(S_AL_CheckInput(entnum, sfx))
|
|
|
|
return;
|
2005-11-13 18:58:14 +00:00
|
|
|
|
2009-10-27 11:13:33 +00:00
|
|
|
if(S_AL_HearingThroughEntity(entnum))
|
|
|
|
{
|
|
|
|
S_AL_StartLocalSound(sfx, entchannel);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VectorCopy(entityList[entnum].origin, sorigin);
|
|
|
|
}
|
|
|
|
|
|
|
|
S_AL_SanitiseVector(sorigin);
|
|
|
|
|
|
|
|
if((srcActiveCnt > 5 * srcCount / 3) &&
|
|
|
|
(DistanceSquared(sorigin, lastListenerOrigin) >=
|
|
|
|
(s_alMaxDistance->value + s_alGraceDistance->value) * (s_alMaxDistance->value + s_alGraceDistance->value)))
|
|
|
|
{
|
|
|
|
// We're getting tight on sources and source is not within hearing distance so don't add it
|
2006-11-25 13:35:23 +00:00
|
|
|
return;
|
2009-10-27 11:13:33 +00:00
|
|
|
}
|
2006-11-25 13:35:23 +00:00
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
// Try to grab a source
|
2007-01-07 16:03:19 +00:00
|
|
|
src = S_AL_SrcAlloc(SRCPRI_ONESHOT, entnum, entchannel);
|
2005-11-13 18:58:14 +00:00
|
|
|
if(src == -1)
|
|
|
|
return;
|
|
|
|
|
2009-10-27 11:13:33 +00:00
|
|
|
S_AL_SrcSetup(src, sfx, SRCPRI_ONESHOT, entnum, entchannel, qfalse);
|
|
|
|
|
|
|
|
curSource = &srcList[src];
|
2006-02-28 21:52:25 +00:00
|
|
|
|
2009-10-27 11:13:33 +00:00
|
|
|
if(!origin)
|
|
|
|
curSource->isTracking = qtrue;
|
|
|
|
|
|
|
|
qalSourcefv(curSource->alSource, AL_POSITION, sorigin );
|
|
|
|
S_AL_ScaleGain(curSource, sorigin);
|
2005-11-13 18:58:14 +00:00
|
|
|
|
|
|
|
// Start it playing
|
2009-10-27 11:13:33 +00:00
|
|
|
curSource->isPlaying = qtrue;
|
|
|
|
qalSourcePlay(curSource->alSource);
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_ClearLoopingSounds
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
void S_AL_ClearLoopingSounds( qboolean killall )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < srcCount; i++)
|
|
|
|
{
|
|
|
|
if((srcList[i].isLooping) && (srcList[i].entity != -1))
|
2005-12-01 18:22:42 +00:00
|
|
|
entityList[srcList[i].entity].loopAddedThisFrame = qfalse;
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_SrcLoop
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
static void S_AL_SrcLoop( alSrcPriority_t priority, sfxHandle_t sfx,
|
2005-12-01 18:22:42 +00:00
|
|
|
const vec3_t origin, const vec3_t velocity, int entityNum )
|
2005-11-13 18:58:14 +00:00
|
|
|
{
|
2005-12-01 18:22:42 +00:00
|
|
|
int src;
|
|
|
|
sentity_t *sent = &entityList[ entityNum ];
|
2006-11-03 08:22:38 +00:00
|
|
|
src_t *curSource;
|
2009-10-26 05:02:18 +00:00
|
|
|
vec3_t sorigin, svelocity;
|
|
|
|
|
|
|
|
if(S_AL_CheckInput(entityNum, sfx))
|
|
|
|
return;
|
2005-11-13 18:58:14 +00:00
|
|
|
|
2005-12-01 18:22:42 +00:00
|
|
|
// Do we need to allocate a new source for this entity
|
|
|
|
if( !sent->srcAllocated )
|
2005-11-13 18:58:14 +00:00
|
|
|
{
|
|
|
|
// Try to get a channel
|
2005-12-01 18:22:42 +00:00
|
|
|
src = S_AL_SrcAlloc( priority, entityNum, -1 );
|
|
|
|
if( src == -1 )
|
|
|
|
{
|
2005-12-11 21:14:45 +00:00
|
|
|
Com_DPrintf( S_COLOR_YELLOW "WARNING: Failed to allocate source "
|
2005-12-01 18:22:42 +00:00
|
|
|
"for loop sfx %d on entity %d\n", sfx, entityNum );
|
2005-11-13 18:58:14 +00:00
|
|
|
return;
|
2005-12-01 18:22:42 +00:00
|
|
|
}
|
|
|
|
|
2009-10-27 11:13:33 +00:00
|
|
|
curSource = &srcList[src];
|
|
|
|
|
2005-12-01 18:22:42 +00:00
|
|
|
sent->startLoopingSound = qtrue;
|
2009-10-27 11:13:33 +00:00
|
|
|
|
|
|
|
curSource->lastTimePos = -1.0;
|
|
|
|
curSource->lastSampleTime = Sys_Milliseconds();
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
else
|
2009-10-27 11:13:33 +00:00
|
|
|
{
|
2005-12-01 18:22:42 +00:00
|
|
|
src = sent->srcIndex;
|
2009-10-27 11:13:33 +00:00
|
|
|
curSource = &srcList[src];
|
|
|
|
}
|
2005-11-13 18:58:14 +00:00
|
|
|
|
2005-12-01 18:22:42 +00:00
|
|
|
sent->srcAllocated = qtrue;
|
|
|
|
sent->srcIndex = src;
|
2005-11-13 18:58:14 +00:00
|
|
|
|
2005-12-01 18:22:42 +00:00
|
|
|
sent->loopPriority = priority;
|
|
|
|
sent->loopSfx = sfx;
|
|
|
|
|
2009-10-23 23:32:52 +00:00
|
|
|
// If this is not set then the looping sound is stopped.
|
2005-12-01 18:22:42 +00:00
|
|
|
sent->loopAddedThisFrame = qtrue;
|
2005-11-13 18:58:14 +00:00
|
|
|
|
2005-12-01 18:22:42 +00:00
|
|
|
// UGH
|
|
|
|
// These lines should be called via S_AL_SrcSetup, but we
|
|
|
|
// can't call that yet as it buffers sfxes that may change
|
|
|
|
// with subsequent calls to S_AL_SrcLoop
|
2006-11-03 08:22:38 +00:00
|
|
|
curSource->entity = entityNum;
|
|
|
|
curSource->isLooping = qtrue;
|
2005-11-13 18:58:14 +00:00
|
|
|
|
2006-02-28 21:52:25 +00:00
|
|
|
if( S_AL_HearingThroughEntity( entityNum ) )
|
|
|
|
{
|
2006-11-03 08:22:38 +00:00
|
|
|
curSource->local = qtrue;
|
2006-02-28 21:52:25 +00:00
|
|
|
|
2009-10-26 05:02:18 +00:00
|
|
|
VectorClear(sorigin);
|
|
|
|
|
|
|
|
qalSourcefv(curSource->alSource, AL_POSITION, sorigin);
|
|
|
|
qalSourcefv(curSource->alSource, AL_VELOCITY, sorigin);
|
2006-02-28 21:52:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-11-03 08:22:38 +00:00
|
|
|
curSource->local = qfalse;
|
2006-02-28 21:52:25 +00:00
|
|
|
|
2009-10-26 05:02:18 +00:00
|
|
|
if(origin)
|
|
|
|
VectorCopy(origin, sorigin);
|
|
|
|
else
|
|
|
|
VectorCopy(sent->origin, sorigin);
|
|
|
|
|
|
|
|
S_AL_SanitiseVector(sorigin);
|
2006-11-03 08:22:38 +00:00
|
|
|
|
2009-10-26 05:02:18 +00:00
|
|
|
VectorCopy(sorigin, curSource->loopSpeakerPos);
|
|
|
|
|
|
|
|
if(velocity)
|
|
|
|
{
|
|
|
|
VectorCopy(velocity, svelocity);
|
|
|
|
S_AL_SanitiseVector(svelocity);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
VectorClear(svelocity);
|
2006-11-03 08:22:38 +00:00
|
|
|
|
2009-10-26 05:02:18 +00:00
|
|
|
qalSourcefv( curSource->alSource, AL_POSITION, (ALfloat *)sorigin );
|
|
|
|
qalSourcefv( curSource->alSource, AL_VELOCITY, (ALfloat *)velocity );
|
|
|
|
}
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_AddLoopingSound
|
|
|
|
=================
|
|
|
|
*/
|
2009-10-26 05:02:18 +00:00
|
|
|
static void S_AL_AddLoopingSound(int entityNum, const vec3_t origin, const vec3_t velocity, sfxHandle_t sfx)
|
2005-11-13 18:58:14 +00:00
|
|
|
{
|
2009-10-26 05:02:18 +00:00
|
|
|
S_AL_SrcLoop(SRCPRI_ENTITY, sfx, origin, velocity, entityNum);
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_AddRealLoopingSound
|
|
|
|
=================
|
|
|
|
*/
|
2009-10-26 05:02:18 +00:00
|
|
|
static void S_AL_AddRealLoopingSound(int entityNum, const vec3_t origin, const vec3_t velocity, sfxHandle_t sfx)
|
2005-11-13 18:58:14 +00:00
|
|
|
{
|
2009-10-26 05:02:18 +00:00
|
|
|
S_AL_SrcLoop(SRCPRI_AMBIENT, sfx, origin, velocity, entityNum);
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_StopLoopingSound
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
void S_AL_StopLoopingSound(int entityNum )
|
|
|
|
{
|
2005-12-01 18:22:42 +00:00
|
|
|
if(entityList[entityNum].srcAllocated)
|
|
|
|
S_AL_SrcKill(entityList[entityNum].srcIndex);
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_SrcUpdate
|
|
|
|
|
|
|
|
Update state (move things around, manage sources, and so on)
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
void S_AL_SrcUpdate( void )
|
|
|
|
{
|
|
|
|
int i;
|
2005-12-01 18:22:42 +00:00
|
|
|
int entityNum;
|
2005-11-13 18:58:14 +00:00
|
|
|
ALint state;
|
2009-10-27 11:13:33 +00:00
|
|
|
src_t *curSource;
|
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
for(i = 0; i < srcCount; i++)
|
|
|
|
{
|
2005-12-01 18:22:42 +00:00
|
|
|
entityNum = srcList[i].entity;
|
2006-11-03 08:22:38 +00:00
|
|
|
curSource = &srcList[i];
|
2005-12-01 18:22:42 +00:00
|
|
|
|
2006-11-03 08:22:38 +00:00
|
|
|
if(curSource->isLocked)
|
2005-11-13 18:58:14 +00:00
|
|
|
continue;
|
|
|
|
|
2006-11-03 08:22:38 +00:00
|
|
|
if(!curSource->isActive)
|
2005-11-13 18:58:14 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Update source parameters
|
2009-10-23 12:18:49 +00:00
|
|
|
if((s_alGain->modified) || (s_volume->modified))
|
2006-11-03 08:22:38 +00:00
|
|
|
curSource->curGain = s_alGain->value * s_volume->value;
|
2009-10-23 12:18:49 +00:00
|
|
|
if((s_alRolloff->modified) && (!curSource->local))
|
2006-11-03 08:22:38 +00:00
|
|
|
qalSourcef(curSource->alSource, AL_ROLLOFF_FACTOR, s_alRolloff->value);
|
2005-11-13 18:58:14 +00:00
|
|
|
if(s_alMinDistance->modified)
|
2006-11-03 08:22:38 +00:00
|
|
|
qalSourcef(curSource->alSource, AL_REFERENCE_DISTANCE, s_alMinDistance->value);
|
2005-11-13 18:58:14 +00:00
|
|
|
|
2006-11-03 08:22:38 +00:00
|
|
|
if(curSource->isLooping)
|
2005-11-13 18:58:14 +00:00
|
|
|
{
|
2005-12-01 18:22:42 +00:00
|
|
|
sentity_t *sent = &entityList[ entityNum ];
|
|
|
|
|
2009-10-26 05:02:18 +00:00
|
|
|
// If a looping effect hasn't been touched this frame, pause or kill it
|
2006-11-03 08:22:38 +00:00
|
|
|
if(sent->loopAddedThisFrame)
|
2005-11-13 18:58:14 +00:00
|
|
|
{
|
2009-10-26 05:02:18 +00:00
|
|
|
alSfx_t *curSfx;
|
|
|
|
|
2005-12-01 18:22:42 +00:00
|
|
|
// The sound has changed without an intervening removal
|
2006-11-03 08:22:38 +00:00
|
|
|
if(curSource->isActive && !sent->startLoopingSound &&
|
|
|
|
curSource->sfx != sent->loopSfx)
|
2005-12-01 18:22:42 +00:00
|
|
|
{
|
2009-10-23 23:32:52 +00:00
|
|
|
S_AL_NewLoopMaster(curSource, qtrue);
|
|
|
|
|
|
|
|
curSource->isPlaying = qfalse;
|
2006-11-03 08:22:38 +00:00
|
|
|
qalSourceStop(curSource->alSource);
|
|
|
|
qalSourcei(curSource->alSource, AL_BUFFER, 0);
|
2005-12-01 18:22:42 +00:00
|
|
|
sent->startLoopingSound = qtrue;
|
|
|
|
}
|
|
|
|
|
2006-11-03 08:22:38 +00:00
|
|
|
// The sound hasn't been started yet
|
|
|
|
if(sent->startLoopingSound)
|
2005-12-01 18:22:42 +00:00
|
|
|
{
|
2006-11-03 08:22:38 +00:00
|
|
|
S_AL_SrcSetup(i, sent->loopSfx, sent->loopPriority,
|
|
|
|
entityNum, -1, curSource->local);
|
|
|
|
curSource->isLooping = qtrue;
|
2009-10-23 12:18:49 +00:00
|
|
|
|
2009-10-23 23:32:52 +00:00
|
|
|
knownSfx[curSource->sfx].loopCnt++;
|
|
|
|
sent->startLoopingSound = qfalse;
|
|
|
|
}
|
|
|
|
|
2009-10-26 05:02:18 +00:00
|
|
|
curSfx = &knownSfx[curSource->sfx];
|
|
|
|
|
|
|
|
S_AL_ScaleGain(curSource, curSource->loopSpeakerPos);
|
|
|
|
if(!curSource->scaleGain)
|
2009-10-23 23:32:52 +00:00
|
|
|
{
|
2009-10-26 05:02:18 +00:00
|
|
|
if(curSource->isPlaying)
|
|
|
|
{
|
|
|
|
// Sound is mute, stop playback until we are in range again
|
|
|
|
S_AL_NewLoopMaster(curSource, qfalse);
|
|
|
|
qalSourceStop(curSource->alSource);
|
|
|
|
curSource->isPlaying = qfalse;
|
|
|
|
}
|
|
|
|
else if(!curSfx->loopActiveCnt && curSfx->masterLoopSrc < 0)
|
|
|
|
curSfx->masterLoopSrc = i;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
2009-10-23 12:18:49 +00:00
|
|
|
|
2009-10-26 05:02:18 +00:00
|
|
|
if(!curSource->isPlaying)
|
|
|
|
{
|
2009-10-27 11:13:33 +00:00
|
|
|
if(curSource->priority == SRCPRI_AMBIENT)
|
2009-10-23 23:32:52 +00:00
|
|
|
{
|
2009-10-27 11:13:33 +00:00
|
|
|
// If there are other ambient looping sources with the same sound,
|
|
|
|
// make sure the sound of these sources are in sync.
|
|
|
|
|
|
|
|
if(curSfx->loopActiveCnt)
|
|
|
|
{
|
|
|
|
int offset, error;
|
|
|
|
|
|
|
|
// we already have a master loop playing, get buffer position.
|
|
|
|
S_AL_ClearError(qfalse);
|
|
|
|
qalGetSourcei(srcList[curSfx->masterLoopSrc].alSource, AL_SAMPLE_OFFSET, &offset);
|
|
|
|
if((error = qalGetError()) != AL_NO_ERROR)
|
|
|
|
{
|
|
|
|
if(error != AL_INVALID_ENUM)
|
|
|
|
{
|
|
|
|
Com_Printf(S_COLOR_YELLOW "WARNING: Cannot get sample offset from source %d: "
|
|
|
|
"%s\n", i, S_AL_ErrorMsg(error));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
qalSourcei(curSource->alSource, AL_SAMPLE_OFFSET, offset);
|
|
|
|
}
|
|
|
|
else if(curSfx->loopCnt && curSfx->masterLoopSrc >= 0)
|
|
|
|
{
|
|
|
|
float secofs;
|
2009-10-23 12:18:49 +00:00
|
|
|
|
2009-10-27 11:13:33 +00:00
|
|
|
src_t *master = &srcList[curSfx->masterLoopSrc];
|
|
|
|
// This loop sound used to be played, but all sources are stopped. Use last sample position/time
|
|
|
|
// to calculate offset so the player thinks the sources continued playing while they were inaudible.
|
|
|
|
|
|
|
|
if(master->lastTimePos >= 0)
|
|
|
|
{
|
|
|
|
secofs = master->lastTimePos + (Sys_Milliseconds() - master->lastSampleTime) / 1000.0f;
|
|
|
|
secofs = fmodf(secofs, (float) curSfx->info.samples / curSfx->info.rate);
|
|
|
|
|
|
|
|
qalSourcef(curSource->alSource, AL_SEC_OFFSET, secofs);
|
|
|
|
}
|
|
|
|
|
|
|
|
// I be the master now
|
|
|
|
curSfx->masterLoopSrc = i;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
curSfx->masterLoopSrc = i;
|
2009-10-23 12:18:49 +00:00
|
|
|
}
|
2009-10-27 11:13:33 +00:00
|
|
|
else if(curSource->lastTimePos >= 0)
|
2009-10-23 23:32:52 +00:00
|
|
|
{
|
|
|
|
float secofs;
|
|
|
|
|
2009-10-27 11:13:33 +00:00
|
|
|
// For unsynced loops (SRCPRI_ENTITY) just carry on playing as if the sound was never stopped
|
2009-10-23 23:32:52 +00:00
|
|
|
|
2009-10-27 11:13:33 +00:00
|
|
|
secofs = curSource->lastTimePos + (Sys_Milliseconds() - curSource->lastSampleTime) / 1000.0f;
|
2009-10-26 05:02:18 +00:00
|
|
|
secofs = fmodf(secofs, (float) curSfx->info.samples / curSfx->info.rate);
|
2009-10-23 23:32:52 +00:00
|
|
|
qalSourcef(curSource->alSource, AL_SEC_OFFSET, secofs);
|
|
|
|
}
|
|
|
|
|
|
|
|
curSfx->loopActiveCnt++;
|
2009-10-23 12:18:49 +00:00
|
|
|
|
2006-11-03 08:22:38 +00:00
|
|
|
qalSourcei(curSource->alSource, AL_LOOPING, AL_TRUE);
|
2009-10-23 23:32:52 +00:00
|
|
|
curSource->isPlaying = qtrue;
|
2006-11-03 08:22:38 +00:00
|
|
|
qalSourcePlay(curSource->alSource);
|
2005-12-01 18:22:42 +00:00
|
|
|
}
|
2006-02-28 21:52:25 +00:00
|
|
|
|
|
|
|
// Update locality
|
2006-11-03 08:22:38 +00:00
|
|
|
if(curSource->local)
|
2006-02-28 21:52:25 +00:00
|
|
|
{
|
2006-11-03 08:22:38 +00:00
|
|
|
qalSourcei(curSource->alSource, AL_SOURCE_RELATIVE, AL_TRUE);
|
|
|
|
qalSourcef(curSource->alSource, AL_ROLLOFF_FACTOR, 0.0f);
|
2006-02-28 21:52:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-11-03 08:22:38 +00:00
|
|
|
qalSourcei(curSource->alSource, AL_SOURCE_RELATIVE, AL_FALSE);
|
|
|
|
qalSourcef(curSource->alSource, AL_ROLLOFF_FACTOR, s_alRolloff->value);
|
2006-02-28 21:52:25 +00:00
|
|
|
}
|
2009-10-23 12:18:49 +00:00
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
2009-10-26 05:02:18 +00:00
|
|
|
else if(curSource->priority == SRCPRI_AMBIENT)
|
2009-10-23 12:18:49 +00:00
|
|
|
{
|
2009-10-26 05:02:18 +00:00
|
|
|
if(curSource->isPlaying)
|
|
|
|
{
|
|
|
|
S_AL_NewLoopMaster(curSource, qfalse);
|
|
|
|
qalSourceStop(curSource->alSource);
|
|
|
|
curSource->isPlaying = qfalse;
|
|
|
|
}
|
2009-10-23 12:18:49 +00:00
|
|
|
}
|
2009-10-26 05:02:18 +00:00
|
|
|
else
|
|
|
|
S_AL_SrcKill(i);
|
2005-12-01 18:22:42 +00:00
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2005-12-01 18:22:42 +00:00
|
|
|
// Check if it's done, and flag it
|
2006-11-03 08:22:38 +00:00
|
|
|
qalGetSourcei(curSource->alSource, AL_SOURCE_STATE, &state);
|
2005-12-01 18:22:42 +00:00
|
|
|
if(state == AL_STOPPED)
|
2005-11-13 18:58:14 +00:00
|
|
|
{
|
2009-10-24 08:33:12 +00:00
|
|
|
curSource->isPlaying = qfalse;
|
2005-12-01 18:22:42 +00:00
|
|
|
S_AL_SrcKill(i);
|
|
|
|
continue;
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
2006-11-03 08:22:38 +00:00
|
|
|
|
|
|
|
// Query relativity of source, don't move if it's true
|
|
|
|
qalGetSourcei(curSource->alSource, AL_SOURCE_RELATIVE, &state);
|
|
|
|
|
|
|
|
// See if it needs to be moved
|
|
|
|
if(curSource->isTracking && !state)
|
|
|
|
{
|
|
|
|
qalSourcefv(curSource->alSource, AL_POSITION, entityList[entityNum].origin);
|
|
|
|
S_AL_ScaleGain(curSource, entityList[entityNum].origin);
|
|
|
|
}
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_SrcShutup
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
void S_AL_SrcShutup( void )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < srcCount; i++)
|
|
|
|
S_AL_SrcKill(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_SrcGet
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
ALuint S_AL_SrcGet(srcHandle_t src)
|
|
|
|
{
|
2005-12-01 18:22:42 +00:00
|
|
|
return srcList[src].alSource;
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
|
2008-06-01 07:51:23 +00:00
|
|
|
static srcHandle_t streamSourceHandles[MAX_RAW_STREAMS];
|
|
|
|
static qboolean streamPlaying[MAX_RAW_STREAMS];
|
|
|
|
static ALuint streamSources[MAX_RAW_STREAMS];
|
2005-11-13 18:58:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_AllocateStreamChannel
|
|
|
|
=================
|
|
|
|
*/
|
2008-06-01 07:51:23 +00:00
|
|
|
static void S_AL_AllocateStreamChannel( int stream )
|
2005-11-13 18:58:14 +00:00
|
|
|
{
|
2008-06-01 07:51:23 +00:00
|
|
|
if ((stream < 0) || (stream >= MAX_RAW_STREAMS))
|
|
|
|
return;
|
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
// Allocate a streamSource at high priority
|
2008-06-01 07:51:23 +00:00
|
|
|
streamSourceHandles[stream] = S_AL_SrcAlloc(SRCPRI_STREAM, -2, 0);
|
|
|
|
if(streamSourceHandles[stream] == -1)
|
2005-11-13 18:58:14 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Lock the streamSource so nobody else can use it, and get the raw streamSource
|
2008-06-01 07:51:23 +00:00
|
|
|
S_AL_SrcLock(streamSourceHandles[stream]);
|
|
|
|
streamSources[stream] = S_AL_SrcGet(streamSourceHandles[stream]);
|
2005-11-13 18:58:14 +00:00
|
|
|
|
2009-11-10 01:08:15 +00:00
|
|
|
// make sure that after unmuting the S_AL_Gain in S_Update() does not turn
|
|
|
|
// volume up prematurely for this source
|
|
|
|
srcList[streamSourceHandles[stream]].scaleGain = 0.0f;
|
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
// Set some streamSource parameters
|
2008-06-01 07:51:23 +00:00
|
|
|
qalSourcei (streamSources[stream], AL_BUFFER, 0 );
|
|
|
|
qalSourcei (streamSources[stream], AL_LOOPING, AL_FALSE );
|
|
|
|
qalSource3f(streamSources[stream], AL_POSITION, 0.0, 0.0, 0.0);
|
|
|
|
qalSource3f(streamSources[stream], AL_VELOCITY, 0.0, 0.0, 0.0);
|
|
|
|
qalSource3f(streamSources[stream], AL_DIRECTION, 0.0, 0.0, 0.0);
|
|
|
|
qalSourcef (streamSources[stream], AL_ROLLOFF_FACTOR, 0.0 );
|
|
|
|
qalSourcei (streamSources[stream], AL_SOURCE_RELATIVE, AL_TRUE );
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_FreeStreamChannel
|
|
|
|
=================
|
|
|
|
*/
|
2008-06-01 07:51:23 +00:00
|
|
|
static void S_AL_FreeStreamChannel( int stream )
|
2005-11-13 18:58:14 +00:00
|
|
|
{
|
2008-06-01 07:51:23 +00:00
|
|
|
if ((stream < 0) || (stream >= MAX_RAW_STREAMS))
|
|
|
|
return;
|
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
// Release the output streamSource
|
2008-06-01 07:51:23 +00:00
|
|
|
S_AL_SrcUnlock(streamSourceHandles[stream]);
|
|
|
|
streamSources[stream] = 0;
|
|
|
|
streamSourceHandles[stream] = -1;
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_RawSamples
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2008-06-01 07:51:23 +00:00
|
|
|
void S_AL_RawSamples(int stream, int samples, int rate, int width, int channels, const byte *data, float volume)
|
2005-11-13 18:58:14 +00:00
|
|
|
{
|
|
|
|
ALuint buffer;
|
2005-12-01 18:22:42 +00:00
|
|
|
ALuint format;
|
2005-11-13 18:58:14 +00:00
|
|
|
|
2008-06-01 07:51:23 +00:00
|
|
|
if ((stream < 0) || (stream >= MAX_RAW_STREAMS))
|
|
|
|
return;
|
|
|
|
|
2005-12-01 18:22:42 +00:00
|
|
|
format = S_AL_Format( width, channels );
|
2005-11-13 18:58:14 +00:00
|
|
|
|
|
|
|
// Create the streamSource if necessary
|
2008-06-01 07:51:23 +00:00
|
|
|
if(streamSourceHandles[stream] == -1)
|
2005-11-13 18:58:14 +00:00
|
|
|
{
|
2008-06-01 07:51:23 +00:00
|
|
|
S_AL_AllocateStreamChannel(stream);
|
2005-11-13 18:58:14 +00:00
|
|
|
|
|
|
|
// Failed?
|
2008-06-01 07:51:23 +00:00
|
|
|
if(streamSourceHandles[stream] == -1)
|
2005-11-13 18:58:14 +00:00
|
|
|
{
|
2005-11-30 01:57:53 +00:00
|
|
|
Com_Printf( S_COLOR_RED "ERROR: Can't allocate streaming streamSource\n");
|
2005-11-13 18:58:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a buffer, and stuff the data into it
|
|
|
|
qalGenBuffers(1, &buffer);
|
2005-11-26 15:01:28 +00:00
|
|
|
qalBufferData(buffer, format, (ALvoid *)data, (samples * width * channels), rate);
|
2005-11-13 18:58:14 +00:00
|
|
|
|
|
|
|
// Shove the data onto the streamSource
|
2008-06-01 07:51:23 +00:00
|
|
|
qalSourceQueueBuffers(streamSources[stream], 1, &buffer);
|
2005-11-13 18:58:14 +00:00
|
|
|
|
|
|
|
// Volume
|
2009-11-10 01:08:15 +00:00
|
|
|
S_AL_Gain (streamSources[stream], volume * s_volume->value * s_alGain->value);
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_StreamUpdate
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2008-06-01 07:51:23 +00:00
|
|
|
void S_AL_StreamUpdate( int stream )
|
2005-11-13 18:58:14 +00:00
|
|
|
{
|
2005-12-03 00:19:27 +00:00
|
|
|
int numBuffers;
|
|
|
|
ALint state;
|
2005-11-13 18:58:14 +00:00
|
|
|
|
2008-06-01 07:51:23 +00:00
|
|
|
if ((stream < 0) || (stream >= MAX_RAW_STREAMS))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(streamSourceHandles[stream] == -1)
|
2005-11-13 18:58:14 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Un-queue any buffers, and delete them
|
2008-06-01 07:51:23 +00:00
|
|
|
qalGetSourcei( streamSources[stream], AL_BUFFERS_PROCESSED, &numBuffers );
|
2005-12-03 00:19:27 +00:00
|
|
|
while( numBuffers-- )
|
2005-11-13 18:58:14 +00:00
|
|
|
{
|
2005-12-03 00:19:27 +00:00
|
|
|
ALuint buffer;
|
2008-06-01 07:51:23 +00:00
|
|
|
qalSourceUnqueueBuffers(streamSources[stream], 1, &buffer);
|
2005-12-03 00:19:27 +00:00
|
|
|
qalDeleteBuffers(1, &buffer);
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
|
2005-12-03 00:19:27 +00:00
|
|
|
// Start the streamSource playing if necessary
|
2008-06-01 07:51:23 +00:00
|
|
|
qalGetSourcei( streamSources[stream], AL_BUFFERS_QUEUED, &numBuffers );
|
2005-12-03 00:19:27 +00:00
|
|
|
|
2008-06-01 07:51:23 +00:00
|
|
|
qalGetSourcei(streamSources[stream], AL_SOURCE_STATE, &state);
|
2005-11-13 18:58:14 +00:00
|
|
|
if(state == AL_STOPPED)
|
|
|
|
{
|
2008-06-01 07:51:23 +00:00
|
|
|
streamPlaying[stream] = qfalse;
|
2005-12-03 16:36:45 +00:00
|
|
|
|
|
|
|
// If there are no buffers queued up, release the streamSource
|
2005-12-03 00:19:27 +00:00
|
|
|
if( !numBuffers )
|
2008-06-01 07:51:23 +00:00
|
|
|
S_AL_FreeStreamChannel( stream );
|
2005-12-03 00:19:27 +00:00
|
|
|
}
|
|
|
|
|
2008-06-01 07:51:23 +00:00
|
|
|
if( !streamPlaying[stream] && numBuffers )
|
2005-12-03 00:19:27 +00:00
|
|
|
{
|
2008-06-01 07:51:23 +00:00
|
|
|
qalSourcePlay( streamSources[stream] );
|
|
|
|
streamPlaying[stream] = qtrue;
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_StreamDie
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2008-06-01 07:51:23 +00:00
|
|
|
void S_AL_StreamDie( int stream )
|
2005-11-13 18:58:14 +00:00
|
|
|
{
|
2009-03-15 12:39:53 +00:00
|
|
|
int numBuffers;
|
|
|
|
|
2008-06-01 07:51:23 +00:00
|
|
|
if ((stream < 0) || (stream >= MAX_RAW_STREAMS))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(streamSourceHandles[stream] == -1)
|
2005-11-13 18:58:14 +00:00
|
|
|
return;
|
|
|
|
|
2008-06-01 07:51:23 +00:00
|
|
|
streamPlaying[stream] = qfalse;
|
|
|
|
qalSourceStop(streamSources[stream]);
|
2009-03-15 12:39:53 +00:00
|
|
|
|
|
|
|
// Un-queue any buffers, and delete them
|
|
|
|
qalGetSourcei( streamSources[stream], AL_BUFFERS_PROCESSED, &numBuffers );
|
|
|
|
while( numBuffers-- )
|
|
|
|
{
|
|
|
|
ALuint buffer;
|
|
|
|
qalSourceUnqueueBuffers(streamSources[stream], 1, &buffer);
|
|
|
|
qalDeleteBuffers(1, &buffer);
|
|
|
|
}
|
|
|
|
|
2008-06-01 07:51:23 +00:00
|
|
|
S_AL_FreeStreamChannel(stream);
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
|
|
|
|
#define NUM_MUSIC_BUFFERS 4
|
|
|
|
#define MUSIC_BUFFER_SIZE 4096
|
|
|
|
|
|
|
|
static qboolean musicPlaying = qfalse;
|
|
|
|
static srcHandle_t musicSourceHandle = -1;
|
|
|
|
static ALuint musicSource;
|
|
|
|
static ALuint musicBuffers[NUM_MUSIC_BUFFERS];
|
|
|
|
|
|
|
|
static snd_stream_t *mus_stream;
|
2006-08-27 15:31:03 +00:00
|
|
|
static snd_stream_t *intro_stream;
|
2005-11-13 18:58:14 +00:00
|
|
|
static char s_backgroundLoop[MAX_QPATH];
|
|
|
|
|
|
|
|
static byte decode_buffer[MUSIC_BUFFER_SIZE];
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_MusicSourceGet
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
static void S_AL_MusicSourceGet( void )
|
|
|
|
{
|
|
|
|
// Allocate a musicSource at high priority
|
|
|
|
musicSourceHandle = S_AL_SrcAlloc(SRCPRI_STREAM, -2, 0);
|
|
|
|
if(musicSourceHandle == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Lock the musicSource so nobody else can use it, and get the raw musicSource
|
|
|
|
S_AL_SrcLock(musicSourceHandle);
|
|
|
|
musicSource = S_AL_SrcGet(musicSourceHandle);
|
|
|
|
|
2009-11-10 01:08:15 +00:00
|
|
|
// make sure that after unmuting the S_AL_Gain in S_Update() does not turn
|
|
|
|
// volume up prematurely for this source
|
|
|
|
srcList[musicSourceHandle].scaleGain = 0.0f;
|
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
// Set some musicSource parameters
|
|
|
|
qalSource3f(musicSource, AL_POSITION, 0.0, 0.0, 0.0);
|
|
|
|
qalSource3f(musicSource, AL_VELOCITY, 0.0, 0.0, 0.0);
|
|
|
|
qalSource3f(musicSource, AL_DIRECTION, 0.0, 0.0, 0.0);
|
|
|
|
qalSourcef (musicSource, AL_ROLLOFF_FACTOR, 0.0 );
|
|
|
|
qalSourcei (musicSource, AL_SOURCE_RELATIVE, AL_TRUE );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_MusicSourceFree
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
static void S_AL_MusicSourceFree( void )
|
|
|
|
{
|
|
|
|
// Release the output musicSource
|
|
|
|
S_AL_SrcUnlock(musicSourceHandle);
|
|
|
|
musicSource = 0;
|
|
|
|
musicSourceHandle = -1;
|
|
|
|
}
|
|
|
|
|
2006-08-27 15:31:03 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_CloseMusicFiles
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
static void S_AL_CloseMusicFiles(void)
|
|
|
|
{
|
|
|
|
if(intro_stream)
|
|
|
|
{
|
|
|
|
S_CodecCloseStream(intro_stream);
|
|
|
|
intro_stream = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mus_stream)
|
|
|
|
{
|
|
|
|
S_CodecCloseStream(mus_stream);
|
|
|
|
mus_stream = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_StopBackgroundTrack
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
void S_AL_StopBackgroundTrack( void )
|
|
|
|
{
|
|
|
|
if(!musicPlaying)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Stop playing
|
|
|
|
qalSourceStop(musicSource);
|
|
|
|
|
|
|
|
// De-queue the musicBuffers
|
|
|
|
qalSourceUnqueueBuffers(musicSource, NUM_MUSIC_BUFFERS, musicBuffers);
|
|
|
|
|
|
|
|
// Destroy the musicBuffers
|
|
|
|
qalDeleteBuffers(NUM_MUSIC_BUFFERS, musicBuffers);
|
|
|
|
|
|
|
|
// Free the musicSource
|
|
|
|
S_AL_MusicSourceFree();
|
|
|
|
|
|
|
|
// Unload the stream
|
2006-08-27 15:31:03 +00:00
|
|
|
S_AL_CloseMusicFiles();
|
2005-11-13 18:58:14 +00:00
|
|
|
|
|
|
|
musicPlaying = qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_MusicProcess
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
void S_AL_MusicProcess(ALuint b)
|
|
|
|
{
|
2005-11-30 01:57:53 +00:00
|
|
|
ALenum error;
|
2005-11-13 18:58:14 +00:00
|
|
|
int l;
|
|
|
|
ALuint format;
|
2006-08-27 15:31:03 +00:00
|
|
|
snd_stream_t *curstream;
|
2005-11-13 18:58:14 +00:00
|
|
|
|
2009-10-13 15:23:17 +00:00
|
|
|
S_AL_ClearError( qfalse );
|
|
|
|
|
2006-08-27 15:31:03 +00:00
|
|
|
if(intro_stream)
|
|
|
|
curstream = intro_stream;
|
|
|
|
else
|
|
|
|
curstream = mus_stream;
|
|
|
|
|
|
|
|
if(!curstream)
|
2006-08-03 02:29:47 +00:00
|
|
|
return;
|
|
|
|
|
2006-08-27 15:31:03 +00:00
|
|
|
l = S_CodecReadStream(curstream, MUSIC_BUFFER_SIZE, decode_buffer);
|
2005-11-13 18:58:14 +00:00
|
|
|
|
2005-11-30 01:57:53 +00:00
|
|
|
// Run out data to read, start at the beginning again
|
2005-11-13 18:58:14 +00:00
|
|
|
if(l == 0)
|
|
|
|
{
|
2006-08-27 15:31:03 +00:00
|
|
|
S_CodecCloseStream(curstream);
|
|
|
|
|
|
|
|
// the intro stream just finished playing so we don't need to reopen
|
|
|
|
// the music stream.
|
|
|
|
if(intro_stream)
|
|
|
|
intro_stream = NULL;
|
|
|
|
else
|
|
|
|
mus_stream = S_CodecOpenStream(s_backgroundLoop);
|
|
|
|
|
|
|
|
curstream = mus_stream;
|
|
|
|
|
|
|
|
if(!curstream)
|
2005-11-13 18:58:14 +00:00
|
|
|
{
|
|
|
|
S_AL_StopBackgroundTrack();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-08-27 15:31:03 +00:00
|
|
|
l = S_CodecReadStream(curstream, MUSIC_BUFFER_SIZE, decode_buffer);
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
|
2006-08-27 15:31:03 +00:00
|
|
|
format = S_AL_Format(curstream->info.width, curstream->info.channels);
|
2005-11-30 01:57:53 +00:00
|
|
|
|
|
|
|
if( l == 0 )
|
|
|
|
{
|
|
|
|
// We have no data to buffer, so buffer silence
|
|
|
|
byte dummyData[ 2 ] = { 0 };
|
|
|
|
|
|
|
|
qalBufferData( b, AL_FORMAT_MONO16, (void *)dummyData, 2, 22050 );
|
|
|
|
}
|
|
|
|
else
|
2006-08-27 15:31:03 +00:00
|
|
|
qalBufferData(b, format, decode_buffer, l, curstream->info.rate);
|
2005-11-30 01:57:53 +00:00
|
|
|
|
|
|
|
if( ( error = qalGetError( ) ) != AL_NO_ERROR )
|
|
|
|
{
|
|
|
|
S_AL_StopBackgroundTrack( );
|
|
|
|
Com_Printf( S_COLOR_RED "ERROR: while buffering data for music stream - %s\n",
|
|
|
|
S_AL_ErrorMsg( error ) );
|
|
|
|
return;
|
|
|
|
}
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_StartBackgroundTrack
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
void S_AL_StartBackgroundTrack( const char *intro, const char *loop )
|
|
|
|
{
|
|
|
|
int i;
|
2006-08-27 15:31:03 +00:00
|
|
|
qboolean issame;
|
2005-11-13 18:58:14 +00:00
|
|
|
|
|
|
|
// Stop any existing music that might be playing
|
|
|
|
S_AL_StopBackgroundTrack();
|
|
|
|
|
2006-11-23 11:10:30 +00:00
|
|
|
if((!intro || !*intro) && (!loop || !*loop))
|
2005-11-13 18:58:14 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Allocate a musicSource
|
|
|
|
S_AL_MusicSourceGet();
|
|
|
|
if(musicSourceHandle == -1)
|
|
|
|
return;
|
|
|
|
|
2006-08-27 15:31:03 +00:00
|
|
|
if (!loop || !*loop)
|
|
|
|
{
|
|
|
|
loop = intro;
|
|
|
|
issame = qtrue;
|
|
|
|
}
|
|
|
|
else if(intro && *intro && !strcmp(intro, loop))
|
|
|
|
issame = qtrue;
|
|
|
|
else
|
|
|
|
issame = qfalse;
|
|
|
|
|
|
|
|
// Copy the loop over
|
|
|
|
strncpy( s_backgroundLoop, loop, sizeof( s_backgroundLoop ) );
|
|
|
|
|
|
|
|
if(!issame)
|
|
|
|
{
|
|
|
|
// Open the intro and don't mind whether it succeeds.
|
|
|
|
// The important part is the loop.
|
|
|
|
intro_stream = S_CodecOpenStream(intro);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
intro_stream = NULL;
|
|
|
|
|
2006-08-03 02:29:47 +00:00
|
|
|
mus_stream = S_CodecOpenStream(s_backgroundLoop);
|
|
|
|
if(!mus_stream)
|
|
|
|
{
|
2006-08-27 15:31:03 +00:00
|
|
|
S_AL_CloseMusicFiles();
|
2006-08-03 02:29:47 +00:00
|
|
|
S_AL_MusicSourceFree();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
// Generate the musicBuffers
|
|
|
|
qalGenBuffers(NUM_MUSIC_BUFFERS, musicBuffers);
|
|
|
|
|
|
|
|
// Queue the musicBuffers up
|
|
|
|
for(i = 0; i < NUM_MUSIC_BUFFERS; i++)
|
2006-02-26 18:47:39 +00:00
|
|
|
{
|
2005-11-13 18:58:14 +00:00
|
|
|
S_AL_MusicProcess(musicBuffers[i]);
|
2006-02-26 18:47:39 +00:00
|
|
|
}
|
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
qalSourceQueueBuffers(musicSource, NUM_MUSIC_BUFFERS, musicBuffers);
|
2005-12-03 00:19:27 +00:00
|
|
|
|
|
|
|
// Set the initial gain property
|
2009-11-10 01:08:15 +00:00
|
|
|
S_AL_Gain(musicSource, s_alGain->value * s_musicVolume->value);
|
2005-11-13 18:58:14 +00:00
|
|
|
|
|
|
|
// Start playing
|
|
|
|
qalSourcePlay(musicSource);
|
|
|
|
|
|
|
|
musicPlaying = qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_MusicUpdate
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
void S_AL_MusicUpdate( void )
|
|
|
|
{
|
2005-12-03 00:19:27 +00:00
|
|
|
int numBuffers;
|
|
|
|
ALint state;
|
2005-11-13 18:58:14 +00:00
|
|
|
|
|
|
|
if(!musicPlaying)
|
|
|
|
return;
|
|
|
|
|
2005-12-03 00:19:27 +00:00
|
|
|
qalGetSourcei( musicSource, AL_BUFFERS_PROCESSED, &numBuffers );
|
|
|
|
while( numBuffers-- )
|
2005-11-13 18:58:14 +00:00
|
|
|
{
|
2005-12-03 00:19:27 +00:00
|
|
|
ALuint b;
|
|
|
|
qalSourceUnqueueBuffers(musicSource, 1, &b);
|
|
|
|
S_AL_MusicProcess(b);
|
|
|
|
qalSourceQueueBuffers(musicSource, 1, &b);
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
|
2005-12-03 00:19:27 +00:00
|
|
|
// Hitches can cause OpenAL to be starved of buffers when streaming.
|
|
|
|
// If this happens, it will stop playback. This restarts the source if
|
|
|
|
// it is no longer playing, and if there are buffers available
|
|
|
|
qalGetSourcei( musicSource, AL_SOURCE_STATE, &state );
|
|
|
|
qalGetSourcei( musicSource, AL_BUFFERS_QUEUED, &numBuffers );
|
|
|
|
if( state == AL_STOPPED && numBuffers )
|
2005-11-13 18:58:14 +00:00
|
|
|
{
|
2005-12-03 00:19:27 +00:00
|
|
|
Com_DPrintf( S_COLOR_YELLOW "Restarted OpenAL music\n" );
|
2005-11-13 18:58:14 +00:00
|
|
|
qalSourcePlay(musicSource);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the gain property
|
2009-11-10 01:08:15 +00:00
|
|
|
S_AL_Gain(musicSource, s_alGain->value * s_musicVolume->value);
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
|
|
|
|
// Local state variables
|
|
|
|
static ALCdevice *alDevice;
|
|
|
|
static ALCcontext *alContext;
|
|
|
|
|
2008-07-07 22:31:39 +00:00
|
|
|
#ifdef USE_VOIP
|
2008-06-01 07:51:23 +00:00
|
|
|
static ALCdevice *alCaptureDevice;
|
|
|
|
static cvar_t *s_alCapture;
|
|
|
|
#endif
|
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#define ALDRIVER_DEFAULT "OpenAL32.dll"
|
2006-08-02 04:01:36 +00:00
|
|
|
#elif defined(MACOS_X)
|
|
|
|
#define ALDRIVER_DEFAULT "/System/Library/Frameworks/OpenAL.framework/OpenAL"
|
2005-11-13 18:58:14 +00:00
|
|
|
#else
|
2009-10-13 15:39:39 +00:00
|
|
|
#define ALDRIVER_DEFAULT "libopenal.so.1"
|
2005-11-13 18:58:14 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_StopAllSounds
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
void S_AL_StopAllSounds( void )
|
|
|
|
{
|
2008-06-01 07:51:23 +00:00
|
|
|
int i;
|
2005-11-13 18:58:14 +00:00
|
|
|
S_AL_SrcShutup();
|
|
|
|
S_AL_StopBackgroundTrack();
|
2008-06-01 07:51:23 +00:00
|
|
|
for (i = 0; i < MAX_RAW_STREAMS; i++)
|
|
|
|
S_AL_StreamDie(i);
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_Respatialize
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
void S_AL_Respatialize( int entityNum, const vec3_t origin, vec3_t axis[3], int inwater )
|
|
|
|
{
|
2006-02-12 10:43:37 +00:00
|
|
|
float velocity[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
float orientation[6];
|
|
|
|
vec3_t sorigin;
|
|
|
|
|
2006-02-28 21:52:25 +00:00
|
|
|
VectorCopy( origin, sorigin );
|
|
|
|
S_AL_SanitiseVector( sorigin );
|
2006-02-07 12:26:53 +00:00
|
|
|
|
|
|
|
S_AL_SanitiseVector( axis[ 0 ] );
|
|
|
|
S_AL_SanitiseVector( axis[ 1 ] );
|
|
|
|
S_AL_SanitiseVector( axis[ 2 ] );
|
|
|
|
|
|
|
|
orientation[0] = axis[0][0]; orientation[1] = axis[0][1]; orientation[2] = axis[0][2];
|
|
|
|
orientation[3] = axis[2][0]; orientation[4] = axis[2][1]; orientation[5] = axis[2][2];
|
2005-11-13 18:58:14 +00:00
|
|
|
|
2006-02-12 10:43:37 +00:00
|
|
|
VectorCopy( sorigin, lastListenerOrigin );
|
2006-01-22 21:09:55 +00:00
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
// Set OpenAL listener paramaters
|
2006-02-12 10:43:37 +00:00
|
|
|
qalListenerfv(AL_POSITION, (ALfloat *)sorigin);
|
2005-11-13 18:58:14 +00:00
|
|
|
qalListenerfv(AL_VELOCITY, velocity);
|
|
|
|
qalListenerfv(AL_ORIENTATION, orientation);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_Update
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
void S_AL_Update( void )
|
|
|
|
{
|
2008-06-01 07:51:23 +00:00
|
|
|
int i;
|
|
|
|
|
2009-11-10 01:08:15 +00:00
|
|
|
if(s_muted->modified)
|
|
|
|
{
|
|
|
|
// muted state changed. Let S_AL_Gain turn up all sources again.
|
|
|
|
for(i = 0; i < srcCount; i++)
|
|
|
|
{
|
|
|
|
if(srcList[i].isActive)
|
|
|
|
S_AL_Gain(srcList[i].alSource, srcList[i].scaleGain);
|
|
|
|
}
|
|
|
|
|
|
|
|
s_muted->modified = qfalse;
|
|
|
|
}
|
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
// Update SFX channels
|
|
|
|
S_AL_SrcUpdate();
|
|
|
|
|
|
|
|
// Update streams
|
2008-06-01 07:51:23 +00:00
|
|
|
for (i = 0; i < MAX_RAW_STREAMS; i++)
|
|
|
|
S_AL_StreamUpdate(i);
|
2005-11-13 18:58:14 +00:00
|
|
|
S_AL_MusicUpdate();
|
|
|
|
|
|
|
|
// Doppler
|
|
|
|
if(s_doppler->modified)
|
|
|
|
{
|
|
|
|
s_alDopplerFactor->modified = qtrue;
|
|
|
|
s_doppler->modified = qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Doppler parameters
|
|
|
|
if(s_alDopplerFactor->modified)
|
|
|
|
{
|
|
|
|
if(s_doppler->integer)
|
|
|
|
qalDopplerFactor(s_alDopplerFactor->value);
|
|
|
|
else
|
|
|
|
qalDopplerFactor(0.0f);
|
|
|
|
s_alDopplerFactor->modified = qfalse;
|
|
|
|
}
|
|
|
|
if(s_alDopplerSpeed->modified)
|
|
|
|
{
|
|
|
|
qalDopplerVelocity(s_alDopplerSpeed->value);
|
|
|
|
s_alDopplerSpeed->modified = qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the modified flags on the other cvars
|
|
|
|
s_alGain->modified = qfalse;
|
|
|
|
s_volume->modified = qfalse;
|
|
|
|
s_musicVolume->modified = qfalse;
|
|
|
|
s_alMinDistance->modified = qfalse;
|
|
|
|
s_alRolloff->modified = qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_DisableSounds
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
void S_AL_DisableSounds( void )
|
|
|
|
{
|
|
|
|
S_AL_StopAllSounds();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_BeginRegistration
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
void S_AL_BeginRegistration( void )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_ClearSoundBuffer
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
void S_AL_ClearSoundBuffer( void )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_SoundList
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
void S_AL_SoundList( void )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-07-07 22:31:39 +00:00
|
|
|
#ifdef USE_VOIP
|
2008-06-01 07:51:23 +00:00
|
|
|
static
|
|
|
|
void S_AL_StartCapture( void )
|
|
|
|
{
|
|
|
|
if (alCaptureDevice != NULL)
|
|
|
|
qalcCaptureStart(alCaptureDevice);
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
int S_AL_AvailableCaptureSamples( void )
|
|
|
|
{
|
|
|
|
int retval = 0;
|
|
|
|
if (alCaptureDevice != NULL)
|
|
|
|
{
|
|
|
|
ALint samples = 0;
|
|
|
|
qalcGetIntegerv(alCaptureDevice, ALC_CAPTURE_SAMPLES, sizeof (samples), &samples);
|
|
|
|
retval = (int) samples;
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void S_AL_Capture( int samples, byte *data )
|
|
|
|
{
|
|
|
|
if (alCaptureDevice != NULL)
|
|
|
|
qalcCaptureSamples(alCaptureDevice, data, samples);
|
|
|
|
}
|
|
|
|
|
|
|
|
void S_AL_StopCapture( void )
|
|
|
|
{
|
|
|
|
if (alCaptureDevice != NULL)
|
|
|
|
qalcCaptureStop(alCaptureDevice);
|
|
|
|
}
|
|
|
|
|
|
|
|
void S_AL_MasterGain( float gain )
|
|
|
|
{
|
|
|
|
qalListenerf(AL_GAIN, gain);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_SoundInfo
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
void S_AL_SoundInfo( void )
|
|
|
|
{
|
|
|
|
Com_Printf( "OpenAL info:\n" );
|
2011-03-09 23:34:15 +00:00
|
|
|
Com_Printf( " Vendor: %s\n", qalGetString( AL_VENDOR ) );
|
|
|
|
Com_Printf( " Version: %s\n", qalGetString( AL_VERSION ) );
|
|
|
|
Com_Printf( " Renderer: %s\n", qalGetString( AL_RENDERER ) );
|
|
|
|
Com_Printf( " AL Extensions: %s\n", qalGetString( AL_EXTENSIONS ) );
|
2008-11-02 17:32:25 +00:00
|
|
|
Com_Printf( " ALC Extensions: %s\n", qalcGetString( alDevice, ALC_EXTENSIONS ) );
|
2011-03-09 12:59:25 +00:00
|
|
|
if(enumeration_ext)
|
2006-08-19 22:17:04 +00:00
|
|
|
{
|
2011-03-09 23:34:15 +00:00
|
|
|
Com_Printf(" Device: %s\n", qalcGetString(alDevice, ALC_DEVICE_SPECIFIER));
|
|
|
|
Com_Printf(" Available Devices:\n%s", s_alAvailableDevices->string);
|
2011-03-08 01:39:34 +00:00
|
|
|
#ifdef USE_VOIP
|
2011-03-09 23:34:15 +00:00
|
|
|
Com_Printf(" Input Device: %s\n", qalcGetString(alCaptureDevice, ALC_DEVICE_SPECIFIER));
|
|
|
|
Com_Printf(" Available Input Devices:\n%s", s_alAvailableInputDevices->string);
|
2011-03-08 01:39:34 +00:00
|
|
|
#endif
|
2006-08-19 22:17:04 +00:00
|
|
|
}
|
2005-11-13 18:58:14 +00:00
|
|
|
}
|
|
|
|
|
2011-03-08 01:39:34 +00:00
|
|
|
|
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_Shutdown
|
|
|
|
=================
|
|
|
|
*/
|
2005-11-19 14:53:46 +00:00
|
|
|
static
|
2005-11-13 18:58:14 +00:00
|
|
|
void S_AL_Shutdown( void )
|
|
|
|
{
|
|
|
|
// Shut down everything
|
2008-06-01 07:51:23 +00:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < MAX_RAW_STREAMS; i++)
|
|
|
|
S_AL_StreamDie(i);
|
2005-11-13 18:58:14 +00:00
|
|
|
S_AL_StopBackgroundTrack( );
|
|
|
|
S_AL_SrcShutdown( );
|
|
|
|
S_AL_BufferShutdown( );
|
|
|
|
|
|
|
|
qalcDestroyContext(alContext);
|
|
|
|
qalcCloseDevice(alDevice);
|
|
|
|
|
2008-07-07 22:31:39 +00:00
|
|
|
#ifdef USE_VOIP
|
2008-06-01 07:51:23 +00:00
|
|
|
if (alCaptureDevice != NULL) {
|
|
|
|
qalcCaptureStop(alCaptureDevice);
|
|
|
|
qalcCaptureCloseDevice(alCaptureDevice);
|
|
|
|
alCaptureDevice = NULL;
|
|
|
|
Com_Printf( "OpenAL capture device closed.\n" );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_RAW_STREAMS; i++) {
|
|
|
|
streamSourceHandles[i] = -1;
|
|
|
|
streamPlaying[i] = qfalse;
|
|
|
|
streamSources[i] = 0;
|
|
|
|
}
|
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
QAL_Shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
S_AL_Init
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
qboolean S_AL_Init( soundInterface_t *si )
|
|
|
|
{
|
2007-09-22 20:32:11 +00:00
|
|
|
#ifdef USE_OPENAL
|
2009-05-08 09:13:06 +00:00
|
|
|
const char* device = NULL;
|
2011-03-08 01:39:34 +00:00
|
|
|
const char* inputdevice = NULL;
|
2008-06-01 07:51:23 +00:00
|
|
|
int i;
|
2006-08-19 11:02:20 +00:00
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
if( !si ) {
|
|
|
|
return qfalse;
|
|
|
|
}
|
|
|
|
|
2008-06-01 07:51:23 +00:00
|
|
|
for (i = 0; i < MAX_RAW_STREAMS; i++) {
|
|
|
|
streamSourceHandles[i] = -1;
|
|
|
|
streamPlaying[i] = qfalse;
|
|
|
|
streamSources[i] = 0;
|
|
|
|
}
|
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
// New console variables
|
2005-12-01 18:22:42 +00:00
|
|
|
s_alPrecache = Cvar_Get( "s_alPrecache", "1", CVAR_ARCHIVE );
|
2008-08-08 18:27:06 +00:00
|
|
|
s_alGain = Cvar_Get( "s_alGain", "1.0", CVAR_ARCHIVE );
|
2005-12-11 21:14:45 +00:00
|
|
|
s_alSources = Cvar_Get( "s_alSources", "96", CVAR_ARCHIVE );
|
2005-11-13 18:58:14 +00:00
|
|
|
s_alDopplerFactor = Cvar_Get( "s_alDopplerFactor", "1.0", CVAR_ARCHIVE );
|
|
|
|
s_alDopplerSpeed = Cvar_Get( "s_alDopplerSpeed", "2200", CVAR_ARCHIVE );
|
2006-01-15 15:45:12 +00:00
|
|
|
s_alMinDistance = Cvar_Get( "s_alMinDistance", "120", CVAR_CHEAT );
|
2006-11-03 08:22:38 +00:00
|
|
|
s_alMaxDistance = Cvar_Get("s_alMaxDistance", "1024", CVAR_CHEAT);
|
|
|
|
s_alRolloff = Cvar_Get( "s_alRolloff", "2", CVAR_CHEAT);
|
|
|
|
s_alGraceDistance = Cvar_Get("s_alGraceDistance", "512", CVAR_CHEAT);
|
2005-11-13 18:58:14 +00:00
|
|
|
|
2009-05-08 09:13:03 +00:00
|
|
|
s_alDriver = Cvar_Get( "s_alDriver", ALDRIVER_DEFAULT, CVAR_ARCHIVE | CVAR_LATCH );
|
2005-11-13 18:58:14 +00:00
|
|
|
|
2011-03-09 23:34:15 +00:00
|
|
|
s_alInputDevice = Cvar_Get( "s_alInputDevice", "", CVAR_ARCHIVE | CVAR_LATCH );
|
2009-05-08 09:13:06 +00:00
|
|
|
s_alDevice = Cvar_Get("s_alDevice", "", CVAR_ARCHIVE | CVAR_LATCH);
|
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
// Load QAL
|
|
|
|
if( !QAL_Init( s_alDriver->string ) )
|
|
|
|
{
|
2005-11-30 01:57:53 +00:00
|
|
|
Com_Printf( "Failed to load library: \"%s\".\n", s_alDriver->string );
|
2005-11-13 18:58:14 +00:00
|
|
|
return qfalse;
|
|
|
|
}
|
|
|
|
|
2009-05-08 09:13:06 +00:00
|
|
|
device = s_alDevice->string;
|
|
|
|
if(device && !*device)
|
|
|
|
device = NULL;
|
|
|
|
|
2011-03-08 01:39:34 +00:00
|
|
|
inputdevice = s_alInputDevice->string;
|
|
|
|
if(inputdevice && !*inputdevice)
|
|
|
|
inputdevice = NULL;
|
|
|
|
|
2011-03-09 12:59:25 +00:00
|
|
|
// Device enumeration support
|
2011-03-09 23:34:15 +00:00
|
|
|
if((enumeration_ext = qalcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT")) ||
|
|
|
|
qalcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT")
|
2011-03-09 12:59:25 +00:00
|
|
|
)
|
2006-08-19 11:02:20 +00:00
|
|
|
{
|
2011-03-11 13:53:22 +00:00
|
|
|
char devicenames[16384] = "";
|
2006-09-05 07:05:04 +00:00
|
|
|
const char *devicelist;
|
|
|
|
const char *defaultdevice;
|
2006-08-19 11:02:20 +00:00
|
|
|
int curlen;
|
|
|
|
|
|
|
|
// get all available devices + the default device name.
|
2011-03-09 12:59:25 +00:00
|
|
|
if(enumeration_ext)
|
2011-03-14 15:57:39 +00:00
|
|
|
{
|
2011-03-09 12:59:25 +00:00
|
|
|
devicelist = qalcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
|
2011-03-14 15:57:39 +00:00
|
|
|
defaultdevice = qalcGetString(NULL, ALC_DEFAULT_ALL_DEVICES_SPECIFIER);
|
|
|
|
}
|
2011-03-09 12:59:25 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// We don't have ALC_ENUMERATE_ALL_EXT but normal enumeration.
|
|
|
|
devicelist = qalcGetString(NULL, ALC_DEVICE_SPECIFIER);
|
2011-03-14 15:57:39 +00:00
|
|
|
defaultdevice = qalcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
|
2011-03-09 12:59:25 +00:00
|
|
|
enumeration_ext = qtrue;
|
|
|
|
}
|
|
|
|
|
2006-08-19 13:44:10 +00:00
|
|
|
#ifdef _WIN32
|
2006-08-19 11:02:20 +00:00
|
|
|
// check whether the default device is generic hardware. If it is, change to
|
|
|
|
// Generic Software as that one works more reliably with various sound systems.
|
|
|
|
// If it's not, use OpenAL's default selection as we don't want to ignore
|
|
|
|
// native hardware acceleration.
|
2009-05-08 09:13:06 +00:00
|
|
|
if(!device && !strcmp(defaultdevice, "Generic Hardware"))
|
|
|
|
device = "Generic Software";
|
2006-08-19 13:44:10 +00:00
|
|
|
#endif
|
2006-08-19 11:02:20 +00:00
|
|
|
|
|
|
|
// dump a list of available devices to a cvar for the user to see.
|
|
|
|
while((curlen = strlen(devicelist)))
|
|
|
|
{
|
|
|
|
Q_strcat(devicenames, sizeof(devicenames), devicelist);
|
2006-08-19 22:17:04 +00:00
|
|
|
Q_strcat(devicenames, sizeof(devicenames), "\n");
|
2006-08-19 11:02:20 +00:00
|
|
|
|
|
|
|
devicelist += curlen + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
s_alAvailableDevices = Cvar_Get("s_alAvailableDevices", devicenames, CVAR_ROM | CVAR_NORESTART);
|
|
|
|
}
|
|
|
|
|
2009-05-08 09:13:06 +00:00
|
|
|
alDevice = qalcOpenDevice(device);
|
|
|
|
if( !alDevice && device )
|
|
|
|
{
|
|
|
|
Com_Printf( "Failed to open OpenAL device '%s', trying default.\n", device );
|
2006-08-19 11:02:20 +00:00
|
|
|
alDevice = qalcOpenDevice(NULL);
|
2009-05-08 09:13:06 +00:00
|
|
|
}
|
2006-08-19 11:02:20 +00:00
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
if( !alDevice )
|
|
|
|
{
|
|
|
|
QAL_Shutdown( );
|
2005-11-30 01:57:53 +00:00
|
|
|
Com_Printf( "Failed to open OpenAL device.\n" );
|
2005-11-13 18:58:14 +00:00
|
|
|
return qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create OpenAL context
|
|
|
|
alContext = qalcCreateContext( alDevice, NULL );
|
|
|
|
if( !alContext )
|
|
|
|
{
|
|
|
|
QAL_Shutdown( );
|
|
|
|
qalcCloseDevice( alDevice );
|
2005-11-30 01:57:53 +00:00
|
|
|
Com_Printf( "Failed to create OpenAL context.\n" );
|
2005-11-13 18:58:14 +00:00
|
|
|
return qfalse;
|
|
|
|
}
|
|
|
|
qalcMakeContextCurrent( alContext );
|
|
|
|
|
|
|
|
// Initialize sources, buffers, music
|
|
|
|
S_AL_BufferInit( );
|
|
|
|
S_AL_SrcInit( );
|
|
|
|
|
|
|
|
// Set up OpenAL parameters (doppler, etc)
|
2006-11-03 08:22:38 +00:00
|
|
|
qalDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
|
2005-11-13 18:58:14 +00:00
|
|
|
qalDopplerFactor( s_alDopplerFactor->value );
|
|
|
|
qalDopplerVelocity( s_alDopplerSpeed->value );
|
|
|
|
|
2008-07-07 22:31:39 +00:00
|
|
|
#ifdef USE_VOIP
|
2008-06-01 07:51:23 +00:00
|
|
|
// !!! FIXME: some of these alcCaptureOpenDevice() values should be cvars.
|
|
|
|
// !!! FIXME: add support for capture device enumeration.
|
|
|
|
// !!! FIXME: add some better error reporting.
|
2008-06-01 18:10:33 +00:00
|
|
|
s_alCapture = Cvar_Get( "s_alCapture", "1", CVAR_ARCHIVE | CVAR_LATCH );
|
2008-08-03 19:31:42 +00:00
|
|
|
if (!s_alCapture->integer)
|
|
|
|
{
|
2008-06-01 07:51:23 +00:00
|
|
|
Com_Printf("OpenAL capture support disabled by user ('+set s_alCapture 1' to enable)\n");
|
2008-08-03 19:31:42 +00:00
|
|
|
}
|
2008-06-01 07:51:23 +00:00
|
|
|
#if USE_MUMBLE
|
2008-08-03 19:31:42 +00:00
|
|
|
else if (cl_useMumble->integer)
|
|
|
|
{
|
2008-06-01 07:51:23 +00:00
|
|
|
Com_Printf("OpenAL capture support disabled for Mumble support\n");
|
2008-08-03 19:31:42 +00:00
|
|
|
}
|
2008-06-01 07:51:23 +00:00
|
|
|
#endif
|
2008-08-03 19:31:42 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef MACOS_X
|
2008-06-01 07:51:23 +00:00
|
|
|
// !!! FIXME: Apple has a 1.1-compliant OpenAL, which includes
|
|
|
|
// !!! FIXME: capture support, but they don't list it in the
|
|
|
|
// !!! FIXME: extension string. We need to check the version string,
|
|
|
|
// !!! FIXME: then the extension string, but that's too much trouble,
|
|
|
|
// !!! FIXME: so we'll just check the function pointer for now.
|
2008-08-03 19:31:42 +00:00
|
|
|
if (qalcCaptureOpenDevice == NULL)
|
|
|
|
#else
|
|
|
|
if (!qalcIsExtensionPresent(NULL, "ALC_EXT_capture"))
|
|
|
|
#endif
|
|
|
|
{
|
2008-06-01 07:51:23 +00:00
|
|
|
Com_Printf("No ALC_EXT_capture support, can't record audio.\n");
|
2008-08-03 19:31:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-03-11 13:53:22 +00:00
|
|
|
char inputdevicenames[16384] = "";
|
2011-03-08 01:39:34 +00:00
|
|
|
const char *inputdevicelist;
|
|
|
|
const char *defaultinputdevice;
|
|
|
|
int curlen;
|
|
|
|
|
|
|
|
// get all available input devices + the default input device name.
|
|
|
|
inputdevicelist = qalcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
|
|
|
|
defaultinputdevice = qalcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER);
|
|
|
|
|
|
|
|
// dump a list of available devices to a cvar for the user to see.
|
|
|
|
while((curlen = strlen(inputdevicelist)))
|
|
|
|
{
|
|
|
|
Q_strcat(inputdevicenames, sizeof(inputdevicenames), inputdevicelist);
|
|
|
|
Q_strcat(inputdevicenames, sizeof(inputdevicenames), "\n");
|
|
|
|
inputdevicelist += curlen + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
s_alAvailableInputDevices = Cvar_Get("s_alAvailableInputDevices", inputdevicenames, CVAR_ROM | CVAR_NORESTART);
|
|
|
|
|
2008-06-07 14:38:46 +00:00
|
|
|
// !!! FIXME: 8000Hz is what Speex narrowband mode needs, but we
|
|
|
|
// !!! FIXME: should probably open the capture device after
|
|
|
|
// !!! FIXME: initializing Speex so we can change to wideband
|
|
|
|
// !!! FIXME: if we like.
|
2011-03-08 01:39:34 +00:00
|
|
|
Com_Printf("OpenAL default capture device is '%s'\n", defaultinputdevice);
|
|
|
|
alCaptureDevice = qalcCaptureOpenDevice(inputdevice, 8000, AL_FORMAT_MONO16, 4096);
|
|
|
|
if( !alCaptureDevice && inputdevice )
|
|
|
|
{
|
|
|
|
Com_Printf( "Failed to open OpenAL Input device '%s', trying default.\n", inputdevice );
|
|
|
|
alCaptureDevice = qalcCaptureOpenDevice(NULL, 8000, AL_FORMAT_MONO16, 4096);
|
|
|
|
}
|
2008-06-01 07:51:23 +00:00
|
|
|
Com_Printf( "OpenAL capture device %s.\n",
|
|
|
|
(alCaptureDevice == NULL) ? "failed to open" : "opened");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
si->Shutdown = S_AL_Shutdown;
|
|
|
|
si->StartSound = S_AL_StartSound;
|
|
|
|
si->StartLocalSound = S_AL_StartLocalSound;
|
|
|
|
si->StartBackgroundTrack = S_AL_StartBackgroundTrack;
|
|
|
|
si->StopBackgroundTrack = S_AL_StopBackgroundTrack;
|
|
|
|
si->RawSamples = S_AL_RawSamples;
|
|
|
|
si->StopAllSounds = S_AL_StopAllSounds;
|
|
|
|
si->ClearLoopingSounds = S_AL_ClearLoopingSounds;
|
|
|
|
si->AddLoopingSound = S_AL_AddLoopingSound;
|
|
|
|
si->AddRealLoopingSound = S_AL_AddRealLoopingSound;
|
|
|
|
si->StopLoopingSound = S_AL_StopLoopingSound;
|
|
|
|
si->Respatialize = S_AL_Respatialize;
|
|
|
|
si->UpdateEntityPosition = S_AL_UpdateEntityPosition;
|
|
|
|
si->Update = S_AL_Update;
|
|
|
|
si->DisableSounds = S_AL_DisableSounds;
|
|
|
|
si->BeginRegistration = S_AL_BeginRegistration;
|
|
|
|
si->RegisterSound = S_AL_RegisterSound;
|
|
|
|
si->ClearSoundBuffer = S_AL_ClearSoundBuffer;
|
|
|
|
si->SoundInfo = S_AL_SoundInfo;
|
|
|
|
si->SoundList = S_AL_SoundList;
|
|
|
|
|
2008-07-07 22:31:39 +00:00
|
|
|
#ifdef USE_VOIP
|
2008-06-01 07:51:23 +00:00
|
|
|
si->StartCapture = S_AL_StartCapture;
|
|
|
|
si->AvailableCaptureSamples = S_AL_AvailableCaptureSamples;
|
|
|
|
si->Capture = S_AL_Capture;
|
|
|
|
si->StopCapture = S_AL_StopCapture;
|
|
|
|
si->MasterGain = S_AL_MasterGain;
|
|
|
|
#endif
|
|
|
|
|
2005-11-13 18:58:14 +00:00
|
|
|
return qtrue;
|
|
|
|
#else
|
|
|
|
return qfalse;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|