From: Carsten W. <ca...@us...> - 2004-07-13 11:20:39
|
Update of /cvsroot/jake2/jake2/src/jake2/sound/joal In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17083/src/jake2/sound/joal Modified Files: JOALSoundImpl.java Log Message: experimental EAX2.0 support (today only win32 is supported) Index: JOALSoundImpl.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/sound/joal/JOALSoundImpl.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JOALSoundImpl.java 9 Jul 2004 06:50:52 -0000 1.1 --- JOALSoundImpl.java 13 Jul 2004 11:20:28 -0000 1.2 *************** *** 7,11 **** package jake2.sound.joal; - import jake2.Defines; import jake2.Globals; --- 7,10 ---- *************** *** 14,25 **** import jake2.qcommon.*; import jake2.sound.*; ! import jake2.util.Math3D; ! import jake2.util.Vargs; import java.io.IOException; import java.io.RandomAccessFile; import java.util.*; import net.java.games.joal.*; /** --- 13,26 ---- import jake2.qcommon.*; import jake2.sound.*; ! import jake2.util.*; import java.io.IOException; import java.io.RandomAccessFile; + import java.nio.IntBuffer; import java.util.*; import net.java.games.joal.*; + import net.java.games.joal.eax.EAX; + import net.java.games.joal.eax.EAXFactory; /** *************** *** 34,37 **** --- 35,39 ---- static AL al; static ALC alc; + static EAX eax; cvar_t s_volume; *************** *** 43,51 **** private int[] sources = new int[MAX_CHANNELS]; private Channel[] channels = null; private JOALSoundImpl() { } - /* (non-Javadoc) * @see jake2.sound.SoundImpl#Init() --- 45,54 ---- private int[] sources = new int[MAX_CHANNELS]; private Channel[] channels = null; + private int num_channels = 0; + // singleton private JOALSoundImpl() { } /* (non-Javadoc) * @see jake2.sound.SoundImpl#Init() *************** *** 57,73 **** al = ALFactory.getAL(); checkError(); } catch (OpenALException e) { Com.Printf(e.getMessage() + '\n'); return false; } - - checkError(); al.alGenBuffers(MAX_SFX, buffers); - al.alGenSources(MAX_CHANNELS, sources); - checkError(); s_volume = Cvar.Get("s_volume", "0.7", Defines.CVAR_ARCHIVE); initChannels(); al.alDistanceModel(AL.AL_INVERSE_DISTANCE_CLAMPED); - // al.alDistanceModel(AL.AL_INVERSE_DISTANCE); Cmd.AddCommand("play", new xcommand_t() { public void execute() { --- 60,72 ---- al = ALFactory.getAL(); checkError(); + initOpenALExtensions(); } catch (OpenALException e) { Com.Printf(e.getMessage() + '\n'); return false; } al.alGenBuffers(MAX_SFX, buffers); s_volume = Cvar.Get("s_volume", "0.7", Defines.CVAR_ARCHIVE); initChannels(); al.alDistanceModel(AL.AL_INVERSE_DISTANCE_CLAMPED); Cmd.AddCommand("play", new xcommand_t() { public void execute() { *************** *** 125,128 **** --- 124,138 ---- } + private void initOpenALExtensions() throws OpenALException { + if (al.alIsExtensionPresent("EAX2.0")) { + Com.Printf("... using EAX2.0\n"); + eax = EAXFactory.getEAX(); + } else { + Com.Printf("... EAX2.0 not found\n"); + eax = null; + } + } + + void exitOpenAL() { // Get the current context. *************** *** 143,149 **** int sourceId; for (int i = 0; i < MAX_CHANNELS; i++) { ! sourceId = sources[i]; channels[i] = new Channel(sourceId); // set default values for AL sources --- 153,170 ---- int sourceId; + int[] tmp = {0}; + int error; for (int i = 0; i < MAX_CHANNELS; i++) { ! ! al.alGenSources(1, tmp); ! sourceId = tmp[0]; ! ! //if ((error = al.alGetError()) != AL.AL_NO_ERROR) break; ! if (sourceId <= 0) break; ! ! sources[i] = sourceId; ! channels[i] = new Channel(sourceId); + num_channels++; // set default values for AL sources *************** *** 157,160 **** --- 178,182 ---- al.alSourcef (sourceId, AL.AL_MAX_GAIN, 1.0f); } + Com.Printf("... using " + num_channels + " channels\n"); } *************** *** 163,168 **** * @see jake2.sound.SoundImpl#RegisterSound(jake2.sound.sfx_t) */ ! private void initBuffer(sfx_t sfx) ! { if (sfx.cache == null ) { //System.out.println(sfx.name + " " + sfx.cache.length+ " " + sfx.cache.loopstart + " " + sfx.cache.speed + " " + sfx.cache.stereo + " " + sfx.cache.width); --- 185,189 ---- * @see jake2.sound.SoundImpl#RegisterSound(jake2.sound.sfx_t) */ ! private void initBuffer(sfx_t sfx) { if (sfx.cache == null ) { //System.out.println(sfx.name + " " + sfx.cache.length+ " " + sfx.cache.loopstart + " " + sfx.cache.speed + " " + sfx.cache.stereo + " " + sfx.cache.width); *************** *** 175,205 **** int size = data.length; ! // if (buffers[sfx.id] != 0) ! // al.alDeleteBuffers(1, new int[] {buffers[sfx.id] }); ! // ! // int[] bid = new int[1]; ! // al.alBufferData( bid[0], format, data, size, freq); ! // buffers[sfx.id] = bid[0]; ! // al.alBufferData( bid[0], format, data, size, freq); ! ! al.alBufferData( buffers[sfx.id], format, data, size, freq); ! // int error; ! // if ((error = al.alGetError()) != AL.AL_NO_ERROR) { ! // String message; ! // switch(error) { ! // case AL.AL_INVALID_OPERATION: message = "invalid operation"; break; ! // case AL.AL_INVALID_VALUE: message = "invalid value"; break; ! // case AL.AL_INVALID_ENUM: message = "invalid enum"; break; ! // case AL.AL_INVALID_NAME: message = "invalid name"; break; ! // default: message = "" + error; ! // } ! // Com.DPrintf("Error Buffer " + sfx.id + ": " + sfx.name + " (" + size + ") --> " + message + '\n'); ! // } } private void checkError() { int error; if ((error = al.alGetError()) != AL.AL_NO_ERROR) { - String message; switch(error) { case AL.AL_INVALID_OPERATION: message = "invalid operation"; break; --- 196,210 ---- int size = data.length; ! al.alBufferData( buffers[sfx.bufferId], format, data, size, freq); } private void checkError() { + Com.DPrintf("AL Error: " + alErrorString() +'\n'); + } + + private String alErrorString(){ int error; + String message = ""; if ((error = al.alGetError()) != AL.AL_NO_ERROR) { switch(error) { case AL.AL_INVALID_OPERATION: message = "invalid operation"; break; *************** *** 209,217 **** default: message = "" + error; } - Com.DPrintf("AL Error: " + message +'\n'); } } - /* (non-Javadoc) * @see jake2.sound.SoundImpl#Shutdown() --- 214,221 ---- default: message = "" + error; } } + return message; } /* (non-Javadoc) * @see jake2.sound.SoundImpl#Shutdown() *************** *** 222,226 **** al.alDeleteBuffers(buffers.length, buffers); exitOpenAL(); ! //ALut.alutExit(); Cmd.RemoveCommand("play"); Cmd.RemoveCommand("stopsound"); --- 226,230 ---- al.alDeleteBuffers(buffers.length, buffers); exitOpenAL(); ! Cmd.RemoveCommand("play"); Cmd.RemoveCommand("stopsound"); *************** *** 235,238 **** --- 239,243 ---- } num_sfx = 0; + num_channels = 0; } *************** *** 258,262 **** attenuation *= 0.5f; ! Channel ch = pickChannel(entnum, entchannel, buffers[sfx.id], attenuation); if (ch == null) return; --- 263,267 ---- attenuation *= 0.5f; ! Channel ch = pickChannel(entnum, entchannel, buffers[sfx.bufferId], attenuation); if (ch == null) return; *************** *** 277,281 **** int i; ! for (i = 0; i < MAX_CHANNELS; i++) { ch = channels[i]; --- 282,286 ---- int i; ! for (i = 0; i < num_channels; i++) { ch = channels[i]; *************** *** 295,299 **** } ! if (i == MAX_CHANNELS) return null; --- 300,304 ---- } ! if (i == num_channels) return null; *************** *** 313,316 **** --- 318,330 ---- private float[] listenerOrigin = {0, 0, 0}; private float[] listenerOrientation = {0, 0, 0, 0, 0, 0}; + private IntBuffer eaxEnv = Lib.newIntBuffer(1); + private int currentEnv = -1; + private boolean changeEnv = true; + + // TODO workaround for JOAL-bug + // should be EAX.LISTENER + private final static int EAX_LISTENER = 0; + // should be EAX.SOURCE + private final static int EAX_SOURCE = 1; /* (non-Javadoc) *************** *** 325,333 **** al.alListenerfv(AL.AL_ORIENTATION, listenerOrientation); AddLoopSounds(origin); playChannels(listenerOrigin); } ! Map looptable = new Hashtable(2 * MAX_CHANNELS); /* --- 339,368 ---- al.alListenerfv(AL.AL_ORIENTATION, listenerOrientation); + if (eax != null) { + // workaround for environment initialisation + if (currentEnv == -1) { + eaxEnv.put(0, EAX.EAX_ENVIRONMENT_UNDERWATER); + eax.EAXSet(EAX_LISTENER, EAX.DSPROPERTY_EAXLISTENER_ENVIRONMENT | EAX.DSPROPERTY_EAXLISTENER_DEFERRED, 0, eaxEnv, 4); + changeEnv = true; + } + + if ((Game.gi.pointcontents.pointcontents(origin)& Defines.MASK_WATER)!= 0) { + changeEnv = currentEnv != EAX.EAX_ENVIRONMENT_UNDERWATER; + currentEnv = EAX.EAX_ENVIRONMENT_UNDERWATER; + } else { + changeEnv = currentEnv != EAX.EAX_ENVIRONMENT_GENERIC; + currentEnv = EAX.EAX_ENVIRONMENT_GENERIC; + } + if (changeEnv) { + eaxEnv.put(0, currentEnv); + eax.EAXSet(EAX_LISTENER, EAX.DSPROPERTY_EAXLISTENER_ENVIRONMENT | EAX.DSPROPERTY_EAXLISTENER_DEFERRED, 0, eaxEnv, 4); + } + } + AddLoopSounds(origin); playChannels(listenerOrigin); } ! Map looptable = new Hashtable(MAX_CHANNELS); /* *************** *** 391,395 **** // allocate a channel ! ch = pickChannel(0, 0, buffers[sfx.id], 6); if (ch == null) break; --- 426,430 ---- // allocate a channel ! ch = pickChannel(0, 0, buffers[sfx.bufferId], 6); if (ch == null) break; *************** *** 428,432 **** int state; ! for (int i = 0; i < MAX_CHANNELS; i++) { ch = channels[i]; if (ch.active) { --- 463,467 ---- int state; ! for (int i = 0; i < num_channels; i++) { ch = channels[i]; if (ch.active) { *************** *** 467,471 **** } } - /* (non-Javadoc) --- 502,505 ---- *************** *** 473,477 **** */ public void StopAllSounds() { ! for (int i = 0; i < MAX_CHANNELS; i++) { al.alSourceStop(sources[i]); al.alSourcei(sources[i], AL.AL_BUFFER, 0); --- 507,511 ---- */ public void StopAllSounds() { ! for (int i = 0; i < num_channels; i++) { al.alSourceStop(sources[i]); al.alSourcei(sources[i], AL.AL_BUFFER, 0); *************** *** 562,565 **** --- 596,600 ---- // determine what model the client is using + // TODO configstrings for player male and female are wrong String model = "male"; int n = Globals.CS_PLAYERSKINS + ent.number - 1; *************** *** 598,608 **** } else { // no, revert to the male sound in the pak0.pak - //Com_sprintf (maleFilename, sizeof(maleFilename), "player/%s/%s", "male", base+1); String maleFilename = "player/male/" + base.substring(1); sfx = AliasName(sexedFilename, maleFilename); } } - - //System.out.println(sfx.name); return sfx; } --- 633,640 ---- *************** *** 653,658 **** sfx.name = name; sfx.registration_sequence = s_registration_sequence; ! // cwei ! sfx.id = i; return sfx; --- 685,689 ---- sfx.name = name; sfx.registration_sequence = s_registration_sequence; ! sfx.bufferId = i; return sfx; *************** *** 690,695 **** sfx.registration_sequence = s_registration_sequence; sfx.truename = s; ! // cwei ! sfx.id = i; return sfx; --- 721,726 ---- sfx.registration_sequence = s_registration_sequence; sfx.truename = s; ! // set the AL bufferId ! sfx.bufferId = i; return sfx; |