1package com.jogamp.openal.test.manual;
3import com.jogamp.openal.*;
4import com.jogamp.openal.util.ALHelpers;
6import java.io.IOException;
7import java.time.Duration;
9import java.util.concurrent.ExecutorService;
10import java.util.concurrent.Executors;
12import static com.jogamp.openal.ALCConstants.*;
13import static com.jogamp.openal.ALConstants.AL_FORMAT_MONO8;
14import static com.jogamp.openal.ALExtConstants.*;
31 public static void main(
final String[] args)
throws IOException, InterruptedException {
40 System.err.println(jv.
toString(alc));
41 System.err.println(
"-----------------------------------------------------------------------------------------------------");
44 final ExecutorService executorService = Executors.newSingleThreadExecutor();
48 final boolean noEnumerateExt = !enumerationExtIsPresent && !enumerateAllExtIsPresent;
50 final Map<ALCdevice, ALCDeviceMetadata> playbackDeviceNameEnumerationExt =
new HashMap<>();
51 final Map<ALCdevice, ALCDeviceMetadata> captureDeviceNameEnumerationExt =
new HashMap<>();
53 if (enumerationExtIsPresent) {
56 String deviceName = alc.
alcGetString(device, ALC_DEVICE_SPECIFIER);
57 playbackDeviceNameEnumerationExt.put(device,
new ALCDeviceMetadata(deviceIdentifier, deviceName));
61 String deviceName = alc.
alcGetString(device, ALC_CAPTURE_DEVICE_SPECIFIER);
62 captureDeviceNameEnumerationExt.put(device,
new ALCDeviceMetadata(deviceIdentifier, deviceName));
66 final Map<ALCdevice, ALCDeviceMetadata> playbackDeviceNameEnumerateAllExt =
new HashMap<>();
68 if (enumerateAllExtIsPresent) {
72 playbackDeviceNameEnumerateAllExt.put(device,
new ALCDeviceMetadata(deviceIdentifier, deviceName));
77 System.err.println(
"Event[eventType: "+Integer.toHexString(eventType)+
78 ", deviceType: "+Integer.toHexString(deviceType)+
", device: "+device+
", message: "+message+
79 ", userParam: "+userParam+
"]");
81 case ALC_EVENT_TYPE_DEFAULT_DEVICE_CHANGED_SOFT: {
83 case ALC_PLAYBACK_DEVICE_SOFT: {
84 executorService.submit(() -> {
85 System.err.println(
"Default playback device are changed");
86 if (enumerateAllExtIsPresent) {
87 System.err.println(
"New default playback device name (With "+
89 alc.
alcGetString(
null, ALC_DEFAULT_ALL_DEVICES_SPECIFIER)
92 if (enumerationExtIsPresent) {
93 System.err.println(
"New default playback device name (With "+
99 System.err.println(
"Unable to retrieve default playback device name ("+
107 case ALC_CAPTURE_DEVICE_SOFT: {
108 executorService.submit(() -> {
109 System.err.println(
"Default capture device are changed");
110 if (enumerationExtIsPresent) {
111 System.err.println(
"New default capture device name: "+
112 alc.
alcGetString(
null, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER)
115 System.err.println(
"Unable to retrieve default capture device name ("+
124 case ALC_EVENT_TYPE_DEVICE_ADDED_SOFT: {
125 switch (deviceType) {
126 case ALC_PLAYBACK_DEVICE_SOFT: {
127 executorService.submit(() -> {
128 System.err.println(
"Playback device are added");
129 if (enumerateAllExtIsPresent) {
131 if (playbackDeviceNameEnumerateAllExt.values().stream()
132 .map(m -> m.deviceName.equals(deviceIdentifier))
139 System.err.println(
"New playback device name (With "+
143 playbackDeviceNameEnumerateAllExt.put(currentDevice,
new ALCDeviceMetadata(deviceIdentifier, deviceName));
146 if (enumerationExtIsPresent) {
148 if (playbackDeviceNameEnumerationExt.values().stream()
149 .map(m -> m.deviceName.equals(deviceIdentifier))
155 final String deviceName = alc.
alcGetString(currentDevice, ALC_DEVICE_SPECIFIER);
156 System.err.println(
"New playback device name (With "+
160 playbackDeviceNameEnumerationExt.put(currentDevice,
new ALCDeviceMetadata(deviceIdentifier, deviceName));
163 if (noEnumerateExt) {
164 System.err.println(
"Unable to retrieve new playback device name ("+
172 case ALC_CAPTURE_DEVICE_SOFT: {
173 executorService.submit(() -> {
174 System.err.println(
"Capture device are added");
175 if (enumerationExtIsPresent) {
177 if (captureDeviceNameEnumerationExt.values().stream()
178 .map(m -> m.deviceName.equals(deviceIdentifier))
184 final String deviceName = alc.
alcGetString(currentDevice, ALC_CAPTURE_DEVICE_SPECIFIER);
185 System.err.println(
"New capture device name (With "+
189 captureDeviceNameEnumerationExt.put(currentDevice,
new ALCDeviceMetadata(deviceIdentifier, deviceName));
192 System.err.println(
"Unable to retrieve new capture device name ("+
201 case ALC_EVENT_TYPE_DEVICE_REMOVED_SOFT: {
202 switch (deviceType) {
203 case ALC_PLAYBACK_DEVICE_SOFT: {
204 executorService.submit(() -> {
205 System.err.println(
"Playback device are removed");
206 if (enumerateAllExtIsPresent) {
208 final List<ALCdevice> devicesToRemove =
new ArrayList<>();
210 if (!devicesNames.contains(deviceEntry.getValue().deviceIdentifier))
continue;
212 System.err.println(
"Removed playback device name (With "+
214 deviceEntry.getValue().deviceName
216 devicesToRemove.add(deviceEntry.getKey());
218 devicesToRemove.forEach(d -> {
220 playbackDeviceNameEnumerateAllExt.remove(d);
223 if (enumerationExtIsPresent) {
225 final List<ALCdevice> devicesToRemove =
new ArrayList<>();
227 if (!devicesNames.contains(deviceEntry.getValue().deviceIdentifier))
continue;
229 System.err.println(
"Removed playback device name (With "+
231 deviceEntry.getValue().deviceName
233 devicesToRemove.add(deviceEntry.getKey());
235 devicesToRemove.forEach(d -> {
237 playbackDeviceNameEnumerationExt.remove(d);
240 if (noEnumerateExt) {
241 System.err.println(
"Unable to retrieve new playback device name ("+
249 case ALC_CAPTURE_DEVICE_SOFT: {
250 executorService.submit(() -> {
251 System.err.println(
"Capture device are removed");
252 if (enumerationExtIsPresent) {
254 final List<ALCdevice> devicesToRemove =
new ArrayList<>();
256 if (!devicesNames.contains(deviceEntry.getValue().deviceIdentifier))
continue;
258 System.err.println(
"Removed capture device name (With "+
260 deviceEntry.getValue().deviceName
262 devicesToRemove.add(deviceEntry.getKey());
264 devicesToRemove.forEach(d -> {
266 captureDeviceNameEnumerationExt.remove(d);
269 System.err.println(
"Unable to retrieve new capture device name ("+
282 ALC_EVENT_TYPE_DEFAULT_DEVICE_CHANGED_SOFT,
283 ALC_EVENT_TYPE_DEVICE_ADDED_SOFT,
284 ALC_EVENT_TYPE_DEVICE_REMOVED_SOFT
288 Thread.sleep(Duration.ofMinutes(2).toMillis());
290 executorService.shutdown();
293 ALC_EVENT_TYPE_DEFAULT_DEVICE_CHANGED_SOFT,
294 ALC_EVENT_TYPE_DEVICE_ADDED_SOFT,
295 ALC_EVENT_TYPE_DEVICE_REMOVED_SOFT
299 if (enumerationExtIsPresent) {
300 for (
final ALCdevice device : playbackDeviceNameEnumerationExt.keySet()) {
303 for (
final ALCdevice device : captureDeviceNameEnumerationExt.keySet()) {
308 if (enumerateAllExtIsPresent) {
309 for (
final ALCdevice device : playbackDeviceNameEnumerateAllExt.keySet()) {
This class provides factory methods for generating AL and ALC objects.
static ALExt getALExt()
Get the default ALExt object.
static ALC getALC()
Get the default ALC object.
static JoalVersion getInstance()
StringBuilder toString(final ALC alc, StringBuilder sb)
Return JogampVersion package information and AL informal strings.
Testing the OpenAL-Soft System Event Extension.
static void main(final String[] args)
static final String ALC_ENUMERATION_EXT
static final String ALC_ENUMERATE_ALL_EXT
static final String ALC_SOFT_system_events
static final int ALC_ALL_DEVICES_SPECIFIER
Define "ALC_ALL_DEVICES_SPECIFIER" with expression '0x1013', CType: int.
boolean alcEnumerationExtIsPresent()
Specify if ALC_ENUMERATION_EXT is present.
boolean alcEnumerateAllExtIsPresent()
Specify if ALC_ENUMERATE_ALL_EXT is present.
java.lang.String[] alcGetAllDeviceSpecifiers()
Fetches the names of the available ALC all capture device specifiers.
String alcGetString(ALCdevice device, int param)
Entry point (through function pointer) to C language function: const ALCchar * alcGetString(ALCdevi...
java.lang.String[] alcGetDeviceSpecifiers()
Fetches the names of the available ALC device specifiers.
boolean alcCloseDevice(ALCdevice device)
Entry point (through function pointer) to C language function: ALCboolean alcCloseDevice(ALCdevice ...
ALCdevice alcCaptureOpenDevice(String devicename, int frequency, int format, int buffersize)
Entry point (through function pointer) to C language function: ALCdevice * alcCaptureOpenDevice(con...
java.lang.String[] alcGetCaptureDeviceSpecifiers()
Fetches the names of the available ALC capture device specifiers.
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...
boolean alcCaptureCloseDevice(ALCdevice device)
Entry point (through function pointer) to C language function: ALCboolean alcCaptureCloseDevice(ALC...
JavaCallback interface: ALCEVENTPROCTYPESOFT -> void (*ALCEVENTPROCTYPESOFT)(ALCenum eventType,...
boolean alcEventControlSOFT(int count, IntBuffer events, boolean enable)
Entry point (through function pointer) to C language function: ALCboolean alcEventControlSOFT(ALCsi...
void alcEventCallbackSOFT(ALCEVENTPROCTYPESOFT callback, Object userParam)
Entry point (through function pointer) to C language function: void alcEventCallbackSOFT(ALCEVENTPR...