summaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorThilo Schulz <arny@ats.s.bawue.de>2011-07-27 15:47:29 +0000
committerTim Angus <tim@ngus.net>2013-01-10 22:36:32 +0000
commit34e5d1056d0cd83648db904549a368ef904e2be8 (patch)
tree94f69d7546b28b8b8854b06526b70934a65c0dc0 /src/client
parentd28ee7e3da161ae9a9e9f339291001948672dae7 (diff)
- Apply parts of Ben Millwood's target bitfield patch (#3787) - Fix Ryan's FIXME and have voip packet buffer on the server dynamically allocated via Z_Malloc and store pointers in a circular buffer - Improve voip target parsing on top of Ben Millwood's patch - Add new "spatial" target where speaker is spatialized in 3d space and can be heard by all clients in hearing range (s_alMaxDistance) (#4467) - Decrease voip sound lengths from 240ms to 80ms per voip packet to mitigate udp packet loss and decrease latency - Protocol version incremented to 71
Diffstat (limited to 'src/client')
-rw-r--r--src/client/cl_cgame.c4
-rw-r--r--src/client/cl_cin.c4
-rw-r--r--src/client/cl_input.c116
-rw-r--r--src/client/cl_main.c95
-rw-r--r--src/client/cl_parse.c34
-rw-r--r--src/client/client.h7
-rw-r--r--src/client/snd_dma.c14
-rw-r--r--src/client/snd_local.h4
-rw-r--r--src/client/snd_main.c7
-rw-r--r--src/client/snd_openal.c122
-rw-r--r--src/client/snd_public.h4
11 files changed, 264 insertions, 147 deletions
diff --git a/src/client/cl_cgame.c b/src/client/cl_cgame.c
index e295fdf7..0425cbd6 100644
--- a/src/client/cl_cgame.c
+++ b/src/client/cl_cgame.c
@@ -1002,8 +1002,8 @@ void CL_FirstSnapshot( void ) {
clc.speexInitialized = qtrue;
clc.voipMuteAll = qfalse;
Cmd_AddCommand ("voip", CL_Voip_f);
- Cvar_Set("cl_voipSendTarget", "all");
- clc.voipTarget1 = clc.voipTarget2 = clc.voipTarget3 = 0x7FFFFFFF;
+ Cvar_Set("cl_voipSendTarget", "spatial");
+ Com_Memset(clc.voipTargets, ~0, sizeof(clc.voipTargets));
}
#endif
}
diff --git a/src/client/cl_cin.c b/src/client/cl_cin.c
index 3793dcd9..0628342a 100644
--- a/src/client/cl_cin.c
+++ b/src/client/cl_cin.c
@@ -1148,7 +1148,7 @@ redump:
case ZA_SOUND_MONO:
if (!cinTable[currentHandle].silent) {
ssize = RllDecodeMonoToStereo( framedata, sbuf, cinTable[currentHandle].RoQFrameSize, 0, (unsigned short)cinTable[currentHandle].roq_flags);
- S_RawSamples( 0, ssize, 22050, 2, 1, (byte *)sbuf, 1.0f );
+ S_RawSamples(0, ssize, 22050, 2, 1, (byte *)sbuf, 1.0f, -1);
}
break;
case ZA_SOUND_STEREO:
@@ -1158,7 +1158,7 @@ redump:
s_rawend[0] = s_soundtime;
}
ssize = RllDecodeStereoToStereo( framedata, sbuf, cinTable[currentHandle].RoQFrameSize, 0, (unsigned short)cinTable[currentHandle].roq_flags);
- S_RawSamples( 0, ssize, 22050, 2, 2, (byte *)sbuf, 1.0f );
+ S_RawSamples(0, ssize, 22050, 2, 2, (byte *)sbuf, 1.0f, -1);
}
break;
case ROQ_QUAD_INFO:
diff --git a/src/client/cl_input.c b/src/client/cl_input.c
index 736378ba..bae37cfe 100644
--- a/src/client/cl_input.c
+++ b/src/client/cl_input.c
@@ -800,83 +800,53 @@ void CL_WritePacket( void ) {
}
#ifdef USE_VOIP
- if (clc.voipOutgoingDataSize > 0) { // only send if data.
- // Move cl_voipSendTarget from a string to the bitmasks if needed.
- if (cl_voipSendTarget->modified) {
- char buffer[32];
- const char *target = cl_voipSendTarget->string;
-
- if (Q_stricmp(target, "attacker") == 0) {
- int player = VM_Call( cgvm, CG_LAST_ATTACKER );
- Com_sprintf(buffer, sizeof (buffer), "%d", player);
- target = buffer;
- } else if (Q_stricmp(target, "crosshair") == 0) {
- int player = VM_Call( cgvm, CG_CROSSHAIR_PLAYER );
- Com_sprintf(buffer, sizeof (buffer), "%d", player);
- target = buffer;
+ if (clc.voipOutgoingDataSize > 0)
+ {
+ if((clc.voipFlags & VOIP_SPATIAL) || Com_IsVoipTarget(clc.voipTargets, sizeof(clc.voipTargets), -1))
+ {
+ MSG_WriteByte (&buf, clc_voip);
+ MSG_WriteByte (&buf, clc.voipOutgoingGeneration);
+ MSG_WriteLong (&buf, clc.voipOutgoingSequence);
+ MSG_WriteByte (&buf, clc.voipOutgoingDataFrames);
+ MSG_WriteData (&buf, clc.voipTargets, sizeof(clc.voipTargets));
+ MSG_WriteByte(&buf, clc.voipFlags);
+ MSG_WriteShort (&buf, clc.voipOutgoingDataSize);
+ MSG_WriteData (&buf, clc.voipOutgoingData, clc.voipOutgoingDataSize);
+
+ // If we're recording a demo, we have to fake a server packet with
+ // this VoIP data so it gets to disk; the server doesn't send it
+ // back to us, and we might as well eliminate concerns about dropped
+ // and misordered packets here.
+ if(clc.demorecording && !clc.demowaiting)
+ {
+ const int voipSize = clc.voipOutgoingDataSize;
+ msg_t fakemsg;
+ byte fakedata[MAX_MSGLEN];
+ MSG_Init (&fakemsg, fakedata, sizeof (fakedata));
+ MSG_Bitstream (&fakemsg);
+ MSG_WriteLong (&fakemsg, clc.reliableAcknowledge);
+ MSG_WriteByte (&fakemsg, svc_voip);
+ MSG_WriteShort (&fakemsg, clc.clientNum);
+ MSG_WriteByte (&fakemsg, clc.voipOutgoingGeneration);
+ MSG_WriteLong (&fakemsg, clc.voipOutgoingSequence);
+ MSG_WriteByte (&fakemsg, clc.voipOutgoingDataFrames);
+ MSG_WriteShort (&fakemsg, clc.voipOutgoingDataSize );
+ MSG_WriteData (&fakemsg, clc.voipOutgoingData, voipSize);
+ MSG_WriteByte (&fakemsg, svc_EOF);
+ CL_WriteDemoMessage (&fakemsg, 0);
}
- if ((*target == '\0') || (Q_stricmp(target, "all") == 0)) {
- const int all = 0x7FFFFFFF;
- clc.voipTarget1 = clc.voipTarget2 = clc.voipTarget3 = all;
- } else if (Q_stricmp(target, "none") == 0) {
- clc.voipTarget1 = clc.voipTarget2 = clc.voipTarget3 = 0;
- } else {
- const char *ptr = target;
- clc.voipTarget1 = clc.voipTarget2 = clc.voipTarget3 = 0;
- do {
- if ((*ptr == ',') || (*ptr == '\0')) {
- const int val = atoi(target);
- target = ptr + 1;
- if ((val >= 0) && (val < 31)) {
- clc.voipTarget1 |= (1 << (val-0));
- } else if ((val >= 31) && (val < 62)) {
- clc.voipTarget2 |= (1 << (val-31));
- } else if ((val >= 62) && (val < 93)) {
- clc.voipTarget3 |= (1 << (val-62));
- }
- }
- } while (*(ptr++));
- }
- cl_voipSendTarget->modified = qfalse;
+ clc.voipOutgoingSequence += clc.voipOutgoingDataFrames;
+ clc.voipOutgoingDataSize = 0;
+ clc.voipOutgoingDataFrames = 0;
}
-
- MSG_WriteByte (&buf, clc_voip);
- MSG_WriteByte (&buf, clc.voipOutgoingGeneration);
- MSG_WriteLong (&buf, clc.voipOutgoingSequence);
- MSG_WriteByte (&buf, clc.voipOutgoingDataFrames);
- MSG_WriteLong (&buf, clc.voipTarget1);
- MSG_WriteLong (&buf, clc.voipTarget2);
- MSG_WriteLong (&buf, clc.voipTarget3);
- MSG_WriteShort (&buf, clc.voipOutgoingDataSize);
- MSG_WriteData (&buf, clc.voipOutgoingData, clc.voipOutgoingDataSize);
-
- // If we're recording a demo, we have to fake a server packet with
- // this VoIP data so it gets to disk; the server doesn't send it
- // back to us, and we might as well eliminate concerns about dropped
- // and misordered packets here.
- if ( clc.demorecording && !clc.demowaiting ) {
- const int voipSize = clc.voipOutgoingDataSize;
- msg_t fakemsg;
- byte fakedata[MAX_MSGLEN];
- MSG_Init (&fakemsg, fakedata, sizeof (fakedata));
- MSG_Bitstream (&fakemsg);
- MSG_WriteLong (&fakemsg, clc.reliableAcknowledge);
- MSG_WriteByte (&fakemsg, svc_voip);
- MSG_WriteShort (&fakemsg, clc.clientNum);
- MSG_WriteByte (&fakemsg, clc.voipOutgoingGeneration);
- MSG_WriteLong (&fakemsg, clc.voipOutgoingSequence);
- MSG_WriteByte (&fakemsg, clc.voipOutgoingDataFrames);
- MSG_WriteShort (&fakemsg, clc.voipOutgoingDataSize );
- MSG_WriteData (&fakemsg, clc.voipOutgoingData, voipSize);
- MSG_WriteByte (&fakemsg, svc_EOF);
- CL_WriteDemoMessage (&fakemsg, 0);
+ else
+ {
+ // We have data, but no targets. Silently discard all data
+ clc.voipOutgoingDataSize = 0;
+ clc.voipOutgoingDataFrames = 0;
}
-
- clc.voipOutgoingSequence += clc.voipOutgoingDataFrames;
- clc.voipOutgoingDataSize = 0;
- clc.voipOutgoingDataFrames = 0;
- } else
+ }
#endif
if ( count >= 1 ) {
diff --git a/src/client/cl_main.c b/src/client/cl_main.c
index ad1acc83..80756007 100644
--- a/src/client/cl_main.c
+++ b/src/client/cl_main.c
@@ -345,6 +345,88 @@ void CL_VoipNewGeneration(void)
/*
===============
+CL_VoipParseTargets
+
+sets clc.voipTargets according to cl_voipSendTarget
+Generally we don't want who's listening to change during a transmission,
+so this is only called when the key is first pressed
+===============
+*/
+void CL_VoipParseTargets(void)
+{
+ const char *target = cl_voipSendTarget->string;
+ char *end;
+ int val;
+
+ Com_Memset(clc.voipTargets, 0, sizeof(clc.voipTargets));
+ clc.voipFlags &= ~VOIP_SPATIAL;
+
+ while(target)
+ {
+ while(*target == ',' || *target == ' ')
+ target++;
+
+ if(!*target)
+ break;
+
+ if(isdigit(*target))
+ {
+ val = strtol(target, &end, 10);
+ target = end;
+ }
+ else
+ {
+ if(!Q_stricmpn(target, "all", 3))
+ {
+ Com_Memset(clc.voipTargets, ~0, sizeof(clc.voipTargets));
+ return;
+ }
+ if(!Q_stricmpn(target, "spatial", 7))
+ {
+ clc.voipFlags |= VOIP_SPATIAL;
+ target += 7;
+ continue;
+ }
+ else
+ {
+ if(!Q_stricmpn(target, "attacker", 8))
+ {
+ val = VM_Call(cgvm, CG_LAST_ATTACKER);
+ target += 8;
+ }
+ else if(!Q_stricmpn(target, "crosshair", 9))
+ {
+ val = VM_Call(cgvm, CG_CROSSHAIR_PLAYER);
+ target += 9;
+ }
+ else
+ {
+ while(*target && *target != ',' && *target != ' ')
+ target++;
+
+ continue;
+ }
+
+ if(val < 0)
+ continue;
+ }
+ }
+
+ if(val < 0 || val >= MAX_CLIENTS)
+ {
+ Com_Printf(S_COLOR_YELLOW "WARNING: VoIP "
+ "target %d is not a valid client "
+ "number\n", val);
+
+ continue;
+ }
+
+ clc.voipTargets[val / 8] |= 1 << (val % 8);
+ }
+}
+
+/*
+===============
CL_CaptureVoip
Record more audio from the hardware if required and encode it into Speex
@@ -394,8 +476,9 @@ void CL_CaptureVoip(void)
cl_voipSend->modified = qfalse;
- if (dontCapture) {
- cl_voipSend->integer = 0;
+ if(dontCapture)
+ {
+ Cvar_Set("cl_voipSend", "0");
return;
}
@@ -419,7 +502,7 @@ void CL_CaptureVoip(void)
if ((cl_voipSend->integer) || (finalFrame)) { // user wants to capture audio?
int samples = S_AvailableCaptureSamples();
- const int mult = (finalFrame) ? 1 : 12; // 12 == 240ms of audio.
+ const int mult = (finalFrame) ? 1 : 4; // 4 == 80ms of audio.
// enough data buffered in audio hardware to process yet?
if (samples >= (clc.speexFrameSize * mult)) {
@@ -431,8 +514,8 @@ void CL_CaptureVoip(void)
int wpos = 0;
int pos = 0;
- if (samples > (clc.speexFrameSize * 12))
- samples = (clc.speexFrameSize * 12);
+ if (samples > (clc.speexFrameSize * 4))
+ samples = (clc.speexFrameSize * 4);
// !!! FIXME: maybe separate recording from encoding, so voipPower
// !!! FIXME: updates faster than 4Hz?
@@ -3537,7 +3620,7 @@ void CL_Init( void ) {
#ifdef USE_VOIP
cl_voipSend = Cvar_Get ("cl_voipSend", "0", 0);
- cl_voipSendTarget = Cvar_Get ("cl_voipSendTarget", "all", 0);
+ cl_voipSendTarget = Cvar_Get ("cl_voipSendTarget", "spatial", 0);
cl_voipGainDuringCapture = Cvar_Get ("cl_voipGainDuringCapture", "0.2", CVAR_ARCHIVE);
cl_voipCaptureMult = Cvar_Get ("cl_voipCaptureMult", "2.0", CVAR_ARCHIVE);
cl_voipUseVAD = Cvar_Get ("cl_voipUseVAD", "0", CVAR_ARCHIVE);
diff --git a/src/client/cl_parse.c b/src/client/cl_parse.c
index 147c3156..5218d0b3 100644
--- a/src/client/cl_parse.c
+++ b/src/client/cl_parse.c
@@ -656,6 +656,29 @@ qboolean CL_ShouldIgnoreVoipSender(int sender)
/*
=====================
+CL_PlayVoip
+
+Play raw data
+=====================
+*/
+
+static void CL_PlayVoip(int sender, int samplecnt, const byte *data, int flags)
+{
+ if(flags & VOIP_DIRECT)
+ {
+ S_RawSamples(sender + 1, samplecnt, clc.speexSampleRate, 2, 1,
+ data, clc.voipGain[sender], -1);
+ }
+
+ if(flags & VOIP_SPATIAL)
+ {
+ S_RawSamples(sender + MAX_CLIENTS + 1, samplecnt, clc.speexSampleRate, 2, 1,
+ data, 1.0f, sender);
+ }
+}
+
+/*
+=====================
CL_ParseVoip
A VoIP message has been received from the server
@@ -670,6 +693,7 @@ void CL_ParseVoip ( msg_t *msg ) {
const int sequence = MSG_ReadLong(msg);
const int frames = MSG_ReadByte(msg);
const int packetsize = MSG_ReadShort(msg);
+ const int flags = MSG_ReadBits(msg, VOIP_FLAGCNT);
char encoded[1024];
int seqdiff = sequence - clc.voipIncomingSequence[sender];
int written = 0;
@@ -760,8 +784,8 @@ void CL_ParseVoip ( msg_t *msg ) {
if ((written + clc.speexFrameSize) * 2 > sizeof (decoded)) {
Com_DPrintf("VoIP: playback %d bytes, %d samples, %d frames\n",
written * 2, written, i);
- S_RawSamples(sender + 1, written, clc.speexSampleRate, 2, 1,
- (const byte *) decoded, clc.voipGain[sender]);
+
+ CL_PlayVoip(sender, written, (const byte *) decoded, flags);
written = 0;
}
@@ -784,10 +808,8 @@ void CL_ParseVoip ( msg_t *msg ) {
Com_DPrintf("VoIP: playback %d bytes, %d samples, %d frames\n",
written * 2, written, i);
- if (written > 0) {
- S_RawSamples(sender + 1, written, clc.speexSampleRate, 2, 1,
- (const byte *) decoded, clc.voipGain[sender]);
- }
+ if(written > 0)
+ CL_PlayVoip(sender, written, (const byte *) decoded, flags);
clc.voipIncomingSequence[sender] = sequence + frames;
}
diff --git a/src/client/client.h b/src/client/client.h
index 3db4e27f..65ff9084 100644
--- a/src/client/client.h
+++ b/src/client/client.h
@@ -253,9 +253,10 @@ typedef struct {
qboolean voipMuteAll;
// outgoing data...
- int voipTarget1; // these three ints make up a bit mask of 92 bits.
- int voipTarget2; // the bits say who a VoIP pack is addressed to:
- int voipTarget3; // (1 << clientnum). See cl_voipSendTarget cvar.
+ // if voipTargets[i / 8] & (1 << (i % 8)),
+ // then we are sending to clientnum i.
+ uint8_t voipTargets[(MAX_CLIENTS + 7) / 8];
+ uint8_t voipFlags;
SpeexPreprocessState *speexPreprocessor;
SpeexBits speexEncoderBits;
void *speexEncoder;
diff --git a/src/client/snd_dma.c b/src/client/snd_dma.c
index fd6edf03..e3ab881c 100644
--- a/src/client/snd_dma.c
+++ b/src/client/snd_dma.c
@@ -932,7 +932,8 @@ S_Base_RawSamples
Music streaming
============
*/
-void S_Base_RawSamples( int stream, int samples, int rate, int width, int s_channels, const byte *data, float volume ) {
+void S_Base_RawSamples( int stream, int samples, int rate, int width, int s_channels, const byte *data, float volume, int entityNum)
+{
int i;
int src, dst;
float scale;
@@ -943,9 +944,16 @@ void S_Base_RawSamples( int stream, int samples, int rate, int width, int s_chan
return;
}
+ if(entityNum >= 0)
+ {
+ // FIXME: support spatialized raw streams, e.g. for VoIP
+ return;
+ }
+
if ( (stream < 0) || (stream >= MAX_RAW_STREAMS) ) {
return;
}
+
rawsamples = s_rawsamples[stream];
if(s_muted->integer)
@@ -1411,8 +1419,8 @@ void S_UpdateBackgroundTrack( void ) {
if(r > 0)
{
// add to raw buffer
- S_Base_RawSamples( 0, fileSamples, s_backgroundStream->info.rate,
- s_backgroundStream->info.width, s_backgroundStream->info.channels, raw, s_musicVolume->value );
+ S_Base_RawSamples(0, fileSamples, s_backgroundStream->info.rate,
+ s_backgroundStream->info.width, s_backgroundStream->info.channels, raw, s_musicVolume->value, -1);
}
else
{
diff --git a/src/client/snd_local.h b/src/client/snd_local.h
index 4cf31774..f139fa5e 100644
--- a/src/client/snd_local.h
+++ b/src/client/snd_local.h
@@ -127,7 +127,7 @@ typedef struct
void (*StartLocalSound)( sfxHandle_t sfx, int channelNum );
void (*StartBackgroundTrack)( const char *intro, const char *loop );
void (*StopBackgroundTrack)( void );
- void (*RawSamples)(int stream, int samples, int rate, int width, int channels, const byte *data, float volume);
+ void (*RawSamples)(int stream, int samples, int rate, int width, int channels, const byte *data, float volume, int entityNum);
void (*StopAllSounds)( void );
void (*ClearLoopingSounds)( qboolean killall );
void (*AddLoopingSound)( int entityNum, const vec3_t origin, const vec3_t velocity, sfxHandle_t sfx );
@@ -189,7 +189,7 @@ extern vec3_t listener_up;
extern dma_t dma;
#define MAX_RAW_SAMPLES 16384
-#define MAX_RAW_STREAMS 128
+#define MAX_RAW_STREAMS (MAX_CLIENTS * 2 + 1)
extern portable_samplepair_t s_rawsamples[MAX_RAW_STREAMS][MAX_RAW_SAMPLES];
extern int s_rawend[MAX_RAW_STREAMS];
diff --git a/src/client/snd_main.c b/src/client/snd_main.c
index 59559deb..ff233039 100644
--- a/src/client/snd_main.c
+++ b/src/client/snd_main.c
@@ -131,11 +131,10 @@ S_RawSamples
=================
*/
void S_RawSamples (int stream, int samples, int rate, int width, int channels,
- const byte *data, float volume)
+ const byte *data, float volume, int entityNum)
{
- if( si.RawSamples ) {
- si.RawSamples( stream, samples, rate, width, channels, data, volume );
- }
+ if(si.RawSamples)
+ si.RawSamples(stream, samples, rate, width, channels, data, volume, entityNum);
}
/*
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);
}
diff --git a/src/client/snd_public.h b/src/client/snd_public.h
index 20c1c7f6..193f89ee 100644
--- a/src/client/snd_public.h
+++ b/src/client/snd_public.h
@@ -34,8 +34,8 @@ void S_StopBackgroundTrack( void );
// cinematics and voice-over-network will send raw samples
// 1.0 volume will be direct output of source samples
-void S_RawSamples (int stream, int samples, int rate, int width, int channels,
- const byte *data, float volume);
+void S_RawSamples(int stream, int samples, int rate, int width, int channels,
+ const byte *data, float volume, int entityNum);
// stop all sounds and the background track
void S_StopAllSounds( void );