[openal] Can I use effect functions without using macros?

Chris Robinson chris.kcat at gmail.com
Thu Jan 28 09:23:01 EST 2021


On Thu, 28 Jan 2021 13:11:39 +0300
Sean <s.tolstoyevski at gmail.com> wrote:

> For example, in the alext.h file there is such a code:
> 
> The alcGetStringiSOFT function takes 3 parameters.
> 
> [...]
> 
> But a few lines below there is another definition:
> 
> 2 parameters.

Those are two different functions. alcGetStringiSOFT (alc) and
alGetStringiSOFT (al). The alc function takes a device handle and
queries device-related strings, while the al function uses the current
context and queries context-related strings.

To clarify, since it's a little difficult to follow what you're asking,
the lines with `#define ...` are what "defines macros". Lines with
`tyoedef ...` define typedefs a.k.a. type aliases, and lines like

AL_API const ALchar* AL_APIENTRY alGetStringiSOFT(ALenum pname, ALsizei index);

declare functions. The lines like

static LPALCGETSTRINGISOFT alcGetStringiSOFT;

define function pointers, and lines like

LOAD_PROC(device, LPALCGETSTRINGISOFT, alcGetStringiSOFT);

use a previously-defined "function-like macro" (to load the function
pointer, in that case).

So yes, you're defining the macros, typedefs, and function pointers
fine. I don't know where your "initMacros" function is called, but it
looks mostly fine as long as 1) it's called after making a context
current (with alcMakeContextCurrent), and 2) it's not using the router
DLL on Windows. The one thing I'd change is to check that the relevant
extensions are supported before trying to load their function pointers.
e.g.

if(alcIsExtensionSupported(device, "ALC_EXT_EFX"))
{
    LOAD_PROC(LPALGENFILTERS, alGenFilters);
    LOAD_PROC(LPALDELETEFILTERS, alDeleteFilters);
    LOAD_PROC(LPALISFILTER, alIsFilter);
    ...
}

...

if(alcIsExtensionSupported(device, "ALC_SOFT_HRTF"))
{
    LOAD_PROC(device, LPALCGETSTRINGISOFT, alcGetStringiSOFT);
    LOAD_PROC(device, LPALCRESETDEVICESOFT, alcResetDeviceSOFT);
}

And so-on for any extensions your wrapper recognizes.


More information about the openal mailing list