2021-05-18 12:31:49

I'm new to open al, And I have problems understanding the positioning stuff,
whenever I say openal I mean soft openal.
the orientation (top, front), and the velocity.
I know how to set them though don't know what do they mean and how they work.
I previously was using bgt and sam's 3d sound pool to play audio in a 3d environment, and to change the listeners direction I would only need to have a direction in angle. But stuffffs seems more complicated in openal and even other 3d audio libraries.
I don't like bgt anymore and want to code in some other languages like C++, or C#.
I think calculating the orientation and velocity requires some math, that I have never been into that.
I also searched a lot about this thing and tested the result on another audio library called bass, and never understood how to set the orientation of the listener with some vectors.
I think the velocity is a diffrent thing, but that would be cool to learn that too, the audio will be more realistic.
another question, about the hrtf in openal.
how to fource the library to use hrtf? and how to tell the library whitch hrtf settings (file) to use?
i'm using C++
thank you

2021-05-18 17:25:10 (edited by kianoosh 2021-05-18 17:29:25)

Hi. So first a heads up. Here's how vectors work in openal. Positive x is right, positive y is up and negative z is forward. Listener location is obviously where the listener is standing in the game world. Orientation actually defines what direction the listener is facing. With these aside, here's how setting of the orientation works in openal. Your first vector, which is the "front" vector is to be assumed like the tip of a line that's pointing to the front of you and the base of it is right between your eyebrows. So based on what I mentioned above, if you face north, the front vector should be 0, 0, -1. If you face east the front vector would be 1, 0, 0. If you face north-east, the front vector would be 1, 0, -1. So you should have graspped the theory of the way the front vector works by now, so let's move on to the "up" vector. This is the tip of a line that comes right out of the very top of your head and points upward. Again based on openal's coordinate system, the up vector is usually 0, 1, 0, Unless you allow the player to change their pitch or the z_angle as some people call it. Now here's how you convert direction angles, assuming that they are in degrees.
The front vector would look something like this:
(sine(radians(direction)), 0, -cosine(radians(direction)))
This is a simple way of doing it, you get the idea. You might need to round the calculations above to 2 decimles.

---
Co-founder of Sonorous Arts.
Check out Sonorous Arts on github: https://github.com/sonorous-arts/
my Discord: kianoosh.shakeri2#2988

2021-05-19 05:54:35

You might want to consider reading the [OpenAL Documentation], which might be helpful for a few things. As for HRTF, there's a few texts and documents floating around about OpenAL Softs handling of that, but you could try checking out my python OpenAL wrapper [PyLite], specifically the handler classes. The Listener class is written to handle HRTF using C calls which might give you an idea on how to do it.

In order to use HRTF though you need HRTF tables, such tables are included with PyLite, and you can also find links included where to get others. It also shows how to check available tables, how to set them, etc. For example:

    #get list of available htrf tables
        self.hrtf_buffers = [alc.ALCint(),alc.ALCint*4,alc.ALCint()]
        alc.alcGetIntegerv(self.device,alc.ALC_NUM_HRTF_SPECIFIERS_SOFT, 1,self.hrtf_buffers[0])
    #attributes for device to set specified hrtf table
        self.hrtf_select = self.hrtf_buffers[1](alc.ALC_HRTF_SOFT,alc.ALC_TRUE,alc.ALC_HRTF_ID_SOFT,1)

...

#list number of available hrtf tables
    def _hrtf_tables(self):
        return self.hrtf_buffers[0].value

#assign hrtf table to device and soft reboot to take effect
    def _set_hrtf(self,num):
        if num == None:
            alc.alcResetDeviceSOFT(self.device, None)
        elif num >= 0 and num <= self.hrtf_buffers[0].value:
            self.hrtf_select[3] = num
        #reset the device so the new hrtf settings take effect
            alc.alcResetDeviceSOFT(self.device, self.hrtf_select)

#confirm hrtf has been loaded and is enabled
    def _get_hrtf(self):
        alc.alcGetIntegerv(self.device,alc.ALC_HRTF_SOFT,1,self.hrtf_buffers[2])
        if self.hrtf_buffers[2].value == alc.ALC_HRTF_DISABLED_SOFT:
            return False
        elif self.hrtf_buffers[2].value == alc.ALC_HRTF_ENABLED_SOFT:
            return True
        elif self.hrtf_buffers[2].value == alc.ALC_HRTF_DENIED_SOFT:
            return False
        elif self.hrtf_buffers[2].value == alc.ALC_HRTF_REQUIRED_SOFT:
            return True
        elif self.hrtf_buffers[2].value == alc.ALC_HRTF_HEADPHONES_DETECTED_SOFT:
            return True
        elif self.hrtf_buffers[2].value == alc.ALC_HRTF_UNSUPPORTED_FORMAT_SOFT:
            return False

Hope that helps.

-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

2021-05-19 11:24:53

@2
Are calculations same for the bass library?

Thank you both, helped me alot.

2021-05-19 17:38:46

I think bass uses another coordinate system so no. Although I can't say much about bass's 3d sound handling with certainty as I usually worked with manual pan handling and stuff so I don't have much experience with bass's sound 3d system. Look up bass's documentation in google, I know there's one provided by the official development team.

---
Co-founder of Sonorous Arts.
Check out Sonorous Arts on github: https://github.com/sonorous-arts/
my Discord: kianoosh.shakeri2#2988

2021-05-19 18:01:37

ok so the trick with this for what most audiogames need is to set the up vector to (0, 0, 1) or (0, 0, -1) depending on whether the library is left or right handed, then shove the way the player is facing into the x and y of the at vector and leave z at 0.  you need (0, 0, 1) for Synthizer, OpenAL, etc. which are right-handed coordinate systems, and (0, 0, -1) for DirectX and other left-handed coordinate systems. The Bass documentation should tell you which it is.  if you do this then positive x is east and positive y is north which is what everyone wants in the end.

My Blog
Twitter: @ajhicks1992