From ef275facacba491c014c3282acfc3f5b065bb06c Mon Sep 17 00:00:00 2001 From: Anton Baskanov Date: Sun, 23 Apr 2023 20:19:30 +0700 Subject: [PATCH] dsound: Store the frequency of 3D buffers separately. --- dlls/dsound/buffer.c | 40 +++++++++++++++++++++++++--------------- dlls/dsound/dsound_private.h | 1 + dlls/dsound/sound3d.c | 11 ++++++----- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/dlls/dsound/buffer.c b/dlls/dsound/buffer.c index 7b830604a60..1b724ee775b 100644 --- a/dlls/dsound/buffer.c +++ b/dlls/dsound/buffer.c @@ -287,10 +287,17 @@ static HRESULT WINAPI IDirectSoundBufferImpl_SetFrequency(IDirectSoundBuffer8 *i AcquireSRWLockExclusive(&This->lock); - oldFreq = This->freq; - This->freq = freq; - if (freq != oldFreq) - DSOUND_RecalcFormat(This); + if (This->dsbd.dwFlags & DSBCAPS_CTRL3D) { + oldFreq = This->ds3db_freq; + This->ds3db_freq = freq; + if (freq != oldFreq) + DSOUND_Calc3DBuffer(This); + } else { + oldFreq = This->freq; + This->freq = freq; + if (freq != oldFreq) + DSOUND_RecalcFormat(This); + } ReleaseSRWLockExclusive(&This->lock); @@ -700,7 +707,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_GetFrequency(IDirectSoundBuffer8 *i return DSERR_INVALIDPARAM; } - *freq = This->freq; + *freq = (This->dsbd.dwFlags & DSBCAPS_CTRL3D) ? This->ds3db_freq : This->freq; TRACE("-> %ld\n", *freq); return DS_OK; @@ -1100,15 +1107,6 @@ HRESULT secondarybuffer_create(DirectSoundDevice *device, const DSBUFFERDESC *ds dsb->sec_mixpos = 0; dsb->state = STATE_STOPPED; - /* calculate fragment size and write lead */ - DSOUND_RecalcFormat(dsb); - - dsb->committedbuff = malloc(dsb->maxwritelead); - if(!dsb->committedbuff) { - IDirectSoundBuffer8_Release(&dsb->IDirectSoundBuffer8_iface); - return DSERR_OUTOFMEMORY; - } - if (dsb->dsbd.dwFlags & DSBCAPS_CTRL3D) { dsb->ds3db_ds3db.dwSize = sizeof(DS3DBUFFER); dsb->ds3db_ds3db.vPosition.x = 0.0; @@ -1127,11 +1125,23 @@ HRESULT secondarybuffer_create(DirectSoundDevice *device, const DSBUFFERDESC *ds dsb->ds3db_ds3db.flMaxDistance = DS3D_DEFAULTMAXDISTANCE; dsb->ds3db_ds3db.dwMode = DS3DMODE_NORMAL; + dsb->ds3db_freq = dsbd->lpwfxFormat->nSamplesPerSec; + dsb->ds3db_need_recalc = FALSE; DSOUND_Calc3DBuffer(dsb); - } else + } else { DSOUND_RecalcVolPan(&(dsb->volpan)); + /* calculate fragment size and write lead */ + DSOUND_RecalcFormat(dsb); + } + + dsb->committedbuff = malloc(dsb->maxwritelead); + if(!dsb->committedbuff) { + IDirectSoundBuffer8_Release(&dsb->IDirectSoundBuffer8_iface); + return DSERR_OUTOFMEMORY; + } + InitializeSRWLock(&dsb->lock); /* register buffer */ diff --git a/dlls/dsound/dsound_private.h b/dlls/dsound/dsound_private.h index d9f488c25b8..e67d474d61d 100644 --- a/dlls/dsound/dsound_private.h +++ b/dlls/dsound/dsound_private.h @@ -164,6 +164,7 @@ struct IDirectSoundBufferImpl /* DirectSound3DBuffer fields */ DS3DBUFFER ds3db_ds3db; LONG ds3db_lVolume; + DWORD ds3db_freq; BOOL ds3db_need_recalc; /* Used for bit depth conversion */ int mix_channels; diff --git a/dlls/dsound/sound3d.c b/dlls/dsound/sound3d.c index 939e0091815..4e98cdc0b8d 100644 --- a/dlls/dsound/sound3d.c +++ b/dlls/dsound/sound3d.c @@ -288,6 +288,8 @@ void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb) } TRACE("panning: Angle = %f rad, lPan = %ld\n", flAngle, dsb->volpan.lPan); + dsb->freq = dsb->ds3db_freq; + /* FIXME: Doppler Effect disabled since i have no idea which frequency to change and how to do it */ if(0) { @@ -310,16 +312,15 @@ if(0) if listener moves AWAY from buffer, its velocity component is NEGATIVE */ flListenerVel = ProjectVector(&dsb->device->ds3dl.vVelocity, &vDistance); /* formula taken from Gianicoli D.: Physics, 4th edition: */ - /* FIXME: replace dsb->freq with appropriate frequency ! */ - flFreq = dsb->freq * ((DEFAULT_VELOCITY + flListenerVel)/(DEFAULT_VELOCITY + flBufferVel)); + flFreq = dsb->ds3db_freq * ((DEFAULT_VELOCITY + flListenerVel)/(DEFAULT_VELOCITY + flBufferVel)); TRACE("doppler: Buffer velocity (component) = %f, Listener velocity (component) = %f => Doppler shift: %ld Hz -> %f Hz\n", - flBufferVel, flListenerVel, dsb->freq, flFreq); - /* FIXME: replace following line with correct frequency setting ! */ + flBufferVel, flListenerVel, dsb->ds3db_freq, flFreq); dsb->freq = flFreq; - DSOUND_RecalcFormat(dsb); } } + DSOUND_RecalcFormat(dsb); + for (i = 0; i < dsb->device->pwfx->nChannels; i++) dsb->volpan.dwTotalAmpFactor[i] = 0; -- 2.11.4.GIT