Michael Stefaniuc : dmsynth: Implement the synth's Open and Close methods.

Alexandre Julliard julliard at winehq.org
Tue Feb 8 16:11:44 CST 2022


Module: wine
Branch: master
Commit: 1383b841c5f699c6b75511aedd84c952b39f692e
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=1383b841c5f699c6b75511aedd84c952b39f692e

Author: Michael Stefaniuc <mstefani at winehq.org>
Date:   Tue Feb  8 00:51:59 2022 +0100

dmsynth: Implement the synth's Open and Close methods.

Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/dmime/tests/performance.c |  4 +-
 dlls/dmsynth/dmsynth_private.h |  5 +--
 dlls/dmsynth/synth.c           | 91 +++++++++++++++++++++++++++++++++++++++---
 3 files changed, 90 insertions(+), 10 deletions(-)

diff --git a/dlls/dmime/tests/performance.c b/dlls/dmime/tests/performance.c
index cec89ca80aa..d09d0120023 100644
--- a/dlls/dmime/tests/performance.c
+++ b/dlls/dmime/tests/performance.c
@@ -286,7 +286,7 @@ static void test_createport(void)
     hr = IDirectMusic_CreatePort(music, &CLSID_DirectMusicSynth, &portparams, &port, NULL);
     ok(hr == S_OK, "CreatePort failed: %08x\n", hr);
     ok(port != NULL, "Didn't get IDirectMusicPort pointer\n");
-    todo_wine ok(portparams.dwValidParams, "portparams struct was not filled in\n");
+    ok(portparams.dwValidParams, "portparams struct was not filled in\n");
     IDirectMusicPort_Release(port);
     port = NULL;
 
@@ -312,7 +312,7 @@ static void test_createport(void)
     hr = IDirectMusic_CreatePort(music, &GUID_NULL, &portparams, &port, NULL);
     ok(hr == S_OK, "CreatePort failed: %08x\n", hr);
     ok(port != NULL, "Didn't get IDirectMusicPort pointer\n");
-    todo_wine ok(portparams.dwValidParams, "portparams struct was not filled in\n");
+    ok(portparams.dwValidParams, "portparams struct was not filled in\n");
     IDirectMusicPort_Release(port);
     port = NULL;
 
diff --git a/dlls/dmsynth/dmsynth_private.h b/dlls/dmsynth/dmsynth_private.h
index aabf1f56904..0058ce04d3a 100644
--- a/dlls/dmsynth/dmsynth_private.h
+++ b/dlls/dmsynth/dmsynth_private.h
@@ -56,14 +56,13 @@ extern HRESULT WINAPI DMUSIC_CreateDirectMusicSynthSinkImpl(REFIID riid, void **
  * IDirectMusicSynth8Impl implementation structure
  */
 struct IDirectMusicSynth8Impl {
-    /* IUnknown fields */
     IDirectMusicSynth8 IDirectMusicSynth8_iface;
     IKsControl IKsControl_iface;
     LONG ref;
-
-    /* IDirectMusicSynth8 fields */
     DMUS_PORTCAPS caps;
+    DMUS_PORTPARAMS params;
     BOOL active;
+    BOOL open;
     IReferenceClock *latency_clock;
     IDirectMusicSynthSink *sink;
 };
diff --git a/dlls/dmsynth/synth.c b/dlls/dmsynth/synth.c
index c69d7a340b1..2db80726408 100644
--- a/dlls/dmsynth/synth.c
+++ b/dlls/dmsynth/synth.c
@@ -94,21 +94,102 @@ static ULONG WINAPI IDirectMusicSynth8Impl_Release(IDirectMusicSynth8 *iface)
 }
 
 /* IDirectMusicSynth8Impl IDirectMusicSynth part: */
