From 29d109f8efdff9c1a90ca8079f0eea5dc2c38c28 Mon Sep 17 00:00:00 2001 From: xorw <10dmar10@gmail.com> Date: Wed, 10 May 2017 12:21:56 +0200 Subject: [PATCH] Finished doppler shift support (added listener's velocity update) --- src/client/cl_entities.c | 10 ++++++++++ src/client/sound/header/sound.h | 1 + src/client/sound/openal.c | 7 +++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/client/cl_entities.c b/src/client/cl_entities.c index dc34e904..69da83e7 100644 --- a/src/client/cl_entities.c +++ b/src/client/cl_entities.c @@ -933,3 +933,13 @@ CL_GetEntitySoundVelocity(int ent, vec3_t vel) VectorSubtract(old->current.origin, old->prev.origin, vel); } +void +CL_GetViewVelocity(vec3_t vel) +{ + // restore value from 12.3 fixed point + const float scale_factor = 1.0f / 8.0f; + + vel[0] = (float)cl.frame.playerstate.pmove.velocity[0] * scale_factor; + vel[1] = (float)cl.frame.playerstate.pmove.velocity[1] * scale_factor; + vel[2] = (float)cl.frame.playerstate.pmove.velocity[2] * scale_factor; +} diff --git a/src/client/sound/header/sound.h b/src/client/sound/header/sound.h index 9defde89..9ad79b38 100644 --- a/src/client/sound/header/sound.h +++ b/src/client/sound/header/sound.h @@ -55,5 +55,6 @@ struct sfx_s *S_FindName(char *name, qboolean create); dynamically re-spatialized */ void CL_GetEntitySoundOrigin(int ent, vec3_t org); void CL_GetEntitySoundVelocity(int ent, vec3_t vel); +void CL_GetViewVelocity(vec3_t vel); #endif diff --git a/src/client/sound/openal.c b/src/client/sound/openal.c index d172b937..93ebf1b4 100644 --- a/src/client/sound/openal.c +++ b/src/client/sound/openal.c @@ -607,6 +607,7 @@ AL_Update(void) int i; channel_t *ch; vec_t orientation[6]; + vec3_t listener_velocity; paintedtime = cls.realtime; @@ -617,8 +618,10 @@ AL_Update(void) qalListener3f(AL_POSITION, AL_UnpackVector(listener_origin)); qalListenerfv(AL_ORIENTATION, orientation); - // TODO(xorw): add current listener's velocity update - // qalListener3f(AL_VELOCITY, AL_UnpackVector(listener_velocity)); + CL_GetViewVelocity(listener_velocity); + // xorw: sounds funky if not scaled down a lot + VectorScale(listener_velocity, 0.05f, listener_velocity); + qalListener3f(AL_VELOCITY, AL_UnpackVector(listener_velocity)); /* update spatialization for dynamic sounds */ ch = channels;