diff --git a/engine/src/android/com/jme3/audio/android/AL.java b/engine/src/android/com/jme3/audio/android/AL.java new file mode 100644 index 000000000..ccbc6f901 --- /dev/null +++ b/engine/src/android/com/jme3/audio/android/AL.java @@ -0,0 +1,384 @@ +package com.jme3.audio.android; + +/** + * + * @author iwgeric + */ +public class AL { + + + + /* ********** */ + /* FROM ALC.h */ + /* ********** */ + +// typedef struct ALCdevice_struct ALCdevice; +// typedef struct ALCcontext_struct ALCcontext; + + + /** + * No error + */ + static final int ALC_NO_ERROR = 0; + + /** + * No device + */ + static final int ALC_INVALID_DEVICE = 0xA001; + + /** + * invalid context ID + */ + static final int ALC_INVALID_CONTEXT = 0xA002; + + /** + * bad enum + */ + static final int ALC_INVALID_ENUM = 0xA003; + + /** + * bad value + */ + static final int ALC_INVALID_VALUE = 0xA004; + + /** + * Out of memory. + */ + static final int ALC_OUT_OF_MEMORY = 0xA005; + + + /** + * The Specifier string for default device + */ + static final int ALC_DEFAULT_DEVICE_SPECIFIER = 0x1004; + static final int ALC_DEVICE_SPECIFIER = 0x1005; + static final int ALC_EXTENSIONS = 0x1006; + + static final int ALC_MAJOR_VERSION = 0x1000; + static final int ALC_MINOR_VERSION = 0x1001; + + static final int ALC_ATTRIBUTES_SIZE = 0x1002; + static final int ALC_ALL_ATTRIBUTES = 0x1003; + + + /** + * Capture extension + */ + static final int ALC_EXT_CAPTURE = 1; + static final int ALC_CAPTURE_DEVICE_SPECIFIER = 0x310; + static final int ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER = 0x311; + static final int ALC_CAPTURE_SAMPLES = 0x312; + + + /** + * ALC_ENUMERATE_ALL_EXT enums + */ + static final int ALC_ENUMERATE_ALL_EXT = 1; + static final int ALC_DEFAULT_ALL_DEVICES_SPECIFIER = 0x1012; + static final int ALC_ALL_DEVICES_SPECIFIER = 0x1013; + + + /* ********** */ + /* FROM AL.h */ + /* ********** */ + +/** Boolean False. */ + static final int AL_FALSE = 0; + +/** Boolean True. */ + static final int AL_TRUE = 1; + +/* "no distance model" or "no buffer" */ + static final int AL_NONE = 0; + +/** Indicate Source has relative coordinates. */ + static final int AL_SOURCE_RELATIVE = 0x202; + + + +/** + * Directional source, inner cone angle, in degrees. + * Range: [0-360] + * Default: 360 + */ + static final int AL_CONE_INNER_ANGLE = 0x1001; + +/** + * Directional source, outer cone angle, in degrees. + * Range: [0-360] + * Default: 360 + */ + static final int AL_CONE_OUTER_ANGLE = 0x1002; + +/** + * Specify the pitch to be applied at source. + * Range: [0.5-2.0] + * Default: 1.0 + */ + static final int AL_PITCH = 0x1003; + +/** + * Specify the current location in three dimensional space. + * OpenAL, like OpenGL, uses a right handed coordinate system, + * where in a frontal default view X (thumb) points right, + * Y points up (index finger), and Z points towards the + * viewer/camera (middle finger). + * To switch from a left handed coordinate system, flip the + * sign on the Z coordinate. + * Listener position is always in the world coordinate system. + */ + static final int AL_POSITION = 0x1004; + +/** Specify the current direction. */ + static final int AL_DIRECTION = 0x1005; + +/** Specify the current velocity in three dimensional space. */ + static final int AL_VELOCITY = 0x1006; + +/** + * Indicate whether source is looping. + * Type: ALboolean? + * Range: [AL_TRUE, AL_FALSE] + * Default: FALSE. + */ + static final int AL_LOOPING = 0x1007; + +/** + * Indicate the buffer to provide sound samples. + * Type: ALuint. + * Range: any valid Buffer id. + */ + static final int AL_BUFFER = 0x1009; + +/** + * Indicate the gain (volume amplification) applied. + * Type: ALfloat. + * Range: ]0.0- ] + * A value of 1.0 means un-attenuated/unchanged. + * Each division by 2 equals an attenuation of -6dB. + * Each multiplicaton with 2 equals an amplification of +6dB. + * A value of 0.0 is meaningless with respect to a logarithmic + * scale; it is interpreted as zero volume - the channel + * is effectively disabled. + */ + static final int AL_GAIN = 0x100A; + +/* + * Indicate minimum source attenuation + * Type: ALfloat + * Range: [0.0 - 1.0] + * + * Logarthmic + */ + static final int AL_MIN_GAIN = 0x100D; + +/** + * Indicate maximum source attenuation + * Type: ALfloat + * Range: [0.0 - 1.0] + * + * Logarthmic + */ + static final int AL_MAX_GAIN = 0x100E; + +/** + * Indicate listener orientation. + * + * at/up + */ + static final int AL_ORIENTATION = 0x100F; + +/** + * Source state information. + */ + static final int AL_SOURCE_STATE = 0x1010; + static final int AL_INITIAL = 0x1011; + static final int AL_PLAYING = 0x1012; + static final int AL_PAUSED = 0x1013; + static final int AL_STOPPED = 0x1014; + +/** + * Buffer Queue params + */ + static final int AL_BUFFERS_QUEUED = 0x1015; + static final int AL_BUFFERS_PROCESSED = 0x1016; + +/** + * Source buffer position information + */ + static final int AL_SEC_OFFSET = 0x1024; + static final int AL_SAMPLE_OFFSET = 0x1025; + static final int AL_BYTE_OFFSET = 0x1026; + +/* + * Source type (Static, Streaming or undetermined) + * Source is Static if a Buffer has been attached using AL_BUFFER + * Source is Streaming if one or more Buffers have been attached using alSourceQueueBuffers + * Source is undetermined when it has the NULL buffer attached + */ + static final int AL_SOURCE_TYPE = 0x1027; + static final int AL_STATIC = 0x1028; + static final int AL_STREAMING = 0x1029; + static final int AL_UNDETERMINED = 0x1030; + +/** Sound samples: format specifier. */ + static final int AL_FORMAT_MONO8 = 0x1100; + static final int AL_FORMAT_MONO16 = 0x1101; + static final int AL_FORMAT_STEREO8 = 0x1102; + static final int AL_FORMAT_STEREO16 = 0x1103; + +/** + * source specific reference distance + * Type: ALfloat + * Range: 0.0 - +inf + * + * At 0.0, no distance attenuation occurs. Default is + * 1.0. + */ + static final int AL_REFERENCE_DISTANCE = 0x1020; + +/** + * source specific rolloff factor + * Type: ALfloat + * Range: 0.0 - +inf + * + */ + static final int AL_ROLLOFF_FACTOR = 0x1021; + +/** + * Directional source, outer cone gain. + * + * Default: 0.0 + * Range: [0.0 - 1.0] + * Logarithmic + */ + static final int AL_CONE_OUTER_GAIN = 0x1022; + +/** + * Indicate distance above which sources are not + * attenuated using the inverse clamped distance model. + * + * Default: +inf + * Type: ALfloat + * Range: 0.0 - +inf + */ + static final int AL_MAX_DISTANCE = 0x1023; + +/** + * Sound samples: frequency, in units of Hertz [Hz]. + * This is the number of samples per second. Half of the + * sample frequency marks the maximum significant + * frequency component. + */ + static final int AL_FREQUENCY = 0x2001; + static final int AL_BITS = 0x2002; + static final int AL_CHANNELS = 0x2003; + static final int AL_SIZE = 0x2004; + +/** + * Buffer state. + * + * Not supported for public use (yet). + */ + static final int AL_UNUSED = 0x2010; + static final int AL_PENDING = 0x2011; + static final int AL_PROCESSED = 0x2012; + + +/** Errors: No Error. */ + static final int AL_NO_ERROR = 0; + +/** + * Invalid Name paramater passed to AL call. + */ + static final int AL_INVALID_NAME = 0xA001; + +/** + * Invalid parameter passed to AL call. + */ + static final int AL_INVALID_ENUM = 0xA002; + +/** + * Invalid enum parameter value. + */ + static final int AL_INVALID_VALUE = 0xA003; + +/** + * Illegal call. + */ + static final int AL_INVALID_OPERATION = 0xA004; + + +/** + * No mojo. + */ + static final int AL_OUT_OF_MEMORY = 0xA005; + + +/** Context strings: Vendor Name. */ + static final int AL_VENDOR = 0xB001; + static final int AL_VERSION = 0xB002; + static final int AL_RENDERER = 0xB003; + static final int AL_EXTENSIONS = 0xB004; + +/** Global tweakage. */ + +/** + * Doppler scale. Default 1.0 + */ + static final int AL_DOPPLER_FACTOR = 0xC000; + +/** + * Tweaks speed of propagation. + */ + static final int AL_DOPPLER_VELOCITY = 0xC001; + +/** + * Speed of Sound in units per second + */ + static final int AL_SPEED_OF_SOUND = 0xC003; + +/** + * Distance models + * + * used in conjunction with DistanceModel + * + * implicit: NONE, which disances distance attenuation. + */ + static final int AL_DISTANCE_MODEL = 0xD000; + static final int AL_INVERSE_DISTANCE = 0xD001; + static final int AL_INVERSE_DISTANCE_CLAMPED = 0xD002; + static final int AL_LINEAR_DISTANCE = 0xD003; + static final int AL_LINEAR_DISTANCE_CLAMPED = 0xD004; + static final int AL_EXPONENT_DISTANCE = 0xD005; + static final int AL_EXPONENT_DISTANCE_CLAMPED = 0xD006; + + + public static String GetALErrorMsg(int errorCode) { + String errorText; + switch (errorCode) { + case AL_NO_ERROR: + errorText = "No Error"; + break; + case AL_INVALID_NAME: + errorText = "Invalid Name"; + break; + case AL_INVALID_ENUM: + errorText = "Invalid Enum"; + break; + case AL_INVALID_VALUE: + errorText = "Invalid Value"; + break; + case AL_INVALID_OPERATION: + errorText = "Invalid Operation"; + break; + case AL_OUT_OF_MEMORY: + errorText = "Out of Memory"; + break; + default: + errorText = "Unknown Error Code: " + String.valueOf(errorCode); + } + return errorText; + } +} + diff --git a/engine/src/android/com/jme3/audio/android/AndroidOpenALSoftAudioRenderer.java b/engine/src/android/com/jme3/audio/android/AndroidOpenALSoftAudioRenderer.java new file mode 100644 index 000000000..3fc4089a2 --- /dev/null +++ b/engine/src/android/com/jme3/audio/android/AndroidOpenALSoftAudioRenderer.java @@ -0,0 +1,1367 @@ +/* + * Copyright (c) 2009-2012 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.android; + +import com.jme3.audio.*; +import com.jme3.audio.AudioSource.Status; +import com.jme3.math.Vector3f; +import com.jme3.util.BufferUtils; +import com.jme3.util.NativeObjectManager; +import java.nio.ByteBuffer; +import java.nio.FloatBuffer; +import java.nio.IntBuffer; +import java.util.ArrayList; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class AndroidOpenALSoftAudioRenderer implements AudioRenderer, Runnable { + + private static final Logger logger = Logger.getLogger(AndroidOpenALSoftAudioRenderer.class.getName()); + private final NativeObjectManager objManager = new NativeObjectManager(); + // When multiplied by STREAMING_BUFFER_COUNT, will equal 44100 * 2 * 2 + // which is exactly 1 second of audio. + private static final int BUFFER_SIZE = 35280; + private static final int STREAMING_BUFFER_COUNT = 5; + private final static int MAX_NUM_CHANNELS = 64; + private IntBuffer ib = BufferUtils.createIntBuffer(1); + private final FloatBuffer fb = BufferUtils.createVector3Buffer(2); + private final ByteBuffer nativeBuf = BufferUtils.createByteBuffer(BUFFER_SIZE); + private final byte[] arrayBuf = new byte[BUFFER_SIZE]; + private int[] channels; + private AudioSource[] chanSrcs; + private int nextChan = 0; + private ArrayList freeChans = new ArrayList(); + private Listener listener; + private boolean audioDisabled = false; + private boolean supportEfx = false; + private int auxSends = 0; + private int reverbFx = -1; + private int reverbFxSlot = -1; + // Update audio 20 times per second + private static final float UPDATE_RATE = 0.05f; + private final Thread audioThread = new Thread(this, "jME3 Audio Thread"); + private final AtomicBoolean threadLock = new AtomicBoolean(false); + + public AndroidOpenALSoftAudioRenderer() { + } + + public void initialize() { + if (!audioThread.isAlive()) { + audioThread.setDaemon(true); + audioThread.setPriority(Thread.NORM_PRIORITY + 1); + audioThread.start(); + } else { + throw new IllegalStateException("Initialize already called"); + } + } + + private void checkDead() { + if (audioThread.getState() == Thread.State.TERMINATED) { + throw new IllegalStateException("Audio thread is terminated"); + } + } + + public void run() { + initInThread(); + synchronized (threadLock) { + threadLock.set(true); + threadLock.notifyAll(); + } + + long updateRateNanos = (long) (UPDATE_RATE * 1000000000); + mainloop: + while (true) { + long startTime = System.nanoTime(); + + if (Thread.interrupted()) { + break; + } + + synchronized (threadLock) { + updateInThread(UPDATE_RATE); + } + + long endTime = System.nanoTime(); + long diffTime = endTime - startTime; + + if (diffTime < updateRateNanos) { + long desiredEndTime = startTime + updateRateNanos; + while (System.nanoTime() < desiredEndTime) { + try { + Thread.sleep(1); + } catch (InterruptedException ex) { + break mainloop; + } + } + } + } + + logger.log(Level.INFO, "Exiting audioThread run loop"); + synchronized (threadLock) { + cleanupInThread(); + } + } + + public void initInThread() { + try { + if (!alIsCreated()) { + //AL.create(); + logger.log(Level.INFO, "Creating OpenAL Soft Renderer"); + alCreate(); + checkError(false); + } +// } catch (OpenALException ex) { +// logger.log(Level.SEVERE, "Failed to load audio library", ex); +// audioDisabled = true; +// return; +// } catch (LWJGLException ex) { +// logger.log(Level.SEVERE, "Failed to load audio library", ex); +// audioDisabled = true; +// return; + } catch (UnsatisfiedLinkError ex) { + logger.log(Level.SEVERE, "Failed to load audio library", ex); + audioDisabled = true; + return; + } + + //ALCdevice device = AL.getDevice(); /* device maintained in jni */ + //String deviceName = ALC10.alcGetString(device, ALC10.ALC_DEVICE_SPECIFIER); + String deviceName = alcGetString(AL.ALC_DEVICE_SPECIFIER); + + logger.log(Level.INFO, "Audio Device: {0}", deviceName); + //logger.log(Level.INFO, "Audio Vendor: {0}", alGetString(AL_VENDOR)); + //logger.log(Level.INFO, "Audio Renderer: {0}", alGetString(AL_RENDERER)); + //logger.log(Level.INFO, "Audio Version: {0}", alGetString(AL_VERSION)); + logger.log(Level.INFO, "Audio Vendor: {0}", alGetString(AL.AL_VENDOR)); + logger.log(Level.INFO, "Audio Renderer: {0}", alGetString(AL.AL_RENDERER)); + logger.log(Level.INFO, "Audio Version: {0}", alGetString(AL.AL_VERSION)); + + // Find maximum # of sources supported by this implementation + ArrayList channelList = new ArrayList(); + for (int i = 0; i < MAX_NUM_CHANNELS; i++) { +// logger.log(Level.INFO, "Generating Source for index: {0}", i); + int chan = alGenSources(); +// logger.log(Level.INFO, "chan: {0}", chan); + //if (alGetError() != 0) { + if (checkError(false) != 0) { +// logger.log(Level.INFO, "alGetError detected an error"); + break; + } else { + channelList.add(chan); + } + } + + channels = new int[channelList.size()]; + for (int i = 0; i < channels.length; i++) { + channels[i] = channelList.get(i); + } + + ib = BufferUtils.createIntBuffer(channels.length); + chanSrcs = new AudioSource[channels.length]; + + logger.log(Level.INFO, "AudioRenderer supports {0} channels", channels.length); + +// supportEfx = ALC10.alcIsExtensionPresent(device, "ALC_EXT_EFX"); +// if (supportEfx) { +// ib.position(0).limit(1); +// ALC10.alcGetInteger(device, EFX10.ALC_EFX_MAJOR_VERSION, ib); +// int major = ib.get(0); +// ib.position(0).limit(1); +// ALC10.alcGetInteger(device, EFX10.ALC_EFX_MINOR_VERSION, ib); +// int minor = ib.get(0); +// logger.log(Level.INFO, "Audio effect extension version: {0}.{1}", new Object[]{major, minor}); +// +// ALC10.alcGetInteger(device, EFX10.ALC_MAX_AUXILIARY_SENDS, ib); +// auxSends = ib.get(0); +// logger.log(Level.INFO, "Audio max auxilary sends: {0}", auxSends); +// +// // create slot +// ib.position(0).limit(1); +// EFX10.alGenAuxiliaryEffectSlots(ib); +// reverbFxSlot = ib.get(0); +// +// // create effect +// ib.position(0).limit(1); +// EFX10.alGenEffects(ib); +// reverbFx = ib.get(0); +// EFX10.alEffecti(reverbFx, EFX10.AL_EFFECT_TYPE, EFX10.AL_EFFECT_REVERB); +// +// // attach reverb effect to effect slot +// EFX10.alAuxiliaryEffectSloti(reverbFxSlot, EFX10.AL_EFFECTSLOT_EFFECT, reverbFx); +// } else { +// logger.log(Level.WARNING, "OpenAL EFX not available! Audio effects won't work."); +// } + } + + public void cleanupInThread() { + logger.log(Level.INFO, "cleanupInThread"); + if (audioDisabled) { + //AL.destroy(); + logger.log(Level.INFO, "Destroying OpenAL Soft Renderer with audioDisabled"); + alDestroy(); + checkError(true); + return; + } + + // stop any playing channels + for (int i = 0; i < chanSrcs.length; i++) { + if (chanSrcs[i] != null) { + clearChannel(i); + } + } + + // delete channel-based sources + ib.clear(); + ib.put(channels); + ib.flip(); + //alDeleteSources(ib); + alDeleteSources(channels.length, ib); + checkError(true); + + // delete audio buffers and filters + objManager.deleteAllObjects(this); + +// if (supportEfx) { +// ib.position(0).limit(1); +// ib.put(0, reverbFx); +// EFX10.alDeleteEffects(ib); +// +// // If this is not allocated, why is it deleted? +// // Commented out to fix native crash in OpenAL. +// ib.position(0).limit(1); +// ib.put(0, reverbFxSlot); +// EFX10.alDeleteAuxiliaryEffectSlots(ib); +// } +// + //AL.destroy(); + logger.log(Level.INFO, "Destroying OpenAL Soft Renderer"); + alDestroy(); +// checkError(true); + } + + public void cleanup() { + logger.log(Level.INFO, "cleanup"); + // kill audio thread + if (audioThread.isAlive()) { + logger.log(Level.INFO, "Interrupting audioThread"); + audioThread.interrupt(); + } + } + + private void updateFilter(Filter f) { +// int id = f.getId(); +// if (id == -1) { +// ib.position(0).limit(1); +// EFX10.alGenFilters(ib); +// id = ib.get(0); +// f.setId(id); +// +// objManager.registerForCleanup(f); +// } +// +// if (f instanceof LowPassFilter) { +// LowPassFilter lpf = (LowPassFilter) f; +// EFX10.alFilteri(id, EFX10.AL_FILTER_TYPE, EFX10.AL_FILTER_LOWPASS); +// EFX10.alFilterf(id, EFX10.AL_LOWPASS_GAIN, lpf.getVolume()); +// EFX10.alFilterf(id, EFX10.AL_LOWPASS_GAINHF, lpf.getHighFreqVolume()); +// } else { +// throw new UnsupportedOperationException("Filter type unsupported: " +// + f.getClass().getName()); +// } +// +// f.clearUpdateNeeded(); + } + + public void updateSourceParam(AudioSource src, AudioParam param) { + checkDead(); + synchronized (threadLock) { + while (!threadLock.get()) { + try { + threadLock.wait(); + } catch (InterruptedException ex) { + } + } + if (audioDisabled) { + return; + } + + // There is a race condition in AudioSource that can + // cause this to be called for a node that has been + // detached from its channel. For example, setVolume() + // called from the render thread may see that that AudioSource + // still has a channel value but the audio thread may + // clear that channel before setVolume() gets to call + // updateSourceParam() (because the audio stopped playing + // on its own right as the volume was set). In this case, + // it should be safe to just ignore the update + if (src.getChannel() < 0) { + return; + } + + assert src.getChannel() >= 0; + + int id = channels[src.getChannel()]; + switch (param) { + case Position: + if (!src.isPositional()) { + return; + } + + Vector3f pos = src.getPosition(); + //alSource3f(id, AL_POSITION, pos.x, pos.y, pos.z); + alSource3f(id, AL.AL_POSITION, pos.x, pos.y, pos.z); + checkError(true); + break; + case Velocity: + if (!src.isPositional()) { + return; + } + + Vector3f vel = src.getVelocity(); + //alSource3f(id, AL_VELOCITY, vel.x, vel.y, vel.z); + alSource3f(id, AL.AL_VELOCITY, vel.x, vel.y, vel.z); + checkError(true); + break; + case MaxDistance: + if (!src.isPositional()) { + return; + } + + //alSourcef(id, AL_MAX_DISTANCE, src.getMaxDistance()); + alSourcef(id, AL.AL_MAX_DISTANCE, src.getMaxDistance()); + checkError(true); + break; + case RefDistance: + if (!src.isPositional()) { + return; + } + + //alSourcef(id, AL_REFERENCE_DISTANCE, src.getRefDistance()); + alSourcef(id, AL.AL_REFERENCE_DISTANCE, src.getRefDistance()); + checkError(true); + break; + case ReverbFilter: + if (!supportEfx || !src.isPositional() || !src.isReverbEnabled()) { + return; + } + +// int filter = EFX10.AL_FILTER_NULL; +// if (src.getReverbFilter() != null) { +// Filter f = src.getReverbFilter(); +// if (f.isUpdateNeeded()) { +// updateFilter(f); +// } +// filter = f.getId(); +// } +// AL11.alSource3i(id, EFX10.AL_AUXILIARY_SEND_FILTER, reverbFxSlot, 0, filter); + break; + case ReverbEnabled: + if (!supportEfx || !src.isPositional()) { + return; + } + + if (src.isReverbEnabled()) { + updateSourceParam(src, AudioParam.ReverbFilter); + } else { +// AL11.alSource3i(id, EFX10.AL_AUXILIARY_SEND_FILTER, 0, 0, EFX10.AL_FILTER_NULL); + } + break; + case IsPositional: + if (!src.isPositional()) { + // Play in headspace + //alSourcei(id, AL_SOURCE_RELATIVE, AL_TRUE); + alSourcei(id, AL.AL_SOURCE_RELATIVE, AL.AL_TRUE); + checkError(true); + //alSource3f(id, AL_POSITION, 0, 0, 0); + alSource3f(id, AL.AL_POSITION, 0, 0, 0); + checkError(true); + //alSource3f(id, AL_VELOCITY, 0, 0, 0); + alSource3f(id, AL.AL_VELOCITY, 0, 0, 0); + checkError(true); + + // Disable reverb +// AL11.alSource3i(id, EFX10.AL_AUXILIARY_SEND_FILTER, 0, 0, EFX10.AL_FILTER_NULL); + } else { + //alSourcei(id, AL_SOURCE_RELATIVE, AL_FALSE); + alSourcei(id, AL.AL_SOURCE_RELATIVE, AL.AL_FALSE); + checkError(true); + updateSourceParam(src, AudioParam.Position); + updateSourceParam(src, AudioParam.Velocity); + updateSourceParam(src, AudioParam.MaxDistance); + updateSourceParam(src, AudioParam.RefDistance); + updateSourceParam(src, AudioParam.ReverbEnabled); + } + break; + case Direction: + if (!src.isDirectional()) { + return; + } + + Vector3f dir = src.getDirection(); + //alSource3f(id, AL_DIRECTION, dir.x, dir.y, dir.z); + alSource3f(id, AL.AL_DIRECTION, dir.x, dir.y, dir.z); + checkError(true); + break; + case InnerAngle: + if (!src.isDirectional()) { + return; + } + + //alSourcef(id, AL_CONE_INNER_ANGLE, src.getInnerAngle()); + alSourcef(id, AL.AL_CONE_INNER_ANGLE, src.getInnerAngle()); + checkError(true); + break; + case OuterAngle: + if (!src.isDirectional()) { + return; + } + + //alSourcef(id, AL_CONE_OUTER_ANGLE, src.getOuterAngle()); + alSourcef(id, AL.AL_CONE_OUTER_ANGLE, src.getOuterAngle()); + checkError(true); + break; + case IsDirectional: + if (src.isDirectional()) { + updateSourceParam(src, AudioParam.Direction); + updateSourceParam(src, AudioParam.InnerAngle); + updateSourceParam(src, AudioParam.OuterAngle); + //alSourcef(id, AL_CONE_OUTER_GAIN, 0); + alSourcef(id, AL.AL_CONE_OUTER_GAIN, 0); + checkError(true); + } else { + //alSourcef(id, AL_CONE_INNER_ANGLE, 360); + alSourcef(id, AL.AL_CONE_INNER_ANGLE, 360); + checkError(true); + //alSourcef(id, AL_CONE_OUTER_ANGLE, 360); + alSourcef(id, AL.AL_CONE_OUTER_ANGLE, 360); + checkError(true); + //alSourcef(id, AL_CONE_OUTER_GAIN, 1f); + alSourcef(id, AL.AL_CONE_OUTER_GAIN, 1f); + checkError(true); + } + break; +// case DryFilter: +// if (!supportEfx) { +// return; +// } +// +// if (src.getDryFilter() != null) { +// Filter f = src.getDryFilter(); +// if (f.isUpdateNeeded()) { +// updateFilter(f); +// +// // NOTE: must re-attach filter for changes to apply. +// alSourcei(id, EFX10.AL_DIRECT_FILTER, f.getId()); +// } +// } else { +// alSourcei(id, EFX10.AL_DIRECT_FILTER, EFX10.AL_FILTER_NULL); +// } +// break; + case Looping: + if (src.isLooping()) { + if (!(src.getAudioData() instanceof AudioStream)) { + //alSourcei(id, AL_LOOPING, AL_TRUE); + alSourcei(id, AL.AL_LOOPING, AL.AL_TRUE); + checkError(true); + } + } else { + //alSourcei(id, AL_LOOPING, AL_FALSE); + alSourcei(id, AL.AL_LOOPING, AL.AL_FALSE); + checkError(true); + } + break; + case Volume: + //alSourcef(id, AL_GAIN, src.getVolume()); + alSourcef(id, AL.AL_GAIN, src.getVolume()); + checkError(true); + break; + case Pitch: + //alSourcef(id, AL_PITCH, src.getPitch()); + alSourcef(id, AL.AL_PITCH, src.getPitch()); + checkError(true); + break; + } + } + } + + private void setSourceParams(int id, AudioSource src, boolean forceNonLoop) { + if (src.isPositional()) { + Vector3f pos = src.getPosition(); + Vector3f vel = src.getVelocity(); + //alSource3f(id, AL_POSITION, pos.x, pos.y, pos.z); + alSource3f(id, AL.AL_POSITION, pos.x, pos.y, pos.z); + checkError(true); + //alSource3f(id, AL_VELOCITY, vel.x, vel.y, vel.z); + alSource3f(id, AL.AL_VELOCITY, vel.x, vel.y, vel.z); + checkError(true); + //alSourcef(id, AL_MAX_DISTANCE, src.getMaxDistance()); + alSourcef(id, AL.AL_MAX_DISTANCE, src.getMaxDistance()); + checkError(true); + //alSourcef(id, AL_REFERENCE_DISTANCE, src.getRefDistance()); + alSourcef(id, AL.AL_REFERENCE_DISTANCE, src.getRefDistance()); + checkError(true); + //alSourcei(id, AL_SOURCE_RELATIVE, AL_FALSE); + alSourcei(id, AL.AL_SOURCE_RELATIVE, AL.AL_FALSE); + checkError(true); + +// if (src.isReverbEnabled() && supportEfx) { +// int filter = EFX10.AL_FILTER_NULL; +// if (src.getReverbFilter() != null) { +// Filter f = src.getReverbFilter(); +// if (f.isUpdateNeeded()) { +// updateFilter(f); +// } +// filter = f.getId(); +// } +// AL11.alSource3i(id, EFX10.AL_AUXILIARY_SEND_FILTER, reverbFxSlot, 0, filter); +// } + } else { + // play in headspace + //alSourcei(id, AL_SOURCE_RELATIVE, AL_TRUE); + alSourcei(id, AL.AL_SOURCE_RELATIVE, AL.AL_TRUE); + checkError(true); + //alSource3f(id, AL_POSITION, 0, 0, 0); + alSource3f(id, AL.AL_POSITION, 0, 0, 0); + checkError(true); + //alSource3f(id, AL_VELOCITY, 0, 0, 0); + alSource3f(id, AL.AL_VELOCITY, 0, 0, 0); + checkError(true); + } + +// if (src.getDryFilter() != null && supportEfx) { +// Filter f = src.getDryFilter(); +// if (f.isUpdateNeeded()) { +// updateFilter(f); +// +// // NOTE: must re-attach filter for changes to apply. +// alSourcei(id, EFX10.AL_DIRECT_FILTER, f.getId()); +// } +// } +// + if (forceNonLoop) { + //alSourcei(id, AL_LOOPING, AL_FALSE); + alSourcei(id, AL.AL_LOOPING, AL.AL_FALSE); + checkError(true); + } else { + //alSourcei(id, AL_LOOPING, src.isLooping() ? AL_TRUE : AL_FALSE); + alSourcei(id, AL.AL_LOOPING, src.isLooping() ? AL.AL_TRUE : AL.AL_FALSE); + checkError(true); + } + //alSourcef(id, AL_GAIN, src.getVolume()); + alSourcef(id, AL.AL_GAIN, src.getVolume()); + checkError(true); + //alSourcef(id, AL_PITCH, src.getPitch()); + alSourcef(id, AL.AL_PITCH, src.getPitch()); + checkError(true); + //alSourcef(id, AL11.AL_SEC_OFFSET, src.getTimeOffset()); + alSourcef(id, AL.AL_SEC_OFFSET, src.getTimeOffset()); + checkError(true); + + if (src.isDirectional()) { + Vector3f dir = src.getDirection(); + //alSource3f(id, AL_DIRECTION, dir.x, dir.y, dir.z); + alSource3f(id, AL.AL_DIRECTION, dir.x, dir.y, dir.z); + checkError(true); + //alSourcef(id, AL_CONE_INNER_ANGLE, src.getInnerAngle()); + alSourcef(id, AL.AL_CONE_INNER_ANGLE, src.getInnerAngle()); + checkError(true); + //alSourcef(id, AL_CONE_OUTER_ANGLE, src.getOuterAngle()); + alSourcef(id, AL.AL_CONE_OUTER_ANGLE, src.getOuterAngle()); + checkError(true); + //alSourcef(id, AL_CONE_OUTER_GAIN, 0); + alSourcef(id, AL.AL_CONE_OUTER_GAIN, 0); + checkError(true); + } else { + //alSourcef(id, AL_CONE_INNER_ANGLE, 360); + alSourcef(id, AL.AL_CONE_INNER_ANGLE, 360); + checkError(true); + //alSourcef(id, AL_CONE_OUTER_ANGLE, 360); + alSourcef(id, AL.AL_CONE_OUTER_ANGLE, 360); + checkError(true); + //alSourcef(id, AL_CONE_OUTER_GAIN, 1f); + alSourcef(id, AL.AL_CONE_OUTER_GAIN, 1f); + checkError(true); + } + } + + public void updateListenerParam(Listener listener, ListenerParam param) { + checkDead(); + synchronized (threadLock) { + while (!threadLock.get()) { + try { + threadLock.wait(); + } catch (InterruptedException ex) { + } + } + if (audioDisabled) { + return; + } + + switch (param) { + case Position: + Vector3f pos = listener.getLocation(); + //alListener3f(AL_POSITION, pos.x, pos.y, pos.z); + alListener3f(AL.AL_POSITION, pos.x, pos.y, pos.z); + checkError(true); + break; + case Rotation: + Vector3f dir = listener.getDirection(); + Vector3f up = listener.getUp(); + fb.rewind(); + fb.put(dir.x).put(dir.y).put(dir.z); + fb.put(up.x).put(up.y).put(up.z); + fb.flip(); + //alListener(AL_ORIENTATION, fb); + alListener(AL.AL_ORIENTATION, fb); + checkError(true); + break; + case Velocity: + Vector3f vel = listener.getVelocity(); + //alListener3f(AL_VELOCITY, vel.x, vel.y, vel.z); + alListener3f(AL.AL_VELOCITY, vel.x, vel.y, vel.z); + checkError(true); + break; + case Volume: + //alListenerf(AL_GAIN, listener.getVolume()); + alListenerf(AL.AL_GAIN, listener.getVolume()); + checkError(true); + break; + } + } + } + + private void setListenerParams(Listener listener) { + Vector3f pos = listener.getLocation(); + Vector3f vel = listener.getVelocity(); + Vector3f dir = listener.getDirection(); + Vector3f up = listener.getUp(); + + //alListener3f(AL_POSITION, pos.x, pos.y, pos.z); + alListener3f(AL.AL_POSITION, pos.x, pos.y, pos.z); + checkError(true); + //alListener3f(AL_VELOCITY, vel.x, vel.y, vel.z); + alListener3f(AL.AL_VELOCITY, vel.x, vel.y, vel.z); + checkError(true); + fb.rewind(); + fb.put(dir.x).put(dir.y).put(dir.z); + fb.put(up.x).put(up.y).put(up.z); + fb.flip(); + //alListener(AL_ORIENTATION, fb); + alListener(AL.AL_ORIENTATION, fb); + checkError(true); + //alListenerf(AL_GAIN, listener.getVolume()); + alListenerf(AL.AL_GAIN, listener.getVolume()); + checkError(true); + } + + private int newChannel() { + if (freeChans.size() > 0) { + return freeChans.remove(0); + } else if (nextChan < channels.length) { + return nextChan++; + } else { + return -1; + } + } + + private void freeChannel(int index) { + if (index == nextChan - 1) { + nextChan--; + } else { + freeChans.add(index); + } + } + + public void setEnvironment(Environment env) { + checkDead(); + synchronized (threadLock) { + while (!threadLock.get()) { + try { + threadLock.wait(); + } catch (InterruptedException ex) { + } + } + if (audioDisabled || !supportEfx) { + return; + } + +// EFX10.alEffectf(reverbFx, EFX10.AL_REVERB_DENSITY, env.getDensity()); +// EFX10.alEffectf(reverbFx, EFX10.AL_REVERB_DIFFUSION, env.getDiffusion()); +// EFX10.alEffectf(reverbFx, EFX10.AL_REVERB_GAIN, env.getGain()); +// EFX10.alEffectf(reverbFx, EFX10.AL_REVERB_GAINHF, env.getGainHf()); +// EFX10.alEffectf(reverbFx, EFX10.AL_REVERB_DECAY_TIME, env.getDecayTime()); +// EFX10.alEffectf(reverbFx, EFX10.AL_REVERB_DECAY_HFRATIO, env.getDecayHFRatio()); +// EFX10.alEffectf(reverbFx, EFX10.AL_REVERB_REFLECTIONS_GAIN, env.getReflectGain()); +// EFX10.alEffectf(reverbFx, EFX10.AL_REVERB_REFLECTIONS_DELAY, env.getReflectDelay()); +// EFX10.alEffectf(reverbFx, EFX10.AL_REVERB_LATE_REVERB_GAIN, env.getLateReverbGain()); +// EFX10.alEffectf(reverbFx, EFX10.AL_REVERB_LATE_REVERB_DELAY, env.getLateReverbDelay()); +// EFX10.alEffectf(reverbFx, EFX10.AL_REVERB_AIR_ABSORPTION_GAINHF, env.getAirAbsorbGainHf()); +// EFX10.alEffectf(reverbFx, EFX10.AL_REVERB_ROOM_ROLLOFF_FACTOR, env.getRoomRolloffFactor()); +// +// // attach effect to slot +// EFX10.alAuxiliaryEffectSloti(reverbFxSlot, EFX10.AL_EFFECTSLOT_EFFECT, reverbFx); + } + } + + private boolean fillBuffer(AudioStream stream, int id) { +// logger.log(Level.INFO, "fillBuffer for id: {0}", id); + int size = 0; + int result; + + while (size < arrayBuf.length) { + result = stream.readSamples(arrayBuf, size, arrayBuf.length - size); + + if (result > 0) { + size += result; + } else { + break; + } + } + +// logger.log(Level.INFO, "data for buffer: {0} is size: {1}", +// new Object[]{id, size}); + + if (size == 0) { + return false; + } + + nativeBuf.clear(); + nativeBuf.put(arrayBuf, 0, size); + nativeBuf.flip(); + + //alBufferData(id, convertFormat(stream), nativeBuf, stream.getSampleRate()); + alBufferData(id, convertFormat(stream), nativeBuf, size, stream.getSampleRate()); + checkError(true); + + return true; + } + + private boolean fillStreamingSource(int sourceId, AudioStream stream) { +// logger.log(Level.INFO, "fillStreamingSource for source: {0}", sourceId); + if (!stream.isOpen()) { + return false; + } + + boolean active = true; + //int processed = alGetSourcei(sourceId, AL_BUFFERS_PROCESSED); + int processed = alGetSourcei(sourceId, AL.AL_BUFFERS_PROCESSED); +// logger.log(Level.INFO, "fillStreamingSource buffers processed: {0}", processed); + checkError(true); + + //while((processed--) != 0){ + if (processed > 0) { + int buffer; + + ib.position(0).limit(1); +// logger.log(Level.INFO, "fillStreamingSource alSourceUnqueueBuffers for source: {0}", sourceId); + //alSourceUnqueueBuffers(sourceId, ib); + alSourceUnqueueBuffers(sourceId, 1, ib); + checkError(true); + buffer = ib.get(0); +// logger.log(Level.INFO, "fillStreamingSource bufferID: {0}", buffer); + + active = fillBuffer(stream, buffer); + + ib.position(0).limit(1); + ib.put(0, buffer); +// logger.log(Level.INFO, "fillStreamingSource alSourceQueueBuffers for source: {0}, buffer: {1}", +// new Object[]{sourceId, buffer}); + //alSourceQueueBuffers(sourceId, ib); + alSourceQueueBuffers(sourceId, 1, ib); + checkError(true); + } + + if (!active && stream.isOpen()) { + stream.close(); + } + + return active; + } + + private boolean attachStreamToSource(int sourceId, AudioStream stream) { +// logger.log(Level.INFO, "attachStreamToSource for source: {0}", sourceId); + boolean active = true; + int activeBufferCount = 0; + for (int id : stream.getIds()) { + active = fillBuffer(stream, id); + ib.position(0).limit(1); + ib.put(id).flip(); + //alSourceQueueBuffers(sourceId, ib); + // OpenAL Soft does not like 0 size buffer data in alSourceQueueBuffers + // Produces error code 40964 (0xA004) = AL_INVALID_OPERATION and + // does not return (crashes) so that the error code can be checked. + // active is FALSE when the data size is 0 + if (active) { +// logger.log(Level.INFO, "attachStreamToSource alSourceQueueBuffers for source: {0}, buffer: {1}", +// new Object[]{sourceId, id}); + alSourceQueueBuffers(sourceId, 1, ib); + checkError(true); + activeBufferCount++; + } + } + // adjust the steam id array if the audio data is smaller than STREAMING_BUFFER_COUNT + // this is to avoid an error with OpenAL Soft when alSourceUnenqueueBuffers + // is called with more buffers than were originally used with alSourceQueueBuffers + if (activeBufferCount < STREAMING_BUFFER_COUNT) { + int[] newIds = new int[activeBufferCount]; + for (int i=0; i +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +static jboolean created = JNI_FALSE; + +#define BUFFER_COUNT 1 +ALuint* buffers[BUFFER_COUNT] = { 0 }; +ALuint* source = 0; + +int getError() { + int errorcode = alGetError(); +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "getError: %d", errorcode); + return errorcode; +} + +/* InitAL opens the default device and sets up a context using default + * attributes, making the program ready to call OpenAL functions. */ +int InitAL() +{ + ALCdevice *device; + ALCcontext *ctx; + + /* Open and initialize a device with default settings */ + device = alcOpenDevice(NULL); + if(!device) + { + fprintf(stderr, "Could not open a device!\n"); + return 1; + } + + ctx = alcCreateContext(device, NULL); +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "NULL: %d", NULL); +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "Created context: %d", ctx); +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "Created context addr: %d", &ctx); + if(ctx == NULL || alcMakeContextCurrent(ctx) == ALC_FALSE) + { + if(ctx != NULL) + alcDestroyContext(ctx); + alcCloseDevice(device); + fprintf(stderr, "Could not set a context!\n"); + return 1; + } + + printf("Opened \"%s\"\n", alcGetString(device, ALC_DEVICE_SPECIFIER)); + __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "Opened %s", alcGetString(device, ALC_DEVICE_SPECIFIER)); + return 0; +} + +/* CloseAL closes the device belonging to the current context, and destroys the + * context. */ +void CloseAL() +{ + ALCdevice *device; + ALCcontext *ctx; + ALCboolean result; + +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "Getting current context"); + ctx = alcGetCurrentContext(); +// getError(); + if(ctx == NULL){ + __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "No context found"); + return; + } + +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "Getting current context device"); + device = alcGetContextsDevice(ctx); + if(device == NULL) { + __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "No device found"); + return; + } else { +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "alcGetContextsDevice device: %d", device); +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "alcGetContextsDevice device addr: %d", &device); + } +// getError(); + +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "Setting context to NULL"); + result = alcMakeContextCurrent(NULL); +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "alcMakeContextCurrent returned"); +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "alcMakeContextCurrent returned with result: %d", result); + if(!result) { + __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "alcMakeContextCurrent failed"); + return; + } + +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "Destroying context: %d", ctx); +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "Destroying context addr: %d", &ctx); + alcDestroyContext(ctx); + +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "Closing device"); + result = alcCloseDevice(device); +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "alcCloseDevice result: %d", result); +} + + +JNIEXPORT jboolean JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alIsCreated + (JNIEnv* env, jclass) +{ + return created; +} + + +JNIEXPORT jboolean JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alCreate + (JNIEnv* env, jclass) +{ + __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "Starting Audio Engine"); + + InitAL(); + created = JNI_TRUE; + return created; + +} + +JNIEXPORT jboolean JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alDestroy + (JNIEnv* env, jclass) +{ + +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "alDestroy"); + CloseAL(); + created = JNI_FALSE; + return created; + +} + +JNIEXPORT jstring JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alcGetString + (JNIEnv* env, jclass, jint param) +{ +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "alcGetString for param: %d", param); + + ALCdevice *device; + ALCcontext *ctx; + + ctx = alcGetCurrentContext(); + if(ctx != NULL) { + device = alcGetContextsDevice(ctx); +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "alcGetString param value: %s", alcGetString(device, param)); + return env->NewStringUTF(alcGetString(device, param)); + } +} + +JNIEXPORT jstring JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alGetString + (JNIEnv* env, jclass, jint param) +{ +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "alGetString for param: %d", param); +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "alGetString param value: %s", alGetString(param)); + return env->NewStringUTF(alGetString(param)); +} + +JNIEXPORT jint JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alGenSources + (JNIEnv *, jclass) +{ + ALuint source; + alGenSources(1, &source); +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "alGenSources: %d", source); + return source; +} + +JNIEXPORT jint JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alGetError + (JNIEnv *, jclass) +{ + return getError(); +} + +JNIEXPORT void JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alDeleteSources + (JNIEnv* env, jclass, jint numSources, jobject intbufSources) +{ +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "alDeleteSources numSources: %d", numSources); + + ALuint* pIntBufSources = (ALuint*) env->GetDirectBufferAddress(intbufSources); + alDeleteSources((ALsizei)numSources, pIntBufSources); +} + +JNIEXPORT void JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alGenBuffers + (JNIEnv* env, jclass, jint numBuffers, jobject intbufBuffers) +{ + ALuint* pIntBufBuffers = (ALuint*) env->GetDirectBufferAddress(intbufBuffers); + alGenBuffers((ALsizei)numBuffers, pIntBufBuffers); +// for (int i=0; iGetDirectBufferAddress(intbufBuffers); +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "alDeleteBuffers Buffers: %d", *pIntBufBuffers); +// for (int i=0; iGetDirectBufferAddress(bufferData); + alBufferData((ALuint)buffer, (ALenum)format, pBufferData, (ALsizei)bufferSize, (ALsizei)frequency); +} + +JNIEXPORT void JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alSourcePlay + (JNIEnv *, jclass, jint source) +{ +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "alSourcePlay for source: %d", source); + alSourcePlay((ALuint)source); +} + +JNIEXPORT void JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alSourcePause + (JNIEnv *, jclass, jint source) +{ +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "alSourcePause for source: %d", source); + alSourcePause((ALuint)source); +} + +JNIEXPORT void JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alSourcef + (JNIEnv *, jclass, jint source, jint param, jfloat value) +{ +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "alSourcef for source: %d, param: %d, value: %f", source, param, value); + alSourcef((ALuint)source, (ALenum)param, (ALfloat)value); +} + +JNIEXPORT void JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alSource3f + (JNIEnv *, jclass, jint source, jint param, jfloat value1, jfloat value2, jfloat value3) +{ +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "alSource3f for source: %d, param: %d, value1: %f, value2: %f, value3: %f", source, param, value1, value2, value3); + alSource3f((ALuint)source, (ALenum)param, (ALfloat)value1, (ALfloat)value2, (ALfloat)value3); +} + +JNIEXPORT jint JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alGetSourcei + (JNIEnv *, jclass, jint source, jint param) +{ +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "alGetSourcei for source: %d, param: %d", source, param); + ALint result; + alGetSourcei((ALuint)source, (ALenum)param, &result); + return (jint)result; +} + +JNIEXPORT void JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alSourceUnqueueBuffers + (JNIEnv* env, jclass, jint source, jint numBuffers, jobject buffers) +{ +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "alSourceUnqueueBuffers for source: %d, numBuffers: %d", source, numBuffers); + ALuint* pBuffers = (ALuint*) env->GetDirectBufferAddress(buffers); + +// for (ALuint i=0; iGetDirectBufferAddress(buffers); + alSourceQueueBuffers((ALuint)source, (ALsizei)numBuffers, pBuffers); +// for (ALuint i=0; iGetDirectBufferAddress(bufferData); + alListenerfv((ALenum)param, pBufferData); +// getError(); +// for (int i=0; i<4; i++) { +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "alListener[%d]: %f", i, *(pBufferData+(i*sizeof(ALfloat)))); +// } + +} + +JNIEXPORT void JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alListenerf + (JNIEnv *, jclass, jint param, jfloat value) +{ +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "alListenerf for param: %d, value: %f", param, value); + alListenerf((ALenum)param, (ALfloat)value); +} + +JNIEXPORT void JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alListener3f + (JNIEnv *, jclass, jint param, jfloat value1, jfloat value2, jfloat value3) +{ +// __android_log_print(ANDROID_LOG_INFO, "OpenAL Soft", "alListener3f for param: %d, value1: %f, value2: %f, value3: %f", param, value1, value2, value3); + alListener3f((ALenum)param, (ALfloat)value1, (ALfloat)value2, (ALfloat)value3); +} + + + + + +#ifdef __cplusplus +} +#endif diff --git a/engine/src/openal-soft-native/android/com_jme3_audio_android_AndroidOpenALSoftAudioRenderer.h b/engine/src/openal-soft-native/android/com_jme3_audio_android_AndroidOpenALSoftAudioRenderer.h new file mode 100644 index 000000000..3469f1da4 --- /dev/null +++ b/engine/src/openal-soft-native/android/com_jme3_audio_android_AndroidOpenALSoftAudioRenderer.h @@ -0,0 +1,207 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class com_jme3_audio_android_AndroidOpenALSoftAudioRenderer */ + +#ifndef _Included_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer +#define _Included_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer +#ifdef __cplusplus +extern "C" { +#endif +/* Inaccessible static: logger */ +#undef com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_BUFFER_SIZE +#define com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_BUFFER_SIZE 35280L +#undef com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_STREAMING_BUFFER_COUNT +#define com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_STREAMING_BUFFER_COUNT 5L +#undef com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_MAX_NUM_CHANNELS +#define com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_MAX_NUM_CHANNELS 64L +#undef com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_UPDATE_RATE +#define com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_UPDATE_RATE 0.05f +/* Inaccessible static: _00024assertionsDisabled */ +/* + * Class: com_jme3_audio_android_AndroidOpenALSoftAudioRenderer + * Method: alIsCreated + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alIsCreated + (JNIEnv *, jclass); + +/* + * Class: com_jme3_audio_android_AndroidOpenALSoftAudioRenderer + * Method: alCreate + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alCreate + (JNIEnv *, jclass); + +/* + * Class: com_jme3_audio_android_AndroidOpenALSoftAudioRenderer + * Method: alDestroy + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alDestroy + (JNIEnv *, jclass); + +/* + * Class: com_jme3_audio_android_AndroidOpenALSoftAudioRenderer + * Method: alcGetString + * Signature: (I)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alcGetString + (JNIEnv *, jclass, jint); + +/* + * Class: com_jme3_audio_android_AndroidOpenALSoftAudioRenderer + * Method: alGetString + * Signature: (I)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alGetString + (JNIEnv *, jclass, jint); + +/* + * Class: com_jme3_audio_android_AndroidOpenALSoftAudioRenderer + * Method: alGenSources + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alGenSources + (JNIEnv *, jclass); + +/* + * Class: com_jme3_audio_android_AndroidOpenALSoftAudioRenderer + * Method: alGetError + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alGetError + (JNIEnv *, jclass); + +/* + * Class: com_jme3_audio_android_AndroidOpenALSoftAudioRenderer + * Method: alDeleteSources + * Signature: (ILjava/nio/IntBuffer;)V + */ +JNIEXPORT void JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alDeleteSources + (JNIEnv *, jclass, jint, jobject); + +/* + * Class: com_jme3_audio_android_AndroidOpenALSoftAudioRenderer + * Method: alGenBuffers + * Signature: (ILjava/nio/IntBuffer;)V + */ +JNIEXPORT void JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alGenBuffers + (JNIEnv *, jclass, jint, jobject); + +/* + * Class: com_jme3_audio_android_AndroidOpenALSoftAudioRenderer + * Method: alDeleteBuffers + * Signature: (ILjava/nio/IntBuffer;)V + */ +JNIEXPORT void JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alDeleteBuffers + (JNIEnv *, jclass, jint, jobject); + +/* + * Class: com_jme3_audio_android_AndroidOpenALSoftAudioRenderer + * Method: alSourceStop + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alSourceStop + (JNIEnv *, jclass, jint); + +/* + * Class: com_jme3_audio_android_AndroidOpenALSoftAudioRenderer + * Method: alSourcei + * Signature: (III)V + */ +JNIEXPORT void JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alSourcei + (JNIEnv *, jclass, jint, jint, jint); + +/* + * Class: com_jme3_audio_android_AndroidOpenALSoftAudioRenderer + * Method: alBufferData + * Signature: (IILjava/nio/ByteBuffer;II)V + */ +JNIEXPORT void JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alBufferData + (JNIEnv *, jclass, jint, jint, jobject, jint, jint); + +/* + * Class: com_jme3_audio_android_AndroidOpenALSoftAudioRenderer + * Method: alSourcePlay + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alSourcePlay + (JNIEnv *, jclass, jint); + +/* + * Class: com_jme3_audio_android_AndroidOpenALSoftAudioRenderer + * Method: alSourcePause + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alSourcePause + (JNIEnv *, jclass, jint); + +/* + * Class: com_jme3_audio_android_AndroidOpenALSoftAudioRenderer + * Method: alSourcef + * Signature: (IIF)V + */ +JNIEXPORT void JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alSourcef + (JNIEnv *, jclass, jint, jint, jfloat); + +/* + * Class: com_jme3_audio_android_AndroidOpenALSoftAudioRenderer + * Method: alSource3f + * Signature: (IIFFF)V + */ +JNIEXPORT void JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alSource3f + (JNIEnv *, jclass, jint, jint, jfloat, jfloat, jfloat); + +/* + * Class: com_jme3_audio_android_AndroidOpenALSoftAudioRenderer + * Method: alGetSourcei + * Signature: (II)I + */ +JNIEXPORT jint JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alGetSourcei + (JNIEnv *, jclass, jint, jint); + +/* + * Class: com_jme3_audio_android_AndroidOpenALSoftAudioRenderer + * Method: alSourceUnqueueBuffers + * Signature: (IILjava/nio/IntBuffer;)V + */ +JNIEXPORT void JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alSourceUnqueueBuffers + (JNIEnv *, jclass, jint, jint, jobject); + +/* + * Class: com_jme3_audio_android_AndroidOpenALSoftAudioRenderer + * Method: alSourceQueueBuffers + * Signature: (IILjava/nio/IntBuffer;)V + */ +JNIEXPORT void JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alSourceQueueBuffers + (JNIEnv *, jclass, jint, jint, jobject); + +/* + * Class: com_jme3_audio_android_AndroidOpenALSoftAudioRenderer + * Method: alListener + * Signature: (ILjava/nio/FloatBuffer;)V + */ +JNIEXPORT void JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alListener + (JNIEnv *, jclass, jint, jobject); + +/* + * Class: com_jme3_audio_android_AndroidOpenALSoftAudioRenderer + * Method: alListenerf + * Signature: (IF)V + */ +JNIEXPORT void JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alListenerf + (JNIEnv *, jclass, jint, jfloat); + +/* + * Class: com_jme3_audio_android_AndroidOpenALSoftAudioRenderer + * Method: alListener3f + * Signature: (IFFF)V + */ +JNIEXPORT void JNICALL Java_com_jme3_audio_android_AndroidOpenALSoftAudioRenderer_alListener3f + (JNIEnv *, jclass, jint, jfloat, jfloat, jfloat); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/engine/src/openal-soft-native/android/config.h b/engine/src/openal-soft-native/android/config.h new file mode 100644 index 000000000..bf3ee85db --- /dev/null +++ b/engine/src/openal-soft-native/android/config.h @@ -0,0 +1,147 @@ +#ifndef CONFIG_H +#define CONFIG_H + +/* Define to the library version */ +#define ALSOFT_VERSION "1.15.1" + +#define ALIGN(x) __attribute__ ((aligned(x))) + +/* Define if we have the Android backend */ +/* #define HAVE_ANDROID 1 */ + +/* Define if we have the ALSA backend */ +/* #define HAVE_ALSA */ + +/* Define if we have the OSS backend */ +/* #cmakedefine HAVE_OSS */ + +/* Define if we have the Solaris backend */ +/* #cmakedefine HAVE_SOLARIS */ + +/* Define if we have the SndIO backend */ +/* #cmakedefine HAVE_SNDIO */ + +/* Define if we have the MMDevApi backend */ +/* #cmakedefine HAVE_MMDEVAPI */ + +/* Define if we have the DSound backend */ +/* #cmakedefine HAVE_DSOUND */ + +/* Define if we have the Windows Multimedia backend */ +/* #cmakedefine HAVE_WINMM */ + +/* Define if we have the PortAudio backend */ +/* #cmakedefine HAVE_PORTAUDIO */ + +/* Define if we have the PulseAudio backend */ +/* #cmakedefine HAVE_PULSEAUDIO */ + +/* Define if we have the CoreAudio backend */ +/* #cmakedefine HAVE_COREAUDIO */ + +/* Define if we have the OpenSL backend */ +#define HAVE_OPENSL /* THIS BACKEND WORKS ON >=2.3 Android!! */ + +/* Define if we have the Wave Writer backend */ +/* #cmakedefine HAVE_WAVE */ + +/* Define if we have dlfcn.h */ +#define HAVE_DLFCN_H + +/* Define if we have the stat function */ +#define HAVE_STAT + +/* Define if we have the powf function */ +/* #define HAVE_POWF 1 */ + +/* Define if we have the sqrtf function */ +/* #define HAVE_SQRTF 1 */ + +/* Define if we have the cosf function */ +/* #define HAVE_COSF 1 */ + +/* Define if we have the sinf function */ +/* #define HAVE_SINF 1 */ + +/* Define if we have the acosf function */ +/* #define HAVE_ACOSF 1 */ + +/* Define if we have the asinf function */ +/* #define HAVE_ASINF 1 */ + +/* Define if we have the atanf function */ +/* #define HAVE_ATANF 1 */ + +/* Define if we have the atan2f function */ +/* #define HAVE_ATAN2F 1 */ + +/* Define if we have the fabsf function */ +/* #define HAVE_FABSF 1 */ + +/* Define if we have the log10f function */ +/* #define HAVE_LOG10F 1 */ + +/* Define if we have the floorf function */ +/* #define HAVE_FLOORF 1 */ + +/* Define if we have the strtof function */ +#define HAVE_STRTOF + +/* Define if we have stdint.h */ +#define HAVE_STDINT_H + +/* Define if we have the __int64 type */ +/* #cmakedefine HAVE___INT64 */ + +/* Define to the size of a long int type */ +#define SIZEOF_LONG 4 + +/* Define to the size of a long long int type */ +#define SIZEOF_LONG_LONG 8 + +/* Define if we have GCC's destructor attribute */ +#define HAVE_GCC_DESTRUCTOR + +/* Define if we have GCC's format attribute */ +#define HAVE_GCC_FORMAT + +/* Define if we have pthread_np.h */ +/* #cmakedefine HAVE_PTHREAD_NP_H */ + +/* Define if we have arm_neon.h */ +/* #cmakedefine HAVE_ARM_NEON_H */ + +/* Define if we have guiddef.h */ +/* #cmakedefine HAVE_GUIDDEF_H */ + +/* Define if we have guiddef.h */ +/* #cmakedefine HAVE_INITGUID_H */ + +/* Define if we have ieeefp.h */ +/* #cmakedefine HAVE_IEEEFP_H */ + +/* Define if we have float.h */ +/* #cmakedefine HAVE_FLOAT_H */ + +/* Define if we have fpu_control.h */ +/* #cmakedefine HAVE_FPU_CONTROL_H */ + +/* Define if we have fenv.h */ +#define HAVE_FENV_H + +/* Define if we have fesetround() */ +/* #cmakedefine HAVE_FESETROUND */ + +/* Define if we have _controlfp() */ +/* #cmakedefine HAVE__CONTROLFP */ + +/* Define if we have pthread_setschedparam() */ +#define HAVE_PTHREAD_SETSCHEDPARAM + +/* Define if we have the restrict keyword */ +/* #cmakedefine HAVE_RESTRICT 1 */ + +/* Define if we have the __restrict keyword */ +#define RESTRICT __restrict + +#endif