[DSOUND_NEW]
authorJohannes Anderwald <johannes.anderwald@reactos.org>
Fri, 12 Feb 2010 09:54:56 +0000 (09:54 +0000)
committerJohannes Anderwald <johannes.anderwald@reactos.org>
Fri, 12 Feb 2010 09:54:56 +0000 (09:54 +0000)
- Setup a default format for the primary sound buffer
- Store last used write position and use it when checking current position
- Check if the buffer has already started to play
- Fill audio buffer with silence bytes when initializing the secondary sound buffer
-- Partialy makes graphedit work when building a simple render graph(FileAsync->WaveParser->AudioRenderer).

svn path=/trunk/; revision=45584

reactos/dll/directx/dsound_new/precomp.h
reactos/dll/directx/dsound_new/primary.c
reactos/dll/directx/dsound_new/secondary.c

index 5a5d0dc..4d413df 100644 (file)
@@ -15,7 +15,7 @@
 #include <dsconf.h>
 #include <vfwmsgs.h>
 #include <setupapi.h>
-#define NDEBUG
+#define YDEBUG
 #include <debug.h>
 #include <ks.h>
 #include <ksmedia.h>
index ca7a285..2a62cce 100644 (file)
@@ -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;
index 216d76d..2293d34 100644 (file)
@@ -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;