dsound: Base fragment size off of the MMDevice's period.

This commit is contained in:
Andrew Eikum 2012-05-14 12:31:13 -05:00 committed by Alexandre Julliard
parent 1053bfb48d
commit 7dce1418ff
2 changed files with 15 additions and 28 deletions

View File

@ -276,7 +276,6 @@ HRESULT DSOUND_Create8(REFIID riid, LPDIRECTSOUND8 *ppDS) DECLSPEC_HIDDEN;
/* primary.c */ /* primary.c */
DWORD DSOUND_fraglen(DWORD nSamplesPerSec, DWORD nBlockAlign) DECLSPEC_HIDDEN;
HRESULT DSOUND_PrimaryCreate(DirectSoundDevice *device) DECLSPEC_HIDDEN; HRESULT DSOUND_PrimaryCreate(DirectSoundDevice *device) DECLSPEC_HIDDEN;
HRESULT DSOUND_PrimaryDestroy(DirectSoundDevice *device) DECLSPEC_HIDDEN; HRESULT DSOUND_PrimaryDestroy(DirectSoundDevice *device) DECLSPEC_HIDDEN;
HRESULT DSOUND_PrimaryPlay(DirectSoundDevice *device) DECLSPEC_HIDDEN; HRESULT DSOUND_PrimaryPlay(DirectSoundDevice *device) DECLSPEC_HIDDEN;

View File

@ -40,41 +40,29 @@
WINE_DEFAULT_DEBUG_CHANNEL(dsound); WINE_DEFAULT_DEBUG_CHANNEL(dsound);
/** Calculate how long a fragment length of about 10 ms should be in frames static DWORD DSOUND_fraglen(DirectSoundDevice *device)
*
* nSamplesPerSec: Frequency rate in samples per second
* nBlockAlign: Size of a single blockalign
*
* Returns:
* Size in bytes of a single fragment
*/
DWORD DSOUND_fraglen(DWORD nSamplesPerSec, DWORD nBlockAlign)
{ {
/* Given a timer delay of 10ms, the fragment size is approximately: REFERENCE_TIME period;
* fraglen = (nSamplesPerSec * 10 / 1000) * nBlockAlign HRESULT hr;
* ==> fraglen = (nSamplesPerSec / 100) * nBlockSize DWORD ret;
*
* ALSA uses buffers that are powers of 2. Because of this, fraglen
* is rounded up to the nearest power of 2:
*/
if (nSamplesPerSec <= 12800) hr = IAudioClient_GetDevicePeriod(device->client, &period, NULL);
return 128 * nBlockAlign; 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);
if (nSamplesPerSec <= 25600) ret -= ret % device->pwfx->nBlockAlign;
return 256 * nBlockAlign; return ret;
if (nSamplesPerSec <= 51200)
return 512 * nBlockAlign;
return 1024 * nBlockAlign;
} }
static void DSOUND_RecalcPrimary(DirectSoundDevice *device) static void DSOUND_RecalcPrimary(DirectSoundDevice *device)
{ {
TRACE("(%p)\n", device); TRACE("(%p)\n", device);
device->fraglen = DSOUND_fraglen(device->pwfx->nSamplesPerSec, device->pwfx->nBlockAlign); device->fraglen = DSOUND_fraglen(device);
device->helfrags = device->buflen / device->fraglen; device->helfrags = device->buflen / device->fraglen;
TRACE("fraglen=%d helfrags=%d\n", device->fraglen, device->helfrags); TRACE("fraglen=%d helfrags=%d\n", device->fraglen, device->helfrags);
@ -114,7 +102,7 @@ HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave)
return hres; return hres;
} }
prebuf_frames = device->prebuf * DSOUND_fraglen(device->pwfx->nSamplesPerSec, device->pwfx->nBlockAlign) / device->pwfx->nBlockAlign; prebuf_frames = device->prebuf * DSOUND_fraglen(device) / device->pwfx->nBlockAlign;
prebuf_rt = (10000000 * (UINT64)prebuf_frames) / device->pwfx->nSamplesPerSec; prebuf_rt = (10000000 * (UINT64)prebuf_frames) / device->pwfx->nSamplesPerSec;
hres = IAudioClient_Initialize(device->client, hres = IAudioClient_Initialize(device->client,