summaryrefslogtreecommitdiff
path: root/src/client/snd_openal.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/snd_openal.c')
-rw-r--r--src/client/snd_openal.c122
1 files changed, 78 insertions, 44 deletions
diff --git a/src/client/snd_openal.c b/src/client/snd_openal.c
index b594732e..660525dd 100644
--- a/src/client/snd_openal.c
+++ b/src/client/snd_openal.c
@@ -540,6 +540,7 @@ typedef struct src_s
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
+ qboolean isStream; // Is this source a stream
float curGain; // gain employed if source is within maxdistance.
float scaleGain; // Last gain value for this source. 0 if muted.
@@ -763,13 +764,8 @@ 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;
src_t *curSource;
- // Mark the SFX as used, and grab the raw AL buffer
- S_AL_BufferUse(sfx);
- buffer = S_AL_BufferGet(sfx);
-
// Set up src struct
curSource = &srcList[src];
@@ -782,12 +778,19 @@ static void S_AL_SrcSetup(srcHandle_t src, sfxHandle_t sfx, alSrcPriority_t prio
curSource->isLocked = qfalse;
curSource->isLooping = qfalse;
curSource->isTracking = qfalse;
+ curSource->isStream = qfalse;
curSource->curGain = s_alGain->value * s_volume->value;
curSource->scaleGain = curSource->curGain;
curSource->local = local;
// Set up OpenAL source
- qalSourcei(curSource->alSource, AL_BUFFER, buffer);
+ if(sfx >= 0)
+ {
+ // Mark the SFX as used, and grab the raw AL buffer
+ S_AL_BufferUse(sfx);
+ qalSourcei(curSource->alSource, AL_BUFFER, S_AL_BufferGet(sfx));
+ }
+
qalSourcef(curSource->alSource, AL_PITCH, 1.0f);
S_AL_Gain(curSource->alSource, curSource->curGain);
qalSourcefv(curSource->alSource, AL_POSITION, vec3_origin);
@@ -1339,7 +1342,7 @@ static void S_AL_SrcLoop( alSrcPriority_t priority, sfxHandle_t sfx,
VectorClear(sorigin);
qalSourcefv(curSource->alSource, AL_POSITION, sorigin);
- qalSourcefv(curSource->alSource, AL_VELOCITY, sorigin);
+ qalSourcefv(curSource->alSource, AL_VELOCITY, vec3_origin);
}
else
{
@@ -1362,8 +1365,8 @@ static void S_AL_SrcLoop( alSrcPriority_t priority, sfxHandle_t sfx,
else
VectorClear(svelocity);
- qalSourcefv( curSource->alSource, AL_POSITION, (ALfloat *)sorigin );
- qalSourcefv( curSource->alSource, AL_VELOCITY, (ALfloat *)velocity );
+ qalSourcefv(curSource->alSource, AL_POSITION, (ALfloat *) sorigin);
+ qalSourcefv(curSource->alSource, AL_VELOCITY, (ALfloat *) svelocity);
}
}
@@ -1576,14 +1579,17 @@ void S_AL_SrcUpdate( void )
continue;
}
- // Check if it's done, and flag it
- qalGetSourcei(curSource->alSource, AL_SOURCE_STATE, &state);
- if(state == AL_STOPPED)
+ if(!curSource->isStream)
{
- curSource->isPlaying = qfalse;
- S_AL_SrcKill(i);
- continue;
- }
+ // Check if it's done, and flag it
+ qalGetSourcei(curSource->alSource, AL_SOURCE_STATE, &state);
+ if(state == AL_STOPPED)
+ {
+ curSource->isPlaying = qfalse;
+ S_AL_SrcKill(i);
+ continue;
+ }
+ }
// Query relativity of source, don't move if it's true
qalGetSourcei(curSource->alSource, AL_SOURCE_RELATIVE, &state);
@@ -1633,32 +1639,57 @@ static ALuint streamSources[MAX_RAW_STREAMS];
S_AL_AllocateStreamChannel
=================
*/
-static void S_AL_AllocateStreamChannel( int stream )
+static void S_AL_AllocateStreamChannel(int stream, int entityNum)
{
+ srcHandle_t cursrc;
+ ALuint alsrc;
+
if ((stream < 0) || (stream >= MAX_RAW_STREAMS))
return;
- // Allocate a streamSource at high priority
- streamSourceHandles[stream] = S_AL_SrcAlloc(SRCPRI_STREAM, -2, 0);
- if(streamSourceHandles[stream] == -1)
- return;
-
- // Lock the streamSource so nobody else can use it, and get the raw streamSource
- S_AL_SrcLock(streamSourceHandles[stream]);
- streamSources[stream] = S_AL_SrcGet(streamSourceHandles[stream]);
-
- // 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;
-
- // Set some streamSource parameters
- 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 );
+ if(entityNum >= 0)
+ {
+ // This is a stream that tracks an entity
+ // Allocate a streamSource at normal priority
+ cursrc = S_AL_SrcAlloc(SRCPRI_ENTITY, entityNum, 0);
+ if(cursrc < 0)
+ return;
+
+ S_AL_SrcSetup(cursrc, -1, SRCPRI_ENTITY, entityNum, 0, qfalse);
+ alsrc = S_AL_SrcGet(cursrc);
+ srcList[cursrc].isTracking = qtrue;
+ srcList[cursrc].isStream = qtrue;
+ }
+ else
+ {
+ // Unspatialized stream source
+
+ // Allocate a streamSource at high priority
+ cursrc = S_AL_SrcAlloc(SRCPRI_STREAM, -2, 0);
+ if(cursrc < 0)
+ return;
+
+ alsrc = S_AL_SrcGet(cursrc);
+
+ // Lock the streamSource so nobody else can use it, and get the raw streamSource
+ S_AL_SrcLock(cursrc);
+
+ // make sure that after unmuting the S_AL_Gain in S_Update() does not turn
+ // volume up prematurely for this source
+ srcList[cursrc].scaleGain = 0.0f;
+
+ // Set some streamSource parameters
+ qalSourcei (alsrc, AL_BUFFER, 0 );
+ qalSourcei (alsrc, AL_LOOPING, AL_FALSE );
+ qalSource3f(alsrc, AL_POSITION, 0.0, 0.0, 0.0);
+ qalSource3f(alsrc, AL_VELOCITY, 0.0, 0.0, 0.0);
+ qalSource3f(alsrc, AL_DIRECTION, 0.0, 0.0, 0.0);
+ qalSourcef (alsrc, AL_ROLLOFF_FACTOR, 0.0 );
+ qalSourcei (alsrc, AL_SOURCE_RELATIVE, AL_TRUE );
+ }
+
+ streamSourceHandles[stream] = cursrc;
+ streamSources[stream] = alsrc;
}
/*
@@ -1673,6 +1704,7 @@ static void S_AL_FreeStreamChannel( int stream )
// Release the output streamSource
S_AL_SrcUnlock(streamSourceHandles[stream]);
+ S_AL_SrcKill(streamSourceHandles[stream]);
streamSources[stream] = 0;
streamSourceHandles[stream] = -1;
}
@@ -1683,7 +1715,7 @@ S_AL_RawSamples
=================
*/
static
-void S_AL_RawSamples(int stream, int samples, int rate, int width, int channels, const byte *data, float volume)
+void S_AL_RawSamples(int stream, int samples, int rate, int width, int channels, const byte *data, float volume, int entityNum)
{
ALuint buffer;
ALuint format;
@@ -1696,7 +1728,7 @@ void S_AL_RawSamples(int stream, int samples, int rate, int width, int channels,
// Create the streamSource if necessary
if(streamSourceHandles[stream] == -1)
{
- S_AL_AllocateStreamChannel(stream);
+ S_AL_AllocateStreamChannel(stream, entityNum);
// Failed?
if(streamSourceHandles[stream] == -1)
@@ -1713,8 +1745,11 @@ void S_AL_RawSamples(int stream, int samples, int rate, int width, int channels,
// Shove the data onto the streamSource
qalSourceQueueBuffers(streamSources[stream], 1, &buffer);
- // Volume
- S_AL_Gain (streamSources[stream], volume * s_volume->value * s_alGain->value);
+ if(entityNum < 0)
+ {
+ // Volume
+ S_AL_Gain (streamSources[stream], volume * s_volume->value * s_alGain->value);
+ }
}
/*
@@ -2125,7 +2160,6 @@ S_AL_Respatialize
static
void S_AL_Respatialize( int entityNum, const vec3_t origin, vec3_t axis[3], int inwater )
{
- float velocity[3] = {0.0f, 0.0f, 0.0f};
float orientation[6];
vec3_t sorigin;
@@ -2143,7 +2177,7 @@ void S_AL_Respatialize( int entityNum, const vec3_t origin, vec3_t axis[3], int
// Set OpenAL listener paramaters
qalListenerfv(AL_POSITION, (ALfloat *)sorigin);
- qalListenerfv(AL_VELOCITY, velocity);
+ qalListenerfv(AL_VELOCITY, vec3_origin);
qalListenerfv(AL_ORIENTATION, orientation);
}