diff options
author | Carsten Weisse <[email protected]> | 2006-11-29 15:28:52 +0000 |
---|---|---|
committer | Carsten Weisse <[email protected]> | 2006-11-29 15:28:52 +0000 |
commit | ea5f55c4b1de3178eceb839bd1a19f0c1823ad20 (patch) | |
tree | ad21ac71bebb9f8884f4074f006a060fb3bc59b9 | |
parent | f28e1b6018e8ebb46fbe2777af6a550df0e8cad3 (diff) |
try to solve the sound on/off/on bug on linux
-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 |