initial commit of OpenAL code

This commit is contained in:
Brian Matzon 2002-08-13 23:13:28 +00:00
parent e26f1ba417
commit a972863064
8 changed files with 598 additions and 0 deletions

View File

@ -0,0 +1,18 @@
package org.lwjgl.openal;
/**
* $Id$
*
* This is the OpenAL class. It extends the latest core.
*
* @author Brian Matzon <brian@matzon.dk>
* @version $Revision$
*/
public class AL extends CoreAL10 {
/**
* Nothing to se here - please move along
*/
public AL() {
}
}

View File

@ -0,0 +1,12 @@
package org.lwjgl.openal;
/**
* $Id$
*
* This class contains all OpenAL constants, including extensions.
*
* @author Brian Matzon <brian@matzon.dk>
* @version $Revision$
*/
public interface ALConstants extends BaseALConstants, EAXALConstants {
}

View File

@ -0,0 +1,56 @@
package org.lwjgl.openal;
/**
* $Id$
*
* This is the utility class for OpenAL. This class implements functions
* in alut.h
*
* @author Brian Matzon <brian@matzon.dk>
* @version $Revision$
*/
public class ALUT {
static {
try {
System.loadLibrary(org.lwjgl.Sys.LIBRARY_NAME);
} catch (UnsatisfiedLinkError ule) {
System.out.println("Failed to load OpenAL library: " + org.lwjgl.Sys.LIBRARY_NAME);
ule.printStackTrace();
}
}
/** Creates a new instance of ALUT */
public ALUT() {
}
/**
* Initializes the OpenAL engine
*
* @param args String array of arguments to engine
*/
public native void alutInit(String[] args);
/**
* Loads a wave file into memory
*
* @param file name of file to load (in current working directory)
* @return ALUTLoadWAVFile object containing information regarding file loaded
*/
public native ALUTLoadWAVFile alutLoadWAVFile(String file);
/**
* Unloads the specified file from memory
*
* @param format OpenAL format specifier
* @param data address of data (pointer)
* @param size size of the data in bytes
* @param freq frequency of the data
*/
public native void alutUnloadWAV(int format, int data, int size, int freq);
/**
* Deinitializes the OpenAL engine
*/
public native void alutExit();
}

View File

@ -0,0 +1,47 @@
package org.lwjgl.openal;
/**
* $Id$
*
* This class is used by the alutLoadWAVFile method. Since we
* cannot modify values supplied to the method (since JNI is pass by value)
* we return this object, which encapsulates the file loaded. Use this class
* when unloading using 'alutUnloadWAV'.
*
* @author Brian Matzon <brian@matzon.dk>
* @version $Revision$
*/
public class ALUTLoadWAVFile {
/* format of file */
public final int format;
/* pointer to data allocated */
public final int data;
/* size of data allocated */
public final int size;
/* frequency of sound data */
public final int freq;
/* whether or not to loop */
public final boolean loop;
/**
* Creates an ALUTLoadWAVFile object with specified properties
*
* @param format OpenAL format specifier
* @param data address of data (pointer)
* @param size size of the data in bytes
* @param freq frequency of the data
* @param loop looping indicator for the WAV data
*/
public ALUTLoadWAVFile(int format, int data, int size, int freq, boolean loop) {
this.format = format;
this.data = data;
this.size = size;
this.freq = freq;
this.loop = loop;
}
}

View File

@ -0,0 +1,24 @@
package org.lwjgl.openal;
/**
* $Id$
*
* The base AL functionality (no actual AL methods).
*
* This has been provided as a base class that we can use for either the
* full AL 1.0 specification or as a cut-down OpenAL embedded spec. (aka
* a mini-driver).
*
* @author Brian Matzon <brian@matzon.dk>
* @version $Revision$
*/
public abstract class BaseAL {
static {
try {
System.loadLibrary(org.lwjgl.Sys.LIBRARY_NAME);
} catch (UnsatisfiedLinkError ule) {
System.out.println("Failed to load OpenAL library: " + org.lwjgl.Sys.LIBRARY_NAME);
ule.printStackTrace();
}
}
}

View File

