Merge pull request #190 from palmalcheg/pch_msvc_fix

enable WinRT XAudio2 sound,  tweaks in cmake script for precompiled header ordering for QtCreator
This commit is contained in:
Robert Beckebans 2014-11-09 11:03:36 +01:00
commit 1f67070170
4 changed files with 160 additions and 35 deletions

View file

@ -157,9 +157,13 @@ elseif(MSVC)
-D_CRT_SECURE_NO_DEPRECATE
-D_CRT_NONSTDC_NO_DEPRECATE
-D_CRT_SECURE_NO_WARNINGS
-D_MBCS
#-DUSE_OPENAL
-D_MBCS
#-DUSE_OPENAL
-DUSE_EXCEPTIONS)
## Check for Version ##
if( ${CMAKE_SYSTEM_VERSION} EQUAL 6.2 ) # Windows 8
add_definitions(-DUSE_WINRT)
endif()
if(NOT CMAKE_CL_64)
add_definitions(-D_USE_32BIT_TIME_T)
@ -1272,19 +1276,21 @@ if(MSVC)
list(REMOVE_ITEM RBDOOM3_PRECOMPILED_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/renderer/jobs/staticshadowvolume/StaticShadowVolume.cpp)
list(REMOVE_ITEM RBDOOM3_PRECOMPILED_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/renderer/jobs/ShadowShared.cpp)
list(REMOVE_ITEM RBDOOM3_PRECOMPILED_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/renderer/RenderLog.cpp)
list(REMOVE_ITEM RBDOOM3_PRECOMPILED_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/framework/precompiled.cpp)
foreach( src_file ${RBDOOM3_PRECOMPILED_SOURCES} )
#message(STATUS "/Yuprecompiled.h for ${src_file}")
set_source_files_properties(
${src_file}
${RBDOOM3_PRECOMPILED_SOURCES}
PROPERTIES
COMPILE_FLAGS "/Yuprecompiled.h"
OBJECT_DEPENDS "precompiled.pch"
)
endforeach()
set_source_files_properties(framework/precompiled.cpp
PROPERTIES
COMPILE_FLAGS "/Ycprecompiled.h"
OBJECT_OUTPUTS "precompiled.pch"
)
list(APPEND RBDOOM3_SOURCES ${WIN32_RESOURCES})

View file

