Skip to content

Commit

Permalink
dmusic: Use the IDirectMusicObject interface for waves.
Browse files Browse the repository at this point in the history
  • Loading branch information
rbernon authored and julliard committed Oct 20, 2023
1 parent dc0431b commit 80e6310
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 30 deletions.
6 changes: 3 additions & 3 deletions dlls/dmime/wavetrack.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(dmime);
struct wave_item {
struct list entry;
DMUS_IO_WAVE_ITEM_HEADER header;
IUnknown *object;
IDirectMusicObject *object;
IDirectSoundBuffer *buffer;
};

Expand Down Expand Up @@ -106,7 +106,7 @@ static ULONG WINAPI wave_track_Release(IDirectMusicTrack8 *iface)
{
list_remove(&item->entry);
if (item->buffer) IDirectSoundBuffer_Release(item->buffer);
if (item->object) IUnknown_Release(item->object);
if (item->object) IDirectMusicObject_Release(item->object);
free(item);
}

Expand Down Expand Up @@ -469,7 +469,7 @@ static HRESULT parse_wave_item(struct wave_part *part, IStream *stream, struct c
hr = DMUS_E_UNSUPPORTED_STREAM;
goto error;
}
if (FAILED(hr = dmobj_parsereference(stream, &chunk, (IDirectMusicObject **)&item->object)))
if (FAILED(hr = dmobj_parsereference(stream, &chunk, &item->object)))
goto error;

list_add_tail(&part->items, &item->entry);
Expand Down
8 changes: 4 additions & 4 deletions dlls/dmusic/collection.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ C_ASSERT(sizeof(struct pool) == offsetof(struct pool, cues[0]));
struct wave_entry
{
struct list entry;
IUnknown *wave;
IDirectMusicObject *wave;
DWORD offset;
};

Expand All @@ -59,13 +59,13 @@ struct collection
struct list waves;
};

extern void collection_internal_addref(struct collection *collection)
void collection_internal_addref(struct collection *collection)
{
ULONG ref = InterlockedIncrement( &collection->internal_ref );
TRACE( "collection %p, internal ref %lu.\n", collection, ref );
}

extern void collection_internal_release(struct collection *collection)
void collection_internal_release(struct collection *collection)
{
ULONG ref = InterlockedDecrement( &collection->internal_ref );
TRACE( "collection %p, internal ref %lu.\n", collection, ref );
Expand All @@ -74,7 +74,7 @@ extern void collection_internal_release(struct collection *collection)
free(collection);
}

