Hello Guest

[SOLVED] OpenAl HRTF

  • 10 Replies
  • 24203 Views
[SOLVED] OpenAl HRTF
« on: March 02, 2016, 00:29:03 »
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
« Last Edit: March 08, 2016, 19:55:47 by Dikill »

*

Offline spasi

  • *****
  • 2261
    • WebHotelier
Re: OpenAl HRTF
« Reply #1 on: March 02, 2016, 00:55:02 »
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.

Re: OpenAl HRTF
« Reply #2 on: March 02, 2016, 19:59:34 »
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:
Code: [Select]
AlDevice.create(ALDevice.create, 44100, 60, false);but I'm not sure it worked :s

*

Offline spasi

  • *****
  • 2261
    • WebHotelier
Re: OpenAl HRTF
« Reply #3 on: March 02, 2016, 20:20:00 »
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.

Re: OpenAl HRTF
« Reply #4 on: March 02, 2016, 22:43:21 »
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


Code: [Select]
      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

Quote
OpenALC10: 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

*

Offline spasi

  • *****
  • 2261
    • WebHotelier
Re: OpenAl HRTF
« Reply #5 on: March 02, 2016, 23:57:03 »
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.

Re: OpenAl HRTF
« Reply #6 on: March 08, 2016, 19:54:32 »
Problem Solved, Thank you !!!  ;D

Re: [SOLVED] OpenAl HRTF
« Reply #7 on: July 03, 2016, 16:12:53 »
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

Re: [SOLVED] OpenAl HRTF
« Reply #8 on: July 03, 2016, 17:08:54 »
"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
« Last Edit: July 03, 2016, 17:17:48 by Kai »

*

Offline spasi

  • *****
  • 2261
    • WebHotelier
Re: [SOLVED] OpenAl HRTF
« Reply #9 on: July 04, 2016, 13:12:28 »
I have added an HRTF demo to the LWJGL repository.

Re: [SOLVED] OpenAl HRTF
« Reply #10 on: July 04, 2016, 21:38:25 »
Oh I see. Thank you very much, managed to get it working now!

Apologies for my ignorance.  ;D