diff options
author | Chris Robinson <[email protected]> | 2012-04-27 00:45:42 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2012-04-27 01:36:13 -0700 |
commit | 549d542a316c1f557c8042d9fc2b409bcd999872 (patch) | |
tree | 16b02e7a55e3bd045df8ea8336e5ee5ebd371c11 | |
parent | 2cdb58fb850f085b801c3d33b82512efd083020c (diff) |
Reorganize some ALsource fields
-rw-r--r-- | Alc/ALc.c | 4 | ||||
-rw-r--r-- | Alc/ALu.c | 78 | ||||
-rw-r--r-- | Alc/mixer.c | 36 | ||||
-rw-r--r-- | OpenAL32/Include/alSource.h | 50 | ||||
-rw-r--r-- | OpenAL32/alSource.c | 34 |
5 files changed, 106 insertions, 96 deletions
@@ -1614,8 +1614,8 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) if(source->Send[s].Slot) DecrementRef(&source->Send[s].Slot->ref); source->Send[s].Slot = NULL; - source->Send[s].WetGain = 1.0f; - source->Send[s].WetGainHF = 1.0f; + source->Send[s].Gain = 1.0f; + source->Send[s].GainHF = 1.0f; s++; } source->NeedsUpdate = AL_FALSE; @@ -183,11 +183,11 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext) for(i = 0;i < NumSends;i++) { WetGain[i] = clampf(SourceVolume, MinVolume, MaxVolume); - WetGain[i] *= ALSource->Send[i].WetGain; - WetGainHF[i] = ALSource->Send[i].WetGainHF; + WetGain[i] *= ALSource->Send[i].Gain; + WetGainHF[i] = ALSource->Send[i].GainHF; } - SrcMatrix = ALSource->Params.DryGains; + SrcMatrix = ALSource->Params.Direct.Gains; for(i = 0;i < MAXCHANNELS;i++) { for(c = 0;c < MAXCHANNELS;c++) @@ -269,12 +269,12 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext) if(chans[c].channel == LFE) { /* Skip LFE */ - ALSource->Params.HrtfDelay[c][0] = 0; - ALSource->Params.HrtfDelay[c][1] = 0; + ALSource->Params.Hrtf.Delay[c][0] = 0; + ALSource->Params.Hrtf.Delay[c][1] = 0; for(i = 0;i < HRIR_LENGTH;i++) { - ALSource->Params.HrtfCoeffs[c][i][0] = 0.0f; - ALSource->Params.HrtfCoeffs[c][i][1] = 0.0f; + ALSource->Params.Hrtf.Coeffs[c][i][0] = 0.0f; + ALSource->Params.Hrtf.Coeffs[c][i][1] = 0.0f; } } else @@ -284,11 +284,11 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext) GetLerpedHrtfCoeffs(Device->Hrtf, 0.0f, chans[c].angle, DryGain*ListenerGain, - ALSource->Params.HrtfCoeffs[c], - ALSource->Params.HrtfDelay[c]); + ALSource->Params.Hrtf.Coeffs[c], + ALSource->Params.Hrtf.Delay[c]); } - ALSource->HrtfCounter = 0; } + ALSource->Hrtf.Counter = 0; } else { @@ -320,7 +320,7 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext) if(Slot && Slot->effect.type == AL_EFFECT_NULL) Slot = NULL; ALSource->Params.Send[i].Slot = Slot; - ALSource->Params.Send[i].WetGain = WetGain[i] * ListenerGain; + ALSource->Params.Send[i].Gain = WetGain[i] * ListenerGain; } /* Update filter coefficients. Calculations based on the I3DL2 @@ -330,7 +330,7 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext) /* We use two chained one-pole filters, so we need to take the * square root of the squared gain, which is the same as the base * gain. */ - ALSource->Params.iirFilter.coeff = lpCoeffCalc(DryGainHF, cw); + ALSource->Params.Direct.iirFilter.coeff = lpCoeffCalc(DryGainHF, cw); for(i = 0;i < NumSends;i++) { /* We use a one-pole filter, so we need to take the squared gain */ @@ -631,8 +631,8 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext) DryGainHF *= ALSource->DirectGainHF; for(i = 0;i < NumSends;i++) { - WetGain[i] *= ALSource->Send[i].WetGain * ListenerGain; - WetGainHF[i] *= ALSource->Send[i].WetGainHF; + WetGain[i] *= ALSource->Send[i].Gain * ListenerGain; + WetGainHF[i] *= ALSource->Send[i].GainHF; } /* Calculate velocity-based doppler effect */ @@ -708,39 +708,39 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext) } /* Check to see if the HRIR is already moving. */ - if(ALSource->HrtfMoving) + if(ALSource->Hrtf.Moving) { /* Calculate the normalized HRTF transition factor (delta). */ - delta = CalcHrtfDelta(ALSource->Params.HrtfGain, DryGain, - ALSource->Params.HrtfDir, Position); + delta = CalcHrtfDelta(ALSource->Params.Hrtf.Gain, DryGain, + ALSource->Params.Hrtf.Dir, Position); /* If the delta is large enough, get the moving HRIR target * coefficients, target delays, steppping values, and counter. */ if(delta > 0.001f) { - ALSource->HrtfCounter = GetMovingHrtfCoeffs(Device->Hrtf, - ev, az, DryGain, delta, - ALSource->HrtfCounter, - ALSource->Params.HrtfCoeffs[0], - ALSource->Params.HrtfDelay[0], - ALSource->Params.HrtfCoeffStep, - ALSource->Params.HrtfDelayStep); - ALSource->Params.HrtfGain = DryGain; - ALSource->Params.HrtfDir[0] = Position[0]; - ALSource->Params.HrtfDir[1] = Position[1]; - ALSource->Params.HrtfDir[2] = Position[2]; + ALSource->Hrtf.Counter = GetMovingHrtfCoeffs(Device->Hrtf, + ev, az, DryGain, delta, + ALSource->Hrtf.Counter, + ALSource->Params.Hrtf.Coeffs[0], + ALSource->Params.Hrtf.Delay[0], + ALSource->Params.Hrtf.CoeffStep, + ALSource->Params.Hrtf.DelayStep); + ALSource->Params.Hrtf.Gain = DryGain; + ALSource->Params.Hrtf.Dir[0] = Position[0]; + ALSource->Params.Hrtf.Dir[1] = Position[1]; + ALSource->Params.Hrtf.Dir[2] = Position[2]; } } else { /* Get the initial (static) HRIR coefficients and delays. */ GetLerpedHrtfCoeffs(Device->Hrtf, ev, az, DryGain, - ALSource->Params.HrtfCoeffs[0], - ALSource->Params.HrtfDelay[0]); - ALSource->HrtfCounter = 0; - ALSource->Params.HrtfGain = DryGain; - ALSource->Params.HrtfDir[0] = Position[0]; - ALSource->Params.HrtfDir[1] = Position[1]; - ALSource->Params.HrtfDir[2] = Position[2]; + ALSource->Params.Hrtf.Coeffs[0], + ALSource->Params.Hrtf.Delay[0]); + ALSource->Hrtf.Counter = 0; + ALSource->Params.Hrtf.Gain = DryGain; + ALSource->Params.Hrtf.Dir[0] = Position[0]; + ALSource->Params.Hrtf.Dir[1] = Position[1]; + ALSource->Params.Hrtf.Dir[2] = Position[2]; } } else @@ -772,22 +772,22 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext) for(i = 0;i < MAXCHANNELS;i++) { for(j = 0;j < MAXCHANNELS;j++) - ALSource->Params.DryGains[i][j] = 0.0f; + ALSource->Params.Direct.Gains[i][j] = 0.0f; } for(i = 0;i < (ALint)Device->NumChan;i++) { enum Channel chan = Device->Speaker2Chan[i]; ALfloat gain = lerp(AmbientGain, ChannelGain[chan], DirGain); - ALSource->Params.DryGains[0][chan] = DryGain * gain; + ALSource->Params.Direct.Gains[0][chan] = DryGain * gain; } } for(i = 0;i < NumSends;i++) - ALSource->Params.Send[i].WetGain = WetGain[i]; + ALSource->Params.Send[i].Gain = WetGain[i]; /* Update filter coefficients. */ cw = aluCos(F_PI*2.0f * LOWPASSFREQREF / Frequency); - ALSource->Params.iirFilter.coeff = lpCoeffCalc(DryGainHF, cw); + ALSource->Params.Direct.iirFilter.coeff = lpCoeffCalc(DryGainHF, cw); for(i = 0;i < NumSends;i++) { ALfloat a = lpCoeffCalc(WetGainHF[i]*WetGainHF[i], cw); diff --git a/Alc/mixer.c b/Alc/mixer.c index b28b4911..7d51ee51 100644 --- a/Alc/mixer.c +++ b/Alc/mixer.c @@ -106,10 +106,10 @@ static void Mix_Hrtf_##sampler(ALsource *Source, ALCdevice *Device, \ ALuint SamplesToDo, ALuint BufferSize) \ { \ const ALuint NumChannels = Source->NumChannels; \ - const ALint *RESTRICT DelayStep = Source->Params.HrtfDelayStep; \ + const ALint *RESTRICT DelayStep = Source->Params.Hrtf.DelayStep; \ ALfloat (*RESTRICT DryBuffer)[MAXCHANNELS]; \ ALfloat *RESTRICT ClickRemoval, *RESTRICT PendingClicks; \ - ALfloat (*RESTRICT CoeffStep)[2] = Source->Params.HrtfCoeffStep; \ + ALfloat (*RESTRICT CoeffStep)[2] = Source->Params.Hrtf.CoeffStep; \ ALuint pos, frac; \ FILTER *DryFilter; \ ALuint BufferIdx; \ @@ -122,19 +122,19 @@ static void Mix_Hrtf_##sampler(ALsource *Source, ALCdevice *Device, \ DryBuffer = Device->DryBuffer; \ ClickRemoval = Device->ClickRemoval; \ PendingClicks = Device->PendingClicks; \ - DryFilter = &Source->Params.iirFilter; \ + DryFilter = &Source->Params.Direct.iirFilter; \ \ pos = 0; \ frac = srcfrac; \ \ for(i = 0;i < NumChannels;i++) \ { \ - ALfloat (*RESTRICT TargetCoeffs)[2] = Source->Params.HrtfCoeffs[i]; \ - ALuint *RESTRICT TargetDelay = Source->Params.HrtfDelay[i]; \ - ALfloat *RESTRICT History = Source->HrtfHistory[i]; \ - ALfloat (*RESTRICT Values)[2] = Source->HrtfValues[i]; \ - ALint Counter = maxu(Source->HrtfCounter, OutPos) - OutPos; \ - ALuint Offset = Source->HrtfOffset + OutPos; \ + ALfloat (*RESTRICT TargetCoeffs)[2] = Source->Params.Hrtf.Coeffs[i]; \ + ALuint *RESTRICT TargetDelay = Source->Params.Hrtf.Delay[i]; \ + ALfloat *RESTRICT History = Source->Hrtf.History[i]; \ + ALfloat (*RESTRICT Values)[2] = Source->Hrtf.Values[i]; \ + ALint Counter = maxu(Source->Hrtf.Counter, OutPos) - OutPos; \ + ALuint Offset = Source->Hrtf.Offset + OutPos; \ ALfloat Coeffs[HRIR_LENGTH][2]; \ ALuint Delay[2]; \ ALfloat left, right; \ @@ -257,7 +257,7 @@ static void Mix_Hrtf_##sampler(ALsource *Source, ALCdevice *Device, \ WetClickRemoval = Slot->ClickRemoval; \ WetPendingClicks = Slot->PendingClicks; \ WetFilter = &Source->Params.Send[out].iirFilter; \ - WetSend = Source->Params.Send[out].WetGain; \ + WetSend = Source->Params.Send[out].Gain; \ \ for(i = 0;i < NumChannels;i++) \ { \ @@ -323,7 +323,7 @@ static void Mix_##sampler(ALsource *Source, ALCdevice *Device, \ DryBuffer = Device->DryBuffer; \ ClickRemoval = Device->ClickRemoval; \ PendingClicks = Device->PendingClicks; \ - DryFilter = &Source->Params.iirFilter; \ + DryFilter = &Source->Params.Direct.iirFilter; \ \ pos = 0; \ frac = srcfrac; \ @@ -331,7 +331,7 @@ static void Mix_##sampler(ALsource *Source, ALCdevice *Device, \ for(i = 0;i < NumChannels;i++) \ { \ for(c = 0;c < MAXCHANNELS;c++) \ - DrySend[c] = Source->Params.DryGains[i][c]; \ + DrySend[c] = Source->Params.Direct.Gains[i][c]; \ \ pos = 0; \ frac = srcfrac; \ @@ -384,7 +384,7 @@ static void Mix_##sampler(ALsource *Source, ALCdevice *Device, \ WetClickRemoval = Slot->ClickRemoval; \ WetPendingClicks = Slot->PendingClicks; \ WetFilter = &Source->Params.Send[out].iirFilter; \ - WetSend = Source->Params.Send[out].WetGain; \ + WetSend = Source->Params.Send[out].Gain; \ \ for(i = 0;i < NumChannels;i++) \ { \ @@ -808,15 +808,15 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo) Source->BuffersPlayed = BuffersPlayed; Source->position = DataPosInt; Source->position_fraction = DataPosFrac; - Source->HrtfOffset += OutPos; + Source->Hrtf.Offset += OutPos; if(State == AL_PLAYING) { - Source->HrtfCounter = maxu(Source->HrtfCounter, OutPos) - OutPos; - Source->HrtfMoving = AL_TRUE; + Source->Hrtf.Counter = maxu(Source->Hrtf.Counter, OutPos) - OutPos; + Source->Hrtf.Moving = AL_TRUE; } else { - Source->HrtfCounter = 0; - Source->HrtfMoving = AL_FALSE; + Source->Hrtf.Counter = 0; + Source->Hrtf.Moving = AL_FALSE; } } diff --git a/OpenAL32/Include/alSource.h b/OpenAL32/Include/alSource.h index c3ae3fe7..98803115 100644 --- a/OpenAL32/Include/alSource.h +++ b/OpenAL32/Include/alSource.h @@ -28,6 +28,23 @@ typedef struct ALbufferlistitem struct ALbufferlistitem *prev; } ALbufferlistitem; +typedef struct HrtfParams { + ALfloat Gain; + ALfloat Dir[3]; + ALfloat Coeffs[MAXCHANNELS][HRIR_LENGTH][2]; + ALuint Delay[MAXCHANNELS][2]; + ALfloat CoeffStep[HRIR_LENGTH][2]; + ALint DelayStep[2]; +} HrtfParams; + +typedef struct HrtfState { + ALboolean Moving; + ALuint Counter; + ALfloat History[MAXCHANNELS][SRC_HISTORY_LENGTH]; + ALfloat Values[MAXCHANNELS][HRIR_LENGTH][2]; + ALuint Offset; +} HrtfState; + typedef struct ALsource { /** Source properties. */ @@ -97,16 +114,12 @@ typedef struct ALsource struct { struct ALeffectslot *Slot; - ALfloat WetGain; - ALfloat WetGainHF; + ALfloat Gain; + ALfloat GainHF; } Send[MAX_SENDS]; /** HRTF info. */ - ALboolean HrtfMoving; - ALuint HrtfCounter; - ALfloat HrtfHistory[MAXCHANNELS][SRC_HISTORY_LENGTH]; - ALfloat HrtfValues[MAXCHANNELS][HRIR_LENGTH][2]; - ALuint HrtfOffset; + HrtfState Hrtf; /** Current target parameters used for mixing. */ struct { @@ -114,24 +127,21 @@ typedef struct ALsource ALint Step; - ALfloat HrtfGain; - ALfloat HrtfDir[3]; - ALfloat HrtfCoeffs[MAXCHANNELS][HRIR_LENGTH][2]; - ALuint HrtfDelay[MAXCHANNELS][2]; - ALfloat HrtfCoeffStep[HRIR_LENGTH][2]; - ALint HrtfDelayStep[2]; + HrtfParams Hrtf; - /* A mixing matrix. First subscript is the channel number of the input - * data (regardless of channel configuration) and the second is the - * channel target (eg. FRONT_LEFT). */ - ALfloat DryGains[MAXCHANNELS][MAXCHANNELS]; + struct { + /* A mixing matrix. First subscript is the channel number of the + * input data (regardless of channel configuration) and the second + * is the channel target (eg. FRONT_LEFT). */ + ALfloat Gains[MAXCHANNELS][MAXCHANNELS]; - FILTER iirFilter; - ALfloat history[MAXCHANNELS*2]; + FILTER iirFilter; + ALfloat history[MAXCHANNELS*2]; + } Direct; struct { struct ALeffectslot *Slot; - ALfloat WetGain; + ALfloat Gain; FILTER iirFilter; ALfloat history[MAXCHANNELS]; } Send[MAX_SENDS]; diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c index 5f52322f..7d0e51d6 100644 --- a/OpenAL32/alSource.c +++ b/OpenAL32/alSource.c @@ -686,13 +686,13 @@ AL_API void AL_APIENTRY alSource3i(ALuint source, ALenum param, ALint value1, AL if(!filter) { /* Disable filter */ - Source->Send[value2].WetGain = 1.0f; - Source->Send[value2].WetGainHF = 1.0f; + Source->Send[value2].Gain = 1.0f; + Source->Send[value2].GainHF = 1.0f; } else { - Source->Send[value2].WetGain = filter->Gain; - Source->Send[value2].WetGainHF = filter->GainHF; + Source->Send[value2].Gain = filter->Gain; + Source->Send[value2].GainHF = filter->GainHF; } Source->NeedsUpdate = AL_TRUE; UnlockContext(Context); @@ -1633,14 +1633,14 @@ static ALvoid InitSourceParams(ALsource *Source) Source->DirectGainHF = 1.0f; for(i = 0;i < MAX_SENDS;i++) { - Source->Send[i].WetGain = 1.0f; - Source->Send[i].WetGainHF = 1.0f; + Source->Send[i].Gain = 1.0f; + Source->Send[i].GainHF = 1.0f; } Source->NeedsUpdate = AL_TRUE; - Source->HrtfMoving = AL_FALSE; - Source->HrtfCounter = 0; + Source->Hrtf.Moving = AL_FALSE; + Source->Hrtf.Counter = 0; } @@ -1670,11 +1670,11 @@ ALvoid SetSourceState(ALsource *Source, ALCcontext *Context, ALenum state) for(j = 0;j < MAXCHANNELS;j++) { for(k = 0;k < SRC_HISTORY_LENGTH;k++) - Source->HrtfHistory[j][k] = 0.0f; + Source->Hrtf.History[j][k] = 0.0f; for(k = 0;k < HRIR_LENGTH;k++) { - Source->HrtfValues[j][k][0] = 0.0f; - Source->HrtfValues[j][k][1] = 0.0f; + Source->Hrtf.Values[j][k][0] = 0.0f; + Source->Hrtf.Values[j][k][1] = 0.0f; } } } @@ -1714,8 +1714,8 @@ ALvoid SetSourceState(ALsource *Source, ALCcontext *Context, ALenum state) if(Source->state == AL_PLAYING) { Source->state = AL_PAUSED; - Source->HrtfMoving = AL_FALSE; - Source->HrtfCounter = 0; + Source->Hrtf.Moving = AL_FALSE; + Source->Hrtf.Counter = 0; } } else if(state == AL_STOPPED) @@ -1724,8 +1724,8 @@ ALvoid SetSourceState(ALsource *Source, ALCcontext *Context, ALenum state) { Source->state = AL_STOPPED; Source->BuffersPlayed = Source->BuffersInQueue; - Source->HrtfMoving = AL_FALSE; - Source->HrtfCounter = 0; + Source->Hrtf.Moving = AL_FALSE; + Source->Hrtf.Counter = 0; } Source->Offset = -1.0; } @@ -1737,8 +1737,8 @@ ALvoid SetSourceState(ALsource *Source, ALCcontext *Context, ALenum state) Source->position = 0; Source->position_fraction = 0; Source->BuffersPlayed = 0; - Source->HrtfMoving = AL_FALSE; - Source->HrtfCounter = 0; + Source->Hrtf.Moving = AL_FALSE; + Source->Hrtf.Counter = 0; } Source->Offset = -1.0; } |