From: Michael Stefaniuc Subject: dmusic: Implement IDirectMusicBuffer::PackUnstructured(). Message-Id: <20170501000504.23909-1-mstefani@winehq.org> Date: Mon, 1 May 2017 02:05:04 +0200 Heavily based on a patch by Michael Müller Signed-off-by: Michael Stefaniuc --- Besides cleanups there is a real fix for the buffer length calculation as that needs to be 4 bytes aligned. dlls/dmusic/buffer.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/dlls/dmusic/buffer.c b/dlls/dmusic/buffer.c index bd0ad1a..ce32b24 100644 --- a/dlls/dmusic/buffer.c +++ b/dlls/dmusic/buffer.c @@ -131,11 +131,29 @@ static HRESULT WINAPI IDirectMusicBufferImpl_PackStructured(LPDIRECTMUSICBUFFER return S_OK; } -static HRESULT WINAPI IDirectMusicBufferImpl_PackUnstructured(LPDIRECTMUSICBUFFER iface, REFERENCE_TIME rt, DWORD dwChannelGroup, DWORD cb, LPBYTE lpb) +static HRESULT WINAPI IDirectMusicBufferImpl_PackUnstructured(IDirectMusicBuffer *iface, + REFERENCE_TIME ref_time, DWORD channel_group, DWORD len, BYTE *data) { IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface); + DWORD new_write_pos = This->write_pos + DMUS_EVENT_SIZE(len); + DMUS_EVENTHEADER header; + + TRACE("(%p, 0x%s, %d, %d, %p)\n", This, wine_dbgstr_longlong(ref_time), channel_group, len, data); - FIXME("(%p, 0x%s, %d, %d, %p): stub\n", This, wine_dbgstr_longlong(rt), dwChannelGroup, cb, lpb); + if (new_write_pos > This->size) + return DMUS_E_BUFFER_FULL; + + if (!This->write_pos) + This->start_time = ref_time; + + header.cbEvent = len; + header.dwChannelGroup = channel_group; + header.rtDelta = ref_time - This->start_time; + header.dwFlags = 0; + + memcpy(This->data + This->write_pos, &header, sizeof(header)); + memcpy(This->data + This->write_pos + sizeof(header), data, len); + This->write_pos = new_write_pos; return S_OK; } -- 2.9.3