From: Carsten W. <ca...@us...> - 2006-10-18 21:15:20
|
Update of /cvsroot/jake2/jake2/src/jake2/sound/joal In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv11824/src/jake2/sound/joal Modified Files: Tag: render-refactoring JOALSoundImpl.java Channel.java Log Message: switch to joal 1.0b01 (new libraries, API changes, tested on MacBook Pro (univeral binaries)) TODO * joal via webstart from sun Index: Channel.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/sound/joal/Channel.java,v retrieving revision 1.4.6.1 retrieving revision 1.4.6.2 diff -C2 -d -r1.4.6.1 -r1.4.6.2 *** Channel.java 25 Dec 2005 18:16:06 -0000 1.4.6.1 --- Channel.java 18 Oct 2006 21:15:14 -0000 1.4.6.2 *************** *** 109,113 **** for (int i = 0; i < MAX_CHANNELS; i++) { ! al.alGenSources(1, tmp); sourceId = tmp[0]; --- 109,113 ---- for (int i = 0; i < MAX_CHANNELS; i++) { ! al.alGenSources(1, tmp, 0); sourceId = tmp[0]; *************** *** 122,127 **** 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_LOOPING, AL.AL_FALSE); al.alSourcef (sourceId, AL.AL_REFERENCE_DISTANCE, 200.0f); --- 122,127 ---- al.alSourcef (sourceId, AL.AL_GAIN, 1.0f); al.alSourcef (sourceId, AL.AL_PITCH, 1.0f); ! 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); *************** *** 142,146 **** static void shutdown() { ! al.alDeleteSources(numChannels, sources); numChannels = 0; isInitialized = false; --- 142,146 ---- static void shutdown() { ! al.alDeleteSources(numChannels, sources, 0); numChannels = 0; isInitialized = false; *************** *** 167,171 **** unqueueStreams(); int source = channels[numChannels].sourceId; ! al.alSourcei (source, AL.AL_SOURCE_ABSOLUTE, AL.AL_TRUE); // free the last source --- 167,171 ---- unqueueStreams(); int source = channels[numChannels].sourceId; ! al.alSourcei (source, AL.AL_SOURCE_RELATIVE, AL.AL_FALSE); // free the last source *************** *** 181,188 **** // stop streaming al.alSourceStop(source); ! int count = al.alGetSourcei(source, AL.AL_BUFFERS_QUEUED); Com.DPrintf("unqueue " + count + " buffers\n"); while (count-- > 0) { ! al.alSourceUnqueueBuffers(source, 1, tmp); } streamQueue = 0; --- 181,190 ---- // stop streaming al.alSourceStop(source); ! 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, 0); } streamQueue = 0; *************** *** 193,199 **** 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); boolean interupted = !playing && streamQueue > 2; --- 195,205 ---- int[] buffer = tmp; int source = channels[numChannels].sourceId; ! 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; *************** *** 209,213 **** } else { // reuse the buffer ! al.alSourceUnqueueBuffers(source, 1, buffer); } --- 215,219 ---- } else { // reuse the buffer ! al.alSourceUnqueueBuffers(source, 1, buffer, 0); } *************** *** 215,219 **** samples.limit(count); al.alBufferData(buffer[0], format, samples, count, rate); ! al.alSourceQueueBuffers(source, 1, buffer); if (streamQueue > 1 && !playing) { --- 221,225 ---- samples.limit(count); al.alBufferData(buffer[0], format, samples, count, rate); ! al.alSourceQueueBuffers(source, 1, buffer, 0); if (streamQueue > 1 && !playing) { *************** *** 299,302 **** --- 305,309 ---- int sourceId; int state; + int[] tmp = new int[]{0}; for (int i = 0; i < numChannels; i++) { *************** *** 325,335 **** } al.alSourcef (sourceId, AL.AL_ROLLOFF_FACTOR, ch.rolloff); ! al.alSourcefv(sourceId, AL.AL_POSITION, sourceOrigin); 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); } else { ch.clear(); --- 332,343 ---- } al.alSourcef (sourceId, AL.AL_ROLLOFF_FACTOR, ch.rolloff); ! al.alSourcefv(sourceId, AL.AL_POSITION, sourceOrigin, 0); al.alSourcePlay(sourceId); ch.modified = false; } else { ! 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(); Index: JOALSoundImpl.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/sound/joal/JOALSoundImpl.java,v retrieving revision 1.13.6.1 retrieving revision 1.13.6.2 diff -C2 -d -r1.13.6.1 -r1.13.6.2 *** JOALSoundImpl.java 25 Dec 2005 18:16:06 -0000 1.13.6.1 --- JOALSoundImpl.java 18 Oct 2006 21:15:14 -0000 1.13.6.2 *************** *** 21,24 **** --- 21,25 ---- import net.java.games.joal.eax.EAX; import net.java.games.joal.eax.EAXFactory; + import net.java.games.joal.util.ALut; /** *************** *** 69,93 **** */ 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(); al = ALFactory.getAL(); checkError(); initOpenALExtensions(); ! } catch (OpenALException e) { Com.Printf(e.getMessage() + '\n'); return false; } catch (Throwable e) { ! Com.DPrintf(e.getMessage() + '\n'); return false; } --- 70,85 ---- */ public boolean Init() { ! try { ! ALut.alutInit(); al = ALFactory.getAL(); + alc = ALFactory.getALC(); checkError(); initOpenALExtensions(); ! } catch (ALException e) { Com.Printf(e.getMessage() + '\n'); return false; } catch (Throwable e) { ! Com.Printf(e.toString() + '\n'); return false; } *************** *** 95,99 **** s_volume = Cvar.Get("s_volume", "0.7", Defines.CVAR_ARCHIVE); ! al.alGenBuffers(buffers.length, buffers); int count = Channel.init(al, buffers); Com.Printf("... using " + count + " channels\n"); --- 87,91 ---- s_volume = Cvar.Get("s_volume", "0.7", Defines.CVAR_ARCHIVE); ! al.alGenBuffers(buffers.length, buffers, 0); int count = Channel.init(al, buffers); Com.Printf("... using " + count + " channels\n"); *************** *** 128,156 **** 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")) { --- 120,124 ---- return true; } ! private void initOpenALExtensions() { if (al.alIsExtensionPresent("EAX2.0")) { *************** *** 165,171 **** void exitOpenAL() { // Get the current context. ! ALC.Context curContext = alc.alcGetCurrentContext(); // Get the device used by that context. ! ALC.Device curDevice = alc.alcGetContextsDevice(curContext); // Reset the current context to NULL. alc.alcMakeContextCurrent(null); --- 133,139 ---- void exitOpenAL() { // Get the current context. ! ALCcontext curContext = alc.alcGetCurrentContext(); // Get the device used by that context. ! ALCdevice curDevice = alc.alcGetContextsDevice(curContext); // Reset the current context to NULL. alc.alcMakeContextCurrent(null); *************** *** 214,218 **** StopAllSounds(); Channel.shutdown(); ! al.alDeleteBuffers(buffers.length, buffers); exitOpenAL(); --- 182,186 ---- StopAllSounds(); Channel.shutdown(); ! al.alDeleteBuffers(buffers.length, buffers, 0); exitOpenAL(); *************** *** 268,275 **** public void Update(float[] origin, float[] forward, float[] right, float[] up) { Channel.convertVector(origin, listenerOrigin); ! al.alListenerfv(AL.AL_POSITION, listenerOrigin); Channel.convertOrientation(forward, up, listenerOrientation); ! al.alListenerfv(AL.AL_ORIENTATION, listenerOrientation); // set the listener (master) volume --- 236,243 ---- public void Update(float[] origin, float[] forward, float[] right, float[] up) { Channel.convertVector(origin, listenerOrigin); ! al.alListenerfv(AL.AL_POSITION, listenerOrigin, 0); Channel.convertOrientation(forward, up, listenerOrientation); ! al.alListenerfv(AL.AL_ORIENTATION, listenerOrientation, 0); // set the listener (master) volume |