[DSOUND_NEW]
[reactos.git] / reactos / dll / directx / dsound_new / primary.c
index e3820e8..ab57c70 100644 (file)
@@ -76,6 +76,12 @@ PrimaryDirectSoundBuffer8Impl_fnRelease(
 
     if (!ref)
     {
+        if (This->hPin)
+        {
+            /* close pin handle */
+            CloseHandle(This->hPin);
+        }
+        /* free primary buffer */
         HeapFree(GetProcessHeap(), 0, This);
     }
 
@@ -223,8 +229,37 @@ PrimaryDirectSoundBuffer8Impl_fnPlay(
     DWORD dwPriority,
     DWORD dwFlags)
 {
-    UNIMPLEMENTED
-    return DSERR_INVALIDPARAM;
+    LPCDirectSoundBuffer This = (LPCDirectSoundBuffer)CONTAINING_RECORD(iface, CDirectSoundBuffer, lpVtbl);
+
+    if (dwReserved1 != 0 || !(dwFlags & DSBPLAY_LOOPING))
+    {
+        /* invalid parameter */
+        return DSERR_INVALIDPARAM;
+    }
+
+    PrimaryDirectSoundBuffer_AcquireLock(iface);
+
+    if (This->State == KSSTATE_STOP)
+    {
+        PrimaryDirectSoundBuffer_SetState(iface, KSSTATE_ACQUIRE);
+        ASSERT(This->State == KSSTATE_ACQUIRE);
+    }
+
+    if (This->State == KSSTATE_ACQUIRE)
+    {
+        PrimaryDirectSoundBuffer_SetState(iface, KSSTATE_PAUSE);
+        ASSERT(This->State == KSSTATE_PAUSE);
+    }
+
+    if (This->State == KSSTATE_PAUSE)
+    {
+        PrimaryDirectSoundBuffer_SetState(iface, KSSTATE_RUN);
+        ASSERT(This->State == KSSTATE_RUN);
+    }
+
+    PrimaryDirectSoundBuffer_ReleaseLock(iface);
+
+    return DS_OK;
 }
 
 HRESULT
@@ -233,8 +268,8 @@ PrimaryDirectSoundBuffer8Impl_fnSetCurrentPosition(
     LPDIRECTSOUNDBUFFER8 iface,
     DWORD dwNewPosition)
 {
-    UNIMPLEMENTED
-    return DSERR_INVALIDPARAM;
+    /* The position of a primary buffer can't be set */
+    return DSERR_INVALIDCALL;
 }
 
 HRESULT
@@ -297,8 +332,31 @@ WINAPI
 PrimaryDirectSoundBuffer8Impl_fnStop(
     LPDIRECTSOUNDBUFFER8 iface)
 {
-    UNIMPLEMENTED
-    return DSERR_INVALIDPARAM;
+    LPCDirectSoundBuffer This = (LPCDirectSoundBuffer)CONTAINING_RECORD(iface, CDirectSoundBuffer, lpVtbl);
+
+    PrimaryDirectSoundBuffer_AcquireLock(iface);
+
+    if (This->State == KSSTATE_RUN)
+    {
+        PrimaryDirectSoundBuffer_SetState(iface, KSSTATE_PAUSE);
+        ASSERT(This->State == KSSTATE_PAUSE);
+    }
+
+    if (This->State == KSSTATE_PAUSE)
+    {
+        PrimaryDirectSoundBuffer_SetState(iface, KSSTATE_ACQUIRE);
+        ASSERT(This->State == KSSTATE_ACQUIRE);
+    }
+
+    if (This->State == KSSTATE_ACQUIRE)
+    {
+        PrimaryDirectSoundBuffer_SetState(iface, KSSTATE_STOP);
+        ASSERT(This->State == KSSTATE_STOP);
+    }
+
+    PrimaryDirectSoundBuffer_ReleaseLock(iface);
+
+    return DS_OK;
 }
 
 
@@ -513,8 +571,14 @@ PrimaryDirectSoundBuffer_SetFormat(
 
     if (This->hPin)
     {
-        /* fixme change format */
-        ASSERT(0);
+        // FIXME
+        // check if multiple buffers are active
+        // in that case need mixing
+
+        if (SetPinFormat(This->hPin, pcfxFormat))
+            return DS_OK;
+        else
+            return DSERR_GENERIC;
     }
 
     do