Commit 569ed159 authored by Maarten Lankhorst's avatar Maarten Lankhorst Committed by Alexandre Julliard

dsound: Use AudioClient buffer statistics.

parent 77184106
......@@ -158,7 +158,6 @@ static HRESULT DirectSoundDevice_Create(DirectSoundDevice ** ppDevice)
device->ds3dl.flRolloffFactor = DS3D_DEFAULTROLLOFFFACTOR;
device->ds3dl.flDopplerFactor = DS3D_DEFAULTDOPPLERFACTOR;
device->prebuf = ds_snd_queue_max;
device->guid = GUID_NULL;
/* Set default wave format (may need it for waveOutOpen) */
......
......@@ -93,7 +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 */
int ds_hel_buflen = 32768 * 2;
int ds_snd_queue_max = 10;
static HINSTANCE instance;
/*
......@@ -146,15 +145,10 @@ void setup_dsound_options(void)
if (!get_config_key( hkey, appkey, "HelBuflen", buffer, MAX_PATH ))
ds_hel_buflen = atoi(buffer);
if (!get_config_key( hkey, appkey, "SndQueueMax", buffer, MAX_PATH ))
ds_snd_queue_max = atoi(buffer);
if (appkey) RegCloseKey( appkey );
if (hkey) RegCloseKey( hkey );
TRACE("ds_hel_buflen = %d\n", ds_hel_buflen);
TRACE("ds_snd_queue_max = %d\n", ds_snd_queue_max);
}
static const char * get_device_id(LPCGUID pGuid)
......
......@@ -35,7 +35,6 @@
#define DS_MAX_CHANNELS 6
extern int ds_hel_buflen DECLSPEC_HIDDEN;
extern int ds_snd_queue_max DECLSPEC_HIDDEN;
/*****************************************************************************
* Predeclare the interface implementation structures
......@@ -76,10 +75,9 @@ struct DirectSoundDevice
DSCAPS drvcaps;
DWORD priolevel, sleeptime;
PWAVEFORMATEX pwfx, primary_pwfx;
UINT playing_offs_bytes, in_mmdev_bytes, prebuf;
DWORD fraglen;
UINT playing_offs_bytes, in_mmdev_bytes;
LPBYTE buffer;
DWORD writelead, buflen, state, playpos, mixpos;
DWORD writelead, buflen, aclen, fraglen, state, playpos, pad;
int nrofbuffers;
IDirectSoundBufferImpl** buffers;
RTL_RWLOCK buffer_list_lock;
......@@ -211,7 +209,6 @@ HRESULT DSOUND_PrimaryCreate(DirectSoundDevice *device) DECLSPEC_HIDDEN;
HRESULT DSOUND_PrimaryDestroy(DirectSoundDevice *device) DECLSPEC_HIDDEN;
HRESULT DSOUND_PrimaryPlay(DirectSoundDevice *device) DECLSPEC_HIDDEN;
HRESULT DSOUND_PrimaryStop(DirectSoundDevice *device) DECLSPEC_HIDDEN;
HRESULT DSOUND_PrimaryGetPosition(DirectSoundDevice *device, LPDWORD playpos, LPDWORD writepos) DECLSPEC_HIDDEN;
LPWAVEFORMATEX DSOUND_CopyFormat(LPCWAVEFORMATEX wfex) DECLSPEC_HIDDEN;
HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave) DECLSPEC_HIDDEN;
HRESULT DSOUND_PrimaryOpen(DirectSoundDevice *device) DECLSPEC_HIDDEN;
......
......@@ -40,24 +40,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(dsound);
static DWORD DSOUND_fraglen(DirectSoundDevice *device)
{
REFERENCE_TIME period;
HRESULT hr;
DWORD ret;
hr = IAudioClient_GetDevicePeriod(device->client, &period, NULL);
if(FAILED(hr)){
/* just guess at 10ms */
WARN("GetDevicePeriod failed: %08x\n", hr);
ret = MulDiv(device->pwfx->nBlockAlign, device->pwfx->nSamplesPerSec, 100);
}else
ret = MulDiv(device->pwfx->nSamplesPerSec * device->pwfx->nBlockAlign, period, 10000000);
ret -= ret % device->pwfx->nBlockAlign;
return ret;
}
static DWORD speaker_config_to_channel_mask(DWORD speaker_config)
{
switch (DSSPEAKER_CONFIG(speaker_config)) {
......@@ -217,11 +199,10 @@ static HRESULT DSOUND_WaveFormat(DirectSoundDevice *device, IAudioClient *client
HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave)
{
UINT prebuf_frames;
REFERENCE_TIME prebuf_rt;
WAVEFORMATEX *wfx = NULL;
HRESULT hres;
REFERENCE_TIME period;
REFERENCE_TIME period, buflen = 800000;
UINT32 frames;
DWORD period_ms;
TRACE("(%p, %d)\n", device, forcewave);
......@@ -243,6 +224,12 @@ HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave)
device->volume = NULL;
}
if (device->pad) {
device->playpos += device->pad;
device->playpos %= device->buflen;
device->pad = 0;
}
hres = IMMDevice_Activate(device->mmdevice, &IID_IAudioClient,
CLSCTX_INPROC_SERVER, NULL, (void **)&device->client);
if(FAILED(hres)) {
......@@ -263,12 +250,9 @@ HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave)
HeapFree(GetProcessHeap(), 0, device->pwfx);
device->pwfx = wfx;
prebuf_frames = device->prebuf * DSOUND_fraglen(device) / device->pwfx->nBlockAlign;
prebuf_rt = (10000000 * (UINT64)prebuf_frames) / device->pwfx->nSamplesPerSec;
hres = IAudioClient_Initialize(device->client,
AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_NOPERSIST |
AUDCLNT_STREAMFLAGS_EVENTCALLBACK, prebuf_rt, 0, device->pwfx, NULL);
AUDCLNT_STREAMFLAGS_EVENTCALLBACK, buflen, 0, device->pwfx, NULL);
if(FAILED(hres)){
IAudioClient_Release(device->client);
device->client = NULL;
......@@ -318,10 +302,19 @@ HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave)
hres = IAudioClient_GetStreamLatency(device->client, &period);
if (FAILED(hres)) {
WARN("GetStreamLatency failed with %08x\n", hres);
period_ms = 10;
} else
period_ms = (period + 9999) / 10000;
TRACE("period %u ms fraglen %u prebuf %u\n", period_ms, device->fraglen, device->prebuf);
period = 100000;
}
period_ms = (period + 9999) / 10000;
hres = IAudioClient_GetBufferSize(device->client, &frames);
if (FAILED(hres)) {
WARN("GetBufferSize failed with %08x\n", hres);
frames = (UINT64)device->pwfx->nSamplesPerSec * buflen / 10000000;
}
device->fraglen = MulDiv(device->pwfx->nSamplesPerSec, period, 10000000) * device->pwfx->nBlockAlign;
device->aclen = frames * device->pwfx->nBlockAlign;
TRACE("period %u ms fraglen %u buflen %u\n", period_ms, device->fraglen, device->aclen);
if (period_ms < 3)
device->sleeptime = 5;
......@@ -339,17 +332,11 @@ HRESULT DSOUND_PrimaryOpen(DirectSoundDevice *device)
TRACE("(%p)\n", device);
device->fraglen = DSOUND_fraglen(device);
/* on original windows, the buffer it set to a fixed size, no matter what the settings are.
on windows this size is always fixed (tested on win-xp) */
if (!device->buflen)
device->buflen = ds_hel_buflen;
device->buflen -= device->buflen % device->pwfx->nBlockAlign;
while(device->buflen < device->fraglen * device->prebuf){
device->buflen += ds_hel_buflen;
device->buflen -= device->buflen % device->pwfx->nBlockAlign;
}
HeapFree(GetProcessHeap(), 0, device->mix_buffer);
device->mix_buffer_len = (device->buflen / (device->pwfx->wBitsPerSample / 8)) * sizeof(float);
......@@ -419,9 +406,6 @@ static void DSOUND_PrimaryClose(DirectSoundDevice *device)
if(FAILED(hr))
WARN("Stop failed: %08x\n", hr);
}
/* clear the queue */
device->in_mmdev_bytes = 0;
}
HRESULT DSOUND_PrimaryCreate(DirectSoundDevice *device)
......
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