46 if (nSamplesPerSec <= 12800)
47 return 128 * nBlockAlign;
49 if (nSamplesPerSec <= 25600)
50 return 256 * nBlockAlign;
52 if (nSamplesPerSec <= 51200)
53 return 512 * nBlockAlign;
55 return 1024 * nBlockAlign;
99 device->drvdesc.dnDevNode = wod;
101 WARN(
"IDsDriver_GetDriverDesc failed: %08x\n",
hres);
120 WARN(
"waveOutOpen failed\n");
147 buflen -= buflen %
device->pwfx->nBlockAlign;
158 WARN(
"IDsDriver_CreateSoundBuffer failed (%08x), falling back to waveout\n",
err);
162 WARN(
"Falling back to waveout failed too! Giving up\n");
180 WARN(
"Falling back to waveout failed too! Giving up\n");
211 TRACE(
"desired buflen=%d, old buffer=%p\n", buflen,
device->buffer);
220 ERR(
"failed to allocate primary buffer\n");
232 ERR(
"failed to allocate wave headers\n");
260 overshot -= overshot %
device->pwfx->nBlockAlign;
261 device->pwave[
device->helfrags - 1].dwBufferLength += overshot;
264 TRACE(
"fraglen=%d, overshot=%d\n",
device->fraglen, overshot);
300 ERR(
"Still %d references on primary buffer, refcount leak?\n",
ref);
313 WARN(
"DSOUND_PrimaryOpen failed\n");
353 WARN(
"IDsDriverBuffer_Play failed\n");
357 WARN(
"waveOutRestart failed\n");
374 ERR(
"DSOUND_ReopenDevice failed\n");
379 WARN(
"DSOUND_PrimaryOpen failed\n");
382 WARN(
"IDsDriverBuffer_Stop failed\n");
396 WARN(
"waveOutPause failed\n");
409 WARN(
"IDsDriverBuffer_GetPosition failed\n");
425 TRACE(
"playpos = %d, writepos = %d (%p, time=%d)\n", playpos?*playpos:-1, writepos?*writepos:-1,
device,
GetTickCount());
442 WARN(
"out of memory\n");
471 WARN(
"failed priority check!\n");
477 WARN(
"invalid parameter: wfex==NULL!\n");
480 TRACE(
"(formattag=0x%04x,chans=%d,samplerate=%d,"
481 "bytespersec=%d,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
490 nSamplesPerSec =
device->pwfx->nSamplesPerSec;
492 chans =
device->pwfx->nChannels;
517 WARN(
"IDsDriverBuffer_SetFormat failed\n");
550 WARN(
"DSOUND_ReopenDevice failed: %08x\n",
err);
555 WARN(
"DSOUND_PrimaryOpen failed\n");
565 WARN(
"DSOUND_ReopenDevice(2) failed: %08x\n",
err);
567 WARN(
"DSOUND_PrimaryOpen(2) failed: %08x\n",
err);
577 if (nSamplesPerSec !=
device->pwfx->nSamplesPerSec ||
bpp !=
device->pwfx->wBitsPerSample || chans !=
device->pwfx->nChannels) {
579 for (
i = 0;
i <
device->nrofbuffers;
i++, dsb++) {
586 (*dsb)->primary_mixpos = 0;
618 TRACE(
"(%p,%p)\n", iface, wfex);
629 TRACE(
"(%p,%d)\n", iface, vol);
632 WARN(
"control unavailable\n");
637 WARN(
"invalid parameter: vol = %d\n", vol);
645 device->volpan.dwTotalLeftAmpFactor=ampfactors & 0xffff;
646 device->volpan.dwTotalRightAmpFactor=ampfactors >> 16;
648 if (vol !=
device->volpan.lVolume) {
649 device->volpan.lVolume=vol;
654 WARN(
"IDsDriverBuffer_SetVolumePan failed\n");
656 ampfactors = (
device->volpan.dwTotalLeftAmpFactor & 0xffff) | (
device->volpan.dwTotalRightAmpFactor << 16);
673 TRACE(
"(%p,%p)\n", iface, vol);
676 WARN(
"control unavailable\n");
681 WARN(
"invalid parameter: vol = NULL\n");
688 device->volpan.dwTotalLeftAmpFactor=ampfactors & 0xffff;
689 device->volpan.dwTotalRightAmpFactor=ampfactors >> 16;
692 *vol =
device->volpan.lVolume;
703 WARN(
"control unavailable\n");
715 WARN(
"invalid parameter: flags = %08x\n",
flags);
737 TRACE(
"(%p)\n", iface);
787 TRACE(
"(%p,%p,%p)\n", iface, playpos, writepos);
794 WARN(
"DSOUND_PrimaryGetPosition failed\n");
801 *writepos +=
device->writelead;
802 while (*writepos >=
device->buflen) *writepos -=
device->buflen;
808 TRACE(
"playpos = %d, writepos = %d (%p, time=%d)\n", playpos?*playpos:0, writepos?*writepos:0,
device,
GetTickCount());
820 WARN(
"invalid parameter: status == NULL\n");
843 TRACE(
"(%p,%p,%d,%p)\n", iface, lpwf, wfsize, wfwritten);
848 if (wfsize >=
size) {
853 WARN(
"invalid parameter: wfsize too small\n");
862 WARN(
"invalid parameter: wfwritten == NULL\n");
876 TRACE(
"(%p,%d,%d,%p,%p,%p,%p,0x%08x) at %d\n",
892 WARN(
"failed priority check!\n");
901 WARN(
"IDirectSoundBuffer_GetCurrentPosition failed\n");
908 writebytes =
device->buflen;
910 if (writecursor >=
device->buflen) {
911 WARN(
"Invalid parameter, writecursor: %u >= buflen: %u\n",
912 writecursor,
device->buflen);
916 if (writebytes >
device->buflen) {
917 WARN(
"Invalid parameter, writebytes: %u > buflen: %u\n",
918 writebytes,
device->buflen);
924 lplpaudioptr1, audiobytes1,
925 lplpaudioptr2, audiobytes2,
926 writecursor, writebytes,
929 WARN(
"IDsDriverBuffer_Lock failed\n");
933 if (writecursor+writebytes <= device->buflen) {
935 *audiobytes1 = writebytes;
940 TRACE(
"->%d.0\n",writebytes);
943 *audiobytes1 =
device->buflen-writecursor;
947 *audiobytes2 = writebytes-(
device->buflen-writecursor);
948 TRACE(
"->%d.%d\n",*audiobytes1,audiobytes2?*audiobytes2:0);
961 WARN(
"invalid call\n");
972 TRACE(
"(%p,%d)\n", iface, pan);
975 WARN(
"control unavailable\n");
980 WARN(
"invalid parameter: pan = %d\n", pan);
990 device->volpan.dwTotalLeftAmpFactor=ampfactors & 0xffff;
991 device->volpan.dwTotalRightAmpFactor=ampfactors >> 16;
994 if (pan !=
device->volpan.lPan) {
1000 WARN(
"IDsDriverBuffer_SetVolumePan failed\n");
1002 ampfactors = (
device->volpan.dwTotalLeftAmpFactor & 0xffff) | (
device->volpan.dwTotalRightAmpFactor << 16);
1019 TRACE(
"(%p,%p)\n", iface, pan);
1022 WARN(
"control unavailable\n");
1027 WARN(
"invalid parameter: pan == NULL\n");
1034 device->volpan.dwTotalLeftAmpFactor=ampfactors & 0xffff;
1035 device->volpan.dwTotalRightAmpFactor=ampfactors >> 16;
1038 *pan =
device->volpan.lPan;
1047 TRACE(
"(%p,%p,%d,%p,%d)\n", iface, p1,
x1, p2,
x2);
1050 WARN(
"failed priority check!\n");
1063 WARN(
"IDsDriverBuffer_Unlock failed\n");
1084 TRACE(
"(%p,%p)\n", iface, freq);
1087 WARN(
"invalid parameter: freq == NULL\n");
1092 WARN(
"control unavailable\n");
1096 *freq =
device->pwfx->nSamplesPerSec;
1097 TRACE(
"-> %d\n", *freq);
1106 WARN(
"(%p) already initialized\n",
This);
1115 TRACE(
"(%p,%p)\n", iface, caps);
1118 WARN(
"invalid parameter: caps == NULL\n");
1122 if (caps->
dwSize <
sizeof(*caps)) {
1123 WARN(
"invalid parameter: caps->dwSize = %d\n", caps->
dwSize);
1144 if (ppobj ==
NULL) {
1145 WARN(
"invalid parameter\n");
1161 WARN(
"app requested DirectSoundBuffer8 on primary buffer\n");
1166 ERR(
"app requested IDirectSoundNotify on primary buffer\n");
1172 ERR(
"app requested IDirectSound3DBuffer on primary buffer\n");
1180 *ppobj =
device->listener;
1185 WARN(
"IID_IDirectSound3DListener failed\n");
1190 FIXME(
"app requested IKsPropertySet on primary buffer\n");
1230 WARN(
"invalid parameter: dsbd->lpwfxFormat != NULL\n");
1238 WARN(
"out of memory\n");
1249 TRACE(
"Created primary buffer at %p\n", dsb);
1250 TRACE(
"(formattag=0x%04x,chans=%d,samplerate=%d,"
1251 "bytespersec=%d,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
1253 device->pwfx->nSamplesPerSec,
device->pwfx->nAvgBytesPerSec,
1254 device->pwfx->nBlockAlign,
device->pwfx->wBitsPerSample,
#define InterlockedIncrement
#define InterlockedDecrement
const GUID IID_IKsPropertySet
#define HeapFree(x, y, z)
DWORD WINAPI GetTickCount(VOID)
#define IDsDriverBuffer_Stop(p)
#define IDsDriverBuffer_SetFormat(p, a)
#define IDsDriver_CreateSoundBuffer(p, a, b, c, d, e, f)
#define IDsDriverBuffer_Play(p, a, b, c)
#define IDsDriver_Close(p)
#define IDsDriverBuffer_Unlock(p, a, b, c, d)
#define DSDDESC_DONTNEEDPRIMARYLOCK
#define DSDDESC_DONTNEEDWRITELEAD
#define IDsDriverBuffer_Release(p)
#define IDsDriverBuffer_SetVolumePan(p, a)
#define DSDDESC_DOMMSYSTEMOPEN
#define IDsDriver_GetDriverDesc(p, a)
#define IDsDriver_Open(p)
#define DSDDESC_DOMMSYSTEMSETFORMAT
#define IDsDriverBuffer_GetPosition(p, a, b)
#define IDsDriver_Release(p)
#define IDsDriverBuffer_Lock(p, a, b, c, d, e, f, g)
#define DSERR_ALREADYINITIALIZED
#define IDirectSoundBuffer_AddRef(p)
#define DSBCAPS_CTRLVOLUME
struct IDirectSoundBuffer * LPDIRECTSOUNDBUFFER
#define DSERR_CONTROLUNAVAIL
#define IDirectSoundBuffer_GetCurrentPosition(p, a, b)
#define DSERR_OUTOFMEMORY
#define DSBLOCK_ENTIREBUFFER
#define DSBLOCK_FROMWRITECURSOR
#define DSBSTATUS_LOOPING
struct IDirectSound3DListener * LPDIRECTSOUND3DLISTENER
#define DSERR_INVALIDCALL
#define DSSCL_WRITEPRIMARY
struct IDirectSound * LPDIRECTSOUND
#define DSBSTATUS_PLAYING
#define DSERR_INVALIDPARAM
#define DSBCAPS_CTRLFREQUENCY
#define DSERR_PRIOLEVELNEEDED
#define IDirectSound3DListener_AddRef(p)
#define DSBCAPS_PRIMARYBUFFER
const mixfunc mixfunctions[4]
const normfunc normfunctions[4]
DWORD DSOUND_bufpos_to_mixpos(const DirectSoundDevice *device, DWORD pos) DECLSPEC_HIDDEN
void DSOUND_AmpFactorToVolPan(PDSVOLUMEPAN volpan) DECLSPEC_HIDDEN
void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2) DECLSPEC_HIDDEN
void DSOUND_MixToTemporary(const IDirectSoundBufferImpl *dsb, DWORD writepos, DWORD mixlen, BOOL inmixer) DECLSPEC_HIDDEN
void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan) DECLSPEC_HIDDEN
HRESULT IDirectSound3DListenerImpl_Create(DirectSoundDevice *device, IDirectSound3DListenerImpl **pdsl) DECLSPEC_HIDDEN
void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb) DECLSPEC_HIDDEN
#define DS_HW_ACCEL_EMULATION
#define FillMemory(BUF, SIZ, MASK)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
struct pcmwaveformat_tag PCMWAVEFORMAT
#define CALLBACK_FUNCTION
NTSYSAPI BOOLEAN NTAPI RtlAcquireResourceExclusive(_In_ PRTL_RESOURCE Resource, _In_ BOOLEAN Wait)
NTSYSAPI VOID NTAPI RtlReleaseResource(_In_ PRTL_RESOURCE Resource)
#define IsEqualGUID(rguid1, rguid2)
vector< Header * > headers
DirectSoundDevice * device
IDirectSoundBuffer8 IDirectSoundBuffer8_iface
DWORD dwUnlockTransferRate
LPWAVEFORMATEX lpwfxFormat
#define CONTAINING_RECORD(address, type, field)
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG _In_ LONG _In_ LONG x2
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG x1
static HRESULT WINAPI PrimaryBufferImpl_Unlock(LPDIRECTSOUNDBUFFER iface, LPVOID p1, DWORD x1, LPVOID p2, DWORD x2)
static HRESULT WINAPI PrimaryBufferImpl_GetFrequency(LPDIRECTSOUNDBUFFER iface, LPDWORD freq)
static HRESULT WINAPI PrimaryBufferImpl_GetFormat(LPDIRECTSOUNDBUFFER iface, LPWAVEFORMATEX lpwf, DWORD wfsize, LPDWORD wfwritten)
static const IDirectSoundBufferVtbl dspbvt
static IDirectSoundBufferImpl * impl_from_IDirectSoundBuffer(IDirectSoundBuffer *iface)
static HRESULT WINAPI PrimaryBufferImpl_GetVolume(LPDIRECTSOUNDBUFFER iface, LPLONG vol)
HRESULT DSOUND_PrimaryPlay(DirectSoundDevice *device)
HRESULT primarybuffer_SetFormat(DirectSoundDevice *device, LPCWAVEFORMATEX wfex)
LPWAVEFORMATEX DSOUND_CopyFormat(LPCWAVEFORMATEX wfex)
void primarybuffer_destroy(IDirectSoundBufferImpl *This)
static HRESULT WINAPI PrimaryBufferImpl_SetCurrentPosition(LPDIRECTSOUNDBUFFER iface, DWORD newpos)
static HRESULT WINAPI PrimaryBufferImpl_Play(LPDIRECTSOUNDBUFFER iface, DWORD reserved1, DWORD reserved2, DWORD flags)
static HRESULT WINAPI PrimaryBufferImpl_SetFrequency(LPDIRECTSOUNDBUFFER iface, DWORD freq)
HRESULT DSOUND_PrimaryStop(DirectSoundDevice *device)
static ULONG WINAPI PrimaryBufferImpl_Release(LPDIRECTSOUNDBUFFER iface)
static HRESULT WINAPI PrimaryBufferImpl_QueryInterface(LPDIRECTSOUNDBUFFER iface, REFIID riid, LPVOID *ppobj)
static void DSOUND_PrimaryClose(DirectSoundDevice *device)
static HRESULT WINAPI PrimaryBufferImpl_SetPan(LPDIRECTSOUNDBUFFER iface, LONG pan)
DWORD DSOUND_fraglen(DWORD nSamplesPerSec, DWORD nBlockAlign)
static HRESULT WINAPI PrimaryBufferImpl_SetFormat(LPDIRECTSOUNDBUFFER iface, LPCWAVEFORMATEX wfex)
static HRESULT WINAPI PrimaryBufferImpl_GetCaps(LPDIRECTSOUNDBUFFER iface, LPDSBCAPS caps)
static HRESULT WINAPI PrimaryBufferImpl_Initialize(LPDIRECTSOUNDBUFFER iface, LPDIRECTSOUND dsound, LPCDSBUFFERDESC dbsd)
HRESULT DSOUND_PrimaryGetPosition(DirectSoundDevice *device, LPDWORD playpos, LPDWORD writepos)
HRESULT DSOUND_PrimaryDestroy(DirectSoundDevice *device)
static DWORD DSOUND_GetFormatSize(LPCWAVEFORMATEX wfex)
static void DSOUND_RecalcPrimary(DirectSoundDevice *device)
static HRESULT WINAPI PrimaryBufferImpl_SetVolume(LPDIRECTSOUNDBUFFER iface, LONG vol)
static HRESULT WINAPI PrimaryBufferImpl_Stop(LPDIRECTSOUNDBUFFER iface)
static HRESULT DSOUND_PrimaryOpen(DirectSoundDevice *device)
static HRESULT WINAPI PrimaryBufferImpl_GetStatus(LPDIRECTSOUNDBUFFER iface, LPDWORD status)
HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave)
static HRESULT WINAPI PrimaryBufferImpl_Lock(LPDIRECTSOUNDBUFFER iface, DWORD writecursor, DWORD writebytes, LPVOID *lplpaudioptr1, LPDWORD audiobytes1, LPVOID *lplpaudioptr2, LPDWORD audiobytes2, DWORD flags)
HRESULT DSOUND_PrimaryCreate(DirectSoundDevice *device)
static HRESULT WINAPI PrimaryBufferImpl_Restore(LPDIRECTSOUNDBUFFER iface)
HRESULT primarybuffer_create(DirectSoundDevice *device, IDirectSoundBufferImpl **ppdsb, const DSBUFFERDESC *dsbd)
static ULONG WINAPI PrimaryBufferImpl_AddRef(LPDIRECTSOUNDBUFFER iface)
static HRESULT WINAPI PrimaryBufferImpl_GetCurrentPosition(LPDIRECTSOUNDBUFFER iface, LPDWORD playpos, LPDWORD writepos)
static HRESULT WINAPI PrimaryBufferImpl_GetPan(LPDIRECTSOUNDBUFFER iface, LPLONG pan)
UINT WINAPI waveOutReset(HWAVEOUT hWaveOut)
UINT WINAPI waveOutSetVolume(HWAVEOUT hWaveOut, DWORD dw)
UINT WINAPI waveOutUnprepareHeader(HWAVEOUT hWaveOut, LPWAVEHDR lpWaveOutHdr, UINT uSize)
MMRESULT WINAPI waveOutOpen(LPHWAVEOUT lphWaveOut, UINT uDeviceID, LPCWAVEFORMATEX lpFormat, DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD dwFlags)
UINT WINAPI waveOutRestart(HWAVEOUT hWaveOut)
UINT WINAPI waveOutPrepareHeader(HWAVEOUT hWaveOut, WAVEHDR *lpWaveOutHdr, UINT uSize)
UINT WINAPI waveOutPause(HWAVEOUT hWaveOut)
UINT WINAPI waveOutMessage(HWAVEOUT hWaveOut, UINT uMessage, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
UINT WINAPI waveOutGetVolume(HWAVEOUT hWaveOut, LPDWORD lpdw)
UINT WINAPI waveOutClose(HWAVEOUT hWaveOut)