[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
A second patch for wdsndmix.c, which is also a test for the AllegMix
driver taking over the DX mixer. This gets applied to the 4.1.14 source,
however, and this is important, the wdsound.c file needs to be
completely emptied out. I haven't figured out how to get a diff to
modify two files at once, so the diff won't do it for you.
This maps the DX* driver names (DIGI_DIRECTX(n)) to the AllegMix
driver, and drops the AM* driver names (DIGI_DIRECTAMX(n)). I could make
them both map to the AllegMix driver, but that would cause all available
DirectSound devices to show up twice in the driver list. Also, it fixes
a few memory leaks and checks the return value of a couple mallocs
associated with the device list generation.
- Kitty Cat
--- wdsndmix.c 2004-04-27 14:03:18.000000000 -0700
+++ wdsndmix.c 2004-04-28 04:10:24.000000000 -0700
@@ -123,6 +123,7 @@
#define MAX_DRIVERS 16
+static int num_drivers = 0;
static char *driver_names[MAX_DRIVERS];
static LPGUID driver_guids[MAX_DRIVERS];
@@ -141,33 +142,93 @@
-/* _get_dsalmix_driver:
+/* DSEnumCallback:
+ * Callback function for enumerating the available DirectSound drivers.
+ */
+static BOOL CALLBACK DSEnumCallback(LPGUID lpGuid, LPCSTR lpcstrDescription, LPCSTR lpcstrModule, LPVOID lpContext)
+{
+ if (lpGuid) {
+ driver_guids[num_drivers] = lpGuid;
+ driver_names[num_drivers] = malloc(strlen(lpcstrDescription)+1);
+ if(!driver_names[num_drivers])
+ return !!0;
+ strcpy(driver_names[num_drivers], lpcstrDescription);
+ num_drivers++;
+ }
+
+ return (num_drivers < MAX_DRIVERS);
+}
+
+
+
+/* _get_win_digi_driver_list:
* System driver hook for listing the available sound drivers. This
* generates the device list at runtime, to match whatever DirectSound
* devices are available.
*/
-DIGI_DRIVER *_get_dsalmix_driver(char *name, LPGUID guid, int num)
+_DRIVER_INFO *_get_win_digi_driver_list(void)
{
DIGI_DRIVER *driver;
+ HRESULT hr;
+ int i;
- driver = malloc(sizeof(DIGI_DRIVER));
- if (!driver)
- return NULL;
+ if (!driver_list) {
+ driver_list = _create_driver_list();
- memcpy(driver, &digi_dsoundmix, sizeof(DIGI_DRIVER));
+ /* enumerate the DirectSound drivers */
+ hr = DirectSoundEnumerate(DSEnumCallback, NULL);
- driver->id = DIGI_DIRECTAMX(num);
+ if (hr == DS_OK) {
+ /* Allegro mixer to DirectSound drivers */
+ for (i=0; i<num_drivers; i++) {
+ driver = malloc(sizeof(DIGI_DRIVER));
+ if (!driver)
+ break;
+
+ memcpy(driver, &digi_dsoundmix, sizeof(DIGI_DRIVER));
+ driver->id = DIGI_DIRECTX(num);
+ driver->ascii_name = driver_names[num];
- driver_names[num] = malloc(strlen(name)+10);
- if (driver_names[num]) {
- strcpy(driver_names[num], "Allegmix ");
- strcpy(driver_names[num]+9, name);
- driver->ascii_name = driver_names[num];
+ _driver_list_append_driver(&driver_list, driver->id, driver, TRUE);
+ }
+ }
+
+ /* Allegro mixer to WaveOut drivers */
+ for (i=0; i<2; i++) {
+ driver = _get_woalmix_driver(i);
+
+ _driver_list_append_driver(&driver_list, driver->id, driver, TRUE);
+ }
}
- driver_guids[num] = guid;
+ return driver_list;
+}
+
- return driver;
+
+/* _free_win_digi_driver_list:
+ * Helper function for freeing the dynamically generated driver list.
+ */
+void _free_win_digi_driver_list(void)
+{
+ int i = 0;
+
+ if (driver_list) {
+ while (driver_list[i].driver) {
+ free(driver_list[i].driver);
+ i++;
+ }
+
+ _destroy_driver_list(driver_list);
+ driver_list = NULL;
+ }
+
+ for(i=0; i<num_drivers; i++) {
+ if(driver_names[num_drivers])
+ free(driver_names[num_drivers]);
+ driver_names[num_drivers] = NULL;
+ }
+ num_drivers = 0;
}
@@ -387,20 +448,21 @@
goto Error;
}
- if (dscaps.dwFlags & DSCAPS_PRIMARY16BIT)
+ if ((dscaps.dwFlags & DSCAPS_PRIMARY16BIT) &&
+ (_sound_bits >= 16 || _sound_bits < 0))
_bits = 16;
else
_bits = 8;
- if (dscaps.dwFlags & DSCAPS_PRIMARYSTEREO)
+ if ((dscaps.dwFlags & DSCAPS_PRIMARYSTEREO) && _sound_stereo)
_stereo = 1;
else
_stereo = 0;
- if (dscaps.dwMaxSecondarySampleRate > 44000)
- _freq = 44100;
+ if ((dscaps.dwMaxSecondarySampleRate > _sound_freq) && (_sound_freq >= 0))
+ _freq = _sound_freq;
else
- _freq = 22050;
+ _freq = dscaps.dwMaxSecondarySampleRate;
_TRACE("DirectSound caps: %u bits, %s, %uHz\n", _bits, _stereo ? "stereo" : "mono", _freq);
@@ -491,7 +553,7 @@
/* start playing */
install_int(digi_dsoundmix_mixer_callback, 20); /* 50 Hz */
IDirectSoundBuffer_Play(prim_buf, 0, 0, DSBPLAY_LOOPING);
-
+
return 0;
Error:
@@ -510,7 +572,7 @@
digi_directsound_capture_exit();
return;
}
-
+
/* stop playing */
remove_int(digi_dsoundmix_mixer_callback);