Commit 605cd62c authored by Maarten Lankhorst's avatar Maarten Lankhorst Committed by Alexandre Julliard

dsound: Create a primary_pwfx separately from pwfx.

parent a0f039a6
...@@ -305,21 +305,36 @@ static HRESULT WINAPI IDirectSound8Impl_SetCooperativeLevel(IDirectSound8 *iface ...@@ -305,21 +305,36 @@ static HRESULT WINAPI IDirectSound8Impl_SetCooperativeLevel(IDirectSound8 *iface
DWORD level) DWORD level)
{ {
IDirectSoundImpl *This = impl_from_IDirectSound8(iface); IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
DirectSoundDevice *device = This->device;
DWORD oldlevel;
HRESULT hr = S_OK;
TRACE("(%p,%p,%s)\n", This, hwnd, dumpCooperativeLevel(level)); TRACE("(%p,%p,%s)\n", This, hwnd, dumpCooperativeLevel(level));
if (!This->device) { if (!device) {
WARN("not initialized\n"); WARN("not initialized\n");
return DSERR_UNINITIALIZED; return DSERR_UNINITIALIZED;
} }
if (level == DSSCL_PRIORITY || level == DSSCL_EXCLUSIVE) { if (level == DSSCL_PRIORITY || level == DSSCL_EXCLUSIVE) {
WARN("level=%s not fully supported\n", WARN("level=%s not fully supported\n",
level == DSSCL_PRIORITY ? "DSSCL_PRIORITY" : "DSSCL_EXCLUSIVE"); level==DSSCL_PRIORITY ? "DSSCL_PRIORITY" : "DSSCL_EXCLUSIVE");
} }
This->device->priolevel = level; RtlAcquireResourceExclusive(&device->buffer_list_lock, TRUE);
return DS_OK; EnterCriticalSection(&device->mixlock);
oldlevel = device->priolevel;
device->priolevel = level;
if ((level == DSSCL_WRITEPRIMARY) != (oldlevel == DSSCL_WRITEPRIMARY)) {
hr = DSOUND_ReopenDevice(device, level == DSSCL_WRITEPRIMARY);
if (FAILED(hr))
device->priolevel = oldlevel;
else
DSOUND_PrimaryOpen(device);
}
LeaveCriticalSection(&device->mixlock);
RtlReleaseResource(&device->buffer_list_lock);
return hr;
} }
static HRESULT WINAPI IDirectSound8Impl_Compact(IDirectSound8 *iface) static HRESULT WINAPI IDirectSound8Impl_Compact(IDirectSound8 *iface)
...@@ -612,20 +627,24 @@ static HRESULT DirectSoundDevice_Create(DirectSoundDevice ** ppDevice) ...@@ -612,20 +627,24 @@ static HRESULT DirectSoundDevice_Create(DirectSoundDevice ** ppDevice)
device->guid = GUID_NULL; device->guid = GUID_NULL;
/* Set default wave format (may need it for waveOutOpen) */ /* Set default wave format (may need it for waveOutOpen) */
device->pwfx = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(WAVEFORMATEX)); device->pwfx = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(WAVEFORMATEXTENSIBLE));
if (device->pwfx == NULL) { device->primary_pwfx = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(WAVEFORMATEXTENSIBLE));
if (!device->pwfx || !device->primary_pwfx) {
WARN("out of memory\n"); WARN("out of memory\n");
HeapFree(GetProcessHeap(),0,device->primary_pwfx);
HeapFree(GetProcessHeap(),0,device->pwfx);
HeapFree(GetProcessHeap(),0,device); HeapFree(GetProcessHeap(),0,device);
return DSERR_OUTOFMEMORY; return DSERR_OUTOFMEMORY;
} }
device->pwfx->wFormatTag = WAVE_FORMAT_PCM; device->pwfx->wFormatTag = WAVE_FORMAT_PCM;
device->pwfx->nSamplesPerSec = ds_default_sample_rate; device->pwfx->nSamplesPerSec = 22050;
device->pwfx->wBitsPerSample = ds_default_bits_per_sample; device->pwfx->wBitsPerSample = 8;
device->pwfx->nChannels = 2; device->pwfx->nChannels = 2;
device->pwfx->nBlockAlign = device->pwfx->wBitsPerSample * device->pwfx->nChannels / 8; device->pwfx->nBlockAlign = device->pwfx->wBitsPerSample * device->pwfx->nChannels / 8;
device->pwfx->nAvgBytesPerSec = device->pwfx->nSamplesPerSec * device->pwfx->nBlockAlign; device->pwfx->nAvgBytesPerSec = device->pwfx->nSamplesPerSec * device->pwfx->nBlockAlign;
device->pwfx->cbSize = 0; device->pwfx->cbSize = 0;
memcpy(device->primary_pwfx, device->pwfx, sizeof(*device->pwfx));
InitializeCriticalSection(&(device->mixlock)); InitializeCriticalSection(&(device->mixlock));
device->mixlock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": DirectSoundDevice.mixlock"); device->mixlock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": DirectSoundDevice.mixlock");
......
...@@ -93,8 +93,6 @@ WCHAR wine_vxd_drv[] = { 'w','i','n','e','m','m','.','v','x','d', 0 }; ...@@ -93,8 +93,6 @@ WCHAR wine_vxd_drv[] = { 'w','i','n','e','m','m','.','v','x','d', 0 };
/* All default settings, you most likely don't want to touch these, see wiki on UsefulRegistryKeys */ /* All default settings, you most likely don't want to touch these, see wiki on UsefulRegistryKeys */
int ds_hel_buflen = 32768 * 2; int ds_hel_buflen = 32768 * 2;
int ds_snd_queue_max = 10; int ds_snd_queue_max = 10;
int ds_default_sample_rate = 44100;
int ds_default_bits_per_sample = 16;
static HINSTANCE instance; static HINSTANCE instance;
/* /*
...@@ -151,19 +149,11 @@ void setup_dsound_options(void) ...@@ -151,19 +149,11 @@ void setup_dsound_options(void)
ds_snd_queue_max = atoi(buffer); ds_snd_queue_max = atoi(buffer);
if (!get_config_key( hkey, appkey, "DefaultSampleRate", buffer, MAX_PATH ))
ds_default_sample_rate = atoi(buffer);
if (!get_config_key( hkey, appkey, "DefaultBitsPerSample", buffer, MAX_PATH ))
ds_default_bits_per_sample = atoi(buffer);
if (appkey) RegCloseKey( appkey ); if (appkey) RegCloseKey( appkey );
if (hkey) RegCloseKey( hkey ); if (hkey) RegCloseKey( hkey );
TRACE("ds_hel_buflen = %d\n", ds_hel_buflen); TRACE("ds_hel_buflen = %d\n", ds_hel_buflen);
TRACE("ds_snd_queue_max = %d\n", ds_snd_queue_max); TRACE("ds_snd_queue_max = %d\n", ds_snd_queue_max);
TRACE("ds_default_sample_rate = %d\n", ds_default_sample_rate);
TRACE("ds_default_bits_per_sample = %d\n", ds_default_bits_per_sample);
} }
static const char * get_device_id(LPCGUID pGuid) static const char * get_device_id(LPCGUID pGuid)
......
...@@ -32,9 +32,6 @@ ...@@ -32,9 +32,6 @@
extern int ds_hel_buflen DECLSPEC_HIDDEN; extern int ds_hel_buflen DECLSPEC_HIDDEN;
extern int ds_snd_queue_max DECLSPEC_HIDDEN; extern int ds_snd_queue_max DECLSPEC_HIDDEN;
extern int ds_snd_shadow_maxsize DECLSPEC_HIDDEN;
extern int ds_default_sample_rate DECLSPEC_HIDDEN;
extern int ds_default_bits_per_sample DECLSPEC_HIDDEN;
/***************************************************************************** /*****************************************************************************
* Predeclare the interface implementation structures * Predeclare the interface implementation structures
...@@ -72,8 +69,8 @@ struct DirectSoundDevice ...@@ -72,8 +69,8 @@ struct DirectSoundDevice
GUID guid; GUID guid;
DSCAPS drvcaps; DSCAPS drvcaps;
DWORD priolevel; DWORD priolevel;
PWAVEFORMATEX pwfx; PWAVEFORMATEX pwfx, primary_pwfx;
UINT timerID, playing_offs_bytes, in_mmdev_bytes, prebuf, helfrags; UINT timerID, playing_offs_bytes, in_mmdev_bytes, prebuf;
DWORD fraglen; DWORD fraglen;
LPBYTE buffer; LPBYTE buffer;
DWORD writelead, buflen, state, playpos, mixpos; DWORD writelead, buflen, state, playpos, mixpos;
...@@ -211,6 +208,7 @@ HRESULT DSOUND_PrimaryStop(DirectSoundDevice *device) DECLSPEC_HIDDEN; ...@@ -211,6 +208,7 @@ HRESULT DSOUND_PrimaryStop(DirectSoundDevice *device) DECLSPEC_HIDDEN;
HRESULT DSOUND_PrimaryGetPosition(DirectSoundDevice *device, LPDWORD playpos, LPDWORD writepos) DECLSPEC_HIDDEN; HRESULT DSOUND_PrimaryGetPosition(DirectSoundDevice *device, LPDWORD playpos, LPDWORD writepos) DECLSPEC_HIDDEN;
LPWAVEFORMATEX DSOUND_CopyFormat(LPCWAVEFORMATEX wfex) DECLSPEC_HIDDEN; LPWAVEFORMATEX DSOUND_CopyFormat(LPCWAVEFORMATEX wfex) DECLSPEC_HIDDEN;
HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave) DECLSPEC_HIDDEN; HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave) DECLSPEC_HIDDEN;
HRESULT DSOUND_PrimaryOpen(DirectSoundDevice *device) DECLSPEC_HIDDEN;
HRESULT primarybuffer_create(DirectSoundDevice *device, IDirectSoundBufferImpl **ppdsb, HRESULT primarybuffer_create(DirectSoundDevice *device, IDirectSoundBufferImpl **ppdsb,
const DSBUFFERDESC *dsbd) DECLSPEC_HIDDEN; const DSBUFFERDESC *dsbd) DECLSPEC_HIDDEN;
void primarybuffer_destroy(IDirectSoundBufferImpl *This) DECLSPEC_HIDDEN; void primarybuffer_destroy(IDirectSoundBufferImpl *This) DECLSPEC_HIDDEN;
......
...@@ -112,6 +112,7 @@ void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb) ...@@ -112,6 +112,7 @@ void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb)
TRACE("(%p)\n",dsb); TRACE("(%p)\n",dsb);
pwfxe = (WAVEFORMATEXTENSIBLE *) dsb->pwfx; pwfxe = (WAVEFORMATEXTENSIBLE *) dsb->pwfx;
dsb->freqAdjust = (float)dsb->freq / dsb->device->pwfx->nSamplesPerSec;
if ((pwfxe->Format.wFormatTag == WAVE_FORMAT_IEEE_FLOAT) || ((pwfxe->Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE) if ((pwfxe->Format.wFormatTag == WAVE_FORMAT_IEEE_FLOAT) || ((pwfxe->Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE)
&& (IsEqualGUID(&pwfxe->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)))) && (IsEqualGUID(&pwfxe->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT))))
......
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