@ -0,0 +1,329 @@
package org.lwjgl.openal;
/**
* $Id$
*
* This class implements all basic OpenAL constants.
*
* @author Brian Matzon <brian@matzon.dk>
* @version $Revision$
*/
public interface BaseALConstants {
/** Bad value */
public static final int AL_INVALID = -1;
/** Disable value */
public static final int AL_NONE = 0;
/** Boolean False */
public static final int AL_FALSE = 0;
/** Boolean True */
public static final int AL_TRUE = 1;
/**
* Indicate the type of AL_SOURCE.
* Sources can be spatialized
*/
public static final int AL_SOURCE_TYPE = 0x200;
/** Indicate source has absolute coordinates */
public static final int AL_SOURCE_ABSOLUTE = 0x201;
/** Indicate Source has listener relative coordinates */
public static final int AL_SOURCE_RELATIVE = 0x202;
/**
* Directional source, inner cone angle, in degrees
* Range: [0-360]
* Default: 360
*/
public static final int AL_CONE_INNER_ANGLE = 0x1001;
/**
* Directional source, outer cone angle, in degrees.
* Range: [0-360]
* Default: 360
*/
public static final int AL_CONE_OUTER_ANGLE = 0x1002;
/**
* Specify the pitch to be applied, either at source,
* or on mixer results, at listener.
* Range: [0.5-2.0]
* Default: 1.0
*/
public 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.
*/
public static final int AL_POSITION = 0x1004;
/** Specify the current direction as forward vector. */
public static final int AL_DIRECTION = 0x1005;
/** Specify the current velocity in three dimensional space. */
public static final int AL_VELOCITY = 0x1006;
/**
* Indicate whether source has to loop infinite.
* Type: ALboolean
* Range: [AL_TRUE, AL_FALSE]
* Default: AL_FALSE
*/
public static final int AL_LOOPING = 0x1007;
/**
* Indicate the buffer to provide sound samples.
* Type: ALuint.
* Range: any valid Buffer id.
*/
public 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.
*/
public static final int AL_GAIN = 0x100A;
/**
* Indicate minimum source attenuation.
* Type: ALfloat
* Range: [0.0 - 1.0]
*/
public static final int AL_MIN_GAIN = 0x100D;
/**
* Indicate maximum source attenuation.
* Type: ALfloat
* Range: [0.0 - 1.0]
*/
public static final int AL_MAX_GAIN = 0x100E;
/**
* Specify the current orientation.
* Type: ALfv6 (at/up)
* Range: N/A
*/
public static final int AL_ORIENTATION = 0x100F;
/* byte offset into source (in canon format). -1 if source
* is not playing. Don't set this, get this.
*
* Type: ALfloat
* Range: [0.0 - ]
* Default: 1.0
*/
public static final int AL_REFERENCE_DISTANCE = 0x1020;
/**
* Indicate the rolloff factor for the source.
* Type: ALfloat
* Range: [0.0 - ]
* Default: 1.0
*/
public static final int AL_ROLLOFF_FACTOR = 0x1021;
/**
* 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.
*/
public static final int AL_CONE_OUTER_GAIN = 0x1022;
/**
* Specify the maximum distance.
* Type: ALfloat
* Range: [0.0 - ]
*/
public static final int AL_MAX_DISTANCE = 0x1023;
/**
* Specify the channel mask. (Creative)
* Type: ALuint
* Range: [0 - 255]
*/
public static final int AL_CHANNEL_MASK = 0x3000;
/** Source state information */
public static final int AL_SOURCE_STATE = 0x1010;
/** Source state information */
public static final int AL_INITIAL = 0x1011;
/** Source state information */
public static final int AL_PLAYING = 0x1012;
/** Source state information */
public static final int AL_PAUSED = 0x1013;
/** Source state information */
public static final int AL_STOPPED = 0x1014;
/** Buffer Queue params */
public static final int AL_BUFFERS_QUEUED = 0x1015;
/** Buffer Queue params */
public static final int AL_BUFFERS_PROCESSED = 0x1016;
/** Sound buffers: format specifier. */
public static final int AL_FORMAT_MONO8 = 0x1100;
/** Sound buffers: format specifier. */
public static final int AL_FORMAT_MONO16 = 0x1101;
/** Sound buffers: format specifier. */
public static final int AL_FORMAT_STEREO8 = 0x1102;
/** Sound buffers: format specifier. */
public static final int AL_FORMAT_STEREO16 = 0x1103;
/**
* Sound buffers: 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.
*/
public static final int AL_FREQUENCY = 0x2001;
/**
* Sound buffers: 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.
*/
public static final int AL_BITS = 0x2002;
/**
* Sound buffers: 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.
*/
public static final int AL_CHANNELS = 0x2003;
/**
* Sound buffers: 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.
*/
public static final int AL_SIZE = 0x2004;
/**
* Sound buffers: 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.
*/
public static final int AL_DATA = 0x2005;
/**
* Buffer state.
*
* Not supported for public use (yet).
*/
public static final int AL_UNUSED = 0x2010;
/**
* Buffer state.
*
* Not supported for public use (yet).
*/
public static final int AL_PENDING = 0x2011;
/**
* Buffer state.
*
* Not supported for public use (yet).
*/
public static final int AL_PROCESSED = 0x2012;
/** Errors: No Error. */
public static final int AL_NO_ERROR = AL_FALSE;
/**
* Illegal name passed as an argument to an AL call.
*/
public static final int AL_INVALID_NAME = 0xA001;
/**
* Illegal enum passed as an argument to an AL call.
*/
public static final int AL_INVALID_ENUM = 0xA002;
/**
* Illegal value passed as an argument to an AL call.
* Applies to parameter values, but not to enumerations.
*/
public static final int AL_INVALID_VALUE = 0xA003;
/**
* A function was called at inappropriate time,
* or in an inappropriate way, causing an illegal state.
* This can be an incompatible ALenum, object ID,
* and/or function.
*/
public static final int AL_INVALID_OPERATION = 0xA004;
/**
* A function could not be completed,
* because there is not enough memory available.
*/
public static final int AL_OUT_OF_MEMORY = 0xA005;
/** Context strings: Vendor */
public static final int AL_VENDOR = 0xB001;
/** Context strings: Version */
public static final int AL_VERSION = 0xB002;
/** Context strings: Renderer */
public static final int AL_RENDERER = 0xB003;
/** Context strings: Extensions */
public static final int AL_EXTENSIONS = 0xB004;
/**
* Doppler scale. Default 1.0
*/
public static final int AL_DOPPLER_FACTOR = 0xC000;
/**
* Doppler velocity. Default 1.0
*/
public static final int AL_DOPPLER_VELOCITY = 0xC001;
/**
* Distance model. Default AL_INVERSE_DISTANCE_CLAMPED
*/
public static final int AL_DISTANCE_MODEL = 0xD000;
/** Distance model */
public static final int AL_INVERSE_DISTANCE = 0xD001;
/** Distance model */
public static final int AL_INVERSE_DISTANCE_CLAMPED = 0xD002;
}

