Question

I've already asked this question on the OpenTK forums but there doesn't seem to be anyone able to respond. (http://www.opentk.com/node/3638)

In OpenTK, I'm trying to get a balance value of -1 to 1 converted to the left/right audio channels. When 0 (default value) both sides should be at 100% gain. When 1 100% for right and 0% for left and the opposite for -1. I'm having a hard time trying to get this to work in OAL seeing as this is actually my first time working with it.

So far I've tried: After OAL initialization:

AL.DistanceModel(ALDistanceModel.LinearDistanceClamped);

For each new source:

AL.Source(SourceId, ALSourcef.MaxDistance, 1f);
AL.Source(SourceId, ALSourceb.SourceRelative, false);

For setting the balance:

float balance = 0f; //(-1f to 1f)
OpenTK.Vector3 position = new OpenTK.Vector3(balance, 0f, 0f);
AL.Source(SourceId, ALSource3f.Position, ref position);

This will make the audio go just above 100% on the left channel and 0% on the right for all negative values of balance and just above 100% right 0% left for all positive values, so I'm kinda stuck.

How should I go about doing this? Any help is appreciated!

Gr.Viller

BTW: This looks like a near-duplicate of the unanswered OpenAL 2d panning C++.

Was it helpful?

Solution

Using the OpenAL Soft mailing list I've got the answer I needed:

In FNA we do something like this, but it's probably not ideal (if not just incorrect):

https://github.com/flibitijibibo/MonoGame/blob/monogame-sdl2/MonoGame.Framework/Audio/SoundEffectInstance.cs#L58

I know for sure that this doesn't provide hard panning, but you probably didn't really want to do hard pans anyway. We do that work to keep things at the 1.0f distance, but if attenuation isn't required for your project, you can turn that off and possibly save some time/effort:

https://github.com/flibitijibibo/MonoGame/blob/monogame-sdl2/MonoGame.Framework/Audio/OpenALDevice.cs#L102

-Ethan

TL;DR: Disable the distance system with:

AL.DistanceModel(ALDistanceModel.None);

Then set the balance like this:

AL.Source(SourceId, ALSource3f.Position, balance, 0f, (float)Math.Sqrt(1 - Math.Pow(balance, 2)));

Basically creating a half-circle on the Z-axis to always keep the same distance from the listener while shifting the direction to the audio.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top