Capturing and alcCaptureOpenDevice

I have tried to use capturing with this code:


        ALut.alutInit();
        AL al = ALFactory.getAL();
        ALC alc = ALFactory.getALC();

        int size = 4010;
        byte[] buffer = new byte[size];

        ALCdevice device =
                alc.alcCaptureOpenDevice(buffer, 22050, AL.AL_FORMAT_MONO16, size, 0);

        int error = alc.alcGetError(device);

        System.out.println("Error ?:  " + alc.alcGetString(null, alc.alcGetError(device)));

        .....


But I got a Invalid Device Error. The question is whether the parameters for the mehtod alcCaptureOpenDevice are correct. There is no way to define a device in this method. In the OpenAL 1.1 Spec parameters looks like this:

ALCdevice* alcCaptureOpenDevice(const ALCchar *deviceName, ALCuint freq, ALCenum fmt, ALCsizei bufsize);

and in JOAL:

alcCaptureOpenDevice(byte[], int0, int1, int2, int3) (a parameter for deviceName is missing)

What should I do to get this work? I hope its not a bug…

The first parameter of alcCaptureOpenDevice, is the device name. JOAL provides 2 variants:

ALCdevice alcCaptureOpenDevice(byte[] devicename, int devicename_offset, int frequency, int format, int buffersize)
ALCdevice alcCaptureOpenDevice(ByteBuffer devicename, int frequency, int format, int buffersize)

According to the OpenAL 1.1 programmers guide, the byte[] or ByteBuffer is actually a device name String. (it’s normally ALCchar*, but char* gets converted to byte[] and ByteBuffer). I think you’ll have to get the device name, convert it to the character bytes, but be sure that you convert to 8-bit characters, not the default 16-bit unicode characters of Java (there are methods in the Java API to do this).

Thx Ultraq for your reply. Well, I have changed my code:

    .....
    int size = 10000;
    byte[] buffer = new byte[size];
    
    ByteBuffer b = ByteBuffer.wrap(alc.alcGetString(null, ALC.ALC_CAPTURE_DEVICE_SPECIFIER);  // SB Audigy Adio [FF80]

    ALCdevice device = alc.alcCaptureOpenDevice(b, 22050, al.AL_FORMAT_MONO16, size);

    .....

But it does not work. I get the same error: “Invalid Device”. Do I anything wrong? Any ideas?

The bytes in the ByteBuffer, are they representing 16-bit character strings (can check by looking at every alternating byte and seeing if it’s 0x00)? Since the OpenAL function requires an ALCchar (8-bit characters), you’ll need to do some conversion. Unfortunately, I don’t have an IDE set up where I am right now, but my guess is you’ll have to do something like this:

String deviceString16 = alc.alcGetString(null, ALC_CAPTURE_DEVICE_SPECIFIER);
byte[] deviceChars8 = device16.getBytes(“US_ASCII”);

ALCdevice device = alc.alcCaptureOpenDevice(deviceChars8, 22050, AL_FORMAT_MONO16, size);

[EDIT]: Looking at the public API of JOAL, there’s also an ALC.alcgetStringImpl() which returns a ByteBuffer. Maybe that retains the 8-bit characters for you, which you can feed into alcCaptureOpenDevice(ByteBuffer, …) ?