From 06d4d63e21a0771bae2932e3284e2d90fd25a9cf Mon Sep 17 00:00:00 2001 From: Carsten Weisse Date: Sun, 8 May 2005 13:37:46 +0000 Subject: handles different source volumes (e.g. explosions far away) --- src/jake2/sound/lwjgl/Channel.java | 27 +++++++++++++++++---------- src/jake2/sound/lwjgl/PlaySound.java | 6 +++--- 2 files changed, 20 insertions(+), 13 deletions(-) (limited to 'src/jake2/sound/lwjgl') diff --git a/src/jake2/sound/lwjgl/Channel.java b/src/jake2/sound/lwjgl/Channel.java index ffa2f8b..daed9db 100644 --- a/src/jake2/sound/lwjgl/Channel.java +++ b/src/jake2/sound/lwjgl/Channel.java @@ -3,7 +3,7 @@ * * Copyright (C) 2003 * - * $Id: Channel.java,v 1.5 2005-04-27 12:41:47 cawe Exp $ + * $Id: Channel.java,v 1.6 2005-05-08 13:37:46 cawe Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. @@ -71,25 +71,27 @@ public class Channel { private int entchannel; private int bufferId; private int sourceId; - // private float volume; + private float volume; private float rolloff; private float[] origin = {0, 0, 0}; // update flags - private boolean autosound = false; - private boolean active = false; - private boolean modified = false; - private boolean bufferChanged = false; + private boolean autosound; + private boolean active; + private boolean modified; + private boolean bufferChanged; + private boolean volumeChanged; private Channel(int sourceId) { this.sourceId = sourceId; clear(); + volumeChanged = false; + volume = 1.0f; } private void clear() { entnum = entchannel = bufferId = -1; bufferChanged = false; - // volume = 1.0f; rolloff = 0; autosound = false; active = false; @@ -183,7 +185,8 @@ public class Channel { ch.bufferChanged = (ch.bufferId != ps.bufferId); ch.bufferId = ps.bufferId; ch.rolloff = ps.attenuation * 2; - //ch.volume = ps.volume; + ch.volumeChanged = (ch.volume != ps.volume); + ch.volume = ps.volume; ch.active = true; ch.modified = true; return true; @@ -199,7 +202,9 @@ public class Channel { ch.entchannel = 0; ch.bufferChanged = (ch.bufferId != bufferId); ch.bufferId = bufferId; - ch.rolloff = attenuation * 2; + ch.volumeChanged = (ch.volume != 1.0f); + ch.volume = 1.0f; + ch.rolloff = attenuation * 2; ch.active = true; ch.modified = true; return ch; @@ -242,7 +247,9 @@ public class Channel { if (ch.bufferChanged) { AL10.alSourcei(sourceId, AL10.AL_BUFFER, ch.bufferId); } - // AL10.alSourcef (sourceId, AL10.AL_GAIN, ch.volume); + if (ch.volumeChanged) { + AL10.alSourcef (sourceId, AL10.AL_GAIN, ch.volume); + } AL10.alSourcef (sourceId, AL10.AL_ROLLOFF_FACTOR, ch.rolloff); AL10.nalSourcefv(sourceId, AL10.AL_POSITION, sourceOrigin, 0); AL10.alSourcePlay(sourceId); diff --git a/src/jake2/sound/lwjgl/PlaySound.java b/src/jake2/sound/lwjgl/PlaySound.java index 703e80c..1e3c4f8 100644 --- a/src/jake2/sound/lwjgl/PlaySound.java +++ b/src/jake2/sound/lwjgl/PlaySound.java @@ -3,7 +3,7 @@ * * Copyright (C) 2003 * - * $Id: PlaySound.java,v 1.1 2004-12-23 00:52:12 cawe Exp $ + * $Id: PlaySound.java,v 1.2 2005-05-08 13:37:46 cawe Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. @@ -59,7 +59,7 @@ public class PlaySound { int entnum; int entchannel; int bufferId; - // float volume; + float volume; float attenuation; float[] origin = {0,0,0}; @@ -158,7 +158,7 @@ public class PlaySound { ps.entnum = entnum; ps.entchannel = entchannel; ps.bufferId = bufferId; - // ps.volume = volume; + ps.volume = volume; ps.attenuation = attenuation; ps.beginTime = Globals.cl.time + (long)(timeoffset * 1000); PlaySound.add(ps); -- cgit v1.2.3