Module: wine Branch: master Commit: db316c124365ef73c03e6c8cb3e79a20c72ba856 URL: http://source.winehq.org/git/wine.git/?a=commit;h=db316c124365ef73c03e6c8cb3...
Author: Maarten Lankhorst wine@mblankhorst.nl Date: Tue May 17 13:41:04 2016 -0500
dsound: Remove unconditional memory allocation in mixing thread.
Signed-off-by: Andrew Eikum aeikum@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/dsound/dsound.c | 1 + dlls/dsound/dsound_private.h | 4 ++-- dlls/dsound/mixer.c | 24 ++++++++++++++++-------- 3 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/dlls/dsound/dsound.c b/dlls/dsound/dsound.c index 7519951..fb9fd66 100644 --- a/dlls/dsound/dsound.c +++ b/dlls/dsound/dsound.c @@ -234,6 +234,7 @@ static ULONG DirectSoundDevice_Release(DirectSoundDevice * device) IAudioStreamVolume_Release(device->volume);
HeapFree(GetProcessHeap(), 0, device->tmp_buffer); + HeapFree(GetProcessHeap(), 0, device->cp_buffer); HeapFree(GetProcessHeap(), 0, device->buffer); RtlDeleteResource(&device->buffer_list_lock); device->mixlock.DebugInfo->Spare[0] = 0; diff --git a/dlls/dsound/dsound_private.h b/dlls/dsound/dsound_private.h index 0ca8aec..d063046 100644 --- a/dlls/dsound/dsound_private.h +++ b/dlls/dsound/dsound_private.h @@ -87,8 +87,8 @@ struct DirectSoundDevice int speaker_num[DS_MAX_CHANNELS]; int num_speakers; int lfe_channel; - float *tmp_buffer; - DWORD tmp_buffer_len; + float *tmp_buffer, *cp_buffer; + DWORD tmp_buffer_len, cp_buffer_len;
DSVOLUMEPAN volpan;
diff --git a/dlls/dsound/mixer.c b/dlls/dsound/mixer.c index 727ceb8..217d4ce 100644 --- a/dlls/dsound/mixer.c +++ b/dlls/dsound/mixer.c @@ -292,18 +292,29 @@ static UINT cp_fields_resample(IDirectSoundBufferImpl *dsb, UINT count, LONG64 *
UINT fir_cachesize = (fir_len + dsbfirstep - 2) / dsbfirstep; UINT required_input = max_ipos + fir_cachesize; + float *intermediate, *fir_copy, *itmp; + + DWORD len = required_input * channels; + len += fir_cachesize; + len *= sizeof(float); + + if (!dsb->device->cp_buffer) { + dsb->device->cp_buffer = HeapAlloc(GetProcessHeap(), 0, len); + dsb->device->cp_buffer_len = len; + } else if (len > dsb->device->cp_buffer_len) { + dsb->device->cp_buffer = HeapReAlloc(GetProcessHeap(), 0, dsb->device->cp_buffer, len); + dsb->device->cp_buffer_len = len; + }
- float* intermediate = HeapAlloc(GetProcessHeap(), 0, - sizeof(float) * required_input * channels); + fir_copy = dsb->device->cp_buffer; + intermediate = fir_copy + fir_cachesize;
- float* fir_copy = HeapAlloc(GetProcessHeap(), 0, - sizeof(float) * fir_cachesize);
/* Important: this buffer MUST be non-interleaved * if you want -msse3 to have any effect. * This is good for CPU cache effects, too. */ - float* itmp = intermediate; + itmp = intermediate; for (channel = 0; channel < channels; channel++) for (i = 0; i < required_input; i++) *(itmp++) = get_current_sample(dsb, @@ -338,9 +349,6 @@ static UINT cp_fields_resample(IDirectSoundBufferImpl *dsb, UINT count, LONG64 *
*freqAccNum = freqAcc_end % dsb->freqAdjustDen;
- HeapFree(GetProcessHeap(), 0, fir_copy); - HeapFree(GetProcessHeap(), 0, intermediate); - return max_ipos; }