diff options
author | Carsten Weisse <[email protected]> | 2006-10-24 22:51:21 +0000 |
---|---|---|
committer | Carsten Weisse <[email protected]> | 2006-10-24 22:51:21 +0000 |
commit | 481d33d34793dd7830987e2a9ad4c372e9da4414 (patch) | |
tree | c17d92d15ebb49d8bc084e1a241c38b74e2cbd29 /src | |
parent | 2f2869e9278bcbf51e2f8e9d66f289a40237e21a (diff) |
switch to joal 1.0b01
(new libraries, API changes)
TODO
* joal via webstart from sun
Diffstat (limited to 'src')
-rw-r--r-- | src/jake2/sound/joal/Channel.java | 40 | ||||
-rw-r--r-- | src/jake2/sound/joal/JOALSoundImpl.java | 60 |
2 files changed, 38 insertions, 62 deletions
diff --git a/src/jake2/sound/joal/Channel.java b/src/jake2/sound/joal/Channel.java index 20d9d83..d69afb9 100644 --- a/src/jake2/sound/joal/Channel.java +++ b/src/jake2/sound/joal/Channel.java @@ -3,7 +3,7 @@ * * Copyright (C) 2003 * - * $Id: Channel.java,v 1.6 2005-12-04 20:56:26 cawe Exp $ + * $Id: Channel.java,v 1.7 2006-10-24 22:51:20 cawe Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. @@ -108,7 +108,7 @@ public class Channel { int sourceId; for (int i = 0; i < MAX_CHANNELS; i++) { - al.alGenSources(1, tmp); + al.alGenSources(1, tmp, 0); sourceId = tmp[0]; if (sourceId <= 0) break; @@ -121,8 +121,8 @@ public class Channel { // set default values for AL sources al.alSourcef (sourceId, AL.AL_GAIN, 1.0f); al.alSourcef (sourceId, AL.AL_PITCH, 1.0f); - al.alSourcei (sourceId, AL.AL_SOURCE_ABSOLUTE, AL.AL_TRUE); - al.alSourcefv(sourceId, AL.AL_VELOCITY, NULLVECTOR); + al.alSourcei (sourceId, AL.AL_SOURCE_RELATIVE, AL.AL_FALSE); + al.alSourcefv(sourceId, AL.AL_VELOCITY, NULLVECTOR, 0); al.alSourcei (sourceId, AL.AL_LOOPING, AL.AL_FALSE); al.alSourcef (sourceId, AL.AL_REFERENCE_DISTANCE, 200.0f); al.alSourcef (sourceId, AL.AL_MIN_GAIN, 0.0005f); @@ -141,7 +141,7 @@ public class Channel { } static void shutdown() { - al.alDeleteSources(numChannels, sources); + al.alDeleteSources(numChannels, sources, 0); numChannels = 0; isInitialized = false; } @@ -166,7 +166,7 @@ public class Channel { if (!streamingEnabled) return; unqueueStreams(); int source = channels[numChannels].sourceId; - al.alSourcei (source, AL.AL_SOURCE_ABSOLUTE, AL.AL_TRUE); + al.alSourcei (source, AL.AL_SOURCE_RELATIVE, AL.AL_FALSE); // free the last source numChannels++; @@ -180,10 +180,12 @@ public class Channel { // stop streaming al.alSourceStop(source); - int count = al.alGetSourcei(source, AL.AL_BUFFERS_QUEUED); + int[] tmpCount = new int[]{0}; + al.alGetSourcei(source, AL.AL_BUFFERS_QUEUED, tmpCount, 0); + int count = tmpCount[0]; Com.DPrintf("unqueue " + count + " buffers\n"); while (count-- > 0) { - al.alSourceUnqueueBuffers(source, 1, tmp); + al.alSourceUnqueueBuffers(source, 1, tmp, 0); } streamQueue = 0; } @@ -192,9 +194,13 @@ public class Channel { enableStreaming(); int[] buffer = tmp; int source = channels[numChannels].sourceId; - int processed = al.alGetSourcei(source, AL.AL_BUFFERS_PROCESSED); - boolean playing = (al.alGetSourcei(source, AL.AL_SOURCE_STATE) == AL.AL_PLAYING); + int[] tmp = new int[]{0}; + al.alGetSourcei(source, AL.AL_BUFFERS_PROCESSED, tmp, 0); + int processed = tmp[0]; + al.alGetSourcei(source, AL.AL_SOURCE_STATE, tmp, 0); + int state = tmp[0]; + boolean playing = ( state == AL.AL_PLAYING); boolean interupted = !playing && streamQueue > 2; if (interupted) { @@ -208,13 +214,13 @@ public class Channel { Com.DPrintf("queue " + (streamQueue - 1) + '\n'); } else { // reuse the buffer - al.alSourceUnqueueBuffers(source, 1, buffer); + al.alSourceUnqueueBuffers(source, 1, buffer, 0); } samples.position(0); samples.limit(count); al.alBufferData(buffer[0], format, samples, count, rate); - al.alSourceQueueBuffers(source, 1, buffer); + al.alSourceQueueBuffers(source, 1, buffer, 0); if (streamQueue > 1 && !playing) { Com.DPrintf("start sound\n"); @@ -298,6 +304,7 @@ public class Channel { Channel ch; int sourceId; int state; + int[] tmp = new int[]{0}; for (int i = 0; i < numChannels; i++) { ch = channels[i]; @@ -324,13 +331,14 @@ public class Channel { al.alSourcef (sourceId, AL.AL_GAIN, ch.volume); } al.alSourcef (sourceId, AL.AL_ROLLOFF_FACTOR, ch.rolloff); - al.alSourcefv(sourceId, AL.AL_POSITION, sourceOrigin); + al.alSourcefv(sourceId, AL.AL_POSITION, sourceOrigin, 0); al.alSourcePlay(sourceId); ch.modified = false; } else { - state = al.alGetSourcei(sourceId, AL.AL_SOURCE_STATE); - if (state == AL.AL_PLAYING) { - al.alSourcefv(sourceId, AL.AL_POSITION, sourceOrigin); + al.alGetSourcei(sourceId, AL.AL_SOURCE_STATE, tmp , 0); + state = tmp[0]; + if (state == AL.AL_PLAYING) { + al.alSourcefv(sourceId, AL.AL_POSITION, sourceOrigin, 0); } else { ch.clear(); } diff --git a/src/jake2/sound/joal/JOALSoundImpl.java b/src/jake2/sound/joal/JOALSoundImpl.java index 6011285..0b82a1d 100644 --- a/src/jake2/sound/joal/JOALSoundImpl.java +++ b/src/jake2/sound/joal/JOALSoundImpl.java @@ -2,7 +2,7 @@ * JOALSoundImpl.java * Copyright (C) 2004 * - * $Id: JOALSoundImpl.java,v 1.15 2005-12-04 19:21:04 cawe Exp $ + * $Id: JOALSoundImpl.java,v 1.16 2006-10-24 22:51:20 cawe Exp $ */ package jake2.sound.joal; @@ -20,6 +20,7 @@ import java.nio.*; import net.java.games.joal.*; import net.java.games.joal.eax.EAX; import net.java.games.joal.eax.EAXFactory; +import net.java.games.joal.util.ALut; /** * JOALSoundImpl @@ -68,33 +69,24 @@ public final class JOALSoundImpl implements Sound { * @see jake2.sound.SoundImpl#Init() */ public boolean Init() { - - // preload OpenAL native library - String os = System.getProperty("os.name"); - if (os.startsWith("Linux")) { - unpack(); - } else if (os.startsWith("Windows")) { - try { - System.loadLibrary("OpenAL32"); - } catch (Throwable e) {} - } - + try { - initOpenAL(); + ALut.alutInit(); al = ALFactory.getAL(); + alc = ALFactory.getALC(); checkError(); initOpenALExtensions(); - } catch (OpenALException e) { + } catch (ALException e) { Com.Printf(e.getMessage() + '\n'); return false; } catch (Throwable e) { - Com.DPrintf(e.getMessage() + '\n'); + Com.Printf(e.toString() + '\n'); return false; } // set the master volume s_volume = Cvar.Get("s_volume", "0.7", Defines.CVAR_ARCHIVE); - al.alGenBuffers(buffers.length, buffers); + al.alGenBuffers(buffers.length, buffers, 0); int count = Channel.init(al, buffers); Com.Printf("... using " + count + " channels\n"); al.alDistanceModel(AL.AL_INVERSE_DISTANCE_CLAMPED); @@ -127,31 +119,7 @@ public final class JOALSoundImpl implements Sound { Com.Printf("------------------------------------\n"); return true; } - - - private void initOpenAL() throws OpenALException { - ALFactory.initialize(); - alc = ALFactory.getALC(); - String deviceName = null; - - String os = System.getProperty("os.name"); - if (os.startsWith("Windows")) { - deviceName = "DirectSound3D"; - } - ALC.Device device = alc.alcOpenDevice(deviceName); - String deviceSpecifier = alc.alcGetString(device, ALC.ALC_DEVICE_SPECIFIER); - String defaultSpecifier = alc.alcGetString(device, ALC.ALC_DEFAULT_DEVICE_SPECIFIER); - - Com.Printf(os + " using " + ((deviceName == null) ? defaultSpecifier : deviceName) + '\n'); - - ALC.Context context = alc.alcCreateContext(device, new int[] {0}); - alc.alcMakeContextCurrent(context); - // Check for an error. - if (alc.alcGetError(device) != ALC.ALC_NO_ERROR) { - Com.DPrintf("Error with SoundDevice"); - } - } - + private void initOpenALExtensions() { if (al.alIsExtensionPresent("EAX2.0")) { Com.Printf("... using EAX2.0\n"); @@ -164,9 +132,9 @@ public final class JOALSoundImpl implements Sound { void exitOpenAL() { // Get the current context. - ALC.Context curContext = alc.alcGetCurrentContext(); + ALCcontext curContext = alc.alcGetCurrentContext(); // Get the device used by that context. - ALC.Device curDevice = alc.alcGetContextsDevice(curContext); + ALCdevice curDevice = alc.alcGetContextsDevice(curContext); // Reset the current context to NULL. alc.alcMakeContextCurrent(null); // Release the context and the device. @@ -213,7 +181,7 @@ public final class JOALSoundImpl implements Sound { public void Shutdown() { StopAllSounds(); Channel.shutdown(); - al.alDeleteBuffers(buffers.length, buffers); + al.alDeleteBuffers(buffers.length, buffers, 0); exitOpenAL(); Cmd.RemoveCommand("play"); @@ -267,10 +235,10 @@ public final class JOALSoundImpl implements Sound { */ public void Update(float[] origin, float[] forward, float[] right, float[] up) { Channel.convertVector(origin, listenerOrigin); - al.alListenerfv(AL.AL_POSITION, listenerOrigin); + al.alListenerfv(AL.AL_POSITION, listenerOrigin, 0); Channel.convertOrientation(forward, up, listenerOrientation); - al.alListenerfv(AL.AL_ORIENTATION, listenerOrientation); + al.alListenerfv(AL.AL_ORIENTATION, listenerOrientation, 0); // set the listener (master) volume al.alListenerf(AL.AL_GAIN, s_volume.value); |