35package com.jogamp.openal.sound3d;
37import java.io.BufferedInputStream;
38import java.io.IOException;
39import java.io.InputStream;
41import com.jogamp.openal.AL;
42import com.jogamp.openal.ALC;
43import com.jogamp.openal.ALCConstants;
44import com.jogamp.openal.ALCcontext;
45import com.jogamp.openal.ALCdevice;
46import com.jogamp.openal.ALConstants;
47import com.jogamp.openal.ALException;
48import com.jogamp.openal.ALExt;
49import com.jogamp.openal.ALFactory;
50import com.jogamp.openal.UnsupportedAudioFileException;
51import com.jogamp.openal.util.WAVData;
52import com.jogamp.openal.util.WAVLoader;
54import jogamp.openal.Debug;
63 static boolean DEBUG = Debug.debug(
"AudioSystem3D");
66 static final ALExt alExt;
67 static final boolean staticAvailable;
78 }
catch(
final Throwable t) {
80 System.err.println(
"AudioSystem3D: Caught "+t.getClass().getName()+
": "+t.getMessage());
87 staticAvailable =
null != alc &&
null != al &&
null != alExt;
125 public static boolean checkError(
final Device device,
final String prefix,
final boolean verbose,
final boolean throwException) {
126 if( !
checkALCError(device, prefix, verbose, throwException) ) {
139 public static boolean checkALError(
final String prefix,
final boolean verbose,
final boolean throwException) {
142 final String msg = prefix+
": AL error 0x"+Integer.toHexString(alErr)+
", '"+al.
alGetString(alErr)+
"'";
144 System.err.println(msg);
146 if( throwException ) {
161 public static boolean checkALCError(
final Device device,
final String prefix,
final boolean verbose,
final boolean throwException) {
165 final String msg = prefix+
": ALC error 0x"+Integer.toHexString(alcErr)+
", '"+alc.
alcGetString(alcDevice, alcErr)+
"'";
167 System.err.println(msg);
169 if( throwException ) {
184 return new Context(device,
null);
195 return new Context(device, attributes);
243 return context.
release(throwException);
254 return new Device(deviceName);
266 final int[] arr =
new int[numBuffers];
269 for (
int i = 0; i < numBuffers; i++) {
270 result[i] =
new Buffer(arr[i]);
320 if (!(stream instanceof BufferedInputStream)) {
321 stream =
new BufferedInputStream(stream);
381 final int[] arr =
new int[numSources];
384 for (
int i = 0; i < numSources; i++) {
385 result[i] =
new Source(arr[i]);
413 if (listener ==
null) {
A generic exception for OpenAL errors used throughout the binding as a substitute for RuntimeExceptio...
This class provides factory methods for generating AL and ALC objects.
static AL getAL()
Get the default AL object.
static ALExt getALExt()
Get the default ALExt object.
static ALC getALC()
Get the default ALC object.
The AudioSystem3D class provides a set of methods for creating and manipulating a 3D audio environmen...
static Listener getListener()
Get the listener object associated with this Sound3D environment.
static Buffer loadBuffer(InputStream stream)
Loads a Sound3D buffer with the specified audio file.
static final ALC getALC()
Return OpenAL global ALC.
static Source loadSource(final String filename)
Loads a Sound3D Source with the specified audio file.
static Source[] generateSources(final int numSources)
Generates a set of uninitialized Source3D sources.
static Source generateSource(final Buffer buff)
Generate a Sound3D source from an initialized Buffer.
static Buffer loadBuffer(final String filename)
Loads a Sound3D buffer with the specified audio file.
static boolean releaseContext(final Context context, final boolean throwException)
Releases control of this audio context from the current thread, if implementation utilizes context lo...
static boolean checkError(final Device device, final String prefix, final boolean verbose, final boolean throwException)
Returns true if an OpenAL ALC or AL error occurred, otherwise false.
static boolean checkALCError(final Device device, final String prefix, final boolean verbose, final boolean throwException)
Returns true if an OpenAL ALC error occurred, otherwise false.
static Device openDevice(final String deviceName)
Opens the named audio device.
static final AL getAL()
Return OpenAL global AL.
static boolean makeContextCurrent(final Context context, final boolean throwException)
Makes the audio context current on the calling thread.
static void init()
Initialize the Sound3D environment.
static boolean checkALError(final String prefix, final boolean verbose, final boolean throwException)
Returns true if an OpenAL AL error occurred, otherwise false.
static Buffer[] generateBuffers(final int numBuffers)
Generate an array of Sound3D buffers.
static Context createContext(final Device device)
Creates a new Sound3D Context for a specified device including native ALCcontext creation.
static boolean isAvailable()
Returns the available state of this instance.
static final ALExt getALExt()
Return OpenAL global ALExt.
static Source loadSource(final InputStream stream)
Loads a Sound3D Source with the specified audio stream.
static Context getCurrentContext()
Returns this thread current context.
static Context createContext(final Device device, final int[] attributes)
Creates a new Sound3D Context for a specified device including native ALCcontext creation.
The Sound3D Buffer is a container for audio data used in the Sound3D environment.
void configure(final ByteBuffer data, final int alFormat, final int freq)
Configure the Sound3D buffer.
This class provides a Sound3D Context associated with a specified device.
boolean release(final boolean throwException)
Releases control of this audio context from the current thread, if implementation utilizes context lo...
boolean makeCurrent(final boolean throwException)
Makes the audio context current on the calling thread.
static Context getCurrentContext()
Returns this thread current context.
This class provides a handle to a specific audio device.
ALCdevice getALDevice()
Returns the OpenAL ALCdevice.
This class represents the human listener in the Sound3D environment.
This class is used to represent sound-producing objects in the Sound3D environment.
void setBuffer(final Buffer buffer)
Associates the buffer with this source if buffer is not null, otherwise disassociates the previously ...
This class is a holder for WAV (.wav ) file Data returned from the WavLoader, or directly via loadFro...
final int format
the format of the Data.
final ByteBuffer data
The audio data.
final int freq
The frequency of the data.
A Loader utility for (.wav) files.
static WAVData loadFromStream(final InputStream stream)
This method loads a (.wav) file into a WAVData object.
static WAVData loadFromFile(final String filename)
This method loads a (.wav) file into a WAVData object.
static final int ALC_NO_ERROR
Define "ALC_NO_ERROR" with expression '0', CType: int.
int alcGetError(ALCdevice device)
Entry point (through function pointer) to C language function: ALCenum alcGetError(ALCdevice * dev...
String alcGetString(ALCdevice device, int param)
Entry point (through function pointer) to C language function: const ALCchar * alcGetString(ALCdevi...
static final int AL_NO_ERROR
Define "AL_NO_ERROR" with expression '0', CType: int.
int alGetError()
Entry point (through function pointer) to C language function: ALenum alGetError()
void alGenBuffers(int n, IntBuffer buffers)
Entry point (through function pointer) to C language function: void alGenBuffers(ALsizei n,...
void alGenSources(int n, IntBuffer sources)
Entry point (through function pointer) to C language function: void alGenSources(ALsizei n,...
String alGetString(int param)
Entry point (through function pointer) to C language function: const ALchar * alGetString(ALenum pa...