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
|
2009-10-04 08:05:20 +02:00
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
* When PrimarySetFormat (via ReopenDevice or PrimaryOpen) fails,
|
|
|
|
* it leaves dsound in unusable (not really open) state.
|
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
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
#define COBJMACROS
|
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 "dsound_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dsound);
|
|
|
|
|
2007-09-29 01:54:03 +02:00
|
|
|
/** Calculate how long a fragment length of about 10 ms should be in frames
|
|
|
|
*
|
|
|
|
* 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)
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
2008-12-22 14:33:43 +01:00
|
|
|
/* Given a timer delay of 10ms, the fragment size is approximately:
|
|
|
|
* fraglen = (nSamplesPerSec * 10 / 1000) * nBlockAlign
|
|
|
|
* ==> fraglen = (nSamplesPerSec / 100) * nBlockSize
|
|
|
|
*
|
|
|
|
* ALSA uses buffers that are powers of 2. Because of this, fraglen
|
|
|
|
* is rounded up to the nearest power of 2:
|
|
|
|
*/
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2008-12-22 14:33:43 +01:00
|
|
|
if (nSamplesPerSec <= 12800)
|
|
|
|
return 128 * nBlockAlign;
|
2007-07-30 16:44:50 +02:00
|
|
|
|
2008-12-22 14:33:43 +01:00
|
|
|
if (nSamplesPerSec <= 25600)
|
|
|
|
return 256 * nBlockAlign;
|
2007-07-30 16:44:50 +02:00
|
|
|
|
2008-12-22 14:33:43 +01:00
|
|
|
if (nSamplesPerSec <= 51200)
|
|
|
|
return 512 * nBlockAlign;
|
2007-07-30 16:44:50 +02:00
|
|
|
|
2008-12-22 14:33:43 +01:00
|
|
|
return 1024 * nBlockAlign;
|
2007-09-29 01:54:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void DSOUND_RecalcPrimary(DirectSoundDevice *device)
|
|
|
|
{
|
|
|
|
TRACE("(%p)\n", device);
|
2007-07-30 16:44:50 +02:00
|
|
|
|
2007-09-29 01:54:03 +02:00
|
|
|
device->fraglen = DSOUND_fraglen(device->pwfx->nSamplesPerSec, device->pwfx->nBlockAlign);
|
|
|
|
device->helfrags = device->buflen / device->fraglen;
|
|
|
|
TRACE("fraglen=%d helfrags=%d\n", device->fraglen, device->helfrags);
|
2007-07-30 16:44:50 +02:00
|
|
|
|
2011-09-24 16:02:52 +02:00
|
|
|
/* calculate the 10ms write lead */
|
|
|
|
device->writelead = (device->pwfx->nSamplesPerSec / 100) * device->pwfx->nBlockAlign;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
|
2007-08-27 17:07:14 +02:00
|
|
|
HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave)
|
|
|
|
{
|
2011-09-27 15:51:07 +02:00
|
|
|
HRESULT hres;
|
2007-09-05 10:58:52 +02:00
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
TRACE("(%p, %d)\n", device, forcewave);
|
|
|
|
|
|
|
|
if(device->client){
|
|
|
|
IAudioClient_Release(device->client);
|
|
|
|
device->client = NULL;
|
|
|
|
}
|
|
|
|
if(device->render){
|
|
|
|
IAudioRenderClient_Release(device->render);
|
|
|
|
device->render = NULL;
|
|
|
|
}
|
|
|
|
if(device->clock){
|
|
|
|
IAudioClock_Release(device->clock);
|
|
|
|
device->clock = NULL;
|
|
|
|
}
|
|
|
|
if(device->volume){
|
|
|
|
IAudioStreamVolume_Release(device->volume);
|
|
|
|
device->volume = NULL;
|
|
|
|
}
|
2007-08-27 17:07:14 +02:00
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
hres = IMMDevice_Activate(device->mmdevice, &IID_IAudioClient,
|
|
|
|
CLSCTX_INPROC_SERVER, NULL, (void **)&device->client);
|
|
|
|
if(FAILED(hres)){
|
|
|
|
WARN("Activate failed: %08x\n", hres);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* buffer size = 200 * 100000 (100 ns) = 2.0 seconds */
|
|
|
|
hres = IAudioClient_Initialize(device->client,
|
|
|
|
AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_NOPERSIST,
|
|
|
|
200 * 100000, 50000, device->pwfx, NULL);
|
|
|
|
if(FAILED(hres)){
|
|
|
|
IAudioClient_Release(device->client);
|
|
|
|
device->client = NULL;
|
|
|
|
WARN("Initialize failed: %08x\n", hres);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IAudioClient_GetService(device->client, &IID_IAudioRenderClient,
|
|
|
|
(void**)&device->render);
|
|
|
|
if(FAILED(hres)){
|
|
|
|
IAudioClient_Release(device->client);
|
|
|
|
device->client = NULL;
|
|
|
|
WARN("GetService failed: %08x\n", hres);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IAudioClient_GetService(device->client, &IID_IAudioClock,
|
|
|
|
(void**)&device->clock);
|
|
|
|
if(FAILED(hres)){
|
|
|
|
IAudioClient_Release(device->client);
|
|
|
|
IAudioRenderClient_Release(device->render);
|
|
|
|
device->client = NULL;
|
|
|
|
device->render = NULL;
|
|
|
|
WARN("GetService failed: %08x\n", hres);
|
|
|
|
return hres;
|
|
|
|
}
|
2007-08-27 17:07:14 +02:00
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
hres = IAudioClient_GetService(device->client, &IID_IAudioStreamVolume,
|
|
|
|
(void**)&device->volume);
|
|
|
|
if(FAILED(hres)){
|
|
|
|
IAudioClient_Release(device->client);
|
|
|
|
IAudioRenderClient_Release(device->render);
|
|
|
|
IAudioClock_Release(device->clock);
|
|
|
|
device->client = NULL;
|
|
|
|
device->render = NULL;
|
|
|
|
device->clock = NULL;
|
|
|
|
WARN("GetService failed: %08x\n", hres);
|
2011-09-24 16:02:52 +02:00
|
|
|
return hres;
|
|
|
|
}
|
2007-08-27 17:07:14 +02:00
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
return S_OK;
|
2007-08-27 17:07:14 +02:00
|
|
|
}
|
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
static HRESULT DSOUND_PrimaryOpen(DirectSoundDevice *device)
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
2007-09-25 14:19:07 +02:00
|
|
|
DWORD buflen;
|
2011-09-27 15:51:07 +02:00
|
|
|
LPBYTE newbuf;
|
2011-09-24 16:02:52 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
TRACE("(%p)\n", device);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2007-09-25 14:19:07 +02:00
|
|
|
/* 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)
|
2007-10-13 19:41:05 +02:00
|
|
|
device->buflen = ds_hel_buflen;
|
|
|
|
buflen = device->buflen;
|
2007-09-25 14:19:07 +02:00
|
|
|
buflen -= buflen % device->pwfx->nBlockAlign;
|
|
|
|
device->buflen = buflen;
|
|
|
|
|
2007-11-07 20:32:22 +01:00
|
|
|
device->mix_buffer_len = DSOUND_bufpos_to_mixpos(device, device->buflen);
|
|
|
|
device->mix_buffer = HeapAlloc(GetProcessHeap(), 0, device->mix_buffer_len);
|
|
|
|
if (!device->mix_buffer)
|
|
|
|
return DSERR_OUTOFMEMORY;
|
|
|
|
|
2007-08-21 21:04:32 +02:00
|
|
|
if (device->state == STATE_PLAYING) device->state = STATE_STARTING;
|
|
|
|
else if (device->state == STATE_STOPPING) device->state = STATE_STOPPED;
|
|
|
|
|
2011-09-24 16:02:52 +02:00
|
|
|
TRACE("desired buflen=%d, old buffer=%p\n", buflen, device->buffer);
|
2007-06-13 17:05:49 +02:00
|
|
|
|
2011-09-24 16:02:52 +02:00
|
|
|
/* reallocate emulated primary buffer */
|
|
|
|
if (device->buffer)
|
|
|
|
newbuf = HeapReAlloc(GetProcessHeap(),0,device->buffer, buflen);
|
|
|
|
else
|
|
|
|
newbuf = HeapAlloc(GetProcessHeap(),0, buflen);
|
2003-10-14 07:24:20 +02:00
|
|
|
|
2011-09-24 16:02:52 +02:00
|
|
|
if (!newbuf) {
|
|
|
|
ERR("failed to allocate primary buffer\n");
|
|
|
|
return DSERR_OUTOFMEMORY;
|
|
|
|
/* but the old buffer might still exist and must be re-prepared */
|
|
|
|
}
|
2003-10-14 07:24:20 +02:00
|
|
|
|
2011-09-24 16:02:52 +02:00
|
|
|
DSOUND_RecalcPrimary(device);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2011-09-24 16:02:52 +02:00
|
|
|
device->buffer = newbuf;
|
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
TRACE("fraglen=%d\n", device->fraglen);
|
2004-08-18 02:30:37 +02:00
|
|
|
|
2007-11-07 20:32:22 +01:00
|
|
|
device->mixfunction = mixfunctions[device->pwfx->wBitsPerSample/8 - 1];
|
|
|
|
device->normfunction = normfunctions[device->pwfx->wBitsPerSample/8 - 1];
|
2007-08-21 21:04:32 +02:00
|
|
|
FillMemory(device->buffer, device->buflen, (device->pwfx->wBitsPerSample == 8) ? 128 : 0);
|
2007-11-07 20:32:22 +01:00
|
|
|
FillMemory(device->mix_buffer, device->mix_buffer_len, 0);
|
2011-09-27 15:51:07 +02:00
|
|
|
device->last_pos_bytes = device->pwplay = device->pwqueue = device->playpos = device->mixpos = 0;
|
|
|
|
return DS_OK;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
static void DSOUND_PrimaryClose(DirectSoundDevice *device)
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
2011-09-27 15:51:07 +02:00
|
|
|
HRESULT hr;
|
2011-09-24 16:02:52 +02:00
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
TRACE("(%p)\n", device);
|
2003-05-02 23:23:16 +02:00
|
|
|
|
2011-09-24 16:02:52 +02:00
|
|
|
device->pwqueue = (DWORD)-1; /* resetting queues */
|
2011-09-27 15:51:07 +02:00
|
|
|
|
|
|
|
if(device->client){
|
|
|
|
hr = IAudioClient_Stop(device->client);
|
|
|
|
if(FAILED(hr))
|
|
|
|
WARN("Stop failed: %08x\n", hr);
|
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2011-09-24 16:02:52 +02:00
|
|
|
/* clear the queue */
|
|
|
|
device->pwqueue = 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
|
|
|
|
2007-08-21 21:04:32 +02:00
|
|
|
device->buflen = ds_hel_buflen;
|
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
|
|
|
}
|
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
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-06-13 17:05:49 +02:00
|
|
|
/* **** */
|
|
|
|
EnterCriticalSection(&(device->mixlock));
|
2007-04-20 22:10:23 +02:00
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
DSOUND_PrimaryClose(device);
|
2011-09-24 16:02:52 +02:00
|
|
|
HeapFree(GetProcessHeap(),0,device->pwfx);
|
|
|
|
device->pwfx=NULL;
|
2007-06-13 17:05:49 +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
|
|
|
{
|
2011-09-27 15:51:07 +02:00
|
|
|
HRESULT hr;
|
2003-05-02 23:23:16 +02:00
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
TRACE("(%p)\n", device);
|
2003-05-22 05:39:13 +02:00
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
hr = IAudioClient_Start(device->client);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
WARN("Start failed: %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DS_OK;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
|
2005-05-31 11:31:37 +02:00
|
|
|
HRESULT DSOUND_PrimaryStop(DirectSoundDevice *device)
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
2011-09-27 15:51:07 +02:00
|
|
|
HRESULT hr;
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
TRACE("(%p)\n", device);
|
2007-06-13 17:05:49 +02:00
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
hr = IAudioClient_Stop(device->client);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
WARN("Stop failed: %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
2007-06-13 17:05:49 +02:00
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
return DS_OK;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2011-09-24 16:02:52 +02:00
|
|
|
TRACE("pwplay=%i, pwqueue=%i\n", device->pwplay, device->pwqueue);
|
2007-06-13 17:05:49 +02:00
|
|
|
|
2011-09-24 16:02:52 +02:00
|
|
|
/* check if playpos was requested */
|
|
|
|
if (playpos)
|
|
|
|
/* use the cached play position */
|
|
|
|
*playpos = device->pwplay * device->fraglen;
|
|
|
|
|
|
|
|
/* check if writepos was requested */
|
|
|
|
if (writepos)
|
|
|
|
/* the writepos is the first non-queued position */
|
|
|
|
*writepos = ((device->pwplay + device->pwqueue) % device->helfrags) * device->fraglen;
|
2007-06-13 17:05:49 +02:00
|
|
|
|
2007-09-06 17:35:58 +02:00
|
|
|
TRACE("playpos = %d, writepos = %d (%p, time=%d)\n", playpos?*playpos:-1, writepos?*writepos:-1, device, GetTickCount());
|
2002-06-13 21:15:06 +02:00
|
|
|
return DS_OK;
|
|
|
|
}
|
|
|
|
|
2010-10-03 17:52:00 +02:00
|
|
|
static DWORD DSOUND_GetFormatSize(LPCWAVEFORMATEX wfex)
|
|
|
|
{
|
|
|
|
if (wfex->wFormatTag == WAVE_FORMAT_PCM)
|
|
|
|
return sizeof(WAVEFORMATEX);
|
|
|
|
else
|
|
|
|
return sizeof(WAVEFORMATEX) + wfex->cbSize;
|
|
|
|
}
|
|
|
|
|
2009-10-04 08:05:20 +02:00
|
|
|
LPWAVEFORMATEX DSOUND_CopyFormat(LPCWAVEFORMATEX wfex)
|
|
|
|
{
|
2010-10-03 17:52:00 +02:00
|
|
|
DWORD size = DSOUND_GetFormatSize(wfex);
|
2009-10-04 08:05:20 +02:00
|
|
|
LPWAVEFORMATEX pwfx = HeapAlloc(GetProcessHeap(),0,size);
|
|
|
|
if (pwfx == NULL) {
|
|
|
|
WARN("out of memory\n");
|
|
|
|
} else if (wfex->wFormatTag != WAVE_FORMAT_PCM) {
|
|
|
|
CopyMemory(pwfx, wfex, size);
|
|
|
|
} else {
|
|
|
|
CopyMemory(pwfx, wfex, sizeof(PCMWAVEFORMAT));
|
|
|
|
pwfx->cbSize=0;
|
|
|
|
if (pwfx->nBlockAlign != pwfx->nChannels * pwfx->wBitsPerSample/8) {
|
|
|
|
WARN("Fixing bad nBlockAlign (%u)\n", pwfx->nBlockAlign);
|
|
|
|
pwfx->nBlockAlign = pwfx->nChannels * pwfx->wBitsPerSample/8;
|
|
|
|
}
|
|
|
|
if (pwfx->nAvgBytesPerSec != pwfx->nSamplesPerSec * pwfx->nBlockAlign) {
|
|
|
|
WARN("Fixing bad nAvgBytesPerSec (%u)\n", pwfx->nAvgBytesPerSec);
|
|
|
|
pwfx->nAvgBytesPerSec = pwfx->nSamplesPerSec * pwfx->nBlockAlign;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pwfx;
|
|
|
|
}
|
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
HRESULT primarybuffer_SetFormat(DirectSoundDevice *device, LPCWAVEFORMATEX passed_fmt)
|
2006-01-14 17:06:22 +01:00
|
|
|
{
|
2007-08-27 17:20:38 +02:00
|
|
|
HRESULT err = DSERR_BUFFERLOST;
|
2009-10-04 08:05:20 +02:00
|
|
|
int i;
|
2011-09-27 15:51:07 +02:00
|
|
|
WAVEFORMATEX *old_fmt;
|
|
|
|
WAVEFORMATEXTENSIBLE *fmtex;
|
|
|
|
BOOL forced = (device->priolevel == DSSCL_WRITEPRIMARY);
|
2011-08-31 01:17:04 +02:00
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
TRACE("(%p,%p)\n", device, passed_fmt);
|
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! */
|
2011-09-27 15:51:07 +02:00
|
|
|
if (passed_fmt == NULL) {
|
|
|
|
WARN("invalid parameter: passed_fmt==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,"
|
2011-09-27 15:51:07 +02:00
|
|
|
"bytespersec=%d,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
|
|
|
|
passed_fmt->wFormatTag, passed_fmt->nChannels, passed_fmt->nSamplesPerSec,
|
|
|
|
passed_fmt->nAvgBytesPerSec, passed_fmt->nBlockAlign,
|
|
|
|
passed_fmt->wBitsPerSample, passed_fmt->cbSize);
|
2003-01-11 21:54:56 +01:00
|
|
|
|
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
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
old_fmt = device->pwfx;
|
|
|
|
device->pwfx = DSOUND_CopyFormat(passed_fmt);
|
|
|
|
fmtex = (WAVEFORMATEXTENSIBLE *)device->pwfx;
|
2009-10-04 08:05:20 +02:00
|
|
|
if (device->pwfx == NULL) {
|
2011-09-27 15:51:07 +02:00
|
|
|
device->pwfx = old_fmt;
|
|
|
|
old_fmt = NULL;
|
2009-10-04 08:05:20 +02:00
|
|
|
err = DSERR_OUTOFMEMORY;
|
|
|
|
goto done;
|
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2011-09-24 16:02:52 +02:00
|
|
|
DSOUND_PrimaryClose(device);
|
2007-09-05 10:58:52 +02:00
|
|
|
|
2011-09-24 16:02:52 +02:00
|
|
|
err = DSOUND_ReopenDevice(device, FALSE);
|
2011-09-27 15:51:07 +02:00
|
|
|
if(SUCCEEDED(err))
|
|
|
|
goto opened;
|
|
|
|
|
|
|
|
/* requested format failed, so try others */
|
|
|
|
if(device->pwfx->wFormatTag == WAVE_FORMAT_IEEE_FLOAT){
|
|
|
|
device->pwfx->wFormatTag = WAVE_FORMAT_PCM;
|
|
|
|
device->pwfx->wBitsPerSample = 32;
|
|
|
|
device->pwfx->nAvgBytesPerSec = passed_fmt->nSamplesPerSec * device->pwfx->nBlockAlign;
|
|
|
|
device->pwfx->nBlockAlign = passed_fmt->nChannels * (device->pwfx->wBitsPerSample / 8);
|
|
|
|
|
|
|
|
err = DSOUND_ReopenDevice(device, FALSE);
|
|
|
|
if(SUCCEEDED(err))
|
|
|
|
goto opened;
|
2011-09-24 16:02:52 +02:00
|
|
|
}
|
2011-09-27 15:51:07 +02:00
|
|
|
|
|
|
|
if(device->pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
|
|
|
|
IsEqualGUID(&fmtex->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)){
|
|
|
|
fmtex->SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
|
|
|
|
device->pwfx->wBitsPerSample = 32;
|
|
|
|
device->pwfx->nAvgBytesPerSec = passed_fmt->nSamplesPerSec * device->pwfx->nBlockAlign;
|
|
|
|
device->pwfx->nBlockAlign = passed_fmt->nChannels * (device->pwfx->wBitsPerSample / 8);
|
|
|
|
|
|
|
|
err = DSOUND_ReopenDevice(device, FALSE);
|
|
|
|
if(SUCCEEDED(err))
|
|
|
|
goto opened;
|
|
|
|
}
|
|
|
|
|
|
|
|
device->pwfx->wBitsPerSample = 32;
|
|
|
|
device->pwfx->nAvgBytesPerSec = passed_fmt->nSamplesPerSec * device->pwfx->nBlockAlign;
|
|
|
|
device->pwfx->nBlockAlign = passed_fmt->nChannels * (device->pwfx->wBitsPerSample / 8);
|
|
|
|
err = DSOUND_ReopenDevice(device, FALSE);
|
|
|
|
if(SUCCEEDED(err))
|
|
|
|
goto opened;
|
|
|
|
|
|
|
|
device->pwfx->wBitsPerSample = 16;
|
|
|
|
device->pwfx->nAvgBytesPerSec = passed_fmt->nSamplesPerSec * device->pwfx->nBlockAlign;
|
|
|
|
device->pwfx->nBlockAlign = passed_fmt->nChannels * (device->pwfx->wBitsPerSample / 8);
|
|
|
|
err = DSOUND_ReopenDevice(device, FALSE);
|
|
|
|
if(SUCCEEDED(err))
|
|
|
|
goto opened;
|
|
|
|
|
|
|
|
device->pwfx->wBitsPerSample = 8;
|
|
|
|
device->pwfx->nAvgBytesPerSec = passed_fmt->nSamplesPerSec * device->pwfx->nBlockAlign;
|
|
|
|
device->pwfx->nBlockAlign = passed_fmt->nChannels * (device->pwfx->wBitsPerSample / 8);
|
|
|
|
err = DSOUND_ReopenDevice(device, FALSE);
|
|
|
|
if(SUCCEEDED(err))
|
|
|
|
goto opened;
|
|
|
|
|
|
|
|
device->pwfx->nChannels = (passed_fmt->nChannels == 2) ? 1 : 2;
|
|
|
|
device->pwfx->wBitsPerSample = passed_fmt->wBitsPerSample;
|
|
|
|
device->pwfx->nAvgBytesPerSec = passed_fmt->nSamplesPerSec * device->pwfx->nBlockAlign;
|
|
|
|
device->pwfx->nBlockAlign = passed_fmt->nChannels * (device->pwfx->wBitsPerSample / 8);
|
|
|
|
err = DSOUND_ReopenDevice(device, FALSE);
|
|
|
|
if(SUCCEEDED(err))
|
|
|
|
goto opened;
|
|
|
|
|
|
|
|
device->pwfx->wBitsPerSample = 32;
|
|
|
|
device->pwfx->nAvgBytesPerSec = passed_fmt->nSamplesPerSec * device->pwfx->nBlockAlign;
|
|
|
|
device->pwfx->nBlockAlign = passed_fmt->nChannels * (device->pwfx->wBitsPerSample / 8);
|
|
|
|
err = DSOUND_ReopenDevice(device, FALSE);
|
|
|
|
if(SUCCEEDED(err))
|
|
|
|
goto opened;
|
|
|
|
|
|
|
|
device->pwfx->wBitsPerSample = 16;
|
|
|
|
device->pwfx->nAvgBytesPerSec = passed_fmt->nSamplesPerSec * device->pwfx->nBlockAlign;
|
|
|
|
device->pwfx->nBlockAlign = passed_fmt->nChannels * (device->pwfx->wBitsPerSample / 8);
|
|
|
|
err = DSOUND_ReopenDevice(device, FALSE);
|
|
|
|
if(SUCCEEDED(err))
|
|
|
|
goto opened;
|
|
|
|
|
|
|
|
device->pwfx->wBitsPerSample = 8;
|
|
|
|
device->pwfx->nAvgBytesPerSec = passed_fmt->nSamplesPerSec * device->pwfx->nBlockAlign;
|
|
|
|
device->pwfx->nBlockAlign = passed_fmt->nChannels * (device->pwfx->wBitsPerSample / 8);
|
|
|
|
err = DSOUND_ReopenDevice(device, FALSE);
|
|
|
|
if(SUCCEEDED(err))
|
|
|
|
goto opened;
|
|
|
|
|
|
|
|
WARN("No formats could be opened\n");
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
opened:
|
2011-09-24 16:02:52 +02:00
|
|
|
err = DSOUND_PrimaryOpen(device);
|
|
|
|
if (err != DS_OK) {
|
|
|
|
WARN("DSOUND_PrimaryOpen failed\n");
|
|
|
|
goto done;
|
2007-08-21 21:04:32 +02:00
|
|
|
}
|
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
if (passed_fmt->nSamplesPerSec/100 != device->pwfx->nSamplesPerSec/100 && forced && device->buffer)
|
2007-08-21 21:04:32 +02:00
|
|
|
{
|
|
|
|
DSOUND_PrimaryClose(device);
|
2011-09-27 15:51:07 +02:00
|
|
|
device->pwfx->nSamplesPerSec = passed_fmt->nSamplesPerSec;
|
2011-09-24 16:02:52 +02:00
|
|
|
err = DSOUND_ReopenDevice(device, TRUE);
|
2007-09-05 10:58:52 +02:00
|
|
|
if (FAILED(err))
|
2011-09-24 16:02:52 +02:00
|
|
|
WARN("DSOUND_ReopenDevice(2) failed: %08x\n", err);
|
|
|
|
else if (FAILED((err = DSOUND_PrimaryOpen(device))))
|
|
|
|
WARN("DSOUND_PrimaryOpen(2) failed: %08x\n", err);
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
|
2007-11-07 20:32:22 +01:00
|
|
|
device->mix_buffer_len = DSOUND_bufpos_to_mixpos(device, device->buflen);
|
|
|
|
device->mix_buffer = HeapReAlloc(GetProcessHeap(), 0, device->mix_buffer, device->mix_buffer_len);
|
|
|
|
FillMemory(device->mix_buffer, device->mix_buffer_len, 0);
|
|
|
|
device->mixfunction = mixfunctions[device->pwfx->wBitsPerSample/8 - 1];
|
|
|
|
device->normfunction = normfunctions[device->pwfx->wBitsPerSample/8 - 1];
|
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
if (old_fmt->nSamplesPerSec != device->pwfx->nSamplesPerSec ||
|
|
|
|
old_fmt->wBitsPerSample != device->pwfx->wBitsPerSample ||
|
|
|
|
old_fmt->nChannels != device->pwfx->nChannels) {
|
2005-05-31 11:31:37 +02:00
|
|
|
IDirectSoundBufferImpl** dsb = device->buffers;
|
|
|
|
for (i = 0; i < device->nrofbuffers; i++, dsb++) {
|
2004-02-06 06:20:28 +01:00
|
|
|
/* **** */
|
2007-07-29 21:01:43 +02:00
|
|
|
RtlAcquireResourceExclusive(&(*dsb)->lock, TRUE);
|
2004-02-06 06:20:28 +01:00
|
|
|
|
2007-07-29 23:47:01 +02:00
|
|
|
(*dsb)->freqAdjust = ((DWORD64)(*dsb)->freq << DSOUND_FREQSHIFT) / device->pwfx->nSamplesPerSec;
|
|
|
|
DSOUND_RecalcFormat((*dsb));
|
2008-03-04 05:18:04 +01:00
|
|
|
DSOUND_MixToTemporary((*dsb), 0, (*dsb)->buflen, FALSE);
|
2007-08-27 17:20:38 +02:00
|
|
|
(*dsb)->primary_mixpos = 0;
|
2004-02-06 06:20:28 +01:00
|
|
|
|
2007-07-29 21:01:43 +02:00
|
|
|
RtlReleaseResource(&(*dsb)->lock);
|
2004-02-06 06:20:28 +01:00
|
|
|
/* **** */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/* **** */
|
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, old_fmt);
|
2002-06-13 21:15:06 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2006-01-14 17:06:22 +01:00
|
|
|
/*******************************************************************************
|
|
|
|
* PrimaryBuffer
|
|
|
|
*/
|
2011-08-31 01:11:29 +02:00
|
|
|
static inline IDirectSoundBufferImpl *impl_from_IDirectSoundBuffer(IDirectSoundBuffer *iface)
|
|
|
|
{
|
|
|
|
/* IDirectSoundBuffer and IDirectSoundBuffer8 use the same iface. */
|
|
|
|
return CONTAINING_RECORD(iface, IDirectSoundBufferImpl, IDirectSoundBuffer8_iface);
|
|
|
|
}
|
|
|
|
|
2006-01-14 17:06:22 +01:00
|
|
|
/* 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(
|
2007-05-13 12:58:36 +02:00
|
|
|
LPDIRECTSOUNDBUFFER iface,
|
2006-01-14 17:06:22 +01:00
|
|
|
LPCWAVEFORMATEX wfex)
|
|
|
|
{
|
2011-08-31 01:11:29 +02:00
|
|
|
IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
|
2006-01-14 17:06:22 +01:00
|
|
|
TRACE("(%p,%p)\n", iface, wfex);
|
2011-08-31 01:17:04 +02:00
|
|
|
return primarybuffer_SetFormat(This->device, wfex);
|
2006-01-14 17:06:22 +01:00
|
|
|
}
|
|
|
|
|
2002-06-13 21:15:06 +02:00
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_SetVolume(
|
2007-05-13 12:58:36 +02:00
|
|
|
LPDIRECTSOUNDBUFFER iface,LONG vol
|
2002-06-13 21:15:06 +02:00
|
|
|
) {
|
2011-09-27 15:51:07 +02:00
|
|
|
IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
|
|
|
|
DirectSoundDevice *device = This->device;
|
|
|
|
HRESULT hr;
|
|
|
|
float lvol, rvol;
|
|
|
|
|
2006-11-12 14:40:35 +01:00
|
|
|
TRACE("(%p,%d)\n", iface, vol);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2011-08-31 01:15:36 +02:00
|
|
|
if (!(This->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
|
|
|
|
|
|
|
/* **** */
|
2011-09-27 15:51:07 +02:00
|
|
|
EnterCriticalSection(&device->mixlock);
|
|
|
|
|
|
|
|
hr = IAudioStreamVolume_GetChannelVolume(device->volume, 0, &lvol);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
LeaveCriticalSection(&device->mixlock);
|
|
|
|
WARN("GetChannelVolume failed: %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(device->pwfx->nChannels > 1){
|
|
|
|
hr = IAudioStreamVolume_GetChannelVolume(device->volume, 1, &rvol);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
LeaveCriticalSection(&device->mixlock);
|
|
|
|
WARN("GetChannelVolume failed: %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}else
|
|
|
|
rvol = 1;
|
|
|
|
|
|
|
|
device->volpan.dwTotalLeftAmpFactor = ((UINT16)(lvol * (DWORD)0xFFFF));
|
|
|
|
device->volpan.dwTotalRightAmpFactor = ((UINT16)(rvol * (DWORD)0xFFFF));
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2011-09-24 16:02:52 +02:00
|
|
|
DSOUND_AmpFactorToVolPan(&device->volpan);
|
|
|
|
if (vol != device->volpan.lVolume) {
|
2011-09-27 15:51:07 +02:00
|
|
|
device->volpan.lVolume=vol;
|
|
|
|
DSOUND_RecalcVolPan(&device->volpan);
|
|
|
|
lvol = (float)((DWORD)(device->volpan.dwTotalLeftAmpFactor & 0xFFFF) / (float)0xFFFF);
|
|
|
|
hr = IAudioStreamVolume_SetChannelVolume(device->volume, 0, lvol);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
LeaveCriticalSection(&device->mixlock);
|
|
|
|
WARN("SetChannelVolume failed: %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(device->pwfx->nChannels > 1){
|
|
|
|
rvol = (float)((DWORD)(device->volpan.dwTotalRightAmpFactor & 0xFFFF) / (float)0xFFFF);
|
|
|
|
hr = IAudioStreamVolume_SetChannelVolume(device->volume, 1, rvol);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
LeaveCriticalSection(&device->mixlock);
|
|
|
|
WARN("SetChannelVolume failed: %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
2011-09-24 16:02:52 +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
|
|
|
/* **** */
|
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
return DS_OK;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_GetVolume(
|
2007-05-13 12:58:36 +02:00
|
|
|
LPDIRECTSOUNDBUFFER iface,LPLONG vol
|
2002-06-13 21:15:06 +02:00
|
|
|
) {
|
2011-09-27 15:51:07 +02:00
|
|
|
IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
|
|
|
|
DirectSoundDevice *device = This->device;
|
|
|
|
float lvol, rvol;
|
|
|
|
HRESULT hr;
|
2005-05-31 11:31:37 +02:00
|
|
|
TRACE("(%p,%p)\n", iface, vol);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2011-08-31 01:15:36 +02:00
|
|
|
if (!(This->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
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
EnterCriticalSection(&device->mixlock);
|
|
|
|
|
|
|
|
hr = IAudioStreamVolume_GetChannelVolume(device->volume, 0, &lvol);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
LeaveCriticalSection(&device->mixlock);
|
|
|
|
WARN("GetChannelVolume failed: %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(device->pwfx->nChannels > 1){
|
|
|
|
hr = IAudioStreamVolume_GetChannelVolume(device->volume, 1, &rvol);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
LeaveCriticalSection(&device->mixlock);
|
|
|
|
WARN("GetChannelVolume failed: %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}else
|
|
|
|
rvol = 1;
|
|
|
|
|
|
|
|
device->volpan.dwTotalLeftAmpFactor = ((UINT16)(lvol * (DWORD)0xFFFF));
|
|
|
|
device->volpan.dwTotalRightAmpFactor = ((UINT16)(rvol * (DWORD)0xFFFF));
|
|
|
|
|
2011-09-24 16:02:52 +02:00
|
|
|
DSOUND_AmpFactorToVolPan(&device->volpan);
|
|
|
|
*vol = device->volpan.lVolume;
|
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
LeaveCriticalSection(&device->mixlock);
|
|
|
|
|
2002-06-13 21:15:06 +02:00
|
|
|
return DS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_SetFrequency(
|
2007-05-13 12:58:36 +02:00
|
|
|
LPDIRECTSOUNDBUFFER iface,DWORD freq
|
2002-06-13 21:15:06 +02:00
|
|
|
) {
|
2011-08-31 01:11:29 +02:00
|
|
|
IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(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(
|
2007-05-13 12:58:36 +02:00
|
|
|
LPDIRECTSOUNDBUFFER iface,DWORD reserved1,DWORD reserved2,DWORD flags
|
2002-06-13 21:15:06 +02:00
|
|
|
) {
|
2011-08-31 01:11:29 +02:00
|
|
|
IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
|
|
|
|
DirectSoundDevice *device = This->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;
|
|
|
|
}
|
|
|
|
|
2007-05-13 12:58:36 +02:00
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_Stop(LPDIRECTSOUNDBUFFER iface)
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
2011-08-31 01:11:29 +02:00
|
|
|
IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
|
|
|
|
DirectSoundDevice *device = This->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;
|
|
|
|
}
|
|
|
|
|
2007-05-13 12:58:36 +02:00
|
|
|
static ULONG WINAPI PrimaryBufferImpl_AddRef(LPDIRECTSOUNDBUFFER iface)
|
2005-02-11 12:49:05 +01:00
|
|
|
{
|
2011-08-31 01:11:29 +02:00
|
|
|
IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
|
2005-02-11 12:49:05 +01:00
|
|
|
ULONG ref = InterlockedIncrement(&(This->ref));
|
2006-11-12 14:40:35 +01:00
|
|
|
TRACE("(%p) ref was %d\n", This, ref - 1);
|
2011-08-31 01:13:33 +02:00
|
|
|
if(ref == 1)
|
|
|
|
InterlockedIncrement(&This->numIfaces);
|
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
|
|
|
|
2011-08-31 01:13:33 +02:00
|
|
|
void primarybuffer_destroy(IDirectSoundBufferImpl *This)
|
|
|
|
{
|
|
|
|
This->device->primary = NULL;
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
TRACE("(%p) released\n", This);
|
|
|
|
}
|
|
|
|
|
2007-05-13 12:58:36 +02:00
|
|
|
static ULONG WINAPI PrimaryBufferImpl_Release(LPDIRECTSOUNDBUFFER iface)
|
2005-02-11 12:49:05 +01:00
|
|
|
{
|
2011-08-31 01:11:29 +02:00
|
|
|
IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
|
2005-02-11 12:49:05 +01:00
|
|
|
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
|
|
|
|
2011-08-31 01:13:33 +02:00
|
|
|
if (!ref && !InterlockedDecrement(&This->numIfaces))
|
|
|
|
primarybuffer_destroy(This);
|
2005-02-11 12:49:05 +01:00
|
|
|
return ref;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_GetCurrentPosition(
|
2007-05-13 12:58:36 +02:00
|
|
|
LPDIRECTSOUNDBUFFER iface,LPDWORD playpos,LPDWORD writepos
|
2002-06-13 21:15:06 +02:00
|
|
|
) {
|
2003-05-22 05:39:13 +02:00
|
|
|
HRESULT hres;
|
2011-08-31 01:11:29 +02:00
|
|
|
IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
|
|
|
|
DirectSoundDevice *device = This->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
|
|
|
|
2007-06-13 17:05:49 +02:00
|
|
|
/* **** */
|
|
|
|
EnterCriticalSection(&(device->mixlock));
|
|
|
|
|
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");
|
2007-06-22 23:29:06 +02:00
|
|
|
LeaveCriticalSection(&(device->mixlock));
|
2003-05-22 05:39:13 +02:00
|
|
|
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
|
|
|
}
|
2007-06-13 17:05:49 +02:00
|
|
|
|
|
|
|
LeaveCriticalSection(&(device->mixlock));
|
|
|
|
/* **** */
|
|
|
|
|
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(
|
2007-05-13 12:58:36 +02:00
|
|
|
LPDIRECTSOUNDBUFFER iface,LPDWORD status
|
2002-06-13 21:15:06 +02:00
|
|
|
) {
|
2011-08-31 01:11:29 +02:00
|
|
|
IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
|
|
|
|
DirectSoundDevice *device = This->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(
|
2007-05-13 12:58:36 +02:00
|
|
|
LPDIRECTSOUNDBUFFER iface,
|
2004-08-18 02:30:37 +02:00
|
|
|
LPWAVEFORMATEX lpwf,
|
|
|
|
DWORD wfsize,
|
|
|
|
LPDWORD wfwritten)
|
|
|
|
{
|
|
|
|
DWORD size;
|
2011-08-31 01:11:29 +02:00
|
|
|
IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
|
|
|
|
DirectSoundDevice *device = This->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-05-13 12:58:36 +02:00
|
|
|
LPDIRECTSOUNDBUFFER 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;
|
2011-08-31 01:11:29 +02:00
|
|
|
IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
|
|
|
|
DirectSoundDevice *device = This->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()
|
|
|
|
);
|
|
|
|
|
2009-01-02 07:39:10 +01:00
|
|
|
if (!audiobytes1)
|
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
|
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;
|
|
|
|
}
|
2007-07-29 23:47:01 +02:00
|
|
|
|
2006-04-29 05:40:09 +02:00
|
|
|
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
|
|
|
|
2011-09-24 16:02:52 +02:00
|
|
|
if (writecursor+writebytes <= device->buflen) {
|
|
|
|
*(LPBYTE*)lplpaudioptr1 = device->buffer+writecursor;
|
|
|
|
*audiobytes1 = writebytes;
|
|
|
|
if (lplpaudioptr2)
|
|
|
|
*(LPBYTE*)lplpaudioptr2 = NULL;
|
|
|
|
if (audiobytes2)
|
|
|
|
*audiobytes2 = 0;
|
|
|
|
TRACE("->%d.0\n",writebytes);
|
2003-05-22 05:39:13 +02:00
|
|
|
} else {
|
2011-09-24 16:02:52 +02:00
|
|
|
*(LPBYTE*)lplpaudioptr1 = device->buffer+writecursor;
|
|
|
|
*audiobytes1 = device->buflen-writecursor;
|
|
|
|
if (lplpaudioptr2)
|
|
|
|
*(LPBYTE*)lplpaudioptr2 = device->buffer;
|
|
|
|
if (audiobytes2)
|
|
|
|
*audiobytes2 = writebytes-(device->buflen-writecursor);
|
|
|
|
TRACE("->%d.%d\n",*audiobytes1,audiobytes2?*audiobytes2:0);
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
return DS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_SetCurrentPosition(
|
2007-05-13 12:58:36 +02:00
|
|
|
LPDIRECTSOUNDBUFFER iface,DWORD newpos
|
2002-06-13 21:15:06 +02:00
|
|
|
) {
|
2011-08-31 01:11:29 +02:00
|
|
|
IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(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(
|
2007-05-13 12:58:36 +02:00
|
|
|
LPDIRECTSOUNDBUFFER iface,LONG pan
|
2002-06-13 21:15:06 +02:00
|
|
|
) {
|
2011-09-27 15:51:07 +02:00
|
|
|
IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
|
|
|
|
DirectSoundDevice *device = This->device;
|
|
|
|
float lvol, rvol;
|
|
|
|
HRESULT hr;
|
2006-11-12 14:40:35 +01:00
|
|
|
TRACE("(%p,%d)\n", iface, pan);
|
2003-09-15 22:08:05 +02:00
|
|
|
|
2011-08-31 01:15:36 +02:00
|
|
|
if (!(This->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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* **** */
|
2011-09-27 15:51:07 +02:00
|
|
|
EnterCriticalSection(&device->mixlock);
|
|
|
|
|
|
|
|
hr = IAudioStreamVolume_GetChannelVolume(device->volume, 0, &lvol);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
LeaveCriticalSection(&device->mixlock);
|
|
|
|
WARN("GetChannelVolume failed: %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(device->pwfx->nChannels > 1){
|
|
|
|
hr = IAudioStreamVolume_GetChannelVolume(device->volume, 1, &rvol);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
LeaveCriticalSection(&device->mixlock);
|
|
|
|
WARN("GetChannelVolume failed: %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}else
|
|
|
|
rvol = 1;
|
|
|
|
|
|
|
|
device->volpan.dwTotalLeftAmpFactor = ((UINT16)(lvol * (DWORD)0xFFFF));
|
|
|
|
device->volpan.dwTotalRightAmpFactor = ((UINT16)(rvol * (DWORD)0xFFFF));
|
2003-09-15 22:08:05 +02:00
|
|
|
|
2011-09-24 16:02:52 +02:00
|
|
|
DSOUND_AmpFactorToVolPan(&device->volpan);
|
|
|
|
if (pan != device->volpan.lPan) {
|
|
|
|
device->volpan.lPan=pan;
|
|
|
|
DSOUND_RecalcVolPan(&device->volpan);
|
2011-09-27 15:51:07 +02:00
|
|
|
|
|
|
|
lvol = (float)((DWORD)(device->volpan.dwTotalLeftAmpFactor & 0xFFFF) / (float)0xFFFF);
|
|
|
|
hr = IAudioStreamVolume_SetChannelVolume(device->volume, 0, lvol);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
LeaveCriticalSection(&device->mixlock);
|
|
|
|
WARN("SetChannelVolume failed: %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(device->pwfx->nChannels > 1){
|
|
|
|
rvol = (float)((DWORD)(device->volpan.dwTotalRightAmpFactor & 0xFFFF) / (float)0xFFFF);
|
|
|
|
hr = IAudioStreamVolume_SetChannelVolume(device->volume, 1, rvol);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
LeaveCriticalSection(&device->mixlock);
|
|
|
|
WARN("SetChannelVolume failed: %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
2011-09-24 16:02:52 +02:00
|
|
|
}
|
2003-09-15 22:08:05 +02:00
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
LeaveCriticalSection(&device->mixlock);
|
2003-09-15 22:08:05 +02:00
|
|
|
/* **** */
|
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
return DS_OK;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_GetPan(
|
2007-05-13 12:58:36 +02:00
|
|
|
LPDIRECTSOUNDBUFFER iface,LPLONG pan
|
2002-06-13 21:15:06 +02:00
|
|
|
) {
|
2011-09-27 15:51:07 +02:00
|
|
|
IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
|
|
|
|
DirectSoundDevice *device = This->device;
|
|
|
|
float lvol, rvol;
|
|
|
|
HRESULT hr;
|
2005-05-31 11:31:37 +02:00
|
|
|
TRACE("(%p,%p)\n", iface, pan);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2011-08-31 01:15:36 +02:00
|
|
|
if (!(This->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
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
EnterCriticalSection(&device->mixlock);
|
|
|
|
|
|
|
|
hr = IAudioStreamVolume_GetChannelVolume(device->volume, 0, &lvol);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
LeaveCriticalSection(&device->mixlock);
|
|
|
|
WARN("GetChannelVolume failed: %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(device->pwfx->nChannels > 1){
|
|
|
|
hr = IAudioStreamVolume_GetChannelVolume(device->volume, 1, &rvol);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
LeaveCriticalSection(&device->mixlock);
|
|
|
|
WARN("GetChannelVolume failed: %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}else
|
|
|
|
rvol = 1;
|
|
|
|
|
|
|
|
device->volpan.dwTotalLeftAmpFactor = ((UINT16)(lvol * (DWORD)0xFFFF));
|
|
|
|
device->volpan.dwTotalRightAmpFactor = ((UINT16)(rvol * (DWORD)0xFFFF));
|
|
|
|
|
2011-09-24 16:02:52 +02:00
|
|
|
DSOUND_AmpFactorToVolPan(&device->volpan);
|
2008-09-28 20:47:28 +02:00
|
|
|
*pan = device->volpan.lPan;
|
2011-09-27 15:51:07 +02:00
|
|
|
|
|
|
|
LeaveCriticalSection(&device->mixlock);
|
|
|
|
|
2002-06-13 21:15:06 +02:00
|
|
|
return DS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_Unlock(
|
2007-05-13 12:58:36 +02:00
|
|
|
LPDIRECTSOUNDBUFFER iface,LPVOID p1,DWORD x1,LPVOID p2,DWORD x2
|
2002-06-13 21:15:06 +02:00
|
|
|
) {
|
2011-08-31 01:11:29 +02:00
|
|
|
IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
|
|
|
|
DirectSoundDevice *device = This->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
|
|
|
|
2011-09-24 16:03:06 +02:00
|
|
|
if((p1 && ((BYTE*)p1 < device->buffer ||
|
|
|
|
(BYTE*)p1 >= device->buffer + device->buflen)) ||
|
|
|
|
(p2 && ((BYTE*)p2 < device->buffer ||
|
|
|
|
(BYTE*)p2 >= device->buffer + device->buflen)))
|
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
|
2002-06-13 21:15:06 +02:00
|
|
|
return DS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_Restore(
|
2007-05-13 12:58:36 +02:00
|
|
|
LPDIRECTSOUNDBUFFER iface
|
2002-06-13 21:15:06 +02:00
|
|
|
) {
|
2011-08-31 01:11:29 +02:00
|
|
|
IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
|
2002-06-13 21:15:06 +02:00
|
|
|
FIXME("(%p):stub\n",This);
|
|
|
|
return DS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_GetFrequency(
|
2007-05-13 12:58:36 +02:00
|
|
|
LPDIRECTSOUNDBUFFER iface,LPDWORD freq
|
2002-06-13 21:15:06 +02:00
|
|
|
) {
|
2011-08-31 01:11:29 +02:00
|
|
|
IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
|
|
|
|
DirectSoundDevice *device = This->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
|
|
|
|
2011-08-31 01:15:36 +02:00
|
|
|
if (!(This->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_Initialize(
|
2007-05-13 12:58:36 +02:00
|
|
|
LPDIRECTSOUNDBUFFER iface,LPDIRECTSOUND dsound,LPCDSBUFFERDESC dbsd
|
2002-06-13 21:15:06 +02:00
|
|
|
) {
|
2011-08-31 01:11:29 +02:00
|
|
|
IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
|
2007-07-29 21:29:33 +02:00
|
|
|
WARN("(%p) already initialized\n", This);
|
2002-06-13 21:15:06 +02:00
|
|
|
return DSERR_ALREADYINITIALIZED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_GetCaps(
|
2007-05-13 12:58:36 +02:00
|
|
|
LPDIRECTSOUNDBUFFER iface,LPDSBCAPS caps
|
2002-06-13 21:15:06 +02:00
|
|
|
) {
|
2011-08-31 01:11:29 +02:00
|
|
|
IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
|
|
|
|
DirectSoundDevice *device = This->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
|
|
|
|
2011-08-31 01:15:36 +02:00
|
|
|
caps->dwFlags = This->dsbd.dwFlags;
|
2005-05-31 11:31:37 +02:00
|
|
|
caps->dwBufferBytes = device->buflen;
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2007-05-30 18:32:35 +02:00
|
|
|
/* Windows reports these as zero */
|
|
|
|
caps->dwUnlockTransferRate = 0;
|
2002-06-13 21:15:06 +02:00
|
|
|
caps->dwPlayCpuOverhead = 0;
|
|
|
|
|
|
|
|
return DS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_QueryInterface(
|
2007-05-13 12:58:36 +02:00
|
|
|
LPDIRECTSOUNDBUFFER iface,REFIID riid,LPVOID *ppobj
|
2002-06-13 21:15:06 +02:00
|
|
|
) {
|
2011-08-31 01:11:29 +02:00
|
|
|
IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(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;
|
|
|
|
}
|
|
|
|
|
2007-05-13 12:58:36 +02:00
|
|
|
static const IDirectSoundBufferVtbl 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,
|
2007-05-13 12:58:36 +02:00
|
|
|
PrimaryBufferImpl_Restore
|
2002-06-13 21:15:06 +02:00
|
|
|
};
|
|
|
|
|
2011-08-31 01:11:29 +02:00
|
|
|
HRESULT primarybuffer_create(DirectSoundDevice *device, IDirectSoundBufferImpl **ppdsb,
|
|
|
|
const DSBUFFERDESC *dsbd)
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
2011-08-31 01:11:29 +02:00
|
|
|
IDirectSoundBufferImpl *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;
|
|
|
|
}
|
|
|
|
|
2011-08-31 01:13:33 +02:00
|
|
|
dsb->ref = 1;
|
|
|
|
dsb->numIfaces = 1;
|
2006-01-06 12:35:20 +01:00
|
|
|
dsb->device = device;
|
2011-08-31 01:11:29 +02:00
|
|
|
dsb->IDirectSoundBuffer8_iface.lpVtbl = (IDirectSoundBuffer8Vtbl *)&dspbvt;
|
2011-08-31 01:15:36 +02:00
|
|
|
dsb->dsbd = *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;
|
|
|
|
}
|