[SOLVED] OpenAl HRTF

Started by Dikill, March 02, 2016, 00:29:03

Previous topic - Next topic

Dikill

Hi everybody !  :)

I'd like to know if the openal part of the library supports the HRTF tech (aka 3D binaural sound).
https://en.wikipedia.org/wiki/Head-related_transfer_function
I made some research on internet but I found contrary answers.  :-\
If it's included in openAl, is it enabled by default or do we have to make some manipulations to make it work.

Thanks a lot for helping

spasi

LWJGL includes OpenAL-Soft, which is a software OpenAL implementation with HRTF support. LWJGL also supports the ALC_SOFT_HRTF extension. There's information in there on how to request HRTF functionality.

OpenAL-Soft can also be configured with a config file, you can use the ALSOFT_CONF environment variable to point to it. Other useful environments variables, here.

Dikill

Thank you for the quick answer
I didn't find a way to enable it in my java code.
The 3.0.0a version of LWJGL contains a java file SOFTHRTF that is not in the last version (3.0.0b) and nothing in the doc seem to loke like HRTF.
How do I initialise the device and/or openAl context in java to have HRTF functioning ?

I tried:
AlDevice.create(ALDevice.create, 44100, 60, false);

but I'm not sure it worked :s

spasi

Support for ALC_SOFT_HRTF was added after the release of 3.0.0b. Please download the latest nightly build, it's there.

For OpenAL sample code, see these demos. To create a context with HRTF support, you must use the ALContext.create(ALDevice, IntBuffer) method. The attributes buffer must contain the values [ALC_HRTF_SOFT, ALC_TRUE, 0], as explained in the extension.

Dikill

I read the demo and tried to do the same
but when I ask for the state I got 0x5 which is ALC_HRTF_UNSUPPORTED_FORMAT_SOFT ...
Here's the code


      ALDevice device = ALDevice.create(null);
      if(device == null)
          throw new IllegalStateException("Failed to open device");
      
      ALCCapabilities caps = device.getCapabilities();


      System.out.println("OpenALC10: " + caps.OpenALC10);
      System.out.println("OpenALC11: " + caps.OpenALC11);
      System.out.println("caps.ALC_EXT_EFX = " + caps.ALC_EXT_EFX);
      
      if ( caps.OpenALC11 ) {
          List<String> devices = ALC.getStringList(NULL, ALC_ALL_DEVICES_SPECIFIER);
          if ( devices == null )
              ALUtil.checkALCError(null);
          else {
              for ( int i = 0; i < devices.size(); i++ )
                  System.out.println(i + ": " + devices.get(i));
          }
      }
      
      String defaultDeviceSpecifier = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);

      System.out.println("Default device: " + defaultDeviceSpecifier);
      
      IntBuffer buffer = (IntBuffer) BufferUtils.createIntBuffer(3).put(new int[]{HRTF.ALC_HRTF_SOFT, ALC10.ALC_TRUE, 0} ).rewind();
      context = ALContext.create(device, buffer);
      int response = alcGetInteger(device.address(), HRTF.ALC_HRTF_STATUS_SOFT);
      
      System.out.println(response == HRTF.ALC_HRTF_ENABLED_SOFT);
      System.out.println("HRTF STATE: 0x" + Integer.toHexString(response));
      System.out.println("Frequency :" + alcGetInteger(device.address(), ALC10.ALC_FREQUENCY));
      
      System.out.println(ALC10.alcGetString(context.getDevice().address(), HRTF.ALC_HRTF_SPECIFIER_SOFT));


And the result

QuoteOpenALC10: true
OpenALC11: true
caps.ALC_EXT_EFX = true
0: Casque (2- Périphérique High Definition Audio) on OpenAL Soft
1: Haut-parleurs (2- Périphérique High Definition Audio) on OpenAL Soft
Default device: OpenAL Soft
false
HRTF STATE: 0x5
Frequency :44100

spasi

OpenAL-Soft needs HRTF data for the extension to work. On Windows, by default OpenAL-Soft uses the %APPDATA% folder for this (download the binary distribution and see readme.txt for details). But you can easily override it with the ALSOFT_CONF environment variable:

- Download the sample config file, rename it (say alsoft.conf), put it with your app.
- Download the sample HRTFs, put them in a folder.
- Set the hrtf-paths property in the config file to the folder where you put the HRTFs.
- Set the ALSOFT_CONF environment variable to the config file path.

If you now query ALC_NUM_HRTF_SPECIFIERS_SOFT, before creating the context, it should return 2. Querying ALC_HRTF_SPECIFIER_SOFT with alcGetStringiSOFT, using indices 0 and 1, should return the two HRTFs. If you get to that point, HRTF should be enabled when you create the context with ALC_HRTF_SOFT set to ALC_TRUE.

Dikill

Problem Solved, Thank you !!!  ;D

CosmicNeanderthal

Hi guys,

I'm following you up until you mention setting the ALSOFT_CONF environment variable to the config file path. I can't seem to figure out how or where exactly to do this. I'm kind of lost here.

If someone could point me in the right direction I would really appreciate it.

Thanks.

Kai

"Environment variables" are an operating-system feature. Every operating system has its ways to set environment variables either via a system setting or/and as part of the command shell session. Use Google to find the way for your operating system.

The GitHub openal-soft link mentioned by Spasi's "Other useful environments variables, here." also updated:
- https://github.com/kcat/openal-soft/blob/master/docs/env-vars.txt

spasi

I have added an HRTF demo to the LWJGL repository.

CosmicNeanderthal

Oh I see. Thank you very much, managed to get it working now!

Apologies for my ignorance.  ;D