[PATCH 3/4] dmsynth: Implement the sink GetDesiredBufferSize method

Michael Stefaniuc mstefani at winehq.org
Mon Feb 21 17:49:58 CST 2022


Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>
---
 dlls/dmsynth/synthsink.c     | 15 +++++++++++++--
 dlls/dmsynth/tests/dmsynth.c | 24 ++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/dlls/dmsynth/synthsink.c b/dlls/dmsynth/synthsink.c
index fe578086a23..d34bcf9df5e 100644
--- a/dlls/dmsynth/synthsink.c
+++ b/dlls/dmsynth/synthsink.c
@@ -180,11 +180,22 @@ static HRESULT WINAPI IDirectMusicSynthSinkImpl_SetDirectSound(IDirectMusicSynth
 }
 
 static HRESULT WINAPI IDirectMusicSynthSinkImpl_GetDesiredBufferSize(IDirectMusicSynthSink *iface,
-        DWORD *buffer_size_in_samples)
+        DWORD *size)
 {
     IDirectMusicSynthSinkImpl *This = impl_from_IDirectMusicSynthSink(iface);
+    WAVEFORMATEX format;
+    DWORD fmtsize = sizeof(format);
 
-    FIXME("(%p)->(%p): stub\n", This, buffer_size_in_samples);
+    TRACE("(%p, %p)\n", This, size);
+
+    if (!size)
+        return E_POINTER;
+    if (!This->synth)
+        return DMUS_E_SYNTHNOTCONFIGURED;
+
+    if (FAILED(IDirectMusicSynth_GetFormat(This->synth, &format, &fmtsize)))
+        return E_UNEXPECTED;
+    *size = format.nSamplesPerSec * format.nChannels * 4;
 
     return S_OK;
 }
diff --git a/dlls/dmsynth/tests/dmsynth.c b/dlls/dmsynth/tests/dmsynth.c
index ab3349f666b..a8bf65cd73e 100644
--- a/dlls/dmsynth/tests/dmsynth.c
+++ b/dlls/dmsynth/tests/dmsynth.c
@@ -149,6 +149,8 @@ static void test_dmsynth(void)
     /* Synth isn't fully initialized yet */
     hr = IDirectMusicSynth_Activate(dmsynth, TRUE);
     ok(hr == DMUS_E_NOSYNTHSINK, "IDirectMusicSynth_Activate returned: %#lx\n", hr);
+    hr = IDirectMusicSynthSink_GetDesiredBufferSize(dmsynth_sink, &size);
+    ok(hr == DMUS_E_SYNTHNOTCONFIGURED, "IDirectMusicSynthSink_GetDesiredBufferSize returned: %#lx\n", hr);
 
     /* Open / Close */
     hr = IDirectMusicSynth_Open(dmsynth, NULL);
@@ -274,6 +276,28 @@ static void test_dmsynth(void)
     hr = IDirectMusicSynth_GetFormat(dmsynth, &format, &size);
     ok(hr == S_OK, "GetFormat failed: %#lx\n", hr);
     ok(size == sizeof(format), "GetFormat size mismatch, got %ld\n", size);
+    IDirectMusicSynth_Close(dmsynth);
+
+    /* GetDesiredBufferSize */
+    hr = IDirectMusicSynthSink_GetDesiredBufferSize(dmsynth_sink, NULL);
+    ok(hr == E_POINTER, "IDirectMusicSynthSink_GetDesiredBufferSize returned: %#lx\n", hr);
+    hr = IDirectMusicSynthSink_GetDesiredBufferSize(dmsynth_sink, &size);
+    ok(hr == E_UNEXPECTED, "IDirectMusicSynthSink_GetDesiredBufferSize returned: %#lx\n", hr);
+    params.dwValidParams = 0;
+    hr = IDirectMusicSynth_Open(dmsynth, &params);
+    ok(hr == S_OK, "Open failed: %#lx\n", hr);
+    hr = IDirectMusicSynthSink_GetDesiredBufferSize(dmsynth_sink, &size);
+    ok(hr == S_OK, "IDirectMusicSynthSink_GetDesiredBufferSize returned: %#lx\n", hr);
+    ok(size == params.dwSampleRate * params.dwAudioChannels * 4, "size: %ld\n", size);
+    IDirectMusicSynth_Close(dmsynth);
+    params.dwValidParams = DMUS_PORTPARAMS_AUDIOCHANNELS;
+    params.dwAudioChannels = 1;
+    hr = IDirectMusicSynth_Open(dmsynth, &params);
+    ok(hr == S_OK, "Open failed: %#lx\n", hr);
+    hr = IDirectMusicSynthSink_GetDesiredBufferSize(dmsynth_sink, &size);
+    ok(hr == S_OK, "IDirectMusicSynthSink_GetDesiredBufferSize returned: %#lx\n", hr);
+    ok(size == params.dwSampleRate * params.dwAudioChannels * 4, "size: %ld\n", size);
+    IDirectMusicSynth_Close(dmsynth);
 
     if (control_synth)
         IDirectMusicSynth_Release(control_synth);
-- 
2.34.1




More information about the wine-devel mailing list