1
0
forked from 0ad/0ad

Fix userreport detection of sound cards

Differential Revision: https://code.wildfiregames.com/D3025
This was SVN commit r24367.
This commit is contained in:
Stan 2020-12-10 18:36:05 +00:00
parent cc65e0e8a2
commit ea38089853
7 changed files with 77 additions and 133 deletions

View File

@ -1,69 +0,0 @@
/* Copyright (C) 2020 Wildfire Games.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* sound card detection.
*/
#include "precompiled.h"
#include "lib/snd.h"
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include "lib/external_libraries/openal.h"
std::string snd_card;
std::string snd_drv_ver;
void snd_detect()
{
// OpenAL alGetString might not return anything interesting on certain platforms
// (see https://stackoverflow.com/questions/28960638 for an example).
// However our previous code supported only Windows, and alGetString does work on
// Windows, so this is an improvement.
// Sound cards
const ALCchar* devices = nullptr;
if (alcIsExtensionPresent(nullptr, "ALC_enumeration_EXT") == AL_TRUE)
{
if (alcIsExtensionPresent(nullptr, "ALC_enumerate_all_EXT") == AL_TRUE)
devices = alcGetString(nullptr, ALC_ALL_DEVICES_SPECIFIER);
else
devices = alcGetString(nullptr, ALC_DEVICE_SPECIFIER);
}
WARN_IF_FALSE(devices);
snd_card.clear();
do {
snd_card += devices;
devices += strlen(devices) + 1;
snd_card += "; ";
} while (*devices);
// Driver version
const ALCchar* al_version = alGetString(AL_VERSION);
if (al_version)
snd_drv_ver = al_version;
}

View File

@ -1,47 +0,0 @@
/* Copyright (C) 2017 Wildfire Games.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* sound card detection.
*/
#ifndef INCLUDED_SND
#define INCLUDED_SND
#include <string>
/**
* description of sound card.
**/
extern std::string snd_card;
/**
* sound driver identification and version.
**/
extern std::string snd_drv_ver;
/**
* detect sound card and set the above information.
**/
extern void snd_detect();
#endif // #ifndef INCLUDED_SND

View File

@ -20,9 +20,6 @@
#include "scriptinterface/ScriptInterface.h"
#include "lib/ogl.h"
#if CONFIG2_AUDIO
#include "lib/snd.h"
#endif
#include "lib/svn_revision.h"
#include "lib/timer.h"
#include "lib/utf8.h"
@ -37,6 +34,9 @@
# include "lib/sysdep/arch/x86_x64/cache.h"
# include "lib/sysdep/arch/x86_x64/topology.h"
#endif
#if CONFIG2_AUDIO
#include "soundmanager/SoundManager.h"
#endif
#include "ps/CLogger.h"
#include "ps/ConfigDB.h"
#include "ps/Filesystem.h"
@ -200,8 +200,8 @@ void RunHardwareDetection()
scriptInterface.SetProperty(settings, "gfx_card", gfx::CardName());
scriptInterface.SetProperty(settings, "gfx_drv_ver", gfx::DriverInfo());
#if CONFIG2_AUDIO
scriptInterface.SetProperty(settings, "snd_card", snd_card);
scriptInterface.SetProperty(settings, "snd_drv_ver", snd_drv_ver);
scriptInterface.SetProperty(settings, "snd_card", g_SoundManager->GetSoundCardNames());
scriptInterface.SetProperty(settings, "snd_drv_ver", g_SoundManager->GetOpenALVersion());
#endif
ReportSDL(scriptInterface, settings);
@ -271,7 +271,7 @@ void RunHardwareDetection()
#endif
scriptInterface.SetProperty(settings, "timer_resolution", timer_Resolution());
// The version should be increased for every meaningful change.
const int reportVersion = 13;

View File

