diff options
author | Xerxes Rånby <[email protected]> | 2012-12-06 09:49:21 +0100 |
---|---|---|
committer | Xerxes Rånby <[email protected]> | 2012-12-06 09:49:21 +0100 |
commit | d75b7a11ba5e32dcbcfd824b702e23a380adefc7 (patch) | |
tree | 3c2a953146025097c69853f42899627e7c717a5a | |
parent | 6909aba0c45cb2c79a09587c25e417d8c233203a (diff) |
Fix static initialization of JOAL.
Signed-off-by: Xerxes Rånby <[email protected]>
-rw-r--r-- | src/jake2/sound/joal/Channel.java | 26 | ||||
-rw-r--r-- | 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 <Integer, Channel> looptable = new Hashtable <Integer, Channel> (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<Globals.cl.frame.num_entities ; i++) { @@ -389,7 +401,7 @@ public class Channel { if (sound == 0) continue; key = new Integer(ent.number); - ch = (Channel)looptable.get(key); + ch = looptable.get(key); if (ch != null) { // keep on looping @@ -426,8 +438,8 @@ public class Channel { private static void removeUnusedLoopSounds() { Channel ch; // stop unused loopsounds - for (Iterator iter = looptable.values().iterator(); iter.hasNext();) { - ch = (Channel)iter.next(); + for (Iterator <Channel> 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) |