Sound Rendering Contexts

OpenAL uses contexts to organize and control rendering of audio according to the spec that has been detailed so far. The term sound-rendering context is used to identify the core operation of OpenAL and its ability to manage and process spatialized audio. Readers who are familiar with OpenGL will probably recognize the use of rendering contexts. Although there can be multiple contexts for OpenGL rendering, there can be only one active context at any given time. OpenAL and JOAL follow this standard as well. When the AL class is used to make a change of some sort within the application, the effect is applied to the current context for the game in question. For most applications, a single AL Context is used throughout the entire execution.

Because the device has already been created and opened, let’s specify a context and set it to be the current context.

ALC.Context context = alc.alcCreateContext(device, null); alc.alcMakeContextCurrent(context);

The alcCreateContext() method accepts an opened device as well as a flag. If the flag is set to null, as in the example, the default values for the chosen implementation will be used. Currently supported flags for context creation include:

ALC_FREQUENCY: Allows the context to set its output Buffer frequency (in Hz).

ALC_REFRESH: The context’s refresh interval. Can be used to set the timing for state changes to the same as in OpenGL (in Hz).

ALC_SYNC: A Boolean flag that indicates that the context is synchronous.

To set one or more of these values, use an integer array and pass the whole thing through the method that creates the context, as follows:

int[] attribs = {ALC.ALC_SYNC, AL.AL_TRUE, ALC.ALC_FREQUENCY, 9600}; ALC.Context context = alc.alcCreateContext(device,attribs); alc.alcMakeContextCurrent(context);

At this point a new context is created and ready for use. These calls can be used to make a custom initialization routine for JOAL and summarily replace the Alut.alutExit and Alut.alutInit calls. All calls related to the destruction of Sources and Buffers remain. Additionally, applications can still use the file loading routines of Alut that have been demonstrated so far.

After a context is created, it can be managed through a set of methods designed to report information and control the activities of a context. As mentioned before, it is completely possible to maintain and manage more than one context, even if it is not currently selected. Let’s look at a few of the more immediately useful methods available to the developer who creates and manages contexts.

alcSuspendContext: This method is one of the more useful control mechanisms available when working directly through contexts. This method allows the current context to be suspended. Whenever a context is suspended, all processing is stopped. This control could be useful as a way of maintaining the state in a game when the user decides to pause the game. The same effect could be handled if the gain on a source was set to 0, but the context would continue to process the audio. The combination of suspending a context and reducing the gain results in a true pause for the current context.

alcProcessContext: This method allows a context to return to the normal processing state. Call this method to remove suspension from a selected context. It is also possible to process a context, even while it is not the current selected context.

alcIsExtensionPresent: One of the best aspects of both OpenGL and OpenAL is that vendors or anyone else with access to the source tree can create customized extensions for the API and include them into the implementation. At this time, JOAL implements the EAX extension, which allows for customized audio processing. In the future other extensions are planned for integration, including Ogg Vorbis support. Using this method allows you to check before using an extension so that the application can set internal switches accordingly to avoid errors or performance degradation.

alcGetString: This method allows the device to return information based on the current device. The attribute parameters can be one of the following attributes:

ALC_DEFAULT_DEVICE_SPECIFIER: When using this attribute, the method returns information about the device that the current implementation prefers the application to use. This information can be helpful when attempting to provide support for multiple implementations.

ALC_DEVICE_SPECIFIER: This attribute returns a string that contains the current device specifiers for the version of OpenAL in use.

ALC_EXTENSIONS: This attribute is designed to return a list of ALC extensions. None of these are currently implemented, making this parameter a placeholder of sorts.

AlcGetError(): This method allows the user to retrieve error messages from the ALC. Table 4.5 shows the list of valid error messages and descriptions for each.

Table 4.5 :  ALC ERROR CODES

Name

Description

ALC_NO_ERROR

The device handle or specifier name is inaccessible

ALC_INVALID_DEVICE

The context argument does not name a valid device

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 invalid or inapplicable value/attribute was passed

That wraps up coverage on the AL Context API. Double-check the most recent JOAL documentation to verify support, and check for any updates that might affect the implementation of any of these routines.



Practical Java Game Programming
Practical Java Game Programming (Charles River Media Game Development)
ISBN: 1584503262
EAN: 2147483647
Year: 2003
Pages: 171

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net