From 5438df173e543d0ae78c90b2f03cf6daababbf3d Mon Sep 17 00:00:00 2001 From: Rok Mandeljc Date: Tue, 14 Jan 2003 19:31:08 +0000 Subject: [PATCH] Added cone support. --- dlls/dsound/sound3d.c | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/dlls/dsound/sound3d.c b/dlls/dsound/sound3d.c index e6f837c8b3b..1407016222a 100644 --- a/dlls/dsound/sound3d.c +++ b/dlls/dsound/sound3d.c @@ -165,7 +165,12 @@ static void WINAPI DSOUND_Mix3DBuffer(IDirectSound3DBufferImpl *ds3db) /* stuff for distance related stuff calc. */ D3DVECTOR vDistance; D3DVALUE fDistance; - + + /* stuff for cone angle calc. */ + DWORD dwAlpha, dwTheta, dwInsideConeAngle, dwOutsideConeAngle; + D3DVECTOR vConeOrientation; + DWORD dwConstVolAng; /* Volume/Angle constant */ + if (ds3db->dsb->dsound->listener == NULL) return; @@ -203,12 +208,43 @@ static void WINAPI DSOUND_Mix3DBuffer(IDirectSound3DBufferImpl *ds3db) ...hope it works */ iPower = fDistance/ds3db->ds3db.flMinDistance - 1; /* this sucks, but for unknown reason damn thing works only if you reduce it for 1 */ lAttuneation = (((pow(2, iPower) - 1)*DSBVOLUME_MIN) + lVolume)/pow(2, iPower); + lAttuneation *= dsl->ds3dl.flRolloffFactor; /* attuneation according to rolloff factor */ lAttuneation /= 5; /* i've figured this value wih trying (without it, sound is too quiet */ TRACE ("distance att.: distance = %f, min distance = %f => adjusting volume %ld for attuneation %ld\n", fDistance, ds3db->ds3db.flMinDistance, lVolume, lAttuneation); - lVolume = lVolume + lAttuneation; + lVolume += lAttuneation; + /* conning */ + /* correct me if I'm wrong, but i believe 'D3DVECTORS' used below are only points + between which vectors are yet to be calculated */ + vConeOrientation = VectorBetweenTwoPoints(&ds3db->ds3db.vPosition, &ds3db->ds3db.vConeOrientation); + /* I/O ConeAngles are defined in both directions; for comparing, we need only half of their values */ + dwOutsideConeAngle = ds3db->ds3db.dwOutsideConeAngle / 2; + dwInsideConeAngle = ds3db->ds3db.dwInsideConeAngle / 2; + dwTheta = AngleBetweenVectorsDeg (&vDistance, &vConeOrientation); + /* actual conning */ + if (dwTheta <= dwInsideConeAngle) + { + lAttuneation = 0; + TRACE("conning: angle (%ld) < InsideConeAngle (%ld), leaving volume at %ld\n", dwTheta, dwInsideConeAngle, lVolume); + } + if (dwTheta > dwOutsideConeAngle) + { + /* attuneation is equal to lConeOutsideVolume */ + lAttuneation = ds3db->ds3db.lConeOutsideVolume; + TRACE("conning: angle (%ld) > OutsideConeAngle (%ld), attuneation = %ld, final volume = %ld\n", dwTheta, dwOutsideConeAngle, \ + ds3db->ds3db.lConeOutsideVolume, lVolume); + } + if (dwTheta > dwInsideConeAngle && dwTheta <= dwOutsideConeAngle) + { + dwAlpha = dwTheta - dwInsideConeAngle; + dwConstVolAng = ((lVolume + ds3db->ds3db.lConeOutsideVolume) - lVolume) / (dwOutsideConeAngle - dwInsideConeAngle); + lAttuneation = dwAlpha*dwConstVolAng; + TRACE("conning: angle = %ld, attuneation = %ld, final Volume = %ld\n", dwTheta, dwAlpha*dwConstVolAng, lVolume); + } + lVolume += lAttuneation; + TRACE("final volume = %ld\n", lVolume); - /* at least, we got the desired volume */ + /* at last, we got the desired volume */ ds3db->dsb->volpan.lVolume = lVolume; DSOUND_RecalcVolPan (&ds3db->dsb->volpan); DSOUND_ForceRemix (ds3db->dsb); -- 2.11.4.GIT