Commit a4a9d50d authored by Maarten Lankhorst's avatar Maarten Lankhorst Committed by Alexandre Julliard

dsound: Fix volume and panning for primary buffer.

Fixes failing dsound tests in wine.
parent d3908e69
...@@ -1471,7 +1471,7 @@ HRESULT DirectSoundDevice_Initialize(DirectSoundDevice ** ppDevice, LPCGUID lpcG ...@@ -1471,7 +1471,7 @@ HRESULT DirectSoundDevice_Initialize(DirectSoundDevice ** ppDevice, LPCGUID lpcG
device->drvcaps.dwFlags |= DSCAPS_EMULDRIVER; device->drvcaps.dwFlags |= DSCAPS_EMULDRIVER;
device->drvcaps.dwMinSecondarySampleRate = DSBFREQUENCY_MIN; device->drvcaps.dwMinSecondarySampleRate = DSBFREQUENCY_MIN;
device->drvcaps.dwMaxSecondarySampleRate = DSBFREQUENCY_MAX; device->drvcaps.dwMaxSecondarySampleRate = DSBFREQUENCY_MAX;
device->drvcaps.dwPrimaryBuffers = 1; ZeroMemory(&device->volpan, sizeof(device->volpan));
} }
hr = DSOUND_PrimaryCreate(device); hr = DSOUND_PrimaryCreate(device);
......
...@@ -108,6 +108,8 @@ struct DirectSoundDevice ...@@ -108,6 +108,8 @@ struct DirectSoundDevice
LPBYTE tmp_buffer, mix_buffer; LPBYTE tmp_buffer, mix_buffer;
DWORD tmp_buffer_len, mix_buffer_len; DWORD tmp_buffer_len, mix_buffer_len;
DSVOLUMEPAN volpan;
mixfunc mixfunction; mixfunc mixfunction;
normfunc normfunction; normfunc normfunction;
......
...@@ -169,6 +169,9 @@ static HRESULT DSOUND_PrimaryOpen(DirectSoundDevice *device) ...@@ -169,6 +169,9 @@ static HRESULT DSOUND_PrimaryOpen(DirectSoundDevice *device)
return err; return err;
} }
} }
if (device->hwbuf)
IDsDriverBuffer_SetVolumePan(device->hwbuf, &device->volpan);
DSOUND_RecalcPrimary(device); DSOUND_RecalcPrimary(device);
device->prebuf = ds_snd_queue_max; device->prebuf = ds_snd_queue_max;
if (device->helfrags < ds_snd_queue_min) if (device->helfrags < ds_snd_queue_min)
...@@ -582,7 +585,6 @@ static HRESULT WINAPI PrimaryBufferImpl_SetVolume( ...@@ -582,7 +585,6 @@ static HRESULT WINAPI PrimaryBufferImpl_SetVolume(
) { ) {
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device; DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
DWORD ampfactors; DWORD ampfactors;
DSVOLUMEPAN volpan;
HRESULT hres = DS_OK; HRESULT hres = DS_OK;
TRACE("(%p,%d)\n", iface, vol); TRACE("(%p,%d)\n", iface, vol);
...@@ -600,18 +602,18 @@ static HRESULT WINAPI PrimaryBufferImpl_SetVolume( ...@@ -600,18 +602,18 @@ static HRESULT WINAPI PrimaryBufferImpl_SetVolume(
EnterCriticalSection(&(device->mixlock)); EnterCriticalSection(&(device->mixlock));
waveOutGetVolume(device->hwo, &ampfactors); waveOutGetVolume(device->hwo, &ampfactors);
volpan.dwTotalLeftAmpFactor=ampfactors & 0xffff; device->volpan.dwTotalLeftAmpFactor=ampfactors & 0xffff;
volpan.dwTotalRightAmpFactor=ampfactors >> 16; device->volpan.dwTotalRightAmpFactor=ampfactors >> 16;
DSOUND_AmpFactorToVolPan(&volpan); DSOUND_AmpFactorToVolPan(&device->volpan);
if (vol != volpan.lVolume) { if (vol != device->volpan.lVolume) {
volpan.lVolume=vol; device->volpan.lVolume=vol;
DSOUND_RecalcVolPan(&volpan); DSOUND_RecalcVolPan(&device->volpan);
if (device->hwbuf) { if (device->hwbuf) {
hres = IDsDriverBuffer_SetVolumePan(device->hwbuf, &volpan); hres = IDsDriverBuffer_SetVolumePan(device->hwbuf, &device->volpan);
if (hres != DS_OK) if (hres != DS_OK)
WARN("IDsDriverBuffer_SetVolumePan failed\n"); WARN("IDsDriverBuffer_SetVolumePan failed\n");
} else { } else {
ampfactors = (volpan.dwTotalLeftAmpFactor & 0xffff) | (volpan.dwTotalRightAmpFactor << 16); ampfactors = (device->volpan.dwTotalLeftAmpFactor & 0xffff) | (device->volpan.dwTotalRightAmpFactor << 16);
waveOutSetVolume(device->hwo, ampfactors); waveOutSetVolume(device->hwo, ampfactors);
} }
} }
...@@ -627,7 +629,6 @@ static HRESULT WINAPI PrimaryBufferImpl_GetVolume( ...@@ -627,7 +629,6 @@ static HRESULT WINAPI PrimaryBufferImpl_GetVolume(
) { ) {
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device; DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
DWORD ampfactors; DWORD ampfactors;
DSVOLUMEPAN volpan;
TRACE("(%p,%p)\n", iface, vol); TRACE("(%p,%p)\n", iface, vol);
if (!(device->dsbd.dwFlags & DSBCAPS_CTRLVOLUME)) { if (!(device->dsbd.dwFlags & DSBCAPS_CTRLVOLUME)) {
...@@ -640,11 +641,14 @@ static HRESULT WINAPI PrimaryBufferImpl_GetVolume( ...@@ -640,11 +641,14 @@ static HRESULT WINAPI PrimaryBufferImpl_GetVolume(
return DSERR_INVALIDPARAM; return DSERR_INVALIDPARAM;
} }
if (!device->hwbuf)
{
waveOutGetVolume(device->hwo, &ampfactors); waveOutGetVolume(device->hwo, &ampfactors);
volpan.dwTotalLeftAmpFactor=ampfactors & 0xffff; device->volpan.dwTotalLeftAmpFactor=ampfactors & 0xffff;
volpan.dwTotalRightAmpFactor=ampfactors >> 16; device->volpan.dwTotalRightAmpFactor=ampfactors >> 16;
DSOUND_AmpFactorToVolPan(&volpan); DSOUND_AmpFactorToVolPan(&device->volpan);
*vol = volpan.lVolume; }
*vol = device->volpan.lVolume;
return DS_OK; return DS_OK;
} }
...@@ -907,7 +911,6 @@ static HRESULT WINAPI PrimaryBufferImpl_SetPan( ...@@ -907,7 +911,6 @@ static HRESULT WINAPI PrimaryBufferImpl_SetPan(
) { ) {
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device; DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
DWORD ampfactors; DWORD ampfactors;
DSVOLUMEPAN volpan;
HRESULT hres = DS_OK; HRESULT hres = DS_OK;
TRACE("(%p,%d)\n", iface, pan); TRACE("(%p,%d)\n", iface, pan);
...@@ -924,19 +927,22 @@ static HRESULT WINAPI PrimaryBufferImpl_SetPan( ...@@ -924,19 +927,22 @@ static HRESULT WINAPI PrimaryBufferImpl_SetPan(
/* **** */ /* **** */
EnterCriticalSection(&(device->mixlock)); EnterCriticalSection(&(device->mixlock));
if (!device->hwbuf)
{
waveOutGetVolume(device->hwo, &ampfactors); waveOutGetVolume(device->hwo, &ampfactors);
volpan.dwTotalLeftAmpFactor=ampfactors & 0xffff; device->volpan.dwTotalLeftAmpFactor=ampfactors & 0xffff;
volpan.dwTotalRightAmpFactor=ampfactors >> 16; device->volpan.dwTotalRightAmpFactor=ampfactors >> 16;
DSOUND_AmpFactorToVolPan(&volpan); DSOUND_AmpFactorToVolPan(&device->volpan);
if (pan != volpan.lPan) { }
volpan.lPan=pan; if (pan != device->volpan.lPan) {
DSOUND_RecalcVolPan(&volpan); device->volpan.lPan=pan;
DSOUND_RecalcVolPan(&device->volpan);
if (device->hwbuf) { if (device->hwbuf) {
hres = IDsDriverBuffer_SetVolumePan(device->hwbuf, &volpan); hres = IDsDriverBuffer_SetVolumePan(device->hwbuf, &device->volpan);
if (hres != DS_OK) if (hres != DS_OK)
WARN("IDsDriverBuffer_SetVolumePan failed\n"); WARN("IDsDriverBuffer_SetVolumePan failed\n");
} else { } else {
ampfactors = (volpan.dwTotalLeftAmpFactor & 0xffff) | (volpan.dwTotalRightAmpFactor << 16); ampfactors = (device->volpan.dwTotalLeftAmpFactor & 0xffff) | (device->volpan.dwTotalRightAmpFactor << 16);
waveOutSetVolume(device->hwo, ampfactors); waveOutSetVolume(device->hwo, ampfactors);
} }
} }
...@@ -952,7 +958,6 @@ static HRESULT WINAPI PrimaryBufferImpl_GetPan( ...@@ -952,7 +958,6 @@ static HRESULT WINAPI PrimaryBufferImpl_GetPan(
) { ) {
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device; DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
DWORD ampfactors; DWORD ampfactors;
DSVOLUMEPAN volpan;
TRACE("(%p,%p)\n", iface, pan); TRACE("(%p,%p)\n", iface, pan);
if (!(device->dsbd.dwFlags & DSBCAPS_CTRLPAN)) { if (!(device->dsbd.dwFlags & DSBCAPS_CTRLPAN)) {
...@@ -965,11 +970,14 @@ static HRESULT WINAPI PrimaryBufferImpl_GetPan( ...@@ -965,11 +970,14 @@ static HRESULT WINAPI PrimaryBufferImpl_GetPan(
return DSERR_INVALIDPARAM; return DSERR_INVALIDPARAM;
} }
if (!device->hwbuf)
{
waveOutGetVolume(device->hwo, &ampfactors); waveOutGetVolume(device->hwo, &ampfactors);
volpan.dwTotalLeftAmpFactor=ampfactors & 0xffff; device->volpan.dwTotalLeftAmpFactor=ampfactors & 0xffff;
volpan.dwTotalRightAmpFactor=ampfactors >> 16; device->volpan.dwTotalRightAmpFactor=ampfactors >> 16;
DSOUND_AmpFactorToVolPan(&volpan); DSOUND_AmpFactorToVolPan(&device->volpan);
*pan = volpan.lPan; }
*pan = device->volpan.lPan;
return DS_OK; return DS_OK;
} }
......
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