diff options
author | Chris Robinson <[email protected]> | 2013-10-08 08:29:14 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2013-10-08 12:39:22 -0700 |
commit | 11365b42c7fedaef61d7123c390c429260eae52f (patch) | |
tree | a4d2c61c8729c4b78b0de49fb12ce5018d7297ef | |
parent | b42fcce014da2c866a3d64f8f4831baed2f46e6f (diff) |
Use helper macros to convert between degrees and radians
-rw-r--r-- | Alc/ALu.c | 60 | ||||
-rw-r--r-- | Alc/panning.c | 62 | ||||
-rw-r--r-- | OpenAL32/Include/alu.h | 7 |
3 files changed, 66 insertions, 63 deletions
@@ -194,49 +194,49 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext) { static const struct ChanMap MonoMap[1] = { { FrontCenter, 0.0f } }; static const struct ChanMap StereoMap[2] = { - { FrontLeft, -30.0f * F_PI/180.0f }, - { FrontRight, 30.0f * F_PI/180.0f } + { FrontLeft, DEG2RAD(-30.0f) }, + { FrontRight, DEG2RAD( 30.0f) } }; static const struct ChanMap StereoWideMap[2] = { - { FrontLeft, -90.0f * F_PI/180.0f }, - { FrontRight, 90.0f * F_PI/180.0f } + { FrontLeft, DEG2RAD(-90.0f) }, + { FrontRight, DEG2RAD( 90.0f) } }; static const struct ChanMap RearMap[2] = { - { BackLeft, -150.0f * F_PI/180.0f }, - { BackRight, 150.0f * F_PI/180.0f } + { BackLeft, DEG2RAD(-150.0f) }, + { BackRight, DEG2RAD( 150.0f) } }; static const struct ChanMap QuadMap[4] = { - { FrontLeft, -45.0f * F_PI/180.0f }, - { FrontRight, 45.0f * F_PI/180.0f }, - { BackLeft, -135.0f * F_PI/180.0f }, - { BackRight, 135.0f * F_PI/180.0f } + { FrontLeft, DEG2RAD( -45.0f) }, + { FrontRight, DEG2RAD( 45.0f) }, + { BackLeft, DEG2RAD(-135.0f) }, + { BackRight, DEG2RAD( 135.0f) } }; static const struct ChanMap X51Map[6] = { - { FrontLeft, -30.0f * F_PI/180.0f }, - { FrontRight, 30.0f * F_PI/180.0f }, - { FrontCenter, 0.0f * F_PI/180.0f }, + { FrontLeft, DEG2RAD( -30.0f) }, + { FrontRight, DEG2RAD( 30.0f) }, + { FrontCenter, DEG2RAD( 0.0f) }, { LFE, 0.0f }, - { BackLeft, -110.0f * F_PI/180.0f }, - { BackRight, 110.0f * F_PI/180.0f } + { BackLeft, DEG2RAD(-110.0f) }, + { BackRight, DEG2RAD( 110.0f) } }; static const struct ChanMap X61Map[7] = { - { FrontLeft, -30.0f * F_PI/180.0f }, - { FrontRight, 30.0f * F_PI/180.0f }, - { FrontCenter, 0.0f * F_PI/180.0f }, + { FrontLeft, DEG2RAD(-30.0f) }, + { FrontRight, DEG2RAD( 30.0f) }, + { FrontCenter, DEG2RAD( 0.0f) }, { LFE, 0.0f }, - { BackCenter, 180.0f * F_PI/180.0f }, - { SideLeft, -90.0f * F_PI/180.0f }, - { SideRight, 90.0f * F_PI/180.0f } + { BackCenter, DEG2RAD(180.0f) }, + { SideLeft, DEG2RAD(-90.0f) }, + { SideRight, DEG2RAD( 90.0f) } }; static const struct ChanMap X71Map[8] = { - { FrontLeft, -30.0f * F_PI/180.0f }, - { FrontRight, 30.0f * F_PI/180.0f }, - { FrontCenter, 0.0f * F_PI/180.0f }, + { FrontLeft, DEG2RAD( -30.0f) }, + { FrontRight, DEG2RAD( 30.0f) }, + { FrontCenter, DEG2RAD( 0.0f) }, { LFE, 0.0f }, - { BackLeft, -150.0f * F_PI/180.0f }, - { BackRight, 150.0f * F_PI/180.0f }, - { SideLeft, -90.0f * F_PI/180.0f }, - { SideRight, 90.0f * F_PI/180.0f } + { BackLeft, DEG2RAD(-150.0f) }, + { BackRight, DEG2RAD( 150.0f) }, + { SideLeft, DEG2RAD( -90.0f) }, + { SideRight, DEG2RAD( 90.0f) } }; ALCdevice *Device = ALContext->Device; @@ -339,7 +339,7 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext) else { chans = StereoWideMap; - hwidth = 60.0f * F_PI/180.0f; + hwidth = DEG2RAD(60.0f); } num_channels = 2; break; @@ -718,7 +718,7 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext) } /* Calculate directional soundcones */ - Angle = acosf(aluDotproduct(Direction,SourceToListener)) * ConeScale * (360.0f/F_PI); + Angle = RAD2DEG(acosf(aluDotproduct(Direction,SourceToListener)) * ConeScale) * 2.0f; if(Angle > InnerAngle && Angle <= OuterAngle) { ALfloat scale = (Angle-InnerAngle) / (OuterAngle-InnerAngle); diff --git a/Alc/panning.c b/Alc/panning.c index 188844e6..10615570 100644 --- a/Alc/panning.c +++ b/Alc/panning.c @@ -102,7 +102,7 @@ static void SetSpeakerArrangement(const char *name, ALfloat SpeakerAngle[MaxChan { long angle = strtol(sep, NULL, 10); if(angle >= -180 && angle <= 180) - SpeakerAngle[i] = angle * F_PI/180.0f; + SpeakerAngle[i] = DEG2RAD(angle); else ERR("Invalid angle for speaker \"%s\": %ld\n", confkey, angle); break; @@ -351,7 +351,7 @@ ALvoid aluInitPanning(ALCdevice *Device) case DevFmtMono: Device->NumChan = 1; Speaker2Chan[0] = FrontCenter; - SpeakerAngle[0] = F_PI/180.0f * 0.0f; + SpeakerAngle[0] = DEG2RAD(0.0f); layoutname = NULL; break; @@ -359,8 +359,8 @@ ALvoid aluInitPanning(ALCdevice *Device) Device->NumChan = 2; Speaker2Chan[0] = FrontLeft; Speaker2Chan[1] = FrontRight; - SpeakerAngle[0] = F_PI/180.0f * -90.0f; - SpeakerAngle[1] = F_PI/180.0f * 90.0f; + SpeakerAngle[0] = DEG2RAD(-90.0f); + SpeakerAngle[1] = DEG2RAD( 90.0f); layoutname = "layout_stereo"; break; @@ -370,10 +370,10 @@ ALvoid aluInitPanning(ALCdevice *Device) Speaker2Chan[1] = FrontLeft; Speaker2Chan[2] = FrontRight; Speaker2Chan[3] = BackRight; - SpeakerAngle[0] = F_PI/180.0f * -135.0f; - SpeakerAngle[1] = F_PI/180.0f * -45.0f; - SpeakerAngle[2] = F_PI/180.0f * 45.0f; - SpeakerAngle[3] = F_PI/180.0f * 135.0f; + SpeakerAngle[0] = DEG2RAD(-135.0f); + SpeakerAngle[1] = DEG2RAD( -45.0f); + SpeakerAngle[2] = DEG2RAD( 45.0f); + SpeakerAngle[3] = DEG2RAD( 135.0f); layoutname = "layout_quad"; break; @@ -384,11 +384,11 @@ ALvoid aluInitPanning(ALCdevice *Device) Speaker2Chan[2] = FrontCenter; Speaker2Chan[3] = FrontRight; Speaker2Chan[4] = BackRight; - SpeakerAngle[0] = F_PI/180.0f * -110.0f; - SpeakerAngle[1] = F_PI/180.0f * -30.0f; - SpeakerAngle[2] = F_PI/180.0f * 0.0f; - SpeakerAngle[3] = F_PI/180.0f * 30.0f; - SpeakerAngle[4] = F_PI/180.0f * 110.0f; + SpeakerAngle[0] = DEG2RAD(-110.0f); + SpeakerAngle[1] = DEG2RAD( -30.0f); + SpeakerAngle[2] = DEG2RAD( 0.0f); + SpeakerAngle[3] = DEG2RAD( 30.0f); + SpeakerAngle[4] = DEG2RAD( 110.0f); layoutname = "layout_surround51"; break; @@ -399,11 +399,11 @@ ALvoid aluInitPanning(ALCdevice *Device) Speaker2Chan[2] = FrontCenter; Speaker2Chan[3] = FrontRight; Speaker2Chan[4] = SideRight; - SpeakerAngle[0] = F_PI/180.0f * -90.0f; - SpeakerAngle[1] = F_PI/180.0f * -30.0f; - SpeakerAngle[2] = F_PI/180.0f * 0.0f; - SpeakerAngle[3] = F_PI/180.0f * 30.0f; - SpeakerAngle[4] = F_PI/180.0f * 90.0f; + SpeakerAngle[0] = DEG2RAD(-90.0f); + SpeakerAngle[1] = DEG2RAD(-30.0f); + SpeakerAngle[2] = DEG2RAD( 0.0f); + SpeakerAngle[3] = DEG2RAD( 30.0f); + SpeakerAngle[4] = DEG2RAD( 90.0f); layoutname = "layout_side51"; break; @@ -415,12 +415,12 @@ ALvoid aluInitPanning(ALCdevice *Device) Speaker2Chan[3] = FrontRight; Speaker2Chan[4] = SideRight; Speaker2Chan[5] = BackCenter; - SpeakerAngle[0] = F_PI/180.0f * -90.0f; - SpeakerAngle[1] = F_PI/180.0f * -30.0f; - SpeakerAngle[2] = F_PI/180.0f * 0.0f; - SpeakerAngle[3] = F_PI/180.0f * 30.0f; - SpeakerAngle[4] = F_PI/180.0f * 90.0f; - SpeakerAngle[5] = F_PI/180.0f * 180.0f; + SpeakerAngle[0] = DEG2RAD(-90.0f); + SpeakerAngle[1] = DEG2RAD(-30.0f); + SpeakerAngle[2] = DEG2RAD( 0.0f); + SpeakerAngle[3] = DEG2RAD( 30.0f); + SpeakerAngle[4] = DEG2RAD( 90.0f); + SpeakerAngle[5] = DEG2RAD(180.0f); layoutname = "layout_surround61"; break; @@ -433,13 +433,13 @@ ALvoid aluInitPanning(ALCdevice *Device) Speaker2Chan[4] = FrontRight; Speaker2Chan[5] = SideRight; Speaker2Chan[6] = BackRight; - SpeakerAngle[0] = F_PI/180.0f * -150.0f; - SpeakerAngle[1] = F_PI/180.0f * -90.0f; - SpeakerAngle[2] = F_PI/180.0f * -30.0f; - SpeakerAngle[3] = F_PI/180.0f * 0.0f; - SpeakerAngle[4] = F_PI/180.0f * 30.0f; - SpeakerAngle[5] = F_PI/180.0f * 90.0f; - SpeakerAngle[6] = F_PI/180.0f * 150.0f; + SpeakerAngle[0] = DEG2RAD(-150.0f); + SpeakerAngle[1] = DEG2RAD( -90.0f); + SpeakerAngle[2] = DEG2RAD( -30.0f); + SpeakerAngle[3] = DEG2RAD( 0.0f); + SpeakerAngle[4] = DEG2RAD( 30.0f); + SpeakerAngle[5] = DEG2RAD( 90.0f); + SpeakerAngle[6] = DEG2RAD( 150.0f); layoutname = "layout_surround71"; break; } diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h index 7327d85b..d27301b3 100644 --- a/OpenAL32/Include/alu.h +++ b/OpenAL32/Include/alu.h @@ -13,13 +13,16 @@ #endif -#define F_PI (3.14159265358979323846f) /* pi */ -#define F_PI_2 (1.57079632679489661923f) /* pi/2 */ +#define F_PI (3.14159265358979323846f) +#define F_PI_2 (1.57079632679489661923f) #ifndef FLT_EPSILON #define FLT_EPSILON (1.19209290e-07f) #endif +#define DEG2RAD(x) ((ALfloat)(x) * (F_PI/180.0f)) +#define RAD2DEG(x) ((ALfloat)(x) * (180.0f/F_PI)) + #ifdef __cplusplus extern "C" { |