- /* Default device? */
- if (!lpcGUID || IsEqualGUID(lpcGUID, &GUID_NULL))
- lpcGUID = &DSDEVID_DefaultPlayback;
-
- if (GetDeviceID(lpcGUID, &devGUID) != DS_OK) {
- WARN("invalid parameter: lpcGUID\n");
- return DSERR_INVALIDPARAM;
- }
-
- /* Enumerate WINMM audio devices and find the one we want */
- wodn = waveOutGetNumDevs();
- if (!wodn) {
- WARN("no driver\n");
- return DSERR_NODRIVER;
- }
-
- for (wod=0; wod<wodn; wod++) {
- if (IsEqualGUID( &devGUID, &DSOUND_renderer_guids[wod])) {
- found = TRUE;
- break;
- }
- }
-
- if (found == FALSE) {
- WARN("No device found matching given ID!\n");
- return DSERR_NODRIVER;
- }
-
- if (DSOUND_renderer[wod]) {
- if (IsEqualGUID(&devGUID, &DSOUND_renderer[wod]->guid)) {
- device = DSOUND_renderer[wod];
- device->ref++;
- This->device = device;
- return DS_OK;
- } else {
- ERR("device GUID doesn't match\n");
- hr = DSERR_GENERIC;
- return hr;
- }
- } else {
- hr = DirectSoundDevice_Create(&(device));
- if (hr != DS_OK) {
- WARN("DirectSoundDevice_Create failed\n");
- return hr;
- }
- }
-
- This->device = device;
- device->guid = devGUID;
-
- /* DRV_QUERYDSOUNDIFACE is a "Wine extension" to get the DSound interface */
- WineWaveOutMessage((HWAVEOUT)wod, DRV_QUERYDSOUNDIFACE, (DWORD_PTR)&device->driver, 0);
-
- /* Disable the direct sound driver to force emulation if requested. */
- if (ds_hw_accel == DS_HW_ACCEL_EMULATION)
- device->driver = NULL;
-
- /* Get driver description */
- if (device->driver) {
- hr = IDsDriver_GetDriverDesc(device->driver,&(device->drvdesc));
- if (hr != DS_OK) {
- WARN("IDsDriver_GetDriverDesc failed\n");
- return hr;
- }
- } else {
- /* if no DirectSound interface available, use WINMM API instead */
- device->drvdesc.dwFlags = DSDDESC_DOMMSYSTEMOPEN | DSDDESC_DOMMSYSTEMSETFORMAT;
- }
-
- device->drvdesc.dnDevNode = wod;
-
- /* If the driver requests being opened through MMSYSTEM
- * (which is recommended by the DDK), it is supposed to happen
- * before the DirectSound interface is opened */
- if (device->drvdesc.dwFlags & DSDDESC_DOMMSYSTEMOPEN)
- {
- DWORD flags = CALLBACK_FUNCTION;
-
- /* disable direct sound if requested */
- if (ds_hw_accel != DS_HW_ACCEL_EMULATION)
- flags |= WAVE_DIRECTSOUND;
-
- hr = mmErr(waveOutOpen(&(device->hwo),
- device->drvdesc.dnDevNode, device->pwfx,
- (DWORD_PTR)DSOUND_callback, (DWORD)device,
- flags));
- if (hr != DS_OK) {
- WARN("waveOutOpen failed\n");
- return hr;
- }
- }
-
- if (device->driver) {
- hr = IDsDriver_Open(device->driver);
- if (hr != DS_OK) {
- WARN("IDsDriver_Open failed\n");
- return hr;
- }
-
- /* the driver is now open, so it's now allowed to call GetCaps */
- hr = IDsDriver_GetCaps(device->driver,&(device->drvcaps));
- if (hr != DS_OK) {
- WARN("IDsDriver_GetCaps failed\n");
- return hr;
- }
- } else {
- WAVEOUTCAPSA woc;
- hr = mmErr(waveOutGetDevCapsA(device->drvdesc.dnDevNode, &woc, sizeof(woc)));
- if (hr != DS_OK) {
- WARN("waveOutGetDevCaps failed\n");
- return hr;
- }
- ZeroMemory(&device->drvcaps, sizeof(device->drvcaps));
- if ((woc.dwFormats & WAVE_FORMAT_1M08) ||
- (woc.dwFormats & WAVE_FORMAT_2M08) ||
- (woc.dwFormats & WAVE_FORMAT_4M08) ||
- (woc.dwFormats & WAVE_FORMAT_48M08) ||
- (woc.dwFormats & WAVE_FORMAT_96M08)) {
- device->drvcaps.dwFlags |= DSCAPS_PRIMARY8BIT;
- device->drvcaps.dwFlags |= DSCAPS_PRIMARYMONO;
- }
- if ((woc.dwFormats & WAVE_FORMAT_1M16) ||
- (woc.dwFormats & WAVE_FORMAT_2M16) ||
- (woc.dwFormats & WAVE_FORMAT_4M16) ||
- (woc.dwFormats & WAVE_FORMAT_48M16) ||
- (woc.dwFormats & WAVE_FORMAT_96M16)) {
- device->drvcaps.dwFlags |= DSCAPS_PRIMARY16BIT;
- device->drvcaps.dwFlags |= DSCAPS_PRIMARYMONO;
- }
- if ((woc.dwFormats & WAVE_FORMAT_1S08) ||
- (woc.dwFormats & WAVE_FORMAT_2S08) ||
- (woc.dwFormats & WAVE_FORMAT_4S08) ||
- (woc.dwFormats & WAVE_FORMAT_48S08) ||
- (woc.dwFormats & WAVE_FORMAT_96S08)) {
- device->drvcaps.dwFlags |= DSCAPS_PRIMARY8BIT;
- device->drvcaps.dwFlags |= DSCAPS_PRIMARYSTEREO;
- }
- if ((woc.dwFormats & WAVE_FORMAT_1S16) ||
- (woc.dwFormats & WAVE_FORMAT_2S16) ||
- (woc.dwFormats & WAVE_FORMAT_4S16) ||
- (woc.dwFormats & WAVE_FORMAT_48S16) ||
- (woc.dwFormats & WAVE_FORMAT_96S16)) {
- device->drvcaps.dwFlags |= DSCAPS_PRIMARY16BIT;
- device->drvcaps.dwFlags |= DSCAPS_PRIMARYSTEREO;
- }
- if (ds_emuldriver)
- device->drvcaps.dwFlags |= DSCAPS_EMULDRIVER;
- device->drvcaps.dwMinSecondarySampleRate = DSBFREQUENCY_MIN;
- device->drvcaps.dwMaxSecondarySampleRate = DSBFREQUENCY_MAX;
- device->drvcaps.dwPrimaryBuffers = 1;
- }
-
- hr = DSOUND_PrimaryCreate(device);
- if (hr == DS_OK) {
- DSOUND_renderer[device->drvdesc.dnDevNode] = device;
- timeBeginPeriod(DS_TIME_RES);
- DSOUND_renderer[device->drvdesc.dnDevNode]->timerID = timeSetEvent(DS_TIME_DEL, DS_TIME_RES, DSOUND_timer,
- (DWORD_PTR)DSOUND_renderer[device->drvdesc.dnDevNode], TIME_PERIODIC | TIME_CALLBACK_FUNCTION);
- } else {
- WARN("DSOUND_PrimaryCreate failed\n");
- }
-
- return hr;