-static HRESULT WINAPI IDirectMusicSynth8Impl_Open(IDirectMusicSynth8 *iface,
-        DMUS_PORTPARAMS *pPortParams)
+static HRESULT WINAPI IDirectMusicSynth8Impl_Open(IDirectMusicSynth8 *iface, DMUS_PORTPARAMS *params)
 {
     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
+    BOOL modified = FALSE;
+    const DMUS_PORTPARAMS def = {
+        .dwValidParams = DMUS_PORTPARAMS_VOICES|DMUS_PORTPARAMS_CHANNELGROUPS|
+                DMUS_PORTPARAMS_AUDIOCHANNELS|DMUS_PORTPARAMS_SAMPLERATE|DMUS_PORTPARAMS_EFFECTS|
+                DMUS_PORTPARAMS_SHARE|DMUS_PORTPARAMS_FEATURES,
+        .dwSize = sizeof(def), .dwVoices = 32, .dwChannelGroups = 2, .dwAudioChannels = 2,
+        .dwSampleRate = 22050, .dwEffectFlags = DMUS_EFFECT_REVERB
+    };
+
+    TRACE("(%p, %p)\n", This, params);
+
+    if (This->open)
+        return DMUS_E_ALREADYOPEN;
+    if (params && params->dwSize < sizeof(DMUS_PORTPARAMS7))
+        return E_INVALIDARG;
 
-    FIXME("(%p)->(%p): stub\n", This, pPortParams);
+    This->open = TRUE;
 
-    return S_OK;
+    if (!params) {
+        memcpy(&This->params, &def, sizeof(This->params));
+        return S_OK;
+    }
+
+    if (params->dwValidParams & DMUS_PORTPARAMS_VOICES && params->dwVoices) {
+        if (params->dwVoices > This->caps.dwMaxVoices) {
+            modified = TRUE;
+            params->dwVoices = This->caps.dwMaxVoices;
+        }
+    } else
+        params->dwVoices = def.dwVoices;
+
+    if (params->dwValidParams & DMUS_PORTPARAMS_CHANNELGROUPS && params->dwChannelGroups) {
+        if (params->dwChannelGroups > This->caps.dwMaxChannelGroups) {
+            modified = TRUE;
+            params->dwChannelGroups = This->caps.dwMaxChannelGroups;
+        }
+    } else
+        params->dwChannelGroups = def.dwChannelGroups;
+
+    if (params->dwValidParams & DMUS_PORTPARAMS_AUDIOCHANNELS && params->dwAudioChannels) {
+        if (params->dwAudioChannels > This->caps.dwMaxAudioChannels) {
+            modified = TRUE;
+            params->dwAudioChannels = This->caps.dwMaxAudioChannels;
+        }
+    } else
+        params->dwAudioChannels = def.dwAudioChannels;
+
+    if (params->dwValidParams & DMUS_PORTPARAMS_SAMPLERATE && params->dwSampleRate) {
+        if (params->dwSampleRate > 96000) {
+            modified = TRUE;
+            params->dwSampleRate = 96000;
+        } else if (params->dwSampleRate < 11025) {
+            modified = TRUE;
+            params->dwSampleRate = 11025;
+        }
+    } else
+        params->dwSampleRate = def.dwSampleRate;
+
+    if (params->dwValidParams & DMUS_PORTPARAMS_EFFECTS && params->dwEffectFlags != def.dwEffectFlags)
+        modified = TRUE;
+    params->dwEffectFlags = def.dwEffectFlags;
+
+    if (params->dwValidParams & DMUS_PORTPARAMS_SHARE && params->fShare)
+        modified = TRUE;
+    params->fShare = FALSE;
+
+    if (params->dwSize >= sizeof(params)) {
+        if (params->dwValidParams & DMUS_PORTPARAMS_FEATURES && params->dwFeatures) {
+            if (params->dwFeatures & ~(DMUS_PORT_FEATURE_AUDIOPATH|DMUS_PORT_FEATURE_STREAMING)) {
+                modified = TRUE;
+                params->dwFeatures &= DMUS_PORT_FEATURE_AUDIOPATH|DMUS_PORT_FEATURE_STREAMING;
+            }
+        } else
+            params->dwFeatures = def.dwFeatures;
+        params->dwValidParams = def.dwValidParams;
+    } else
+        params->dwValidParams = def.dwValidParams & ~DMUS_PORTPARAMS_FEATURES;
+
+    memcpy(&This->params, params, min(params->dwSize, sizeof(This->params)));
+
+    return modified ? S_FALSE : S_OK;
 }
 
 static HRESULT WINAPI IDirectMusicSynth8Impl_Close(IDirectMusicSynth8 *iface)
 {
     IDirectMusicSynth8Impl *This = impl_from_IDirectMusicSynth8(iface);
 
-    FIXME("(%p)->(): stub\n", This);
+    TRACE("(%p)\n", This);
+
+    if (!This->open)
+        return DMUS_E_ALREADYCLOSED;
+
+    This->open = FALSE;
 
     return S_OK;
 }




More information about the wine-cvs mailing list