[Openal-devel] fix alf_panning

Prakash Punnoor prakash at punnoor.de
Sat Apr 21 01:27:26 PDT 2007


HI,

the current panning in the SI is obviously wrong:

void alf_panning( ALuint cid,
                 AL_source *src,
                 UNUSED(AL_buffer *samp),
                 UNUSED(ALshort **buffers),
                 ALuint nc,
                 UNUSED(ALuint len) )
{
	ALfloat lp[3]; /* listener position */
	ALfloat *sp; /* source position */
	ALfloat *sd; /* speaker position */
	ALfloat m;
	ALfloat sa;
	ALuint i;

	alGetListenerfv(AL_POSITION, lp);
	sp = _alGetSourceParam(src, AL_POSITION );

	if ((sp == NULL) || (lp == NULL)) {
		return;
	}

	m = _alVectorMagnitude(lp, sp);
	if (m == 0) {
		/* should this use epsilon? */
		return;
	}
	for (i = 0; i < nc; i++) {
		sd = _alcGetSpeakerPosition(cid, i);
		sa = _alVectorDotp(lp, sp, sd) / m;
		sa += 1.0;

		src->srcParams.gain[i] *= sa;
	}
}


It just scales the volume linearily. Even with my limited dsp knowlegdes I 
know that if the source is between two speakers, it should not be scaled to 
0.5 but to 0.707.

So I think this would fix it in the stereo case. I got the idea from the 
windows implementation:

        for (i = 0; i < nc; i++) {
                sd = _alcGetSpeakerPosition(cid, i);
                sa = _alVectorDotp(lp, sp, sd) / m;
                sa += 1.0;
+               sa *= 0.5f;
+               sa = sqrt(sa);

                src->srcParams.gain[i] *= sa;
        }

Is this correct?

What about 4ch case?

Cheers,
-- 
(°=                 =°)
//\ Prakash Punnoor /\\
V_/                 \_V
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://opensource.creative.com/pipermail/openal-devel/attachments/20070421/c84c940b/attachment.bin


More information about the Openal-devel mailing list