Commit e49a5c22 authored by Robert Reif's avatar Robert Reif Committed by Alexandre Julliard

dsound: Refactor playback.

Replace references of IDirectSoundImpl with DirectSoundDevice to remove one level of indirection and remove the problem of a three object circular reference.
parent ead00327
......@@ -277,7 +277,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_SetFrequency(
oldFreq = This->freq;
This->freq = freq;
if (freq != oldFreq) {
This->freqAdjust = (freq << DSOUND_FREQSHIFT) / This->dsound->device->pwfx->nSamplesPerSec;
This->freqAdjust = (freq << DSOUND_FREQSHIFT) / This->device->pwfx->nSamplesPerSec;
This->nAvgBytesPerSec = freq * This->pwfx->nBlockAlign;
DSOUND_RecalcFormat(This);
if (!This->hwbuf)
......@@ -364,14 +364,14 @@ static ULONG WINAPI IDirectSoundBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface)
TRACE("(%p) ref was %ld\n", This, ref + 1);
if (!ref) {
DSOUND_RemoveBuffer(This->dsound, This);
DSOUND_RemoveBuffer(This->device, This);
This->lock.DebugInfo->Spare[0] = 0;
DeleteCriticalSection(&(This->lock));
if (This->hwbuf) {
IDsDriverBuffer_Release(This->hwbuf);
if (This->dsound->device->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) {
if (This->device->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) {
This->buffer->ref--;
if (This->buffer->ref==0) {
HeapFree(GetProcessHeap(),0,This->buffer->memory);
......@@ -399,22 +399,23 @@ DWORD DSOUND_CalcPlayPosition(IDirectSoundBufferImpl *This, DWORD pplay, DWORD p
{
DWORD bplay = This->buf_mixpos;
DWORD pmix = This->primary_mixpos;
DirectSoundDevice * device = This->device;
TRACE("(%p, pplay=%lu, pwrite=%lu)\n", This, pplay, pwrite);
/* the actual primary play position (pplay) is always behind last mixed (pmix),
* unless the computer is too slow or something */
/* we need to know how far away we are from there */
if (pmix < pplay) pmix += This->dsound->device->buflen; /* wraparound */
if (pmix < pplay) pmix += device->buflen; /* wraparound */
pmix -= pplay;
/* detect buffer underrun */
if (pwrite < pplay) pwrite += This->dsound->device->buflen; /* wraparound */
if (pwrite < pplay) pwrite += device->buflen; /* wraparound */
pwrite -= pplay;
if (pmix > (ds_snd_queue_max * This->dsound->device->fraglen + pwrite + This->dsound->device->writelead)) {
if (pmix > (ds_snd_queue_max * device->fraglen + pwrite + device->writelead)) {
WARN("detected an underrun: primary queue was %ld\n",pmix);
pmix = 0;
}
/* divide the offset by its sample size */
pmix /= This->dsound->device->pwfx->nBlockAlign;
pmix /= device->pwfx->nBlockAlign;
TRACE("primary back-samples=%ld\n",pmix);
/* adjust for our frequency */
pmix = (pmix * This->freqAdjust) >> DSOUND_FREQSHIFT;
......@@ -452,13 +453,13 @@ static HRESULT WINAPI IDirectSoundBufferImpl_GetCurrentPosition(
} else if (playpos) {
DWORD pplay, pwrite;
/* let's get this exact; first, recursively call GetPosition on the primary */
EnterCriticalSection(&(This->dsound->device->mixlock));
if (DSOUND_PrimaryGetPosition(This->dsound->device, &pplay, &pwrite) != DS_OK)
EnterCriticalSection(&(This->device->mixlock));
if (DSOUND_PrimaryGetPosition(This->device, &pplay, &pwrite) != DS_OK)
WARN("DSOUND_PrimaryGetPosition failed\n");
/* detect HEL mode underrun */
if (!(This->dsound->device->hwbuf || This->dsound->device->pwqueue))
if (!(This->device->hwbuf || This->device->pwqueue))
TRACE("detected an underrun\n");
if ((This->dsbd.dwFlags & DSBCAPS_GETCURRENTPOSITION2) || This->dsound->device->hwbuf) {
if ((This->dsbd.dwFlags & DSBCAPS_GETCURRENTPOSITION2) || This->device->hwbuf) {
/* calculate play position using this */
*playpos = DSOUND_CalcPlayPosition(This, pplay, pwrite);
} else {
......@@ -468,11 +469,11 @@ static HRESULT WINAPI IDirectSoundBufferImpl_GetCurrentPosition(
* behind write cursor, hmm... */
/* let's just do what might work for Half-Life */
DWORD wp;
wp = (This->dsound->device->pwplay + ds_hel_margin) * This->dsound->device->fraglen;
wp %= This->dsound->device->buflen;
wp = (This->device->pwplay + ds_hel_margin) * This->device->fraglen;
wp %= This->device->buflen;
*playpos = DSOUND_CalcPlayPosition(This, wp, pwrite);
}
LeaveCriticalSection(&(This->dsound->device->mixlock));
LeaveCriticalSection(&(This->device->mixlock));
}
if (writepos)
*writepos = This->buf_mixpos;
......@@ -595,7 +596,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Lock(
else
This->probably_valid_to = writecursor;
if (!(This->dsound->device->drvdesc.dwFlags & DSDDESC_DONTNEEDSECONDARYLOCK) && This->hwbuf) {
if (!(This->device->drvdesc.dwFlags & DSDDESC_DONTNEEDSECONDARYLOCK) && This->hwbuf) {
hres = IDsDriverBuffer_Lock(This->hwbuf,
lplpaudioptr1, audiobytes1,
lplpaudioptr2, audiobytes2,
......@@ -748,7 +749,7 @@ static HRESULT WINAPI IDirectSoundBufferImpl_Unlock(
/* **** */
EnterCriticalSection(&(This->lock));
if (!(This->dsound->device->drvdesc.dwFlags & DSDDESC_DONTNEEDSECONDARYLOCK) && This->hwbuf) {
if (!(This->device->drvdesc.dwFlags & DSDDESC_DONTNEEDSECONDARYLOCK) && This->hwbuf) {
hres = IDsDriverBuffer_Unlock(This->hwbuf, p1, x1, p2, x2);
if (hres != DS_OK)
WARN("IDsDriverBuffer_Unlock failed\n");
......@@ -984,7 +985,7 @@ static const IDirectSoundBuffer8Vtbl dsbvt =
};
HRESULT IDirectSoundBufferImpl_Create(
IDirectSoundImpl *ds,
DirectSoundDevice * device,
IDirectSoundBufferImpl **pdsb,
LPCDSBUFFERDESC dsbd)
{
......@@ -993,7 +994,7 @@ HRESULT IDirectSoundBufferImpl_Create(
HRESULT err = DS_OK;
DWORD capf = 0;
int use_hw, alloc_size, cp_size;
TRACE("(%p,%p,%p)\n",ds,pdsb,dsbd);
TRACE("(%p,%p,%p)\n",device,pdsb,dsbd);
if (dsbd->dwBufferBytes < DSBSIZE_MIN || dsbd->dwBufferBytes > DSBSIZE_MAX) {
WARN("invalid parameter: dsbd->dwBufferBytes = %ld\n", dsbd->dwBufferBytes);
......@@ -1013,7 +1014,7 @@ HRESULT IDirectSoundBufferImpl_Create(
dsb->ref = 0;
dsb->secondary = 0;
dsb->dsound = ds;
dsb->device = device;
dsb->lpVtbl = &dsbvt;
dsb->iks = NULL;
......@@ -1056,8 +1057,8 @@ HRESULT IDirectSoundBufferImpl_Create(
if (wfex->wBitsPerSample==16) capf |= DSCAPS_SECONDARY16BIT;
else capf |= DSCAPS_SECONDARY8BIT;
use_hw = (ds->device->drvcaps.dwFlags & capf) == capf;
TRACE("use_hw = 0x%08x, capf = 0x%08lx, ds->drvcaps.dwFlags = 0x%08lx\n", use_hw, capf, ds->device->drvcaps.dwFlags);
use_hw = (device->drvcaps.dwFlags & capf) == capf;
TRACE("use_hw = 0x%08x, capf = 0x%08lx, device->drvcaps.dwFlags = 0x%08lx\n", use_hw, capf, device->drvcaps.dwFlags);
/* FIXME: check hardware sample rate mixing capabilities */
/* FIXME: check app hints for software/hardware buffer (STATIC, LOCHARDWARE, etc) */
......@@ -1075,7 +1076,7 @@ HRESULT IDirectSoundBufferImpl_Create(
}
/* Allocate system memory for buffer if applicable */
if ((ds->device->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) || !use_hw) {
if ((device->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) || !use_hw) {
dsb->buffer->memory = HeapAlloc(GetProcessHeap(),0,dsb->buflen);
if (dsb->buffer->memory == NULL) {
WARN("out of memory\n");
......@@ -1091,14 +1092,14 @@ HRESULT IDirectSoundBufferImpl_Create(
/* Allocate the hardware buffer */
if (use_hw) {
err = IDsDriver_CreateSoundBuffer(ds->device->driver,wfex,dsbd->dwFlags,0,
err = IDsDriver_CreateSoundBuffer(device->driver,wfex,dsbd->dwFlags,0,
&(dsb->buflen),&(dsb->buffer->memory),
(LPVOID*)&(dsb->hwbuf));
/* fall back to software buffer on failure */
if (err != DS_OK) {
TRACE("IDsDriver_CreateSoundBuffer failed, falling back to software buffer\n");
use_hw = 0;
if (ds->device->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) {
if (device->drvdesc.dwFlags & DSDDESC_USESYSTEMMEMORY) {
dsb->buffer->memory = HeapAlloc(GetProcessHeap(),0,dsb->buflen);
if (dsb->buffer->memory == NULL) {
WARN("out of memory\n");
......@@ -1125,7 +1126,7 @@ HRESULT IDirectSoundBufferImpl_Create(
dsb->state = STATE_STOPPED;
dsb->freqAdjust = (dsb->freq << DSOUND_FREQSHIFT) /
ds->device->pwfx->nSamplesPerSec;
device->pwfx->nSamplesPerSec;
dsb->nAvgBytesPerSec = dsb->freq *
dsbd->lpwfxFormat->nBlockAlign;
......@@ -1157,7 +1158,7 @@ HRESULT IDirectSoundBufferImpl_Create(
/* register buffer if not primary */
if (!(dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER)) {
err = DSOUND_AddBuffer(ds, dsb);
err = DSOUND_AddBuffer(device, dsb);
if (err != DS_OK) {
HeapFree(GetProcessHeap(),0,dsb->buffer->memory);
HeapFree(GetProcessHeap(),0,dsb->buffer);
......@@ -1235,8 +1236,10 @@ static ULONG WINAPI SecondaryBufferImpl_AddRef(LPDIRECTSOUNDBUFFER8 iface)
static ULONG WINAPI SecondaryBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface)
{
SecondaryBufferImpl *This = (SecondaryBufferImpl *)iface;
ULONG ref = InterlockedDecrement(&(This->ref));
TRACE("(%p) ref was %ld\n", This, ref + 1);
ULONG ref;
TRACE("(%p)\n", This);
ref = InterlockedDecrement(&(This->ref));
TRACE("ref was %ld\n", ref + 1);
if (!ref) {
This->dsb->secondary = NULL;
......
......@@ -248,13 +248,8 @@ static ULONG WINAPI IDirectSoundImpl_Release(
TRACE("(%p) ref was %ld\n", This, ref + 1);
if (!ref) {
if (This->device) {
if (DirectSoundDevice_Release(This->device) != 0) {
/* device not released so make sure primary reference to This removed */
if (This->device->primary)
This->device->primary->dsound = NULL;
}
}
if (This->device)
DirectSoundDevice_Release(This->device);
HeapFree(GetProcessHeap(),0,This);
TRACE("(%p) released\n", This);
}
......@@ -330,10 +325,9 @@ static HRESULT WINAPI DSOUND_CreateSoundBuffer(
WARN("Primary Buffer already created\n");
IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER8)(This->device->primary));
*ppdsb = (LPDIRECTSOUNDBUFFER)(This->device->primary);
This->device->primary->dsound = This;
} else {
This->device->dsbd = *dsbd;
hres = PrimaryBufferImpl_Create(This, (PrimaryBufferImpl**)&(This->device->primary), &(This->device->dsbd));
hres = PrimaryBufferImpl_Create(This->device, (PrimaryBufferImpl**)&(This->device->primary), &(This->device->dsbd));
if (This->device->primary) {
IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER8)(This->device->primary));
*ppdsb = (LPDIRECTSOUNDBUFFER)(This->device->primary);
......@@ -362,7 +356,7 @@ static HRESULT WINAPI DSOUND_CreateSoundBuffer(
return DSERR_INVALIDPARAM;
}
hres = IDirectSoundBufferImpl_Create(This, (IDirectSoundBufferImpl**)&dsb, dsbd);
hres = IDirectSoundBufferImpl_Create(This->device, (IDirectSoundBufferImpl**)&dsb, dsbd);
if (dsb) {
hres = SecondaryBufferImpl_Create(dsb, (SecondaryBufferImpl**)ppdsb);
if (*ppdsb) {
......@@ -474,8 +468,8 @@ static HRESULT WINAPI IDirectSoundImpl_DuplicateSoundBuffer(
return DSERR_INVALIDPARAM;
}
/* FIXME: hack to make sure we have a secondary buffer */
if ((IDirectSoundImpl *)((SecondaryBufferImpl *)psb)->dsb == This) {
/* make sure we have a secondary buffer */
if ((PrimaryBufferImpl *)psb == This->device->primary) {
WARN("trying to duplicate primary buffer\n");
*ppdsb = NULL;
return DSERR_INVALIDCALL;
......@@ -532,7 +526,7 @@ static HRESULT WINAPI IDirectSoundImpl_DuplicateSoundBuffer(
dsb->state = STATE_STOPPED;
dsb->playpos = 0;
dsb->buf_mixpos = 0;
dsb->dsound = This;
dsb->device = This->device;
dsb->ds3db = NULL;
dsb->iks = NULL; /* FIXME? */
dsb->secondary = NULL;
......@@ -555,7 +549,7 @@ static HRESULT WINAPI IDirectSoundImpl_DuplicateSoundBuffer(
dsb->lock.DebugInfo->Spare[0] = (DWORD_PTR)"DSOUNDBUFFER_lock";
/* register buffer */
hres = DSOUND_AddBuffer(This, dsb);
hres = DSOUND_AddBuffer(This->device, dsb);
if (hres != DS_OK) {
IDirectSoundBuffer8_Release(psb);
dsb->lock.DebugInfo->Spare[0] = 0;
......@@ -1855,32 +1849,32 @@ HRESULT WINAPI DirectSoundCreate8(
* Gets exclusive access to buffer for writing.
*/
HRESULT DSOUND_AddBuffer(
IDirectSoundImpl * pDS,
DirectSoundDevice * device,
IDirectSoundBufferImpl * pDSB)
{
IDirectSoundBufferImpl **newbuffers;
HRESULT hr = DS_OK;
TRACE("(%p, %p)\n", pDS, pDSB);
TRACE("(%p, %p)\n", device, pDSB);
RtlAcquireResourceExclusive(&(pDS->device->buffer_list_lock), TRUE);
RtlAcquireResourceExclusive(&(device->buffer_list_lock), TRUE);
if (pDS->device->buffers)
newbuffers = HeapReAlloc(GetProcessHeap(),0,pDS->device->buffers,sizeof(IDirectSoundBufferImpl*)*(pDS->device->nrofbuffers+1));
if (device->buffers)
newbuffers = HeapReAlloc(GetProcessHeap(),0,device->buffers,sizeof(IDirectSoundBufferImpl*)*(device->nrofbuffers+1));
else
newbuffers = HeapAlloc(GetProcessHeap(),0,sizeof(IDirectSoundBufferImpl*)*(pDS->device->nrofbuffers+1));
newbuffers = HeapAlloc(GetProcessHeap(),0,sizeof(IDirectSoundBufferImpl*)*(device->nrofbuffers+1));
if (newbuffers) {
pDS->device->buffers = newbuffers;
pDS->device->buffers[pDS->device->nrofbuffers] = pDSB;
pDS->device->nrofbuffers++;
TRACE("buffer count is now %d\n", pDS->device->nrofbuffers);
device->buffers = newbuffers;
device->buffers[device->nrofbuffers] = pDSB;
device->nrofbuffers++;
TRACE("buffer count is now %d\n", device->nrofbuffers);
} else {
ERR("out of memory for buffer list! Current buffer count is %d\n", pDS->device->nrofbuffers);
ERR("out of memory for buffer list! Current buffer count is %d\n", device->nrofbuffers);
hr = DSERR_OUTOFMEMORY;
}
RtlReleaseResource(&(pDS->device->buffer_list_lock));
RtlReleaseResource(&(device->buffer_list_lock));
return hr;
}
......@@ -1890,34 +1884,34 @@ HRESULT DSOUND_AddBuffer(
* Gets exclusive access to buffer for writing.
*/
HRESULT DSOUND_RemoveBuffer(
IDirectSoundImpl * pDS,
DirectSoundDevice * device,
IDirectSoundBufferImpl * pDSB)
{
int i;
HRESULT hr = DS_OK;
TRACE("(%p, %p)\n", pDS, pDSB);
TRACE("(%p, %p)\n", device, pDSB);
RtlAcquireResourceExclusive(&(pDS->device->buffer_list_lock), TRUE);
RtlAcquireResourceExclusive(&(device->buffer_list_lock), TRUE);
for (i = 0; i < pDS->device->nrofbuffers; i++)
if (pDS->device->buffers[i] == pDSB)
for (i = 0; i < device->nrofbuffers; i++)
if (device->buffers[i] == pDSB)
break;
if (i < pDS->device->nrofbuffers) {
if (i < device->nrofbuffers) {
/* Put the last buffer of the list in the (now empty) position */
pDS->device->buffers[i] = pDS->device->buffers[pDS->device->nrofbuffers - 1];
pDS->device->nrofbuffers--;
pDS->device->buffers = HeapReAlloc(GetProcessHeap(),0,pDS->device->buffers,sizeof(LPDIRECTSOUNDBUFFER8)*pDS->device->nrofbuffers);
TRACE("buffer count is now %d\n", pDS->device->nrofbuffers);
device->buffers[i] = device->buffers[device->nrofbuffers - 1];
device->nrofbuffers--;
device->buffers = HeapReAlloc(GetProcessHeap(),0,device->buffers,sizeof(LPDIRECTSOUNDBUFFER8)*device->nrofbuffers);
TRACE("buffer count is now %d\n", device->nrofbuffers);
}
if (pDS->device->nrofbuffers == 0) {
HeapFree(GetProcessHeap(),0,pDS->device->buffers);
pDS->device->buffers = NULL;
if (device->nrofbuffers == 0) {
HeapFree(GetProcessHeap(),0,device->buffers);
device->buffers = NULL;
}
RtlReleaseResource(&(pDS->device->buffer_list_lock));
RtlReleaseResource(&(device->buffer_list_lock));
return hr;
}
......@@ -200,7 +200,7 @@ struct IDirectSoundBufferImpl
LONG ref;
/* IDirectSoundBufferImpl fields */
SecondaryBufferImpl* secondary;
IDirectSoundImpl* dsound;
DirectSoundDevice* device;
CRITICAL_SECTION lock;
PIDSDRIVERBUFFER hwbuf;
PWAVEFORMATEX pwfx;
......@@ -235,8 +235,8 @@ struct IDirectSoundBufferImpl
};
HRESULT IDirectSoundBufferImpl_Create(
IDirectSoundImpl *ds,
IDirectSoundBufferImpl **pdsb,
DirectSoundDevice *device,
IDirectSoundBufferImpl **ppdsb,
LPCDSBUFFERDESC dsbd);
HRESULT IDirectSoundBufferImpl_Destroy(
IDirectSoundBufferImpl *pdsb);
......@@ -264,12 +264,12 @@ struct PrimaryBufferImpl
{
const IDirectSoundBuffer8Vtbl *lpVtbl;
LONG ref;
IDirectSoundImpl* dsound;
DirectSoundDevice* device;
};
HRESULT PrimaryBufferImpl_Create(
IDirectSoundImpl *ds,
PrimaryBufferImpl **pdsb,
DirectSoundDevice * device,
PrimaryBufferImpl **ppdsb,
LPCDSBUFFERDESC dsbd);
/*****************************************************************************
......@@ -413,11 +413,11 @@ struct IDirectSound3DListenerImpl
const IDirectSound3DListenerVtbl *lpVtbl;
LONG ref;
/* IDirectSound3DListenerImpl fields */
IDirectSoundImpl* dsound;
DirectSoundDevice* device;
};
HRESULT IDirectSound3DListenerImpl_Create(
PrimaryBufferImpl *pb,
DirectSoundDevice *device,
IDirectSound3DListenerImpl **pdsl);
/*****************************************************************************
......@@ -488,8 +488,8 @@ void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb);
/* dsound.c */
HRESULT DSOUND_AddBuffer(IDirectSoundImpl * pDS, IDirectSoundBufferImpl * pDSB);
HRESULT DSOUND_RemoveBuffer(IDirectSoundImpl * pDS, IDirectSoundBufferImpl * pDSB);
HRESULT DSOUND_AddBuffer(DirectSoundDevice *device, IDirectSoundBufferImpl * pDSB);
HRESULT DSOUND_RemoveBuffer(DirectSoundDevice *device, IDirectSoundBufferImpl * pDSB);
/* primary.c */
......
......@@ -326,7 +326,7 @@ HRESULT DSOUND_PrimaryGetPosition(DirectSoundDevice *device, LPDWORD playpos, LP
static HRESULT WINAPI PrimaryBufferImpl_SetFormat(
LPDIRECTSOUNDBUFFER8 iface,LPCWAVEFORMATEX wfex
) {
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->dsound->device;
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
HRESULT err = DS_OK;
int i, alloc_size, cp_size;
DWORD nSamplesPerSec;
......@@ -433,7 +433,7 @@ done:
static HRESULT WINAPI PrimaryBufferImpl_SetVolume(
LPDIRECTSOUNDBUFFER8 iface,LONG vol
) {
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->dsound->device;
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
DWORD ampfactors;
DSVOLUMEPAN volpan;
HRESULT hres = DS_OK;
......@@ -478,7 +478,7 @@ static HRESULT WINAPI PrimaryBufferImpl_SetVolume(
static HRESULT WINAPI PrimaryBufferImpl_GetVolume(
LPDIRECTSOUNDBUFFER8 iface,LPLONG vol
) {
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->dsound->device;
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
DWORD ampfactors;
DSVOLUMEPAN volpan;
TRACE("(%p,%p)\n", iface, vol);
......@@ -515,7 +515,7 @@ static HRESULT WINAPI PrimaryBufferImpl_SetFrequency(
static HRESULT WINAPI PrimaryBufferImpl_Play(
LPDIRECTSOUNDBUFFER8 iface,DWORD reserved1,DWORD reserved2,DWORD flags
) {
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->dsound->device;
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
TRACE("(%p,%08lx,%08lx,%08lx)\n", iface, reserved1, reserved2, flags);
if (!(flags & DSBPLAY_LOOPING)) {
......@@ -539,7 +539,7 @@ static HRESULT WINAPI PrimaryBufferImpl_Play(
static HRESULT WINAPI PrimaryBufferImpl_Stop(LPDIRECTSOUNDBUFFER8 iface)
{
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->dsound->device;
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
TRACE("(%p)\n", iface);
/* **** */
......@@ -571,7 +571,7 @@ static ULONG WINAPI PrimaryBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface)
TRACE("(%p) ref was %ld\n", This, ref + 1);
if (!ref) {
This->dsound->device->primary = NULL;
This->device->primary = NULL;
HeapFree(GetProcessHeap(), 0, This);
TRACE("(%p) released\n", This);
}
......@@ -582,7 +582,7 @@ static HRESULT WINAPI PrimaryBufferImpl_GetCurrentPosition(
LPDIRECTSOUNDBUFFER8 iface,LPDWORD playpos,LPDWORD writepos
) {
HRESULT hres;
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->dsound->device;
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
TRACE("(%p,%p,%p)\n", iface, playpos, writepos);
hres = DSOUND_PrimaryGetPosition(device, playpos, writepos);
......@@ -603,7 +603,7 @@ static HRESULT WINAPI PrimaryBufferImpl_GetCurrentPosition(
static HRESULT WINAPI PrimaryBufferImpl_GetStatus(
LPDIRECTSOUNDBUFFER8 iface,LPDWORD status
) {
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->dsound->device;
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
TRACE("(%p,%p)\n", iface, status);
if (status == NULL) {
......@@ -628,7 +628,7 @@ static HRESULT WINAPI PrimaryBufferImpl_GetFormat(
LPDWORD wfwritten)
{
DWORD size;
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->dsound->device;
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
TRACE("(%p,%p,%ld,%p)\n", iface, lpwf, wfsize, wfwritten);
size = sizeof(WAVEFORMATEX) + device->pwfx->cbSize;
......@@ -659,7 +659,7 @@ static HRESULT WINAPI PrimaryBufferImpl_GetFormat(
static HRESULT WINAPI PrimaryBufferImpl_Lock(
LPDIRECTSOUNDBUFFER8 iface,DWORD writecursor,DWORD writebytes,LPVOID lplpaudioptr1,LPDWORD audiobytes1,LPVOID lplpaudioptr2,LPDWORD audiobytes2,DWORD flags
) {
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->dsound->device;
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
TRACE("(%p,%ld,%ld,%p,%p,%p,%p,0x%08lx) at %ld\n",
iface,
writecursor,
......@@ -742,7 +742,7 @@ static HRESULT WINAPI PrimaryBufferImpl_SetCurrentPosition(
static HRESULT WINAPI PrimaryBufferImpl_SetPan(
LPDIRECTSOUNDBUFFER8 iface,LONG pan
) {
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->dsound->device;
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
DWORD ampfactors;
DSVOLUMEPAN volpan;
HRESULT hres = DS_OK;
......@@ -787,7 +787,7 @@ static HRESULT WINAPI PrimaryBufferImpl_SetPan(
static HRESULT WINAPI PrimaryBufferImpl_GetPan(
LPDIRECTSOUNDBUFFER8 iface,LPLONG pan
) {
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->dsound->device;
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
DWORD ampfactors;
DSVOLUMEPAN volpan;
TRACE("(%p,%p)\n", iface, pan);
......@@ -813,7 +813,7 @@ static HRESULT WINAPI PrimaryBufferImpl_GetPan(
static HRESULT WINAPI PrimaryBufferImpl_Unlock(
LPDIRECTSOUNDBUFFER8 iface,LPVOID p1,DWORD x1,LPVOID p2,DWORD x2
) {
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->dsound->device;
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
TRACE("(%p,%p,%ld,%p,%ld)\n", iface, p1, x1, p2, x2);
if (device->priolevel != DSSCL_WRITEPRIMARY) {
......@@ -845,7 +845,7 @@ static HRESULT WINAPI PrimaryBufferImpl_Restore(
static HRESULT WINAPI PrimaryBufferImpl_GetFrequency(
LPDIRECTSOUNDBUFFER8 iface,LPDWORD freq
) {
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->dsound->device;
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
TRACE("(%p,%p)\n", iface, freq);
if (freq == NULL) {
......@@ -915,7 +915,7 @@ static HRESULT WINAPI PrimaryBufferImpl_Initialize(
static HRESULT WINAPI PrimaryBufferImpl_GetCaps(
LPDIRECTSOUNDBUFFER8 iface,LPDSBCAPS caps
) {
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->dsound->device;
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
TRACE("(%p,%p)\n", iface, caps);
if (caps == NULL) {
......@@ -948,7 +948,7 @@ static HRESULT WINAPI PrimaryBufferImpl_QueryInterface(
LPDIRECTSOUNDBUFFER8 iface,REFIID riid,LPVOID *ppobj
) {
PrimaryBufferImpl *This = (PrimaryBufferImpl *)iface;
DirectSoundDevice *device = This->dsound->device;
DirectSoundDevice *device = This->device;
TRACE("(%p,%s,%p)\n", iface, debugstr_guid(riid), ppobj);
if (ppobj == NULL) {
......@@ -985,7 +985,7 @@ static HRESULT WINAPI PrimaryBufferImpl_QueryInterface(
if ( IsEqualGUID( &IID_IDirectSound3DListener, riid ) ) {
if (!device->listener)
IDirectSound3DListenerImpl_Create(This, &device->listener);
IDirectSound3DListenerImpl_Create(device, &device->listener);
if (device->listener) {
*ppobj = device->listener;
IDirectSound3DListener_AddRef((LPDIRECTSOUND3DLISTENER)*ppobj);
......@@ -1034,16 +1034,16 @@ static const IDirectSoundBuffer8Vtbl dspbvt =
};
HRESULT PrimaryBufferImpl_Create(
IDirectSoundImpl *ds,
PrimaryBufferImpl **pdsb,
DirectSoundDevice * device,
PrimaryBufferImpl ** ppdsb,
LPCDSBUFFERDESC dsbd)
{
PrimaryBufferImpl *dsb;
TRACE("%p,%p,%p)\n",ds,pdsb,dsbd);
TRACE("%p,%p,%p)\n",device,ppdsb,dsbd);
if (dsbd->lpwfxFormat) {
WARN("invalid parameter: dsbd->lpwfxFormat != NULL\n");
*pdsb = NULL;
*ppdsb = NULL;
return DSERR_INVALIDPARAM;
}
......@@ -1051,23 +1051,24 @@ HRESULT PrimaryBufferImpl_Create(
if (dsb == NULL) {
WARN("out of memory\n");
*pdsb = NULL;
*ppdsb = NULL;
return DSERR_OUTOFMEMORY;
}
dsb->ref = 0;
dsb->dsound = ds;
dsb->device = device;
dsb->lpVtbl = &dspbvt;
CopyMemory(&ds->device->dsbd, dsbd, sizeof(*dsbd));
CopyMemory(&device->dsbd, dsbd, sizeof(*dsbd));
TRACE("Created primary buffer at %p\n", dsb);
TRACE("(formattag=0x%04x,chans=%d,samplerate=%ld,"
"bytespersec=%ld,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
ds->device->pwfx->wFormatTag, ds->device->pwfx->nChannels, ds->device->pwfx->nSamplesPerSec,
ds->device->pwfx->nAvgBytesPerSec, ds->device->pwfx->nBlockAlign,
ds->device->pwfx->wBitsPerSample, ds->device->pwfx->cbSize);
device->pwfx->wFormatTag, device->pwfx->nChannels,
device->pwfx->nSamplesPerSec, device->pwfx->nAvgBytesPerSec,
device->pwfx->nBlockAlign, device->pwfx->wBitsPerSample,
device->pwfx->cbSize);
*pdsb = dsb;
*ppdsb = dsb;
return S_OK;
}
......@@ -110,7 +110,7 @@ static HRESULT WINAPI IKsBufferPropertySetImpl_Get(
S(prop).Set = *guidPropSet;
S(prop).Id = dwPropID;
S(prop).Flags = 0; /* unused */
S(prop).InstanceId = (ULONG)This->dsb->dsound;
S(prop).InstanceId = (ULONG)This->dsb->device;
hres = IDsDriverPropertySet_Get(ps, &prop, pInstanceData, cbInstanceData, pPropData, cbPropData, pcbReturned);
......@@ -146,7 +146,7 @@ static HRESULT WINAPI IKsBufferPropertySetImpl_Set(
S(prop).Set = *guidPropSet;
S(prop).Id = dwPropID;
S(prop).Flags = 0; /* unused */
S(prop).InstanceId = (ULONG)This->dsb->dsound;
S(prop).InstanceId = (ULONG)This->dsb->device;
hres = IDsDriverPropertySet_Set(ps,&prop,pInstanceData,cbInstanceData,pPropData,cbPropData);
IDsDriverPropertySet_Release(ps);
......
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