aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/mixer.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2016-10-05 20:33:45 -0700
committerChris Robinson <[email protected]>2016-10-05 20:33:45 -0700
commit9b8f36b75879d2fee652c9ff81e1cb5db665a5c5 (patch)
treedae9a1458b8f2d12fab0962792a8bf3528e111ab /Alc/mixer.c
parent1e1a8837f8a595639aa8933889b892766379d111 (diff)
Pass current and target gains directly for mixing
Diffstat (limited to 'Alc/mixer.c')
-rw-r--r--Alc/mixer.c102
1 files changed, 16 insertions, 86 deletions
diff --git a/Alc/mixer.c b/Alc/mixer.c
index 864e2395..a0132e0f 100644
--- a/Alc/mixer.c
+++ b/Alc/mixer.c
@@ -393,6 +393,7 @@ ALvoid MixSource(ALvoice *voice, ALsource *Source, ALCdevice *Device, ALuint Sam
ALuint NumChannels;
ALuint SampleSize;
ALint64 DataSize64;
+ ALuint Counter;
ALuint IrSize;
ALuint chan, send, j;
@@ -411,22 +412,10 @@ ALvoid MixSource(ALvoice *voice, ALsource *Source, ALCdevice *Device, ALuint Sam
Resample = ((increment == FRACTIONONE && DataPosFrac == 0) ?
Resample_copy32_C : ResampleSamples);
+ Counter = voice->Moving ? SamplesToDo : 0;
OutPos = 0;
do {
ALuint SrcBufferSize, DstBufferSize;
- ALuint Counter;
- ALfloat Delta;
-
- if(!voice->Moving)
- {
- Counter = 0;
- Delta = 0.0f;
- }
- else
- {
- Counter = SamplesToDo - OutPos;
- Delta = 1.0f / (ALfloat)Counter;
- }
/* Figure out how many buffer samples will be needed */
DataSize64 = SamplesToDo-OutPos;
@@ -575,42 +564,12 @@ ALvoid MixSource(ALvoice *voice, ALsource *Source, ALCdevice *Device, ALuint Sam
);
if(!voice->IsHrtf)
{
- ALfloat *restrict currents = parms->Gains.Current;
- const ALfloat *targets = parms->Gains.Target;
- MixGains gains[MAX_OUTPUT_CHANNELS];
-
if(!Counter)
- {
- for(j = 0;j < voice->DirectOut.Channels;j++)
- {
- gains[j].Target = targets[j];
- gains[j].Current = gains[j].Target;
- gains[j].Step = 0.0f;
- }
- }
- else
- {
- for(j = 0;j < voice->DirectOut.Channels;j++)
- {
- ALfloat diff;
- gains[j].Target = targets[j];
- gains[j].Current = currents[j];
- diff = gains[j].Target - gains[j].Current;
- if(fabsf(diff) >= GAIN_SILENCE_THRESHOLD)
- gains[j].Step = diff * Delta;
- else
- {
- gains[j].Current = gains[j].Target;
- gains[j].Step = 0.0f;
- }
- }
- }
-
+ memcpy(parms->Gains.Current, parms->Gains.Target,
+ sizeof(parms->Gains.Current));
MixSamples(samples, voice->DirectOut.Channels, voice->DirectOut.Buffer,
- gains, Counter, OutPos, DstBufferSize);
-
- for(j = 0;j < voice->DirectOut.Channels;j++)
- currents[j] = gains[j].Current;
+ parms->Gains.Current, parms->Gains.Target, Counter, OutPos, DstBufferSize
+ );
}
else
{
@@ -630,19 +589,20 @@ ALvoid MixSource(ALvoice *voice, ALsource *Source, ALCdevice *Device, ALuint Sam
}
else
{
+ ALfloat delta = 1.0f / (ALfloat)Counter;
ALfloat coeffdiff;
ALint delaydiff;
for(j = 0;j < IrSize;j++)
{
coeffdiff = parms->Hrtf.Target.Coeffs[j][0] - parms->Hrtf.Current.Coeffs[j][0];
- hrtfparams.Steps.Coeffs[j][0] = coeffdiff * Delta;
+ hrtfparams.Steps.Coeffs[j][0] = coeffdiff * delta;
coeffdiff = parms->Hrtf.Target.Coeffs[j][1] - parms->Hrtf.Current.Coeffs[j][1];
- hrtfparams.Steps.Coeffs[j][1] = coeffdiff * Delta;
+ hrtfparams.Steps.Coeffs[j][1] = coeffdiff * delta;
}
delaydiff = (ALint)(parms->Hrtf.Target.Delay[0] - parms->Hrtf.Current.Delay[0]);
- hrtfparams.Steps.Delay[0] = fastf2i((ALfloat)delaydiff * Delta);
+ hrtfparams.Steps.Delay[0] = fastf2i((ALfloat)delaydiff * delta);
delaydiff = (ALint)(parms->Hrtf.Target.Delay[1] - parms->Hrtf.Current.Delay[1]);
- hrtfparams.Steps.Delay[1] = fastf2i((ALfloat)delaydiff * Delta);
+ hrtfparams.Steps.Delay[1] = fastf2i((ALfloat)delaydiff * delta);
}
hrtfparams.Target = &parms->Hrtf.Target;
hrtfparams.Current = &parms->Hrtf.Current;
@@ -660,9 +620,6 @@ ALvoid MixSource(ALvoice *voice, ALsource *Source, ALCdevice *Device, ALuint Sam
for(send = 0;send < Device->NumAuxSends;send++)
{
SendParams *parms = &voice->Chan[chan].Send[send];
- ALfloat *restrict currents = parms->Gains.Current;
- const ALfloat *targets = parms->Gains.Target;
- MixGains gains[MAX_OUTPUT_CHANNELS];
const ALfloat *samples;
if(!voice->SendOut[send].Buffer)
@@ -674,39 +631,11 @@ ALvoid MixSource(ALvoice *voice, ALsource *Source, ALCdevice *Device, ALuint Sam
);
if(!Counter)
- {
- for(j = 0;j < voice->SendOut[send].Channels;j++)
- {
- gains[j].Target = targets[j];
- gains[j].Current = gains[j].Target;
- gains[j].Step = 0.0f;
- }
- }
- else
- {
- for(j = 0;j < voice->SendOut[send].Channels;j++)
- {
- ALfloat diff;
- gains[j].Target = targets[j];
- gains[j].Current = currents[j];
- diff = gains[j].Target - gains[j].Current;
- if(fabsf(diff) >= GAIN_SILENCE_THRESHOLD)
- gains[j].Step = diff * Delta;
- else
- {
- gains[j].Current = gains[j].Target;
- gains[j].Step = 0.0f;
- }
- }
- }
-
- MixSamples(samples,
- voice->SendOut[send].Channels, voice->SendOut[send].Buffer,
- gains, Counter, OutPos, DstBufferSize
+ memcpy(parms->Gains.Current, parms->Gains.Target,
+ sizeof(parms->Gains.Current));
+ MixSamples(samples, voice->SendOut[send].Channels, voice->SendOut[send].Buffer,
+ parms->Gains.Current, parms->Gains.Target, Counter, OutPos, DstBufferSize
);
-
- for(j = 0;j < voice->SendOut[send].Channels;j++)
- currents[j] = gains[j].Current;
}
}
/* Update positions */
@@ -716,6 +645,7 @@ ALvoid MixSource(ALvoice *voice, ALsource *Source, ALCdevice *Device, ALuint Sam
OutPos += DstBufferSize;
voice->Offset += DstBufferSize;
+ Counter = maxu(DstBufferSize, Counter) - DstBufferSize;
/* Handle looping sources */
while(1)