From 41b89ddd53d045ca57eb0c9103bada90dc295284 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Fri, 13 Feb 2004 20:22:02 +0000 Subject: [PATCH] Properly release hardware primary buffer when changing formats. --- dlls/dsound/primary.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/dlls/dsound/primary.c b/dlls/dsound/primary.c index 69e47c44a24..2dce6908a90 100644 --- a/dlls/dsound/primary.c +++ b/dlls/dsound/primary.c @@ -77,7 +77,7 @@ static HRESULT DSOUND_PrimaryOpen(IDirectSoundImpl *This) DSOUND_RecalcVolPan(&(This->volpan)); /* are we using waveOut stuff? */ - if (!This->hwbuf) { + if (!This->driver) { LPBYTE newbuf; DWORD buflen; HRESULT merr = DS_OK; @@ -141,6 +141,19 @@ static HRESULT DSOUND_PrimaryOpen(IDirectSoundImpl *This) err = mmErr(waveOutSetVolume(This->hwo, vol)); } } else { + if (!This->hwbuf) { + err = IDsDriver_CreateSoundBuffer(This->driver,&(This->wfx), + DSBCAPS_PRIMARYBUFFER,0, + &(This->buflen),&(This->buffer), + (LPVOID*)&(This->hwbuf)); + if (err != DS_OK) { + WARN("IDsDriver_CreateSoundBuffer failed\n"); + return err; + } + + if (dsound->state == STATE_PLAYING) dsound->state = STATE_STARTING; + else if (dsound->state == STATE_STOPPING) dsound->state = STATE_STOPPED; + } err = IDsDriverBuffer_SetVolumePan(This->hwbuf, &(This->volpan)); } @@ -161,6 +174,9 @@ static void DSOUND_PrimaryClose(IDirectSoundImpl *This) for (c=0; chwo, This->pwave[c], sizeof(WAVEHDR)); This->pwqueue = 0; + } else { + if (IDsDriverBuffer_Release(This->hwbuf) == 0) + This->hwbuf = 0; } } @@ -217,9 +233,11 @@ HRESULT DSOUND_PrimaryDestroy(IDirectSoundImpl *This) TRACE("(%p)\n",This); DSOUND_PrimaryClose(This); - if (This->hwbuf) { - if (IDsDriverBuffer_Release(This->hwbuf) == 0) - This->hwbuf = 0; + if (This->driver) { + if (This->hwbuf) { + if (IDsDriverBuffer_Release(This->hwbuf) == 0) + This->hwbuf = 0; + } } else { unsigned c; for (c=0; clock)); return err; } - } - if (dsound->hwbuf) { + } else if (dsound->hwbuf) { err = IDsDriverBuffer_SetFormat(dsound->hwbuf, &(dsound->wfx)); if (err == DSERR_BUFFERLOST) { /* Wine-only: the driver wants us to recreate the HW buffer */ -- 2.11.4.GIT