Fix sound errors when no sound card is detected.

Based on a patch by: @Imarok
Refs: #3285

Differential Revision: https://code.wildfiregames.com/D1481
This was SVN commit r24551.
This commit is contained in:
Stan 2021-01-11 18:56:33 +00:00
parent 687a9335f0
commit 205486d6f3
5 changed files with 34 additions and 15 deletions

View File

@ -915,7 +915,7 @@ bool Init(const CmdLineArgs& args, int flags)
CNetHost::Initialize();
#if CONFIG2_AUDIO
if (!args.Has("autostart-nonvisual"))
if (!args.Has("autostart-nonvisual") && !g_DisableAudio)
ISoundManager::CreateSoundManager();
#endif

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2020 Wildfire Games.
/* Copyright (C) 2021 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -143,8 +143,11 @@ void RunHardwareDetection()
scriptInterface.SetProperty(settings, "gfx_card", gfx::CardName());
scriptInterface.SetProperty(settings, "gfx_drv_ver", gfx::DriverInfo());
#if CONFIG2_AUDIO
if (g_SoundManager)
{
scriptInterface.SetProperty(settings, "snd_card", g_SoundManager->GetSoundCardNames());
scriptInterface.SetProperty(settings, "snd_drv_ver", g_SoundManager->GetOpenALVersion());
}
#endif
ReportSDL(scriptInterface, settings);

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2020 Wildfire Games.
/* Copyright (C) 2021 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -137,8 +137,15 @@ void WriteSystemInfo()
fprintf(f, "Video Mode : %dx%d:%d\n", g_VideoMode.GetXRes(), g_VideoMode.GetYRes(), g_VideoMode.GetBPP());
#if CONFIG2_AUDIO
if (g_SoundManager)
{
fprintf(f, "Sound Card : %s\n", g_SoundManager->GetSoundCardNames().c_str());
fprintf(f, "Sound Drivers : %s\n", g_SoundManager->GetOpenALVersion().c_str());
}
else if(g_DisableAudio)
fprintf(f, "Sound : Game was ran without audio\n");
else
fprintf(f, "Sound : No audio device was found\n");
#else
fprintf(f, "Sound : Game was compiled without audio\n");
#endif

View File

@ -184,11 +184,18 @@ private:
void ISoundManager::CreateSoundManager()
{
if (!g_SoundManager)
if (g_SoundManager)
return;
ALCdevice* device = alcOpenDevice(nullptr);
if (!device)
{
g_SoundManager = new CSoundManager();
g_SoundManager->StartWorker();
LOGWARNING("No audio device was found.");
return;
}
g_SoundManager = new CSoundManager(device);
g_SoundManager->StartWorker();
}
void ISoundManager::SetEnabled(bool doEnable)
@ -227,8 +234,8 @@ Status CSoundManager::ReloadChangedFiles(const VfsPath& UNUSED(path))
return static_cast<CSoundManager*>(param)->ReloadChangedFiles(path);
}
CSoundManager::CSoundManager()
: m_Context(nullptr), m_Device(nullptr), m_ALSourceBuffer(nullptr),
CSoundManager::CSoundManager(ALCdevice* device)
: m_Context(nullptr), m_Device(device), m_ALSourceBuffer(nullptr),
m_CurrentTune(nullptr), m_CurrentEnvirons(nullptr),
m_Worker(nullptr), m_DistressMutex(), m_PlayListItems(nullptr), m_SoundGroups(),
m_Gain(.5f), m_MusicGain(.5f), m_AmbientGain(.5f), m_ActionGain(.5f), m_UIGain(.5f),
@ -305,7 +312,9 @@ Status CSoundManager::AlcInit()
{
Status ret = INFO::OK;
m_Device = alcOpenDevice(NULL);
if(!m_Device)
m_Device = alcOpenDevice(nullptr);
if (m_Device)
{
ALCint attribs[] = {ALC_STEREO_SOURCES, 16, 0};

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2020 Wildfire Games.
/* Copyright (C) 2021 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -96,7 +96,7 @@ protected:
CStr8 m_SoundCardNames;
CStr8 m_OpenALVersion;
public:
CSoundManager();
CSoundManager(ALCdevice* device);
virtual ~CSoundManager();
void StartWorker();