@ -84,23 +84,21 @@ list(REMOVE_ITEM ID_PRECOMPILED_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/geometry/Ren
list(REMOVE_ITEM ID_PRECOMPILED_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/SoftwareCache.cpp)
if(MSVC)
#set_target_properties(idlib PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h")
foreach( src_file ${ID_PRECOMPILED_SOURCES} )
#message(STATUS "/Yuprecompiled.h for ${src_file}")
set_source_files_properties(
${src_file}
PROPERTIES
COMPILE_FLAGS "/Yuprecompiled.h"
)
endforeach()
set_source_files_properties(precompiled.cpp
list(REMOVE_ITEM ID_PRECOMPILED_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/precompiled.cpp)
#set_target_properties(idlib PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h")
set_source_files_properties(precompiled.cpp
PROPERTIES
COMPILE_FLAGS "/Ycprecompiled.h"
OBJECT_OUTPUTS "precompiled.pch"
)
set_source_files_properties(
${ID_PRECOMPILED_SOURCES}
PROPERTIES
COMPILE_FLAGS "/Yuprecompiled.h"
OBJECT_DEPENDS "precompiled.pch"
)
add_library(idlib ${ID_SOURCES_ALL} ${ID_INCLUDES_ALL})
else()
foreach( src_file ${ID_PRECOMPILED_SOURCES} )

View file

@ -258,18 +258,123 @@ void idSoundHardware_XAudio2::Init()
// Register the sound engine callback
pXAudio2->RegisterForCallbacks( &soundEngineCallback );
soundEngineCallback.hardware = this;
// RB: not available on Windows 8 SDK
UINT32 deviceCount = 0;
DWORD outputSampleRate = 44100; // Max( (DWORD)XAUDIO2FX_REVERB_MIN_FRAMERATE, Min( (DWORD)XAUDIO2FX_REVERB_MAX_FRAMERATE, deviceDetails.OutputFormat.Format.nSamplesPerSec ) );
// RB: not available on Windows 8 SDK
#if defined(USE_WINRT) //(_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/)
// FIXME
idLib::Warning( "No audio devices found" );
pXAudio2->Release();
pXAudio2 = NULL;
return;
#else
UINT32 deviceCount = 0;
IMMDeviceEnumerator *immDevEnum = nullptr;
IMMDeviceCollection *immDevCollection = nullptr;
IMMDevice *immDev = nullptr;
std::vector<AudioDevice> vAudioDevices;
HRESULT hResult = CoCreateInstance(
__uuidof(MMDeviceEnumerator), NULL,
CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**) &immDevEnum);
if (FAILED(hResult)) {
idLib::Warning( "Failed to get audio enumerator" );
pXAudio2->Release();
pXAudio2 = NULL;
return;
}
hResult = immDevEnum->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, &immDevCollection);
if (FAILED(hResult)) {
idLib::Warning( "Failed to get audio endpoints" );
pXAudio2->Release();
pXAudio2 = NULL;
return;
}
hResult = immDevCollection->GetCount(&deviceCount);
if (FAILED(hResult)) {
idLib::Warning( "No audio devices found" );
pXAudio2->Release();
pXAudio2 = NULL;
return;
}
for (UINT i = 0; i < deviceCount; i++) {
IPropertyStore *propStore = nullptr;
PROPVARIANT varName;
PROPVARIANT varId;
PropVariantInit(&varId);
PropVariantInit(&varName);
hResult = immDevCollection->Item(i, &immDev);
if (SUCCEEDED(hResult)) {
hResult = immDev->OpenPropertyStore(STGM_READ, &propStore);
}
if (SUCCEEDED(hResult)) {
hResult = propStore->GetValue(PKEY_AudioEndpoint_Path, &varId);
}
if (SUCCEEDED(hResult)) {
hResult = propStore->GetValue(PKEY_Device_FriendlyName, &varName);
}
if (SUCCEEDED(hResult)) {
assert(varId.vt == VT_LPWSTR);
assert(varName.vt == VT_LPWSTR);
// Now save somewhere the device display name & id
AudioDevice ad;
ad.name = varName.pwszVal;
ad.id = varId.pwszVal;
vAudioDevices.push_back(ad);
}
PropVariantClear(&varName);
PropVariantClear(&varId);
if (propStore != nullptr) {
propStore->Release();
}
if (immDev != nullptr) {
immDev->Release();
}
}
immDevCollection->Release();
immDevEnum->Release();
int preferredDevice = s_device.GetInteger();
if (!vAudioDevices.empty()) {
if (SUCCEEDED(pXAudio2->CreateMasteringVoice(&pMasterVoice,
XAUDIO2_DEFAULT_CHANNELS,
outputSampleRate,
0,
vAudioDevices.at(0).id.c_str(),
NULL,
AudioCategory_GameEffects)))
{
XAUDIO2_VOICE_DETAILS deviceDetails;
pMasterVoice->GetVoiceDetails(&deviceDetails);
pMasterVoice->SetVolume(DBtoLinear(s_volume_dB.GetFloat()));
outputChannels = deviceDetails.InputChannels;
DWORD win8_channelMask;
pMasterVoice->GetChannelMask(&win8_channelMask);
channelMask = (unsigned int)win8_channelMask;
idLib::Printf( "Using device %s\n", vAudioDevices.at(0).name );
}
else {
idLib::Warning("Failed to create master voice");
pXAudio2->Release();
pXAudio2 = NULL;
return;
}
}
#else
if( pXAudio2->GetDeviceCount( &deviceCount ) != S_OK || deviceCount == 0 )
{
idLib::Warning( "No audio devices found" );
@ -322,8 +427,7 @@ void idSoundHardware_XAudio2::Init()
return;
}
DWORD outputSampleRate = 44100; // Max( (DWORD)XAUDIO2FX_REVERB_MIN_FRAMERATE, Min( (DWORD)XAUDIO2FX_REVERB_MAX_FRAMERATE, deviceDetails.OutputFormat.Format.nSamplesPerSec ) );
if( FAILED( pXAudio2->CreateMasteringVoice( &pMasterVoice, XAUDIO2_DEFAULT_CHANNELS, outputSampleRate, 0, preferredDevice, NULL ) ) )
{
idLib::Warning( "Failed to create master voice" );
@ -335,7 +439,9 @@ void idSoundHardware_XAudio2::Init()
outputChannels = deviceDetails.OutputFormat.Format.nChannels;
channelMask = deviceDetails.OutputFormat.dwChannelMask;
#endif // #if (_WIN32_WINNT < 0x0602 /*_WIN32_WINNT_WIN8*/)
idSoundVoice::InitSurround( outputChannels, channelMask );
#if defined(USE_DOOMCLASSIC)
@ -409,7 +515,6 @@ void idSoundHardware_XAudio2::Init()
{
freeVoices[i] = &voices[i];
}
#endif // #if (_WIN32_WINNT < 0x0602 /*_WIN32_WINNT_WIN8*/)
// RB end
}

View file

@ -137,7 +137,23 @@ ID_INLINE_EXTERN ALCenum CheckALCErrors_( ALCdevice* device, const char* filenam
#define OPERATION_SET 1
// RB: not available on Windows 8 SDK
#if !defined(USE_WINRT) // (_WIN32_WINNT < 0x0602 /*_WIN32_WINNT_WIN8*/)
#if defined(USE_WINRT) // (_WIN32_WINNT < 0x0602 /*_WIN32_WINNT_WIN8*/)
#include <mmdeviceapi.h>
#include <initguid.h> // For the pkey defines to be properly instantiated.
#include <propkeydef.h>
#include "functiondiscoverykeys_devpkey.h"
#include <string>
#include <vector>
DEFINE_PROPERTYKEY(PKEY_AudioEndpoint_Path, 0x9c119480, 0xddc2, 0x4954, 0xa1, 0x50, 0x5b, 0xd2, 0x40, 0xd4, 0x54, 0xad, 1);
#pragma comment(lib,"xaudio2.lib")
struct AudioDevice {
std::wstring name;
std::wstring id;
};
#else
#include <dxsdkver.h>
#endif
// RB end