From: Carsten W. <ca...@us...> - 2006-11-29 15:28:55
|
Update of /cvsroot/jake2/jake2/src/jake2/sound/joal In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv10242/src/jake2/sound/joal Modified Files: JOALSoundImpl.java Log Message: try to solve the sound on/off/on bug on linux Index: JOALSoundImpl.java =================================================================== RCS file: /cvsroot/jake2/jake2/src/jake2/sound/joal/JOALSoundImpl.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** JOALSoundImpl.java 29 Nov 2006 12:55:09 -0000 1.19 --- JOALSoundImpl.java 29 Nov 2006 15:28:52 -0000 1.20 *************** *** 33,36 **** --- 33,37 ---- static AL al; static ALC alc; + static ALCcontext currentContext; static EAX eax; *************** *** 47,99 **** */ 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; - } - // 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(); ! } ! }); ! num_sfx = 0; ! Com.Printf("sound sampling rate: 44100Hz\n"); ! StopAllSounds(); ! Com.Printf("------------------------------------\n"); ! return true; } --- 48,100 ---- */ public boolean Init() { ! 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(); ! } ! }); ! 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; ! Com.Printf("sound sampling rate: 44100Hz\n"); ! ! StopAllSounds(); ! Com.Printf("------------------------------------\n"); ! return true; } *************** *** 113,126 **** } 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); // Release the context and the device. ! alc.alcDestroyContext(curContext); ! alc.alcCloseDevice(curDevice); } --- 114,149 ---- } + 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(); // Get the device used by that context. ! ALCdevice curDevice = alc.alcGetContextsDevice(currentContext); // Reset the current context to NULL. // Release the context and the device. ! alc.alcDestroyContext(currentContext); ! if (!alc.alcCloseDevice(curDevice)) { ! System.err.println("DEBUG: Can't close AL device"); ! } } |