JOAL v2.6.0-rc-20250706
JOAL, OpenAL® API Binding for Java™ (public API).
Device.java
Go to the documentation of this file.
1/**
2* Copyright (c) 2010-2023 JogAmp Community. All rights reserved.
3* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7*
8* -Redistribution of source code must retain the above copyright notice,
9* this list of conditions and the following disclaimer.
10*
11* -Redistribution in binary form must reproduce the above copyright notice,
12* this list of conditions and the following disclaimer in the documentation
13* and/or other materials provided with the distribution.
14*
15* Neither the name of Sun Microsystems, Inc. or the names of contributors may
16* be used to endorse or promote products derived from this software without
17* specific prior written permission.
18*
19* This software is provided "AS IS," without a warranty of any kind.
20* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
21* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
22* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS
23* LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A
24* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
25* IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT
26* OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
27* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
28* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS
29* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
30*
31* You acknowledge that this software is not designed or intended for use in the
32* design, construction, operation or maintenance of any nuclear facility.
33*/
34
35package com.jogamp.openal.sound3d;
36
37import com.jogamp.openal.*;
38import com.jogamp.openal.util.ALHelpers;
39
40
41/**
42 * This class provides a handle to a specific audio device.
43 *
44 * @author Athomas Goldberg, Sven Gothel, et al.
45 */
46public final class Device {
47 private String name;
48 private ALCdevice alDev;
49
50 /**
51 * Create a new device by {@link #open()}'ing the named audio device.
52 *
53 * @param deviceName The specified device name, null for default.
54 */
55 public Device(final String deviceName) {
56 this.name = deviceName;
57 this.alDev = null;
58 open();
59 }
60
61 /** Returns the device name. */
62 public String getName() { return name; }
63
64 /** Returns the OpenAL {@link ALCdevice}. */
65 public ALCdevice getALDevice() { return alDev; }
66
67 /** Return {@link ALC#alcGetError(ALCdevice)} */
68 public int getALCError() {
69 return AudioSystem3D.alc.alcGetError(alDev);
70 }
71
72 /** Returns whether {@link #getALDevice()} is open and valid, i.e. not null, e.g. not {@link #close()}. */
73 public boolean isValid() { return null != alDev; }
74
75 /**
76 * Returns whether `ALC_EXT_debug` is available for this device.
77 * <p>
78 * This context may or may not be current.
79 * </p>
80 * @see Context#isDebugAvail()
81 */
82 public boolean isDebugAvail() {
84 }
85
86 /**
87 * Opens the device if not yet opened
88 * @return true if already open or newly opened
89 * @see #isValid()
90 * @see #clone()
91 */
92 public boolean open() {
93 if( null == alDev ) {
94 alDev = AudioSystem3D.alc.alcOpenDevice(name);
95 if( null != alDev && null == name ) {
97 }
98 }
99 return isValid();
100 }
101
102 /**
103 * closes the device, freeing its resources.
104 */
105 public void close() {
106 if( null != alDev ) {
107 AudioSystem3D.alc.alcCloseDevice(alDev);
108 alDev = null;
109 }
110 }
111
112 @Override
113 public String toString() {
114 final String alStr = null != alDev ? "0x"+Integer.toHexString(alDev.hashCode()) : "null";
115 return "ALDevice[this 0x"+Integer.toHexString(hashCode())+", name '"+name+"', alDev "+alStr+"]";
116 }
117
118}
The AudioSystem3D class provides a set of methods for creating and manipulating a 3D audio environmen...
This class provides a handle to a specific audio device.
Definition: Device.java:46
int getALCError()
Return ALC#alcGetError(ALCdevice).
Definition: Device.java:68
boolean isDebugAvail()
Returns whether ALC_EXT_debug is available for this device.
Definition: Device.java:82
String getName()
Returns the device name.
Definition: Device.java:62
void close()
closes the device, freeing its resources.
Definition: Device.java:105
ALCdevice getALDevice()
Returns the OpenAL ALCdevice.
Definition: Device.java:65
Device(final String deviceName)
Create a new device by open()'ing the named audio device.
Definition: Device.java:55
boolean open()
Opens the device if not yet opened.
Definition: Device.java:92
boolean isValid()
Returns whether getALDevice() is open and valid, i.e.
Definition: Device.java:73
static final String ALC_EXT_debug
Definition: ALHelpers.java:58
static final int ALC_DEVICE_SPECIFIER
Define "ALC_DEVICE_SPECIFIER" with expression '0x1005', 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...
boolean alcCloseDevice(ALCdevice device)
Entry point (through function pointer) to C language function: ALCboolean alcCloseDevice(ALCdevice ...
boolean alcIsExtensionPresent(ALCdevice device, String extname)
Entry point (through function pointer) to C language function: ALCboolean alcIsExtensionPresent(ALC...
ALCdevice alcOpenDevice(String devicename)
Entry point (through function pointer) to C language function: ALCdevice * alcOpenDevice(const ALCc...