From d75b7a11ba5e32dcbcfd824b702e23a380adefc7 Mon Sep 17 00:00:00 2001 From: Xerxes Rånby Date: Thu, 6 Dec 2012 09:49:21 +0100 Subject: Fix static initialization of JOAL. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Xerxes Rånby --- src/jake2/sound/joal/Channel.java | 26 +++++++++++++++++++------- src/jake2/sound/joal/JOALSoundImpl.java | 20 ++++++++------------ 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/jake2/sound/joal/Channel.java b/src/jake2/sound/joal/Channel.java index 86a5990..d786a56 100644 --- a/src/jake2/sound/joal/Channel.java +++ b/src/jake2/sound/joal/Channel.java @@ -60,7 +60,7 @@ public class Channel { private static int[] sources = new int[MAX_CHANNELS]; // a reference of JOALSoundImpl.buffers private static int[] buffers; - private static Map looptable = new Hashtable(MAX_CHANNELS); + private static Map looptable = new Hashtable (MAX_CHANNELS); private static int numChannels; @@ -101,9 +101,12 @@ public class Channel { modified = false; } - private static int[] tmp = new int[1]; + private static int[] tmp; static int init(AL al, int[] buffers) { + if(tmp==null) + tmp = new int[1]; + Channel.al = al; Channel.buffers = buffers; // create channels @@ -115,9 +118,14 @@ public class Channel { al.alGenSources(1, tmp, 0); sourceId = tmp[0]; // can't generate more sources - if (sourceId <= 0) break; + if (sourceId <= 0) { + Com.Println("can't generate more sources: channel="+ + i +" sourceId<=0"); + break; + } } catch (ALException e) { // can't generate more sources + Com.Println("can't generate more sources: "+e); break; } @@ -181,6 +189,8 @@ public class Channel { } static void unqueueStreams() { + if(tmp==null) + tmp = new int[1]; if (!streamingEnabled) return; int source = channels[numChannels].sourceId; @@ -197,6 +207,8 @@ public class Channel { } static void updateStream(ByteBuffer samples, int count, int format, int rate) { + if(tmp==null) + tmp = new int[1]; enableStreaming(); int[] buffer = tmp; int source = channels[numChannels].sourceId; @@ -378,7 +390,7 @@ public class Channel { sfxcache_t sc; int num; entity_state_t ent; - Object key; + Integer key; int sound = 0; for (int i=0 ; i iter = looptable.values().iterator(); iter.hasNext();) { + ch = iter.next(); if (!ch.autosound) { al.alSourceStop(ch.sourceId); al.alSourcei(ch.sourceId, AL.AL_LOOPING, AL.AL_FALSE); diff --git a/src/jake2/sound/joal/JOALSoundImpl.java b/src/jake2/sound/joal/JOALSoundImpl.java index e70b348..8677267 100644 --- a/src/jake2/sound/joal/JOALSoundImpl.java +++ b/src/jake2/sound/joal/JOALSoundImpl.java @@ -31,17 +31,15 @@ public final class JOALSoundImpl implements Sound { static AL al; static ALC alc; + static ALCdevice alcDevice; + static ALCcontext alcContext; static EAX eax; cvar_t s_volume; private int[] buffers = new int[MAX_SFX + STREAM_QUEUE]; - private boolean initialized; - private JOALSoundImpl() { - // singleton - this.initialized = false; } /* (non-Javadoc) @@ -50,13 +48,11 @@ public final class JOALSoundImpl implements Sound { public boolean Init() { try { - // TODO this a linux hack - if (!initialized) { - ALut.alutInit(); - initialized = true; - } - al = ALFactory.getAL(); alc = ALFactory.getALC(); + alcDevice = alc.alcOpenDevice(null); + alcContext = alc.alcCreateContext(alcDevice, null); + alc.alcMakeContextCurrent(alcContext); + al = ALFactory.getAL(); checkError(); initOpenALExtensions(); } catch (ALException e) { @@ -160,8 +156,6 @@ public final class JOALSoundImpl implements Sound { StopAllSounds(); Channel.shutdown(); al.alDeleteBuffers(buffers.length, buffers, 0); - // TODO this is a linux hack - // ALut.alutExit(); Cmd.RemoveCommand("play"); Cmd.RemoveCommand("stopsound"); @@ -175,6 +169,8 @@ public final class JOALSoundImpl implements Sound { known_sfx[i].clear(); } num_sfx = 0; + alc.alcDestroyContext(alcContext); + alc.alcCloseDevice(alcDevice); } /* (non-Javadoc) -- cgit v1.2.3