The AL Context API

Up to this point, all the sample applications have relied heavily on the Alut class. The Alut class is a valuable resource that lets new developers get acclimated with the API quickly without being mired in minutia from the start. That being said, at some point in time it may become necessary to be more specific in the setup and structure of JOAL’s initialization or with controlling how OpenAL interacts with the operating system on which it is deployed. This section discusses AL Contexts and how an application can manage them using the AL Context API.

Fundamentally, the AL Context API works through the use of the ALC class. This class is structured to allow the user to gain access to hardware by presenting it as a resource. Through the AL Context API, the audio resources are presented in the form of devices. A device can be thought of as a handle to the actual physical audio card used, which is exposed through the local implementation. At this point, it is not possible to enumerate the list of available sound cards through the use of the ALC. It is possible, however, to identify a particular implementation or to use the implementation’s default device.

JOAL provides an ALFactory class to work with the generation of AL and ALC classes. The ALFactory has already been used to create the AL objects earlier in the chapter. When creating a context, the first step is to initialize the ALFactory, then to retrieve an ALC object for use in the application. Let’s set up this basic step.

ALFactory.initialize(); ALC alc = ALFactory.getALC();

Now that the application has access to an ALC object, it is time to create the device instance that will be used by this application. When creating one of the device objects, the application can be set to use the default device by passing null through to the alcOpenDevice() method, or it can specify a particular string to work with a valid implementation. Be sure to reference the platform-specific documentation to verify that the desired implementation is valid before using it.

Let’s set up a device for the Window’s platform using the DirextX DirectSound3D implementation.

ALC.Device device = alc.alcOpenDevice(“DirectSound3D”);

This method will return null if it is unable to find a device on the system. When this call correctly returns, the application holds a handle to the specified device. When the application is completed, we must destroy the context and then close the device before exiting, as follows:

alc.DestroyContext(context); alc.alcCloseDevice(device);



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