From eca337ee55ecaed909f3e0748913bcb18f54e58f Mon Sep 17 00:00:00 2001 From: Themaister Date: Fri, 30 Mar 2012 20:09:40 +0200 Subject: [PATCH] Allow device to be selected in DirectSound. --- audio/dsound.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/audio/dsound.c b/audio/dsound.c index 2403dd4cc6..37c2cbff8f 100644 --- a/audio/dsound.c +++ b/audio/dsound.c @@ -249,10 +249,28 @@ static void dsound_free(void *data) } } +struct dsound_dev +{ + unsigned device; + unsigned total_count; + LPGUID guid; +}; + +static BOOL CALLBACK enumerate_cb(LPGUID guid, LPCSTR desc, LPCSTR module, LPVOID context) +{ + struct dsound_dev *dev = (struct dsound_dev*)context; + SSNES_LOG("\t%u: %s\n", dev->total_count, desc); + if (dev->device == dev->total_count) + dev->guid = guid; + dev->total_count++; + return TRUE; +} + static void *dsound_init(const char *device, unsigned rate, unsigned latency) { WAVEFORMATEX wfx = {0}; DSBUFFERDESC bufdesc = {0}; + struct dsound_dev dev = {0}; dsound_t *ds = (dsound_t*)calloc(1, sizeof(*ds)); if (!ds) @@ -260,7 +278,13 @@ static void *dsound_init(const char *device, unsigned rate, unsigned latency) InitializeCriticalSection(&ds->crit); - if (DirectSoundCreate(NULL, &ds->ds, NULL) != DS_OK) + if (device) + dev.device = strtoul(device, NULL, 0); + + SSNES_LOG("DirectSound devices:\n"); + DirectSoundEnumerate(enumerate_cb, &dev); + + if (DirectSoundCreate(dev.guid, &ds->ds, NULL) != DS_OK) goto error; if (IDirectSound_SetCooperativeLevel(ds->ds, GetDesktopWindow(), DSSCL_PRIORITY) != DS_OK)