diff --git a/reactos/dll/directx/dsound_new/precomp.h b/reactos/dll/directx/dsound_new/precomp.h index 5a5d0dc29b0..4d413df51b9 100644 --- a/reactos/dll/directx/dsound_new/precomp.h +++ b/reactos/dll/directx/dsound_new/precomp.h @@ -15,7 +15,7 @@ #include #include #include -#define NDEBUG +#define YDEBUG #include #include #include diff --git a/reactos/dll/directx/dsound_new/primary.c b/reactos/dll/directx/dsound_new/primary.c index ca7a285f004..2a62ccee855 100644 --- a/reactos/dll/directx/dsound_new/primary.c +++ b/reactos/dll/directx/dsound_new/primary.c @@ -100,6 +100,8 @@ PrimaryDirectSoundBuffer8Impl_fnGetCaps( { LPCDirectSoundBuffer This = (LPCDirectSoundBuffer)CONTAINING_RECORD(iface, CDirectSoundBuffer, lpVtbl); + DPRINT("PrimaryDirectSoundBuffer8Impl_fnGetCaps\n"); + if (!pDSBufferCaps) { /* invalid parameter */ @@ -130,6 +132,8 @@ PrimaryDirectSoundBuffer8Impl_fnGetCurrentPosition( { LPCDirectSoundBuffer This = (LPCDirectSoundBuffer)CONTAINING_RECORD(iface, CDirectSoundBuffer, lpVtbl); + DPRINT("PrimaryDirectSoundBuffer8Impl_fnGetCurrentPosition\n"); + if (This->dwLevel < DSSCL_PRIORITY) { /* needs priority level */ @@ -157,6 +161,8 @@ PrimaryDirectSoundBuffer8Impl_fnGetFormat( DWORD FormatSize; LPCDirectSoundBuffer This = (LPCDirectSoundBuffer)CONTAINING_RECORD(iface, CDirectSoundBuffer, lpVtbl); + DPRINT("PrimaryDirectSoundBuffer8Impl_fnGetFormat\n"); + FormatSize = sizeof(WAVEFORMATEX) + This->Format.cbSize; if (!pwfxFormat && !pdwSizeWritten) @@ -199,6 +205,8 @@ PrimaryDirectSoundBuffer8Impl_fnGetVolume( { LPCDirectSoundBuffer This = (LPCDirectSoundBuffer)CONTAINING_RECORD(iface, CDirectSoundBuffer, lpVtbl); + DPRINT("PrimaryDirectSoundBuffer8Impl_fnGetVolume\n"); + if (!plVolume) { /* invalid parameter */ @@ -219,6 +227,8 @@ PrimaryDirectSoundBuffer8Impl_fnGetPan( { LPCDirectSoundBuffer This = (LPCDirectSoundBuffer)CONTAINING_RECORD(iface, CDirectSoundBuffer, lpVtbl); + DPRINT("PrimaryDirectSoundBuffer8Impl_fnGetPan\n"); + if (!plPan) { /* invalid parameter */ @@ -239,6 +249,8 @@ PrimaryDirectSoundBuffer8Impl_fnGetFrequency( { LPCDirectSoundBuffer This = (LPCDirectSoundBuffer)CONTAINING_RECORD(iface, CDirectSoundBuffer, lpVtbl); + DPRINT("PrimaryDirectSoundBuffer8Impl_fnGetFrequency\n"); + if (!pdwFrequency) { /* invalid parameter */ @@ -259,6 +271,8 @@ PrimaryDirectSoundBuffer8Impl_fnGetStatus( { LPCDirectSoundBuffer This = (LPCDirectSoundBuffer)CONTAINING_RECORD(iface, CDirectSoundBuffer, lpVtbl); + DPRINT("PrimaryDirectSoundBuffer8Impl_fnGetStatus\n"); + if (!pdwStatus) { /* invalid parameter */ @@ -312,6 +326,8 @@ PrimaryDirectSoundBuffer8Impl_fnPlay( { LPCDirectSoundBuffer This = (LPCDirectSoundBuffer)CONTAINING_RECORD(iface, CDirectSoundBuffer, lpVtbl); + DPRINT("PrimaryDirectSoundBuffer8Impl_fnPlay dwFlags %x\n", dwFlags); + if (dwReserved1 != 0 || !(dwFlags & DSBPLAY_LOOPING)) { /* invalid parameter */ @@ -447,6 +463,8 @@ PrimaryDirectSoundBuffer8Impl_fnStop( { LPCDirectSoundBuffer This = (LPCDirectSoundBuffer)CONTAINING_RECORD(iface, CDirectSoundBuffer, lpVtbl); + DPRINT("PrimaryDirectSoundBuffer8Impl_fnStop\n"); + PrimaryDirectSoundBuffer_AcquireLock(iface); if (This->State == KSSTATE_RUN) @@ -631,9 +649,10 @@ PrimaryDirectSoundBuffer_GetPosition( KSAUDIO_POSITION Position; KSPROPERTY Request; DWORD Result; - LPCDirectSoundBuffer This = (LPCDirectSoundBuffer)CONTAINING_RECORD(iface, CDirectSoundBuffer, lpVtbl); + //DPRINT("PrimaryDirectSoundBuffer_GetPosition\n"); + if (!This->hPin) { if (pdwCurrentPlayCursor) @@ -770,6 +789,15 @@ NewPrimarySoundBuffer( This->VolumePan = DSBPAN_CENTER; This->hPin = NULL; + /* FIXME: determine default format for audio device */ + This->Format.cbSize = sizeof(WAVEFORMATEX); + This->Format.nChannels = 2; + This->Format.nSamplesPerSec = 44100; + This->Format.wBitsPerSample = 16; + This->Format.wFormatTag = WAVE_FORMAT_PCM; + This->Format.nBlockAlign = (This->Format.nChannels * This->Format.wBitsPerSample) / 8; + This->Format.nAvgBytesPerSec = (This->Format.nChannels * This->Format.nSamplesPerSec * This->Format.wBitsPerSample) / 8; + InitializeCriticalSection(&This->Lock); *OutBuffer = (LPDIRECTSOUNDBUFFER8)&This->lpVtbl; diff --git a/reactos/dll/directx/dsound_new/secondary.c b/reactos/dll/directx/dsound_new/secondary.c index 216d76d197d..2293d34f2e9 100644 --- a/reactos/dll/directx/dsound_new/secondary.c +++ b/reactos/dll/directx/dsound_new/secondary.c @@ -19,6 +19,7 @@ typedef struct DWORD dwLevel; DWORD dwFlags; DWORD dwFrequency; + DWORD BufferPosition; LONG Volume; LONG VolumePan; LPWAVEFORMATEX Format; @@ -135,7 +136,12 @@ SecondaryDirectSoundBuffer8Impl_fnGetCurrentPosition( //DPRINT("SecondaryDirectSoundBuffer8Impl_fnGetCurrentPosition This %p Play %p Write %p\n", This, pdwCurrentPlayCursor, pdwCurrentWriteCursor); - return PrimaryDirectSoundBuffer_GetPosition(This->PrimaryBuffer, pdwCurrentPlayCursor, pdwCurrentWriteCursor); + if (pdwCurrentWriteCursor) + { + *pdwCurrentWriteCursor = This->BufferPosition; + } + + return PrimaryDirectSoundBuffer_GetPosition(This->PrimaryBuffer, pdwCurrentPlayCursor, NULL); } HRESULT @@ -322,6 +328,12 @@ SecondaryDirectSoundBuffer8Impl_fnLock( *ppvAudioPtr1 = This->Buffer + dwOffset; *pdwAudioBytes1 = dwBytes; + + This->BufferPosition = dwOffset + dwBytes; + + if (This->BufferPosition == This->BufferSize) + This->BufferPosition = 0; + if (ppvAudioPtr2) *ppvAudioPtr2 = NULL; if (pdwAudioBytes2) @@ -351,6 +363,13 @@ SecondaryDirectSoundBuffer8Impl_fnPlay( /* sanity check */ ASSERT(dwFlags & DSBPLAY_LOOPING); + + if (This->State == KSSTATE_RUN) + { + /* sound buffer is already playing */ + return DS_OK; + } + /* set dataformat */ hResult = PrimaryDirectSoundBuffer_SetFormat(This->PrimaryBuffer, This->Format, TRUE); @@ -371,6 +390,8 @@ SecondaryDirectSoundBuffer8Impl_fnPlay( PrimaryDirectSoundBuffer_ReleaseLock(This->PrimaryBuffer); DPRINT("SetFormatSuccess PrimaryBuffer %p\n", This->PrimaryBuffer); + This->State = KSSTATE_RUN; + return DS_OK; } @@ -481,6 +502,13 @@ SecondaryDirectSoundBuffer8Impl_fnStop( PrimaryDirectSoundBuffer_SetState(This->PrimaryBuffer, KSSTATE_ACQUIRE); PrimaryDirectSoundBuffer_SetState(This->PrimaryBuffer, KSSTATE_STOP); + DPRINT("SecondaryDirectSoundBuffer8Impl_fnStop\n"); + + + /* set state to stop */ + This->State = KSSTATE_STOP; + This->BufferPosition = 0; + return DS_OK; } @@ -619,6 +647,8 @@ NewSecondarySoundBuffer( return DSERR_OUTOFMEMORY; } + /* fill buffer with silence */ + FillMemory(This->Buffer, lpcDSBufferDesc->dwBufferBytes, lpcDSBufferDesc->lpwfxFormat->wBitsPerSample == 8 ? 0x80 : 0); This->ref = 1; This->lpVtbl = &vt_DirectSoundBuffer8;