diff options
author | Chris Robinson <[email protected]> | 2017-12-16 09:41:27 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2017-12-16 09:41:27 -0800 |
commit | b10780f119443eecb2a639bfc21530b579179f1c (patch) | |
tree | da645da4b53303d150245c8ebd3e27a75570f3f2 /Alc/mixer.c | |
parent | d657c51be83b50ba6a73c30d3633066b4a78d786 (diff) |
Pre-clear the source temp buffer and accumulate into it
Diffstat (limited to 'Alc/mixer.c')
-rw-r--r-- | Alc/mixer.c | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/Alc/mixer.c b/Alc/mixer.c index 29ec07a0..3e019ddb 100644 --- a/Alc/mixer.c +++ b/Alc/mixer.c @@ -216,7 +216,7 @@ static inline void Load_##T(ALfloat *restrict dst, const T *restrict src, \ { \ ALsizei i; \ for(i = 0;i < samples;i++) \ - dst[i] = Sample_##T(src[i*srcstep]); \ + dst[i] += Sample_##T(src[i*srcstep]); \ } DECL_TEMPLATE(ALbyte) @@ -242,13 +242,6 @@ static void LoadSamples(ALfloat *restrict dst, const ALvoid *restrict src, ALint } } -static inline void SilenceSamples(ALfloat *dst, ALsizei samples) -{ - ALsizei i; - for(i = 0;i < samples;i++) - dst[i] = 0.0f; -} - static const ALfloat *DoFilters(ALfilterState *lpfilter, ALfilterState *hpfilter, ALfloat *restrict dst, const ALfloat *restrict src, @@ -356,8 +349,9 @@ ALboolean MixSource(ALvoice *voice, ALsource *Source, ALCdevice *Device, ALsizei ALfloat *SrcData = Device->SourceData; ALsizei FilledAmt; - /* Load the previous samples into the source data first. */ + /* Load the previous samples into the source data first, and clear the rest. */ memcpy(SrcData, voice->PrevSamples[chan], MAX_PRE_SAMPLES*sizeof(ALfloat)); + memset(SrcData+MAX_PRE_SAMPLES, 0, (SrcBufferSize-MAX_PRE_SAMPLES)*sizeof(ALfloat)); FilledAmt = MAX_PRE_SAMPLES; /* TODO: Handle multi-buffer items by adding them together in @@ -386,9 +380,6 @@ ALboolean MixSource(ALvoice *voice, ALsource *Source, ALCdevice *Device, ALsizei LoadSamples(&SrcData[FilledAmt], &Data[DataPosInt * NumChannels*SampleSize], NumChannels, ALBuffer->FmtType, DataSize); FilledAmt += DataSize; - - SilenceSamples(&SrcData[FilledAmt], SrcBufferSize - FilledAmt); - FilledAmt += SrcBufferSize - FilledAmt; } else { @@ -443,13 +434,11 @@ ALboolean MixSource(ALvoice *voice, ALsource *Source, ALCdevice *Device, ALsizei FilledAmt += DataSize; } } - tmpiter = ATOMIC_LOAD(&tmpiter->next, almemory_order_acquire); - if(!tmpiter && BufferLoopItem) - tmpiter = BufferLoopItem; - else if(!tmpiter) + if(SrcBufferSize > FilledAmt) { - SilenceSamples(&SrcData[FilledAmt], SrcBufferSize - FilledAmt); - FilledAmt += SrcBufferSize - FilledAmt; + tmpiter = ATOMIC_LOAD(&tmpiter->next, almemory_order_acquire); + if(!tmpiter && BufferLoopItem) + tmpiter = BufferLoopItem; } } } |