From: Matteo Bruni <mbruni@codeweavers.com> Since bfa7387c03992f172b7e080f1705b7c72ae32156, dsound is guaranteed to use a float format for its mixing output, although in practice it was often the case even before then. Simplify code accordingly. --- dlls/dsound/dsound_convert.c | 90 ------------------------------------ dlls/dsound/dsound_private.h | 4 -- dlls/dsound/mixer.c | 12 +---- dlls/dsound/primary.c | 23 ++++----- 4 files changed, 9 insertions(+), 120 deletions(-) diff --git a/dlls/dsound/dsound_convert.c b/dlls/dsound/dsound_convert.c index bdd62c8e51f..c1acc95652c 100644 --- a/dlls/dsound/dsound_convert.c +++ b/dlls/dsound/dsound_convert.c @@ -111,42 +111,6 @@ float get_mono(const IDirectSoundBufferImpl *dsb, BYTE *base, DWORD channel) return val; } -static inline unsigned char f_to_8(float value) -{ - if(value <= -1.f) - return 0; - if(value >= 1.f * 0x7f / 0x80) - return 0xFF; - return lrintf((value + 1.f) * 0x80); -} - -static inline SHORT f_to_16(float value) -{ - if(value <= -1.f) - return 0x8000; - if(value >= 1.f * 0x7FFF / 0x8000) - return 0x7FFF; - return le16(lrintf(value * 0x8000)); -} - -static LONG f_to_24(float value) -{ - if(value <= -1.f) - return 0x80000000; - if(value >= 1.f * 0x7FFFFF / 0x800000) - return 0x7FFFFF00; - return lrintf(value * 0x80000000U); -} - -static inline LONG f_to_32(float value) -{ - if(value <= -1.f) - return 0x80000000; - if(value >= 1.f) - return 0x7FFFFFFF; - return le32(lrintf(value * 0x80000000U)); -} - void putieee32(const IDirectSoundBufferImpl *dsb, DWORD pos, DWORD channel, float value) { BYTE *buf = (BYTE *)dsb->device->tmp_buffer; @@ -327,57 +291,3 @@ void mixieee32(float *src, float *dst, unsigned samples) while (samples--) *(dst++) += *(src++); } - -static void norm8(float *src, unsigned char *dst, unsigned samples) -{ - TRACE("%p - %p %d\n", src, dst, samples); - while (samples--) - { - *dst = f_to_8(*src); - ++dst; - ++src; - } -} - -static void norm16(float *src, SHORT *dst, unsigned samples) -{ - TRACE("%p - %p %d\n", src, dst, samples); - while (samples--) - { - *dst = f_to_16(*src); - ++dst; - ++src; - } -} - -static void norm24(float *src, BYTE *dst, unsigned samples) -{ - TRACE("%p - %p %d\n", src, dst, samples); - while (samples--) - { - LONG t = f_to_24(*src); - dst[0] = (t >> 8) & 0xFF; - dst[1] = (t >> 16) & 0xFF; - dst[2] = t >> 24; - dst += 3; - ++src; - } -} - -static void norm32(float *src, INT *dst, unsigned samples) -{ - TRACE("%p - %p %d\n", src, dst, samples); - while (samples--) - { - *dst = f_to_32(*src); - ++dst; - ++src; - } -} - -const normfunc normfunctions[4] = { - (normfunc)norm8, - (normfunc)norm16, - (normfunc)norm24, - (normfunc)norm32, -}; diff --git a/dlls/dsound/dsound_private.h b/dlls/dsound/dsound_private.h index 7e6768a21a8..c9b8a1b202d 100644 --- a/dlls/dsound/dsound_private.h +++ b/dlls/dsound/dsound_private.h @@ -49,8 +49,6 @@ extern const bitsgetfunc getbpp[5]; void putieee32(const IDirectSoundBufferImpl *dsb, DWORD pos, DWORD channel, float value); void putieee32_sum(const IDirectSoundBufferImpl *dsb, DWORD pos, DWORD channel, float value); void mixieee32(float *src, float *dst, unsigned samples); -typedef void (*normfunc)(const void *, void *, unsigned); -extern const normfunc normfunctions[4]; typedef struct _DSVOLUMEPAN { @@ -93,8 +91,6 @@ struct DirectSoundDevice DSVOLUMEPAN volpan; - normfunc normfunction; - /* DirectSound3DListener fields */ DS3DLISTENER ds3dl; BOOL ds3dl_need_recalc; diff --git a/dlls/dsound/mixer.c b/dlls/dsound/mixer.c index 3b7715e0c69..c8d0ea369d2 100644 --- a/dlls/dsound/mixer.c +++ b/dlls/dsound/mixer.c @@ -879,7 +879,6 @@ static void DSOUND_WaveQueue(DirectSoundDevice *device, LPBYTE pos, DWORD bytes) * secondary->buffer (secondary format) * =[Resample]=> device->tmp_buffer (float format) * =[Volume]=> device->tmp_buffer (float format) - * =[Reformat]=> device->buffer (device format, skipped on float) */ static void DSOUND_PerformMix(DirectSoundDevice *device) { @@ -934,16 +933,7 @@ static void DSOUND_PerformMix(DirectSoundDevice *device) memset(buffer, nfiller, frames * block); - if (!device->normfunction) - DSOUND_MixToPrimary(device, buffer, frames); - else { - memset(device->buffer, nfiller, device->buflen); - - /* do the mixing */ - DSOUND_MixToPrimary(device, (float*)device->buffer, frames); - - device->normfunction(device->buffer, buffer, frames * device->pwfx->nChannels); - } + DSOUND_MixToPrimary(device, buffer, frames); hr = IAudioRenderClient_ReleaseBuffer(device->render, frames, 0); if(FAILED(hr)) diff --git a/dlls/dsound/primary.c b/dlls/dsound/primary.c index e180dbaeacd..bd992f78984 100644 --- a/dlls/dsound/primary.c +++ b/dlls/dsound/primary.c @@ -24,6 +24,7 @@ */ #include <stdarg.h> +#include <assert.h> #define COBJMACROS #include "windef.h" @@ -210,7 +211,6 @@ static HRESULT DSOUND_PrimaryOpen(DirectSoundDevice *device, WAVEFORMATEX *wfx, IDirectSoundBufferImpl** dsb = device->buffers; LPBYTE newbuf; DWORD new_buflen; - BOOL mixfloat = FALSE; int i; TRACE("(%p)\n", device); @@ -218,16 +218,10 @@ static HRESULT DSOUND_PrimaryOpen(DirectSoundDevice *device, WAVEFORMATEX *wfx, new_buflen = device->buflen; new_buflen -= new_buflen % wfx->nBlockAlign; - if (wfx->wFormatTag == WAVE_FORMAT_IEEE_FLOAT || - (wfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE && - IsEqualGUID(&((WAVEFORMATEXTENSIBLE*)wfx)->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT))) - mixfloat = TRUE; - /* reallocate emulated primary buffer */ - if (forcewave || !mixfloat) { - if (!forcewave) - new_buflen = frames * wfx->nChannels * sizeof(float); - + if (forcewave) + { + /* forcewave means DSSCL_WRITEPRIMARY, which implies no mixing */ newbuf = realloc(device->buffer, new_buflen); if (!newbuf) { @@ -236,6 +230,10 @@ static HRESULT DSOUND_PrimaryOpen(DirectSoundDevice *device, WAVEFORMATEX *wfx, } FillMemory(newbuf, new_buflen, (wfx->wBitsPerSample == 8) ? 128 : 0); } else { + assert(wfx->wFormatTag == WAVE_FORMAT_IEEE_FLOAT || + (wfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE && + IsEqualGUID(&((WAVEFORMATEXTENSIBLE*)wfx)->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT))); + free(device->buffer); newbuf = NULL; } @@ -249,11 +247,6 @@ static HRESULT DSOUND_PrimaryOpen(DirectSoundDevice *device, WAVEFORMATEX *wfx, TRACE("buflen: %lu, frames %lu\n", device->buflen, frames); - if (!mixfloat) - device->normfunction = normfunctions[wfx->wBitsPerSample/8 - 1]; - else - device->normfunction = NULL; - device->playpos = 0; for (i = 0; i < device->nrofbuffers; i++) { -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/11145