update openal-soft to 1.24.3

keeping the alt 87514151c4 (diff-73a8dc1ce58605f6c5ea53548454c3bae516ec5132a29c9d7ff7edf9730c75be)
This commit is contained in:
AzaezelX 2025-09-03 11:09:27 -05:00
parent 12db0500e8
commit ba32094b7b
276 changed files with 49304 additions and 8712 deletions

View file

@ -28,10 +28,8 @@
#include <string>
#include <string_view>
#include "almalloc.h"
#include "alnumeric.h"
#include "core/device.h"
#include "core/logging.h"
_Pragma("GCC diagnostic push")
_Pragma("GCC diagnostic ignored \"-Wold-style-cast\"")
@ -41,18 +39,13 @@ _Pragma("GCC diagnostic pop")
namespace {
#ifdef _WIN32
#define DEVNAME_PREFIX "OpenAL Soft on "
#else
#define DEVNAME_PREFIX ""
#endif
using namespace std::string_view_literals;
constexpr auto getDevicePrefix() noexcept -> std::string_view { return DEVNAME_PREFIX; }
constexpr auto getDefaultDeviceName() noexcept -> std::string_view
{ return DEVNAME_PREFIX "Default Device"; }
[[nodiscard]] constexpr auto getDefaultDeviceName() noexcept -> std::string_view
{ return "Default Device"sv; }
struct Sdl2Backend final : public BackendBase {
Sdl2Backend(DeviceBase *device) noexcept : BackendBase{device} { }
explicit Sdl2Backend(DeviceBase *device) noexcept : BackendBase{device} { }
~Sdl2Backend() override;
void audioCallback(Uint8 *stream, int len) noexcept;
@ -62,13 +55,9 @@ struct Sdl2Backend final : public BackendBase {
void start() override;
void stop() override;
std::string mSDLName;
SDL_AudioDeviceID mDeviceID{0u};
uint mFrameSize{0};
uint mFrequency{0u};
DevFmtChannels mFmtChans{};
DevFmtType mFmtType{};
uint mUpdateSize{0u};
};
Sdl2Backend::~Sdl2Backend()
@ -89,7 +78,7 @@ void Sdl2Backend::open(std::string_view name)
{
SDL_AudioSpec want{}, have{};
want.freq = static_cast<int>(mDevice->Frequency);
want.freq = static_cast<int>(mDevice->mSampleRate);
switch(mDevice->FmtType)
{
case DevFmtUByte: want.format = AUDIO_U8; break;
@ -100,8 +89,9 @@ void Sdl2Backend::open(std::string_view name)
case DevFmtInt: want.format = AUDIO_S32SYS; break;
case DevFmtFloat: want.format = AUDIO_F32; break;
}
want.channels = (mDevice->FmtChans == DevFmtMono) ? 1 : 2;
want.samples = static_cast<Uint16>(std::min(mDevice->UpdateSize, 8192u));
want.channels = static_cast<Uint8>(std::min<uint>(mDevice->channelsFromFmt(),
std::numeric_limits<Uint8>::max()));
want.samples = static_cast<Uint16>(std::min(mDevice->mUpdateSize, 8192u));
want.callback = [](void *ptr, Uint8 *stream, int len) noexcept
{ return static_cast<Sdl2Backend*>(ptr)->audioCallback(stream, len); };
want.userdata = this;
@ -110,45 +100,21 @@ void Sdl2Backend::open(std::string_view name)
* necessarily the first in the list.
*/
const auto defaultDeviceName = getDefaultDeviceName();
SDL_AudioDeviceID devid;
if(name.empty() || name == defaultDeviceName)
{
name = defaultDeviceName;
devid = SDL_OpenAudioDevice(nullptr, SDL_FALSE, &want, &have, SDL_AUDIO_ALLOW_ANY_CHANGE);
mSDLName.clear();
mDeviceID = SDL_OpenAudioDevice(nullptr, SDL_FALSE, &want, &have,
SDL_AUDIO_ALLOW_ANY_CHANGE);
}
else
{
const auto namePrefix = getDevicePrefix();
if(name.size() >= namePrefix.size() && name.substr(0, namePrefix.size()) == namePrefix)
{
/* Copy the string_view to a string to ensure it's null terminated
* for this call.
*/
const std::string devname{name.substr(namePrefix.size())};
devid = SDL_OpenAudioDevice(devname.c_str(), SDL_FALSE, &want, &have,
SDL_AUDIO_ALLOW_ANY_CHANGE);
}
else
{
const std::string devname{name};
devid = SDL_OpenAudioDevice(devname.c_str(), SDL_FALSE, &want, &have,
SDL_AUDIO_ALLOW_ANY_CHANGE);
}
}
if(!devid)
throw al::backend_exception{al::backend_error::NoDevice, "%s", SDL_GetError()};
DevFmtChannels devchans{};
if(have.channels >= 2)
devchans = DevFmtStereo;
else if(have.channels == 1)
devchans = DevFmtMono;
else
{
SDL_CloseAudioDevice(devid);
throw al::backend_exception{al::backend_error::DeviceError,
"Unhandled SDL channel count: %d", int{have.channels}};
mSDLName = name;
mDeviceID = SDL_OpenAudioDevice(mSDLName.c_str(), SDL_FALSE, &want, &have,
SDL_AUDIO_ALLOW_ANY_CHANGE);
}
if(!mDeviceID)
throw al::backend_exception{al::backend_error::NoDevice, "{}", SDL_GetError()};
DevFmtType devtype{};
switch(have.format)
@ -160,32 +126,100 @@ void Sdl2Backend::open(std::string_view name)
case AUDIO_S32SYS: devtype = DevFmtInt; break;
case AUDIO_F32SYS: devtype = DevFmtFloat; break;
default:
SDL_CloseAudioDevice(devid);
throw al::backend_exception{al::backend_error::DeviceError, "Unhandled SDL format: 0x%04x",
have.format};
throw al::backend_exception{al::backend_error::DeviceError,
"Unhandled SDL format: {:#04x}", have.format};
}
if(mDeviceID)
SDL_CloseAudioDevice(mDeviceID);
mDeviceID = devid;
mFrameSize = BytesFromDevFmt(devtype) * have.channels;
mFrequency = static_cast<uint>(have.freq);
mFmtChans = devchans;
mFmtType = devtype;
mUpdateSize = have.samples;
mDevice->DeviceName = name;
mDeviceName = name;
}
bool Sdl2Backend::reset()
{
mDevice->Frequency = mFrequency;
mDevice->FmtChans = mFmtChans;
mDevice->FmtType = mFmtType;
mDevice->UpdateSize = mUpdateSize;
mDevice->BufferSize = mUpdateSize * 2; /* SDL always (tries to) use two periods. */
if(mDeviceID)
SDL_CloseAudioDevice(mDeviceID);
mDeviceID = 0;
auto want = SDL_AudioSpec{};
want.freq = static_cast<int>(mDevice->mSampleRate);
switch(mDevice->FmtType)
{
case DevFmtUByte: want.format = AUDIO_U8; break;
case DevFmtByte: want.format = AUDIO_S8; break;
case DevFmtUShort: want.format = AUDIO_U16SYS; break;
case DevFmtShort: want.format = AUDIO_S16SYS; break;
case DevFmtUInt: [[fallthrough]];
case DevFmtInt: want.format = AUDIO_S32SYS; break;
case DevFmtFloat: want.format = AUDIO_F32; break;
}
want.channels = static_cast<Uint8>(std::min<uint>(mDevice->channelsFromFmt(),
std::numeric_limits<Uint8>::max()));
want.samples = static_cast<Uint16>(std::min(mDevice->mUpdateSize, 8192u));
want.callback = [](void *ptr, Uint8 *stream, int len) noexcept
{ return static_cast<Sdl2Backend*>(ptr)->audioCallback(stream, len); };
want.userdata = this;
auto have = SDL_AudioSpec{};
if(mSDLName.empty())
{
mDeviceID = SDL_OpenAudioDevice(nullptr, SDL_FALSE, &want, &have,
SDL_AUDIO_ALLOW_ANY_CHANGE);
}
else
{
mDeviceID = SDL_OpenAudioDevice(mSDLName.c_str(), SDL_FALSE, &want, &have,
SDL_AUDIO_ALLOW_ANY_CHANGE);
}
if(!mDeviceID)
throw al::backend_exception{al::backend_error::NoDevice, "{}", SDL_GetError()};
if(have.channels != mDevice->channelsFromFmt())
{
/* SDL guarantees these layouts for the given channel count. */
if(have.channels == 8)
mDevice->FmtChans = DevFmtX71;
else if(have.channels == 7)
mDevice->FmtChans = DevFmtX61;
else if(have.channels == 6)
mDevice->FmtChans = DevFmtX51;
else if(have.channels == 4)
mDevice->FmtChans = DevFmtQuad;
else if(have.channels >= 2)
mDevice->FmtChans = DevFmtStereo;
else if(have.channels == 1)
mDevice->FmtChans = DevFmtMono;
else
throw al::backend_exception{al::backend_error::DeviceError,
"Unhandled SDL channel count: {}", int{have.channels}};
mDevice->mAmbiOrder = 0;
}
switch(have.format)
{
case AUDIO_U8: mDevice->FmtType = DevFmtUByte; break;
case AUDIO_S8: mDevice->FmtType = DevFmtByte; break;
case AUDIO_U16SYS: mDevice->FmtType = DevFmtUShort; break;
case AUDIO_S16SYS: mDevice->FmtType = DevFmtShort; break;
case AUDIO_S32SYS: mDevice->FmtType = DevFmtInt; break;
case AUDIO_F32SYS: mDevice->FmtType = DevFmtFloat; break;
default:
throw al::backend_exception{al::backend_error::DeviceError,
"Unhandled SDL format: {:#04x}", have.format};
}
mFrameSize = BytesFromDevFmt(mDevice->FmtType) * have.channels;
if(have.freq < int{MinOutputRate})
throw al::backend_exception{al::backend_error::DeviceError,
"Unhandled SDL sample rate: {}", have.freq};
mDevice->mSampleRate = static_cast<uint>(have.freq);
mDevice->mUpdateSize = have.samples;
mDevice->mBufferSize = std::max(have.size/mFrameSize, mDevice->mUpdateSize*2u);
setDefaultWFXChannelOrder();
return true;
}
@ -220,16 +254,14 @@ auto SDL2BackendFactory::enumerate(BackendType type) -> std::vector<std::string>
if(num_devices <= 0)
return outnames;
outnames.reserve(static_cast<unsigned int>(num_devices));
outnames.reserve(static_cast<unsigned int>(num_devices)+1_uz);
outnames.emplace_back(getDefaultDeviceName());
for(int i{0};i < num_devices;++i)
{
std::string outname{getDevicePrefix()};
if(const char *name = SDL_GetAudioDeviceName(i, SDL_FALSE))
outname += name;
outnames.emplace_back(name);
else
outname += "Unknown Device Name #"+std::to_string(i);
outnames.emplace_back(std::move(outname));
outnames.emplace_back("Unknown Device Name #"+std::to_string(i));
}
return outnames;
}