@ -21,9 +21,6 @@
#include "lib/posix/posix_utsname.h"
#include "lib/ogl.h"
#if CONFIG2_AUDIO
#include "lib/snd.h"
#endif
#include "lib/timer.h"
#include "lib/bits.h" // round_up
#include "lib/allocators/shared_ptr.h"
@ -51,6 +48,10 @@
#include "maths/MathUtil.h"
#include "graphics/GameView.h"
#if CONFIG2_AUDIO
#include "soundmanager/SoundManager.h"
#endif
#include <iomanip>
#include <sstream>
@ -136,9 +137,8 @@ void WriteSystemInfo()
fprintf(f, "Video Mode : %dx%d:%d\n", g_VideoMode.GetXRes(), g_VideoMode.GetYRes(), g_VideoMode.GetBPP());
#if CONFIG2_AUDIO
snd_detect();
fprintf(f, "Sound Card : %s\n", snd_card.c_str());
fprintf(f, "Sound Drivers : %s\n", snd_drv_ver.c_str());
fprintf(f, "Sound Card : %s\n", g_SoundManager->GetSoundCardNames().c_str());
fprintf(f, "Sound Drivers : %s\n", g_SoundManager->GetOpenALVersion().c_str());
#else
fprintf(f, "Sound : Game was compiled without audio\n");
#endif

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2017 Wildfire Games.
/* Copyright (C) 2020 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -23,6 +23,7 @@
#include "simulation2/system/Entity.h"
class CVector3D;
class CStr8;
class ISoundManager
{
@ -44,6 +45,10 @@ public:
virtual void SetActionGain(float gain) = 0;
virtual void SetUIGain(float gain) = 0;
virtual void RunHardwareDetection() = 0;
virtual CStr8 GetSoundCardNames() const = 0;
virtual CStr8 GetOpenALVersion() const = 0;
virtual void PlayAsUI(const VfsPath& itemPath, bool looping) = 0;
virtual void PlayAsMusic(const VfsPath& itemPath, bool looping) = 0;
virtual void PlayAsAmbient(const VfsPath& itemPath, bool looping) = 0;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2019 Wildfire Games.
/* Copyright (C) 2020 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -257,6 +257,8 @@ CSoundManager::CSoundManager()
LOGERROR("CSoundManager: failed to load grammar file 'audio/sound_group.rng'");
RegisterFileReloadFunc(ReloadChangedFileCB, this);
RunHardwareDetection();
}
CSoundManager::~CSoundManager()
@ -808,11 +810,56 @@ void CSoundManager::SetAmbientItem(ISoundItem* anItem)
AL_CHECK;
}
}
void CSoundManager::RunHardwareDetection()
{
// OpenAL alGetString might not return anything interesting on certain platforms
// (see https://stackoverflow.com/questions/28960638 for an example).
// However our previous code supported only Windows, and alGetString does work on
// Windows, so this is an improvement.
// Sound cards
const ALCchar* devices = nullptr;
if (alcIsExtensionPresent(nullptr, "ALC_enumeration_EXT") == AL_TRUE)
{
if (alcIsExtensionPresent(nullptr, "ALC_enumerate_all_EXT") == AL_TRUE)
devices = alcGetString(nullptr, ALC_ALL_DEVICES_SPECIFIER);
else
devices = alcGetString(nullptr, ALC_DEVICE_SPECIFIER);
}
WARN_IF_FALSE(devices);
m_SoundCardNames.clear();
do {
m_SoundCardNames += devices;
devices += strlen(devices) + 1;
m_SoundCardNames += "; ";
} while (*devices);
// Driver version
const ALCchar* al_version = alGetString(AL_VERSION);
if (al_version)
m_OpenALVersion = al_version;
}
CStr8 CSoundManager::GetOpenALVersion() const
{
return m_OpenALVersion;
}
CStr8 CSoundManager::GetSoundCardNames() const
{
return m_SoundCardNames;
}
#else // CONFIG2_AUDIO
void ISoundManager::CreateSoundManager(){}
void ISoundManager::SetEnabled(bool UNUSED(doEnable)){}
void ISoundManager::CloseGame(){}
void ISoundManager::RunHardwareDetection() {}
CStr8 ISoundManager::GetSoundCardNames() const { return CStr8(); };
CStr8 ISoundManager::GetOpenALVersion() const { return CStr8(); };
#endif // CONFIG2_AUDIO

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2019 Wildfire Games.
/* Copyright (C) 2020 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -36,6 +36,8 @@
#include <mutex>
#include <vector>
class CStr8;
#define AL_CHECK CSoundManager::al_check(__func__, __LINE__)
struct ALSourceHolder
@ -91,7 +93,8 @@ protected:
long m_DistressErrCount;
long m_DistressTime;
CStr8 m_SoundCardNames;
CStr8 m_OpenALVersion;
public:
CSoundManager();
virtual ~CSoundManager();
@ -134,6 +137,8 @@ public:
void SetMemoryUsage(long bufferSize, int bufferCount);
long GetBufferCount();
long GetBufferSize();
CStr8 GetSoundCardNames() const;
CStr8 GetOpenALVersion() const;
void PlayAsMusic(const VfsPath& itemPath, bool looping);
void PlayAsAmbient(const VfsPath& itemPath, bool looping);
@ -150,6 +155,9 @@ public:
void PauseMusic(bool pauseIt);
void PauseAmbient(bool pauseIt);
void PauseAction(bool pauseIt);
void RunHardwareDetection();
void SetAmbientItem(ISoundItem* anItem);
void SetMasterGain(float gain);