Commit ef275fac authored by Anton Baskanov's avatar Anton Baskanov Committed by Alexandre Julliard

dsound: Store the frequency of 3D buffers separately.

parent 0433db1e
......@@ -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 */
......
......@@ -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;
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment