OpenAL 2d panning C++

2019-06-06 04:14发布

问题:

I'm trying to figure out how to get openAL to pan in 2D (by manipulating the 3D positioning). Ideally I want to achieve panning such that the Left or Right channel can be fully engaged with the other channel completely silent. It seems that Open AL handles 3d distances and falloffs nicely, but I'm struggling to emulate this kind of 2D panning.

I'm using

alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED)

float sourcePosition[3] = {0.99f,0.f,0.f};
alSourcefv(sourceID, AL_POSITION, sourcePosition);
alSourcei(sourceID, AL_SOURCE_RELATIVE, AL_FALSE);
alSourcef(sourceID, AL_MAX_DISTANCE, 1.f);
alSourcef(sourceID, AL_REFERENCE_DISTANCE, 0.5f);

However there is a substantial amount of audio in the right channel. I don't really want gain to drop off based on distance, just proportion the channels.

Is it possible to emulate 2d panning with open AL?

回答1:

You'll want to set AL_SOURCE_RELATIVE to AL_TRUE, rather than false.

AL_SOURCE_RELATIVE set to AL_TRUE indicates that the position, velocity, cone, and direction properties of a source are to be interpreted relative to the listener position.

So says the OpenAL 1.1 Specification (page 34)!

So, changing

alSourcei(sourceID, AL_SOURCE_RELATIVE, AL_FALSE);

to

alSourcei(sourceID, AL_SOURCE_RELATIVE, AL_TRUE);

should achieve the desired result.