How playback audio data with several audio card's simultaneously uses LWJGL

I need to play audio data with several audio card’s simultaneously. For begin I don’t know how change audio device with method

AL.create(“DirectSound3D”, 44100, 15, false);

for use another audio card in PC. Maybe someone know how can realize this issue >:(

Using lwjgl3 I use this method to create a context

device=ALDevice.create(…);
context=ALContext.create(device);

You can therefore create multiple contexts on multiple devices

Thanks’s for answer.
You can show sample code how create multiple contexts on multiple devices and play audio data on 2 soundcard’s?
context=ALContext.create(device); device where i can see name of my device (for example second sound card)

Hi

looks like there is a bit more work!


            String deviceList = ALC10.alcGetString(sound.ALC_DEVICE_SPECIFIER);
            System.out.println("Device["+deviceList+"]");
            String captureDeviceList = sound.alcGetString(ALC11.ALC_CAPTURE_DEVICE_SPECIFIER);
            System.out.println("Capture Device["+captureDeviceList+"]");
            
            long device  = ALC10.alcOpenDevice(deviceList);
            long context = ALC10.alcCreateContext(device, null);           
            boolean success =  ALC10.alcMakeContextCurrent(context);
            System.out.println(success);

The device list and captureList are a null separated list, I only have 1 sound card so can’t test. Tell me how it goes.

This is my output

Device[OpenAL Soft]
Capture Device[Built-in Audio Analogue Stereo]
true

Ok, thank’s for help, will try today at work, with usb sound card :slight_smile: and reply to you

Sorry for long answer.
I have use’d some same code before, but have error. Your code i use like

    String deviceList = ALC10.alcGetString(null, ALC10.ALC_ALL_ATTRIBUTES);
    System.out.println("Device["+deviceList+"]");
    String captureDeviceList = ALC10.alcGetString(null, ALC11.ALC_CAPTURE_DEVICE_SPECIFIER);
    System.out.println("Capture Device["+captureDeviceList+"]");
    
    ALCdevice device  = ALC10.alcOpenDevice(deviceList);
    ALCcontext context = ALC10.alcCreateContext(device, null);           
    int success =  ALC10.alcMakeContextCurrent(context);
    System.out.println(success);

Have exception in thread “JavaFX Application Thread” WARN 2016-04-04 16:05:17,979 SystemErr - Exception in thread “JavaFX Application Thread”
WARN 2016-04-04 16:05:17,979 SystemErr - org.lwjgl.openal.OpenALException: Invalid Enum
WARN 2016-04-04 16:05:17,979 SystemErr - at org.lwjgl.openal.Util.checkALCError(Util.java:55)
WARN 2016-04-04 16:05:17,979 SystemErr - at org.lwjgl.openal.ALC10.alcGetString(ALC10.java:156)
in this line String deviceList = ALC10.alcGetString(null, ALC10.ALC_ALL_ATTRIBUTES);
what is sound variable in your code? (ALDevice sound = ALDevice.create():wink:
And ALC10.alcGetString() has two parameter’s, in your code only one, how it could be?

I believe I missed off a static reference when I posted my code, you can use

ALC10.ALC_DEVICE_SPECIFIER

instead of

sound.ALC_DEVICE_SPECIFIER

where as you use

ALC10.ALC_ALL_ATTRIBUTES

I beleive your code doesn’t work with getString.

I believe you are right.
Use your code like


String deviceList = ALC10.alcGetString(null,ALC10.ALC_DEVICE_SPECIFIER);
System.out.println("Device["+deviceList+"]");
String captureDeviceList = ALC10.alcGetString(null,ALC11.ALC_CAPTURE_DEVICE_SPECIFIER);
System.out.println("Capture Device["+captureDeviceList+"]");

but have Exception in thread “main” java.lang.UnsatisfiedLinkError: org.lwjgl.openal.ALC10.nalcGetString(JI)Ljava/nio/ByteBuffer;
Problem with alcGetString, as you said before
Try to enumerate audio device


System.out.println("Default device: " + ALC10.alcGetString(null, ALC10.ALC_DEVICE_SPECIFIER));
		if(ALC10.alcIsExtensionPresent(null, "ALC_ENUMERATION_EXT")) {
	  		String[] devices = ALC10.alcGetString(null, ALC10.ALC_DEVICE_SPECIFIER).split("\0");
		System.out.println("Available devices: ");
	  		for(int i=0; i<devices.length; i++) {
	  			System.out.println(i +": " + devices[i]);
	  		}
	  	}

result is:


Available devices:  INFO 2016-04-05 16:45:58,309    SystemOut - Available devices: 

0: OpenAL Soft INFO 2016-04-05 16:45:58,309    SystemOut - 0: OpenAL Soft

If use System.out.println("Default device: " + ALC10.alcGetString(null, ALC11.ALC_ALL_DEVICES_SPECIFIER)); insted System.out.println("Default device: " + ALC10.alcGetString(null, ALC10.ALC_DEVICE_SPECIFIER));
result is


Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.nio.charset.MalformedInputException: Input length = 1
	at org.lwjgl.MemoryUtil.decodeImpl(MemoryUtil.java:336)
	at org.lwjgl.MemoryUtil.decode(MemoryUtil.java:305)
	at org.lwjgl.MemoryUtil.decodeUTF8(MemoryUtil.java:294)
	at org.lwjgl.openal.ALC10.alcGetString(ALC10.java:157)

Test in condition when used 2 card’s (one sound usb). How to resolve this issue… ???

This code have exception too…


      String[] devices = ALC10.alcGetString(AL.getDevice(), ALC11.ALC_ALL_DEVICES_SPECIFIER).split("\0"); // -- in this line
		System.out.println("Available devices: ");
		for(int i=0; i<devices.length; i++) {
			System.out.println(i +": " + devices[i]);
		}


Exception in thread "main" java.lang.RuntimeException: java.nio.charset.MalformedInputException: Input length = 1
	at org.lwjgl.MemoryUtil.decodeImpl(MemoryUtil.java:336)
	at org.lwjgl.MemoryUtil.decode(MemoryUtil.java:305)
	at org.lwjgl.MemoryUtil.decodeUTF8(MemoryUtil.java:294)
	at org.lwjgl.openal.ALC10.alcGetString(ALC10.java:157)

@spasi

Is this exception caused by something LWJGL is doing?

@aurusd

If you don’t hear from spasi here you might want to post the exceptions in the LWJGL forums or on the github issues list.

The ALC_ALL_DEVICES_SPECIFIER query returns a null-terminated list of null-terminated strings, but the normal alcGetString can only handle a normal string. LWJGL provides the ALUtil.getStringList() method for this special case. The alcGetString javadoc mentions this.