int I2_Init() { DSBUFFERDESC desc; LPDIRECTSOUNDBUFFER bufTemp; if(initOk) return true; // Don't init a second time. if(FAILED(hr = EAXDirectSoundCreate(NULL, &dsound, NULL))) { // EAX can't be initialized. Use normal DS, then. ST_Message("I2_Init: EAX 2 couldn't be initialized (result: %i).\n", hr & 0xffff); if(FAILED(hr = DirectSoundCreate(NULL, &dsound, NULL))) { ST_Message("I2_Init: Couldn't create dsound (result: %i).\n", hr & 0xffff); return false; } } // Set the cooperative level. if(FAILED(hr = IDirectSound_SetCooperativeLevel(dsound, hWndMain, DSSCL_PRIORITY))) { ST_Message("I2_Init: Couldn't set dSound cooperative level (result: %i).\n", hr & 0xffff); return false; } // Get the listener. memset(&desc, 0, sizeof(desc)); desc.dwSize = sizeof(desc); desc.dwFlags = DSBCAPS_CTRL3D | DSBCAPS_PRIMARYBUFFER; if(SUCCEEDED(IDirectSound_CreateSoundBuffer(dsound, &desc, &bufTemp, NULL))) { // Query the listener interface. IDirectSoundBuffer_QueryInterface(bufTemp, &IID_IDirectSound3DListener, &dsListener); } // Release the primary buffer interface, we won't need it. IDirectSoundBuffer_Release(bufTemp); // Try to get the EAX listener property set. Create a temporary secondary buffer for it. if(SUCCEEDED( createDSBuffer(DSBCAPS_STATIC | DSBCAPS_CTRL3D, DSBSIZE_MIN, 22050, 8, 1, &bufTemp) )) { // Now try to get the property set. if(SUCCEEDED(hr = IDirectSoundBuffer_QueryInterface(bufTemp, &IID_IKsPropertySet, &eaxListener))) { DWORD support = 0, revsize = 0; // Check for support. if(FAILED(hr = IKsPropertySet_QuerySupport(eaxListener, &DSPROPSETID_EAX_ListenerProperties, DSPROPERTY_EAXLISTENER_ENVIRONMENT, &support)) || ((support & NEEDED_SUPPORT) != NEEDED_SUPPORT)) { ST_Message("I2_Init: Property set acquired, but EAX 2 not supported.\n Result:%i, support:%x\n", hr&0xffff, support); IKsPropertySet_Release(eaxListener); eaxListener = NULL; } else { // EAX is supported! ST_Message("I2_Init: EAX 2 available.\n"); } } // Release the temporary buffer interface. IDirectSoundBuffer_Release(bufTemp); } // Get the caps. dsCaps.dwSize = sizeof(dsCaps); IDirectSound_GetCaps(dsound, &dsCaps); ST_Message("I2_Init: Number of hardware 3D buffers: %i\n", dsCaps.dwMaxHw3DAllBuffers); // Configure the DS3D listener. if(dsListener) { IDirectSound3DListener_SetDistanceFactor(dsListener, 1/36.0f, DS3D_DEFERRED); IDirectSound3DListener_SetDopplerFactor(dsListener, 2, DS3D_DEFERRED); } // Success! initOk = true; return true; }
//=========================================================================== // DS_Init //=========================================================================== int DS_Init(void) { HWND hWnd; DSBUFFERDESC desc; LPDIRECTSOUNDBUFFER bufTemp; if(initOk) return true; // Are we in verbose mode? if((verbose = ArgExists("-verbose"))) Con_Message("DS_Init(Compat): Initializing sound driver...\n"); // Get Doomsday's window handle. hWnd = (HWND) DD_GetInteger(DD_WINDOW_HANDLE); hr = DS_OK; if(ArgExists("-noeax") || FAILED(hr = EAXDirectSoundCreate(NULL, &dsound, NULL))) { // EAX can't be initialized. Use normal DS, then. if(FAILED(hr)) Error("DS_Init", "EAX 2 couldn't be initialized."); if(FAILED(hr = DirectSoundCreate(NULL, &dsound, NULL))) { Error("DS_Init", "Failed to create dsound interface."); return false; } } // Set the cooperative level. if(FAILED(hr = dsound->SetCooperativeLevel(hWnd, DSSCL_PRIORITY))) { Error("DS_Init", "Couldn't set dSound coop level."); return false; } // Get the primary buffer and the listener. primary = NULL; memset(&desc, 0, sizeof(desc)); desc.dwSize = sizeof(desc); desc.dwFlags = DSBCAPS_CTRL3D | DSBCAPS_PRIMARYBUFFER; dsListener = NULL; if(SUCCEEDED(dsound->CreateSoundBuffer(&desc, &primary, NULL))) { // Query the listener interface. primary->QueryInterface(IID_IDirectSound3DListener, (void**) &dsListener); } else { // Failure; get a 2D primary buffer, then. desc.dwFlags = DSBCAPS_PRIMARYBUFFER; dsound->CreateSoundBuffer(&desc, &primary, NULL); } // Start playing the primary buffer. if(primary) { if(FAILED(hr = primary->Play(0, 0, DSBPLAY_LOOPING))) Error("DS_Init", "Can't play primary buffer."); } // Try to get the EAX listener property set. // Create a temporary secondary buffer for it. eaxListener = NULL; if(SUCCEEDED(CreateDSBuffer(DSBCAPS_STATIC | DSBCAPS_CTRL3D, DSBSIZE_MIN, 22050, 8, 1, &bufTemp))) { // Now try to get the property set. if(SUCCEEDED(hr = bufTemp->QueryInterface(IID_IKsPropertySet, (void**) &eaxListener))) { DWORD support = 0, revsize = 0; // Check for support. if(FAILED(hr = eaxListener->QuerySupport( DSPROPSETID_EAX_ListenerProperties, DSPROPERTY_EAXLISTENER_ENVIRONMENT, &support)) || ((support & NEEDED_SUPPORT) != NEEDED_SUPPORT)) { Error("DS_Init", "Sufficient EAX2 support not present."); eaxListener->Release(); eaxListener = NULL; } else { // EAX is supported! if(verbose) Con_Message("DS_Init(Compat): EAX2 is available.\n"); } } // Release the temporary buffer interface. bufTemp->Release(); } // Get the caps. dsCaps.dwSize = sizeof(dsCaps); dsound->GetCaps(&dsCaps); if(verbose) Con_Message("DS_Init(Compat): Number of hardware 3D " "buffers: %i\n", dsCaps.dwMaxHw3DAllBuffers); // Configure the DS3D listener. if(dsListener) { dsListener->SetDistanceFactor(1/36.0f, DS3D_DEFERRED); dsListener->SetDopplerFactor(2, DS3D_DEFERRED); } // Success! initOk = true; return true; }