2002-06-13 21:15:06 +02:00
|
|
|
/* DirectSound
|
|
|
|
*
|
|
|
|
* Copyright 1998 Marcus Meissner
|
|
|
|
* Copyright 1998 Rob Riggs
|
|
|
|
* Copyright 2000-2002 TransGaming Technologies, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-06-13 21:15:06 +02:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2005-01-24 14:31:27 +01:00
|
|
|
#define NONAMELESSSTRUCT
|
|
|
|
#define NONAMELESSUNION
|
2002-06-13 21:15:06 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2005-10-17 11:24:50 +02:00
|
|
|
#include "winuser.h"
|
2002-06-13 21:15:06 +02:00
|
|
|
#include "mmsystem.h"
|
2002-09-13 00:07:02 +02:00
|
|
|
#include "winternl.h"
|
2002-06-13 21:15:06 +02:00
|
|
|
#include "mmddk.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "dsound.h"
|
|
|
|
#include "dsdriver.h"
|
|
|
|
#include "dsound_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dsound);
|
|
|
|
|
2006-08-02 13:26:14 +02:00
|
|
|
static void DSOUND_RecalcPrimary(DirectSoundDevice *device)
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
2005-02-16 17:26:13 +01:00
|
|
|
DWORD nBlockAlign;
|
2005-05-31 11:31:37 +02:00
|
|
|
TRACE("(%p)\n", device);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
nBlockAlign = device->pwfx->nBlockAlign;
|
|
|
|
if (device->hwbuf) {
|
2002-06-13 21:15:06 +02:00
|
|
|
DWORD fraglen;
|
|
|
|
/* let fragment size approximate the timer delay */
|
2005-05-31 11:31:37 +02:00
|
|
|
fraglen = (device->pwfx->nSamplesPerSec * DS_TIME_DEL / 1000) * nBlockAlign;
|
2002-06-13 21:15:06 +02:00
|
|
|
/* reduce fragment size until an integer number of them fits in the buffer */
|
|
|
|
/* (FIXME: this may or may not be a good idea) */
|
2005-05-31 11:31:37 +02:00
|
|
|
while (device->buflen % fraglen) fraglen -= nBlockAlign;
|
|
|
|
device->fraglen = fraglen;
|
2006-11-12 14:40:35 +01:00
|
|
|
TRACE("fraglen=%d\n", device->fraglen);
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
/* calculate the 10ms write lead */
|
2005-05-31 11:31:37 +02:00
|
|
|
device->writelead = (device->pwfx->nSamplesPerSec / 100) * nBlockAlign;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
static HRESULT DSOUND_PrimaryOpen(DirectSoundDevice *device)
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
|
|
|
HRESULT err = DS_OK;
|
2005-05-31 11:31:37 +02:00
|
|
|
TRACE("(%p)\n", device);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
|
|
|
/* are we using waveOut stuff? */
|
2005-05-31 11:31:37 +02:00
|
|
|
if (!device->driver) {
|
2002-06-13 21:15:06 +02:00
|
|
|
LPBYTE newbuf;
|
|
|
|
DWORD buflen;
|
|
|
|
HRESULT merr = DS_OK;
|
|
|
|
/* Start in pause mode, to allow buffers to get filled */
|
2005-05-31 11:31:37 +02:00
|
|
|
waveOutPause(device->hwo);
|
|
|
|
if (device->state == STATE_PLAYING) device->state = STATE_STARTING;
|
|
|
|
else if (device->state == STATE_STOPPING) device->state = STATE_STOPPED;
|
2002-06-13 21:15:06 +02:00
|
|
|
/* use fragments of 10ms (1/100s) each (which should get us within
|
|
|
|
* the documented write cursor lead of 10-15ms) */
|
2005-05-31 11:31:37 +02:00
|
|
|
buflen = ((device->pwfx->nSamplesPerSec / 100) * device->pwfx->nBlockAlign) * DS_HEL_FRAGS;
|
2006-11-12 14:40:35 +01:00
|
|
|
TRACE("desired buflen=%d, old buffer=%p\n", buflen, device->buffer);
|
2002-06-13 21:15:06 +02:00
|
|
|
/* reallocate emulated primary buffer */
|
2003-10-14 07:24:20 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
if (device->buffer)
|
|
|
|
newbuf = HeapReAlloc(GetProcessHeap(),0,device->buffer,buflen);
|
2003-10-14 07:24:20 +02:00
|
|
|
else
|
2004-08-18 02:30:37 +02:00
|
|
|
newbuf = HeapAlloc(GetProcessHeap(),0,buflen);
|
2003-10-14 07:24:20 +02:00
|
|
|
|
2002-06-13 21:15:06 +02:00
|
|
|
if (newbuf == NULL) {
|
|
|
|
ERR("failed to allocate primary buffer\n");
|
|
|
|
merr = DSERR_OUTOFMEMORY;
|
2003-01-11 21:54:56 +01:00
|
|
|
/* but the old buffer might still exist and must be re-prepared */
|
2002-06-13 21:15:06 +02:00
|
|
|
} else {
|
2005-05-31 11:31:37 +02:00
|
|
|
device->buffer = newbuf;
|
|
|
|
device->buflen = buflen;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
2005-05-31 11:31:37 +02:00
|
|
|
if (device->buffer) {
|
2002-06-13 21:15:06 +02:00
|
|
|
unsigned c;
|
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
device->fraglen = device->buflen / DS_HEL_FRAGS;
|
2002-06-13 21:15:06 +02:00
|
|
|
|
|
|
|
/* prepare fragment headers */
|
|
|
|
for (c=0; c<DS_HEL_FRAGS; c++) {
|
2005-08-30 10:56:35 +02:00
|
|
|
device->pwave[c]->lpData = (char*)device->buffer + c*device->fraglen;
|
2005-05-31 11:31:37 +02:00
|
|
|
device->pwave[c]->dwBufferLength = device->fraglen;
|
|
|
|
device->pwave[c]->dwUser = (DWORD)device;
|
|
|
|
device->pwave[c]->dwFlags = 0;
|
|
|
|
device->pwave[c]->dwLoops = 0;
|
|
|
|
err = mmErr(waveOutPrepareHeader(device->hwo,device->pwave[c],sizeof(WAVEHDR)));
|
2002-06-13 21:15:06 +02:00
|
|
|
if (err != DS_OK) {
|
|
|
|
while (c--)
|
2005-05-31 11:31:37 +02:00
|
|
|
waveOutUnprepareHeader(device->hwo,device->pwave[c],sizeof(WAVEHDR));
|
2002-06-13 21:15:06 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
device->pwplay = 0;
|
|
|
|
device->pwwrite = 0;
|
|
|
|
device->pwqueue = 0;
|
|
|
|
device->playpos = 0;
|
|
|
|
device->mixpos = 0;
|
|
|
|
FillMemory(device->buffer, device->buflen, (device->pwfx->wBitsPerSample == 8) ? 128 : 0);
|
2006-11-12 14:40:35 +01:00
|
|
|
TRACE("fraglen=%d\n", device->fraglen);
|
2005-05-31 11:31:37 +02:00
|
|
|
DSOUND_WaveQueue(device, (DWORD)-1);
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
if ((err == DS_OK) && (merr != DS_OK))
|
|
|
|
err = merr;
|
2005-05-31 11:31:37 +02:00
|
|
|
} else if (!device->hwbuf) {
|
|
|
|
err = IDsDriver_CreateSoundBuffer(device->driver,device->pwfx,
|
2004-08-18 02:30:37 +02:00
|
|
|
DSBCAPS_PRIMARYBUFFER,0,
|
2005-05-31 11:31:37 +02:00
|
|
|
&(device->buflen),&(device->buffer),
|
|
|
|
(LPVOID*)&(device->hwbuf));
|
2004-08-18 02:30:37 +02:00
|
|
|
if (err != DS_OK) {
|
|
|
|
WARN("IDsDriver_CreateSoundBuffer failed\n");
|
|
|
|
return err;
|
2004-02-13 21:22:02 +01:00
|
|
|
}
|
2004-08-18 02:30:37 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
if (device->state == STATE_PLAYING) device->state = STATE_STARTING;
|
|
|
|
else if (device->state == STATE_STOPPING) device->state = STATE_STOPPED;
|
|
|
|
device->playpos = 0;
|
|
|
|
device->mixpos = 0;
|
|
|
|
FillMemory(device->buffer, device->buflen, (device->pwfx->wBitsPerSample == 8) ? 128 : 0);
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
2003-09-19 02:10:51 +02:00
|
|
|
|
2002-06-13 21:15:06 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
static void DSOUND_PrimaryClose(DirectSoundDevice *device)
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
2005-05-31 11:31:37 +02:00
|
|
|
TRACE("(%p)\n", device);
|
2003-05-02 23:23:16 +02:00
|
|
|
|
2002-06-13 21:15:06 +02:00
|
|
|
/* are we using waveOut stuff? */
|
2005-05-31 11:31:37 +02:00
|
|
|
if (!device->hwbuf) {
|
2002-06-13 21:15:06 +02:00
|
|
|
unsigned c;
|
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
device->pwqueue = (DWORD)-1; /* resetting queues */
|
|
|
|
waveOutReset(device->hwo);
|
2002-06-13 21:15:06 +02:00
|
|
|
for (c=0; c<DS_HEL_FRAGS; c++)
|
2005-05-31 11:31:37 +02:00
|
|
|
waveOutUnprepareHeader(device->hwo, device->pwave[c], sizeof(WAVEHDR));
|
|
|
|
device->pwqueue = 0;
|
2004-02-13 21:22:02 +01:00
|
|
|
} else {
|
2005-05-31 11:31:37 +02:00
|
|
|
if (IDsDriverBuffer_Release(device->hwbuf) == 0)
|
|
|
|
device->hwbuf = 0;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
HRESULT DSOUND_PrimaryCreate(DirectSoundDevice *device)
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
|
|
|
HRESULT err = DS_OK;
|
2005-05-31 11:31:37 +02:00
|
|
|
TRACE("(%p)\n", device);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
device->buflen = device->pwfx->nAvgBytesPerSec;
|
2002-06-13 21:15:06 +02:00
|
|
|
|
|
|
|
/* FIXME: verify that hardware capabilities (DSCAPS_PRIMARY flags) match */
|
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
if (device->driver) {
|
|
|
|
err = IDsDriver_CreateSoundBuffer(device->driver,device->pwfx,
|
2002-06-13 21:15:06 +02:00
|
|
|
DSBCAPS_PRIMARYBUFFER,0,
|
2005-05-31 11:31:37 +02:00
|
|
|
&(device->buflen),&(device->buffer),
|
|
|
|
(LPVOID*)&(device->hwbuf));
|
2003-05-22 05:39:13 +02:00
|
|
|
if (err != DS_OK) {
|
|
|
|
WARN("IDsDriver_CreateSoundBuffer failed\n");
|
|
|
|
return err;
|
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
2005-05-31 11:31:37 +02:00
|
|
|
if (!device->hwbuf) {
|
2003-01-15 01:44:50 +01:00
|
|
|
/* Allocate memory for HEL buffer headers */
|
|
|
|
unsigned c;
|
|
|
|
for (c=0; c<DS_HEL_FRAGS; c++) {
|
2005-05-31 11:31:37 +02:00
|
|
|
device->pwave[c] = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(WAVEHDR));
|
|
|
|
if (!device->pwave[c]) {
|
2003-01-15 01:44:50 +01:00
|
|
|
/* Argh, out of memory */
|
|
|
|
while (c--) {
|
2005-05-31 11:31:37 +02:00
|
|
|
HeapFree(GetProcessHeap(),0,device->pwave[c]);
|
2003-01-15 01:44:50 +01:00
|
|
|
}
|
2003-05-22 05:39:13 +02:00
|
|
|
WARN("out of memory\n");
|
|
|
|
return DSERR_OUTOFMEMORY;
|
2003-01-15 01:44:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-05-22 05:39:13 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
err = DSOUND_PrimaryOpen(device);
|
2003-05-22 05:39:13 +02:00
|
|
|
|
|
|
|
if (err != DS_OK) {
|
|
|
|
WARN("DSOUND_PrimaryOpen failed\n");
|
2002-06-13 21:15:06 +02:00
|
|
|
return err;
|
2003-05-22 05:39:13 +02:00
|
|
|
}
|
|
|
|
|
2002-06-13 21:15:06 +02:00
|
|
|
/* calculate fragment size and write lead */
|
2005-05-31 11:31:37 +02:00
|
|
|
DSOUND_RecalcPrimary(device);
|
|
|
|
device->state = STATE_STOPPED;
|
2002-06-13 21:15:06 +02:00
|
|
|
return DS_OK;
|
|
|
|
}
|
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
HRESULT DSOUND_PrimaryDestroy(DirectSoundDevice *device)
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
2005-05-31 11:31:37 +02:00
|
|
|
TRACE("(%p)\n", device);
|
2003-05-02 23:23:16 +02:00
|
|
|
|
2007-04-20 22:10:23 +02:00
|
|
|
EnterCriticalSection(&(device->mixlock));
|
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
DSOUND_PrimaryClose(device);
|
|
|
|
if (device->driver) {
|
|
|
|
if (device->hwbuf) {
|
|
|
|
if (IDsDriverBuffer_Release(device->hwbuf) == 0)
|
|
|
|
device->hwbuf = 0;
|
2004-02-13 21:22:02 +01:00
|
|
|
}
|
2003-01-15 01:44:50 +01:00
|
|
|
} else {
|
|
|
|
unsigned c;
|
|
|
|
for (c=0; c<DS_HEL_FRAGS; c++) {
|
2005-05-31 11:31:37 +02:00
|
|
|
HeapFree(GetProcessHeap(),0,device->pwave[c]);
|
2003-01-15 01:44:50 +01:00
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
2005-05-31 11:31:37 +02:00
|
|
|
HeapFree(GetProcessHeap(),0,device->pwfx);
|
|
|
|
device->pwfx=NULL;
|
2007-04-20 22:10:23 +02:00
|
|
|
LeaveCriticalSection(&(device->mixlock));
|
2002-06-13 21:15:06 +02:00
|
|
|
return DS_OK;
|
|
|
|
}
|
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
HRESULT DSOUND_PrimaryPlay(DirectSoundDevice *device)
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
|
|
|
HRESULT err = DS_OK;
|
2005-05-31 11:31:37 +02:00
|
|
|
TRACE("(%p)\n", device);
|
2003-05-02 23:23:16 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
if (device->hwbuf) {
|
|
|
|
err = IDsDriverBuffer_Play(device->hwbuf, 0, 0, DSBPLAY_LOOPING);
|
2003-05-22 05:39:13 +02:00
|
|
|
if (err != DS_OK)
|
|
|
|
WARN("IDsDriverBuffer_Play failed\n");
|
|
|
|
} else {
|
2005-05-31 11:31:37 +02:00
|
|
|
err = mmErr(waveOutRestart(device->hwo));
|
2003-05-22 05:39:13 +02:00
|
|
|
if (err != DS_OK)
|
|
|
|
WARN("waveOutRestart failed\n");
|
|
|
|
}
|
|
|
|
|
2002-06-13 21:15:06 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
HRESULT DSOUND_PrimaryStop(DirectSoundDevice *device)
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
|
|
|
HRESULT err = DS_OK;
|
2005-05-31 11:31:37 +02:00
|
|
|
TRACE("(%p)\n", device);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2007-04-20 22:10:23 +02:00
|
|
|
EnterCriticalSection(&(device->mixlock));
|
2005-05-31 11:31:37 +02:00
|
|
|
if (device->hwbuf) {
|
|
|
|
err = IDsDriverBuffer_Stop(device->hwbuf);
|
2002-06-13 21:15:06 +02:00
|
|
|
if (err == DSERR_BUFFERLOST) {
|
2003-03-06 23:46:34 +01:00
|
|
|
DWORD flags = CALLBACK_FUNCTION;
|
|
|
|
if (ds_hw_accel != DS_HW_ACCEL_EMULATION)
|
|
|
|
flags |= WAVE_DIRECTSOUND;
|
2002-06-13 21:15:06 +02:00
|
|
|
/* Wine-only: the driver wants us to reopen the device */
|
|
|
|
/* FIXME: check for errors */
|
2005-05-31 11:31:37 +02:00
|
|
|
IDsDriverBuffer_Release(device->hwbuf);
|
|
|
|
waveOutClose(device->hwo);
|
|
|
|
device->hwo = 0;
|
|
|
|
err = mmErr(waveOutOpen(&(device->hwo), device->drvdesc.dnDevNode,
|
2005-09-12 17:14:06 +02:00
|
|
|
device->pwfx, (DWORD_PTR)DSOUND_callback, (DWORD)device,
|
2003-03-06 23:46:34 +01:00
|
|
|
flags));
|
2003-05-22 05:39:13 +02:00
|
|
|
if (err == DS_OK) {
|
2005-05-31 11:31:37 +02:00
|
|
|
err = IDsDriver_CreateSoundBuffer(device->driver,device->pwfx,
|
2002-06-13 21:15:06 +02:00
|
|
|
DSBCAPS_PRIMARYBUFFER,0,
|
2005-05-31 11:31:37 +02:00
|
|
|
&(device->buflen),&(device->buffer),
|
|
|
|
(LPVOID)&(device->hwbuf));
|
2003-05-22 05:39:13 +02:00
|
|
|
if (err != DS_OK)
|
|
|
|
WARN("IDsDriver_CreateSoundBuffer failed\n");
|
|
|
|
} else {
|
|
|
|
WARN("waveOutOpen failed\n");
|
|
|
|
}
|
|
|
|
} else if (err != DS_OK) {
|
|
|
|
WARN("IDsDriverBuffer_Stop failed\n");
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
2003-05-22 05:39:13 +02:00
|
|
|
} else {
|
2005-05-31 11:31:37 +02:00
|
|
|
err = mmErr(waveOutPause(device->hwo));
|
2003-05-22 05:39:13 +02:00
|
|
|
if (err != DS_OK)
|
|
|
|
WARN("waveOutPause failed\n");
|
|
|
|
}
|
2007-04-20 22:10:23 +02:00
|
|
|
LeaveCriticalSection(&(device->mixlock));
|
2002-06-13 21:15:06 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
HRESULT DSOUND_PrimaryGetPosition(DirectSoundDevice *device, LPDWORD playpos, LPDWORD writepos)
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
2005-05-31 11:31:37 +02:00
|
|
|
TRACE("(%p,%p,%p)\n", device, playpos, writepos);
|
2003-05-02 23:23:16 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
if (device->hwbuf) {
|
|
|
|
HRESULT err=IDsDriverBuffer_GetPosition(device->hwbuf,playpos,writepos);
|
2003-05-22 05:39:13 +02:00
|
|
|
if (err) {
|
|
|
|
WARN("IDsDriverBuffer_GetPosition failed\n");
|
|
|
|
return err;
|
|
|
|
}
|
2004-08-18 02:30:37 +02:00
|
|
|
} else {
|
2002-06-13 21:15:06 +02:00
|
|
|
if (playpos) {
|
|
|
|
MMTIME mtime;
|
|
|
|
mtime.wType = TIME_BYTES;
|
2005-05-31 11:31:37 +02:00
|
|
|
waveOutGetPosition(device->hwo, &mtime, sizeof(mtime));
|
|
|
|
mtime.u.cb = mtime.u.cb % device->buflen;
|
2002-06-13 21:15:06 +02:00
|
|
|
*playpos = mtime.u.cb;
|
|
|
|
}
|
|
|
|
if (writepos) {
|
|
|
|
/* the writepos should only be used by apps with WRITEPRIMARY priority,
|
|
|
|
* in which case our software mixer is disabled anyway */
|
2005-05-31 11:31:37 +02:00
|
|
|
*writepos = (device->pwplay + ds_hel_margin) * device->fraglen;
|
|
|
|
while (*writepos >= device->buflen)
|
|
|
|
*writepos -= device->buflen;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
}
|
2006-11-12 14:40:35 +01:00
|
|
|
TRACE("playpos = %d, writepos = %d (%p, time=%d)\n", playpos?*playpos:0, writepos?*writepos:0, device, GetTickCount());
|
2002-06-13 21:15:06 +02:00
|
|
|
return DS_OK;
|
|
|
|
}
|
|
|
|
|
2006-01-14 17:06:22 +01:00
|
|
|
HRESULT DSOUND_PrimarySetFormat(DirectSoundDevice *device, LPCWAVEFORMATEX wfex)
|
|
|
|
{
|
2002-06-13 21:15:06 +02:00
|
|
|
HRESULT err = DS_OK;
|
2004-08-18 02:30:37 +02:00
|
|
|
int i, alloc_size, cp_size;
|
|
|
|
DWORD nSamplesPerSec;
|
2006-01-14 17:06:22 +01:00
|
|
|
TRACE("(%p,%p)\n", device, wfex);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
if (device->priolevel == DSSCL_NORMAL) {
|
2003-05-22 05:39:13 +02:00
|
|
|
WARN("failed priority check!\n");
|
2002-06-13 21:15:06 +02:00
|
|
|
return DSERR_PRIOLEVELNEEDED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Let's be pedantic! */
|
2003-01-11 21:54:56 +01:00
|
|
|
if (wfex == NULL) {
|
2003-05-22 05:39:13 +02:00
|
|
|
WARN("invalid parameter: wfex==NULL!\n");
|
2003-01-11 21:54:56 +01:00
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
2006-11-12 14:40:35 +01:00
|
|
|
TRACE("(formattag=0x%04x,chans=%d,samplerate=%d,"
|
|
|
|
"bytespersec=%d,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
|
2003-01-11 21:54:56 +01:00
|
|
|
wfex->wFormatTag, wfex->nChannels, wfex->nSamplesPerSec,
|
|
|
|
wfex->nAvgBytesPerSec, wfex->nBlockAlign,
|
|
|
|
wfex->wBitsPerSample, wfex->cbSize);
|
|
|
|
|
2002-06-13 21:15:06 +02:00
|
|
|
/* **** */
|
2005-05-31 11:31:37 +02:00
|
|
|
RtlAcquireResourceExclusive(&(device->buffer_list_lock), TRUE);
|
|
|
|
EnterCriticalSection(&(device->mixlock));
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2004-08-18 02:30:37 +02:00
|
|
|
if (wfex->wFormatTag == WAVE_FORMAT_PCM) {
|
|
|
|
alloc_size = sizeof(WAVEFORMATEX);
|
|
|
|
cp_size = sizeof(PCMWAVEFORMAT);
|
|
|
|
} else
|
|
|
|
alloc_size = cp_size = sizeof(WAVEFORMATEX) + wfex->cbSize;
|
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
device->pwfx = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,device->pwfx,alloc_size);
|
2004-08-18 02:30:37 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
nSamplesPerSec = device->pwfx->nSamplesPerSec;
|
2004-08-18 02:30:37 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
CopyMemory(device->pwfx, wfex, cp_size);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
if (device->drvdesc.dwFlags & DSDDESC_DOMMSYSTEMSETFORMAT) {
|
2003-03-06 23:46:34 +01:00
|
|
|
DWORD flags = CALLBACK_FUNCTION;
|
|
|
|
if (ds_hw_accel != DS_HW_ACCEL_EMULATION)
|
|
|
|
flags |= WAVE_DIRECTSOUND;
|
2002-06-13 21:15:06 +02:00
|
|
|
/* FIXME: check for errors */
|
2005-05-31 11:31:37 +02:00
|
|
|
DSOUND_PrimaryClose(device);
|
|
|
|
waveOutClose(device->hwo);
|
|
|
|
device->hwo = 0;
|
|
|
|
err = mmErr(waveOutOpen(&(device->hwo), device->drvdesc.dnDevNode,
|
2005-09-12 17:14:06 +02:00
|
|
|
device->pwfx, (DWORD_PTR)DSOUND_callback, (DWORD)device,
|
2003-03-06 23:46:34 +01:00
|
|
|
flags));
|
2003-05-22 05:39:13 +02:00
|
|
|
if (err == DS_OK) {
|
2005-05-31 11:31:37 +02:00
|
|
|
err = DSOUND_PrimaryOpen(device);
|
2003-05-22 05:39:13 +02:00
|
|
|
if (err != DS_OK) {
|
2005-01-24 14:35:57 +01:00
|
|
|
WARN("DSOUND_PrimaryOpen failed\n");
|
|
|
|
goto done;
|
2003-05-22 05:39:13 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
WARN("waveOutOpen failed\n");
|
2005-01-24 14:35:57 +01:00
|
|
|
goto done;
|
2003-05-22 05:39:13 +02:00
|
|
|
}
|
2005-05-31 11:31:37 +02:00
|
|
|
} else if (device->hwbuf) {
|
|
|
|
err = IDsDriverBuffer_SetFormat(device->hwbuf, device->pwfx);
|
2002-06-13 21:15:06 +02:00
|
|
|
if (err == DSERR_BUFFERLOST) {
|
|
|
|
/* Wine-only: the driver wants us to recreate the HW buffer */
|
2005-05-31 11:31:37 +02:00
|
|
|
IDsDriverBuffer_Release(device->hwbuf);
|
|
|
|
err = IDsDriver_CreateSoundBuffer(device->driver,device->pwfx,
|
2002-06-13 21:15:06 +02:00
|
|
|
DSBCAPS_PRIMARYBUFFER,0,
|
2005-05-31 11:31:37 +02:00
|
|
|
&(device->buflen),&(device->buffer),
|
|
|
|
(LPVOID)&(device->hwbuf));
|
2003-05-22 05:39:13 +02:00
|
|
|
if (err != DS_OK) {
|
|
|
|
WARN("IDsDriver_CreateSoundBuffer failed\n");
|
2005-01-24 14:35:57 +01:00
|
|
|
goto done;
|
2003-05-22 05:39:13 +02:00
|
|
|
}
|
2005-05-31 11:31:37 +02:00
|
|
|
if (device->state == STATE_PLAYING) device->state = STATE_STARTING;
|
|
|
|
else if (device->state == STATE_STOPPING) device->state = STATE_STOPPED;
|
2003-05-22 05:39:13 +02:00
|
|
|
} else {
|
|
|
|
WARN("IDsDriverBuffer_SetFormat failed\n");
|
2005-01-24 14:35:57 +01:00
|
|
|
goto done;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
/* FIXME: should we set err back to DS_OK in all cases ? */
|
|
|
|
}
|
2005-05-31 11:31:37 +02:00
|
|
|
DSOUND_RecalcPrimary(device);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
if (nSamplesPerSec != device->pwfx->nSamplesPerSec) {
|
|
|
|
IDirectSoundBufferImpl** dsb = device->buffers;
|
|
|
|
for (i = 0; i < device->nrofbuffers; i++, dsb++) {
|
2004-02-06 06:20:28 +01:00
|
|
|
/* **** */
|
|
|
|
EnterCriticalSection(&((*dsb)->lock));
|
|
|
|
|
|
|
|
(*dsb)->freqAdjust = ((*dsb)->freq << DSOUND_FREQSHIFT) /
|
|
|
|
wfex->nSamplesPerSec;
|
|
|
|
|
|
|
|
LeaveCriticalSection(&((*dsb)->lock));
|
|
|
|
/* **** */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-24 14:35:57 +01:00
|
|
|
done:
|
2005-05-31 11:31:37 +02:00
|
|
|
LeaveCriticalSection(&(device->mixlock));
|
|
|
|
RtlReleaseResource(&(device->buffer_list_lock));
|
2002-06-13 21:15:06 +02:00
|
|
|
/* **** */
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2006-01-14 17:06:22 +01:00
|
|
|
/*******************************************************************************
|
|
|
|
* PrimaryBuffer
|
|
|
|
*/
|
|
|
|
/* This sets this format for the <em>Primary Buffer Only</em> */
|
|
|
|
/* See file:///cdrom/sdk52/docs/worddoc/dsound.doc page 120 */
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_SetFormat(
|
|
|
|
LPDIRECTSOUNDBUFFER8 iface,
|
|
|
|
LPCWAVEFORMATEX wfex)
|
|
|
|
{
|
|
|
|
TRACE("(%p,%p)\n", iface, wfex);
|
|
|
|
return DSOUND_PrimarySetFormat(((PrimaryBufferImpl *)iface)->device, wfex);
|
|
|
|
}
|
|
|
|
|
2002-06-13 21:15:06 +02:00
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_SetVolume(
|
|
|
|
LPDIRECTSOUNDBUFFER8 iface,LONG vol
|
|
|
|
) {
|
2006-01-06 12:35:20 +01:00
|
|
|
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
|
2004-07-23 21:06:31 +02:00
|
|
|
DWORD ampfactors;
|
|
|
|
DSVOLUMEPAN volpan;
|
2004-09-07 21:32:21 +02:00
|
|
|
HRESULT hres = DS_OK;
|
2006-11-12 14:40:35 +01:00
|
|
|
TRACE("(%p,%d)\n", iface, vol);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
if (!(device->dsbd.dwFlags & DSBCAPS_CTRLVOLUME)) {
|
2003-05-22 05:39:13 +02:00
|
|
|
WARN("control unavailable\n");
|
2002-06-13 21:15:06 +02:00
|
|
|
return DSERR_CONTROLUNAVAIL;
|
2003-05-22 05:39:13 +02:00
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2003-05-22 05:39:13 +02:00
|
|
|
if ((vol > DSBVOLUME_MAX) || (vol < DSBVOLUME_MIN)) {
|
2006-11-12 14:40:35 +01:00
|
|
|
WARN("invalid parameter: vol = %d\n", vol);
|
2002-06-13 21:15:06 +02:00
|
|
|
return DSERR_INVALIDPARAM;
|
2003-05-22 05:39:13 +02:00
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
|
|
|
|
/* **** */
|
2005-05-31 11:31:37 +02:00
|
|
|
EnterCriticalSection(&(device->mixlock));
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
waveOutGetVolume(device->hwo, &factors);
|
2004-07-23 21:06:31 +02:00
|
|
|
volpan.dwTotalLeftAmpFactor=ampfactors & 0xffff;
|
|
|
|
volpan.dwTotalRightAmpFactor=ampfactors >> 16;
|
|
|
|
DSOUND_AmpFactorToVolPan(&volpan);
|
|
|
|
if (vol != volpan.lVolume) {
|
|
|
|
volpan.lVolume=vol;
|
|
|
|
DSOUND_RecalcVolPan(&volpan);
|
2005-05-31 11:31:37 +02:00
|
|
|
if (device->hwbuf) {
|
|
|
|
hres = IDsDriverBuffer_SetVolumePan(device->hwbuf, &volpan);
|
2004-09-07 21:32:21 +02:00
|
|
|
if (hres != DS_OK)
|
2004-07-23 21:06:31 +02:00
|
|
|
WARN("IDsDriverBuffer_SetVolumePan failed\n");
|
|
|
|
} else {
|
|
|
|
ampfactors = (volpan.dwTotalLeftAmpFactor & 0xffff) | (volpan.dwTotalRightAmpFactor << 16);
|
2005-05-31 11:31:37 +02:00
|
|
|
waveOutSetVolume(device->hwo, ampfactors);
|
2004-07-23 21:06:31 +02:00
|
|
|
}
|
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
LeaveCriticalSection(&(device->mixlock));
|
2002-06-13 21:15:06 +02:00
|
|
|
/* **** */
|
|
|
|
|
2004-09-07 21:32:21 +02:00
|
|
|
return hres;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_GetVolume(
|
|
|
|
LPDIRECTSOUNDBUFFER8 iface,LPLONG vol
|
|
|
|
) {
|
2006-01-06 12:35:20 +01:00
|
|
|
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
|
2004-07-23 21:06:31 +02:00
|
|
|
DWORD ampfactors;
|
|
|
|
DSVOLUMEPAN volpan;
|
2005-05-31 11:31:37 +02:00
|
|
|
TRACE("(%p,%p)\n", iface, vol);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
if (!(device->dsbd.dwFlags & DSBCAPS_CTRLVOLUME)) {
|
2003-06-28 00:22:15 +02:00
|
|
|
WARN("control unavailable\n");
|
|
|
|
return DSERR_CONTROLUNAVAIL;
|
|
|
|
}
|
|
|
|
|
2003-05-22 05:39:13 +02:00
|
|
|
if (vol == NULL) {
|
|
|
|
WARN("invalid parameter: vol = NULL\n");
|
2002-06-13 21:15:06 +02:00
|
|
|
return DSERR_INVALIDPARAM;
|
2003-05-22 05:39:13 +02:00
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
waveOutGetVolume(device->hwo, &factors);
|
2004-07-23 21:06:31 +02:00
|
|
|
volpan.dwTotalLeftAmpFactor=ampfactors & 0xffff;
|
|
|
|
volpan.dwTotalRightAmpFactor=ampfactors >> 16;
|
|
|
|
DSOUND_AmpFactorToVolPan(&volpan);
|
|
|
|
*vol = volpan.lVolume;
|
2002-06-13 21:15:06 +02:00
|
|
|
return DS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_SetFrequency(
|
|
|
|
LPDIRECTSOUNDBUFFER8 iface,DWORD freq
|
|
|
|
) {
|
2004-09-09 22:17:07 +02:00
|
|
|
PrimaryBufferImpl *This = (PrimaryBufferImpl *)iface;
|
2006-11-12 14:40:35 +01:00
|
|
|
TRACE("(%p,%d)\n",This,freq);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
|
|
|
/* You cannot set the frequency of the primary buffer */
|
2003-05-22 05:39:13 +02:00
|
|
|
WARN("control unavailable\n");
|
2002-06-13 21:15:06 +02:00
|
|
|
return DSERR_CONTROLUNAVAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_Play(
|
|
|
|
LPDIRECTSOUNDBUFFER8 iface,DWORD reserved1,DWORD reserved2,DWORD flags
|
|
|
|
) {
|
2006-01-06 12:35:20 +01:00
|
|
|
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
|
2006-11-12 14:40:35 +01:00
|
|
|
TRACE("(%p,%08x,%08x,%08x)\n", iface, reserved1, reserved2, flags);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2003-05-22 05:39:13 +02:00
|
|
|
if (!(flags & DSBPLAY_LOOPING)) {
|
2006-11-12 14:40:35 +01:00
|
|
|
WARN("invalid parameter: flags = %08x\n", flags);
|
2002-06-13 21:15:06 +02:00
|
|
|
return DSERR_INVALIDPARAM;
|
2003-05-22 05:39:13 +02:00
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
|
|
|
|
/* **** */
|
2005-05-31 11:31:37 +02:00
|
|
|
EnterCriticalSection(&(device->mixlock));
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
if (device->state == STATE_STOPPED)
|
|
|
|
device->state = STATE_STARTING;
|
|
|
|
else if (device->state == STATE_STOPPING)
|
|
|
|
device->state = STATE_PLAYING;
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
LeaveCriticalSection(&(device->mixlock));
|
2002-06-13 21:15:06 +02:00
|
|
|
/* **** */
|
|
|
|
|
|
|
|
return DS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_Stop(LPDIRECTSOUNDBUFFER8 iface)
|
|
|
|
{
|
2006-01-06 12:35:20 +01:00
|
|
|
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
|
2005-05-31 11:31:37 +02:00
|
|
|
TRACE("(%p)\n", iface);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
|
|
|
/* **** */
|
2005-05-31 11:31:37 +02:00
|
|
|
EnterCriticalSection(&(device->mixlock));
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
if (device->state == STATE_PLAYING)
|
|
|
|
device->state = STATE_STOPPING;
|
|
|
|
else if (device->state == STATE_STARTING)
|
|
|
|
device->state = STATE_STOPPED;
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
LeaveCriticalSection(&(device->mixlock));
|
2002-06-13 21:15:06 +02:00
|
|
|
/* **** */
|
|
|
|
|
|
|
|
return DS_OK;
|
|
|
|
}
|
|
|
|
|
2005-02-11 12:49:05 +01:00
|
|
|
static ULONG WINAPI PrimaryBufferImpl_AddRef(LPDIRECTSOUNDBUFFER8 iface)
|
|
|
|
{
|
|
|
|
PrimaryBufferImpl *This = (PrimaryBufferImpl *)iface;
|
|
|
|
ULONG ref = InterlockedIncrement(&(This->ref));
|
2006-11-12 14:40:35 +01:00
|
|
|
TRACE("(%p) ref was %d\n", This, ref - 1);
|
2005-02-11 12:49:05 +01:00
|
|
|
return ref;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
2003-06-28 00:22:15 +02:00
|
|
|
|
2005-02-11 12:49:05 +01:00
|
|
|
static ULONG WINAPI PrimaryBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface)
|
|
|
|
{
|
|
|
|
PrimaryBufferImpl *This = (PrimaryBufferImpl *)iface;
|
|
|
|
DWORD ref = InterlockedDecrement(&(This->ref));
|
2006-11-12 14:40:35 +01:00
|
|
|
TRACE("(%p) ref was %d\n", This, ref + 1);
|
2005-02-11 12:49:05 +01:00
|
|
|
|
|
|
|
if (!ref) {
|
2006-01-06 12:35:20 +01:00
|
|
|
This->device->primary = NULL;
|
2005-02-11 12:49:05 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
TRACE("(%p) released\n", This);
|
|
|
|
}
|
|
|
|
return ref;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_GetCurrentPosition(
|
|
|
|
LPDIRECTSOUNDBUFFER8 iface,LPDWORD playpos,LPDWORD writepos
|
|
|
|
) {
|
2003-05-22 05:39:13 +02:00
|
|
|
HRESULT hres;
|
2006-01-06 12:35:20 +01:00
|
|
|
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
|
2005-05-31 11:31:37 +02:00
|
|
|
TRACE("(%p,%p,%p)\n", iface, playpos, writepos);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
hres = DSOUND_PrimaryGetPosition(device, playpos, writepos);
|
2003-05-22 05:39:13 +02:00
|
|
|
if (hres != DS_OK) {
|
|
|
|
WARN("DSOUND_PrimaryGetPosition failed\n");
|
|
|
|
return hres;
|
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
if (writepos) {
|
2005-05-31 11:31:37 +02:00
|
|
|
if (device->state != STATE_STOPPED)
|
2002-06-13 21:15:06 +02:00
|
|
|
/* apply the documented 10ms lead to writepos */
|
2005-05-31 11:31:37 +02:00
|
|
|
*writepos += device->writelead;
|
|
|
|
while (*writepos >= device->buflen) *writepos -= device->buflen;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
2006-11-12 14:40:35 +01:00
|
|
|
TRACE("playpos = %d, writepos = %d (%p, time=%d)\n", playpos?*playpos:0, writepos?*writepos:0, device, GetTickCount());
|
2002-06-13 21:15:06 +02:00
|
|
|
return DS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_GetStatus(
|
|
|
|
LPDIRECTSOUNDBUFFER8 iface,LPDWORD status
|
|
|
|
) {
|
2006-01-06 12:35:20 +01:00
|
|
|
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
|
2005-05-31 11:31:37 +02:00
|
|
|
TRACE("(%p,%p)\n", iface, status);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2003-05-22 05:39:13 +02:00
|
|
|
if (status == NULL) {
|
|
|
|
WARN("invalid parameter: status == NULL\n");
|
2002-06-13 21:15:06 +02:00
|
|
|
return DSERR_INVALIDPARAM;
|
2003-05-22 05:39:13 +02:00
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
|
|
|
|
*status = 0;
|
2005-05-31 11:31:37 +02:00
|
|
|
if ((device->state == STATE_STARTING) ||
|
|
|
|
(device->state == STATE_PLAYING))
|
2002-06-13 21:15:06 +02:00
|
|
|
*status |= DSBSTATUS_PLAYING | DSBSTATUS_LOOPING;
|
|
|
|
|
2006-11-12 14:40:35 +01:00
|
|
|
TRACE("status=%x\n", *status);
|
2002-06-13 21:15:06 +02:00
|
|
|
return DS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_GetFormat(
|
2004-08-18 02:30:37 +02:00
|
|
|
LPDIRECTSOUNDBUFFER8 iface,
|
|
|
|
LPWAVEFORMATEX lpwf,
|
|
|
|
DWORD wfsize,
|
|
|
|
LPDWORD wfwritten)
|
|
|
|
{
|
|
|
|
DWORD size;
|
2006-01-06 12:35:20 +01:00
|
|
|
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
|
2006-11-12 14:40:35 +01:00
|
|
|
TRACE("(%p,%p,%d,%p)\n", iface, lpwf, wfsize, wfwritten);
|
2004-08-18 02:30:37 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
size = sizeof(WAVEFORMATEX) + device->pwfx->cbSize;
|
2004-08-18 02:30:37 +02:00
|
|
|
|
|
|
|
if (lpwf) { /* NULL is valid */
|
|
|
|
if (wfsize >= size) {
|
2005-05-31 11:31:37 +02:00
|
|
|
CopyMemory(lpwf,device->pwfx,size);
|
2004-08-18 02:30:37 +02:00
|
|
|
if (wfwritten)
|
|
|
|
*wfwritten = size;
|
|
|
|
} else {
|
2005-05-06 17:44:31 +02:00
|
|
|
WARN("invalid parameter: wfsize too small\n");
|
2004-08-18 02:30:37 +02:00
|
|
|
if (wfwritten)
|
|
|
|
*wfwritten = 0;
|
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (wfwritten)
|
2005-05-31 11:31:37 +02:00
|
|
|
*wfwritten = sizeof(WAVEFORMATEX) + device->pwfx->cbSize;
|
2004-08-18 02:30:37 +02:00
|
|
|
else {
|
|
|
|
WARN("invalid parameter: wfwritten == NULL\n");
|
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2004-08-18 02:30:37 +02:00
|
|
|
return DS_OK;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_Lock(
|
2007-03-08 14:48:45 +01:00
|
|
|
LPDIRECTSOUNDBUFFER8 iface,DWORD writecursor,DWORD writebytes,LPVOID *lplpaudioptr1,LPDWORD audiobytes1,LPVOID *lplpaudioptr2,LPDWORD audiobytes2,DWORD flags
|
2002-06-13 21:15:06 +02:00
|
|
|
) {
|
2006-04-29 05:40:09 +02:00
|
|
|
HRESULT hres;
|
2006-01-06 12:35:20 +01:00
|
|
|
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
|
2006-11-12 14:40:35 +01:00
|
|
|
TRACE("(%p,%d,%d,%p,%p,%p,%p,0x%08x) at %d\n",
|
2005-05-31 11:31:37 +02:00
|
|
|
iface,
|
2002-06-13 21:15:06 +02:00
|
|
|
writecursor,
|
|
|
|
writebytes,
|
|
|
|
lplpaudioptr1,
|
|
|
|
audiobytes1,
|
|
|
|
lplpaudioptr2,
|
|
|
|
audiobytes2,
|
|
|
|
flags,
|
|
|
|
GetTickCount()
|
|
|
|
);
|
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
if (device->priolevel != DSSCL_WRITEPRIMARY) {
|
2003-05-22 05:39:13 +02:00
|
|
|
WARN("failed priority check!\n");
|
2002-06-13 21:15:06 +02:00
|
|
|
return DSERR_PRIOLEVELNEEDED;
|
2003-05-22 05:39:13 +02:00
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2006-04-29 05:40:09 +02:00
|
|
|
/* when this flag is set, writecursor is meaningless and must be calculated */
|
2002-06-13 21:15:06 +02:00
|
|
|
if (flags & DSBLOCK_FROMWRITECURSOR) {
|
|
|
|
/* GetCurrentPosition does too much magic to duplicate here */
|
2006-04-29 05:40:09 +02:00
|
|
|
hres = IDirectSoundBuffer_GetCurrentPosition(iface, NULL, &writecursor);
|
2003-05-22 05:39:13 +02:00
|
|
|
if (hres != DS_OK) {
|
|
|
|
WARN("IDirectSoundBuffer_GetCurrentPosition failed\n");
|
|
|
|
return hres;
|
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
2006-04-29 05:40:09 +02:00
|
|
|
|
|
|
|
/* when this flag is set, writebytes is meaningless and must be set */
|
2002-06-13 21:15:06 +02:00
|
|
|
if (flags & DSBLOCK_ENTIREBUFFER)
|
2005-05-31 11:31:37 +02:00
|
|
|
writebytes = device->buflen;
|
2006-04-29 05:40:09 +02:00
|
|
|
|
|
|
|
if (writecursor >= device->buflen) {
|
2006-11-12 14:40:35 +01:00
|
|
|
WARN("Invalid parameter, writecursor: %u >= buflen: %u\n",
|
2006-04-29 05:40:09 +02:00
|
|
|
writecursor, device->buflen);
|
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (writebytes > device->buflen) {
|
2006-11-12 14:40:35 +01:00
|
|
|
WARN("Invalid parameter, writebytes: %u > buflen: %u\n",
|
2006-04-29 05:40:09 +02:00
|
|
|
writebytes, device->buflen);
|
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
if (!(device->drvdesc.dwFlags & DSDDESC_DONTNEEDPRIMARYLOCK) && device->hwbuf) {
|
|
|
|
hres = IDsDriverBuffer_Lock(device->hwbuf,
|
2003-05-22 05:39:13 +02:00
|
|
|
lplpaudioptr1, audiobytes1,
|
|
|
|
lplpaudioptr2, audiobytes2,
|
|
|
|
writecursor, writebytes,
|
|
|
|
0);
|
|
|
|
if (hres != DS_OK) {
|
|
|
|
WARN("IDsDriverBuffer_Lock failed\n");
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
} else {
|
2005-05-31 11:31:37 +02:00
|
|
|
if (writecursor+writebytes <= device->buflen) {
|
|
|
|
*(LPBYTE*)lplpaudioptr1 = device->buffer+writecursor;
|
2002-06-13 21:15:06 +02:00
|
|
|
*audiobytes1 = writebytes;
|
|
|
|
if (lplpaudioptr2)
|
|
|
|
*(LPBYTE*)lplpaudioptr2 = NULL;
|
|
|
|
if (audiobytes2)
|
|
|
|
*audiobytes2 = 0;
|
2006-11-12 14:40:35 +01:00
|
|
|
TRACE("->%d.0\n",writebytes);
|
2002-06-13 21:15:06 +02:00
|
|
|
} else {
|
2005-05-31 11:31:37 +02:00
|
|
|
*(LPBYTE*)lplpaudioptr1 = device->buffer+writecursor;
|
|
|
|
*audiobytes1 = device->buflen-writecursor;
|
2002-06-13 21:15:06 +02:00
|
|
|
if (lplpaudioptr2)
|
2005-05-31 11:31:37 +02:00
|
|
|
*(LPBYTE*)lplpaudioptr2 = device->buffer;
|
2002-06-13 21:15:06 +02:00
|
|
|
if (audiobytes2)
|
2005-05-31 11:31:37 +02:00
|
|
|
*audiobytes2 = writebytes-(device->buflen-writecursor);
|
2006-11-12 14:40:35 +01:00
|
|
|
TRACE("->%d.%d\n",*audiobytes1,audiobytes2?*audiobytes2:0);
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return DS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_SetCurrentPosition(
|
|
|
|
LPDIRECTSOUNDBUFFER8 iface,DWORD newpos
|
|
|
|
) {
|
2004-09-09 22:17:07 +02:00
|
|
|
PrimaryBufferImpl *This = (PrimaryBufferImpl *)iface;
|
2006-11-12 14:40:35 +01:00
|
|
|
TRACE("(%p,%d)\n",This,newpos);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
|
|
|
/* You cannot set the position of the primary buffer */
|
2003-05-22 05:39:13 +02:00
|
|
|
WARN("invalid call\n");
|
2002-06-13 21:15:06 +02:00
|
|
|
return DSERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_SetPan(
|
|
|
|
LPDIRECTSOUNDBUFFER8 iface,LONG pan
|
|
|
|
) {
|
2006-01-06 12:35:20 +01:00
|
|
|
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
|
2004-07-23 21:06:31 +02:00
|
|
|
DWORD ampfactors;
|
|
|
|
DSVOLUMEPAN volpan;
|
2004-09-10 21:34:01 +02:00
|
|
|
HRESULT hres = DS_OK;
|
2006-11-12 14:40:35 +01:00
|
|
|
TRACE("(%p,%d)\n", iface, pan);
|
2003-09-15 22:08:05 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
if (!(device->dsbd.dwFlags & DSBCAPS_CTRLPAN)) {
|
2003-09-15 22:08:05 +02:00
|
|
|
WARN("control unavailable\n");
|
|
|
|
return DSERR_CONTROLUNAVAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((pan > DSBPAN_RIGHT) || (pan < DSBPAN_LEFT)) {
|
2006-11-12 14:40:35 +01:00
|
|
|
WARN("invalid parameter: pan = %d\n", pan);
|
2003-09-15 22:08:05 +02:00
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* **** */
|
2005-05-31 11:31:37 +02:00
|
|
|
EnterCriticalSection(&(device->mixlock));
|
2003-09-15 22:08:05 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
waveOutGetVolume(device->hwo, &factors);
|
2004-07-23 21:06:31 +02:00
|
|
|
volpan.dwTotalLeftAmpFactor=ampfactors & 0xffff;
|
|
|
|
volpan.dwTotalRightAmpFactor=ampfactors >> 16;
|
|
|
|
DSOUND_AmpFactorToVolPan(&volpan);
|
|
|
|
if (pan != volpan.lPan) {
|
|
|
|
volpan.lPan=pan;
|
|
|
|
DSOUND_RecalcVolPan(&volpan);
|
2005-05-31 11:31:37 +02:00
|
|
|
if (device->hwbuf) {
|
|
|
|
hres = IDsDriverBuffer_SetVolumePan(device->hwbuf, &volpan);
|
2004-09-07 21:32:21 +02:00
|
|
|
if (hres != DS_OK)
|
2004-07-23 21:06:31 +02:00
|
|
|
WARN("IDsDriverBuffer_SetVolumePan failed\n");
|
2004-09-10 21:34:01 +02:00
|
|
|
} else {
|
2004-07-23 21:06:31 +02:00
|
|
|
ampfactors = (volpan.dwTotalLeftAmpFactor & 0xffff) | (volpan.dwTotalRightAmpFactor << 16);
|
2005-05-31 11:31:37 +02:00
|
|
|
waveOutSetVolume(device->hwo, ampfactors);
|
2004-07-23 21:06:31 +02:00
|
|
|
}
|
|
|
|
}
|
2003-09-15 22:08:05 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
LeaveCriticalSection(&(device->mixlock));
|
2003-09-15 22:08:05 +02:00
|
|
|
/* **** */
|
|
|
|
|
2004-09-10 21:34:01 +02:00
|
|
|
return hres;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_GetPan(
|
|
|
|
LPDIRECTSOUNDBUFFER8 iface,LPLONG pan
|
|
|
|
) {
|
2006-01-06 12:35:20 +01:00
|
|
|
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
|
2004-07-23 21:06:31 +02:00
|
|
|
DWORD ampfactors;
|
|
|
|
DSVOLUMEPAN volpan;
|
2005-05-31 11:31:37 +02:00
|
|
|
TRACE("(%p,%p)\n", iface, pan);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
if (!(device->dsbd.dwFlags & DSBCAPS_CTRLPAN)) {
|
2003-09-15 22:08:05 +02:00
|
|
|
WARN("control unavailable\n");
|
|
|
|
return DSERR_CONTROLUNAVAIL;
|
|
|
|
}
|
|
|
|
|
2003-05-22 05:39:13 +02:00
|
|
|
if (pan == NULL) {
|
|
|
|
WARN("invalid parameter: pan == NULL\n");
|
2002-06-13 21:15:06 +02:00
|
|
|
return DSERR_INVALIDPARAM;
|
2003-05-22 05:39:13 +02:00
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
waveOutGetVolume(device->hwo, &factors);
|
2004-07-23 21:06:31 +02:00
|
|
|
volpan.dwTotalLeftAmpFactor=ampfactors & 0xffff;
|
|
|
|
volpan.dwTotalRightAmpFactor=ampfactors >> 16;
|
|
|
|
DSOUND_AmpFactorToVolPan(&volpan);
|
|
|
|
*pan = volpan.lPan;
|
2002-06-13 21:15:06 +02:00
|
|
|
return DS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_Unlock(
|
|
|
|
LPDIRECTSOUNDBUFFER8 iface,LPVOID p1,DWORD x1,LPVOID p2,DWORD x2
|
|
|
|
) {
|
2006-01-06 12:35:20 +01:00
|
|
|
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
|
2006-11-12 14:40:35 +01:00
|
|
|
TRACE("(%p,%p,%d,%p,%d)\n", iface, p1, x1, p2, x2);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
if (device->priolevel != DSSCL_WRITEPRIMARY) {
|
2003-05-22 05:39:13 +02:00
|
|
|
WARN("failed priority check!\n");
|
2002-06-13 21:15:06 +02:00
|
|
|
return DSERR_PRIOLEVELNEEDED;
|
2003-05-22 05:39:13 +02:00
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
if (!(device->drvdesc.dwFlags & DSDDESC_DONTNEEDPRIMARYLOCK) && device->hwbuf) {
|
2003-05-22 05:39:13 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
hres = IDsDriverBuffer_Unlock(device->hwbuf, p1, x1, p2, x2);
|
2003-05-22 05:39:13 +02:00
|
|
|
if (hres != DS_OK) {
|
|
|
|
WARN("IDsDriverBuffer_Unlock failed\n");
|
|
|
|
return hres;
|
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return DS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_Restore(
|
|
|
|
LPDIRECTSOUNDBUFFER8 iface
|
|
|
|
) {
|
2004-09-09 22:17:07 +02:00
|
|
|
PrimaryBufferImpl *This = (PrimaryBufferImpl *)iface;
|
2002-06-13 21:15:06 +02:00
|
|
|
FIXME("(%p):stub\n",This);
|
|
|
|
return DS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_GetFrequency(
|
|
|
|
LPDIRECTSOUNDBUFFER8 iface,LPDWORD freq
|
|
|
|
) {
|
2006-01-06 12:35:20 +01:00
|
|
|
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
|
2005-05-31 11:31:37 +02:00
|
|
|
TRACE("(%p,%p)\n", iface, freq);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2003-05-22 05:39:13 +02:00
|
|
|
if (freq == NULL) {
|
|
|
|
WARN("invalid parameter: freq == NULL\n");
|
2002-06-13 21:15:06 +02:00
|
|
|
return DSERR_INVALIDPARAM;
|
2003-05-22 05:39:13 +02:00
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
if (!(device->dsbd.dwFlags & DSBCAPS_CTRLFREQUENCY)) {
|
2003-06-28 00:22:15 +02:00
|
|
|
WARN("control unavailable\n");
|
|
|
|
return DSERR_CONTROLUNAVAIL;
|
|
|
|
}
|
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
*freq = device->pwfx->nSamplesPerSec;
|
2006-11-12 14:40:35 +01:00
|
|
|
TRACE("-> %d\n", *freq);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
|
|
|
return DS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_SetFX(
|
|
|
|
LPDIRECTSOUNDBUFFER8 iface,DWORD dwEffectsCount,LPDSEFFECTDESC pDSFXDesc,LPDWORD pdwResultCodes
|
|
|
|
) {
|
2004-09-09 22:17:07 +02:00
|
|
|
PrimaryBufferImpl *This = (PrimaryBufferImpl *)iface;
|
2002-06-13 21:15:06 +02:00
|
|
|
DWORD u;
|
2006-11-12 14:40:35 +01:00
|
|
|
FIXME("(%p,%u,%p,%p): stub\n",This,dwEffectsCount,pDSFXDesc,pdwResultCodes);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
|
|
|
if (pdwResultCodes)
|
|
|
|
for (u=0; u<dwEffectsCount; u++) pdwResultCodes[u] = DSFXR_UNKNOWN;
|
|
|
|
|
2003-05-22 05:39:13 +02:00
|
|
|
WARN("control unavailable\n");
|
2002-06-13 21:15:06 +02:00
|
|
|
return DSERR_CONTROLUNAVAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_AcquireResources(
|
|
|
|
LPDIRECTSOUNDBUFFER8 iface,DWORD dwFlags,DWORD dwEffectsCount,LPDWORD pdwResultCodes
|
|
|
|
) {
|
2004-09-09 22:17:07 +02:00
|
|
|
PrimaryBufferImpl *This = (PrimaryBufferImpl *)iface;
|
2002-06-13 21:15:06 +02:00
|
|
|
DWORD u;
|
2006-11-12 14:40:35 +01:00
|
|
|
FIXME("(%p,%08u,%u,%p): stub\n",This,dwFlags,dwEffectsCount,pdwResultCodes);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
|
|
|
if (pdwResultCodes)
|
|
|
|
for (u=0; u<dwEffectsCount; u++) pdwResultCodes[u] = DSFXR_UNKNOWN;
|
|
|
|
|
2003-05-22 05:39:13 +02:00
|
|
|
WARN("control unavailable\n");
|
2002-06-13 21:15:06 +02:00
|
|
|
return DSERR_CONTROLUNAVAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_GetObjectInPath(
|
|
|
|
LPDIRECTSOUNDBUFFER8 iface,REFGUID rguidObject,DWORD dwIndex,REFGUID rguidInterface,LPVOID* ppObject
|
|
|
|
) {
|
2004-09-09 22:17:07 +02:00
|
|
|
PrimaryBufferImpl *This = (PrimaryBufferImpl *)iface;
|
2006-11-12 14:40:35 +01:00
|
|
|
FIXME("(%p,%s,%u,%s,%p): stub\n",This,debugstr_guid(rguidObject),dwIndex,debugstr_guid(rguidInterface),ppObject);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2003-05-22 05:39:13 +02:00
|
|
|
WARN("control unavailable\n");
|
2002-06-13 21:15:06 +02:00
|
|
|
return DSERR_CONTROLUNAVAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_Initialize(
|
2004-07-06 21:27:00 +02:00
|
|
|
LPDIRECTSOUNDBUFFER8 iface,LPDIRECTSOUND dsound,LPCDSBUFFERDESC dbsd
|
2002-06-13 21:15:06 +02:00
|
|
|
) {
|
2004-09-09 22:17:07 +02:00
|
|
|
PrimaryBufferImpl *This = (PrimaryBufferImpl *)iface;
|
2002-06-13 21:15:06 +02:00
|
|
|
FIXME("(%p,%p,%p):stub\n",This,dsound,dbsd);
|
|
|
|
DPRINTF("Re-Init!!!\n");
|
2003-05-22 05:39:13 +02:00
|
|
|
WARN("already initialized\n");
|
2002-06-13 21:15:06 +02:00
|
|
|
return DSERR_ALREADYINITIALIZED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_GetCaps(
|
|
|
|
LPDIRECTSOUNDBUFFER8 iface,LPDSBCAPS caps
|
|
|
|
) {
|
2006-01-06 12:35:20 +01:00
|
|
|
DirectSoundDevice *device = ((PrimaryBufferImpl *)iface)->device;
|
2005-05-31 11:31:37 +02:00
|
|
|
TRACE("(%p,%p)\n", iface, caps);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2003-05-22 05:39:13 +02:00
|
|
|
if (caps == NULL) {
|
|
|
|
WARN("invalid parameter: caps == NULL\n");
|
2002-06-13 21:15:06 +02:00
|
|
|
return DSERR_INVALIDPARAM;
|
2003-05-22 05:39:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (caps->dwSize < sizeof(*caps)) {
|
2006-11-12 14:40:35 +01:00
|
|
|
WARN("invalid parameter: caps->dwSize = %d\n", caps->dwSize);
|
2003-05-22 05:39:13 +02:00
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
caps->dwFlags = device->dsbd.dwFlags;
|
|
|
|
if (device->hwbuf) caps->dwFlags |= DSBCAPS_LOCHARDWARE;
|
2002-06-13 21:15:06 +02:00
|
|
|
else caps->dwFlags |= DSBCAPS_LOCSOFTWARE;
|
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
caps->dwBufferBytes = device->buflen;
|
2002-06-13 21:15:06 +02:00
|
|
|
|
|
|
|
/* This value represents the speed of the "unlock" command.
|
|
|
|
As unlock is quite fast (it does not do anything), I put
|
|
|
|
4096 ko/s = 4 Mo / s */
|
|
|
|
/* FIXME: hwbuf speed */
|
|
|
|
caps->dwUnlockTransferRate = 4096;
|
|
|
|
caps->dwPlayCpuOverhead = 0;
|
|
|
|
|
|
|
|
return DS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_QueryInterface(
|
|
|
|
LPDIRECTSOUNDBUFFER8 iface,REFIID riid,LPVOID *ppobj
|
|
|
|
) {
|
2005-05-31 11:31:37 +02:00
|
|
|
PrimaryBufferImpl *This = (PrimaryBufferImpl *)iface;
|
2006-01-06 12:35:20 +01:00
|
|
|
DirectSoundDevice *device = This->device;
|
2005-05-31 11:31:37 +02:00
|
|
|
TRACE("(%p,%s,%p)\n", iface, debugstr_guid(riid), ppobj);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2003-08-07 00:57:24 +02:00
|
|
|
if (ppobj == NULL) {
|
|
|
|
WARN("invalid parameter\n");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2003-06-28 00:22:15 +02:00
|
|
|
*ppobj = NULL; /* assume failure */
|
|
|
|
|
2004-08-18 02:30:37 +02:00
|
|
|
if ( IsEqualGUID(riid, &IID_IUnknown) ||
|
2003-06-28 00:22:15 +02:00
|
|
|
IsEqualGUID(riid, &IID_IDirectSoundBuffer) ) {
|
|
|
|
IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER)This);
|
|
|
|
*ppobj = This;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DirectSoundBuffer and DirectSoundBuffer8 are different and */
|
|
|
|
/* a primary buffer can't have a DirectSoundBuffer8 interface */
|
|
|
|
if ( IsEqualGUID( &IID_IDirectSoundBuffer8, riid ) ) {
|
|
|
|
WARN("app requested DirectSoundBuffer8 on primary buffer\n");
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2002-06-13 21:15:06 +02:00
|
|
|
if ( IsEqualGUID( &IID_IDirectSoundNotify, riid ) ) {
|
|
|
|
ERR("app requested IDirectSoundNotify on primary buffer\n");
|
2003-05-22 05:39:13 +02:00
|
|
|
/* FIXME: should we support this? */
|
2003-06-28 00:22:15 +02:00
|
|
|
return E_NOINTERFACE;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( IsEqualGUID( &IID_IDirectSound3DBuffer, riid ) ) {
|
|
|
|
ERR("app requested IDirectSound3DBuffer on primary buffer\n");
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( IsEqualGUID( &IID_IDirectSound3DListener, riid ) ) {
|
2005-05-31 11:31:37 +02:00
|
|
|
if (!device->listener)
|
2006-01-06 12:35:20 +01:00
|
|
|
IDirectSound3DListenerImpl_Create(device, &device->listener);
|
2005-05-31 11:31:37 +02:00
|
|
|
if (device->listener) {
|
|
|
|
*ppobj = device->listener;
|
2003-09-02 01:58:43 +02:00
|
|
|
IDirectSound3DListener_AddRef((LPDIRECTSOUND3DLISTENER)*ppobj);
|
|
|
|
return S_OK;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
2003-06-28 00:22:15 +02:00
|
|
|
|
2003-05-22 05:39:13 +02:00
|
|
|
WARN("IID_IDirectSound3DListener failed\n");
|
2003-06-28 00:22:15 +02:00
|
|
|
return E_NOINTERFACE;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( IsEqualGUID( &IID_IKsPropertySet, riid ) ) {
|
|
|
|
FIXME("app requested IKsPropertySet on primary buffer\n");
|
2003-06-28 00:22:15 +02:00
|
|
|
return E_NOINTERFACE;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
FIXME( "Unknown IID %s\n", debugstr_guid( riid ) );
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2005-06-01 21:57:42 +02:00
|
|
|
static const IDirectSoundBuffer8Vtbl dspbvt =
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
|
|
|
PrimaryBufferImpl_QueryInterface,
|
|
|
|
PrimaryBufferImpl_AddRef,
|
|
|
|
PrimaryBufferImpl_Release,
|
|
|
|
PrimaryBufferImpl_GetCaps,
|
|
|
|
PrimaryBufferImpl_GetCurrentPosition,
|
|
|
|
PrimaryBufferImpl_GetFormat,
|
|
|
|
PrimaryBufferImpl_GetVolume,
|
|
|
|
PrimaryBufferImpl_GetPan,
|
|
|
|
PrimaryBufferImpl_GetFrequency,
|
|
|
|
PrimaryBufferImpl_GetStatus,
|
|
|
|
PrimaryBufferImpl_Initialize,
|
|
|
|
PrimaryBufferImpl_Lock,
|
|
|
|
PrimaryBufferImpl_Play,
|
|
|
|
PrimaryBufferImpl_SetCurrentPosition,
|
|
|
|
PrimaryBufferImpl_SetFormat,
|
|
|
|
PrimaryBufferImpl_SetVolume,
|
|
|
|
PrimaryBufferImpl_SetPan,
|
|
|
|
PrimaryBufferImpl_SetFrequency,
|
|
|
|
PrimaryBufferImpl_Stop,
|
|
|
|
PrimaryBufferImpl_Unlock,
|
|
|
|
PrimaryBufferImpl_Restore,
|
|
|
|
PrimaryBufferImpl_SetFX,
|
|
|
|
PrimaryBufferImpl_AcquireResources,
|
|
|
|
PrimaryBufferImpl_GetObjectInPath
|
|
|
|
};
|
|
|
|
|
2006-01-03 17:32:50 +01:00
|
|
|
HRESULT PrimaryBufferImpl_Create(
|
2006-01-06 12:35:20 +01:00
|
|
|
DirectSoundDevice * device,
|
|
|
|
PrimaryBufferImpl ** ppdsb,
|
2004-01-09 23:06:54 +01:00
|
|
|
LPCDSBUFFERDESC dsbd)
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
|
|
|
PrimaryBufferImpl *dsb;
|
2006-01-06 12:35:20 +01:00
|
|
|
TRACE("%p,%p,%p)\n",device,ppdsb,dsbd);
|
2003-05-02 23:23:16 +02:00
|
|
|
|
2003-05-22 05:39:13 +02:00
|
|
|
if (dsbd->lpwfxFormat) {
|
|
|
|
WARN("invalid parameter: dsbd->lpwfxFormat != NULL\n");
|
2006-01-06 12:35:20 +01:00
|
|
|
*ppdsb = NULL;
|
2002-06-13 21:15:06 +02:00
|
|
|
return DSERR_INVALIDPARAM;
|
2003-05-22 05:39:13 +02:00
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2004-08-18 02:30:37 +02:00
|
|
|
dsb = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*dsb));
|
2003-05-22 05:39:13 +02:00
|
|
|
|
|
|
|
if (dsb == NULL) {
|
|
|
|
WARN("out of memory\n");
|
2006-01-06 12:35:20 +01:00
|
|
|
*ppdsb = NULL;
|
2003-05-22 05:39:13 +02:00
|
|
|
return DSERR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2003-09-02 01:58:43 +02:00
|
|
|
dsb->ref = 0;
|
2006-01-06 12:35:20 +01:00
|
|
|
dsb->device = device;
|
2003-04-10 20:17:34 +02:00
|
|
|
dsb->lpVtbl = &dspbvt;
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2006-01-06 12:35:20 +01:00
|
|
|
CopyMemory(&device->dsbd, dsbd, sizeof(*dsbd));
|
2002-06-13 21:15:06 +02:00
|
|
|
|
|
|
|
TRACE("Created primary buffer at %p\n", dsb);
|
2006-11-12 14:40:35 +01:00
|
|
|
TRACE("(formattag=0x%04x,chans=%d,samplerate=%d,"
|
|
|
|
"bytespersec=%d,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
|
2006-01-06 12:35:20 +01:00
|
|
|
device->pwfx->wFormatTag, device->pwfx->nChannels,
|
|
|
|
device->pwfx->nSamplesPerSec, device->pwfx->nAvgBytesPerSec,
|
|
|
|
device->pwfx->nBlockAlign, device->pwfx->wBitsPerSample,
|
|
|
|
device->pwfx->cbSize);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2006-01-06 12:35:20 +01:00
|
|
|
*ppdsb = dsb;
|
2002-06-13 21:15:06 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|