Use ComputeAngleGains for multi-channel sources and remove the unused lookup table stuff

This commit is contained in:
Chris Robinson 2012-04-29 05:04:46 -07:00
parent 8d9838012d
commit aed35fd811
4 changed files with 4 additions and 85 deletions

View File

@ -115,14 +115,12 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
ALfloat WetGain[MAX_SENDS];
ALfloat WetGainHF[MAX_SENDS];
ALint NumSends, Frequency;
const ALfloat *ChannelGain;
const struct ChanMap *chans = NULL;
enum Resampler Resampler;
ALint num_channels = 0;
ALboolean DirectChannels;
ALfloat Pitch;
ALfloat cw;
ALuint pos;
ALint i, c;
/* Get device properties */
@ -281,17 +279,11 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext)
/* Special-case LFE */
if(chans[c].channel == LFE)
{
SrcMatrix[c][LFE] += DryGain;
SrcMatrix[c][chans[c].channel] = DryGain;
continue;
}
pos = aluCart2LUTpos(aluSin(chans[c].angle), aluCos(chans[c].angle));
ChannelGain = Device->PanningLUT[pos];
for(i = 0;i < (ALint)Device->NumChan;i++)
{
enum Channel chan = Device->Speaker2Chan[i];
SrcMatrix[c][chan] += DryGain * ChannelGain[chan];
}
ComputeAngleGains(Device, chans[c].angle, 0.0f, DryGain,
SrcMatrix[c]);
}
}
for(i = 0;i < NumSends;i++)

View File

@ -139,30 +139,6 @@ static void SetSpeakerArrangement(const char *name, ALfloat SpeakerAngle[MAXCHAN
}
}
static ALfloat aluLUTpos2Angle(ALint pos)
{
if(pos < QUADRANT_NUM)
return aluAtan((ALfloat)pos / (ALfloat)(QUADRANT_NUM - pos));
if(pos < 2 * QUADRANT_NUM)
return F_PI_2 + aluAtan((ALfloat)(pos - QUADRANT_NUM) / (ALfloat)(2 * QUADRANT_NUM - pos));
if(pos < 3 * QUADRANT_NUM)
return aluAtan((ALfloat)(pos - 2 * QUADRANT_NUM) / (ALfloat)(3 * QUADRANT_NUM - pos)) - F_PI;
return aluAtan((ALfloat)(pos - 3 * QUADRANT_NUM) / (ALfloat)(4 * QUADRANT_NUM - pos)) - F_PI_2;
}
ALint aluCart2LUTpos(ALfloat im, ALfloat re)
{
ALint pos = 0;
ALfloat denom = aluFabs(im) + aluFabs(re);
if(denom > 0.0f)
pos = (ALint)(QUADRANT_NUM*aluFabs(im) / denom + 0.5);
if(re < 0.0f)
pos = 2 * QUADRANT_NUM - pos;
if(im < 0.0f)
pos = LUT_NUM - pos;
return pos%LUT_NUM;
}
/**
* ComputeAngleGains
@ -357,14 +333,12 @@ ALvoid ComputeAngleGains(const ALCdevice *device, ALfloat angle, ALfloat hwidth,
}
}
ALvoid aluInitPanning(ALCdevice *Device)
{
const char *layoutname = NULL;
enum Channel *Speaker2Chan;
ALfloat *SpeakerAngle;
ALfloat Alpha, Theta;
ALint pos;
ALuint s;
Speaker2Chan = Device->Speaker2Chan;
SpeakerAngle = Device->SpeakerAngle;
@ -467,46 +441,4 @@ ALvoid aluInitPanning(ALCdevice *Device)
}
if(layoutname && Device->Type != Loopback)
SetSpeakerArrangement(layoutname, SpeakerAngle, Speaker2Chan, Device->NumChan);
for(pos = 0; pos < LUT_NUM; pos++)
{
ALfloat *PanningLUT = Device->PanningLUT[pos];
/* clear all values */
for(s = 0; s < MAXCHANNELS; s++)
PanningLUT[s] = 0.0f;
if(Device->NumChan == 1)
{
PanningLUT[Speaker2Chan[0]] = 1.0f;
continue;
}
/* source angle */
Theta = aluLUTpos2Angle(pos);
/* set panning values */
for(s = 0; s < Device->NumChan - 1; s++)
{
if(Theta >= SpeakerAngle[s] && Theta < SpeakerAngle[s+1])
{
/* source between speaker s and speaker s+1 */
Alpha = (Theta-SpeakerAngle[s]) /
(SpeakerAngle[s+1]-SpeakerAngle[s]);
PanningLUT[Speaker2Chan[s]] = aluSqrt(1.0f-Alpha);
PanningLUT[Speaker2Chan[s+1]] = aluSqrt( Alpha);
break;
}
}
if(s == Device->NumChan - 1)
{
/* source between last and first speaker */
if(Theta < SpeakerAngle[0])
Theta += F_PI*2.0f;
Alpha = (Theta-SpeakerAngle[s]) /
(F_PI*2.0f + SpeakerAngle[0]-SpeakerAngle[s]);
PanningLUT[Speaker2Chan[s]] = aluSqrt(1.0f-Alpha);
PanningLUT[Speaker2Chan[0]] = aluSqrt( Alpha);
}
}
}

View File

@ -579,7 +579,6 @@ struct ALCdevice_struct
enum Channel Speaker2Chan[MAXCHANNELS];
ALfloat SpeakerAngle[MAXCHANNELS];
ALfloat PanningLUT[LUT_NUM][MAXCHANNELS];
ALuint NumChan;
ALfloat ClickRemoval[MAXCHANNELS];

View File

@ -110,9 +110,6 @@ _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _controlfp (unsigned int unNew, uns
#define aluFloor(x) ((ALfloat)floor((double)(x)))
#endif
#define QUADRANT_NUM 128
#define LUT_NUM (4 * QUADRANT_NUM)
#ifdef __cplusplus
extern "C" {
#endif
@ -296,7 +293,6 @@ static __inline void aluNormalize(ALfloat *inVector)
ALvoid aluInitPanning(ALCdevice *Device);
ALint aluCart2LUTpos(ALfloat im, ALfloat re);
ALvoid ComputeAngleGains(const ALCdevice *device, ALfloat angle, ALfloat hwidth, ALfloat ingain, ALfloat *gains);