2004-07-04 02:13:44 +02:00
|
|
|
/* DirectSound
|
|
|
|
*
|
|
|
|
* Copyright 1998 Marcus Meissner
|
|
|
|
* Copyright 1998 Rob Riggs
|
|
|
|
* Copyright 2000-2002 TransGaming Technologies, Inc.
|
|
|
|
* Copyright 2004 Robert Reif
|
|
|
|
*
|
|
|
|
* 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
|
2004-07-04 02:13:44 +02:00
|
|
|
*/
|
|
|
|
|
2012-09-25 23:23:31 +02:00
|
|
|
#include <assert.h>
|
2004-07-04 02:13:44 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
2015-01-06 20:26:47 +01:00
|
|
|
#include <math.h>
|
2004-07-04 02:13:44 +02:00
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
#define COBJMACROS
|
2015-03-11 11:30:29 +01:00
|
|
|
|
2004-07-04 02:13:44 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2005-10-17 11:24:50 +02:00
|
|
|
#include "winuser.h"
|
2004-07-04 02:13:44 +02:00
|
|
|
#include "winternl.h"
|
|
|
|
#include "mmddk.h"
|
2007-11-05 23:23:11 +01:00
|
|
|
#include "wingdi.h"
|
|
|
|
#include "mmreg.h"
|
|
|
|
#include "ks.h"
|
|
|
|
#include "ksmedia.h"
|
2004-07-04 02:13:44 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "dsound.h"
|
|
|
|
#include "dsound_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dsound);
|
|
|
|
|
2012-07-19 01:54:54 +02:00
|
|
|
typedef struct IDirectSoundImpl {
|
2012-08-16 01:45:29 +02:00
|
|
|
IUnknown IUnknown_inner;
|
2012-07-19 02:04:11 +02:00
|
|
|
IDirectSound8 IDirectSound8_iface;
|
2012-08-16 01:45:29 +02:00
|
|
|
IUnknown *outer_unk; /* internal */
|
2012-07-19 02:04:11 +02:00
|
|
|
LONG ref, refds, numIfaces;
|
2012-07-19 01:51:26 +02:00
|
|
|
DirectSoundDevice *device;
|
2012-07-19 01:49:53 +02:00
|
|
|
BOOL has_ds8;
|
2012-07-19 01:54:54 +02:00
|
|
|
} IDirectSoundImpl;
|
2006-08-02 13:26:14 +02:00
|
|
|
|
2012-08-21 13:31:39 +02:00
|
|
|
static const char * dumpCooperativeLevel(DWORD level)
|
2004-07-04 02:13:44 +02:00
|
|
|
{
|
|
|
|
#define LE(x) case x: return #x
|
|
|
|
switch (level) {
|
|
|
|
LE(DSSCL_NORMAL);
|
|
|
|
LE(DSSCL_PRIORITY);
|
|
|
|
LE(DSSCL_EXCLUSIVE);
|
|
|
|
LE(DSSCL_WRITEPRIMARY);
|
|
|
|
}
|
|
|
|
#undef LE
|
2009-11-30 10:22:07 +01:00
|
|
|
return wine_dbg_sprintf("Unknown(%08x)", level);
|
2004-07-04 02:13:44 +02:00
|
|
|
}
|
|
|
|
|
2004-07-22 21:42:11 +02:00
|
|
|
static void _dump_DSCAPS(DWORD xmask) {
|
|
|
|
struct {
|
|
|
|
DWORD mask;
|
2005-07-15 11:58:36 +02:00
|
|
|
const char *name;
|
2004-07-22 21:42:11 +02:00
|
|
|
} flags[] = {
|
|
|
|
#define FE(x) { x, #x },
|
|
|
|
FE(DSCAPS_PRIMARYMONO)
|
|
|
|
FE(DSCAPS_PRIMARYSTEREO)
|
|
|
|
FE(DSCAPS_PRIMARY8BIT)
|
|
|
|
FE(DSCAPS_PRIMARY16BIT)
|
|
|
|
FE(DSCAPS_CONTINUOUSRATE)
|
|
|
|
FE(DSCAPS_EMULDRIVER)
|
|
|
|
FE(DSCAPS_CERTIFIED)
|
|
|
|
FE(DSCAPS_SECONDARYMONO)
|
|
|
|
FE(DSCAPS_SECONDARYSTEREO)
|
|
|
|
FE(DSCAPS_SECONDARY8BIT)
|
|
|
|
FE(DSCAPS_SECONDARY16BIT)
|
|
|
|
#undef FE
|
|
|
|
};
|
2004-09-08 03:23:57 +02:00
|
|
|
unsigned int i;
|
2004-07-22 21:42:11 +02:00
|
|
|
|
|
|
|
for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++)
|
|
|
|
if ((flags[i].mask & xmask) == flags[i].mask)
|
2007-03-28 17:30:16 +02:00
|
|
|
TRACE("%s ",flags[i].name);
|
2004-07-22 21:42:11 +02:00
|
|
|
}
|
|
|
|
|
2004-07-04 02:13:44 +02:00
|
|
|
static void _dump_DSBCAPS(DWORD xmask) {
|
|
|
|
struct {
|
|
|
|
DWORD mask;
|
2005-07-15 11:58:36 +02:00
|
|
|
const char *name;
|
2004-07-04 02:13:44 +02:00
|
|
|
} flags[] = {
|
|
|
|
#define FE(x) { x, #x },
|
|
|
|
FE(DSBCAPS_PRIMARYBUFFER)
|
|
|
|
FE(DSBCAPS_STATIC)
|
|
|
|
FE(DSBCAPS_LOCHARDWARE)
|
|
|
|
FE(DSBCAPS_LOCSOFTWARE)
|
|
|
|
FE(DSBCAPS_CTRL3D)
|
|
|
|
FE(DSBCAPS_CTRLFREQUENCY)
|
|
|
|
FE(DSBCAPS_CTRLPAN)
|
|
|
|
FE(DSBCAPS_CTRLVOLUME)
|
|
|
|
FE(DSBCAPS_CTRLPOSITIONNOTIFY)
|
|
|
|
FE(DSBCAPS_STICKYFOCUS)
|
|
|
|
FE(DSBCAPS_GLOBALFOCUS)
|
|
|
|
FE(DSBCAPS_GETCURRENTPOSITION2)
|
|
|
|
FE(DSBCAPS_MUTE3DATMAXDISTANCE)
|
|
|
|
#undef FE
|
|
|
|
};
|
2004-09-08 03:23:57 +02:00
|
|
|
unsigned int i;
|
2004-07-04 02:13:44 +02:00
|
|
|
|
|
|
|
for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++)
|
|
|
|
if ((flags[i].mask & xmask) == flags[i].mask)
|
2007-03-28 17:30:16 +02:00
|
|
|
TRACE("%s ",flags[i].name);
|
2004-07-04 02:13:44 +02:00
|
|
|
}
|
|
|
|
|
2006-01-17 16:10:15 +01:00
|
|
|
/*******************************************************************************
|
2015-01-20 03:28:02 +01:00
|
|
|
* DirectSoundDevice
|
2006-01-17 16:10:15 +01:00
|
|
|
*/
|
2015-01-20 03:28:02 +01:00
|
|
|
static HRESULT DirectSoundDevice_Create(DirectSoundDevice ** ppDevice)
|
2004-08-25 04:09:00 +02:00
|
|
|
{
|
2015-01-20 03:28:02 +01:00
|
|
|
DirectSoundDevice * device;
|
|
|
|
TRACE("(%p)\n", ppDevice);
|
2004-07-04 02:13:44 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
/* Allocate memory */
|
|
|
|
device = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DirectSoundDevice));
|
|
|
|
if (device == NULL) {
|
|
|
|
WARN("out of memory\n");
|
|
|
|
return DSERR_OUTOFMEMORY;
|
|
|
|
}
|
2012-07-19 02:07:23 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
device->ref = 1;
|
|
|
|
device->priolevel = DSSCL_NORMAL;
|
|
|
|
device->state = STATE_STOPPED;
|
|
|
|
device->speaker_config = DSSPEAKER_COMBINED(DSSPEAKER_STEREO, DSSPEAKER_GEOMETRY_WIDE);
|
2012-07-19 02:07:23 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
DSOUND_ParseSpeakerConfig(device);
|
2012-07-19 02:07:23 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
/* 3D listener initial parameters */
|
|
|
|
device->ds3dl.dwSize = sizeof(DS3DLISTENER);
|
|
|
|
device->ds3dl.vPosition.x = 0.0;
|
|
|
|
device->ds3dl.vPosition.y = 0.0;
|
|
|
|
device->ds3dl.vPosition.z = 0.0;
|
|
|
|
device->ds3dl.vVelocity.x = 0.0;
|
|
|
|
device->ds3dl.vVelocity.y = 0.0;
|
|
|
|
device->ds3dl.vVelocity.z = 0.0;
|
|
|
|
device->ds3dl.vOrientFront.x = 0.0;
|
|
|
|
device->ds3dl.vOrientFront.y = 0.0;
|
|
|
|
device->ds3dl.vOrientFront.z = 1.0;
|
|
|
|
device->ds3dl.vOrientTop.x = 0.0;
|
|
|
|
device->ds3dl.vOrientTop.y = 1.0;
|
|
|
|
device->ds3dl.vOrientTop.z = 0.0;
|
|
|
|
device->ds3dl.flDistanceFactor = DS3D_DEFAULTDISTANCEFACTOR;
|
|
|
|
device->ds3dl.flRolloffFactor = DS3D_DEFAULTROLLOFFFACTOR;
|
|
|
|
device->ds3dl.flDopplerFactor = DS3D_DEFAULTDOPPLERFACTOR;
|
|
|
|
|
|
|
|
device->prebuf = ds_snd_queue_max;
|
|
|
|
device->guid = GUID_NULL;
|
|
|
|
|
|
|
|
/* Set default wave format (may need it for waveOutOpen) */
|
|
|
|
device->pwfx = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(WAVEFORMATEXTENSIBLE));
|
|
|
|
device->primary_pwfx = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(WAVEFORMATEXTENSIBLE));
|
|
|
|
if (!device->pwfx || !device->primary_pwfx) {
|
|
|
|
WARN("out of memory\n");
|
|
|
|
HeapFree(GetProcessHeap(),0,device->primary_pwfx);
|
|
|
|
HeapFree(GetProcessHeap(),0,device->pwfx);
|
|
|
|
HeapFree(GetProcessHeap(),0,device);
|
|
|
|
return DSERR_OUTOFMEMORY;
|
2012-07-19 02:07:23 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
device->pwfx->wFormatTag = WAVE_FORMAT_PCM;
|
|
|
|
device->pwfx->nSamplesPerSec = 22050;
|
|
|
|
device->pwfx->wBitsPerSample = 8;
|
|
|
|
device->pwfx->nChannels = 2;
|
|
|
|
device->pwfx->nBlockAlign = device->pwfx->wBitsPerSample * device->pwfx->nChannels / 8;
|
|
|
|
device->pwfx->nAvgBytesPerSec = device->pwfx->nSamplesPerSec * device->pwfx->nBlockAlign;
|
|
|
|
device->pwfx->cbSize = 0;
|
|
|
|
memcpy(device->primary_pwfx, device->pwfx, sizeof(*device->pwfx));
|
2004-07-19 22:06:22 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
InitializeCriticalSection(&(device->mixlock));
|
|
|
|
device->mixlock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": DirectSoundDevice.mixlock");
|
2004-07-04 02:13:44 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
RtlInitializeResource(&(device->buffer_list_lock));
|
2006-01-17 16:10:15 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
*ppDevice = device;
|
2004-07-04 02:13:44 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
return DS_OK;
|
2012-07-19 01:54:54 +02:00
|
|
|
}
|
2004-07-04 02:13:44 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
static ULONG DirectSoundDevice_AddRef(DirectSoundDevice * device)
|
2012-07-19 01:54:54 +02:00
|
|
|
{
|
2015-01-20 03:28:02 +01:00
|
|
|
ULONG ref = InterlockedIncrement(&(device->ref));
|
|
|
|
TRACE("(%p) ref was %d\n", device, ref - 1);
|
2012-07-19 01:54:54 +02:00
|
|
|
return ref;
|
2006-01-17 16:10:15 +01:00
|
|
|
}
|
2004-08-25 04:09:00 +02:00
|
|
|
|
2015-01-20 03:28:05 +01:00
|
|
|
static ULONG DirectSoundDevice_Release(DirectSoundDevice * device)
|
2012-07-19 01:54:54 +02:00
|
|
|
{
|
2015-01-20 03:28:02 +01:00
|
|
|
HRESULT hr;
|
|
|
|
ULONG ref = InterlockedDecrement(&(device->ref));
|
|
|
|
TRACE("(%p) ref was %u\n", device, ref + 1);
|
|
|
|
if (!ref) {
|
|
|
|
int i;
|
2012-07-19 01:54:54 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
SetEvent(device->sleepev);
|
|
|
|
if (device->thread) {
|
2015-03-17 17:35:47 +01:00
|
|
|
WaitForSingleObject(device->thread_finished, INFINITE);
|
2015-01-20 03:28:02 +01:00
|
|
|
CloseHandle(device->thread);
|
2015-03-17 17:35:47 +01:00
|
|
|
CloseHandle(device->thread_finished);
|
2015-01-20 03:28:02 +01:00
|
|
|
}
|
|
|
|
CloseHandle(device->sleepev);
|
2012-07-19 02:04:11 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
EnterCriticalSection(&DSOUND_renderers_lock);
|
|
|
|
list_remove(&device->entry);
|
|
|
|
LeaveCriticalSection(&DSOUND_renderers_lock);
|
2004-07-04 02:13:44 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
/* It is allowed to release this object even when buffers are playing */
|
|
|
|
if (device->buffers) {
|
|
|
|
WARN("%d secondary buffers not released\n", device->nrofbuffers);
|
|
|
|
for( i=0;i<device->nrofbuffers;i++)
|
|
|
|
secondarybuffer_destroy(device->buffers[i]);
|
|
|
|
}
|
2012-07-19 02:04:11 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
hr = DSOUND_PrimaryDestroy(device);
|
|
|
|
if (hr != DS_OK)
|
|
|
|
WARN("DSOUND_PrimaryDestroy failed\n");
|
2012-07-19 02:04:11 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if(device->client)
|
|
|
|
IAudioClient_Release(device->client);
|
|
|
|
if(device->render)
|
|
|
|
IAudioRenderClient_Release(device->render);
|
|
|
|
if(device->clock)
|
|
|
|
IAudioClock_Release(device->clock);
|
|
|
|
if(device->volume)
|
|
|
|
IAudioStreamVolume_Release(device->volume);
|
2012-07-19 02:04:11 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, device->tmp_buffer);
|
|
|
|
HeapFree(GetProcessHeap(), 0, device->mix_buffer);
|
|
|
|
HeapFree(GetProcessHeap(), 0, device->buffer);
|
|
|
|
RtlDeleteResource(&device->buffer_list_lock);
|
|
|
|
device->mixlock.DebugInfo->Spare[0] = 0;
|
|
|
|
DeleteCriticalSection(&device->mixlock);
|
|
|
|
HeapFree(GetProcessHeap(),0,device);
|
|
|
|
TRACE("(%p) released\n", device);
|
|
|
|
}
|
2005-10-10 12:29:13 +02:00
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
BOOL DSOUND_check_supported(IAudioClient *client, DWORD rate,
|
|
|
|
DWORD depth, WORD channels)
|
2005-05-31 11:31:37 +02:00
|
|
|
{
|
2015-01-20 03:28:02 +01:00
|
|
|
WAVEFORMATEX fmt, *junk;
|
|
|
|
HRESULT hr;
|
2012-07-19 02:04:11 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
fmt.wFormatTag = WAVE_FORMAT_PCM;
|
|
|
|
fmt.nChannels = channels;
|
|
|
|
fmt.nSamplesPerSec = rate;
|
|
|
|
fmt.wBitsPerSample = depth;
|
|
|
|
fmt.nBlockAlign = (channels * depth) / 8;
|
|
|
|
fmt.nAvgBytesPerSec = rate * fmt.nBlockAlign;
|
|
|
|
fmt.cbSize = 0;
|
2012-07-19 02:04:11 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
hr = IAudioClient_IsFormatSupported(client, AUDCLNT_SHAREMODE_SHARED, &fmt, &junk);
|
|
|
|
if(SUCCEEDED(hr))
|
|
|
|
CoTaskMemFree(junk);
|
2004-07-04 02:13:44 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
return hr == S_OK;
|
2006-01-17 16:10:15 +01:00
|
|
|
}
|
2004-07-04 02:13:44 +02:00
|
|
|
|
2015-01-20 03:28:05 +01:00
|
|
|
static HRESULT DirectSoundDevice_Initialize(DirectSoundDevice ** ppDevice, LPCGUID lpcGUID)
|
2006-01-17 16:10:15 +01:00
|
|
|
{
|
2015-01-20 03:28:02 +01:00
|
|
|
HRESULT hr = DS_OK;
|
|
|
|
GUID devGUID;
|
|
|
|
DirectSoundDevice *device;
|
|
|
|
IMMDevice *mmdevice;
|
2012-09-05 23:19:12 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
TRACE("(%p,%s)\n",ppDevice,debugstr_guid(lpcGUID));
|
2012-09-05 23:19:12 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if (*ppDevice != NULL) {
|
|
|
|
WARN("already initialized\n");
|
|
|
|
return DSERR_ALREADYINITIALIZED;
|
2012-09-05 23:19:12 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
/* Default device? */
|
|
|
|
if (!lpcGUID || IsEqualGUID(lpcGUID, &GUID_NULL))
|
|
|
|
lpcGUID = &DSDEVID_DefaultPlayback;
|
2015-01-11 22:42:44 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if(IsEqualGUID(lpcGUID, &DSDEVID_DefaultCapture) ||
|
|
|
|
IsEqualGUID(lpcGUID, &DSDEVID_DefaultVoiceCapture))
|
|
|
|
return DSERR_NODRIVER;
|
|
|
|
|
|
|
|
if (GetDeviceID(lpcGUID, &devGUID) != DS_OK) {
|
|
|
|
WARN("invalid parameter: lpcGUID\n");
|
|
|
|
return DSERR_INVALIDPARAM;
|
2015-01-11 22:42:44 +01:00
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
hr = get_mmdevice(eRender, &devGUID, &mmdevice);
|
|
|
|
if(FAILED(hr))
|
|
|
|
return hr;
|
2012-09-05 23:19:12 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
EnterCriticalSection(&DSOUND_renderers_lock);
|
2012-09-05 23:19:12 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
LIST_FOR_EACH_ENTRY(device, &DSOUND_renderers, DirectSoundDevice, entry){
|
|
|
|
if(IsEqualGUID(&device->guid, &devGUID)){
|
|
|
|
IMMDevice_Release(mmdevice);
|
|
|
|
DirectSoundDevice_AddRef(device);
|
|
|
|
*ppDevice = device;
|
|
|
|
LeaveCriticalSection(&DSOUND_renderers_lock);
|
|
|
|
return DS_OK;
|
|
|
|
}
|
2012-09-05 23:19:12 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
hr = DirectSoundDevice_Create(&device);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
WARN("DirectSoundDevice_Create failed\n");
|
|
|
|
IMMDevice_Release(mmdevice);
|
|
|
|
LeaveCriticalSection(&DSOUND_renderers_lock);
|
|
|
|
return hr;
|
2012-11-16 20:35:51 +01:00
|
|
|
}
|
2012-09-05 23:19:12 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
device->mmdevice = mmdevice;
|
|
|
|
device->guid = devGUID;
|
|
|
|
device->sleepev = CreateEventW(0, 0, 0, 0);
|
2012-09-05 23:19:12 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
hr = DSOUND_ReopenDevice(device, FALSE);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, device);
|
|
|
|
LeaveCriticalSection(&DSOUND_renderers_lock);
|
|
|
|
IMMDevice_Release(mmdevice);
|
|
|
|
WARN("DSOUND_ReopenDevice failed: %08x\n", hr);
|
|
|
|
return hr;
|
2012-09-05 23:19:12 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
ZeroMemory(&device->drvcaps, sizeof(device->drvcaps));
|
2004-07-04 02:13:44 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if(DSOUND_check_supported(device->client, 11025, 8, 1) ||
|
|
|
|
DSOUND_check_supported(device->client, 22050, 8, 1) ||
|
|
|
|
DSOUND_check_supported(device->client, 44100, 8, 1) ||
|
|
|
|
DSOUND_check_supported(device->client, 48000, 8, 1) ||
|
|
|
|
DSOUND_check_supported(device->client, 96000, 8, 1))
|
|
|
|
device->drvcaps.dwFlags |= DSCAPS_PRIMARY8BIT | DSCAPS_PRIMARYMONO;
|
2012-09-05 23:19:12 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if(DSOUND_check_supported(device->client, 11025, 16, 1) ||
|
|
|
|
DSOUND_check_supported(device->client, 22050, 16, 1) ||
|
|
|
|
DSOUND_check_supported(device->client, 44100, 16, 1) ||
|
|
|
|
DSOUND_check_supported(device->client, 48000, 16, 1) ||
|
|
|
|
DSOUND_check_supported(device->client, 96000, 16, 1))
|
|
|
|
device->drvcaps.dwFlags |= DSCAPS_PRIMARY16BIT | DSCAPS_PRIMARYMONO;
|
2012-09-05 23:19:12 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if(DSOUND_check_supported(device->client, 11025, 8, 2) ||
|
|
|
|
DSOUND_check_supported(device->client, 22050, 8, 2) ||
|
|
|
|
DSOUND_check_supported(device->client, 44100, 8, 2) ||
|
|
|
|
DSOUND_check_supported(device->client, 48000, 8, 2) ||
|
|
|
|
DSOUND_check_supported(device->client, 96000, 8, 2))
|
|
|
|
device->drvcaps.dwFlags |= DSCAPS_PRIMARY8BIT | DSCAPS_PRIMARYSTEREO;
|
2012-09-05 23:19:12 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if(DSOUND_check_supported(device->client, 11025, 16, 2) ||
|
|
|
|
DSOUND_check_supported(device->client, 22050, 16, 2) ||
|
|
|
|
DSOUND_check_supported(device->client, 44100, 16, 2) ||
|
|
|
|
DSOUND_check_supported(device->client, 48000, 16, 2) ||
|
|
|
|
DSOUND_check_supported(device->client, 96000, 16, 2))
|
|
|
|
device->drvcaps.dwFlags |= DSCAPS_PRIMARY16BIT | DSCAPS_PRIMARYSTEREO;
|
2004-07-04 02:13:44 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
/* the dsound mixer supports all of the following */
|
|
|
|
device->drvcaps.dwFlags |= DSCAPS_SECONDARY8BIT | DSCAPS_SECONDARY16BIT;
|
|
|
|
device->drvcaps.dwFlags |= DSCAPS_SECONDARYMONO | DSCAPS_SECONDARYSTEREO;
|
|
|
|
device->drvcaps.dwFlags |= DSCAPS_CONTINUOUSRATE;
|
2012-09-05 23:19:12 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
device->drvcaps.dwPrimaryBuffers = 1;
|
|
|
|
device->drvcaps.dwMinSecondarySampleRate = DSBFREQUENCY_MIN;
|
|
|
|
device->drvcaps.dwMaxSecondarySampleRate = DSBFREQUENCY_MAX;
|
|
|
|
device->drvcaps.dwMaxHwMixingAllBuffers = 16;
|
|
|
|
device->drvcaps.dwMaxHwMixingStaticBuffers = 1;
|
|
|
|
device->drvcaps.dwMaxHwMixingStreamingBuffers = 1;
|
|
|
|
device->drvcaps.dwFreeHwMixingAllBuffers = device->drvcaps.dwMaxHwMixingAllBuffers;
|
|
|
|
device->drvcaps.dwFreeHwMixingStaticBuffers = device->drvcaps.dwMaxHwMixingStaticBuffers;
|
|
|
|
device->drvcaps.dwFreeHwMixingStreamingBuffers = device->drvcaps.dwMaxHwMixingStreamingBuffers;
|
2012-09-05 23:19:12 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
ZeroMemory(&device->volpan, sizeof(device->volpan));
|
2012-09-05 23:19:12 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
hr = DSOUND_PrimaryCreate(device);
|
|
|
|
if (hr == DS_OK) {
|
2015-03-17 17:35:47 +01:00
|
|
|
device->thread_finished = CreateEventW(0, 0, 0, 0);
|
2015-01-20 03:28:02 +01:00
|
|
|
device->thread = CreateThread(0, 0, DSOUND_mixthread, device, 0, 0);
|
|
|
|
SetThreadPriority(device->thread, THREAD_PRIORITY_TIME_CRITICAL);
|
|
|
|
} else
|
|
|
|
WARN("DSOUND_PrimaryCreate failed: %08x\n", hr);
|
2014-12-31 19:53:06 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
*ppDevice = device;
|
|
|
|
list_add_tail(&DSOUND_renderers, &device->entry);
|
2004-07-04 02:13:44 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
LeaveCriticalSection(&DSOUND_renderers_lock);
|
|
|
|
|
|
|
|
return hr;
|
2006-01-17 16:10:15 +01:00
|
|
|
}
|
2004-07-04 02:13:44 +02:00
|
|
|
|
2015-01-20 03:28:05 +01:00
|
|
|
static HRESULT DirectSoundDevice_CreateSoundBuffer(
|
2015-01-20 03:28:02 +01:00
|
|
|
DirectSoundDevice * device,
|
|
|
|
LPCDSBUFFERDESC dsbd,
|
|
|
|
LPLPDIRECTSOUNDBUFFER ppdsb,
|
|
|
|
LPUNKNOWN lpunk,
|
|
|
|
BOOL from8)
|
2006-01-17 16:10:15 +01:00
|
|
|
{
|
2015-01-20 03:28:02 +01:00
|
|
|
HRESULT hres = DS_OK;
|
|
|
|
TRACE("(%p,%p,%p,%p)\n",device,dsbd,ppdsb,lpunk);
|
2012-09-05 23:19:12 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if (device == NULL) {
|
2012-09-05 23:19:12 +02:00
|
|
|
WARN("not initialized\n");
|
|
|
|
return DSERR_UNINITIALIZED;
|
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if (dsbd == NULL) {
|
|
|
|
WARN("invalid parameter: dsbd == NULL\n");
|
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
2004-07-04 02:13:44 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if (dsbd->dwSize != sizeof(DSBUFFERDESC) &&
|
|
|
|
dsbd->dwSize != sizeof(DSBUFFERDESC1)) {
|
|
|
|
WARN("invalid parameter: dsbd\n");
|
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
2004-07-04 02:13:44 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if (ppdsb == NULL) {
|
|
|
|
WARN("invalid parameter: ppdsb == NULL\n");
|
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
*ppdsb = NULL;
|
2012-07-19 02:00:27 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if (TRACE_ON(dsound)) {
|
|
|
|
TRACE("(structsize=%d)\n",dsbd->dwSize);
|
|
|
|
TRACE("(flags=0x%08x:\n",dsbd->dwFlags);
|
|
|
|
_dump_DSBCAPS(dsbd->dwFlags);
|
|
|
|
TRACE(")\n");
|
|
|
|
TRACE("(bufferbytes=%d)\n",dsbd->dwBufferBytes);
|
|
|
|
TRACE("(lpwfxFormat=%p)\n",dsbd->lpwfxFormat);
|
|
|
|
}
|
2012-07-19 01:53:31 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if (!(dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER) &&
|
|
|
|
dsbd->dwFlags & DSBCAPS_LOCHARDWARE &&
|
|
|
|
device->drvcaps.dwFreeHwMixingAllBuffers == 0)
|
|
|
|
{
|
|
|
|
WARN("ran out of emulated hardware buffers\n");
|
|
|
|
return DSERR_ALLOCATED;
|
2012-07-19 01:53:31 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if (dsbd->dwFlags & DSBCAPS_PRIMARYBUFFER) {
|
|
|
|
if (dsbd->lpwfxFormat != NULL) {
|
|
|
|
WARN("invalid parameter: dsbd->lpwfxFormat must be NULL for "
|
|
|
|
"primary buffer\n");
|
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
2012-07-19 02:00:27 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if (device->primary) {
|
|
|
|
WARN("Primary Buffer already created\n");
|
|
|
|
IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER8)(device->primary));
|
|
|
|
*ppdsb = (LPDIRECTSOUNDBUFFER)(device->primary);
|
|
|
|
} else {
|
|
|
|
hres = primarybuffer_create(device, &device->primary, dsbd);
|
|
|
|
if (device->primary) {
|
|
|
|
*ppdsb = (IDirectSoundBuffer*)&device->primary->IDirectSoundBuffer8_iface;
|
|
|
|
device->primary->dsbd.dwFlags &= ~(DSBCAPS_LOCHARDWARE | DSBCAPS_LOCSOFTWARE);
|
|
|
|
device->primary->dsbd.dwFlags |= DSBCAPS_LOCSOFTWARE;
|
|
|
|
} else
|
|
|
|
WARN("primarybuffer_create() failed\n");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
IDirectSoundBufferImpl * dsb;
|
|
|
|
WAVEFORMATEXTENSIBLE *pwfxe;
|
2012-07-19 01:53:31 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if (dsbd->lpwfxFormat == NULL) {
|
|
|
|
WARN("invalid parameter: dsbd->lpwfxFormat can't be NULL for "
|
|
|
|
"secondary buffer\n");
|
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
pwfxe = (WAVEFORMATEXTENSIBLE*)dsbd->lpwfxFormat;
|
2012-08-16 01:45:29 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if (pwfxe->Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE)
|
|
|
|
{
|
|
|
|
/* check if cbSize is at least 22 bytes */
|
|
|
|
if (pwfxe->Format.cbSize < (sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX)))
|
|
|
|
{
|
|
|
|
WARN("Too small a cbSize %u\n", pwfxe->Format.cbSize);
|
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
2012-07-19 02:00:27 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
/* cbSize should be 22 bytes, with one possible exception */
|
|
|
|
if (pwfxe->Format.cbSize > (sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX)) &&
|
|
|
|
!((IsEqualGUID(&pwfxe->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM) || IsEqualGUID(&pwfxe->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)) &&
|
|
|
|
pwfxe->Format.cbSize == sizeof(WAVEFORMATEXTENSIBLE)))
|
|
|
|
{
|
|
|
|
WARN("Too big a cbSize %u\n", pwfxe->Format.cbSize);
|
|
|
|
return DSERR_CONTROLUNAVAIL;
|
|
|
|
}
|
2012-07-19 01:53:31 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if ((!IsEqualGUID(&pwfxe->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM)) && (!IsEqualGUID(&pwfxe->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)))
|
|
|
|
{
|
|
|
|
if (!IsEqualGUID(&pwfxe->SubFormat, &GUID_NULL))
|
|
|
|
FIXME("SubFormat %s not supported right now.\n", debugstr_guid(&pwfxe->SubFormat));
|
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
if (pwfxe->Samples.wValidBitsPerSample > dsbd->lpwfxFormat->wBitsPerSample)
|
|
|
|
{
|
|
|
|
WARN("Samples.wValidBitsPerSample(%d) > Format.wBitsPerSample (%d)\n", pwfxe->Samples.wValidBitsPerSample, pwfxe->Format.wBitsPerSample);
|
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
if (pwfxe->Samples.wValidBitsPerSample && pwfxe->Samples.wValidBitsPerSample < dsbd->lpwfxFormat->wBitsPerSample)
|
|
|
|
{
|
|
|
|
FIXME("Non-packed formats not supported right now: %d/%d\n", pwfxe->Samples.wValidBitsPerSample, dsbd->lpwfxFormat->wBitsPerSample);
|
|
|
|
return DSERR_CONTROLUNAVAIL;
|
|
|
|
}
|
|
|
|
}
|
2006-01-17 16:10:15 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
TRACE("(formattag=0x%04x,chans=%d,samplerate=%d,"
|
|
|
|
"bytespersec=%d,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
|
|
|
|
dsbd->lpwfxFormat->wFormatTag, dsbd->lpwfxFormat->nChannels,
|
|
|
|
dsbd->lpwfxFormat->nSamplesPerSec,
|
|
|
|
dsbd->lpwfxFormat->nAvgBytesPerSec,
|
|
|
|
dsbd->lpwfxFormat->nBlockAlign,
|
|
|
|
dsbd->lpwfxFormat->wBitsPerSample, dsbd->lpwfxFormat->cbSize);
|
|
|
|
|
|
|
|
if (from8 && (dsbd->dwFlags & DSBCAPS_CTRL3D) && (dsbd->lpwfxFormat->nChannels != 1)) {
|
|
|
|
WARN("invalid parameter: 3D buffer format must be mono\n");
|
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IDirectSoundBufferImpl_Create(device, &dsb, dsbd);
|
|
|
|
if (dsb) {
|
|
|
|
*ppdsb = (IDirectSoundBuffer*)&dsb->IDirectSoundBuffer8_iface;
|
|
|
|
if (dsbd->dwFlags & DSBCAPS_LOCHARDWARE)
|
|
|
|
device->drvcaps.dwFreeHwMixingAllBuffers--;
|
|
|
|
} else
|
|
|
|
WARN("IDirectSoundBufferImpl_Create failed\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return hres;
|
2004-07-04 02:13:44 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:05 +01:00
|
|
|
static HRESULT DirectSoundDevice_DuplicateSoundBuffer(
|
2015-01-20 03:28:02 +01:00
|
|
|
DirectSoundDevice * device,
|
|
|
|
LPDIRECTSOUNDBUFFER psb,
|
|
|
|
LPLPDIRECTSOUNDBUFFER ppdsb)
|
2004-07-04 02:13:44 +02:00
|
|
|
{
|
2015-01-20 03:28:02 +01:00
|
|
|
HRESULT hres = DS_OK;
|
|
|
|
IDirectSoundBufferImpl* dsb;
|
|
|
|
TRACE("(%p,%p,%p)\n",device,psb,ppdsb);
|
2004-07-04 02:13:44 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if (device == NULL) {
|
|
|
|
WARN("not initialized\n");
|
|
|
|
return DSERR_UNINITIALIZED;
|
|
|
|
}
|
2004-07-04 02:13:44 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if (psb == NULL) {
|
|
|
|
WARN("invalid parameter: psb == NULL\n");
|
2004-07-04 02:13:44 +02:00
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if (ppdsb == NULL) {
|
|
|
|
WARN("invalid parameter: ppdsb == NULL\n");
|
2006-01-17 16:10:15 +01:00
|
|
|
return DSERR_INVALIDPARAM;
|
2004-07-04 02:13:44 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
/* make sure we have a secondary buffer */
|
|
|
|
if (psb == (IDirectSoundBuffer *)&device->primary->IDirectSoundBuffer8_iface) {
|
|
|
|
WARN("trying to duplicate primary buffer\n");
|
|
|
|
*ppdsb = NULL;
|
|
|
|
return DSERR_INVALIDCALL;
|
2004-07-04 02:13:44 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
/* duplicate the actual buffer implementation */
|
|
|
|
hres = IDirectSoundBufferImpl_Duplicate(device, &dsb, (IDirectSoundBufferImpl*)psb);
|
|
|
|
if (hres == DS_OK)
|
|
|
|
*ppdsb = (IDirectSoundBuffer*)&dsb->IDirectSoundBuffer8_iface;
|
|
|
|
else
|
|
|
|
WARN("IDirectSoundBufferImpl_Duplicate failed\n");
|
2004-07-04 02:13:44 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
return hres;
|
2004-07-04 02:13:44 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
/*
|
|
|
|
* Add secondary buffer to buffer list.
|
|
|
|
* Gets exclusive access to buffer for writing.
|
2006-01-17 16:10:15 +01:00
|
|
|
*/
|
2015-01-20 03:28:02 +01:00
|
|
|
HRESULT DirectSoundDevice_AddBuffer(
|
|
|
|
DirectSoundDevice * device,
|
|
|
|
IDirectSoundBufferImpl * pDSB)
|
2004-07-04 02:13:44 +02:00
|
|
|
{
|
2015-01-20 03:28:02 +01:00
|
|
|
IDirectSoundBufferImpl **newbuffers;
|
|
|
|
HRESULT hr = DS_OK;
|
2004-07-04 02:13:44 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
TRACE("(%p, %p)\n", device, pDSB);
|
2004-07-04 02:13:44 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
RtlAcquireResourceExclusive(&(device->buffer_list_lock), TRUE);
|
2004-07-04 02:13:44 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if (device->buffers)
|
|
|
|
newbuffers = HeapReAlloc(GetProcessHeap(),0,device->buffers,sizeof(IDirectSoundBufferImpl*)*(device->nrofbuffers+1));
|
|
|
|
else
|
|
|
|
newbuffers = HeapAlloc(GetProcessHeap(),0,sizeof(IDirectSoundBufferImpl*)*(device->nrofbuffers+1));
|
2004-07-04 02:13:44 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if (newbuffers) {
|
|
|
|
device->buffers = newbuffers;
|
|
|
|
device->buffers[device->nrofbuffers] = pDSB;
|
|
|
|
device->nrofbuffers++;
|
|
|
|
TRACE("buffer count is now %d\n", device->nrofbuffers);
|
|
|
|
} else {
|
|
|
|
ERR("out of memory for buffer list! Current buffer count is %d\n", device->nrofbuffers);
|
|
|
|
hr = DSERR_OUTOFMEMORY;
|
2004-07-04 02:13:44 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
RtlReleaseResource(&(device->buffer_list_lock));
|
2004-07-04 02:13:44 +02:00
|
|
|
|
2006-01-17 16:10:15 +01:00
|
|
|
return hr;
|
2004-07-04 02:13:44 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
/*
|
|
|
|
* Remove secondary buffer from buffer list.
|
|
|
|
* Gets exclusive access to buffer for writing.
|
|
|
|
*/
|
|
|
|
void DirectSoundDevice_RemoveBuffer(DirectSoundDevice * device, IDirectSoundBufferImpl * pDSB)
|
2015-01-06 20:26:47 +01:00
|
|
|
{
|
2015-01-20 03:28:02 +01:00
|
|
|
int i;
|
2015-01-06 20:26:47 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
TRACE("(%p, %p)\n", device, pDSB);
|
2015-01-06 20:27:21 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
RtlAcquireResourceExclusive(&(device->buffer_list_lock), TRUE);
|
2015-01-06 20:27:21 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if (device->nrofbuffers == 1) {
|
|
|
|
assert(device->buffers[0] == pDSB);
|
|
|
|
HeapFree(GetProcessHeap(), 0, device->buffers);
|
|
|
|
device->buffers = NULL;
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < device->nrofbuffers; i++) {
|
|
|
|
if (device->buffers[i] == pDSB) {
|
|
|
|
/* Put the last buffer of the list in the (now empty) position */
|
|
|
|
device->buffers[i] = device->buffers[device->nrofbuffers - 1];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-01-06 20:26:47 +01:00
|
|
|
}
|
2015-01-20 03:28:02 +01:00
|
|
|
device->nrofbuffers--;
|
|
|
|
TRACE("buffer count is now %d\n", device->nrofbuffers);
|
|
|
|
|
|
|
|
RtlReleaseResource(&(device->buffer_list_lock));
|
2015-01-06 20:26:47 +01:00
|
|
|
}
|
|
|
|
|
2004-07-04 02:13:44 +02:00
|
|
|
/*******************************************************************************
|
2015-01-20 03:28:02 +01:00
|
|
|
* IUnknown Implementation for DirectSound
|
2004-07-04 02:13:44 +02:00
|
|
|
*/
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
static void directsound_destroy(IDirectSoundImpl *This)
|
|
|
|
{
|
|
|
|
if (This->device)
|
|
|
|
DirectSoundDevice_Release(This->device);
|
|
|
|
HeapFree(GetProcessHeap(),0,This);
|
|
|
|
TRACE("(%p) released\n", This);
|
|
|
|
}
|
2004-07-04 02:13:44 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
static inline IDirectSoundImpl *impl_from_IUnknown(IUnknown *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, IDirectSoundImpl, IUnknown_inner);
|
|
|
|
}
|
2006-01-17 16:10:15 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
static HRESULT WINAPI IUnknownImpl_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
IDirectSoundImpl *This = impl_from_IUnknown(iface);
|
2015-01-06 20:26:47 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
TRACE("(%p,%s,%p)\n", This, debugstr_guid(riid), ppv);
|
2006-01-17 16:10:15 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if (!ppv) {
|
|
|
|
WARN("invalid parameter\n");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
*ppv = NULL;
|
2006-01-17 16:10:15 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if (IsEqualIID(riid, &IID_IUnknown))
|
|
|
|
*ppv = &This->IUnknown_inner;
|
|
|
|
else if (IsEqualIID(riid, &IID_IDirectSound) ||
|
|
|
|
(IsEqualIID(riid, &IID_IDirectSound8) && This->has_ds8))
|
|
|
|
*ppv = &This->IDirectSound8_iface;
|
|
|
|
else {
|
|
|
|
WARN("unknown IID %s\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
2004-07-04 02:13:44 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
2004-07-04 02:13:44 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
static ULONG WINAPI IUnknownImpl_AddRef(IUnknown *iface)
|
|
|
|
{
|
|
|
|
IDirectSoundImpl *This = impl_from_IUnknown(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
2004-07-04 02:13:44 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
2006-01-17 16:10:15 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if(ref == 1)
|
|
|
|
InterlockedIncrement(&This->numIfaces);
|
2006-01-17 16:10:15 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
return ref;
|
2004-07-04 02:13:44 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
static ULONG WINAPI IUnknownImpl_Release(IUnknown *iface)
|
2004-07-04 02:13:44 +02:00
|
|
|
{
|
2015-01-20 03:28:02 +01:00
|
|
|
IDirectSoundImpl *This = impl_from_IUnknown(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
|
|
|
|
|
|
|
if (!ref && !InterlockedDecrement(&This->numIfaces))
|
|
|
|
directsound_destroy(This);
|
|
|
|
|
2006-01-17 16:10:15 +01:00
|
|
|
return ref;
|
2004-07-04 02:13:44 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
static const IUnknownVtbl unk_vtbl =
|
2004-07-04 02:13:44 +02:00
|
|
|
{
|
2015-01-20 03:28:02 +01:00
|
|
|
IUnknownImpl_QueryInterface,
|
|
|
|
IUnknownImpl_AddRef,
|
|
|
|
IUnknownImpl_Release
|
|
|
|
};
|
2006-01-17 16:10:15 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
/*******************************************************************************
|
|
|
|
* IDirectSound and IDirectSound8 Implementation
|
|
|
|
*/
|
|
|
|
static inline IDirectSoundImpl *impl_from_IDirectSound8(IDirectSound8 *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, IDirectSoundImpl, IDirectSound8_iface);
|
|
|
|
}
|
2006-01-17 16:10:15 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
static HRESULT WINAPI IDirectSound8Impl_QueryInterface(IDirectSound8 *iface, REFIID riid,
|
|
|
|
void **ppv)
|
|
|
|
{
|
|
|
|
IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
|
|
|
|
TRACE("(%p,%s,%p)\n", This, debugstr_guid(riid), ppv);
|
|
|
|
return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
|
|
|
|
}
|
2011-09-27 15:51:07 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
static ULONG WINAPI IDirectSound8Impl_AddRef(IDirectSound8 *iface)
|
|
|
|
{
|
|
|
|
IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&This->refds);
|
2006-01-17 16:10:15 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
TRACE("(%p) refds=%d\n", This, ref);
|
2006-01-17 16:10:15 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if(ref == 1)
|
|
|
|
InterlockedIncrement(&This->numIfaces);
|
2006-01-17 16:10:15 +01:00
|
|
|
|
|
|
|
return ref;
|
2004-07-04 02:13:44 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
static ULONG WINAPI IDirectSound8Impl_Release(IDirectSound8 *iface)
|
2011-09-27 15:51:07 +02:00
|
|
|
{
|
2015-01-20 03:28:02 +01:00
|
|
|
IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&(This->refds));
|
2011-09-27 15:51:07 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
TRACE("(%p) refds=%d\n", This, ref);
|
2011-09-27 15:51:07 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if (!ref && !InterlockedDecrement(&This->numIfaces))
|
|
|
|
directsound_destroy(This);
|
2011-09-27 15:51:07 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
return ref;
|
2011-09-27 15:51:07 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
static HRESULT WINAPI IDirectSound8Impl_CreateSoundBuffer(IDirectSound8 *iface,
|
|
|
|
const DSBUFFERDESC *dsbd, IDirectSoundBuffer **ppdsb, IUnknown *lpunk)
|
2004-07-04 02:13:44 +02:00
|
|
|
{
|
2015-01-20 03:28:02 +01:00
|
|
|
IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
|
|
|
|
TRACE("(%p,%p,%p,%p)\n", This, dsbd, ppdsb, lpunk);
|
|
|
|
return DirectSoundDevice_CreateSoundBuffer(This->device, dsbd, ppdsb, lpunk, This->has_ds8);
|
|
|
|
}
|
2006-01-17 16:10:15 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
static HRESULT WINAPI IDirectSound8Impl_GetCaps(IDirectSound8 *iface, DSCAPS *dscaps)
|
|
|
|
{
|
|
|
|
IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
|
2006-01-17 16:10:15 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
TRACE("(%p, %p)\n", This, dscaps);
|
2011-09-27 15:51:07 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if (!This->device) {
|
|
|
|
WARN("not initialized\n");
|
|
|
|
return DSERR_UNINITIALIZED;
|
|
|
|
}
|
|
|
|
if (!dscaps) {
|
|
|
|
WARN("invalid parameter: dscaps = NULL\n");
|
2006-01-17 16:10:15 +01:00
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
2015-01-20 03:28:02 +01:00
|
|
|
if (dscaps->dwSize < sizeof(*dscaps)) {
|
|
|
|
WARN("invalid parameter: dscaps->dwSize = %d\n", dscaps->dwSize);
|
|
|
|
return DSERR_INVALIDPARAM;
|
2006-01-17 16:10:15 +01:00
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
dscaps->dwFlags = This->device->drvcaps.dwFlags;
|
|
|
|
dscaps->dwMinSecondarySampleRate = This->device->drvcaps.dwMinSecondarySampleRate;
|
|
|
|
dscaps->dwMaxSecondarySampleRate = This->device->drvcaps.dwMaxSecondarySampleRate;
|
|
|
|
dscaps->dwPrimaryBuffers = This->device->drvcaps.dwPrimaryBuffers;
|
|
|
|
dscaps->dwMaxHwMixingAllBuffers = This->device->drvcaps.dwMaxHwMixingAllBuffers;
|
|
|
|
dscaps->dwMaxHwMixingStaticBuffers = This->device->drvcaps.dwMaxHwMixingStaticBuffers;
|
|
|
|
dscaps->dwMaxHwMixingStreamingBuffers = This->device->drvcaps.dwMaxHwMixingStreamingBuffers;
|
|
|
|
dscaps->dwFreeHwMixingAllBuffers = This->device->drvcaps.dwFreeHwMixingAllBuffers;
|
|
|
|
|
|
|
|
if (This->device->drvcaps.dwFreeHwMixingAllBuffers > 0) {
|
|
|
|
dscaps->dwFreeHwMixingStaticBuffers = This->device->drvcaps.dwFreeHwMixingStaticBuffers;
|
|
|
|
dscaps->dwFreeHwMixingStreamingBuffers = This->device->drvcaps.dwFreeHwMixingStreamingBuffers;
|
|
|
|
} else {
|
|
|
|
dscaps->dwFreeHwMixingStaticBuffers = 0;
|
|
|
|
dscaps->dwFreeHwMixingStreamingBuffers = 0;
|
2011-09-27 15:51:07 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
dscaps->dwMaxHw3DAllBuffers = This->device->drvcaps.dwMaxHw3DAllBuffers;
|
|
|
|
dscaps->dwMaxHw3DStaticBuffers = This->device->drvcaps.dwMaxHw3DStaticBuffers;
|
|
|
|
dscaps->dwMaxHw3DStreamingBuffers = This->device->drvcaps.dwMaxHw3DStreamingBuffers;
|
|
|
|
dscaps->dwFreeHw3DAllBuffers = This->device->drvcaps.dwFreeHw3DAllBuffers;
|
|
|
|
dscaps->dwFreeHw3DStaticBuffers = This->device->drvcaps.dwFreeHw3DStaticBuffers;
|
|
|
|
dscaps->dwFreeHw3DStreamingBuffers = This->device->drvcaps.dwFreeHw3DStreamingBuffers;
|
|
|
|
dscaps->dwTotalHwMemBytes = This->device->drvcaps.dwTotalHwMemBytes;
|
|
|
|
dscaps->dwFreeHwMemBytes = This->device->drvcaps.dwFreeHwMemBytes;
|
|
|
|
dscaps->dwMaxContigFreeHwMemBytes = This->device->drvcaps.dwMaxContigFreeHwMemBytes;
|
|
|
|
dscaps->dwUnlockTransferRateHwBuffers = This->device->drvcaps.dwUnlockTransferRateHwBuffers;
|
|
|
|
dscaps->dwPlayCpuOverheadSwBuffers = This->device->drvcaps.dwPlayCpuOverheadSwBuffers;
|
2006-01-17 16:10:15 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if (TRACE_ON(dsound)) {
|
|
|
|
TRACE("(flags=0x%08x:\n", dscaps->dwFlags);
|
|
|
|
_dump_DSCAPS(dscaps->dwFlags);
|
|
|
|
TRACE(")\n");
|
2006-01-17 16:10:15 +01:00
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
return DS_OK;
|
|
|
|
}
|
2011-09-27 15:51:07 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
static HRESULT WINAPI IDirectSound8Impl_DuplicateSoundBuffer(IDirectSound8 *iface,
|
|
|
|
IDirectSoundBuffer *psb, IDirectSoundBuffer **ppdsb)
|
|
|
|
{
|
|
|
|
IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
|
|
|
|
TRACE("(%p,%p,%p)\n", This, psb, ppdsb);
|
|
|
|
return DirectSoundDevice_DuplicateSoundBuffer(This->device, psb, ppdsb);
|
|
|
|
}
|
2011-09-27 15:51:07 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
static HRESULT WINAPI IDirectSound8Impl_SetCooperativeLevel(IDirectSound8 *iface, HWND hwnd,
|
|
|
|
DWORD level)
|
|
|
|
{
|
|
|
|
IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
|
|
|
|
DirectSoundDevice *device = This->device;
|
|
|
|
DWORD oldlevel;
|
|
|
|
HRESULT hr = S_OK;
|
2011-09-27 15:51:07 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
TRACE("(%p,%p,%s)\n", This, hwnd, dumpCooperativeLevel(level));
|
2011-09-27 15:51:07 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if (!device) {
|
|
|
|
WARN("not initialized\n");
|
|
|
|
return DSERR_UNINITIALIZED;
|
|
|
|
}
|
2012-02-14 16:40:38 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if (level == DSSCL_PRIORITY || level == DSSCL_EXCLUSIVE) {
|
|
|
|
WARN("level=%s not fully supported\n",
|
|
|
|
level==DSSCL_PRIORITY ? "DSSCL_PRIORITY" : "DSSCL_EXCLUSIVE");
|
|
|
|
}
|
2011-09-27 15:51:07 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
RtlAcquireResourceExclusive(&device->buffer_list_lock, TRUE);
|
|
|
|
EnterCriticalSection(&device->mixlock);
|
|
|
|
oldlevel = device->priolevel;
|
|
|
|
device->priolevel = level;
|
|
|
|
if ((level == DSSCL_WRITEPRIMARY) != (oldlevel == DSSCL_WRITEPRIMARY)) {
|
|
|
|
hr = DSOUND_ReopenDevice(device, level == DSSCL_WRITEPRIMARY);
|
|
|
|
if (FAILED(hr))
|
|
|
|
device->priolevel = oldlevel;
|
|
|
|
else
|
|
|
|
DSOUND_PrimaryOpen(device);
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(&device->mixlock);
|
|
|
|
RtlReleaseResource(&device->buffer_list_lock);
|
|
|
|
return hr;
|
|
|
|
}
|
2006-01-17 16:10:15 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
static HRESULT WINAPI IDirectSound8Impl_Compact(IDirectSound8 *iface)
|
|
|
|
{
|
|
|
|
IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
|
2011-09-27 15:51:07 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
TRACE("(%p)\n", This);
|
2011-09-27 15:51:07 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if (!This->device) {
|
|
|
|
WARN("not initialized\n");
|
|
|
|
return DSERR_UNINITIALIZED;
|
|
|
|
}
|
2006-01-17 16:10:15 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if (This->device->priolevel < DSSCL_PRIORITY) {
|
|
|
|
WARN("incorrect priority level\n");
|
|
|
|
return DSERR_PRIOLEVELNEEDED;
|
|
|
|
}
|
|
|
|
return DS_OK;
|
2004-07-04 02:13:44 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
static HRESULT WINAPI IDirectSound8Impl_GetSpeakerConfig(IDirectSound8 *iface, DWORD *config)
|
2004-07-04 02:13:44 +02:00
|
|
|
{
|
2015-01-20 03:28:02 +01:00
|
|
|
IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
|
2006-01-17 16:10:15 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
TRACE("(%p, %p)\n", This, config);
|
|
|
|
|
|
|
|
if (!This->device) {
|
2006-01-17 16:10:15 +01:00
|
|
|
WARN("not initialized\n");
|
|
|
|
return DSERR_UNINITIALIZED;
|
|
|
|
}
|
2015-01-20 03:28:02 +01:00
|
|
|
if (!config) {
|
|
|
|
WARN("invalid parameter: config == NULL\n");
|
2006-01-17 16:10:15 +01:00
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
WARN("not fully functional\n");
|
|
|
|
*config = This->device->speaker_config;
|
|
|
|
return DS_OK;
|
|
|
|
}
|
2006-01-17 16:10:15 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
static HRESULT WINAPI IDirectSound8Impl_SetSpeakerConfig(IDirectSound8 *iface, DWORD config)
|
|
|
|
{
|
|
|
|
IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
|
2006-01-17 16:10:15 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
TRACE("(%p,0x%08x)\n", This, config);
|
|
|
|
|
|
|
|
if (!This->device) {
|
|
|
|
WARN("not initialized\n");
|
|
|
|
return DSERR_UNINITIALIZED;
|
2006-01-17 16:10:15 +01:00
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
/* NOP on Vista and above */
|
|
|
|
|
|
|
|
return DS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IDirectSound8Impl_Initialize(IDirectSound8 *iface, const GUID *lpcGuid)
|
|
|
|
{
|
|
|
|
IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
|
|
|
|
TRACE("(%p, %s)\n", This, debugstr_guid(lpcGuid));
|
|
|
|
return DirectSoundDevice_Initialize(&This->device, lpcGuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IDirectSound8Impl_VerifyCertification(IDirectSound8 *iface, DWORD *certified)
|
|
|
|
{
|
|
|
|
IDirectSoundImpl *This = impl_from_IDirectSound8(iface);
|
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", This, certified);
|
|
|
|
|
|
|
|
if (!This->device) {
|
|
|
|
WARN("not initialized\n");
|
|
|
|
return DSERR_UNINITIALIZED;
|
2011-10-19 22:07:18 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if (This->device->drvcaps.dwFlags & DSCAPS_CERTIFIED)
|
|
|
|
*certified = DS_CERTIFIED;
|
|
|
|
else
|
|
|
|
*certified = DS_UNCERTIFIED;
|
2006-01-17 16:10:15 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
return DS_OK;
|
|
|
|
}
|
2006-01-17 16:10:15 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
static const IDirectSound8Vtbl ds8_vtbl =
|
|
|
|
{
|
|
|
|
IDirectSound8Impl_QueryInterface,
|
|
|
|
IDirectSound8Impl_AddRef,
|
|
|
|
IDirectSound8Impl_Release,
|
|
|
|
IDirectSound8Impl_CreateSoundBuffer,
|
|
|
|
IDirectSound8Impl_GetCaps,
|
|
|
|
IDirectSound8Impl_DuplicateSoundBuffer,
|
|
|
|
IDirectSound8Impl_SetCooperativeLevel,
|
|
|
|
IDirectSound8Impl_Compact,
|
|
|
|
IDirectSound8Impl_GetSpeakerConfig,
|
|
|
|
IDirectSound8Impl_SetSpeakerConfig,
|
|
|
|
IDirectSound8Impl_Initialize,
|
|
|
|
IDirectSound8Impl_VerifyCertification
|
|
|
|
};
|
2007-11-05 23:23:11 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
HRESULT IDirectSoundImpl_Create(IUnknown *outer_unk, REFIID riid, void **ppv, BOOL has_ds8)
|
|
|
|
{
|
|
|
|
IDirectSoundImpl *obj;
|
|
|
|
HRESULT hr;
|
2007-11-05 23:23:11 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
|
2007-11-05 23:23:11 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
*ppv = NULL;
|
|
|
|
obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*obj));
|
|
|
|
if (!obj) {
|
|
|
|
WARN("out of memory\n");
|
|
|
|
return DSERR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_dsound_options();
|
|
|
|
|
|
|
|
obj->IUnknown_inner.lpVtbl = &unk_vtbl;
|
|
|
|
obj->IDirectSound8_iface.lpVtbl = &ds8_vtbl;
|
|
|
|
obj->ref = 1;
|
|
|
|
obj->refds = 0;
|
|
|
|
obj->numIfaces = 1;
|
|
|
|
obj->device = NULL;
|
|
|
|
obj->has_ds8 = has_ds8;
|
2006-01-17 16:10:15 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
/* COM aggregation supported only internally */
|
|
|
|
if (outer_unk)
|
|
|
|
obj->outer_unk = outer_unk;
|
|
|
|
else
|
|
|
|
obj->outer_unk = &obj->IUnknown_inner;
|
2006-01-17 16:10:15 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
hr = IUnknown_QueryInterface(&obj->IUnknown_inner, riid, ppv);
|
|
|
|
IUnknown_Release(&obj->IUnknown_inner);
|
2004-07-04 02:13:44 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
return hr;
|
|
|
|
}
|
2006-01-17 16:10:15 +01:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
HRESULT DSOUND_Create(REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
return IDirectSoundImpl_Create(NULL, riid, ppv, FALSE);
|
2004-07-04 02:13:44 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
HRESULT DSOUND_Create8(REFIID riid, void **ppv)
|
2004-07-04 02:13:44 +02:00
|
|
|
{
|
2015-01-20 03:28:02 +01:00
|
|
|
return IDirectSoundImpl_Create(NULL, riid, ppv, TRUE);
|
|
|
|
}
|
2004-07-04 02:13:44 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
/*******************************************************************************
|
|
|
|
* DirectSoundCreate (DSOUND.1)
|
|
|
|
*
|
|
|
|
* Creates and initializes a DirectSound interface.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpcGUID [I] Address of the GUID that identifies the sound device.
|
|
|
|
* ppDS [O] Address of a variable to receive the interface pointer.
|
|
|
|
* pUnkOuter [I] Must be NULL.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: DS_OK
|
|
|
|
* Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
|
|
|
|
* DSERR_NODRIVER, DSERR_OUTOFMEMORY
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI DirectSoundCreate(
|
|
|
|
LPCGUID lpcGUID,
|
|
|
|
LPDIRECTSOUND *ppDS,
|
|
|
|
IUnknown *pUnkOuter)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
LPDIRECTSOUND pDS;
|
2004-07-04 02:13:44 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID),ppDS,pUnkOuter);
|
|
|
|
|
|
|
|
if (ppDS == NULL) {
|
|
|
|
WARN("invalid parameter: ppDS == NULL\n");
|
2004-07-04 02:13:44 +02:00
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if (pUnkOuter != NULL) {
|
|
|
|
WARN("invalid parameter: pUnkOuter != NULL\n");
|
|
|
|
*ppDS = 0;
|
2004-07-04 02:13:44 +02:00
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
hr = DSOUND_Create(&IID_IDirectSound, (void **)&pDS);
|
|
|
|
if (hr == DS_OK) {
|
|
|
|
hr = IDirectSound_Initialize(pDS, lpcGUID);
|
|
|
|
if (hr != DS_OK) {
|
|
|
|
if (hr != DSERR_ALREADYINITIALIZED) {
|
|
|
|
IDirectSound_Release(pDS);
|
|
|
|
pDS = 0;
|
|
|
|
} else
|
|
|
|
hr = DS_OK;
|
|
|
|
}
|
2004-07-04 02:13:44 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
*ppDS = pDS;
|
2004-07-04 02:13:44 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
return hr;
|
2004-07-04 02:13:44 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
/*******************************************************************************
|
|
|
|
* DirectSoundCreate8 (DSOUND.11)
|
|
|
|
*
|
|
|
|
* Creates and initializes a DirectSound8 interface.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpcGUID [I] Address of the GUID that identifies the sound device.
|
|
|
|
* ppDS [O] Address of a variable to receive the interface pointer.
|
|
|
|
* pUnkOuter [I] Must be NULL.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: DS_OK
|
|
|
|
* Failure: DSERR_ALLOCATED, DSERR_INVALIDPARAM, DSERR_NOAGGREGATION,
|
|
|
|
* DSERR_NODRIVER, DSERR_OUTOFMEMORY
|
2004-09-07 21:32:21 +02:00
|
|
|
*/
|
2015-01-20 03:28:02 +01:00
|
|
|
HRESULT WINAPI DirectSoundCreate8(
|
|
|
|
LPCGUID lpcGUID,
|
|
|
|
LPDIRECTSOUND8 *ppDS,
|
|
|
|
IUnknown *pUnkOuter)
|
2004-09-07 21:32:21 +02:00
|
|
|
{
|
2015-01-20 03:28:02 +01:00
|
|
|
HRESULT hr;
|
|
|
|
LPDIRECTSOUND8 pDS;
|
2004-09-07 21:32:21 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
TRACE("(%s,%p,%p)\n",debugstr_guid(lpcGUID),ppDS,pUnkOuter);
|
2004-09-07 21:32:21 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if (ppDS == NULL) {
|
|
|
|
WARN("invalid parameter: ppDS == NULL\n");
|
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
2004-09-07 21:32:21 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
if (pUnkOuter != NULL) {
|
|
|
|
WARN("invalid parameter: pUnkOuter != NULL\n");
|
|
|
|
*ppDS = 0;
|
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
2004-09-07 21:32:21 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
hr = DSOUND_Create8(&IID_IDirectSound8, (void **)&pDS);
|
|
|
|
if (hr == DS_OK) {
|
|
|
|
hr = IDirectSound8_Initialize(pDS, lpcGUID);
|
|
|
|
if (hr != DS_OK) {
|
|
|
|
if (hr != DSERR_ALREADYINITIALIZED) {
|
|
|
|
IDirectSound8_Release(pDS);
|
|
|
|
pDS = 0;
|
|
|
|
} else
|
|
|
|
hr = DS_OK;
|
|
|
|
}
|
2004-09-07 21:32:21 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
*ppDS = pDS;
|
2004-09-07 21:32:21 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
void DSOUND_ParseSpeakerConfig(DirectSoundDevice *device)
|
2004-09-07 21:32:21 +02:00
|
|
|
{
|
2015-01-20 03:28:02 +01:00
|
|
|
switch (DSSPEAKER_CONFIG(device->speaker_config)) {
|
|
|
|
case DSSPEAKER_MONO:
|
|
|
|
device->speaker_angles[0] = M_PI/180.0f * 0.0f;
|
|
|
|
device->speaker_num[0] = 0;
|
|
|
|
device->num_speakers = 1;
|
|
|
|
device->lfe_channel = -1;
|
|
|
|
break;
|
2004-09-07 21:32:21 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
case DSSPEAKER_STEREO:
|
|
|
|
case DSSPEAKER_HEADPHONE:
|
|
|
|
device->speaker_angles[0] = M_PI/180.0f * -90.0f;
|
|
|
|
device->speaker_angles[1] = M_PI/180.0f * 90.0f;
|
|
|
|
device->speaker_num[0] = 0; /* Left */
|
|
|
|
device->speaker_num[1] = 1; /* Right */
|
|
|
|
device->num_speakers = 2;
|
|
|
|
device->lfe_channel = -1;
|
|
|
|
break;
|
2004-09-07 21:32:21 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
case DSSPEAKER_QUAD:
|
|
|
|
device->speaker_angles[0] = M_PI/180.0f * -135.0f;
|
|
|
|
device->speaker_angles[1] = M_PI/180.0f * -45.0f;
|
|
|
|
device->speaker_angles[2] = M_PI/180.0f * 45.0f;
|
|
|
|
device->speaker_angles[3] = M_PI/180.0f * 135.0f;
|
|
|
|
device->speaker_num[0] = 2; /* Rear left */
|
|
|
|
device->speaker_num[1] = 0; /* Front left */
|
|
|
|
device->speaker_num[2] = 1; /* Front right */
|
|
|
|
device->speaker_num[3] = 3; /* Rear right */
|
|
|
|
device->num_speakers = 4;
|
|
|
|
device->lfe_channel = -1;
|
|
|
|
break;
|
2004-09-07 21:32:21 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
case DSSPEAKER_5POINT1_BACK:
|
|
|
|
device->speaker_angles[0] = M_PI/180.0f * -135.0f;
|
|
|
|
device->speaker_angles[1] = M_PI/180.0f * -45.0f;
|
|
|
|
device->speaker_angles[2] = M_PI/180.0f * 0.0f;
|
|
|
|
device->speaker_angles[3] = M_PI/180.0f * 45.0f;
|
|
|
|
device->speaker_angles[4] = M_PI/180.0f * 135.0f;
|
|
|
|
device->speaker_angles[5] = 9999.0f;
|
|
|
|
device->speaker_num[0] = 4; /* Rear left */
|
|
|
|
device->speaker_num[1] = 0; /* Front left */
|
|
|
|
device->speaker_num[2] = 2; /* Front centre */
|
|
|
|
device->speaker_num[3] = 1; /* Front right */
|
|
|
|
device->speaker_num[4] = 5; /* Rear right */
|
|
|
|
device->speaker_num[5] = 3; /* LFE */
|
|
|
|
device->num_speakers = 6;
|
|
|
|
device->lfe_channel = 3;
|
|
|
|
break;
|
2004-09-07 21:32:21 +02:00
|
|
|
|
2015-01-20 03:28:02 +01:00
|
|
|
case DSSPEAKER_5POINT1_SURROUND:
|
|
|
|
device->speaker_angles[0] = M_PI/180.0f * -90.0f;
|
|
|
|
device->speaker_angles[1] = M_PI/180.0f * -30.0f;
|
|
|
|
device->speaker_angles[2] = M_PI/180.0f * 0.0f;
|
|
|
|
device->speaker_angles[3] = M_PI/180.0f * 30.0f;
|
|
|
|
device->speaker_angles[4] = M_PI/180.0f * 90.0f;
|
|
|
|
device->speaker_angles[5] = 9999.0f;
|
|
|
|
device->speaker_num[0] = 4; /* Rear left */
|
|
|
|
device->speaker_num[1] = 0; /* Front left */
|
|
|
|
device->speaker_num[2] = 2; /* Front centre */
|
|
|
|
device->speaker_num[3] = 1; /* Front right */
|
|
|
|
device->speaker_num[4] = 5; /* Rear right */
|
|
|
|
device->speaker_num[5] = 3; /* LFE */
|
|
|
|
device->num_speakers = 6;
|
|
|
|
device->lfe_channel = 3;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
WARN("unknown speaker_config %u\n", device->speaker_config);
|
|
|
|
}
|
2004-09-07 21:32:21 +02:00
|
|
|
}
|