diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/jake2/sound/joal/JOALSoundImpl.java | 125 |
1 files changed, 74 insertions, 51 deletions
diff --git a/src/jake2/sound/joal/JOALSoundImpl.java b/src/jake2/sound/joal/JOALSoundImpl.java index 0e4aae2..5ba250f 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.19 2006-11-29 12:55:09 cawe Exp $ + * $Id: JOALSoundImpl.java,v 1.20 2006-11-29 15:28:52 cawe Exp $ */ package jake2.sound.joal; @@ -32,6 +32,7 @@ public final class JOALSoundImpl implements Sound { static AL al; static ALC alc; + static ALCcontext currentContext; static EAX eax; cvar_t s_volume; @@ -46,55 +47,55 @@ public final class JOALSoundImpl implements Sound { * @see jake2.sound.SoundImpl#Init() */ 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; + + try { + initOpenAL(); + 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; + } + // set the master volume + 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"); + al.alDistanceModel(AL.AL_INVERSE_DISTANCE_CLAMPED); + Cmd.AddCommand("play", new xcommand_t() { + public void execute() { + Play(); } - // set the master volume - 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"); - al.alDistanceModel(AL.AL_INVERSE_DISTANCE_CLAMPED); - Cmd.AddCommand("play", new xcommand_t() { - public void execute() { - Play(); - } - }); - Cmd.AddCommand("stopsound", new xcommand_t() { - public void execute() { - StopAllSounds(); - } - }); - Cmd.AddCommand("soundlist", new xcommand_t() { - public void execute() { - SoundList(); - } - }); - Cmd.AddCommand("soundinfo", new xcommand_t() { - public void execute() { - SoundInfo_f(); - } - }); + }); + Cmd.AddCommand("stopsound", new xcommand_t() { + public void execute() { + StopAllSounds(); + } + }); + Cmd.AddCommand("soundlist", new xcommand_t() { + public void execute() { + SoundList(); + } + }); + Cmd.AddCommand("soundinfo", new xcommand_t() { + public void execute() { + SoundInfo_f(); + } + }); - num_sfx = 0; + num_sfx = 0; - Com.Printf("sound sampling rate: 44100Hz\n"); + Com.Printf("sound sampling rate: 44100Hz\n"); - StopAllSounds(); - Com.Printf("------------------------------------\n"); - return true; + StopAllSounds(); + Com.Printf("------------------------------------\n"); + return true; } private void initOpenALExtensions() { @@ -112,16 +113,38 @@ public final class JOALSoundImpl implements Sound { } } + void initOpenAL() throws ALException { + alc = ALFactory.getALC(); + String deviceName = null; + ALCcontext context; + ALCdevice device; + device = alc.alcOpenDevice(deviceName); + if (device == null) { + throw new ALException("Error opening default OpenAL device"); + } + context = alc.alcCreateContext(device, null); + if (context == null) { + throw new ALException("Error creating OpenAL context"); + } + alc.alcMakeContextCurrent(context); + if (alc.alcGetError(device) != 0) { + throw new ALException("Error making OpenAL context current"); + } + currentContext = context; + } + void exitOpenAL() { + alc.alcMakeContextCurrent(null); // Get the current context. - ALCcontext curContext = alc.alcGetCurrentContext(); + //ALCcontext curContext = alc.alcGetCurrentContext(); // Get the device used by that context. - ALCdevice curDevice = alc.alcGetContextsDevice(curContext); + ALCdevice curDevice = alc.alcGetContextsDevice(currentContext); // Reset the current context to NULL. - alc.alcMakeContextCurrent(null); // Release the context and the device. - alc.alcDestroyContext(curContext); - alc.alcCloseDevice(curDevice); + alc.alcDestroyContext(currentContext); + if (!alc.alcCloseDevice(curDevice)) { + System.err.println("DEBUG: Can't close AL device"); + } } // TODO check the sfx direct buffer size |