extern HRESULT collection_get_wave(struct collection *collection, DWORD index, IUnknown **out)
HRESULT collection_get_wave(struct collection *collection, DWORD index, IDirectMusicObject **out)
{
struct wave_entry *wave_entry;
DWORD offset;
Expand Down
2 changes: 1 addition & 1 deletion dlls/dmusic/dmusic_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ typedef struct port_info {
struct collection;
extern void collection_internal_addref(struct collection *collection);
extern void collection_internal_release(struct collection *collection);
extern HRESULT collection_get_wave(struct collection *collection, DWORD index, IUnknown **out);
extern HRESULT collection_get_wave(struct collection *collection, DWORD index, IDirectMusicObject **out);

/* CLSID */
extern HRESULT music_create(IUnknown **ret_iface);
Expand Down
11 changes: 6 additions & 5 deletions dlls/dmusic/dmusic_wave.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
struct soundfont;
struct chunk_entry;

extern HRESULT wave_create_from_soundfont(struct soundfont *soundfont, UINT index, IUnknown **out);
extern HRESULT wave_create_from_chunk(IStream *stream, struct chunk_entry *parent, IUnknown **out);
extern HRESULT wave_download_to_port(IUnknown *iface, IDirectMusicPortDownload *port, DWORD *id);
extern HRESULT wave_download_to_dsound(IUnknown *iface, IDirectSound *dsound, IDirectSoundBuffer **ret_iface);
extern HRESULT wave_get_duration(IUnknown *iface, REFERENCE_TIME *duration);
extern HRESULT wave_create_from_soundfont(struct soundfont *soundfont, UINT index, IDirectMusicObject **out);
extern HRESULT wave_create_from_chunk(IStream *stream, struct chunk_entry *parent, IDirectMusicObject **out);
extern HRESULT wave_download_to_port(IDirectMusicObject *iface, IDirectMusicPortDownload *port, DWORD *id);
extern HRESULT wave_download_to_dsound(IDirectMusicObject *iface, IDirectSound *dsound,
IDirectSoundBuffer **ret_iface);
extern HRESULT wave_get_duration(IDirectMusicObject *iface, REFERENCE_TIME *duration);
4 changes: 2 additions & 2 deletions dlls/dmusic/instrument.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ HRESULT instrument_download_to_port(IDirectMusicInstrument *iface, IDirectMusicP
IDirectMusicDownload *download;
DWORD size, offset_count;
struct region *region;
IUnknown *wave;
IDirectMusicObject *wave;
HRESULT hr;

if (This->download) goto done;
Expand Down Expand Up @@ -827,7 +827,7 @@ HRESULT instrument_download_to_port(IDirectMusicInstrument *iface, IDirectMusicP
if (SUCCEEDED(hr = collection_get_wave(This->collection, region->wave_link.ulTableIndex, &wave)))
{
hr = wave_download_to_port(wave, port, &dmus_region->WaveLink.ulTableIndex);
IUnknown_Release(wave);
IDirectMusicObject_Release(wave);
}
if (FAILED(hr)) goto failed;

Expand Down
35 changes: 20 additions & 15 deletions dlls/dmusic/wave.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ static HRESULT parse_wave_chunk(struct wave *This, IStream *stream, struct chunk
return hr;
}

static inline struct wave *impl_from_IDirectMusicObject(IDirectMusicObject *iface)
{
return CONTAINING_RECORD(iface, struct wave, dmobj.IDirectMusicObject_iface);
}

static HRESULT WINAPI wave_object_ParseDescriptor(IDirectMusicObject *iface,
IStream *stream, DMUS_OBJECTDESC *desc)
{
Expand Down Expand Up @@ -259,7 +264,7 @@ static const IPersistStreamVtbl wave_persist_stream_vtbl =
unimpl_IPersistStream_GetSizeMax,
};

static HRESULT wave_create(IUnknown **ret_iface)
static HRESULT wave_create(IDirectMusicObject **ret_iface)
{
struct wave *obj;

Expand All @@ -270,24 +275,24 @@ static HRESULT wave_create(IUnknown **ret_iface)
obj->dmobj.IDirectMusicObject_iface.lpVtbl = &wave_object_vtbl;
obj->dmobj.IPersistStream_iface.lpVtbl = &wave_persist_stream_vtbl;

*ret_iface = &obj->IUnknown_iface;
*ret_iface = &obj->dmobj.IDirectMusicObject_iface;
return S_OK;
}

HRESULT wave_create_from_chunk(IStream *stream, struct chunk_entry *parent, IUnknown **ret_iface)
HRESULT wave_create_from_chunk(IStream *stream, struct chunk_entry *parent, IDirectMusicObject **ret_iface)
{
struct wave *This;
IUnknown *iface;
IDirectMusicObject *iface;
HRESULT hr;

TRACE("(%p, %p, %p)\n", stream, parent, ret_iface);

if (FAILED(hr = wave_create(&iface))) return hr;
This = impl_from_IUnknown(iface);
This = impl_from_IDirectMusicObject(iface);

if (FAILED(hr = parse_wave_chunk(This, stream, parent)))
{
IUnknown_Release(iface);
IDirectMusicObject_Release(iface);
return DMUS_E_UNSUPPORTED_STREAM;
}

Expand Down Expand Up @@ -324,7 +329,7 @@ HRESULT wave_create_from_chunk(IStream *stream, struct chunk_entry *parent, IUnk
return S_OK;
}

HRESULT wave_create_from_soundfont(struct soundfont *soundfont, UINT index, IUnknown **ret_iface)
HRESULT wave_create_from_soundfont(struct soundfont *soundfont, UINT index, IDirectMusicObject **ret_iface)
{
struct sf_sample *sf_sample = soundfont->shdr + index;
struct sample *sample = NULL;
Expand All @@ -333,7 +338,7 @@ HRESULT wave_create_from_soundfont(struct soundfont *soundfont, UINT index, IUnk
UINT data_size, offset;
struct wave *This;
void *data = NULL;
IUnknown *iface;
IDirectMusicObject *iface;

TRACE("(%p, %u, %p)\n", soundfont, index, ret_iface);

Expand All @@ -360,7 +365,7 @@ HRESULT wave_create_from_soundfont(struct soundfont *soundfont, UINT index, IUnk

if (FAILED(hr = wave_create(&iface))) goto failed;

This = impl_from_IUnknown(iface);
This = impl_from_IDirectMusicObject(iface);
This->format = format;
This->sample = sample;
This->data_size = data_size;
Expand Down Expand Up @@ -403,7 +408,7 @@ HRESULT wave_create_from_soundfont(struct soundfont *soundfont, UINT index, IUnk
return hr;
}

HRESULT wave_download_to_port(IUnknown *iface, IDirectMusicPortDownload *port, DWORD *id)
HRESULT wave_download_to_port(IDirectMusicObject *iface, IDirectMusicPortDownload *port, DWORD *id)
{
struct download_buffer
{
Expand All @@ -413,7 +418,7 @@ HRESULT wave_download_to_port(IUnknown *iface, IDirectMusicPortDownload *port, D
DMUS_WAVEDATA data;
} *buffer;

struct wave *This = impl_from_IUnknown(iface);
struct wave *This = impl_from_IDirectMusicObject(iface);
DWORD size = offsetof(struct download_buffer, data.byData[This->data_size]);
IDirectMusicDownload *download;
HRESULT hr;
Expand Down Expand Up @@ -446,9 +451,9 @@ HRESULT wave_download_to_port(IUnknown *iface, IDirectMusicPortDownload *port, D
return hr;
}

HRESULT wave_download_to_dsound(IUnknown *iface, IDirectSound *dsound, IDirectSoundBuffer **ret_iface)
HRESULT wave_download_to_dsound(IDirectMusicObject *iface, IDirectSound *dsound, IDirectSoundBuffer **ret_iface)
{
struct wave *This = impl_from_IUnknown(iface);
struct wave *This = impl_from_IDirectMusicObject(iface);
DSBUFFERDESC desc =
{
.dwSize = sizeof(desc),
Expand Down Expand Up @@ -485,9 +490,9 @@ HRESULT wave_download_to_dsound(IUnknown *iface, IDirectSound *dsound, IDirectSo
return S_OK;
}

HRESULT wave_get_duration(IUnknown *iface, REFERENCE_TIME *duration)
HRESULT wave_get_duration(IDirectMusicObject *iface, REFERENCE_TIME *duration)
{
struct wave *This = impl_from_IUnknown(iface);
struct wave *This = impl_from_IDirectMusicObject(iface);
*duration = (REFERENCE_TIME)This->data_size * 10000000 / This->format->nAvgBytesPerSec;
return S_OK;
}

0 comments on commit 80e6310

Please sign in to comment.