/* * Copyright (c) 2002-2004 LWJGL Project * 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 'LWJGL' 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 org.lwjgl.openal; import java.nio.Buffer; import java.nio.IntBuffer; import org.lwjgl.Sys; import org.lwjgl.LWJGLException; import org.lwjgl.BufferChecks; /** * $Id$ * *
* This is the context class for OpenAL. This class implements functions * in alc.h *
* ** ALC introduces the notion of a Device. A Device can be, depending on the * implementation, a hardware device, or a daemon/OS service/actual server. This * mechanism also permits different drivers (and hardware) to coexist within the same * system, as well as allowing several applications to share system resources for audio, * including a single hardware output device. The details are left to the * implementation, which has to map the available backends to unique device * specifiers (represented as strings). *
* *
* NOTE:
* The LWJGL implementation of OpenAL does not expose the device, nor the context.
* Whenever AL is created using the create method, an underlying
* device and context is created. Thus more advanced usage of multiple contexts and/or devices
* are not possible. The above mentioned features are very rarely used in games.
*
ALC_DEFAULT_DEVICE_SPECIFIER - The specifer string for the default device
* ALC_DEVICE_SPECIFIER - The specifer string for the device
* ALC_EXTENSIONS - The extensions string for diagnostics and printing.
*
* In addition, printable error message strings are provided for all valid error tokens,
* including ALC_NO_ERROR,ALC_INVALID_DEVICE, ALC_INVALID_CONTEXT,
* ALC_INVALID_ENUM, ALC_INVALID_VALUE.
*
* @param pname Property to get
* @return String property from device
*/
public static String alcGetString(int pname) {
return nalcGetString(AL.device.device, pname);
}
native static String nalcGetString(int device, int pname);
/**
* The application can query ALC for information using an integer query function.
* For some tokens, null is a legal deviceHandle. In other cases, specifying a null
* device will generate an ALC_INVALID_DEVICE error. The application has to
* specify the size of the destination buffer provided. A null destination or a zero
* size parameter will cause ALC to ignore the query.
*
* ALC_MAJOR_VERSION - Major version query.
* ALC_MINOR_VERSION - Minor version query.
* ALC_ATTRIBUTES_SIZE - The size required for the zero-terminated attributes list,
* for the current context. null is an invalid device. null (no current context
* for the specified device) is legal.
* ALC_ALL_ATTRIBUTES - Expects a destination of ALC_CURRENT_ATTRIBUTES_SIZE,
* and provides the attribute list for the current context of the specified device.
* null is an invalid device. null (no current context for the specified device)
* will return the default attributes defined by the specified device.
*
* @param pname Property to get
* @param integerdata ByteBuffer to write integers to
*/
public static void alcGetInteger(int pname, IntBuffer integerdata) {
BufferChecks.checkDirect(integerdata);
nalcGetIntegerv(AL.device.device, pname, integerdata.remaining(), integerdata, integerdata.position());
}
native static void nalcGetIntegerv(int device, int pname, int size, Buffer integerdata, int offset);
/**
* The alcOpenDevice function allows the application (i.e. the client program) to
* connect to a device (i.e. the server).
*
* If the function returns null, then no sound driver/device has been found. The
* argument is a null terminated string that requests a certain device or device
* configuration. If null is specified, the implementation will provide an
* implementation specific default.
*
* @param devicename name of device to open
* @return opened device, or null
*/
native static ALCdevice alcOpenDevice(String devicename);
/**
* The alcCloseDevice function allows the application (i.e. the client program) to
* disconnect from a device (i.e. the server).
*
* If deviceHandle is null or invalid, an ALC_INVALID_DEVICE error will be
* generated. Once closed, a deviceHandle is invalid.
*
* @param device address of native device to close
*/
native static void alcCloseDevice(int device);
/**
* A context is created using alcCreateContext. The device parameter has to be a valid
* device. The attribute list can be null, or a zero terminated list of integer pairs
* composed of valid ALC attribute tokens and requested values.
*
* Context creation will fail if the application requests attributes that, by themselves,
* can not be provided. Context creation will fail if the combination of specified
* attributes can not be provided. Context creation will fail if a specified attribute, or
* the combination of attributes, does not match the default values for unspecified
* attributes.
*
* @param device address of device to associate context to
* @param attrList Buffer to read attributes from
* @return New context, or null if creation failed
*/
native static ALCcontext alcCreateContext(int device, IntBuffer attrList);
/**
* To make a Context current with respect to AL Operation (state changes by issueing
* commands), alcMakeContextCurrent is used. The context parameter can be null
* or a valid context pointer. The operation will apply to the device that the context
* was created for.
*
* For each OS process (usually this means for each application), only one context can
* be current at any given time. All AL commands apply to the current context.
* Commands that affect objects shared among contexts (e.g. buffers) have side effects
* on other contexts.
*
* @param context address of context to make current
* @return true if successfull, false if not
*/
native static int alcMakeContextCurrent(int context);
/**
* The current context is the only context accessible to state changes by AL commands
* (aside from state changes affecting shared objects). However, multiple contexts can
* be processed at the same time. To indicate that a context should be processed (i.e.
* that internal execution state like offset increments are supposed to be performed),
* the application has to use alcProcessContext.
*
* Repeated calls to alcProcessContext are legal, and do not affect a context that is
* already marked as processing. The default state of a context created by
* alcCreateContext is that it is not marked as processing.
*/
public static void alcProcessContext() {
nalcProcessContext(AL.context.context);
}
native static void nalcProcessContext(int context);
/**
* The application can query for, and obtain an handle to, the current context for the
* application. If there is no current context, null is returned.
*
* @return Current ALCcontext
*/
native static ALCcontext alcGetCurrentContext();
/**
* The application can query for, and obtain an handle to, the device of a given context.
*
* @param context address of context to get device for
* @param ALCdevice associated with context
*/
native static ALCdevice alcGetContextsDevice(int context);
/**
* The application can suspend any context from processing (including the current
* one). To indicate that a context should be suspended from processing (i.e. that
* internal execution state like offset increments is not supposed to be changed), the
* application has to use alcSuspendContext.
*
* Repeated calls to alcSuspendContext are legal, and do not affect a context that is
* already marked as suspended. The default state of a context created by
* alcCreateContext is that it is marked as suspended.
*
* @param context address of context to suspend
*/
public static void alcSuspendContext() {
nalcSuspendContext(AL.context.context);
}
native static void nalcSuspendContext(int context);
/**
* The correct way to destroy a context is to first release it using alcMakeCurrent and
* null. Applications should not attempt to destroy a current context.
*
* @param context address of context to Destroy
*/
native static void alcDestroyContext(int context);
/**
* ALC uses the same conventions and mechanisms as AL for error handling. In
* particular, ALC does not use conventions derived from X11 (GLX) or Windows
* (WGL). The alcGetError function can be used to query ALC errors.
*
* Error conditions are specific to the device.
*
* ALC_NO_ERROR - The device handle or specifier does name an accessible driver/server.
* ALC_INVALID_DEVICE - The Context argument does not name a valid context.
* ALC_INVALID_CONTEXT - The Context argument does not name a valid context.
* ALC_INVALID_ENUM - A token used is not valid, or not applicable.
* ALC_INVALID_VALUE - An value (e.g. attribute) is not valid, or not applicable.
*
* @return Errorcode from ALC statemachine
*/
public static int alcGetError() {
return nalcGetError(AL.device.device);
}
native static int nalcGetError(int device);
/**
* Verify that a given extension is available for the current context and the device it
* is associated with.
* A null name argument returns ALC_FALSE, as do invalid and unsupported string
* tokens.
*
* @param extName name of extension to find
* @return true if extension is available, false if not
*/
public static boolean alcIsExtensionPresent(String extName) {
return nalcIsExtensionPresent(AL.device.device, extName);
}
native static boolean nalcIsExtensionPresent(int device, String extName);
/**
* Enumeration/token values are device independend, but tokens defined for
* extensions might not be present for a given device. But only the tokens defined
* by the AL core are guaranteed. Availability of extension tokens dependends on the ALC extension.
*
* Specifying a null name parameter will cause an ALC_INVALID_VALUE error.
*
* @param enumName name of enum to find
* @return value of enumeration
*/
public static int alcGetEnumValue(String enumName) {
return nalcGetEnumValue(AL.device.device, enumName);
}
native static int nalcGetEnumValue(int device, String enumName);
}