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);
|
|
|
|
|
2012-05-14 19:31:13 +02:00
|
|
|
static DWORD DSOUND_fraglen(DirectSoundDevice *device)
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
2012-05-14 19:31:13 +02:00
|
|
|
REFERENCE_TIME period;
|
|
|
|
HRESULT hr;
|
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
hr = IAudioClient_GetDevicePeriod(device->client, &period, NULL);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
/* just guess at 10ms */
|
|
|
|
WARN("GetDevicePeriod failed: %08x\n", hr);
|
|
|
|
ret = MulDiv(device->pwfx->nBlockAlign, device->pwfx->nSamplesPerSec, 100);
|
|
|
|
}else
|
|
|
|
ret = MulDiv(device->pwfx->nSamplesPerSec * device->pwfx->nBlockAlign, period, 10000000);
|
|
|
|
|
|
|
|
ret -= ret % device->pwfx->nBlockAlign;
|
|
|
|
return ret;
|
2007-09-29 01:54:03 +02:00
|
|
|
}
|
|
|
|
|
2015-01-06 20:26:47 +01:00
|
|
|
static DWORD speaker_config_to_channel_mask(DWORD speaker_config)
|
|
|
|
{
|
|
|
|
switch (DSSPEAKER_CONFIG(speaker_config)) {
|
|
|
|
case DSSPEAKER_MONO:
|
|
|
|
return SPEAKER_FRONT_LEFT;
|
|
|
|
|
|
|
|
case DSSPEAKER_STEREO:
|
|
|
|
case DSSPEAKER_HEADPHONE:
|
|
|
|
return SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT;
|
2015-01-06 20:27:10 +01:00
|
|
|
|
|
|
|
case DSSPEAKER_QUAD:
|
|
|
|
return SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT;
|
2015-01-06 20:27:21 +01:00
|
|
|
|
|
|
|
case DSSPEAKER_5POINT1_BACK:
|
|
|
|
return SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT;
|
2015-01-06 20:26:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
WARN("unknown speaker_config %u\n", speaker_config);
|
|
|
|
return SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT;
|
|
|
|
}
|
|
|
|
|
2015-01-20 03:25:49 +01:00
|
|
|
static DWORD DSOUND_FindSpeakerConfig(IMMDevice *mmdevice, int channels)
|
|
|
|
{
|
|
|
|
IPropertyStore *store;
|
|
|
|
HRESULT hr;
|
|
|
|
PROPVARIANT pv;
|
|
|
|
ULONG phys_speakers;
|
|
|
|
|
|
|
|
const DWORD def = DSSPEAKER_COMBINED(DSSPEAKER_STEREO, DSSPEAKER_GEOMETRY_WIDE);
|
|
|
|
|
|
|
|
hr = IMMDevice_OpenPropertyStore(mmdevice, STGM_READ, &store);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
WARN("IMMDevice_OpenPropertyStore failed: %08x\n", hr);
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IPropertyStore_GetValue(store, &PKEY_AudioEndpoint_PhysicalSpeakers, &pv);
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
WARN("IPropertyStore_GetValue failed: %08x\n", hr);
|
|
|
|
IPropertyStore_Release(store);
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pv.vt != VT_UI4) {
|
|
|
|
WARN("PKEY_AudioEndpoint_PhysicalSpeakers is not a ULONG: 0x%x\n", pv.vt);
|
|
|
|
PropVariantClear(&pv);
|
|
|
|
IPropertyStore_Release(store);
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
|
|
|
phys_speakers = pv.u.ulVal;
|
|
|
|
|
|
|
|
PropVariantClear(&pv);
|
|
|
|
IPropertyStore_Release(store);
|
|
|
|
|
|
|
|
if ((channels >= 6 || channels == 0) && (phys_speakers & KSAUDIO_SPEAKER_5POINT1) == KSAUDIO_SPEAKER_5POINT1)
|
|
|
|
return DSSPEAKER_5POINT1_BACK;
|
|
|
|
else if ((channels >= 6 || channels == 0) && (phys_speakers & KSAUDIO_SPEAKER_5POINT1_SURROUND) == KSAUDIO_SPEAKER_5POINT1_SURROUND)
|
|
|
|
return DSSPEAKER_5POINT1_SURROUND;
|
|
|
|
else if ((channels >= 4 || channels == 0) && (phys_speakers & KSAUDIO_SPEAKER_QUAD) == KSAUDIO_SPEAKER_QUAD)
|
|
|
|
return DSSPEAKER_QUAD;
|
|
|
|
else if ((channels >= 2 || channels == 0) && (phys_speakers & KSAUDIO_SPEAKER_STEREO) == KSAUDIO_SPEAKER_STEREO)
|
|
|
|
return DSSPEAKER_COMBINED(DSSPEAKER_STEREO, DSSPEAKER_GEOMETRY_WIDE);
|
|
|
|
else if ((phys_speakers & KSAUDIO_SPEAKER_MONO) == KSAUDIO_SPEAKER_MONO)
|
|
|
|
return DSSPEAKER_MONO;
|
|
|
|
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
2012-11-16 20:35:51 +01:00
|
|
|
static HRESULT DSOUND_WaveFormat(DirectSoundDevice *device, IAudioClient *client,
|
|
|
|
BOOL forcewave, WAVEFORMATEX **wfx)
|
|
|
|
{
|
|
|
|
WAVEFORMATEXTENSIBLE *retwfe = NULL;
|
|
|
|
WAVEFORMATEX *w;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (!forcewave) {
|
|
|
|
WAVEFORMATEXTENSIBLE *mixwfe;
|
|
|
|
hr = IAudioClient_GetMixFormat(client, (WAVEFORMATEX**)&mixwfe);
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
2015-01-11 18:40:52 +01:00
|
|
|
if (mixwfe->Format.nChannels < device->num_speakers) {
|
|
|
|
device->speaker_config = DSOUND_FindSpeakerConfig(device->mmdevice, mixwfe->Format.nChannels);
|
|
|
|
DSOUND_ParseSpeakerConfig(device);
|
|
|
|
} else if (mixwfe->Format.nChannels > device->num_speakers) {
|
2015-01-06 20:26:47 +01:00
|
|
|
mixwfe->Format.nChannels = device->num_speakers;
|
2012-11-16 20:35:51 +01:00
|
|
|
mixwfe->Format.nBlockAlign = mixwfe->Format.nChannels * mixwfe->Format.wBitsPerSample / 8;
|
|
|
|
mixwfe->Format.nAvgBytesPerSec = mixwfe->Format.nSamplesPerSec * mixwfe->Format.nBlockAlign;
|
2015-01-06 20:26:47 +01:00
|
|
|
mixwfe->dwChannelMask = speaker_config_to_channel_mask(device->speaker_config);
|
2012-11-16 20:35:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!IsEqualGUID(&mixwfe->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)) {
|
|
|
|
WAVEFORMATEXTENSIBLE testwfe = *mixwfe;
|
|
|
|
|
|
|
|
testwfe.SubFormat = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
|
2012-12-14 15:47:16 +01:00
|
|
|
testwfe.Samples.wValidBitsPerSample = testwfe.Format.wBitsPerSample = 32;
|
2012-11-16 20:35:51 +01:00
|
|
|
testwfe.Format.nBlockAlign = testwfe.Format.nChannels * testwfe.Format.wBitsPerSample / 8;
|
|
|
|
testwfe.Format.nAvgBytesPerSec = testwfe.Format.nSamplesPerSec * testwfe.Format.nBlockAlign;
|
|
|
|
|
|
|
|
if (FAILED(IAudioClient_IsFormatSupported(client, AUDCLNT_SHAREMODE_SHARED, &testwfe.Format, (WAVEFORMATEX**)&retwfe)))
|
|
|
|
w = DSOUND_CopyFormat(&mixwfe->Format);
|
|
|
|
else if (retwfe)
|
|
|
|
w = DSOUND_CopyFormat(&retwfe->Format);
|
|
|
|
else
|
|
|
|
w = DSOUND_CopyFormat(&testwfe.Format);
|
|
|
|
CoTaskMemFree(retwfe);
|
|
|
|
retwfe = NULL;
|
|
|
|
} else
|
|
|
|
w = DSOUND_CopyFormat(&mixwfe->Format);
|
|
|
|
CoTaskMemFree(mixwfe);
|
|
|
|
} else if (device->primary_pwfx->wFormatTag == WAVE_FORMAT_PCM ||
|
|
|
|
device->primary_pwfx->wFormatTag == WAVE_FORMAT_IEEE_FLOAT) {
|
|
|
|
WAVEFORMATEX *wi = device->primary_pwfx;
|
|
|
|
WAVEFORMATEXTENSIBLE *wfe;
|
|
|
|
|
|
|
|
/* Convert to WAVEFORMATEXTENSIBLE */
|
|
|
|
w = HeapAlloc(GetProcessHeap(), 0, sizeof(WAVEFORMATEXTENSIBLE));
|
|
|
|
wfe = (WAVEFORMATEXTENSIBLE*)w;
|
|
|
|
if (!wfe)
|
|
|
|
return DSERR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
wfe->Format = *wi;
|
|
|
|
w->wFormatTag = WAVE_FORMAT_EXTENSIBLE;
|
|
|
|
w->cbSize = sizeof(*wfe) - sizeof(*w);
|
|
|
|
w->nBlockAlign = w->nChannels * w->wBitsPerSample / 8;
|
|
|
|
w->nAvgBytesPerSec = w->nSamplesPerSec * w->nBlockAlign;
|
|
|
|
|
|
|
|
wfe->dwChannelMask = 0;
|
|
|
|
if (wi->wFormatTag == WAVE_FORMAT_IEEE_FLOAT) {
|
|
|
|
w->wBitsPerSample = 32;
|
|
|
|
wfe->SubFormat = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
|
|
|
|
} else
|
|
|
|
wfe->SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
|
2012-12-14 15:47:16 +01:00
|
|
|
wfe->Samples.wValidBitsPerSample = w->wBitsPerSample;
|
2012-11-16 20:35:51 +01:00
|
|
|
} else
|
|
|
|
w = DSOUND_CopyFormat(device->primary_pwfx);
|
|
|
|
|
|
|
|
if (!w)
|
|
|
|
return DSERR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
hr = IAudioClient_IsFormatSupported(client, AUDCLNT_SHAREMODE_SHARED, w, (WAVEFORMATEX**)&retwfe);
|
|
|
|
if (retwfe) {
|
|
|
|
memcpy(w, retwfe, sizeof(WAVEFORMATEX) + retwfe->Format.cbSize);
|
|
|
|
CoTaskMemFree(retwfe);
|
|
|
|
}
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
WARN("IsFormatSupported failed: %08x\n", hr);
|
|
|
|
HeapFree(GetProcessHeap(), 0, w);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
*wfx = w;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2007-08-27 17:07:14 +02:00
|
|
|
HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave)
|
|
|
|
{
|
2011-10-12 22:10:04 +02:00
|
|
|
UINT prebuf_frames;
|
|
|
|
REFERENCE_TIME prebuf_rt;
|
2012-11-16 20:35:51 +01:00
|
|
|
WAVEFORMATEX *wfx = NULL;
|
2011-09-27 15:51:07 +02:00
|
|
|
HRESULT hres;
|
2012-12-19 10:30:04 +01:00
|
|
|
REFERENCE_TIME period;
|
|
|
|
DWORD period_ms;
|
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);
|
2012-11-16 20:35:51 +01:00
|
|
|
if(FAILED(hres)) {
|
2011-09-27 15:51:07 +02:00
|
|
|
WARN("Activate failed: %08x\n", hres);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2015-01-11 18:40:52 +01:00
|
|
|
device->speaker_config = DSOUND_FindSpeakerConfig(device->mmdevice, 0);
|
2014-12-31 21:49:21 +01:00
|
|
|
|
2015-01-06 20:26:47 +01:00
|
|
|
DSOUND_ParseSpeakerConfig(device);
|
|
|
|
|
2012-11-16 20:35:51 +01:00
|
|
|
hres = DSOUND_WaveFormat(device, device->client, forcewave, &wfx);
|
|
|
|
if (FAILED(hres)) {
|
|
|
|
IAudioClient_Release(device->client);
|
|
|
|
device->client = NULL;
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, device->pwfx);
|
|
|
|
device->pwfx = wfx;
|
|
|
|
|
2012-05-14 19:31:13 +02:00
|
|
|
prebuf_frames = device->prebuf * DSOUND_fraglen(device) / device->pwfx->nBlockAlign;
|
2011-10-17 21:52:03 +02:00
|
|
|
prebuf_rt = (10000000 * (UINT64)prebuf_frames) / device->pwfx->nSamplesPerSec;
|
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
hres = IAudioClient_Initialize(device->client,
|
2012-12-19 10:30:04 +01:00
|
|
|
AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_NOPERSIST |
|
|
|
|
AUDCLNT_STREAMFLAGS_EVENTCALLBACK, prebuf_rt, 0, device->pwfx, NULL);
|
2011-09-27 15:51:07 +02:00
|
|
|
if(FAILED(hres)){
|
|
|
|
IAudioClient_Release(device->client);
|
|
|
|
device->client = NULL;
|
|
|
|
WARN("Initialize failed: %08x\n", hres);
|
|
|
|
return hres;
|
|
|
|
}
|
2012-12-19 10:30:04 +01:00
|
|
|
IAudioClient_SetEventHandle(device->client, device->sleepev);
|
2011-09-27 15:51:07 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2012-12-19 10:30:04 +01:00
|
|
|
/* Now kick off the timer so the event fires periodically */
|
|
|
|
hres = IAudioClient_Start(device->client);
|
|
|
|
if (FAILED(hres))
|
|
|
|
WARN("starting failed with %08x\n", hres);
|
|
|
|
|
|
|
|
hres = IAudioClient_GetStreamLatency(device->client, &period);
|
|
|
|
if (FAILED(hres)) {
|
|
|
|
WARN("GetStreamLatency failed with %08x\n", hres);
|
|
|
|
period_ms = 10;
|
|
|
|
} else
|
|
|
|
period_ms = (period + 9999) / 10000;
|
|
|
|
TRACE("period %u ms fraglen %u prebuf %u\n", period_ms, device->fraglen, device->prebuf);
|
|
|
|
|
|
|
|
if (period_ms < 3)
|
|
|
|
device->sleeptime = 5;
|
|
|
|
else
|
|
|
|
device->sleeptime = period_ms * 5 / 2;
|
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
return S_OK;
|
2007-08-27 17:07:14 +02:00
|
|
|
}
|
|
|
|
|
2012-11-16 20:35:51 +01:00
|
|
|
HRESULT DSOUND_PrimaryOpen(DirectSoundDevice *device)
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
2012-11-16 20:35:51 +01:00
|
|
|
IDirectSoundBufferImpl** dsb = device->buffers;
|
2011-09-27 15:51:07 +02:00
|
|
|
LPBYTE newbuf;
|
2013-01-15 23:27:02 +01:00
|
|
|
int i;
|
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
|
|
|
|
2012-05-14 19:31:17 +02:00
|
|
|
device->fraglen = DSOUND_fraglen(device);
|
|
|
|
|
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;
|
2012-05-14 19:31:17 +02:00
|
|
|
device->buflen -= device->buflen % device->pwfx->nBlockAlign;
|
|
|
|
while(device->buflen < device->fraglen * device->prebuf){
|
|
|
|
device->buflen += ds_hel_buflen;
|
|
|
|
device->buflen -= device->buflen % device->pwfx->nBlockAlign;
|
|
|
|
}
|
|
|
|
|
2012-11-16 20:35:51 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, device->mix_buffer);
|
|
|
|
device->mix_buffer_len = (device->buflen / (device->pwfx->wBitsPerSample / 8)) * sizeof(float);
|
2012-05-14 22:20:02 +02:00
|
|
|
device->mix_buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, device->mix_buffer_len);
|
2007-11-07 20:32:22 +01:00
|
|
|
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
|
|
|
/* reallocate emulated primary buffer */
|
|
|
|
if (device->buffer)
|
2012-05-14 19:31:17 +02:00
|
|
|
newbuf = HeapReAlloc(GetProcessHeap(),0,device->buffer, device->buflen);
|
2011-09-24 16:02:52 +02:00
|
|
|
else
|
2012-05-14 19:31:17 +02:00
|
|
|
newbuf = HeapAlloc(GetProcessHeap(),0, device->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
|
|
|
|
2012-05-14 19:31:17 +02:00
|
|
|
device->writelead = (device->pwfx->nSamplesPerSec / 100) * device->pwfx->nBlockAlign;
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2011-09-24 16:02:52 +02:00
|
|
|
device->buffer = newbuf;
|
|
|
|
|
2012-11-16 20:35:51 +01:00
|
|
|
TRACE("buflen: %u, fraglen: %u, mix_buffer_len: %u\n",
|
|
|
|
device->buflen, device->fraglen, device->mix_buffer_len);
|
2004-08-18 02:30:37 +02:00
|
|
|
|
2012-05-14 22:19:46 +02:00
|
|
|
if(device->pwfx->wFormatTag == WAVE_FORMAT_IEEE_FLOAT ||
|
|
|
|
(device->pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
|
|
|
|
IsEqualGUID(&((WAVEFORMATEXTENSIBLE*)device->pwfx)->SubFormat,
|
2012-05-15 15:29:34 +02:00
|
|
|
&KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)))
|
2012-05-14 22:19:46 +02:00
|
|
|
device->normfunction = normfunctions[4];
|
2012-05-15 15:29:34 +02:00
|
|
|
else
|
2012-05-14 22:19:46 +02:00
|
|
|
device->normfunction = normfunctions[device->pwfx->wBitsPerSample/8 - 1];
|
|
|
|
|
2012-12-15 15:43:30 +01:00
|
|
|
FillMemory(device->buffer, device->buflen, (device->pwfx->wBitsPerSample == 8) ? 128 : 0);
|
|
|
|
FillMemory(device->mix_buffer, device->mix_buffer_len, 0);
|
|
|
|
device->playpos = 0;
|
2012-11-16 20:35:51 +01:00
|
|
|
|
|
|
|
if (device->pwfx->wFormatTag == WAVE_FORMAT_IEEE_FLOAT ||
|
|
|
|
(device->pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
|
|
|
|
IsEqualGUID(&((WAVEFORMATEXTENSIBLE*)device->pwfx)->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)))
|
|
|
|
device->normfunction = normfunctions[4];
|
|
|
|
else
|
|
|
|
device->normfunction = normfunctions[device->pwfx->wBitsPerSample/8 - 1];
|
|
|
|
|
|
|
|
for (i = 0; i < device->nrofbuffers; i++) {
|
|
|
|
RtlAcquireResourceExclusive(&dsb[i]->lock, TRUE);
|
|
|
|
DSOUND_RecalcFormat(dsb[i]);
|
|
|
|
RtlReleaseResource(&dsb[i]->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
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-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 */
|
2012-05-14 19:31:10 +02:00
|
|
|
device->in_mmdev_bytes = 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);
|
2012-05-09 15:48:56 +02:00
|
|
|
|
|
|
|
if(device->primary && (device->primary->ref || device->primary->numIfaces))
|
|
|
|
WARN("Destroying primary buffer while references held (%u %u)\n", device->primary->ref, device->primary->numIfaces);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, device->primary);
|
|
|
|
device->primary = NULL;
|
|
|
|
|
2012-11-16 20:35:51 +01:00
|
|
|
HeapFree(GetProcessHeap(),0,device->primary_pwfx);
|
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);
|
2012-12-19 10:30:04 +01:00
|
|
|
if(FAILED(hr) && hr != AUDCLNT_E_NOT_STOPPED){
|
2011-09-27 15:51:07 +02:00
|
|
|
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
|
|
|
/* check if playpos was requested */
|
|
|
|
if (playpos)
|
2012-05-14 19:31:10 +02:00
|
|
|
*playpos = device->playing_offs_bytes;
|
2011-09-24 16:02:52 +02:00
|
|
|
|
|
|
|
/* check if writepos was requested */
|
|
|
|
if (writepos)
|
|
|
|
/* the writepos is the first non-queued position */
|
2012-05-14 19:31:10 +02:00
|
|
|
*writepos = (device->playing_offs_bytes + device->in_mmdev_bytes) % device->buflen;
|
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;
|
|
|
|
}
|
|
|
|
|
2013-05-28 21:05:47 +02:00
|
|
|
WAVEFORMATEX *DSOUND_CopyFormat(const WAVEFORMATEX *wfex)
|
2010-10-03 17:52:00 +02:00
|
|
|
{
|
2013-05-28 21:05:47 +02:00
|
|
|
WAVEFORMATEX *pwfx;
|
|
|
|
if(wfex->wFormatTag == WAVE_FORMAT_PCM){
|
|
|
|
pwfx = HeapAlloc(GetProcessHeap(), 0, sizeof(WAVEFORMATEX));
|
|
|
|
CopyMemory(pwfx, wfex, sizeof(PCMWAVEFORMAT));
|
|
|
|
pwfx->cbSize = 0;
|
|
|
|
}else{
|
|
|
|
pwfx = HeapAlloc(GetProcessHeap(), 0, sizeof(WAVEFORMATEX) + wfex->cbSize);
|
|
|
|
CopyMemory(pwfx, wfex, sizeof(WAVEFORMATEX) + wfex->cbSize);
|
|
|
|
}
|
2010-10-03 17:52:00 +02:00
|
|
|
|
2013-05-28 21:05:47 +02:00
|
|
|
if(pwfx->wFormatTag == WAVE_FORMAT_PCM ||
|
|
|
|
(pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
|
|
|
|
IsEqualGUID(&((const WAVEFORMATEXTENSIBLE*)pwfx)->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM)))
|
|
|
|
pwfx->nBlockAlign = (pwfx->nChannels * pwfx->wBitsPerSample) / 8;
|
|
|
|
|
|
|
|
return pwfx;
|
2009-10-04 08:05:20 +02:00
|
|
|
}
|
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
HRESULT primarybuffer_SetFormat(DirectSoundDevice *device, LPCWAVEFORMATEX passed_fmt)
|
2006-01-14 17:06:22 +01:00
|
|
|
{
|
2012-11-16 20:35:51 +01:00
|
|
|
HRESULT err = S_OK;
|
2011-09-27 15:51:07 +02:00
|
|
|
WAVEFORMATEX *old_fmt;
|
2012-04-02 16:41:06 +02:00
|
|
|
WAVEFORMATEXTENSIBLE *fmtex, *passed_fmtex = (WAVEFORMATEXTENSIBLE*)passed_fmt;
|
2011-09-27 15:51:07 +02:00
|
|
|
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
|
|
|
|
2011-12-02 18:53:14 +01:00
|
|
|
if(passed_fmt->wBitsPerSample < 8 || passed_fmt->wBitsPerSample % 8 != 0 ||
|
|
|
|
passed_fmt->nChannels == 0 || passed_fmt->nSamplesPerSec == 0 ||
|
|
|
|
passed_fmt->nAvgBytesPerSec == 0 ||
|
|
|
|
passed_fmt->nBlockAlign != passed_fmt->nChannels * passed_fmt->wBitsPerSample / 8)
|
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
|
2012-04-02 16:41:06 +02:00
|
|
|
if(passed_fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE){
|
|
|
|
if(passed_fmtex->Samples.wValidBitsPerSample > passed_fmtex->Format.wBitsPerSample)
|
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2012-11-16 20:35:51 +01:00
|
|
|
if (device->priolevel == DSSCL_WRITEPRIMARY) {
|
|
|
|
old_fmt = device->primary_pwfx;
|
|
|
|
device->primary_pwfx = DSOUND_CopyFormat(passed_fmt);
|
|
|
|
fmtex = (WAVEFORMATEXTENSIBLE *)device->primary_pwfx;
|
|
|
|
if (device->primary_pwfx == NULL) {
|
|
|
|
err = DSERR_OUTOFMEMORY;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2012-11-16 20:35:51 +01:00
|
|
|
if (fmtex->Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
|
|
|
|
fmtex->Samples.wValidBitsPerSample == 0) {
|
2012-04-02 16:41:06 +02:00
|
|
|
TRACE("Correcting 0 valid bits per sample\n");
|
|
|
|
fmtex->Samples.wValidBitsPerSample = fmtex->Format.wBitsPerSample;
|
|
|
|
}
|
2011-09-27 15:51:07 +02:00
|
|
|
|
2007-08-21 21:04:32 +02:00
|
|
|
DSOUND_PrimaryClose(device);
|
2012-05-15 15:29:34 +02:00
|
|
|
|
2012-11-16 20:35:51 +01:00
|
|
|
err = DSOUND_ReopenDevice(device, forced);
|
|
|
|
if (FAILED(err)) {
|
|
|
|
ERR("No formats could be opened\n");
|
|
|
|
goto done;
|
|
|
|
}
|
2004-02-06 06:20:28 +01:00
|
|
|
|
2012-11-16 20:35:51 +01:00
|
|
|
err = DSOUND_PrimaryOpen(device);
|
|
|
|
if (err != DS_OK) {
|
|
|
|
ERR("DSOUND_PrimaryOpen failed\n");
|
|
|
|
goto done;
|
|
|
|
}
|
2004-02-06 06:20:28 +01:00
|
|
|
|
2012-11-16 20:35:51 +01:00
|
|
|
done:
|
|
|
|
if (err != DS_OK)
|
|
|
|
device->primary_pwfx = old_fmt;
|
|
|
|
else
|
|
|
|
HeapFree(GetProcessHeap(), 0, old_fmt);
|
|
|
|
} else {
|
2013-05-28 21:05:47 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, device->primary_pwfx);
|
|
|
|
device->primary_pwfx = DSOUND_CopyFormat(passed_fmt);
|
2004-02-06 06:20:28 +01:00
|
|
|
}
|
|
|
|
|
2012-11-16 20:35:51 +01:00
|
|
|
out:
|
2005-05-31 11:31:37 +02:00
|
|
|
LeaveCriticalSection(&(device->mixlock));
|
|
|
|
RtlReleaseResource(&(device->buffer_list_lock));
|
2002-06-13 21:15:06 +02:00
|
|
|
/* **** */
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2006-01-14 17:06:22 +01:00
|
|
|
/*******************************************************************************
|
|
|
|
* PrimaryBuffer
|
|
|
|
*/
|
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);
|
|
|
|
}
|
|
|
|
|
2012-01-16 00:12:14 +01:00
|
|
|
/* This sets this format for the primary buffer only */
|
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_SetFormat(IDirectSoundBuffer *iface,
|
|
|
|
const WAVEFORMATEX *wfex)
|
2006-01-14 17:06:22 +01:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2012-01-16 00:12:14 +01:00
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_SetVolume(IDirectSoundBuffer *iface, LONG vol)
|
|
|
|
{
|
2011-09-27 15:51:07 +02:00
|
|
|
IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
|
|
|
|
DirectSoundDevice *device = This->device;
|
|
|
|
HRESULT hr;
|
2014-12-27 22:32:24 +01:00
|
|
|
float fvol;
|
|
|
|
int i;
|
2011-09-27 15:51:07 +02:00
|
|
|
|
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);
|
|
|
|
|
2014-12-27 22:32:24 +01:00
|
|
|
for (i = 0; i < DS_MAX_CHANNELS; i++) {
|
|
|
|
if (device->pwfx->nChannels > i){
|
|
|
|
hr = IAudioStreamVolume_GetChannelVolume(device->volume, i, &fvol);
|
|
|
|
if (FAILED(hr)){
|
|
|
|
LeaveCriticalSection(&device->mixlock);
|
|
|
|
WARN("GetChannelVolume failed: %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
fvol=1.0f;
|
2011-09-27 15:51:07 +02:00
|
|
|
|
2014-12-27 22:32:24 +01:00
|
|
|
device->volpan.dwTotalAmpFactor[i]=((UINT16)(fvol * (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);
|
|
|
|
|
2014-12-27 22:32:24 +01:00
|
|
|
for (i = 0; i < DS_MAX_CHANNELS; i++) {
|
|
|
|
if (device->pwfx->nChannels > i){
|
|
|
|
fvol = (float)((DWORD)(device->volpan.dwTotalAmpFactor[i] & 0xFFFF) / (float)0xFFFF);
|
|
|
|
hr = IAudioStreamVolume_SetChannelVolume(device->volume, i, fvol);
|
|
|
|
if (FAILED(hr)){
|
|
|
|
LeaveCriticalSection(&device->mixlock);
|
|
|
|
WARN("SetChannelVolume failed: %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
2011-09-27 15:51:07 +02:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2012-01-16 00:12:14 +01:00
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_GetVolume(IDirectSoundBuffer *iface, LONG *vol)
|
|
|
|
{
|
2011-09-27 15:51:07 +02:00
|
|
|
IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
|
|
|
|
DirectSoundDevice *device = This->device;
|
2014-12-27 22:32:24 +01:00
|
|
|
float fvol;
|
2011-09-27 15:51:07 +02:00
|
|
|
HRESULT hr;
|
2014-12-27 22:32:24 +01:00
|
|
|
int i;
|
|
|
|
|
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);
|
|
|
|
|
2014-12-27 22:32:24 +01:00
|
|
|
for (i = 0; i < DS_MAX_CHANNELS; i++) {
|
|
|
|
if (device->pwfx->nChannels > i){
|
|
|
|
hr = IAudioStreamVolume_GetChannelVolume(device->volume, i, &fvol);
|
|
|
|
if (FAILED(hr)){
|
|
|
|
LeaveCriticalSection(&device->mixlock);
|
|
|
|
WARN("GetChannelVolume failed: %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
fvol = 1;
|
2011-09-27 15:51:07 +02:00
|
|
|
|
2014-12-27 22:32:24 +01:00
|
|
|
device->volpan.dwTotalAmpFactor[i] = ((UINT16)(fvol * (DWORD)0xFFFF));
|
|
|
|
}
|
2011-09-27 15:51:07 +02:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-01-16 00:12:14 +01:00
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_SetFrequency(IDirectSoundBuffer *iface, DWORD freq)
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
2012-01-16 00:12:14 +01:00
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_Play(IDirectSoundBuffer *iface, DWORD reserved1,
|
|
|
|
DWORD reserved2, DWORD flags)
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
2012-01-16 00:12:14 +01:00
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_Stop(IDirectSoundBuffer *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;
|
|
|
|
}
|
|
|
|
|
2012-01-16 00:12:14 +01:00
|
|
|
static ULONG WINAPI PrimaryBufferImpl_AddRef(IDirectSoundBuffer *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
|
|
|
|
2012-05-09 15:48:56 +02:00
|
|
|
/* Decreases *out by 1 to no less than 0.
|
|
|
|
* Returns the new value of *out. */
|
|
|
|
LONG capped_refcount_dec(LONG *out)
|
2011-08-31 01:13:33 +02:00
|
|
|
{
|
2012-05-09 15:48:56 +02:00
|
|
|
LONG ref, oldref;
|
|
|
|
do {
|
|
|
|
ref = *out;
|
|
|
|
if(!ref)
|
|
|
|
return 0;
|
|
|
|
oldref = InterlockedCompareExchange(out, ref - 1, ref);
|
|
|
|
} while(oldref != ref);
|
|
|
|
return ref - 1;
|
2011-08-31 01:13:33 +02:00
|
|
|
}
|
|
|
|
|
2012-01-16 00:12:14 +01:00
|
|
|
static ULONG WINAPI PrimaryBufferImpl_Release(IDirectSoundBuffer *iface)
|
2005-02-11 12:49:05 +01:00
|
|
|
{
|
2011-08-31 01:11:29 +02:00
|
|
|
IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
|
2012-05-09 15:48:56 +02:00
|
|
|
ULONG ref;
|
|
|
|
|
|
|
|
ref = capped_refcount_dec(&This->ref);
|
|
|
|
if(!ref)
|
|
|
|
capped_refcount_dec(&This->numIfaces);
|
|
|
|
|
|
|
|
TRACE("(%p) primary ref is now %d\n", This, ref);
|
2005-02-11 12:49:05 +01:00
|
|
|
|
|
|
|
return ref;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
|
2012-01-16 00:12:14 +01:00
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_GetCurrentPosition(IDirectSoundBuffer *iface,
|
|
|
|
DWORD *playpos, DWORD *writepos)
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
2012-01-16 00:12:14 +01:00
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_GetStatus(IDirectSoundBuffer *iface, DWORD *status)
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-16 00:12:14 +01:00
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_GetFormat(IDirectSoundBuffer *iface, WAVEFORMATEX *lpwf,
|
|
|
|
DWORD wfsize, DWORD *wfwritten)
|
2004-08-18 02:30:37 +02:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2012-11-16 20:35:51 +01:00
|
|
|
size = sizeof(WAVEFORMATEX) + device->primary_pwfx->cbSize;
|
2004-08-18 02:30:37 +02:00
|
|
|
|
|
|
|
if (lpwf) { /* NULL is valid */
|
|
|
|
if (wfsize >= size) {
|
2012-11-16 20:35:51 +01:00
|
|
|
CopyMemory(lpwf,device->primary_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)
|
2012-11-16 20:35:51 +01:00
|
|
|
*wfwritten = sizeof(WAVEFORMATEX) + device->primary_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
|
|
|
}
|
|
|
|
|
2012-01-16 00:12:14 +01:00
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_Lock(IDirectSoundBuffer *iface, DWORD writecursor,
|
|
|
|
DWORD writebytes, void **lplpaudioptr1, DWORD *audiobytes1, void **lplpaudioptr2,
|
|
|
|
DWORD *audiobytes2, DWORD flags)
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
2012-01-16 00:12:14 +01:00
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_SetCurrentPosition(IDirectSoundBuffer *iface, DWORD newpos)
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
2012-01-16 00:12:14 +01:00
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_SetPan(IDirectSoundBuffer *iface, LONG pan)
|
|
|
|
{
|
2011-09-27 15:51:07 +02:00
|
|
|
IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
|
|
|
|
DirectSoundDevice *device = This->device;
|
2014-12-27 22:32:24 +01:00
|
|
|
float fvol;
|
2011-09-27 15:51:07 +02:00
|
|
|
HRESULT hr;
|
2014-12-27 22:32:24 +01:00
|
|
|
int i;
|
|
|
|
|
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);
|
|
|
|
|
2014-12-27 22:32:24 +01:00
|
|
|
for (i = 0; i < DS_MAX_CHANNELS; i++) {
|
|
|
|
if (device->pwfx->nChannels > i){
|
|
|
|
hr = IAudioStreamVolume_GetChannelVolume(device->volume, i, &fvol);
|
|
|
|
if (FAILED(hr)){
|
|
|
|
LeaveCriticalSection(&device->mixlock);
|
|
|
|
WARN("GetChannelVolume failed: %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
fvol = 1;
|
2011-09-27 15:51:07 +02:00
|
|
|
|
2014-12-27 22:32:24 +01:00
|
|
|
device->volpan.dwTotalAmpFactor[i] = ((UINT16)(fvol * (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
|
|
|
|
2014-12-27 22:32:24 +01:00
|
|
|
for (i = 0; i < DS_MAX_CHANNELS; i++) {
|
|
|
|
if (device->pwfx->nChannels > i) {
|
|
|
|
fvol = (float)((DWORD)(device->volpan.dwTotalAmpFactor[i] & 0xFFFF) / (float)0xFFFF);
|
|
|
|
hr = IAudioStreamVolume_SetChannelVolume(device->volume, i, fvol);
|
|
|
|
if (FAILED(hr)){
|
|
|
|
LeaveCriticalSection(&device->mixlock);
|
|
|
|
WARN("SetChannelVolume failed: %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
2011-09-27 15:51:07 +02:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2012-01-16 00:12:14 +01:00
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_GetPan(IDirectSoundBuffer *iface, LONG *pan)
|
|
|
|
{
|
2011-09-27 15:51:07 +02:00
|
|
|
IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
|
|
|
|
DirectSoundDevice *device = This->device;
|
2014-12-27 22:32:24 +01:00
|
|
|
float fvol;
|
2011-09-27 15:51:07 +02:00
|
|
|
HRESULT hr;
|
2014-12-27 22:32:24 +01:00
|
|
|
int i;
|
|
|
|
|
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);
|
|
|
|
|
2014-12-27 22:32:24 +01:00
|
|
|
for (i = 0; i < DS_MAX_CHANNELS; i++) {
|
|
|
|
if (device->pwfx->nChannels > i) {
|
|
|
|
hr = IAudioStreamVolume_GetChannelVolume(device->volume, i, &fvol);
|
|
|
|
if (FAILED(hr)){
|
|
|
|
LeaveCriticalSection(&device->mixlock);
|
|
|
|
WARN("GetChannelVolume failed: %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
fvol = 1;
|
2011-09-27 15:51:07 +02:00
|
|
|
|
2014-12-27 22:32:24 +01:00
|
|
|
device->volpan.dwTotalAmpFactor[i] = ((UINT16)(fvol * (DWORD)0xFFFF));
|
|
|
|
}
|
2011-09-27 15:51:07 +02:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-01-16 00:12:14 +01:00
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_Unlock(IDirectSoundBuffer *iface, void *p1, DWORD x1,
|
|
|
|
void *p2, DWORD x2)
|
|
|
|
{
|
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
|
|
|
|
2012-12-15 15:43:30 +01: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;
|
2011-09-24 16:03:06 +02:00
|
|
|
|
2002-06-13 21:15:06 +02:00
|
|
|
return DS_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-16 00:12:14 +01:00
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_Restore(IDirectSoundBuffer *iface)
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
2012-01-16 00:12:14 +01:00
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_GetFrequency(IDirectSoundBuffer *iface, DWORD *freq)
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
2012-01-16 00:12:14 +01:00
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_Initialize(IDirectSoundBuffer *iface, IDirectSound *dsound,
|
|
|
|
const DSBUFFERDESC *dbsd)
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
2012-01-16 00:12:14 +01:00
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_GetCaps(IDirectSoundBuffer *iface, DSBCAPS *caps)
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
2012-01-16 00:12:14 +01:00
|
|
|
static HRESULT WINAPI PrimaryBufferImpl_QueryInterface(IDirectSoundBuffer *iface, REFIID riid,
|
|
|
|
void **ppobj)
|
|
|
|
{
|
2011-08-31 01:11:29 +02:00
|
|
|
IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer(iface);
|
2012-01-16 00:13:31 +01:00
|
|
|
|
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) ) {
|
2012-01-16 00:12:14 +01:00
|
|
|
IDirectSoundBuffer_AddRef(iface);
|
|
|
|
*ppobj = iface;
|
2003-06-28 00:22:15 +02:00
|
|
|
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 ) ) {
|
2012-01-16 00:13:31 +01:00
|
|
|
*ppobj = &This->IDirectSound3DListener_iface;
|
|
|
|
IDirectSound3DListener_AddRef(&This->IDirectSound3DListener_iface);
|
|
|
|
return S_OK;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( IsEqualGUID( &IID_IKsPropertySet, riid ) ) {
|
2012-01-17 01:54:53 +01:00
|
|
|
*ppobj = &This->IKsPropertySet_iface;
|
|
|
|
IKsPropertySet_AddRef(&This->IKsPropertySet_iface);
|
|
|
|
return S_OK;
|
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;
|
|
|
|
}
|
|
|
|
|
2012-01-16 00:14:35 +01:00
|
|
|
dsb->ref = 0;
|
2012-01-16 00:13:31 +01:00
|
|
|
dsb->ref3D = 0;
|
2012-01-17 01:54:53 +01:00
|
|
|
dsb->refiks = 0;
|
2012-01-16 00:14:35 +01:00
|
|
|
dsb->numIfaces = 0;
|
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;
|
2012-01-16 00:13:31 +01:00
|
|
|
dsb->IDirectSound3DListener_iface.lpVtbl = &ds3dlvt;
|
2012-01-17 01:54:53 +01:00
|
|
|
dsb->IKsPropertySet_iface.lpVtbl = &iksbvt;
|
2011-08-31 01:15:36 +02:00
|
|
|
dsb->dsbd = *dsbd;
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2012-01-16 00:13:31 +01:00
|
|
|
/* IDirectSound3DListener */
|
|
|
|
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->ds3dl_need_recalc = TRUE;
|
|
|
|
|
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
|
|
|
|
2012-01-16 00:14:35 +01:00
|
|
|
IDirectSoundBuffer_AddRef(&dsb->IDirectSoundBuffer8_iface);
|
2006-01-06 12:35:20 +01:00
|
|
|
*ppdsb = dsb;
|
2002-06-13 21:15:06 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|