View File

@ -0,0 +1,99 @@
package org.lwjgl.openal;
/**
* $Id$
*
* This is the core OpenAL 1.0 class. This class implements
* AL.h version 1.0
*
* @author Brian Matzon <brian@matzon.dk>
* @version $Revision$
*/
public class CoreAL10 extends BaseAL implements BaseALConstants {
/** Creates a new instance of CoreAL10 */
public CoreAL10() {
}
/**
* Retrieve the current error state and then clears the error state.
*
* @return current error state
*/
public native int alGetError();
/**
* Retrieve an OpenAL string property.
*
* @param param The property to be returned
* @return OpenAL String property
*/
public native String alGetString(int param);
/**
* Generate one or more buffers.
*
* @param n number of buffers to generate
* @param buffers array holding buffers
*/
public native void alGenBuffers(int n, int[] buffers);
/**
* Generate one or more sources.
*
* @param n number of sources to generate
* @param sources array holding sources
*/
public native void alGenSources(int n, int[] sources);
/**
* Fill a buffer with audio data.
*
* @param buffer Buffer to fill
* @param format format sound data is in
* @param data location of data (pointer)
* @param size size of data segment
* @param freq frequency of data
*/
public native void alBufferData(int buffer, int format, int data, int size, int freq);
/**
* Set an integer property of a source.
*
* @param source Source to det property on
* @param param property to set
* @param value value of property
*/
public native void alSourcei(int source, int param, int value);
/**
* Play a source.
*
* @param source Source to play
*/
public native void alSourcePlay(int source);
/**
* Stops a source.
*
* @param source Source to stop
*/
public native void alSourceStop(int source);
/**
* Delete one or more sources.
*
* @param n Number of sources to delete
* @param source Source array to delete from
*/
public native void alDeleteSources(int n, int[] source);
/**
* Delete one or more buffers.
*
* @param n Number of buffers to delete
* @param buffers Buffer array to delete from
*/
public native void alDeleteBuffers(int n, int[] buffers);
}

View File

@ -0,0 +1,13 @@
package org.lwjgl.openal;
/**
* $Id$
*
* This class implements the EAX extension constants.
*
* @author Brian Matzon <brian@matzon.dk>
* @version $Revision$
*/
public interface EAXALConstants {
//add some...
}