JOAL audio renderer to use the unified OpenAL backend as well

experimental
shadowislord 10 years ago
parent a177ffa208
commit 5f33bdfa95
  1. 49
      jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java
  2. 138
      jme3-jogl/src/main/java/com/jme3/audio/joal/JoalAL.java
  3. 144
      jme3-jogl/src/main/java/com/jme3/audio/joal/JoalALC.java
  4. 1131
      jme3-jogl/src/main/java/com/jme3/audio/joal/JoalAudioRenderer.java
  5. 96
      jme3-jogl/src/main/java/com/jme3/audio/joal/JoalEFX.java

@ -273,39 +273,32 @@ public class JmeDesktopSystem extends JmeSystemDelegate {
return null;
}
private AudioRenderer newAudioRendererLwjgl() {
AL al = newObject("com.jme3.audio.lwjgl.LwjglAL");
ALC alc = newObject("com.jme3.audio.lwjgl.LwjglALC");
EFX efx = newObject("com.jme3.audio.lwjgl.LwjglEFX");
return new ALAudioRenderer(al, alc, efx);
}
@Override
public AudioRenderer newAudioRenderer(AppSettings settings) {
initialize(settings);
Class<? extends AudioRenderer> clazz = null;
try {
if (settings.getAudioRenderer().startsWith("LWJGL")) {
return newAudioRendererLwjgl();
} else if (settings.getAudioRenderer().startsWith("JOAL")) {
clazz = (Class<? extends AudioRenderer>) Class.forName("com.jme3.audio.joal.JoalAudioRenderer");
} else {
throw new UnsupportedOperationException(
"Unrecognizable audio renderer specified: "
+ settings.getAudioRenderer());
}
AudioRenderer ar = clazz.newInstance();
return ar;
} catch (InstantiationException ex) {
logger.log(Level.SEVERE, "Failed to create context", ex);
} catch (IllegalAccessException ex) {
logger.log(Level.SEVERE, "Failed to create context", ex);
} catch (ClassNotFoundException ex) {
logger.log(Level.SEVERE, "CRITICAL ERROR: Audio implementation class is missing!\n"
+ "Make sure jme3_lwjgl-oal or jm3_joal is on the classpath.", ex);
AL al;
ALC alc;
EFX efx;
if (settings.getAudioRenderer().startsWith("LWJGL")) {
al = newObject("com.jme3.audio.lwjgl.LwjglAL");
alc = newObject("com.jme3.audio.lwjgl.LwjglALC");
efx = newObject("com.jme3.audio.lwjgl.LwjglEFX");
} else if (settings.getAudioRenderer().startsWith("JOAL")) {
al = newObject("com.jme3.audio.joal.JoalAL");
alc = newObject("com.jme3.audio.joal.JoalALC");
efx = newObject("com.jme3.audio.joal.JoalEFX");
} else {
throw new UnsupportedOperationException(
"Unrecognizable audio renderer specified: "
+ settings.getAudioRenderer());
}
return null;
if (al == null || alc == null || efx == null) {
return null;
}
return new ALAudioRenderer(al, alc, efx);
}
@Override

@ -0,0 +1,138 @@
/*
* Copyright (c) 2009-2014 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jme3.audio.joal;
import com.jme3.util.BufferUtils;
import com.jogamp.openal.AL;
import com.jogamp.openal.ALFactory;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
/**
* Exposes OpenAL functions via JOAL.
*
* @author Kirill Vainer
*/
public final class JoalAL implements com.jme3.audio.openal.AL {
private final AL joalAl;
public JoalAL() {
this.joalAl = ALFactory.getAL();
}
public String alGetString(int parameter) {
return joalAl.alGetString(parameter);
}
public int alGenSources() {
IntBuffer ib = BufferUtils.createIntBuffer(1);
joalAl.alGenSources(1, ib);
return ib.get(0);
}
public int alGetError() {
return joalAl.alGetError();
}
public void alDeleteSources(int numSources, IntBuffer sources) {
joalAl.alDeleteSources(numSources, sources);
}
public void alGenBuffers(int numBuffers, IntBuffer buffers) {
joalAl.alGenBuffers(numBuffers, buffers);
}
public void alDeleteBuffers(int numBuffers, IntBuffer buffers) {
joalAl.alDeleteBuffers(numBuffers, buffers);
}
public void alSourceStop(int source) {
joalAl.alSourceStop(source);
}
public void alSourcei(int source, int param, int value) {
joalAl.alSourcei(source, param, value);
}
public void alBufferData(int buffer, int format, ByteBuffer data, int size, int frequency) {
joalAl.alBufferData(buffer, format, data, size, frequency);
}
public void alSourcePlay(int source) {
joalAl.alSourcePlay(source);
}
public void alSourcePause(int source) {
joalAl.alSourcePause(source);
}
public void alSourcef(int source, int param, float value) {
joalAl.alSourcef(source, param, value);
}
public void alSource3f(int source, int param, float value1, float value2, float value3) {
joalAl.alSource3f(source, param, value1, value2, value3);
}
public int alGetSourcei(int source, int param) {
IntBuffer ib = BufferUtils.createIntBuffer(1);
joalAl.alGetSourcei(source, param, ib);
return ib.get(0);
}
public void alSourceUnqueueBuffers(int source, int numBuffers, IntBuffer buffers) {
joalAl.alSourceUnqueueBuffers(source, numBuffers, buffers);
}
public void alSourceQueueBuffers(int source, int numBuffers, IntBuffer buffers) {
joalAl.alSourceQueueBuffers(source, numBuffers, buffers);
}
public void alListener(int param, FloatBuffer data) {
joalAl.alListenerfv(param, data);
}
public void alListenerf(int param, float value) {
joalAl.alListenerf(param, value);
}
public void alListener3f(int param, float value1, float value2, float value3) {
joalAl.alListener3f(param, value1, value2, value3);
}
public void alSource3i(int source, int param, int value1, int value2, int value3) {
joalAl.alSource3i(source, param, value1, value2, value3);
}
}

@ -0,0 +1,144 @@
/*
* Copyright (c) 2009-2014 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jme3.audio.joal;
import com.jogamp.openal.ALCcontext;
import com.jogamp.openal.ALCdevice;
import com.jogamp.openal.ALFactory;
import com.jogamp.openal.util.ALut;
import java.nio.IntBuffer;
/**
* Exposes ALC functions via JOAL.
*
* @author Kirill Vainer
*/
public final class JoalALC implements com.jme3.audio.openal.ALC {
private final com.jogamp.openal.ALC joalAlc;
public JoalALC() {
joalAlc = ALFactory.getALC();
}
private ALCdevice getALCDevice() {
ALCcontext ctx = joalAlc.alcGetCurrentContext();
if (ctx == null) {
return null;
}
ALCdevice device = joalAlc.alcGetContextsDevice(ctx);
if (device == null) {
return null;
}
return device;
}
public void createALC() {
ALut.alutInit();
/*
// Get handle to default device.
ALCdevice device = joalAlc.alcOpenDevice(null);
if (device == null) {
throw new ALException("Error opening default OpenAL device");
}
// Create audio context.
ALCcontext context = joalAlc.alcCreateContext(device, null);
if (context == null) {
throw new ALException("Error creating OpenAL context");
}
// Set active context.
if (!joalAlc.alcMakeContextCurrent(context)) {
throw new ALException("Failed to make OpenAL context current");
}
// Check for an error.
if (joalAlc.alcGetError(device) != com.jogamp.openal.ALC.ALC_NO_ERROR) {
throw new ALException("Error making OpenAL context current");
}
*/
}
public void destroyALC() {
/*
ALCcontext ctx = joalAlc.alcGetCurrentContext();
if (ctx == null) {
return;
}
ALCdevice device = joalAlc.alcGetContextsDevice(ctx);
if (device == null) {
return;
}
if (!joalAlc.alcMakeContextCurrent(null)) {
return;
}
joalAlc.alcDestroyContext(ctx);
joalAlc.alcCloseDevice(device);
*/
ALut.alutExit();
}
public boolean isCreated() {
return getALCDevice() != null;
}
public String alcGetString(int parameter) {
return joalAlc.alcGetString(getALCDevice(), parameter);
}
public boolean alcIsExtensionPresent(String extension) {
return joalAlc.alcIsExtensionPresent(getALCDevice(), extension);
}
public void alcGetInteger(int param, IntBuffer buffer, int size) {
joalAlc.alcGetIntegerv(getALCDevice(), param, size, buffer);
}
public void alcDevicePauseSOFT() {
}
public void alcDeviceResumeSOFT() {
}
}

@ -0,0 +1,96 @@
/*
* Copyright (c) 2009-2014 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jme3.audio.joal;
import com.jme3.audio.openal.EFX;
import com.jogamp.openal.ALExt;
import com.jogamp.openal.ALFactory;
import java.nio.IntBuffer;
/**
* Exposes EFX extension for JOAL.
*
* @author Kirill Vainer
*/
public final class JoalEFX implements EFX {
private final ALExt joalAlext;
public JoalEFX() {
joalAlext = ALFactory.getALExt();
}
public void alGenAuxiliaryEffectSlots(int numSlots, IntBuffer buffers) {
joalAlext.alGenAuxiliaryEffectSlots(numSlots, buffers);
}
public void alGenEffects(int numEffects, IntBuffer buffers) {
joalAlext.alGenEffects(numEffects, buffers);
}
public void alEffecti(int effect, int param, int value) {
joalAlext.alEffecti(effect, param, value);
}
public void alAuxiliaryEffectSloti(int effectSlot, int param, int value) {
joalAlext.alAuxiliaryEffectSloti(effectSlot, param, value);
}
public void alDeleteEffects(int numEffects, IntBuffer buffers) {
joalAlext.alDeleteEffects(numEffects, buffers);
}
public void alDeleteAuxiliaryEffectSlots(int numEffectSlots, IntBuffer buffers) {
joalAlext.alDeleteAuxiliaryEffectSlots(numEffectSlots, buffers);
}
public void alGenFilters(int numFilters, IntBuffer buffers) {
joalAlext.alGenFilters(numFilters, buffers);
}
public void alFilteri(int filter, int param, int value) {
joalAlext.alFilteri(filter, param, value);
}
public void alFilterf(int filter, int param, float value) {
joalAlext.alFilterf(filter, param, value);
}
public void alDeleteFilters(int numFilters, IntBuffer buffers) {
joalAlext.alDeleteFilters(numFilters, buffers);
}
public void alEffectf(int effect, int param, float value) {
joalAlext.alEffectf(effect, param, value);
}
}
Loading…
Cancel
Save