From 8f661a2f59e63cbed540b512dc564a3aca7c4211 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 8 Dec 2023 04:33:32 -0800 Subject: Fix some clang-tidy warnings --- al/eax/api.h | 10 +++++----- al/eax/call.h | 42 +++++++++++++++++++++--------------------- al/eax/fx_slots.h | 9 +++------ 3 files changed, 29 insertions(+), 32 deletions(-) (limited to 'al/eax') diff --git a/al/eax/api.h b/al/eax/api.h index 18d93ef8..038fdf75 100644 --- a/al/eax/api.h +++ b/al/eax/api.h @@ -22,12 +22,12 @@ #ifndef _WIN32 -typedef struct _GUID { +using GUID = struct _GUID { std::uint32_t Data1; std::uint16_t Data2; std::uint16_t Data3; - std::uint8_t Data4[8]; -} GUID; + std::array Data4; +}; inline bool operator==(const GUID& lhs, const GUID& rhs) noexcept { return std::memcmp(&lhs, &rhs, sizeof(GUID)) == 0; } @@ -654,11 +654,11 @@ struct EAXSPEAKERLEVELPROPERTIES { }; // EAXSPEAKERLEVELPROPERTIES struct EAX40ACTIVEFXSLOTS { - GUID guidActiveFXSlots[EAX40_MAX_ACTIVE_FXSLOTS]; + std::array guidActiveFXSlots; }; // EAX40ACTIVEFXSLOTS struct EAX50ACTIVEFXSLOTS { - GUID guidActiveFXSlots[EAX50_MAX_ACTIVE_FXSLOTS]; + std::array guidActiveFXSlots; }; // EAX50ACTIVEFXSLOTS // Use this structure for EAXSOURCE_OBSTRUCTIONPARAMETERS property. diff --git a/al/eax/call.h b/al/eax/call.h index 45ff328c..04e94f3e 100644 --- a/al/eax/call.h +++ b/al/eax/call.h @@ -31,16 +31,16 @@ public: ALvoid* property_buffer, ALuint property_size); - bool is_get() const noexcept { return mCallType == EaxCallType::get; } - bool is_deferred() const noexcept { return mIsDeferred; } - int get_version() const noexcept { return mVersion; } - EaxCallPropertySetId get_property_set_id() const noexcept { return mPropertySetId; } - ALuint get_property_id() const noexcept { return mPropertyId; } - ALuint get_property_al_name() const noexcept { return mPropertySourceId; } - EaxFxSlotIndex get_fx_slot_index() const noexcept { return mFxSlotIndex; } + [[nodiscard]] auto is_get() const noexcept -> bool { return mCallType == EaxCallType::get; } + [[nodiscard]] auto is_deferred() const noexcept -> bool { return mIsDeferred; } + [[nodiscard]] auto get_version() const noexcept -> int { return mVersion; } + [[nodiscard]] auto get_property_set_id() const noexcept -> EaxCallPropertySetId { return mPropertySetId; } + [[nodiscard]] auto get_property_id() const noexcept -> ALuint { return mPropertyId; } + [[nodiscard]] auto get_property_al_name() const noexcept -> ALuint { return mPropertySourceId; } + [[nodiscard]] auto get_fx_slot_index() const noexcept -> EaxFxSlotIndex { return mFxSlotIndex; } template - TValue& get_value() const + [[nodiscard]] auto get_value() const -> TValue& { if(mPropertyBufferSize < sizeof(TValue)) fail_too_small(); @@ -49,7 +49,7 @@ public: } template - al::span get_values(size_t max_count) const + [[nodiscard]] auto get_values(size_t max_count) const -> al::span { if(max_count == 0 || mPropertyBufferSize < sizeof(TValue)) fail_too_small(); @@ -59,28 +59,28 @@ public: } template - al::span get_values() const + [[nodiscard]] auto get_values() const -> al::span { return get_values(~0_uz); } template - void set_value(const TValue& value) const + auto set_value(const TValue& value) const -> void { get_value() = value; } private: - const EaxCallType mCallType; - int mVersion; - EaxFxSlotIndex mFxSlotIndex; - EaxCallPropertySetId mPropertySetId; - bool mIsDeferred; - - const ALuint mPropertyId; - const ALuint mPropertySourceId; - ALvoid*const mPropertyBuffer; - const ALuint mPropertyBufferSize; + const EaxCallType mCallType{}; + int mVersion{}; + EaxFxSlotIndex mFxSlotIndex{}; + EaxCallPropertySetId mPropertySetId{}; + bool mIsDeferred{}; + + const ALuint mPropertyId{}; + const ALuint mPropertySourceId{}; + ALvoid*const mPropertyBuffer{}; + const ALuint mPropertyBufferSize{}; [[noreturn]] static void fail(const char* message); [[noreturn]] static void fail_too_small(); diff --git a/al/eax/fx_slots.h b/al/eax/fx_slots.h index 18b2d3ad..b7ed1031 100644 --- a/al/eax/fx_slots.h +++ b/al/eax/fx_slots.h @@ -25,11 +25,9 @@ public: } - const ALeffectslot& get( - EaxFxSlotIndex index) const; + [[nodiscard]] auto get(EaxFxSlotIndex index) const -> const ALeffectslot&; - ALeffectslot& get( - EaxFxSlotIndex index); + [[nodiscard]] auto get(EaxFxSlotIndex index) -> ALeffectslot&; private: using Items = std::array; @@ -39,8 +37,7 @@ private: [[noreturn]] - static void fail( - const char* message); + static void fail(const char* message); void initialize_fx_slots(ALCcontext& al_context); }; // EaxFxSlots -- cgit v1.2.3 From 073d79c2047143e70bb199077fe3c8dbafe0a606 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 10 Dec 2023 11:34:04 -0800 Subject: More clang-tidy cleanup And suppress some warnings --- al/eax/globals.h | 2 + al/effect.h | 2 +- alc/alc.cpp | 183 ++++++++++++++++++++++++---------------------- alc/backends/pipewire.cpp | 58 +++++++++------ alc/export_list.h | 16 ++-- alc/inprogext.h | 2 + common/alspan.h | 8 +- core/helpers.h | 4 +- 8 files changed, 151 insertions(+), 124 deletions(-) (limited to 'al/eax') diff --git a/al/eax/globals.h b/al/eax/globals.h index ff05d009..4d501ff9 100644 --- a/al/eax/globals.h +++ b/al/eax/globals.h @@ -3,6 +3,7 @@ inline bool eax_g_is_enabled{true}; +/* NOLINTBEGIN(*-avoid-c-arrays) */ inline constexpr char eax1_ext_name[]{"EAX"}; inline constexpr char eax2_ext_name[]{"EAX2.0"}; inline constexpr char eax3_ext_name[]{"EAX3.0"}; @@ -16,5 +17,6 @@ inline constexpr char eax_eax_get_func_name[]{"EAXGet"}; inline constexpr char eax_eax_set_buffer_mode_func_name[]{"EAXSetBufferMode"}; inline constexpr char eax_eax_get_buffer_mode_func_name[]{"EAXGetBufferMode"}; +/* NOLINTEND(*-avoid-c-arrays) */ #endif // !EAX_GLOBALS_INCLUDED diff --git a/al/effect.h b/al/effect.h index 7c5c40dc..fef03475 100644 --- a/al/effect.h +++ b/al/effect.h @@ -34,7 +34,7 @@ enum { inline std::bitset DisabledEffects; struct EffectList { - const char name[16]; + const char name[16]; /* NOLINT(*-avoid-c-arrays) */ ALuint type; ALenum val; }; diff --git a/alc/alc.cpp b/alc/alc.cpp index 3fcdcc3e..6e851b74 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -50,7 +50,6 @@ #include #include #include -#include #include #include #include @@ -196,66 +195,66 @@ using float2 = std::array; ************************************************/ struct BackendInfo { const char *name; - BackendFactory& (*getFactory)(void); + BackendFactory& (*getFactory)(); }; -BackendInfo BackendList[] = { +std::array BackendList{ #ifdef HAVE_PIPEWIRE - { "pipewire", PipeWireBackendFactory::getFactory }, + BackendInfo{"pipewire", PipeWireBackendFactory::getFactory}, #endif #ifdef HAVE_PULSEAUDIO - { "pulse", PulseBackendFactory::getFactory }, + BackendInfo{"pulse", PulseBackendFactory::getFactory}, #endif #ifdef HAVE_WASAPI - { "wasapi", WasapiBackendFactory::getFactory }, + BackendInfo{"wasapi", WasapiBackendFactory::getFactory}, #endif #ifdef HAVE_COREAUDIO - { "core", CoreAudioBackendFactory::getFactory }, + BackendInfo{"core", CoreAudioBackendFactory::getFactory}, #endif #ifdef HAVE_OBOE - { "oboe", OboeBackendFactory::getFactory }, + BackendInfo{"oboe", OboeBackendFactory::getFactory}, #endif #ifdef HAVE_OPENSL - { "opensl", OSLBackendFactory::getFactory }, + BackendInfo{"opensl", OSLBackendFactory::getFactory}, #endif #ifdef HAVE_ALSA - { "alsa", AlsaBackendFactory::getFactory }, + BackendInfo{"alsa", AlsaBackendFactory::getFactory}, #endif #ifdef HAVE_SOLARIS - { "solaris", SolarisBackendFactory::getFactory }, + BackendInfo{"solaris", SolarisBackendFactory::getFactory}, #endif #ifdef HAVE_SNDIO - { "sndio", SndIOBackendFactory::getFactory }, + BackendInfo{"sndio", SndIOBackendFactory::getFactory}, #endif #ifdef HAVE_OSS - { "oss", OSSBackendFactory::getFactory }, + BackendInfo{"oss", OSSBackendFactory::getFactory}, #endif #ifdef HAVE_JACK - { "jack", JackBackendFactory::getFactory }, + BackendInfo{"jack", JackBackendFactory::getFactory}, #endif #ifdef HAVE_DSOUND - { "dsound", DSoundBackendFactory::getFactory }, + BackendInfo{"dsound", DSoundBackendFactory::getFactory}, #endif #ifdef HAVE_WINMM - { "winmm", WinMMBackendFactory::getFactory }, + BackendInfo{"winmm", WinMMBackendFactory::getFactory}, #endif #ifdef HAVE_PORTAUDIO - { "port", PortBackendFactory::getFactory }, + BackendInfo{"port", PortBackendFactory::getFactory}, #endif #ifdef HAVE_SDL2 - { "sdl2", SDL2BackendFactory::getFactory }, + BackendInfo{"sdl2", SDL2BackendFactory::getFactory}, #endif - { "null", NullBackendFactory::getFactory }, + BackendInfo{"null", NullBackendFactory::getFactory}, #ifdef HAVE_WAVE - { "wave", WaveBackendFactory::getFactory }, + BackendInfo{"wave", WaveBackendFactory::getFactory}, #endif }; BackendFactory *PlaybackFactory{}; BackendFactory *CaptureFactory{}; - +/* NOLINTBEGIN(*-avoid-c-arrays) */ constexpr ALCchar alcNoError[] = "No Error"; constexpr ALCchar alcErrInvalidDevice[] = "Invalid Device"; constexpr ALCchar alcErrInvalidContext[] = "Invalid Context"; @@ -270,6 +269,7 @@ constexpr ALCchar alcErrOutOfMemory[] = "Out of Memory"; /* Enumerated device names */ constexpr ALCchar alcDefaultName[] = "OpenAL Soft\0"; +/* NOLINTEND(*-avoid-c-arrays) */ std::string alcAllDevicesList; std::string alcCaptureDeviceList; @@ -298,6 +298,7 @@ constexpr uint DitherRNGSeed{22222u}; /************************************************ * ALC information ************************************************/ +/* NOLINTBEGIN(*-avoid-c-arrays) */ constexpr ALCchar alcNoDeviceExtList[] = "ALC_ENUMERATE_ALL_EXT " "ALC_ENUMERATION_EXT " @@ -328,6 +329,7 @@ constexpr ALCchar alcExtensionList[] = "ALC_SOFT_pause_device " "ALC_SOFT_reopen_device " "ALC_SOFT_system_events"; +/* NOLINTEND(*-avoid-c-arrays) */ constexpr int alcMajorVersion{1}; constexpr int alcMinorVersion{1}; @@ -347,7 +349,7 @@ std::vector ContextList; std::recursive_mutex ListLock; -void alc_initconfig(void) +void alc_initconfig() { if(auto loglevel = al::getenv("ALSOFT_LOGLEVEL")) { @@ -672,7 +674,7 @@ void alc_initconfig(void) #ifdef ALSOFT_EAX { - static constexpr char eax_block_name[] = "eax"; + const char *eax_block_name{"eax"}; if(const auto eax_enable_opt = ConfigValueBool(nullptr, eax_block_name, "enable")) { @@ -736,44 +738,45 @@ void ProbeCaptureDeviceList() struct DevFmtPair { DevFmtChannels chans; DevFmtType type; }; std::optional DecomposeDevFormat(ALenum format) { - static const struct { + struct FormatType { ALenum format; DevFmtChannels channels; DevFmtType type; - } list[] = { - { AL_FORMAT_MONO8, DevFmtMono, DevFmtUByte }, - { AL_FORMAT_MONO16, DevFmtMono, DevFmtShort }, - { AL_FORMAT_MONO_I32, DevFmtMono, DevFmtInt }, - { AL_FORMAT_MONO_FLOAT32, DevFmtMono, DevFmtFloat }, - - { AL_FORMAT_STEREO8, DevFmtStereo, DevFmtUByte }, - { AL_FORMAT_STEREO16, DevFmtStereo, DevFmtShort }, - { AL_FORMAT_STEREO_I32, DevFmtStereo, DevFmtInt }, - { AL_FORMAT_STEREO_FLOAT32, DevFmtStereo, DevFmtFloat }, - - { AL_FORMAT_QUAD8, DevFmtQuad, DevFmtUByte }, - { AL_FORMAT_QUAD16, DevFmtQuad, DevFmtShort }, - { AL_FORMAT_QUAD32, DevFmtQuad, DevFmtFloat }, - { AL_FORMAT_QUAD_I32, DevFmtQuad, DevFmtInt }, - { AL_FORMAT_QUAD_FLOAT32, DevFmtQuad, DevFmtFloat }, - - { AL_FORMAT_51CHN8, DevFmtX51, DevFmtUByte }, - { AL_FORMAT_51CHN16, DevFmtX51, DevFmtShort }, - { AL_FORMAT_51CHN32, DevFmtX51, DevFmtFloat }, - { AL_FORMAT_51CHN_I32, DevFmtX51, DevFmtInt }, - { AL_FORMAT_51CHN_FLOAT32, DevFmtX51, DevFmtFloat }, - - { AL_FORMAT_61CHN8, DevFmtX61, DevFmtUByte }, - { AL_FORMAT_61CHN16, DevFmtX61, DevFmtShort }, - { AL_FORMAT_61CHN32, DevFmtX61, DevFmtFloat }, - { AL_FORMAT_61CHN_I32, DevFmtX61, DevFmtInt }, - { AL_FORMAT_61CHN_FLOAT32, DevFmtX61, DevFmtFloat }, - - { AL_FORMAT_71CHN8, DevFmtX71, DevFmtUByte }, - { AL_FORMAT_71CHN16, DevFmtX71, DevFmtShort }, - { AL_FORMAT_71CHN32, DevFmtX71, DevFmtFloat }, - { AL_FORMAT_71CHN_I32, DevFmtX71, DevFmtInt }, - { AL_FORMAT_71CHN_FLOAT32, DevFmtX71, DevFmtFloat }, + }; + static constexpr std::array list{ + FormatType{AL_FORMAT_MONO8, DevFmtMono, DevFmtUByte}, + FormatType{AL_FORMAT_MONO16, DevFmtMono, DevFmtShort}, + FormatType{AL_FORMAT_MONO_I32, DevFmtMono, DevFmtInt}, + FormatType{AL_FORMAT_MONO_FLOAT32, DevFmtMono, DevFmtFloat}, + + FormatType{AL_FORMAT_STEREO8, DevFmtStereo, DevFmtUByte}, + FormatType{AL_FORMAT_STEREO16, DevFmtStereo, DevFmtShort}, + FormatType{AL_FORMAT_STEREO_I32, DevFmtStereo, DevFmtInt}, + FormatType{AL_FORMAT_STEREO_FLOAT32, DevFmtStereo, DevFmtFloat}, + + FormatType{AL_FORMAT_QUAD8, DevFmtQuad, DevFmtUByte}, + FormatType{AL_FORMAT_QUAD16, DevFmtQuad, DevFmtShort}, + FormatType{AL_FORMAT_QUAD32, DevFmtQuad, DevFmtFloat}, + FormatType{AL_FORMAT_QUAD_I32, DevFmtQuad, DevFmtInt}, + FormatType{AL_FORMAT_QUAD_FLOAT32, DevFmtQuad, DevFmtFloat}, + + FormatType{AL_FORMAT_51CHN8, DevFmtX51, DevFmtUByte}, + FormatType{AL_FORMAT_51CHN16, DevFmtX51, DevFmtShort}, + FormatType{AL_FORMAT_51CHN32, DevFmtX51, DevFmtFloat}, + FormatType{AL_FORMAT_51CHN_I32, DevFmtX51, DevFmtInt}, + FormatType{AL_FORMAT_51CHN_FLOAT32, DevFmtX51, DevFmtFloat}, + + FormatType{AL_FORMAT_61CHN8, DevFmtX61, DevFmtUByte}, + FormatType{AL_FORMAT_61CHN16, DevFmtX61, DevFmtShort}, + FormatType{AL_FORMAT_61CHN32, DevFmtX61, DevFmtFloat}, + FormatType{AL_FORMAT_61CHN_I32, DevFmtX61, DevFmtInt}, + FormatType{AL_FORMAT_61CHN_FLOAT32, DevFmtX61, DevFmtFloat}, + + FormatType{AL_FORMAT_71CHN8, DevFmtX71, DevFmtUByte}, + FormatType{AL_FORMAT_71CHN16, DevFmtX71, DevFmtShort}, + FormatType{AL_FORMAT_71CHN32, DevFmtX71, DevFmtFloat}, + FormatType{AL_FORMAT_71CHN_I32, DevFmtX71, DevFmtInt}, + FormatType{AL_FORMAT_71CHN_FLOAT32, DevFmtX71, DevFmtFloat}, }; for(const auto &item : list) @@ -1034,54 +1037,56 @@ ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList) if(auto typeopt = device->configValue(nullptr, "sample-type")) { - static constexpr struct TypeMap { - const char name[8]; + struct TypeMap { + const char name[8]; /* NOLINT(*-avoid-c-arrays) */ DevFmtType type; - } typelist[] = { - { "int8", DevFmtByte }, - { "uint8", DevFmtUByte }, - { "int16", DevFmtShort }, - { "uint16", DevFmtUShort }, - { "int32", DevFmtInt }, - { "uint32", DevFmtUInt }, - { "float32", DevFmtFloat }, + }; + static constexpr std::array typelist{ + TypeMap{"int8", DevFmtByte }, + TypeMap{"uint8", DevFmtUByte }, + TypeMap{"int16", DevFmtShort }, + TypeMap{"uint16", DevFmtUShort}, + TypeMap{"int32", DevFmtInt }, + TypeMap{"uint32", DevFmtUInt }, + TypeMap{"float32", DevFmtFloat }, }; const ALCchar *fmt{typeopt->c_str()}; - auto iter = std::find_if(std::begin(typelist), std::end(typelist), + auto iter = std::find_if(typelist.begin(), typelist.end(), [fmt](const TypeMap &entry) -> bool { return al::strcasecmp(entry.name, fmt) == 0; }); - if(iter == std::end(typelist)) + if(iter == typelist.end()) ERR("Unsupported sample-type: %s\n", fmt); else opttype = iter->type; } if(auto chanopt = device->configValue(nullptr, "channels")) { - static constexpr struct ChannelMap { - const char name[16]; + struct ChannelMap { + const char name[16]; /* NOLINT(*-avoid-c-arrays) */ DevFmtChannels chans; uint8_t order; - } chanlist[] = { - { "mono", DevFmtMono, 0 }, - { "stereo", DevFmtStereo, 0 }, - { "quad", DevFmtQuad, 0 }, - { "surround51", DevFmtX51, 0 }, - { "surround61", DevFmtX61, 0 }, - { "surround71", DevFmtX71, 0 }, - { "surround714", DevFmtX714, 0 }, - { "surround3d71", DevFmtX3D71, 0 }, - { "surround51rear", DevFmtX51, 0 }, - { "ambi1", DevFmtAmbi3D, 1 }, - { "ambi2", DevFmtAmbi3D, 2 }, - { "ambi3", DevFmtAmbi3D, 3 }, + }; + static constexpr std::array chanlist{ + ChannelMap{"mono", DevFmtMono, 0}, + ChannelMap{"stereo", DevFmtStereo, 0}, + ChannelMap{"quad", DevFmtQuad, 0}, + ChannelMap{"surround51", DevFmtX51, 0}, + ChannelMap{"surround61", DevFmtX61, 0}, + ChannelMap{"surround71", DevFmtX71, 0}, + ChannelMap{"surround714", DevFmtX714, 0}, + ChannelMap{"surround3d71", DevFmtX3D71, 0}, + ChannelMap{"surround51rear", DevFmtX51, 0}, + ChannelMap{"ambi1", DevFmtAmbi3D, 1}, + ChannelMap{"ambi2", DevFmtAmbi3D, 2}, + ChannelMap{"ambi3", DevFmtAmbi3D, 3}, }; const ALCchar *fmt{chanopt->c_str()}; - auto iter = std::find_if(std::begin(chanlist), std::end(chanlist), + auto iter = std::find_if(chanlist.end(), chanlist.end(), [fmt](const ChannelMap &entry) -> bool { return al::strcasecmp(entry.name, fmt) == 0; }); - if(iter == std::end(chanlist)) + if(iter == chanlist.end()) ERR("Unsupported channels: %s\n", fmt); else { @@ -1856,7 +1861,7 @@ FORCE_ALIGN void ALC_APIENTRY alsoft_set_log_callback(LPALSOFTLOGCALLBACK callba } /** Returns a new reference to the currently active context for this thread. */ -ContextRef GetContextRef(void) +ContextRef GetContextRef() { ALCcontext *context{ALCcontext::getThreadContext()}; if(context) @@ -2980,7 +2985,7 @@ ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *device) noexcept auto ctxiter = std::lower_bound(ContextList.begin(), ContextList.end(), ctx); if(ctxiter != ContextList.end() && *ctxiter == ctx) { - orphanctxs.emplace_back(ContextRef{*ctxiter}); + orphanctxs.emplace_back(*ctxiter); ContextList.erase(ctxiter); } } diff --git a/alc/backends/pipewire.cpp b/alc/backends/pipewire.cpp index ca7e3cf3..d934071e 100644 --- a/alc/backends/pipewire.cpp +++ b/alc/backends/pipewire.cpp @@ -28,12 +28,12 @@ #include #include #include +#include #include #include #include #include #include -#include #include #include #include @@ -169,8 +169,10 @@ using std::chrono::milliseconds; using std::chrono::nanoseconds; using uint = unsigned int; +/* NOLINTBEGIN(*-avoid-c-arrays) */ constexpr char pwireDevice[] = "PipeWire Output"; constexpr char pwireInput[] = "PipeWire Input"; +/* NOLINTEND(*-avoid-c-arrays) */ bool check_version(const char *version) @@ -238,7 +240,7 @@ bool pwire_load() if(pwire_handle) return true; - static constexpr char pwire_library[] = "libpipewire-0.3.so.0"; + const char *pwire_library{"libpipewire-0.3.so.0"}; std::string missing_funcs; pwire_handle = LoadLib(pwire_library); @@ -434,9 +436,11 @@ public: explicit operator bool() const noexcept { return mLoop != nullptr; } + [[nodiscard]] auto start() const { return pw_thread_loop_start(mLoop); } auto stop() const { return pw_thread_loop_stop(mLoop); } + [[nodiscard]] auto getLoop() const { return pw_thread_loop_get_loop(mLoop); } auto lock() const { return pw_thread_loop_lock(mLoop); } @@ -501,8 +505,8 @@ struct NodeProxy { /* Track changes to the enumerable and current formats (indicates the * default and active format, which is what we're interested in). */ - uint32_t fmtids[]{SPA_PARAM_EnumFormat, SPA_PARAM_Format}; - ppw_node_subscribe_params(mNode.get(), std::data(fmtids), std::size(fmtids)); + std::array fmtids{{SPA_PARAM_EnumFormat, SPA_PARAM_Format}}; + ppw_node_subscribe_params(mNode.get(), fmtids.data(), fmtids.size()); } ~NodeProxy() { spa_hook_remove(&mListener); } @@ -765,25 +769,32 @@ void DeviceNode::Remove(uint32_t id) } -const spa_audio_channel MonoMap[]{ +constexpr std::array MonoMap{ SPA_AUDIO_CHANNEL_MONO -}, StereoMap[] { +}; +constexpr std::array StereoMap{ SPA_AUDIO_CHANNEL_FL, SPA_AUDIO_CHANNEL_FR -}, QuadMap[]{ +}; +constexpr std::array QuadMap{ SPA_AUDIO_CHANNEL_FL, SPA_AUDIO_CHANNEL_FR, SPA_AUDIO_CHANNEL_RL, SPA_AUDIO_CHANNEL_RR -}, X51Map[]{ +}; +constexpr std::array X51Map{ SPA_AUDIO_CHANNEL_FL, SPA_AUDIO_CHANNEL_FR, SPA_AUDIO_CHANNEL_FC, SPA_AUDIO_CHANNEL_LFE, SPA_AUDIO_CHANNEL_SL, SPA_AUDIO_CHANNEL_SR -}, X51RearMap[]{ +}; +constexpr std::array X51RearMap{ SPA_AUDIO_CHANNEL_FL, SPA_AUDIO_CHANNEL_FR, SPA_AUDIO_CHANNEL_FC, SPA_AUDIO_CHANNEL_LFE, SPA_AUDIO_CHANNEL_RL, SPA_AUDIO_CHANNEL_RR -}, X61Map[]{ +}; +constexpr std::array X61Map{ SPA_AUDIO_CHANNEL_FL, SPA_AUDIO_CHANNEL_FR, SPA_AUDIO_CHANNEL_FC, SPA_AUDIO_CHANNEL_LFE, SPA_AUDIO_CHANNEL_RC, SPA_AUDIO_CHANNEL_SL, SPA_AUDIO_CHANNEL_SR -}, X71Map[]{ +}; +constexpr std::array X71Map{ SPA_AUDIO_CHANNEL_FL, SPA_AUDIO_CHANNEL_FR, SPA_AUDIO_CHANNEL_FC, SPA_AUDIO_CHANNEL_LFE, SPA_AUDIO_CHANNEL_RL, SPA_AUDIO_CHANNEL_RR, SPA_AUDIO_CHANNEL_SL, SPA_AUDIO_CHANNEL_SR -}, X714Map[]{ +}; +constexpr std::array X714Map{ SPA_AUDIO_CHANNEL_FL, SPA_AUDIO_CHANNEL_FR, SPA_AUDIO_CHANNEL_FC, SPA_AUDIO_CHANNEL_LFE, SPA_AUDIO_CHANNEL_RL, SPA_AUDIO_CHANNEL_RR, SPA_AUDIO_CHANNEL_SL, SPA_AUDIO_CHANNEL_SR, SPA_AUDIO_CHANNEL_TFL, SPA_AUDIO_CHANNEL_TFR, SPA_AUDIO_CHANNEL_TRL, SPA_AUDIO_CHANNEL_TRR @@ -793,10 +804,10 @@ const spa_audio_channel MonoMap[]{ * Checks if every channel in 'map1' exists in 'map0' (that is, map0 is equal * to or a superset of map1). */ -template -bool MatchChannelMap(const al::span map0, const spa_audio_channel (&map1)[N]) +bool MatchChannelMap(const al::span map0, + const al::span map1) { - if(map0.size() < N) + if(map0.size() < map1.size()) return false; for(const spa_audio_channel chid : map1) { @@ -956,6 +967,7 @@ void DeviceNode::parseChannelCount(const spa_pod *value, bool force_update) noex } +/* NOLINTBEGIN(*-avoid-c-arrays) */ constexpr char MonitorPrefix[]{"Monitor of "}; constexpr auto MonitorPrefixLen = std::size(MonitorPrefix) - 1; constexpr char AudioSinkClass[]{"Audio/Sink"}; @@ -963,6 +975,7 @@ constexpr char AudioSourceClass[]{"Audio/Source"}; constexpr char AudioSourceVirtualClass[]{"Audio/Source/Virtual"}; constexpr char AudioDuplexClass[]{"Audio/Duplex"}; constexpr char StreamClass[]{"Stream/"}; +/* NOLINTEND(*-avoid-c-arrays) */ void NodeProxy::infoCallback(const pw_node_info *info) noexcept { @@ -1103,8 +1116,8 @@ int MetadataProxy::propertyCallback(uint32_t id, const char *key, const char *ty return 0; } - spa_json it[2]{}; - spa_json_init(&it[0], value, strlen(value)); + std::array it{}; + spa_json_init(it.data(), value, strlen(value)); if(spa_json_enter_object(&it[0], &it[1]) <= 0) return 0; @@ -1425,7 +1438,7 @@ class PipeWirePlayback final : public BackendBase { public: PipeWirePlayback(DeviceBase *device) noexcept : BackendBase{device} { } - ~PipeWirePlayback() + ~PipeWirePlayback() final { /* Stop the mainloop so the stream can be properly destroyed. */ if(mLoop) mLoop.stop(); @@ -1915,7 +1928,7 @@ class PipeWireCapture final : public BackendBase { public: PipeWireCapture(DeviceBase *device) noexcept : BackendBase{device} { } - ~PipeWireCapture() { if(mLoop) mLoop.stop(); } + ~PipeWireCapture() final { if(mLoop) mLoop.stop(); } DEF_NEWDEL(PipeWireCapture) }; @@ -2057,7 +2070,8 @@ void PipeWireCapture::open(std::string_view name) static constexpr uint32_t pod_buffer_size{1024}; PodDynamicBuilder b(pod_buffer_size); - const spa_pod *params[]{spa_format_audio_raw_build(b.get(), SPA_PARAM_EnumFormat, &info)}; + std::array params{static_cast(spa_format_audio_raw_build(b.get(), + SPA_PARAM_EnumFormat, &info))}; if(!params[0]) throw al::backend_exception{al::backend_error::DeviceError, "Failed to set PipeWire audio format parameters"}; @@ -2099,7 +2113,7 @@ void PipeWireCapture::open(std::string_view name) constexpr pw_stream_flags Flags{PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_INACTIVE | PW_STREAM_FLAG_MAP_BUFFERS | PW_STREAM_FLAG_RT_PROCESS}; - if(int res{pw_stream_connect(mStream.get(), PW_DIRECTION_INPUT, PwIdAny, Flags, params, 1)}) + if(int res{pw_stream_connect(mStream.get(), PW_DIRECTION_INPUT, PwIdAny, Flags, params.data(), 1)}) throw al::backend_exception{al::backend_error::DeviceError, "Error connecting PipeWire stream (res: %d)", res}; @@ -2174,7 +2188,7 @@ bool PipeWireBackendFactory::init() } TRACE("Found PipeWire version \"%s\" (%s or newer)\n", version, pw_get_headers_version()); - pw_init(0, nullptr); + pw_init(nullptr, nullptr); if(!gEventHandler.init()) return false; diff --git a/alc/export_list.h b/alc/export_list.h index c5af1ab0..7856bdc8 100644 --- a/alc/export_list.h +++ b/alc/export_list.h @@ -16,7 +16,8 @@ struct FuncExport { const char *funcName; void *address; }; -#define DECL(x) { #x, reinterpret_cast(x) } +#define DECL(x) FuncExport{#x, reinterpret_cast(x)} +/* NOLINTNEXTLINE(*-avoid-c-arrays) Too large for std::array auto-deduction :( */ inline const FuncExport alcFunctions[]{ DECL(alcCreateContext), DECL(alcMakeContextCurrent), @@ -376,8 +377,9 @@ inline const FuncExport alcFunctions[]{ /* Extra functions */ DECL(alsoft_set_log_callback), +}; #ifdef ALSOFT_EAX -}, eaxFunctions[]{ +inline const std::array eaxFunctions{ DECL(EAXGet), DECL(EAXSet), DECL(EAXGetBufferMode), @@ -387,15 +389,16 @@ inline const FuncExport alcFunctions[]{ DECL(EAXSetDirect), DECL(EAXGetBufferModeDirect), DECL(EAXSetBufferModeDirect), -#endif }; +#endif #undef DECL struct EnumExport { const char *enumName; int value; }; -#define DECL(x) { #x, (x) } +#define DECL(x) EnumExport{#x, (x)} +/* NOLINTNEXTLINE(*-avoid-c-arrays) Too large for std::array auto-deduction :( */ inline const EnumExport alcEnumerations[]{ DECL(ALC_INVALID), DECL(ALC_FALSE), @@ -901,15 +904,16 @@ inline const EnumExport alcEnumerations[]{ DECL(AL_AUXILIARY_EFFECT_SLOT_EXT), DECL(AL_STOP_SOURCES_ON_DISCONNECT_SOFT), +}; #ifdef ALSOFT_EAX -}, eaxEnumerations[]{ +inline const std::array eaxEnumerations{ DECL(AL_EAX_RAM_SIZE), DECL(AL_EAX_RAM_FREE), DECL(AL_STORAGE_AUTOMATIC), DECL(AL_STORAGE_HARDWARE), DECL(AL_STORAGE_ACCESSIBLE), -#endif // ALSOFT_EAX }; +#endif // ALSOFT_EAX #undef DECL #endif /* ALC_EXPORT_LIST_H */ diff --git a/alc/inprogext.h b/alc/inprogext.h index 64d187f1..a150af86 100644 --- a/alc/inprogext.h +++ b/alc/inprogext.h @@ -1,6 +1,7 @@ #ifndef INPROGEXT_H #define INPROGEXT_H +/* NOLINTBEGIN */ #include "AL/al.h" #include "AL/alc.h" #include "AL/alext.h" @@ -436,5 +437,6 @@ void AL_APIENTRY alGetInteger64vDirectSOFT(ALCcontext *context, ALenum pname, AL #ifdef __cplusplus } /* extern "C" */ #endif +/* NOLINTEND */ #endif /* INPROGEXT_H */ diff --git a/common/alspan.h b/common/alspan.h index d91747c2..37b475d2 100644 --- a/common/alspan.h +++ b/common/alspan.h @@ -44,7 +44,7 @@ namespace detail_ { && !std::is_array::value && has_size_and_data; template - constexpr bool is_array_compatible = std::is_convertible::value; + constexpr bool is_array_compatible = std::is_convertible::value; /* NOLINT(*-avoid-c-arrays) */ template constexpr bool is_valid_container = is_valid_container_type @@ -81,7 +81,7 @@ public: constexpr explicit span(U first, V) : mData{::al::to_address(first)} {} - constexpr span(type_identity_t (&arr)[E]) noexcept + constexpr span(type_identity_t (&arr)[E]) noexcept /* NOLINT(*-avoid-c-arrays) */ : span{std::data(arr), std::size(arr)} { } constexpr span(std::array &arr) noexcept @@ -199,7 +199,7 @@ public: { } template - constexpr span(type_identity_t (&arr)[N]) noexcept + constexpr span(type_identity_t (&arr)[N]) noexcept /* NOLINT(*-avoid-c-arrays) */ : span{std::data(arr), std::size(arr)} { } template @@ -305,7 +305,7 @@ template span(T, EndOrSize) -> span())>>; template -span(T (&)[N]) -> span; +span(T (&)[N]) -> span; /* NOLINT(*-avoid-c-arrays) */ template span(std::array&) -> span; diff --git a/core/helpers.h b/core/helpers.h index df51c116..64fc67fb 100644 --- a/core/helpers.h +++ b/core/helpers.h @@ -15,11 +15,11 @@ struct PathNamePair { : path{std::forward(path_)}, fname{std::forward(fname_)} { } }; -const PathNamePair &GetProcBinary(void); +const PathNamePair &GetProcBinary(); extern int RTPrioLevel; extern bool AllowRTTimeLimit; -void SetRTPriority(void); +void SetRTPriority(); std::vector SearchDataFiles(const char *match, const char *subdir); -- cgit v1.2.3 From bb3387b0fc5d3071a30c6d003b415dc6e77f3d62 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 10 Dec 2023 22:15:17 -0800 Subject: Much more clang-tidy cleanup --- al/auxeffectslot.cpp | 40 ++-- al/debug.cpp | 2 +- al/eax/call.cpp | 3 +- al/eax/call.h | 14 +- al/effect.cpp | 47 ++--- al/filter.cpp | 2 +- al/state.cpp | 2 + alc/backends/null.cpp | 1 + alc/backends/pipewire.cpp | 12 +- alc/backends/portaudio.cpp | 3 +- alc/backends/sdl2.cpp | 3 +- alc/context.cpp | 2 +- alc/device.cpp | 2 +- alc/effects/convolution.cpp | 2 +- alc/effects/null.cpp | 2 +- alc/panning.cpp | 247 +++++++++++++------------ common/phase_shifter.h | 10 +- common/ringbuffer.cpp | 2 +- core/ambdec.cpp | 31 ++-- core/ambdec.h | 10 +- core/buffer_storage.cpp | 2 +- core/converter.cpp | 26 +-- core/converter.h | 16 +- core/cubic_tables.cpp | 4 +- core/dbus_wrap.cpp | 2 +- core/effectslot.cpp | 2 +- core/filters/biquad.cpp | 4 +- core/filters/nfc.cpp | 12 +- core/helpers.cpp | 2 +- core/hrtf.cpp | 57 +++--- core/hrtf.h | 3 +- core/mastering.cpp | 11 +- core/mixer/mixer_neon.cpp | 7 +- core/mixer/mixer_sse2.cpp | 2 +- core/mixer/mixer_sse41.cpp | 2 +- core/rtkit.cpp | 4 +- core/uhjfilter.cpp | 14 +- examples/alffplay.cpp | 52 +++--- examples/alstreamcb.cpp | 32 ++-- include/AL/al.h | 2 + include/AL/alc.h | 2 + include/AL/alext.h | 2 + include/AL/efx-presets.h | 2 + include/AL/efx.h | 2 + utils/alsoft-config/mainwindow.h | 25 ++- utils/makemhr/loaddef.cpp | 385 +++++++++++++++++++-------------------- utils/makemhr/loadsofa.cpp | 20 +- utils/makemhr/makemhr.cpp | 37 ++-- utils/makemhr/makemhr.h | 4 +- utils/sofa-info.cpp | 3 +- utils/sofa-support.cpp | 8 +- utils/uhjdecoder.cpp | 32 ++-- utils/uhjencoder.cpp | 95 +++++----- 53 files changed, 659 insertions(+), 651 deletions(-) (limited to 'al/eax') diff --git a/al/auxeffectslot.cpp b/al/auxeffectslot.cpp index 7b7672a5..02c061a4 100644 --- a/al/auxeffectslot.cpp +++ b/al/auxeffectslot.cpp @@ -55,31 +55,31 @@ namespace { struct FactoryItem { EffectSlotType Type; - EffectStateFactory* (&GetFactory)(void); + EffectStateFactory* (&GetFactory)(); }; -constexpr FactoryItem FactoryList[] = { - { EffectSlotType::None, NullStateFactory_getFactory }, - { EffectSlotType::EAXReverb, ReverbStateFactory_getFactory }, - { EffectSlotType::Reverb, StdReverbStateFactory_getFactory }, - { EffectSlotType::Autowah, AutowahStateFactory_getFactory }, - { EffectSlotType::Chorus, ChorusStateFactory_getFactory }, - { EffectSlotType::Compressor, CompressorStateFactory_getFactory }, - { EffectSlotType::Distortion, DistortionStateFactory_getFactory }, - { EffectSlotType::Echo, EchoStateFactory_getFactory }, - { EffectSlotType::Equalizer, EqualizerStateFactory_getFactory }, - { EffectSlotType::Flanger, FlangerStateFactory_getFactory }, - { EffectSlotType::FrequencyShifter, FshifterStateFactory_getFactory }, - { EffectSlotType::RingModulator, ModulatorStateFactory_getFactory }, - { EffectSlotType::PitchShifter, PshifterStateFactory_getFactory }, - { EffectSlotType::VocalMorpher, VmorpherStateFactory_getFactory }, - { EffectSlotType::DedicatedDialog, DedicatedStateFactory_getFactory }, - { EffectSlotType::DedicatedLFE, DedicatedStateFactory_getFactory }, - { EffectSlotType::Convolution, ConvolutionStateFactory_getFactory }, +constexpr std::array FactoryList{ + FactoryItem{EffectSlotType::None, NullStateFactory_getFactory}, + FactoryItem{EffectSlotType::EAXReverb, ReverbStateFactory_getFactory}, + FactoryItem{EffectSlotType::Reverb, StdReverbStateFactory_getFactory}, + FactoryItem{EffectSlotType::Autowah, AutowahStateFactory_getFactory}, + FactoryItem{EffectSlotType::Chorus, ChorusStateFactory_getFactory}, + FactoryItem{EffectSlotType::Compressor, CompressorStateFactory_getFactory}, + FactoryItem{EffectSlotType::Distortion, DistortionStateFactory_getFactory}, + FactoryItem{EffectSlotType::Echo, EchoStateFactory_getFactory}, + FactoryItem{EffectSlotType::Equalizer, EqualizerStateFactory_getFactory}, + FactoryItem{EffectSlotType::Flanger, FlangerStateFactory_getFactory}, + FactoryItem{EffectSlotType::FrequencyShifter, FshifterStateFactory_getFactory}, + FactoryItem{EffectSlotType::RingModulator, ModulatorStateFactory_getFactory}, + FactoryItem{EffectSlotType::PitchShifter, PshifterStateFactory_getFactory}, + FactoryItem{EffectSlotType::VocalMorpher, VmorpherStateFactory_getFactory}, + FactoryItem{EffectSlotType::DedicatedDialog, DedicatedStateFactory_getFactory}, + FactoryItem{EffectSlotType::DedicatedLFE, DedicatedStateFactory_getFactory}, + FactoryItem{EffectSlotType::Convolution, ConvolutionStateFactory_getFactory}, }; EffectStateFactory *getFactoryByType(EffectSlotType type) { - auto iter = std::find_if(std::begin(FactoryList), std::end(FactoryList), + auto iter = std::find_if(FactoryList.begin(), FactoryList.end(), [type](const FactoryItem &item) noexcept -> bool { return item.Type == type; }); return (iter != std::end(FactoryList)) ? iter->GetFactory() : nullptr; diff --git a/al/debug.cpp b/al/debug.cpp index b76ec9af..cd79c148 100644 --- a/al/debug.cpp +++ b/al/debug.cpp @@ -4,10 +4,10 @@ #include #include +#include #include #include #include -#include #include #include #include diff --git a/al/eax/call.cpp b/al/eax/call.cpp index 689d5cf1..013a3992 100644 --- a/al/eax/call.cpp +++ b/al/eax/call.cpp @@ -22,8 +22,7 @@ EaxCall::EaxCall( ALuint property_source_id, ALvoid* property_buffer, ALuint property_size) - : mCallType{type}, mVersion{0}, mPropertySetId{EaxCallPropertySetId::none} - , mIsDeferred{(property_id & deferred_flag) != 0} + : mCallType{type}, mIsDeferred{(property_id & deferred_flag) != 0} , mPropertyId{property_id & ~deferred_flag}, mPropertySourceId{property_source_id} , mPropertyBuffer{property_buffer}, mPropertyBufferSize{property_size} { diff --git a/al/eax/call.h b/al/eax/call.h index 04e94f3e..e7f2329f 100644 --- a/al/eax/call.h +++ b/al/eax/call.h @@ -71,16 +71,16 @@ public: } private: - const EaxCallType mCallType{}; + const EaxCallType mCallType; int mVersion{}; EaxFxSlotIndex mFxSlotIndex{}; - EaxCallPropertySetId mPropertySetId{}; - bool mIsDeferred{}; + EaxCallPropertySetId mPropertySetId{EaxCallPropertySetId::none}; + bool mIsDeferred; - const ALuint mPropertyId{}; - const ALuint mPropertySourceId{}; - ALvoid*const mPropertyBuffer{}; - const ALuint mPropertyBufferSize{}; + const ALuint mPropertyId; + const ALuint mPropertySourceId; + ALvoid*const mPropertyBuffer; + const ALuint mPropertyBufferSize; [[noreturn]] static void fail(const char* message); [[noreturn]] static void fail_too_small(); diff --git a/al/effect.cpp b/al/effect.cpp index e99226c8..7cd6a67b 100644 --- a/al/effect.cpp +++ b/al/effect.cpp @@ -94,24 +94,24 @@ struct EffectPropsItem { const EffectProps &DefaultProps; const EffectVtable &Vtable; }; -constexpr EffectPropsItem EffectPropsList[] = { - { AL_EFFECT_NULL, NullEffectProps, NullEffectVtable }, - { AL_EFFECT_EAXREVERB, ReverbEffectProps, ReverbEffectVtable }, - { AL_EFFECT_REVERB, StdReverbEffectProps, StdReverbEffectVtable }, - { AL_EFFECT_AUTOWAH, AutowahEffectProps, AutowahEffectVtable }, - { AL_EFFECT_CHORUS, ChorusEffectProps, ChorusEffectVtable }, - { AL_EFFECT_COMPRESSOR, CompressorEffectProps, CompressorEffectVtable }, - { AL_EFFECT_DISTORTION, DistortionEffectProps, DistortionEffectVtable }, - { AL_EFFECT_ECHO, EchoEffectProps, EchoEffectVtable }, - { AL_EFFECT_EQUALIZER, EqualizerEffectProps, EqualizerEffectVtable }, - { AL_EFFECT_FLANGER, FlangerEffectProps, FlangerEffectVtable }, - { AL_EFFECT_FREQUENCY_SHIFTER, FshifterEffectProps, FshifterEffectVtable }, - { AL_EFFECT_RING_MODULATOR, ModulatorEffectProps, ModulatorEffectVtable }, - { AL_EFFECT_PITCH_SHIFTER, PshifterEffectProps, PshifterEffectVtable }, - { AL_EFFECT_VOCAL_MORPHER, VmorpherEffectProps, VmorpherEffectVtable }, - { AL_EFFECT_DEDICATED_DIALOGUE, DedicatedEffectProps, DedicatedEffectVtable }, - { AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT, DedicatedEffectProps, DedicatedEffectVtable }, - { AL_EFFECT_CONVOLUTION_SOFT, ConvolutionEffectProps, ConvolutionEffectVtable }, +constexpr std::array EffectPropsList{ + EffectPropsItem{AL_EFFECT_NULL, NullEffectProps, NullEffectVtable}, + EffectPropsItem{AL_EFFECT_EAXREVERB, ReverbEffectProps, ReverbEffectVtable}, + EffectPropsItem{AL_EFFECT_REVERB, StdReverbEffectProps, StdReverbEffectVtable}, + EffectPropsItem{AL_EFFECT_AUTOWAH, AutowahEffectProps, AutowahEffectVtable}, + EffectPropsItem{AL_EFFECT_CHORUS, ChorusEffectProps, ChorusEffectVtable}, + EffectPropsItem{AL_EFFECT_COMPRESSOR, CompressorEffectProps, CompressorEffectVtable}, + EffectPropsItem{AL_EFFECT_DISTORTION, DistortionEffectProps, DistortionEffectVtable}, + EffectPropsItem{AL_EFFECT_ECHO, EchoEffectProps, EchoEffectVtable}, + EffectPropsItem{AL_EFFECT_EQUALIZER, EqualizerEffectProps, EqualizerEffectVtable}, + EffectPropsItem{AL_EFFECT_FLANGER, FlangerEffectProps, FlangerEffectVtable}, + EffectPropsItem{AL_EFFECT_FREQUENCY_SHIFTER, FshifterEffectProps, FshifterEffectVtable}, + EffectPropsItem{AL_EFFECT_RING_MODULATOR, ModulatorEffectProps, ModulatorEffectVtable}, + EffectPropsItem{AL_EFFECT_PITCH_SHIFTER, PshifterEffectProps, PshifterEffectVtable}, + EffectPropsItem{AL_EFFECT_VOCAL_MORPHER, VmorpherEffectProps, VmorpherEffectVtable}, + EffectPropsItem{AL_EFFECT_DEDICATED_DIALOGUE, DedicatedEffectProps, DedicatedEffectVtable}, + EffectPropsItem{AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT, DedicatedEffectProps, DedicatedEffectVtable}, + EffectPropsItem{AL_EFFECT_CONVOLUTION_SOFT, ConvolutionEffectProps, ConvolutionEffectVtable}, }; @@ -136,7 +136,7 @@ void ALeffect_getParamfv(const ALeffect *effect, ALenum param, float *values) const EffectPropsItem *getEffectPropsItemByType(ALenum type) { - auto iter = std::find_if(std::begin(EffectPropsList), std::end(EffectPropsList), + auto iter = std::find_if(EffectPropsList.begin(), EffectPropsList.end(), [type](const EffectPropsItem &item) noexcept -> bool { return item.Type == type; }); return (iter != std::end(EffectPropsList)) ? al::to_address(iter) : nullptr; @@ -542,11 +542,12 @@ EffectSubList::~EffectSubList() } -#define DECL(x) { #x, EFX_REVERB_PRESET_##x } -static const struct { - const char name[32]; +struct EffectPreset { + const char name[32]; /* NOLINT(*-avoid-c-arrays) */ EFXEAXREVERBPROPERTIES props; -} reverblist[] = { +}; +#define DECL(x) EffectPreset{#x, EFX_REVERB_PRESET_##x} +static constexpr std::array reverblist{ DECL(GENERIC), DECL(PADDEDCELL), DECL(ROOM), diff --git a/al/filter.cpp b/al/filter.cpp index 4f79db7d..9c8e4c62 100644 --- a/al/filter.cpp +++ b/al/filter.cpp @@ -61,7 +61,7 @@ public: filter_exception(ALenum code, const char *msg, ...); ~filter_exception() override; - ALenum errorCode() const noexcept { return mErrorCode; } + [[nodiscard]] auto errorCode() const noexcept -> ALenum { return mErrorCode; } }; filter_exception::filter_exception(ALenum code, const char* msg, ...) : mErrorCode{code} diff --git a/al/state.cpp b/al/state.cpp index 5131edd9..fd5dc5e3 100644 --- a/al/state.cpp +++ b/al/state.cpp @@ -60,6 +60,7 @@ namespace { +/* NOLINTBEGIN(*-avoid-c-arrays) */ constexpr ALchar alVendor[] = "OpenAL Community"; constexpr ALchar alVersion[] = "1.1 ALSOFT " ALSOFT_VERSION; constexpr ALchar alRenderer[] = "OpenAL Soft"; @@ -73,6 +74,7 @@ constexpr ALchar alErrInvalidOp[] = "Invalid Operation"; constexpr ALchar alErrOutOfMemory[] = "Out of Memory"; constexpr ALchar alStackOverflow[] = "Stack Overflow"; constexpr ALchar alStackUnderflow[] = "Stack Underflow"; +/* NOLINTEND(*-avoid-c-arrays) */ /* Resampler strings */ template struct ResamplerName { }; diff --git a/alc/backends/null.cpp b/alc/backends/null.cpp index 3c68e4ce..c149820c 100644 --- a/alc/backends/null.cpp +++ b/alc/backends/null.cpp @@ -42,6 +42,7 @@ using std::chrono::seconds; using std::chrono::milliseconds; using std::chrono::nanoseconds; +/* NOLINTNEXTLINE(*-avoid-c-arrays) */ constexpr char nullDevice[] = "No Output"; diff --git a/alc/backends/pipewire.cpp b/alc/backends/pipewire.cpp index d934071e..2c726cbe 100644 --- a/alc/backends/pipewire.cpp +++ b/alc/backends/pipewire.cpp @@ -1420,8 +1420,7 @@ class PipeWirePlayback final : public BackendBase { PwStreamPtr mStream; spa_hook mStreamListener{}; spa_io_rate_match *mRateMatch{}; - std::unique_ptr mChannelPtrs; - uint mNumChannels{}; + std::vector mChannelPtrs; static constexpr pw_stream_events CreateEvents() { @@ -1468,7 +1467,7 @@ void PipeWirePlayback::outputCallback() noexcept if(!pw_buf) UNLIKELY return; const al::span datas{pw_buf->buffer->datas, - minu(mNumChannels, pw_buf->buffer->n_datas)}; + minz(mChannelPtrs.size(), pw_buf->buffer->n_datas)}; #if PW_CHECK_VERSION(0,3,49) /* In 0.3.49, pw_buffer::requested specifies the number of samples needed * by the resampler/graph for this audio update. @@ -1488,7 +1487,7 @@ void PipeWirePlayback::outputCallback() noexcept * buffer length in any one channel is smaller than we wanted (shouldn't * be, but just in case). */ - float **chanptr_end{mChannelPtrs.get()}; + auto chanptr_end = mChannelPtrs.begin(); for(const auto &data : datas) { length = minu(length, data.maxsize/sizeof(float)); @@ -1500,7 +1499,7 @@ void PipeWirePlayback::outputCallback() noexcept data.chunk->size = length * sizeof(float); } - mDevice->renderSamples({mChannelPtrs.get(), chanptr_end}, length); + mDevice->renderSamples(mChannelPtrs, length); pw_buf->size = length; pw_stream_queue_buffer(mStream.get(), pw_buf); @@ -1711,8 +1710,7 @@ bool PipeWirePlayback::reset() */ plock.unlock(); - mNumChannels = mDevice->channelsFromFmt(); - mChannelPtrs = std::make_unique(mNumChannels); + mChannelPtrs.resize(mDevice->channelsFromFmt()); setDefaultWFXChannelOrder(); diff --git a/alc/backends/portaudio.cpp b/alc/backends/portaudio.cpp index 2e2e33cc..554efe9a 100644 --- a/alc/backends/portaudio.cpp +++ b/alc/backends/portaudio.cpp @@ -39,7 +39,8 @@ namespace { -constexpr char pa_device[] = "PortAudio Default"; +/* NOLINTNEXTLINE(*-avoid-c-arrays) */ +constexpr char pa_device[]{"PortAudio Default"}; #ifdef HAVE_DYNLOAD diff --git a/alc/backends/sdl2.cpp b/alc/backends/sdl2.cpp index f5ed4316..d7f66d93 100644 --- a/alc/backends/sdl2.cpp +++ b/alc/backends/sdl2.cpp @@ -46,7 +46,8 @@ namespace { #define DEVNAME_PREFIX "" #endif -constexpr char defaultDeviceName[] = DEVNAME_PREFIX "Default Device"; +/* NOLINTNEXTLINE(*-avoid-c-arrays) */ +constexpr char defaultDeviceName[]{DEVNAME_PREFIX "Default Device"}; struct Sdl2Backend final : public BackendBase { Sdl2Backend(DeviceBase *device) noexcept : BackendBase{device} { } diff --git a/alc/context.cpp b/alc/context.cpp index 2e67f9ac..92e458cb 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -5,11 +5,11 @@ #include #include +#include #include #include #include #include -#include #include #include #include diff --git a/alc/device.cpp b/alc/device.cpp index 27aa6f36..5a34ad64 100644 --- a/alc/device.cpp +++ b/alc/device.cpp @@ -3,8 +3,8 @@ #include "device.h" +#include #include -#include #include "albit.h" #include "alconfig.h" diff --git a/alc/effects/convolution.cpp b/alc/effects/convolution.cpp index 5e81f6d1..c877456d 100644 --- a/alc/effects/convolution.cpp +++ b/alc/effects/convolution.cpp @@ -5,10 +5,10 @@ #include #include #include +#include #include #include #include -#include #include #ifdef HAVE_SSE_INTRINSICS diff --git a/alc/effects/null.cpp b/alc/effects/null.cpp index 1f9ae67b..12d1688e 100644 --- a/alc/effects/null.cpp +++ b/alc/effects/null.cpp @@ -1,7 +1,7 @@ #include "config.h" -#include +#include #include "almalloc.h" #include "alspan.h" diff --git a/alc/panning.cpp b/alc/panning.cpp index add07051..c0fe83ee 100644 --- a/alc/panning.cpp +++ b/alc/panning.cpp @@ -227,10 +227,10 @@ struct DecoderConfig { using DecoderView = DecoderConfig; -void InitNearFieldCtrl(ALCdevice *device, float ctrl_dist, uint order, bool is3d) +void InitNearFieldCtrl(ALCdevice *device, const float ctrl_dist, const uint order, const bool is3d) { - static const uint chans_per_order2d[MaxAmbiOrder+1]{ 1, 2, 2, 2 }; - static const uint chans_per_order3d[MaxAmbiOrder+1]{ 1, 3, 5, 7 }; + static const std::array chans_per_order2d{{1, 2, 2, 2}}; + static const std::array chans_per_order3d{{1, 3, 5, 7}}; /* NFC is only used when AvgSpeakerDist is greater than 0. */ if(!device->getConfigValueBool("decoder", "nfc", false) || !(ctrl_dist > 0.0f)) @@ -243,7 +243,7 @@ void InitNearFieldCtrl(ALCdevice *device, float ctrl_dist, uint order, bool is3d (device->AvgSpeakerDist * static_cast(device->Frequency))}; device->mNFCtrlFilter.init(w1); - auto iter = std::copy_n(is3d ? chans_per_order3d : chans_per_order2d, order+1u, + auto iter = std::copy_n(is3d ? chans_per_order3d.begin() : chans_per_order2d.begin(), order+1u, std::begin(device->NumChannelsPerOrder)); std::fill(iter, std::end(device->NumChannelsPerOrder), 0u); } @@ -361,8 +361,7 @@ DecoderView MakeDecoderView(ALCdevice *device, const AmbDecConf *conf, const auto lfmatrix = conf->LFMatrix; uint chan_count{0}; - using const_speaker_span = al::span; - for(auto &speaker : const_speaker_span{conf->Speakers.get(), conf->NumSpeakers}) + for(auto &speaker : al::span{conf->Speakers}) { /* NOTE: AmbDec does not define any standard speaker names, however * for this to work we have to by able to find the output channel @@ -708,120 +707,126 @@ void InitPanning(ALCdevice *device, const bool hqdec=false, const bool stablize= void InitHrtfPanning(ALCdevice *device) { - constexpr float Deg180{al::numbers::pi_v}; - constexpr float Deg_90{Deg180 / 2.0f /* 90 degrees*/}; - constexpr float Deg_45{Deg_90 / 2.0f /* 45 degrees*/}; - constexpr float Deg135{Deg_45 * 3.0f /*135 degrees*/}; - constexpr float Deg_21{3.648638281e-01f /* 20~ 21 degrees*/}; - constexpr float Deg_32{5.535743589e-01f /* 31~ 32 degrees*/}; - constexpr float Deg_35{6.154797087e-01f /* 35~ 36 degrees*/}; - constexpr float Deg_58{1.017221968e+00f /* 58~ 59 degrees*/}; - constexpr float Deg_69{1.205932499e+00f /* 69~ 70 degrees*/}; - constexpr float Deg111{1.935660155e+00f /*110~111 degrees*/}; - constexpr float Deg122{2.124370686e+00f /*121~122 degrees*/}; - static const AngularPoint AmbiPoints1O[]{ - { EvRadians{ Deg_35}, AzRadians{-Deg_45} }, - { EvRadians{ Deg_35}, AzRadians{-Deg135} }, - { EvRadians{ Deg_35}, AzRadians{ Deg_45} }, - { EvRadians{ Deg_35}, AzRadians{ Deg135} }, - { EvRadians{-Deg_35}, AzRadians{-Deg_45} }, - { EvRadians{-Deg_35}, AzRadians{-Deg135} }, - { EvRadians{-Deg_35}, AzRadians{ Deg_45} }, - { EvRadians{-Deg_35}, AzRadians{ Deg135} }, - }, AmbiPoints2O[]{ - { EvRadians{-Deg_32}, AzRadians{ 0.0f} }, - { EvRadians{ 0.0f}, AzRadians{ Deg_58} }, - { EvRadians{ Deg_58}, AzRadians{ Deg_90} }, - { EvRadians{ Deg_32}, AzRadians{ 0.0f} }, - { EvRadians{ 0.0f}, AzRadians{ Deg122} }, - { EvRadians{-Deg_58}, AzRadians{-Deg_90} }, - { EvRadians{-Deg_32}, AzRadians{ Deg180} }, - { EvRadians{ 0.0f}, AzRadians{-Deg122} }, - { EvRadians{ Deg_58}, AzRadians{-Deg_90} }, - { EvRadians{ Deg_32}, AzRadians{ Deg180} }, - { EvRadians{ 0.0f}, AzRadians{-Deg_58} }, - { EvRadians{-Deg_58}, AzRadians{ Deg_90} }, - }, AmbiPoints3O[]{ - { EvRadians{ Deg_69}, AzRadians{-Deg_90} }, - { EvRadians{ Deg_69}, AzRadians{ Deg_90} }, - { EvRadians{-Deg_69}, AzRadians{-Deg_90} }, - { EvRadians{-Deg_69}, AzRadians{ Deg_90} }, - { EvRadians{ 0.0f}, AzRadians{-Deg_69} }, - { EvRadians{ 0.0f}, AzRadians{-Deg111} }, - { EvRadians{ 0.0f}, AzRadians{ Deg_69} }, - { EvRadians{ 0.0f}, AzRadians{ Deg111} }, - { EvRadians{ Deg_21}, AzRadians{ 0.0f} }, - { EvRadians{ Deg_21}, AzRadians{ Deg180} }, - { EvRadians{-Deg_21}, AzRadians{ 0.0f} }, - { EvRadians{-Deg_21}, AzRadians{ Deg180} }, - { EvRadians{ Deg_35}, AzRadians{-Deg_45} }, - { EvRadians{ Deg_35}, AzRadians{-Deg135} }, - { EvRadians{ Deg_35}, AzRadians{ Deg_45} }, - { EvRadians{ Deg_35}, AzRadians{ Deg135} }, - { EvRadians{-Deg_35}, AzRadians{-Deg_45} }, - { EvRadians{-Deg_35}, AzRadians{-Deg135} }, - { EvRadians{-Deg_35}, AzRadians{ Deg_45} }, - { EvRadians{-Deg_35}, AzRadians{ Deg135} }, + static constexpr float Deg180{al::numbers::pi_v}; + static constexpr float Deg_90{Deg180 / 2.0f /* 90 degrees*/}; + static constexpr float Deg_45{Deg_90 / 2.0f /* 45 degrees*/}; + static constexpr float Deg135{Deg_45 * 3.0f /*135 degrees*/}; + static constexpr float Deg_21{3.648638281e-01f /* 20~ 21 degrees*/}; + static constexpr float Deg_32{5.535743589e-01f /* 31~ 32 degrees*/}; + static constexpr float Deg_35{6.154797087e-01f /* 35~ 36 degrees*/}; + static constexpr float Deg_58{1.017221968e+00f /* 58~ 59 degrees*/}; + static constexpr float Deg_69{1.205932499e+00f /* 69~ 70 degrees*/}; + static constexpr float Deg111{1.935660155e+00f /*110~111 degrees*/}; + static constexpr float Deg122{2.124370686e+00f /*121~122 degrees*/}; + static constexpr std::array AmbiPoints1O{ + AngularPoint{EvRadians{ Deg_35}, AzRadians{-Deg_45}}, + AngularPoint{EvRadians{ Deg_35}, AzRadians{-Deg135}}, + AngularPoint{EvRadians{ Deg_35}, AzRadians{ Deg_45}}, + AngularPoint{EvRadians{ Deg_35}, AzRadians{ Deg135}}, + AngularPoint{EvRadians{-Deg_35}, AzRadians{-Deg_45}}, + AngularPoint{EvRadians{-Deg_35}, AzRadians{-Deg135}}, + AngularPoint{EvRadians{-Deg_35}, AzRadians{ Deg_45}}, + AngularPoint{EvRadians{-Deg_35}, AzRadians{ Deg135}}, }; - static const float AmbiMatrix1O[][MaxAmbiChannels]{ - { 1.250000000e-01f, 1.250000000e-01f, 1.250000000e-01f, 1.250000000e-01f }, - { 1.250000000e-01f, 1.250000000e-01f, 1.250000000e-01f, -1.250000000e-01f }, - { 1.250000000e-01f, -1.250000000e-01f, 1.250000000e-01f, 1.250000000e-01f }, - { 1.250000000e-01f, -1.250000000e-01f, 1.250000000e-01f, -1.250000000e-01f }, - { 1.250000000e-01f, 1.250000000e-01f, -1.250000000e-01f, 1.250000000e-01f }, - { 1.250000000e-01f, 1.250000000e-01f, -1.250000000e-01f, -1.250000000e-01f }, - { 1.250000000e-01f, -1.250000000e-01f, -1.250000000e-01f, 1.250000000e-01f }, - { 1.250000000e-01f, -1.250000000e-01f, -1.250000000e-01f, -1.250000000e-01f }, - }, AmbiMatrix2O[][MaxAmbiChannels]{ - { 8.333333333e-02f, 0.000000000e+00f, -7.588274978e-02f, 1.227808683e-01f, 0.000000000e+00f, 0.000000000e+00f, -1.591525047e-02f, -1.443375673e-01f, 1.167715449e-01f, }, - { 8.333333333e-02f, -1.227808683e-01f, 0.000000000e+00f, 7.588274978e-02f, -1.443375673e-01f, 0.000000000e+00f, -9.316949906e-02f, 0.000000000e+00f, -7.216878365e-02f, }, - { 8.333333333e-02f, -7.588274978e-02f, 1.227808683e-01f, 0.000000000e+00f, 0.000000000e+00f, -1.443375673e-01f, 1.090847495e-01f, 0.000000000e+00f, -4.460276122e-02f, }, - { 8.333333333e-02f, 0.000000000e+00f, 7.588274978e-02f, 1.227808683e-01f, 0.000000000e+00f, 0.000000000e+00f, -1.591525047e-02f, 1.443375673e-01f, 1.167715449e-01f, }, - { 8.333333333e-02f, -1.227808683e-01f, 0.000000000e+00f, -7.588274978e-02f, 1.443375673e-01f, 0.000000000e+00f, -9.316949906e-02f, 0.000000000e+00f, -7.216878365e-02f, }, - { 8.333333333e-02f, 7.588274978e-02f, -1.227808683e-01f, 0.000000000e+00f, 0.000000000e+00f, -1.443375673e-01f, 1.090847495e-01f, 0.000000000e+00f, -4.460276122e-02f, }, - { 8.333333333e-02f, 0.000000000e+00f, -7.588274978e-02f, -1.227808683e-01f, 0.000000000e+00f, 0.000000000e+00f, -1.591525047e-02f, 1.443375673e-01f, 1.167715449e-01f, }, - { 8.333333333e-02f, 1.227808683e-01f, 0.000000000e+00f, -7.588274978e-02f, -1.443375673e-01f, 0.000000000e+00f, -9.316949906e-02f, 0.000000000e+00f, -7.216878365e-02f, }, - { 8.333333333e-02f, 7.588274978e-02f, 1.227808683e-01f, 0.000000000e+00f, 0.000000000e+00f, 1.443375673e-01f, 1.090847495e-01f, 0.000000000e+00f, -4.460276122e-02f, }, - { 8.333333333e-02f, 0.000000000e+00f, 7.588274978e-02f, -1.227808683e-01f, 0.000000000e+00f, 0.000000000e+00f, -1.591525047e-02f, -1.443375673e-01f, 1.167715449e-01f, }, - { 8.333333333e-02f, 1.227808683e-01f, 0.000000000e+00f, 7.588274978e-02f, 1.443375673e-01f, 0.000000000e+00f, -9.316949906e-02f, 0.000000000e+00f, -7.216878365e-02f, }, - { 8.333333333e-02f, -7.588274978e-02f, -1.227808683e-01f, 0.000000000e+00f, 0.000000000e+00f, 1.443375673e-01f, 1.090847495e-01f, 0.000000000e+00f, -4.460276122e-02f, }, - }, AmbiMatrix3O[][MaxAmbiChannels]{ - { 5.000000000e-02f, 3.090169944e-02f, 8.090169944e-02f, 0.000000000e+00f, 0.000000000e+00f, 6.454972244e-02f, 9.045084972e-02f, 0.000000000e+00f, -1.232790000e-02f, -1.256118221e-01f, 0.000000000e+00f, 1.126112056e-01f, 7.944389175e-02f, 0.000000000e+00f, 2.421151497e-02f, 0.000000000e+00f, }, - { 5.000000000e-02f, -3.090169944e-02f, 8.090169944e-02f, 0.000000000e+00f, 0.000000000e+00f, -6.454972244e-02f, 9.045084972e-02f, 0.000000000e+00f, -1.232790000e-02f, 1.256118221e-01f, 0.000000000e+00f, -1.126112056e-01f, 7.944389175e-02f, 0.000000000e+00f, 2.421151497e-02f, 0.000000000e+00f, }, - { 5.000000000e-02f, 3.090169944e-02f, -8.090169944e-02f, 0.000000000e+00f, 0.000000000e+00f, -6.454972244e-02f, 9.045084972e-02f, 0.000000000e+00f, -1.232790000e-02f, -1.256118221e-01f, 0.000000000e+00f, 1.126112056e-01f, -7.944389175e-02f, 0.000000000e+00f, -2.421151497e-02f, 0.000000000e+00f, }, - { 5.000000000e-02f, -3.090169944e-02f, -8.090169944e-02f, 0.000000000e+00f, 0.000000000e+00f, 6.454972244e-02f, 9.045084972e-02f, 0.000000000e+00f, -1.232790000e-02f, 1.256118221e-01f, 0.000000000e+00f, -1.126112056e-01f, -7.944389175e-02f, 0.000000000e+00f, -2.421151497e-02f, 0.000000000e+00f, }, - { 5.000000000e-02f, 8.090169944e-02f, 0.000000000e+00f, 3.090169944e-02f, 6.454972244e-02f, 0.000000000e+00f, -5.590169944e-02f, 0.000000000e+00f, -7.216878365e-02f, -7.763237543e-02f, 0.000000000e+00f, -2.950836627e-02f, 0.000000000e+00f, -1.497759251e-01f, 0.000000000e+00f, -7.763237543e-02f, }, - { 5.000000000e-02f, 8.090169944e-02f, 0.000000000e+00f, -3.090169944e-02f, -6.454972244e-02f, 0.000000000e+00f, -5.590169944e-02f, 0.000000000e+00f, -7.216878365e-02f, -7.763237543e-02f, 0.000000000e+00f, -2.950836627e-02f, 0.000000000e+00f, 1.497759251e-01f, 0.000000000e+00f, 7.763237543e-02f, }, - { 5.000000000e-02f, -8.090169944e-02f, 0.000000000e+00f, 3.090169944e-02f, -6.454972244e-02f, 0.000000000e+00f, -5.590169944e-02f, 0.000000000e+00f, -7.216878365e-02f, 7.763237543e-02f, 0.000000000e+00f, 2.950836627e-02f, 0.000000000e+00f, -1.497759251e-01f, 0.000000000e+00f, -7.763237543e-02f, }, - { 5.000000000e-02f, -8.090169944e-02f, 0.000000000e+00f, -3.090169944e-02f, 6.454972244e-02f, 0.000000000e+00f, -5.590169944e-02f, 0.000000000e+00f, -7.216878365e-02f, 7.763237543e-02f, 0.000000000e+00f, 2.950836627e-02f, 0.000000000e+00f, 1.497759251e-01f, 0.000000000e+00f, 7.763237543e-02f, }, - { 5.000000000e-02f, 0.000000000e+00f, 3.090169944e-02f, 8.090169944e-02f, 0.000000000e+00f, 0.000000000e+00f, -3.454915028e-02f, 6.454972244e-02f, 8.449668365e-02f, 0.000000000e+00f, 0.000000000e+00f, 0.000000000e+00f, 3.034486645e-02f, -6.779013272e-02f, 1.659481923e-01f, 4.797944664e-02f, }, - { 5.000000000e-02f, 0.000000000e+00f, 3.090169944e-02f, -8.090169944e-02f, 0.000000000e+00f, 0.000000000e+00f, -3.454915028e-02f, -6.454972244e-02f, 8.449668365e-02f, 0.000000000e+00f, 0.000000000e+00f, 0.000000000e+00f, 3.034486645e-02f, 6.779013272e-02f, 1.659481923e-01f, -4.797944664e-02f, }, - { 5.000000000e-02f, 0.000000000e+00f, -3.090169944e-02f, 8.090169944e-02f, 0.000000000e+00f, 0.000000000e+00f, -3.454915028e-02f, -6.454972244e-02f, 8.449668365e-02f, 0.000000000e+00f, 0.000000000e+00f, 0.000000000e+00f, -3.034486645e-02f, -6.779013272e-02f, -1.659481923e-01f, 4.797944664e-02f, }, - { 5.000000000e-02f, 0.000000000e+00f, -3.090169944e-02f, -8.090169944e-02f, 0.000000000e+00f, 0.000000000e+00f, -3.454915028e-02f, 6.454972244e-02f, 8.449668365e-02f, 0.000000000e+00f, 0.000000000e+00f, 0.000000000e+00f, -3.034486645e-02f, 6.779013272e-02f, -1.659481923e-01f, -4.797944664e-02f, }, - { 5.000000000e-02f, 5.000000000e-02f, 5.000000000e-02f, 5.000000000e-02f, 6.454972244e-02f, 6.454972244e-02f, 0.000000000e+00f, 6.454972244e-02f, 0.000000000e+00f, 1.016220987e-01f, 6.338656910e-02f, -1.092600649e-02f, -7.364853795e-02f, 1.011266756e-01f, -7.086833869e-02f, -1.482646439e-02f, }, - { 5.000000000e-02f, 5.000000000e-02f, 5.000000000e-02f, -5.000000000e-02f, -6.454972244e-02f, 6.454972244e-02f, 0.000000000e+00f, -6.454972244e-02f, 0.000000000e+00f, 1.016220987e-01f, -6.338656910e-02f, -1.092600649e-02f, -7.364853795e-02f, -1.011266756e-01f, -7.086833869e-02f, 1.482646439e-02f, }, - { 5.000000000e-02f, -5.000000000e-02f, 5.000000000e-02f, 5.000000000e-02f, -6.454972244e-02f, -6.454972244e-02f, 0.000000000e+00f, 6.454972244e-02f, 0.000000000e+00f, -1.016220987e-01f, -6.338656910e-02f, 1.092600649e-02f, -7.364853795e-02f, 1.011266756e-01f, -7.086833869e-02f, -1.482646439e-02f, }, - { 5.000000000e-02f, -5.000000000e-02f, 5.000000000e-02f, -5.000000000e-02f, 6.454972244e-02f, -6.454972244e-02f, 0.000000000e+00f, -6.454972244e-02f, 0.000000000e+00f, -1.016220987e-01f, 6.338656910e-02f, 1.092600649e-02f, -7.364853795e-02f, -1.011266756e-01f, -7.086833869e-02f, 1.482646439e-02f, }, - { 5.000000000e-02f, 5.000000000e-02f, -5.000000000e-02f, 5.000000000e-02f, 6.454972244e-02f, -6.454972244e-02f, 0.000000000e+00f, -6.454972244e-02f, 0.000000000e+00f, 1.016220987e-01f, -6.338656910e-02f, -1.092600649e-02f, 7.364853795e-02f, 1.011266756e-01f, 7.086833869e-02f, -1.482646439e-02f, }, - { 5.000000000e-02f, 5.000000000e-02f, -5.000000000e-02f, -5.000000000e-02f, -6.454972244e-02f, -6.454972244e-02f, 0.000000000e+00f, 6.454972244e-02f, 0.000000000e+00f, 1.016220987e-01f, 6.338656910e-02f, -1.092600649e-02f, 7.364853795e-02f, -1.011266756e-01f, 7.086833869e-02f, 1.482646439e-02f, }, - { 5.000000000e-02f, -5.000000000e-02f, -5.000000000e-02f, 5.000000000e-02f, -6.454972244e-02f, 6.454972244e-02f, 0.000000000e+00f, -6.454972244e-02f, 0.000000000e+00f, -1.016220987e-01f, 6.338656910e-02f, 1.092600649e-02f, 7.364853795e-02f, 1.011266756e-01f, 7.086833869e-02f, -1.482646439e-02f, }, - { 5.000000000e-02f, -5.000000000e-02f, -5.000000000e-02f, -5.000000000e-02f, 6.454972244e-02f, 6.454972244e-02f, 0.000000000e+00f, 6.454972244e-02f, 0.000000000e+00f, -1.016220987e-01f, -6.338656910e-02f, 1.092600649e-02f, 7.364853795e-02f, -1.011266756e-01f, 7.086833869e-02f, 1.482646439e-02f, }, + static constexpr std::array AmbiPoints2O{ + AngularPoint{EvRadians{-Deg_32}, AzRadians{ 0.0f}}, + AngularPoint{EvRadians{ 0.0f}, AzRadians{ Deg_58}}, + AngularPoint{EvRadians{ Deg_58}, AzRadians{ Deg_90}}, + AngularPoint{EvRadians{ Deg_32}, AzRadians{ 0.0f}}, + AngularPoint{EvRadians{ 0.0f}, AzRadians{ Deg122}}, + AngularPoint{EvRadians{-Deg_58}, AzRadians{-Deg_90}}, + AngularPoint{EvRadians{-Deg_32}, AzRadians{ Deg180}}, + AngularPoint{EvRadians{ 0.0f}, AzRadians{-Deg122}}, + AngularPoint{EvRadians{ Deg_58}, AzRadians{-Deg_90}}, + AngularPoint{EvRadians{ Deg_32}, AzRadians{ Deg180}}, + AngularPoint{EvRadians{ 0.0f}, AzRadians{-Deg_58}}, + AngularPoint{EvRadians{-Deg_58}, AzRadians{ Deg_90}}, }; - static const float AmbiOrderHFGain1O[MaxAmbiOrder+1]{ + static constexpr std::array AmbiPoints3O{ + AngularPoint{EvRadians{ Deg_69}, AzRadians{-Deg_90}}, + AngularPoint{EvRadians{ Deg_69}, AzRadians{ Deg_90}}, + AngularPoint{EvRadians{-Deg_69}, AzRadians{-Deg_90}}, + AngularPoint{EvRadians{-Deg_69}, AzRadians{ Deg_90}}, + AngularPoint{EvRadians{ 0.0f}, AzRadians{-Deg_69}}, + AngularPoint{EvRadians{ 0.0f}, AzRadians{-Deg111}}, + AngularPoint{EvRadians{ 0.0f}, AzRadians{ Deg_69}}, + AngularPoint{EvRadians{ 0.0f}, AzRadians{ Deg111}}, + AngularPoint{EvRadians{ Deg_21}, AzRadians{ 0.0f}}, + AngularPoint{EvRadians{ Deg_21}, AzRadians{ Deg180}}, + AngularPoint{EvRadians{-Deg_21}, AzRadians{ 0.0f}}, + AngularPoint{EvRadians{-Deg_21}, AzRadians{ Deg180}}, + AngularPoint{EvRadians{ Deg_35}, AzRadians{-Deg_45}}, + AngularPoint{EvRadians{ Deg_35}, AzRadians{-Deg135}}, + AngularPoint{EvRadians{ Deg_35}, AzRadians{ Deg_45}}, + AngularPoint{EvRadians{ Deg_35}, AzRadians{ Deg135}}, + AngularPoint{EvRadians{-Deg_35}, AzRadians{-Deg_45}}, + AngularPoint{EvRadians{-Deg_35}, AzRadians{-Deg135}}, + AngularPoint{EvRadians{-Deg_35}, AzRadians{ Deg_45}}, + AngularPoint{EvRadians{-Deg_35}, AzRadians{ Deg135}}, + }; + static constexpr std::array AmbiMatrix1O{ + std::array{{1.250000000e-01f, 1.250000000e-01f, 1.250000000e-01f, 1.250000000e-01f}}, + std::array{{1.250000000e-01f, 1.250000000e-01f, 1.250000000e-01f, -1.250000000e-01f}}, + std::array{{1.250000000e-01f, -1.250000000e-01f, 1.250000000e-01f, 1.250000000e-01f}}, + std::array{{1.250000000e-01f, -1.250000000e-01f, 1.250000000e-01f, -1.250000000e-01f}}, + std::array{{1.250000000e-01f, 1.250000000e-01f, -1.250000000e-01f, 1.250000000e-01f}}, + std::array{{1.250000000e-01f, 1.250000000e-01f, -1.250000000e-01f, -1.250000000e-01f}}, + std::array{{1.250000000e-01f, -1.250000000e-01f, -1.250000000e-01f, 1.250000000e-01f}}, + std::array{{1.250000000e-01f, -1.250000000e-01f, -1.250000000e-01f, -1.250000000e-01f}}, + }; + static constexpr std::array AmbiMatrix2O{ + std::array{{8.333333333e-02f, 0.000000000e+00f, -7.588274978e-02f, 1.227808683e-01f, 0.000000000e+00f, 0.000000000e+00f, -1.591525047e-02f, -1.443375673e-01f, 1.167715449e-01f}}, + std::array{{8.333333333e-02f, -1.227808683e-01f, 0.000000000e+00f, 7.588274978e-02f, -1.443375673e-01f, 0.000000000e+00f, -9.316949906e-02f, 0.000000000e+00f, -7.216878365e-02f}}, + std::array{{8.333333333e-02f, -7.588274978e-02f, 1.227808683e-01f, 0.000000000e+00f, 0.000000000e+00f, -1.443375673e-01f, 1.090847495e-01f, 0.000000000e+00f, -4.460276122e-02f}}, + std::array{{8.333333333e-02f, 0.000000000e+00f, 7.588274978e-02f, 1.227808683e-01f, 0.000000000e+00f, 0.000000000e+00f, -1.591525047e-02f, 1.443375673e-01f, 1.167715449e-01f}}, + std::array{{8.333333333e-02f, -1.227808683e-01f, 0.000000000e+00f, -7.588274978e-02f, 1.443375673e-01f, 0.000000000e+00f, -9.316949906e-02f, 0.000000000e+00f, -7.216878365e-02f}}, + std::array{{8.333333333e-02f, 7.588274978e-02f, -1.227808683e-01f, 0.000000000e+00f, 0.000000000e+00f, -1.443375673e-01f, 1.090847495e-01f, 0.000000000e+00f, -4.460276122e-02f}}, + std::array{{8.333333333e-02f, 0.000000000e+00f, -7.588274978e-02f, -1.227808683e-01f, 0.000000000e+00f, 0.000000000e+00f, -1.591525047e-02f, 1.443375673e-01f, 1.167715449e-01f}}, + std::array{{8.333333333e-02f, 1.227808683e-01f, 0.000000000e+00f, -7.588274978e-02f, -1.443375673e-01f, 0.000000000e+00f, -9.316949906e-02f, 0.000000000e+00f, -7.216878365e-02f}}, + std::array{{8.333333333e-02f, 7.588274978e-02f, 1.227808683e-01f, 0.000000000e+00f, 0.000000000e+00f, 1.443375673e-01f, 1.090847495e-01f, 0.000000000e+00f, -4.460276122e-02f}}, + std::array{{8.333333333e-02f, 0.000000000e+00f, 7.588274978e-02f, -1.227808683e-01f, 0.000000000e+00f, 0.000000000e+00f, -1.591525047e-02f, -1.443375673e-01f, 1.167715449e-01f}}, + std::array{{8.333333333e-02f, 1.227808683e-01f, 0.000000000e+00f, 7.588274978e-02f, 1.443375673e-01f, 0.000000000e+00f, -9.316949906e-02f, 0.000000000e+00f, -7.216878365e-02f}}, + std::array{{8.333333333e-02f, -7.588274978e-02f, -1.227808683e-01f, 0.000000000e+00f, 0.000000000e+00f, 1.443375673e-01f, 1.090847495e-01f, 0.000000000e+00f, -4.460276122e-02f}}, + }; + static constexpr std::array AmbiMatrix3O{ + std::array{{5.000000000e-02f, 3.090169944e-02f, 8.090169944e-02f, 0.000000000e+00f, 0.000000000e+00f, 6.454972244e-02f, 9.045084972e-02f, 0.000000000e+00f, -1.232790000e-02f, -1.256118221e-01f, 0.000000000e+00f, 1.126112056e-01f, 7.944389175e-02f, 0.000000000e+00f, 2.421151497e-02f, 0.000000000e+00f}}, + std::array{{5.000000000e-02f, -3.090169944e-02f, 8.090169944e-02f, 0.000000000e+00f, 0.000000000e+00f, -6.454972244e-02f, 9.045084972e-02f, 0.000000000e+00f, -1.232790000e-02f, 1.256118221e-01f, 0.000000000e+00f, -1.126112056e-01f, 7.944389175e-02f, 0.000000000e+00f, 2.421151497e-02f, 0.000000000e+00f}}, + std::array{{5.000000000e-02f, 3.090169944e-02f, -8.090169944e-02f, 0.000000000e+00f, 0.000000000e+00f, -6.454972244e-02f, 9.045084972e-02f, 0.000000000e+00f, -1.232790000e-02f, -1.256118221e-01f, 0.000000000e+00f, 1.126112056e-01f, -7.944389175e-02f, 0.000000000e+00f, -2.421151497e-02f, 0.000000000e+00f}}, + std::array{{5.000000000e-02f, -3.090169944e-02f, -8.090169944e-02f, 0.000000000e+00f, 0.000000000e+00f, 6.454972244e-02f, 9.045084972e-02f, 0.000000000e+00f, -1.232790000e-02f, 1.256118221e-01f, 0.000000000e+00f, -1.126112056e-01f, -7.944389175e-02f, 0.000000000e+00f, -2.421151497e-02f, 0.000000000e+00f}}, + std::array{{5.000000000e-02f, 8.090169944e-02f, 0.000000000e+00f, 3.090169944e-02f, 6.454972244e-02f, 0.000000000e+00f, -5.590169944e-02f, 0.000000000e+00f, -7.216878365e-02f, -7.763237543e-02f, 0.000000000e+00f, -2.950836627e-02f, 0.000000000e+00f, -1.497759251e-01f, 0.000000000e+00f, -7.763237543e-02f}}, + std::array{{5.000000000e-02f, 8.090169944e-02f, 0.000000000e+00f, -3.090169944e-02f, -6.454972244e-02f, 0.000000000e+00f, -5.590169944e-02f, 0.000000000e+00f, -7.216878365e-02f, -7.763237543e-02f, 0.000000000e+00f, -2.950836627e-02f, 0.000000000e+00f, 1.497759251e-01f, 0.000000000e+00f, 7.763237543e-02f}}, + std::array{{5.000000000e-02f, -8.090169944e-02f, 0.000000000e+00f, 3.090169944e-02f, -6.454972244e-02f, 0.000000000e+00f, -5.590169944e-02f, 0.000000000e+00f, -7.216878365e-02f, 7.763237543e-02f, 0.000000000e+00f, 2.950836627e-02f, 0.000000000e+00f, -1.497759251e-01f, 0.000000000e+00f, -7.763237543e-02f}}, + std::array{{5.000000000e-02f, -8.090169944e-02f, 0.000000000e+00f, -3.090169944e-02f, 6.454972244e-02f, 0.000000000e+00f, -5.590169944e-02f, 0.000000000e+00f, -7.216878365e-02f, 7.763237543e-02f, 0.000000000e+00f, 2.950836627e-02f, 0.000000000e+00f, 1.497759251e-01f, 0.000000000e+00f, 7.763237543e-02f}}, + std::array{{5.000000000e-02f, 0.000000000e+00f, 3.090169944e-02f, 8.090169944e-02f, 0.000000000e+00f, 0.000000000e+00f, -3.454915028e-02f, 6.454972244e-02f, 8.449668365e-02f, 0.000000000e+00f, 0.000000000e+00f, 0.000000000e+00f, 3.034486645e-02f, -6.779013272e-02f, 1.659481923e-01f, 4.797944664e-02f}}, + std::array{{5.000000000e-02f, 0.000000000e+00f, 3.090169944e-02f, -8.090169944e-02f, 0.000000000e+00f, 0.000000000e+00f, -3.454915028e-02f, -6.454972244e-02f, 8.449668365e-02f, 0.000000000e+00f, 0.000000000e+00f, 0.000000000e+00f, 3.034486645e-02f, 6.779013272e-02f, 1.659481923e-01f, -4.797944664e-02f}}, + std::array{{5.000000000e-02f, 0.000000000e+00f, -3.090169944e-02f, 8.090169944e-02f, 0.000000000e+00f, 0.000000000e+00f, -3.454915028e-02f, -6.454972244e-02f, 8.449668365e-02f, 0.000000000e+00f, 0.000000000e+00f, 0.000000000e+00f, -3.034486645e-02f, -6.779013272e-02f, -1.659481923e-01f, 4.797944664e-02f}}, + std::array{{5.000000000e-02f, 0.000000000e+00f, -3.090169944e-02f, -8.090169944e-02f, 0.000000000e+00f, 0.000000000e+00f, -3.454915028e-02f, 6.454972244e-02f, 8.449668365e-02f, 0.000000000e+00f, 0.000000000e+00f, 0.000000000e+00f, -3.034486645e-02f, 6.779013272e-02f, -1.659481923e-01f, -4.797944664e-02f}}, + std::array{{5.000000000e-02f, 5.000000000e-02f, 5.000000000e-02f, 5.000000000e-02f, 6.454972244e-02f, 6.454972244e-02f, 0.000000000e+00f, 6.454972244e-02f, 0.000000000e+00f, 1.016220987e-01f, 6.338656910e-02f, -1.092600649e-02f, -7.364853795e-02f, 1.011266756e-01f, -7.086833869e-02f, -1.482646439e-02f}}, + std::array{{5.000000000e-02f, 5.000000000e-02f, 5.000000000e-02f, -5.000000000e-02f, -6.454972244e-02f, 6.454972244e-02f, 0.000000000e+00f, -6.454972244e-02f, 0.000000000e+00f, 1.016220987e-01f, -6.338656910e-02f, -1.092600649e-02f, -7.364853795e-02f, -1.011266756e-01f, -7.086833869e-02f, 1.482646439e-02f}}, + std::array{{5.000000000e-02f, -5.000000000e-02f, 5.000000000e-02f, 5.000000000e-02f, -6.454972244e-02f, -6.454972244e-02f, 0.000000000e+00f, 6.454972244e-02f, 0.000000000e+00f, -1.016220987e-01f, -6.338656910e-02f, 1.092600649e-02f, -7.364853795e-02f, 1.011266756e-01f, -7.086833869e-02f, -1.482646439e-02f}}, + std::array{{5.000000000e-02f, -5.000000000e-02f, 5.000000000e-02f, -5.000000000e-02f, 6.454972244e-02f, -6.454972244e-02f, 0.000000000e+00f, -6.454972244e-02f, 0.000000000e+00f, -1.016220987e-01f, 6.338656910e-02f, 1.092600649e-02f, -7.364853795e-02f, -1.011266756e-01f, -7.086833869e-02f, 1.482646439e-02f}}, + std::array{{5.000000000e-02f, 5.000000000e-02f, -5.000000000e-02f, 5.000000000e-02f, 6.454972244e-02f, -6.454972244e-02f, 0.000000000e+00f, -6.454972244e-02f, 0.000000000e+00f, 1.016220987e-01f, -6.338656910e-02f, -1.092600649e-02f, 7.364853795e-02f, 1.011266756e-01f, 7.086833869e-02f, -1.482646439e-02f}}, + std::array{{5.000000000e-02f, 5.000000000e-02f, -5.000000000e-02f, -5.000000000e-02f, -6.454972244e-02f, -6.454972244e-02f, 0.000000000e+00f, 6.454972244e-02f, 0.000000000e+00f, 1.016220987e-01f, 6.338656910e-02f, -1.092600649e-02f, 7.364853795e-02f, -1.011266756e-01f, 7.086833869e-02f, 1.482646439e-02f}}, + std::array{{5.000000000e-02f, -5.000000000e-02f, -5.000000000e-02f, 5.000000000e-02f, -6.454972244e-02f, 6.454972244e-02f, 0.000000000e+00f, -6.454972244e-02f, 0.000000000e+00f, -1.016220987e-01f, 6.338656910e-02f, 1.092600649e-02f, 7.364853795e-02f, 1.011266756e-01f, 7.086833869e-02f, -1.482646439e-02f}}, + std::array{{5.000000000e-02f, -5.000000000e-02f, -5.000000000e-02f, -5.000000000e-02f, 6.454972244e-02f, 6.454972244e-02f, 0.000000000e+00f, 6.454972244e-02f, 0.000000000e+00f, -1.016220987e-01f, -6.338656910e-02f, 1.092600649e-02f, 7.364853795e-02f, -1.011266756e-01f, 7.086833869e-02f, 1.482646439e-02f}}, + }; + static constexpr std::array AmbiOrderHFGain1O{ /*ENRGY*/ 2.000000000e+00f, 1.154700538e+00f - }, AmbiOrderHFGain2O[MaxAmbiOrder+1]{ + }; + static constexpr std::array AmbiOrderHFGain2O{ /*ENRGY*/ 1.825741858e+00f, 1.414213562e+00f, 7.302967433e-01f /*AMP 1.000000000e+00f, 7.745966692e-01f, 4.000000000e-01f*/ /*RMS 9.128709292e-01f, 7.071067812e-01f, 3.651483717e-01f*/ - }, AmbiOrderHFGain3O[MaxAmbiOrder+1]{ + }; + static constexpr std::array AmbiOrderHFGain3O{ /*ENRGY 1.865086714e+00f, 1.606093894e+00f, 1.142055301e+00f, 5.683795528e-01f*/ /*AMP*/ 1.000000000e+00f, 8.611363116e-01f, 6.123336207e-01f, 3.047469850e-01f /*RMS 8.340921354e-01f, 7.182670250e-01f, 5.107426573e-01f, 2.541870634e-01f*/ }; - static_assert(std::size(AmbiPoints1O) == std::size(AmbiMatrix1O), "First-Order Ambisonic HRTF mismatch"); - static_assert(std::size(AmbiPoints2O) == std::size(AmbiMatrix2O), "Second-Order Ambisonic HRTF mismatch"); - static_assert(std::size(AmbiPoints3O) == std::size(AmbiMatrix3O), "Third-Order Ambisonic HRTF mismatch"); + static_assert(AmbiPoints1O.size() == AmbiMatrix1O.size(), "First-Order Ambisonic HRTF mismatch"); + static_assert(AmbiPoints2O.size() == AmbiMatrix2O.size(), "Second-Order Ambisonic HRTF mismatch"); + static_assert(AmbiPoints3O.size() == AmbiMatrix3O.size(), "Third-Order Ambisonic HRTF mismatch"); /* A 700hz crossover frequency provides tighter sound imaging at the sweet * spot with ambisonic decoding, as the distance between the ears is closer @@ -844,15 +849,15 @@ void InitHrtfPanning(ALCdevice *device) if(auto modeopt = device->configValue(nullptr, "hrtf-mode")) { struct HrtfModeEntry { - char name[8]; + char name[7]; /* NOLINT(*-avoid-c-arrays) */ RenderMode mode; uint order; }; - static const HrtfModeEntry hrtf_modes[]{ - { "full", RenderMode::Hrtf, 1 }, - { "ambi1", RenderMode::Normal, 1 }, - { "ambi2", RenderMode::Normal, 2 }, - { "ambi3", RenderMode::Normal, 3 }, + static constexpr std::array hrtf_modes{ + HrtfModeEntry{"full", RenderMode::Hrtf, 1}, + HrtfModeEntry{"ambi1", RenderMode::Normal, 1}, + HrtfModeEntry{"ambi2", RenderMode::Normal, 2}, + HrtfModeEntry{"ambi3", RenderMode::Normal, 3}, }; const char *mode{modeopt->c_str()}; @@ -882,9 +887,9 @@ void InitHrtfPanning(ALCdevice *device) device->mHrtfName.c_str()); bool perHrirMin{false}; - al::span AmbiPoints{AmbiPoints1O}; - const float (*AmbiMatrix)[MaxAmbiChannels]{AmbiMatrix1O}; - al::span AmbiOrderHFGain{AmbiOrderHFGain1O}; + auto AmbiPoints = al::span{AmbiPoints1O}.subspan(0); + auto AmbiMatrix = al::span{AmbiMatrix1O}.subspan(0); + auto AmbiOrderHFGain = al::span{AmbiOrderHFGain1O}; if(ambi_order >= 3) { perHrirMin = true; @@ -903,7 +908,7 @@ void InitHrtfPanning(ALCdevice *device) const size_t count{AmbiChannelsFromOrder(ambi_order)}; std::transform(AmbiIndex::FromACN.begin(), AmbiIndex::FromACN.begin()+count, - std::begin(device->Dry.AmbiMap), + device->Dry.AmbiMap.begin(), [](const uint8_t &index) noexcept { return BFChannelConfig{1.0f, index}; } ); AllocChannels(device, count, device->channelsFromFmt()); @@ -981,9 +986,9 @@ void aluInitRenderer(ALCdevice *device, int hrtf_id, std::optionalc_str()); return false; } - else if(conf.NumSpeakers > MaxOutputChannels) + else if(conf.Speakers.size() > MaxOutputChannels) { - ERR("Unsupported decoder speaker count %zu (max %zu)\n", conf.NumSpeakers, + ERR("Unsupported decoder speaker count %zu (max %zu)\n", conf.Speakers.size(), MaxOutputChannels); return false; } diff --git a/common/phase_shifter.h b/common/phase_shifter.h index e1a83dab..1b3463de 100644 --- a/common/phase_shifter.h +++ b/common/phase_shifter.h @@ -10,6 +10,7 @@ #include #include #include +#include #include "alcomplex.h" #include "alspan.h" @@ -52,20 +53,19 @@ struct PhaseShifterT { constexpr size_t fft_size{FilterSize}; constexpr size_t half_size{fft_size / 2}; - auto fftBuffer = std::make_unique(fft_size); - std::fill_n(fftBuffer.get(), fft_size, complex_d{}); + auto fftBuffer = std::vector(fft_size, complex_d{}); fftBuffer[half_size] = 1.0; - forward_fft(al::span{fftBuffer.get(), fft_size}); + forward_fft(al::span{fftBuffer}); fftBuffer[0] *= std::numeric_limits::epsilon(); for(size_t i{1};i < half_size;++i) fftBuffer[i] = complex_d{-fftBuffer[i].imag(), fftBuffer[i].real()}; fftBuffer[half_size] *= std::numeric_limits::epsilon(); for(size_t i{half_size+1};i < fft_size;++i) fftBuffer[i] = std::conj(fftBuffer[fft_size - i]); - inverse_fft(al::span{fftBuffer.get(), fft_size}); + inverse_fft(al::span{fftBuffer}); - auto fftiter = fftBuffer.get() + fft_size - 1; + auto fftiter = fftBuffer.data() + fft_size - 1; for(float &coeff : mCoeffs) { coeff = static_cast(fftiter->real() / double{fft_size}); diff --git a/common/ringbuffer.cpp b/common/ringbuffer.cpp index 0d3b7e30..13db7eba 100644 --- a/common/ringbuffer.cpp +++ b/common/ringbuffer.cpp @@ -24,9 +24,9 @@ #include #include +#include #include #include -#include #include "almalloc.h" diff --git a/core/ambdec.cpp b/core/ambdec.cpp index fb747fdf..ea369d38 100644 --- a/core/ambdec.cpp +++ b/core/ambdec.cpp @@ -111,7 +111,7 @@ std::optional AmbDecConf::load(const char *fname) noexcept { if(command == "add_spkr") { - if(speaker_pos == NumSpeakers) + if(speaker_pos == Speakers.size()) return make_error(linenum, "Too many speakers specified"); AmbDecConf::SpeakerConf &spkr = Speakers[speaker_pos++]; @@ -145,7 +145,7 @@ std::optional AmbDecConf::load(const char *fname) noexcept } else if(command == "add_row") { - if(pos == NumSpeakers) + if(pos == Speakers.size()) return make_error(linenum, "Too many matrix rows specified"); unsigned int mask{ChanMask}; @@ -205,12 +205,13 @@ std::optional AmbDecConf::load(const char *fname) noexcept } else if(command == "/dec/speakers") { - if(NumSpeakers) + if(!Speakers.empty()) return make_error(linenum, "Duplicate speakers"); - istr >> NumSpeakers; - if(!NumSpeakers) - return make_error(linenum, "Invalid speakers: %zu", NumSpeakers); - Speakers = std::make_unique(NumSpeakers); + size_t numspeakers{}; + istr >> numspeakers; + if(!numspeakers) + return make_error(linenum, "Invalid speakers: %zu", numspeakers); + Speakers.resize(numspeakers); } else if(command == "/dec/coeff_scale") { @@ -243,22 +244,22 @@ std::optional AmbDecConf::load(const char *fname) noexcept } else if(command == "/speakers/{") { - if(!NumSpeakers) + if(Speakers.empty()) return make_error(linenum, "Speakers defined without a count"); scope = ReaderScope::Speakers; } else if(command == "/lfmatrix/{" || command == "/hfmatrix/{" || command == "/matrix/{") { - if(!NumSpeakers) + if(Speakers.empty()) return make_error(linenum, "Matrix defined without a speaker count"); if(!ChanMask) return make_error(linenum, "Matrix defined without a channel mask"); - if(!Matrix) + if(Matrix.empty()) { - Matrix = std::make_unique(NumSpeakers * FreqBands); - LFMatrix = Matrix.get(); - HFMatrix = LFMatrix + NumSpeakers*(FreqBands-1); + Matrix.resize(Speakers.size() * FreqBands); + LFMatrix = Matrix.data(); + HFMatrix = LFMatrix + Speakers.size()*(FreqBands-1); } if(FreqBands == 1) @@ -285,8 +286,8 @@ std::optional AmbDecConf::load(const char *fname) noexcept if(!is_at_end(buffer, endpos)) return make_error(linenum, "Extra junk on end: %s", buffer.substr(endpos).c_str()); - if(speaker_pos < NumSpeakers || hfmatrix_pos < NumSpeakers - || (FreqBands == 2 && lfmatrix_pos < NumSpeakers)) + if(speaker_pos < Speakers.empty() || hfmatrix_pos < Speakers.empty() + || (FreqBands == 2 && lfmatrix_pos < Speakers.empty())) return make_error(linenum, "Incomplete decoder definition"); if(CoeffScale == AmbDecScale::Unset) return make_error(linenum, "No coefficient scaling defined"); diff --git a/core/ambdec.h b/core/ambdec.h index 19f68697..4305070f 100644 --- a/core/ambdec.h +++ b/core/ambdec.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "core/ambidefs.h" @@ -34,17 +35,16 @@ struct AmbDecConf { float Elevation{0.0f}; std::string Connection; }; - size_t NumSpeakers{0}; - std::unique_ptr Speakers; + std::vector Speakers; using CoeffArray = std::array; - std::unique_ptr Matrix; + std::vector Matrix; /* Unused when FreqBands == 1 */ - float LFOrderGain[MaxAmbiOrder+1]{}; + std::array LFOrderGain{}; CoeffArray *LFMatrix; - float HFOrderGain[MaxAmbiOrder+1]{}; + std::array HFOrderGain{}; CoeffArray *HFMatrix; ~AmbDecConf(); diff --git a/core/buffer_storage.cpp b/core/buffer_storage.cpp index 6ffab124..a343b946 100644 --- a/core/buffer_storage.cpp +++ b/core/buffer_storage.cpp @@ -3,7 +3,7 @@ #include "buffer_storage.h" -#include +#include const char *NameFromFormat(FmtType type) noexcept diff --git a/core/converter.cpp b/core/converter.cpp index 5b2f3e15..fb293ee2 100644 --- a/core/converter.cpp +++ b/core/converter.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include "albit.h" #include "alnumeric.h" @@ -51,7 +51,7 @@ template inline void LoadSampleArray(float *RESTRICT dst, const void *src, const size_t srcstep, const size_t samples) noexcept { - const DevFmtType_t *ssrc = static_cast*>(src); + auto *ssrc = static_cast*>(src); for(size_t i{0u};i < samples;i++) dst[i] = LoadSample(ssrc[i*srcstep]); } @@ -99,7 +99,7 @@ template inline void StoreSampleArray(void *dst, const float *RESTRICT src, const size_t dststep, const size_t samples) noexcept { - DevFmtType_t *sdst = static_cast*>(dst); + auto *sdst = static_cast*>(dst); for(size_t i{0u};i < samples;i++) sdst[i*dststep] = StoreSample(src[i]); } @@ -127,7 +127,7 @@ void StoreSamples(void *dst, const float *src, const size_t dststep, const DevFm template void Mono2Stereo(float *RESTRICT dst, const void *src, const size_t frames) noexcept { - const DevFmtType_t *ssrc = static_cast*>(src); + auto *ssrc = static_cast*>(src); for(size_t i{0u};i < frames;i++) dst[i*2 + 1] = dst[i*2 + 0] = LoadSample(ssrc[i]) * 0.707106781187f; } @@ -136,7 +136,7 @@ template void Multi2Mono(uint chanmask, const size_t step, const float scale, float *RESTRICT dst, const void *src, const size_t frames) noexcept { - const DevFmtType_t *ssrc = static_cast*>(src); + auto *ssrc = static_cast*>(src); std::fill_n(dst, frames, 0.0f); for(size_t c{0};chanmask;++c) { @@ -243,8 +243,8 @@ uint SampleConverter::convert(const void **src, uint *srcframes, void *dst, uint break; } - float *RESTRICT SrcData{mSrcSamples}; - float *RESTRICT DstData{mDstSamples}; + float *RESTRICT SrcData{mSrcSamples.data()}; + float *RESTRICT DstData{mDstSamples.data()}; uint DataPosFrac{mFracOffset}; uint64_t DataSize64{prepcount}; DataSize64 += readable; @@ -271,13 +271,13 @@ uint SampleConverter::convert(const void **src, uint *srcframes, void *dst, uint /* Load the previous samples into the source data first, then the * new samples from the input buffer. */ - std::copy_n(mChan[chan].PrevSamples, prepcount, SrcData); + std::copy_n(mChan[chan].PrevSamples.cbegin(), prepcount, SrcData); LoadSamples(SrcData + prepcount, SrcSamples, mChan.size(), mSrcType, readable); /* Store as many prep samples for next time as possible, given the * number of output samples being generated. */ - std::copy_n(SrcData+SrcDataEnd, nextprep, mChan[chan].PrevSamples); + std::copy_n(SrcData+SrcDataEnd, nextprep, mChan[chan].PrevSamples.begin()); std::fill(std::begin(mChan[chan].PrevSamples)+nextprep, std::end(mChan[chan].PrevSamples), 0.0f); @@ -338,8 +338,8 @@ uint SampleConverter::convertPlanar(const void **src, uint *srcframes, void *con break; } - float *RESTRICT SrcData{mSrcSamples}; - float *RESTRICT DstData{mDstSamples}; + float *RESTRICT SrcData{mSrcSamples.data()}; + float *RESTRICT DstData{mDstSamples.data()}; uint DataPosFrac{mFracOffset}; uint64_t DataSize64{prepcount}; DataSize64 += readable; @@ -363,13 +363,13 @@ uint SampleConverter::convertPlanar(const void **src, uint *srcframes, void *con /* Load the previous samples into the source data first, then the * new samples from the input buffer. */ - std::copy_n(mChan[chan].PrevSamples, prepcount, SrcData); + std::copy_n(mChan[chan].PrevSamples.cbegin(), prepcount, SrcData); LoadSamples(SrcData + prepcount, src[chan], 1, mSrcType, readable); /* Store as many prep samples for next time as possible, given the * number of output samples being generated. */ - std::copy_n(SrcData+SrcDataEnd, nextprep, mChan[chan].PrevSamples); + std::copy_n(SrcData+SrcDataEnd, nextprep, mChan[chan].PrevSamples.begin()); std::fill(std::begin(mChan[chan].PrevSamples)+nextprep, std::end(mChan[chan].PrevSamples), 0.0f); diff --git a/core/converter.h b/core/converter.h index 7aeb6cad..3dc2babb 100644 --- a/core/converter.h +++ b/core/converter.h @@ -26,22 +26,22 @@ struct SampleConverter { InterpState mState{}; ResamplerFunc mResample{}; - alignas(16) float mSrcSamples[BufferLineSize]{}; - alignas(16) float mDstSamples[BufferLineSize]{}; + alignas(16) FloatBufferLine mSrcSamples{}; + alignas(16) FloatBufferLine mDstSamples{}; struct ChanSamples { - alignas(16) float PrevSamples[MaxResamplerPadding]; + alignas(16) std::array PrevSamples; }; al::FlexArray mChan; SampleConverter(size_t numchans) : mChan{numchans} { } - uint convert(const void **src, uint *srcframes, void *dst, uint dstframes); - uint convertPlanar(const void **src, uint *srcframes, void *const*dst, uint dstframes); - uint availableOut(uint srcframes) const; + [[nodiscard]] auto convert(const void **src, uint *srcframes, void *dst, uint dstframes) -> uint; + [[nodiscard]] auto convertPlanar(const void **src, uint *srcframes, void *const*dst, uint dstframes) -> uint; + [[nodiscard]] auto availableOut(uint srcframes) const -> uint; using SampleOffset = std::chrono::duration>; - SampleOffset currentInputDelay() const noexcept + [[nodiscard]] auto currentInputDelay() const noexcept -> SampleOffset { const int64_t prep{int64_t{mSrcPrepCount} - MaxResamplerEdge}; return SampleOffset{(prep< bool { return mChanMask != 0; } void convert(const void *src, float *dst, uint frames) const; }; diff --git a/core/cubic_tables.cpp b/core/cubic_tables.cpp index 5e7aafad..84462893 100644 --- a/core/cubic_tables.cpp +++ b/core/cubic_tables.cpp @@ -2,7 +2,7 @@ #include "cubic_tables.h" #include -#include +#include #include "cubic_defs.h" @@ -41,7 +41,7 @@ struct SplineFilterArray { mTable[pi].mDeltas[3] = -mTable[pi].mCoeffs[3]; } - constexpr auto& getTable() const noexcept { return mTable; } + [[nodiscard]] constexpr auto& getTable() const noexcept { return mTable; } }; constexpr SplineFilterArray SplineFilter{}; diff --git a/core/dbus_wrap.cpp b/core/dbus_wrap.cpp index 48419566..08020c9b 100644 --- a/core/dbus_wrap.cpp +++ b/core/dbus_wrap.cpp @@ -14,7 +14,7 @@ void PrepareDBus() { - static constexpr char libname[] = "libdbus-1.so.3"; + const char *libname{"libdbus-1.so.3"}; auto load_func = [](auto &f, const char *name) -> void { f = al::bit_cast>(GetSymbol(dbus_handle, name)); }; diff --git a/core/effectslot.cpp b/core/effectslot.cpp index db8aa078..99224225 100644 --- a/core/effectslot.cpp +++ b/core/effectslot.cpp @@ -3,7 +3,7 @@ #include "effectslot.h" -#include +#include #include "almalloc.h" #include "context.h" diff --git a/core/filters/biquad.cpp b/core/filters/biquad.cpp index a0a62eb8..6671f60f 100644 --- a/core/filters/biquad.cpp +++ b/core/filters/biquad.cpp @@ -27,8 +27,8 @@ void BiquadFilterR::setParams(BiquadType type, Real f0norm, Real gain, Rea const Real alpha{sin_w0/2.0f * rcpQ}; Real sqrtgain_alpha_2; - Real a[3]{ 1.0f, 0.0f, 0.0f }; - Real b[3]{ 1.0f, 0.0f, 0.0f }; + std::array a{{1.0f, 0.0f, 0.0f}}; + std::array b{{1.0f, 0.0f, 0.0f}}; /* Calculate filter coefficients depending on filter type */ switch(type) diff --git a/core/filters/nfc.cpp b/core/filters/nfc.cpp index aa64c613..95b84e2c 100644 --- a/core/filters/nfc.cpp +++ b/core/filters/nfc.cpp @@ -48,12 +48,12 @@ namespace { -constexpr float B[5][4] = { - { 0.0f }, - { 1.0f }, - { 3.0f, 3.0f }, - { 3.6778f, 6.4595f, 2.3222f }, - { 4.2076f, 11.4877f, 5.7924f, 9.1401f } +constexpr std::array B{ + std::array{ 0.0f, 0.0f, 0.0f, 0.0f}, + std::array{ 1.0f, 0.0f, 0.0f, 0.0f}, + std::array{ 3.0f, 3.0f, 0.0f, 0.0f}, + std::array{3.6778f, 6.4595f, 2.3222f, 0.0f}, + std::array{4.2076f, 11.4877f, 5.7924f, 9.1401f} }; NfcFilter1 NfcFilterCreate1(const float w0, const float w1) noexcept diff --git a/core/helpers.cpp b/core/helpers.cpp index 5a996eee..0e02b09f 100644 --- a/core/helpers.cpp +++ b/core/helpers.cpp @@ -256,7 +256,7 @@ const PathNamePair &GetProcBinary() #ifndef __SWITCH__ if(pathname.empty()) { - const char *SelfLinkNames[]{ + std::array SelfLinkNames{ "/proc/self/exe", "/proc/self/file", "/proc/curproc/exe", diff --git a/core/hrtf.cpp b/core/hrtf.cpp index 1b7da3f9..5a696e66 100644 --- a/core/hrtf.cpp +++ b/core/hrtf.cpp @@ -88,10 +88,12 @@ constexpr uint HrirDelayFracHalf{HrirDelayFracOne >> 1}; static_assert(MaxHrirDelay*HrirDelayFracOne < 256, "MAX_HRIR_DELAY or DELAY_FRAC too large"); +/* NOLINTBEGIN(*-avoid-c-arrays) */ constexpr char magicMarker00[8]{'M','i','n','P','H','R','0','0'}; constexpr char magicMarker01[8]{'M','i','n','P','H','R','0','1'}; constexpr char magicMarker02[8]{'M','i','n','P','H','R','0','2'}; constexpr char magicMarker03[8]{'M','i','n','P','H','R','0','3'}; +/* NOLINTEND(*-avoid-c-arrays) */ /* First value for pass-through coefficients (remaining are 0), used for omni- * directional sounds. */ @@ -231,22 +233,22 @@ void HrtfStore::getCoeffs(float elevation, float azimuth, float distance, float const auto az1 = CalcAzIndex(mElev[ebase + elev1_idx].azCount, azimuth); /* Calculate the HRIR indices to blend. */ - const size_t idx[4]{ + const std::array idx{{ ir0offset + az0.idx, ir0offset + ((az0.idx+1) % mElev[ebase + elev0.idx].azCount), ir1offset + az1.idx, ir1offset + ((az1.idx+1) % mElev[ebase + elev1_idx].azCount) - }; + }}; /* Calculate bilinear blending weights, attenuated according to the * directional panning factor. */ - const float blend[4]{ + const std::array blend{{ (1.0f-elev0.blend) * (1.0f-az0.blend) * dirfact, (1.0f-elev0.blend) * ( az0.blend) * dirfact, ( elev0.blend) * (1.0f-az1.blend) * dirfact, ( elev0.blend) * ( az1.blend) * dirfact - }; + }}; /* Calculate the blended HRIR delays. */ float d{mDelays[idx[0]][0]*blend[0] + mDelays[idx[1]][0]*blend[1] + mDelays[idx[2]][0]*blend[2] @@ -276,7 +278,8 @@ std::unique_ptr DirectHrtfState::Create(size_t num_chans) { return std::unique_ptr{new(FamCount(num_chans)) DirectHrtfState{num_chans}}; } void DirectHrtfState::build(const HrtfStore *Hrtf, const uint irSize, const bool perHrirMin, - const al::span AmbiPoints, const float (*AmbiMatrix)[MaxAmbiChannels], + const al::span AmbiPoints, + const al::span> AmbiMatrix, const float XOverFreq, const al::span AmbiOrderHFGain) { using double2 = std::array; @@ -307,7 +310,7 @@ void DirectHrtfState::build(const HrtfStore *Hrtf, const uint irSize, const bool const auto az0 = CalcAzIndex(Hrtf->mElev[elev0.idx].azCount, pt.Azim.value); const auto az1 = CalcAzIndex(Hrtf->mElev[elev1_idx].azCount, pt.Azim.value); - const size_t idx[4]{ + const std::array idx{ ir0offset + az0.idx, ir0offset + ((az0.idx+1) % Hrtf->mElev[elev0.idx].azCount), ir1offset + az1.idx, @@ -492,10 +495,10 @@ T> readle(std::istream &data) static_assert(num_bits <= sizeof(T)*8, "num_bits is too large for the type"); T ret{}; - std::byte b[sizeof(T)]{}; - if(!data.read(reinterpret_cast(b), num_bits/8)) + std::array b{}; + if(!data.read(reinterpret_cast(b.data()), num_bits/8)) return static_cast(EOF); - std::reverse_copy(std::begin(b), std::end(b), reinterpret_cast(&ret)); + std::reverse_copy(b.begin(), b.end(), reinterpret_cast(&ret)); return fixsign(ret); } @@ -598,9 +601,9 @@ std::unique_ptr LoadHrtf00(std::istream &data, const char *filename) /* Mirror the left ear responses to the right ear. */ MirrorLeftHrirs({elevs.data(), elevs.size()}, coeffs.data(), delays.data()); - const HrtfStore::Field field[1]{{0.0f, evCount}}; - return CreateHrtfStore(rate, static_cast(irSize), field, {elevs.data(), elevs.size()}, - coeffs.data(), delays.data(), filename); + const std::array field{HrtfStore::Field{0.0f, evCount}}; + return CreateHrtfStore(rate, static_cast(irSize), field, elevs, coeffs.data(), + delays.data(), filename); } std::unique_ptr LoadHrtf01(std::istream &data, const char *filename) @@ -676,9 +679,8 @@ std::unique_ptr LoadHrtf01(std::istream &data, const char *filename) /* Mirror the left ear responses to the right ear. */ MirrorLeftHrirs({elevs.data(), elevs.size()}, coeffs.data(), delays.data()); - const HrtfStore::Field field[1]{{0.0f, evCount}}; - return CreateHrtfStore(rate, irSize, field, {elevs.data(), elevs.size()}, coeffs.data(), - delays.data(), filename); + const std::array field{HrtfStore::Field{0.0f, evCount}}; + return CreateHrtfStore(rate, irSize, field, elevs, coeffs.data(), delays.data(), filename); } std::unique_ptr LoadHrtf02(std::istream &data, const char *filename) @@ -946,8 +948,7 @@ std::unique_ptr LoadHrtf02(std::istream &data, const char *filename) delays = std::move(delays_); } - return CreateHrtfStore(rate, irSize, {fields.data(), fields.size()}, - {elevs.data(), elevs.size()}, coeffs.data(), delays.data(), filename); + return CreateHrtfStore(rate, irSize, fields, elevs, coeffs.data(), delays.data(), filename); } std::unique_ptr LoadHrtf03(std::istream &data, const char *filename) @@ -1115,8 +1116,7 @@ std::unique_ptr LoadHrtf03(std::istream &data, const char *filename) } } - return CreateHrtfStore(rate, irSize, {fields.data(), fields.size()}, - {elevs.data(), elevs.size()}, coeffs.data(), delays.data(), filename); + return CreateHrtfStore(rate, irSize, fields, elevs, coeffs.data(), delays.data(), filename); } @@ -1206,6 +1206,7 @@ al::span GetResource(int /*name*/) #else +/* NOLINTNEXTLINE(*-avoid-c-arrays) */ constexpr unsigned char hrtf_default[]{ #include "default_hrtf.txt" }; @@ -1329,32 +1330,32 @@ HrtfStorePtr GetLoadedHrtf(const std::string &name, const uint devrate) } std::unique_ptr hrtf; - char magic[sizeof(magicMarker03)]; - stream->read(magic, sizeof(magic)); + std::array magic{}; + stream->read(magic.data(), magic.size()); if(stream->gcount() < static_cast(sizeof(magicMarker03))) ERR("%s data is too short (%zu bytes)\n", name.c_str(), stream->gcount()); - else if(memcmp(magic, magicMarker03, sizeof(magicMarker03)) == 0) + else if(memcmp(magic.data(), magicMarker03, sizeof(magicMarker03)) == 0) { TRACE("Detected data set format v3\n"); hrtf = LoadHrtf03(*stream, name.c_str()); } - else if(memcmp(magic, magicMarker02, sizeof(magicMarker02)) == 0) + else if(memcmp(magic.data(), magicMarker02, sizeof(magicMarker02)) == 0) { TRACE("Detected data set format v2\n"); hrtf = LoadHrtf02(*stream, name.c_str()); } - else if(memcmp(magic, magicMarker01, sizeof(magicMarker01)) == 0) + else if(memcmp(magic.data(), magicMarker01, sizeof(magicMarker01)) == 0) { TRACE("Detected data set format v1\n"); hrtf = LoadHrtf01(*stream, name.c_str()); } - else if(memcmp(magic, magicMarker00, sizeof(magicMarker00)) == 0) + else if(memcmp(magic.data(), magicMarker00, sizeof(magicMarker00)) == 0) { TRACE("Detected data set format v0\n"); hrtf = LoadHrtf00(*stream, name.c_str()); } else - ERR("Invalid header in %s: \"%.8s\"\n", name.c_str(), magic); + ERR("Invalid header in %s: \"%.8s\"\n", name.c_str(), magic.data()); stream.reset(); if(!hrtf) @@ -1380,7 +1381,7 @@ HrtfStorePtr GetLoadedHrtf(const std::string &name, const uint devrate) rs.init(hrtf->mSampleRate, devrate); for(size_t i{0};i < irCount;++i) { - HrirArray &coeffs = const_cast(hrtf->mCoeffs[i]); + auto &coeffs = const_cast(hrtf->mCoeffs[i]); for(size_t j{0};j < 2;++j) { std::transform(coeffs.cbegin(), coeffs.cend(), inout[0].begin(), @@ -1420,7 +1421,7 @@ HrtfStorePtr GetLoadedHrtf(const std::string &name, const uint devrate) for(size_t i{0};i < irCount;++i) { - ubyte2 &delays = const_cast(hrtf->mDelays[i]); + auto &delays = const_cast(hrtf->mDelays[i]); for(size_t j{0};j < 2;++j) delays[j] = static_cast(float2int(new_delays[i][j]*delay_scale + 0.5f)); } diff --git a/core/hrtf.h b/core/hrtf.h index 31168be6..c5dc6475 100644 --- a/core/hrtf.h +++ b/core/hrtf.h @@ -75,7 +75,8 @@ struct DirectHrtfState { * are ordered and scaled according to the matrix input. */ void build(const HrtfStore *Hrtf, const uint irSize, const bool perHrirMin, - const al::span AmbiPoints, const float (*AmbiMatrix)[MaxAmbiChannels], + const al::span AmbiPoints, + const al::span> AmbiMatrix, const float XOverFreq, const al::span AmbiOrderHFGain); static std::unique_ptr Create(size_t num_chans); diff --git a/core/mastering.cpp b/core/mastering.cpp index 1f8ad921..e9b079d6 100644 --- a/core/mastering.cpp +++ b/core/mastering.cpp @@ -21,8 +21,8 @@ static_assert((BufferLineSize & (BufferLineSize-1)) == 0, "BufferLineSize is not a power of 2"); struct SlidingHold { - alignas(16) float mValues[BufferLineSize]; - uint mExpiries[BufferLineSize]; + alignas(16) FloatBufferLine mValues; + std::array mExpiries; uint mLowerIndex; uint mUpperIndex; uint mLength; @@ -44,8 +44,8 @@ float UpdateSlidingHold(SlidingHold *Hold, const uint i, const float in) { static constexpr uint mask{BufferLineSize - 1}; const uint length{Hold->mLength}; - float (&values)[BufferLineSize] = Hold->mValues; - uint (&expiries)[BufferLineSize] = Hold->mExpiries; + const al::span values{Hold->mValues}; + const al::span expiries{Hold->mExpiries}; uint lowerIndex{Hold->mLowerIndex}; uint upperIndex{Hold->mUpperIndex}; @@ -110,7 +110,8 @@ void LinkChannels(Compressor *Comp, const uint SamplesToDo, const FloatBufferLin auto fill_max = [SamplesToDo,side_begin](const FloatBufferLine &input) -> void { const float *RESTRICT buffer{al::assume_aligned<16>(input.data())}; - auto max_abs = std::bind(maxf, _1, std::bind(static_cast(std::fabs), _2)); + auto max_abs = [](const float s0, const float s1) noexcept -> float + { return std::max(s0, std::fabs(s1)); }; std::transform(side_begin, side_begin+SamplesToDo, buffer, side_begin, max_abs); }; std::for_each(OutBuffer, OutBuffer+numChans, fill_max); diff --git a/core/mixer/mixer_neon.cpp b/core/mixer/mixer_neon.cpp index a509e8ba..cbaf2d3d 100644 --- a/core/mixer/mixer_neon.cpp +++ b/core/mixer/mixer_neon.cpp @@ -146,12 +146,11 @@ void Resample_(const InterpState*, const float *RESTRICT src, u const int32x4_t increment4 = vdupq_n_s32(static_cast(increment*4)); const float32x4_t fracOne4 = vdupq_n_f32(1.0f/MixerFracOne); const int32x4_t fracMask4 = vdupq_n_s32(MixerFracMask); - alignas(16) uint pos_[4], frac_[4]; - int32x4_t pos4, frac4; + alignas(16) std::array pos_, frac_; InitPosArrays(frac, increment, al::span{frac_}, al::span{pos_}); - frac4 = vld1q_s32(reinterpret_cast(frac_)); - pos4 = vld1q_s32(reinterpret_cast(pos_)); + int32x4_t frac4 = vld1q_s32(reinterpret_cast(frac_)); + int32x4_t pos4 = vld1q_s32(reinterpret_cast(pos_)); auto dst_iter = dst.begin(); for(size_t todo{dst.size()>>2};todo;--todo) diff --git a/core/mixer/mixer_sse2.cpp b/core/mixer/mixer_sse2.cpp index aa99250e..aa08b7ed 100644 --- a/core/mixer/mixer_sse2.cpp +++ b/core/mixer/mixer_sse2.cpp @@ -44,7 +44,7 @@ void Resample_(const InterpState*, const float *RESTRICT src, u const __m128 fracOne4{_mm_set1_ps(1.0f/MixerFracOne)}; const __m128i fracMask4{_mm_set1_epi32(MixerFracMask)}; - alignas(16) uint pos_[4], frac_[4]; + alignas(16) std::array pos_, frac_; InitPosArrays(frac, increment, al::span{frac_}, al::span{pos_}); __m128i frac4{_mm_setr_epi32(static_cast(frac_[0]), static_cast(frac_[1]), static_cast(frac_[2]), static_cast(frac_[3]))}; diff --git a/core/mixer/mixer_sse41.cpp b/core/mixer/mixer_sse41.cpp index 4e4605df..d66f9ce5 100644 --- a/core/mixer/mixer_sse41.cpp +++ b/core/mixer/mixer_sse41.cpp @@ -45,7 +45,7 @@ void Resample_(const InterpState*, const float *RESTRICT src, u const __m128 fracOne4{_mm_set1_ps(1.0f/MixerFracOne)}; const __m128i fracMask4{_mm_set1_epi32(MixerFracMask)}; - alignas(16) uint pos_[4], frac_[4]; + alignas(16) std::array pos_, frac_; InitPosArrays(frac, increment, al::span{frac_}, al::span{pos_}); __m128i frac4{_mm_setr_epi32(static_cast(frac_[0]), static_cast(frac_[1]), static_cast(frac_[2]), static_cast(frac_[3]))}; diff --git a/core/rtkit.cpp b/core/rtkit.cpp index ff944ebf..73ea132f 100644 --- a/core/rtkit.cpp +++ b/core/rtkit.cpp @@ -30,14 +30,14 @@ #include "rtkit.h" -#include +#include #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include -#include +#include #include #include #ifdef __linux__ diff --git a/core/uhjfilter.cpp b/core/uhjfilter.cpp index e507d705..681b0abc 100644 --- a/core/uhjfilter.cpp +++ b/core/uhjfilter.cpp @@ -5,6 +5,7 @@ #include #include +#include #include "alcomplex.h" #include "alnumeric.h" @@ -64,8 +65,7 @@ struct SegmentedFilter { /* To set up the filter, we need to generate the desired response. * Start with a pure delay that passes all frequencies through. */ - auto fftBuffer = std::make_unique(fft_size); - std::fill_n(fftBuffer.get(), fft_size, complex_d{}); + auto fftBuffer = std::vector(fft_size, complex_d{}); fftBuffer[half_size] = 1.0; /* Convert to the frequency domain, shift the phase of each bin by +90 @@ -75,27 +75,27 @@ struct SegmentedFilter { * To maintain that and their phase (0 or pi), they're heavily * attenuated instead of shifted like the others. */ - forward_fft(al::span{fftBuffer.get(), fft_size}); + forward_fft(al::span{fftBuffer}); fftBuffer[0] *= std::numeric_limits::epsilon(); for(size_t i{1};i < half_size;++i) fftBuffer[i] = complex_d{-fftBuffer[i].imag(), fftBuffer[i].real()}; fftBuffer[half_size] *= std::numeric_limits::epsilon(); for(size_t i{half_size+1};i < fft_size;++i) fftBuffer[i] = std::conj(fftBuffer[fft_size - i]); - inverse_fft(al::span{fftBuffer.get(), fft_size}); + inverse_fft(al::span{fftBuffer}); /* The segments of the filter are converted back to the frequency * domain, each on their own (0 stuffed). */ - auto fftBuffer2 = std::make_unique(sFftLength); + auto fftBuffer2 = std::vector(sFftLength); auto fftTmp = al::vector(sFftLength); float *filter{mFilterData.data()}; for(size_t s{0};s < sNumSegments;++s) { for(size_t i{0};i < sSampleLength;++i) fftBuffer2[i] = fftBuffer[sSampleLength*s + i].real() / double{fft_size}; - std::fill_n(fftBuffer2.get()+sSampleLength, sSampleLength, complex_d{}); - forward_fft(al::span{fftBuffer2.get(), sFftLength}); + std::fill_n(fftBuffer2.data()+sSampleLength, sSampleLength, complex_d{}); + forward_fft(al::span{fftBuffer2}); /* Convert to zdomain data for PFFFT, scaled by the FFT length so * the iFFT result will be normalized. diff --git a/examples/alffplay.cpp b/examples/alffplay.cpp index 54803035..5a10bf05 100644 --- a/examples/alffplay.cpp +++ b/examples/alffplay.cpp @@ -310,8 +310,9 @@ struct AudioState { int mSamplesPos{0}; int mSamplesMax{0}; - std::unique_ptr mBufferData; - size_t mBufferDataSize{0}; + std::vector mBufferData_; + //std::unique_ptr mBufferData; + //size_t mBufferDataSize{0}; std::atomic mReadPos{0}; std::atomic mWritePos{0}; @@ -485,7 +486,7 @@ nanoseconds AudioState::getClockNoLock() return device_time - mDeviceStartTime - latency; } - if(mBufferDataSize > 0) + if(!mBufferData_.empty()) { if(mDeviceStartTime == nanoseconds::min()) return nanoseconds::zero(); @@ -522,7 +523,7 @@ nanoseconds AudioState::getClockNoLock() */ const size_t woffset{mWritePos.load(std::memory_order_acquire)}; const size_t roffset{mReadPos.load(std::memory_order_relaxed)}; - const size_t readable{((woffset >= roffset) ? woffset : (mBufferDataSize+woffset)) - + const size_t readable{((woffset>=roffset) ? woffset : (mBufferData_.size()+woffset)) - roffset}; pts = mCurrentPts - nanoseconds{seconds{readable/mFrameSize}}/mCodecCtx->sample_rate; @@ -584,10 +585,10 @@ bool AudioState::startPlayback() { const size_t woffset{mWritePos.load(std::memory_order_acquire)}; const size_t roffset{mReadPos.load(std::memory_order_relaxed)}; - const size_t readable{((woffset >= roffset) ? woffset : (mBufferDataSize+woffset)) - + const size_t readable{((woffset >= roffset) ? woffset : (mBufferData_.size()+woffset)) - roffset}; - if(mBufferDataSize > 0) + if(!mBufferData_.empty()) { if(readable == 0) return false; @@ -620,7 +621,7 @@ bool AudioState::startPlayback() * the device time the stream would have started at to reach where it * is now. */ - if(mBufferDataSize > 0) + if(!mBufferData_.empty()) { nanoseconds startpts{mCurrentPts - nanoseconds{seconds{readable/mFrameSize}}/mCodecCtx->sample_rate}; @@ -789,17 +790,17 @@ bool AudioState::readAudio(int sample_skip) while(mSamplesLen > 0) { const size_t nsamples{((roffset > woffset) ? roffset-woffset-1 - : (roffset == 0) ? (mBufferDataSize-woffset-1) - : (mBufferDataSize-woffset)) / mFrameSize}; + : (roffset == 0) ? (mBufferData_.size()-woffset-1) + : (mBufferData_.size()-woffset)) / mFrameSize}; if(!nsamples) break; if(mSamplesPos < 0) { const size_t rem{std::min(nsamples, static_cast(-mSamplesPos))}; - sample_dup(&mBufferData[woffset], mSamples, rem, mFrameSize); + sample_dup(&mBufferData_[woffset], mSamples, rem, mFrameSize); woffset += rem * mFrameSize; - if(woffset == mBufferDataSize) woffset = 0; + if(woffset == mBufferData_.size()) woffset = 0; mWritePos.store(woffset, std::memory_order_release); mCurrentPts += nanoseconds{seconds{rem}} / mCodecCtx->sample_rate; @@ -811,9 +812,9 @@ bool AudioState::readAudio(int sample_skip) const size_t boffset{static_cast(mSamplesPos) * size_t{mFrameSize}}; const size_t nbytes{rem * mFrameSize}; - memcpy(&mBufferData[woffset], mSamples + boffset, nbytes); + memcpy(&mBufferData_[woffset], mSamples + boffset, nbytes); woffset += nbytes; - if(woffset == mBufferDataSize) woffset = 0; + if(woffset == mBufferData_.size()) woffset = 0; mWritePos.store(woffset, std::memory_order_release); mCurrentPts += nanoseconds{seconds{rem}} / mCodecCtx->sample_rate; @@ -886,15 +887,15 @@ ALsizei AudioState::bufferCallback(void *data, ALsizei size) noexcept const size_t woffset{mWritePos.load(std::memory_order_relaxed)}; if(woffset == roffset) break; - size_t todo{((woffset < roffset) ? mBufferDataSize : woffset) - roffset}; + size_t todo{((woffset < roffset) ? mBufferData_.size() : woffset) - roffset}; todo = std::min(todo, static_cast(size-got)); - memcpy(data, &mBufferData[roffset], todo); + memcpy(data, &mBufferData_[roffset], todo); data = static_cast(data) + todo; got += static_cast(todo); roffset += todo; - if(roffset == mBufferDataSize) + if(roffset == mBufferData_.size()) roffset = 0; } mReadPos.store(roffset, std::memory_order_release); @@ -934,7 +935,7 @@ int AudioState::handler() }; EventControlManager event_controller{sleep_time}; - std::unique_ptr samples; + std::vector samples; ALsizei buffer_len{0}; /* Find a suitable format for OpenAL. */ @@ -1235,13 +1236,12 @@ int AudioState::handler() } else { - mBufferDataSize = static_cast(duration_cast(mCodecCtx->sample_rate * - AudioBufferTotalTime).count()) * mFrameSize; - mBufferData = std::make_unique(mBufferDataSize); - std::fill_n(mBufferData.get(), mBufferDataSize, uint8_t{}); + mBufferData_.resize(static_cast(duration_cast(mCodecCtx->sample_rate * + AudioBufferTotalTime).count()) * mFrameSize); + std::fill(mBufferData_.begin(), mBufferData_.end(), uint8_t{}); mReadPos.store(0, std::memory_order_relaxed); - mWritePos.store(mBufferDataSize/mFrameSize/2*mFrameSize, std::memory_order_relaxed); + mWritePos.store(mBufferData_.size()/mFrameSize/2*mFrameSize, std::memory_order_relaxed); ALCint refresh{}; alcGetIntegerv(alcGetContextsDevice(alcGetCurrentContext()), ALC_REFRESH, 1, &refresh); @@ -1253,7 +1253,7 @@ int AudioState::handler() buffer_len = static_cast(duration_cast(mCodecCtx->sample_rate * AudioBufferTime).count() * mFrameSize); if(buffer_len > 0) - samples = std::make_unique(static_cast(buffer_len)); + samples.resize(static_cast(buffer_len)); /* Prefill the codec buffer. */ auto packet_sender = [this]() @@ -1301,7 +1301,7 @@ int AudioState::handler() } ALenum state; - if(mBufferDataSize > 0) + if(!mBufferData_.empty()) { alGetSourcei(mSource, AL_SOURCE_STATE, &state); @@ -1331,13 +1331,13 @@ int AudioState::handler() /* Read the next chunk of data, filling the buffer, and queue * it on the source. */ - if(!readAudio(samples.get(), static_cast(buffer_len), sync_skip)) + if(!readAudio(samples.data(), static_cast(buffer_len), sync_skip)) break; const ALuint bufid{mBuffers[mBufferIdx]}; mBufferIdx = static_cast((mBufferIdx+1) % mBuffers.size()); - alBufferData(bufid, mFormat, samples.get(), buffer_len, mCodecCtx->sample_rate); + alBufferData(bufid, mFormat, samples.data(), buffer_len, mCodecCtx->sample_rate); alSourceQueueBuffers(mSource, 1, &bufid); ++queued; } diff --git a/examples/alstreamcb.cpp b/examples/alstreamcb.cpp index b970c920..0b0aeeb7 100644 --- a/examples/alstreamcb.cpp +++ b/examples/alstreamcb.cpp @@ -24,12 +24,12 @@ /* This file contains a streaming audio player using a callback buffer. */ -#include -#include -#include #include #include +#include +#include +#include #include #include #include @@ -58,8 +58,7 @@ struct StreamPlayer { /* A lockless ring-buffer (supports single-provider, single-consumer * operation). */ - std::unique_ptr mBufferData; - size_t mBufferDataSize{0}; + std::vector mBufferData; std::atomic mReadPos{0}; std::atomic mWritePos{0}; size_t mSamplesPerBlock{1}; @@ -234,7 +233,7 @@ struct StreamPlayer { } else if(mSfInfo.channels == 3) { - if(sf_command(mSndfile, SFC_WAVEX_GET_AMBISONIC, NULL, 0) == SF_AMBISONIC_B_FORMAT) + if(sf_command(mSndfile, SFC_WAVEX_GET_AMBISONIC, nullptr, 0) == SF_AMBISONIC_B_FORMAT) { if(mSampleFormat == SampleType::Int16) mFormat = AL_FORMAT_BFORMAT2D_16; @@ -244,7 +243,7 @@ struct StreamPlayer { } else if(mSfInfo.channels == 4) { - if(sf_command(mSndfile, SFC_WAVEX_GET_AMBISONIC, NULL, 0) == SF_AMBISONIC_B_FORMAT) + if(sf_command(mSndfile, SFC_WAVEX_GET_AMBISONIC, nullptr, 0) == SF_AMBISONIC_B_FORMAT) { if(mSampleFormat == SampleType::Int16) mFormat = AL_FORMAT_BFORMAT3D_16; @@ -264,8 +263,7 @@ struct StreamPlayer { /* Set a 1s ring buffer size. */ size_t numblocks{(static_cast(mSfInfo.samplerate) + mSamplesPerBlock-1) / mSamplesPerBlock}; - mBufferDataSize = static_cast(numblocks * mBytesPerBlock); - mBufferData.reset(new ALbyte[mBufferDataSize]); + mBufferData.resize(static_cast(numblocks * mBytesPerBlock)); mReadPos.store(0, std::memory_order_relaxed); mWritePos.store(0, std::memory_order_relaxed); mDecoderOffset = 0; @@ -305,7 +303,7 @@ struct StreamPlayer { * that case, otherwise read up to the write offset. Also limit the * amount to copy given how much is remaining to write. */ - size_t todo{((woffset < roffset) ? mBufferDataSize : woffset) - roffset}; + size_t todo{((woffset < roffset) ? mBufferData.size() : woffset) - roffset}; todo = std::min(todo, static_cast(size-got)); /* Copy from the ring buffer to the provided output buffer. Wrap @@ -317,7 +315,7 @@ struct StreamPlayer { got += static_cast(todo); roffset += todo; - if(roffset == mBufferDataSize) + if(roffset == mBufferData.size()) roffset = 0; } /* Finally, store the updated read offset, and return how many bytes @@ -353,7 +351,7 @@ struct StreamPlayer { if(state != AL_INITIAL) { const size_t roffset{mReadPos.load(std::memory_order_relaxed)}; - const size_t readable{((woffset >= roffset) ? woffset : (mBufferDataSize+woffset)) - + const size_t readable{((woffset >= roffset) ? woffset : (mBufferData.size()+woffset)) - roffset}; /* For a stopped (underrun) source, the current playback offset is * the current decoder offset excluding the readable buffered data. @@ -364,7 +362,7 @@ struct StreamPlayer { ? (mDecoderOffset-readable) / mBytesPerBlock * mSamplesPerBlock : (static_cast(pos) + mStartOffset/mBytesPerBlock*mSamplesPerBlock)) / static_cast(mSfInfo.samplerate)}; - printf("\r%3zus (%3zu%% full)", curtime, readable * 100 / mBufferDataSize); + printf("\r%3zus (%3zu%% full)", curtime, readable * 100 / mBufferData.size()); } else fputs("Starting...", stdout); @@ -417,8 +415,8 @@ struct StreamPlayer { * data can fit, and calculate how much can go in front before * wrapping. */ - const size_t writable{(!roffset ? mBufferDataSize-woffset-1 : - (mBufferDataSize-woffset)) / mBytesPerBlock}; + const size_t writable{(!roffset ? mBufferData.size()-woffset-1 : + (mBufferData.size()-woffset)) / mBytesPerBlock}; if(!writable) break; if(mSampleFormat == SampleType::Int16) @@ -446,7 +444,7 @@ struct StreamPlayer { } woffset += read_bytes; - if(woffset == mBufferDataSize) + if(woffset == mBufferData.size()) woffset = 0; } mWritePos.store(woffset, std::memory_order_release); @@ -461,7 +459,7 @@ struct StreamPlayer { * what's available. */ const size_t roffset{mReadPos.load(std::memory_order_relaxed)}; - const size_t readable{((woffset >= roffset) ? woffset : (mBufferDataSize+woffset)) - + const size_t readable{((woffset >= roffset) ? woffset : (mBufferData.size()+woffset)) - roffset}; if(readable == 0) return false; diff --git a/include/AL/al.h b/include/AL/al.h index 87274184..e9f8f3b1 100644 --- a/include/AL/al.h +++ b/include/AL/al.h @@ -1,6 +1,7 @@ #ifndef AL_AL_H #define AL_AL_H +/* NOLINTBEGIN */ #ifdef __cplusplus extern "C" { @@ -689,5 +690,6 @@ typedef void (AL_APIENTRY *LPALDISTANCEMODEL)(ALenum distanceModel) AL_ #ifdef __cplusplus } /* extern "C" */ #endif +/* NOLINTEND */ #endif /* AL_AL_H */ diff --git a/include/AL/alc.h b/include/AL/alc.h index 73dcf08f..3311b57f 100644 --- a/include/AL/alc.h +++ b/include/AL/alc.h @@ -1,6 +1,7 @@ #ifndef AL_ALC_H #define AL_ALC_H +/* NOLINTBEGIN */ #ifdef __cplusplus extern "C" { @@ -289,5 +290,6 @@ typedef void (ALC_APIENTRY *LPALCCAPTURESAMPLES)(ALCdevice *device, AL #ifdef __cplusplus } /* extern "C" */ #endif +/* NOLINTEND */ #endif /* AL_ALC_H */ diff --git a/include/AL/alext.h b/include/AL/alext.h index c75e0770..3f373704 100644 --- a/include/AL/alext.h +++ b/include/AL/alext.h @@ -1,6 +1,7 @@ #ifndef AL_ALEXT_H #define AL_ALEXT_H +/* NOLINTBEGIN */ #include /* Define int64 and uint64 types */ #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \ @@ -737,5 +738,6 @@ void ALC_APIENTRY alcEventCallbackSOFT(ALCEVENTPROCTYPESOFT callback, void *user #ifdef __cplusplus } #endif +/* NOLINTEND */ #endif diff --git a/include/AL/efx-presets.h b/include/AL/efx-presets.h index 8539fd51..acd5bf39 100644 --- a/include/AL/efx-presets.h +++ b/include/AL/efx-presets.h @@ -2,6 +2,7 @@ #ifndef EFX_PRESETS_H #define EFX_PRESETS_H +/* NOLINTBEGIN */ #ifndef EFXEAXREVERBPROPERTIES_DEFINED #define EFXEAXREVERBPROPERTIES_DEFINED @@ -399,4 +400,5 @@ typedef struct { #define EFX_REVERB_PRESET_SMALLWATERROOM \ { 1.0000f, 0.7000f, 0.3162f, 0.4477f, 1.0000f, 1.5100f, 1.2500f, 1.1400f, 0.8913f, 0.0200f, { 0.0000f, 0.0000f, 0.0000f }, 1.4125f, 0.0300f, { 0.0000f, 0.0000f, 0.0000f }, 0.1790f, 0.1500f, 0.8950f, 0.1900f, 0.9920f, 5000.0000f, 250.0000f, 0.0000f, 0x0 } +/* NOLINTEND */ #endif /* EFX_PRESETS_H */ diff --git a/include/AL/efx.h b/include/AL/efx.h index f24222c3..1e93bf22 100644 --- a/include/AL/efx.h +++ b/include/AL/efx.h @@ -1,6 +1,7 @@ #ifndef AL_EFX_H #define AL_EFX_H +/* NOLINTBEGIN */ #include #include "alc.h" @@ -758,5 +759,6 @@ AL_API void AL_APIENTRY alGetAuxiliaryEffectSlotfv(ALuint effectslot, ALenum par #ifdef __cplusplus } /* extern "C" */ #endif +/* NOLINTEND */ #endif /* AL_EFX_H */ diff --git a/utils/alsoft-config/mainwindow.h b/utils/alsoft-config/mainwindow.h index f7af8eac..e2d30b86 100644 --- a/utils/alsoft-config/mainwindow.h +++ b/utils/alsoft-config/mainwindow.h @@ -8,13 +8,12 @@ namespace Ui { class MainWindow; } -class MainWindow : public QMainWindow -{ +class MainWindow : public QMainWindow { Q_OBJECT public: - explicit MainWindow(QWidget *parent = 0); - ~MainWindow(); + explicit MainWindow(QWidget *parent=nullptr); + ~MainWindow() override; private slots: void cancelCloseAction(); @@ -63,17 +62,17 @@ private slots: private: Ui::MainWindow *ui; - QValidator *mPeriodSizeValidator; - QValidator *mPeriodCountValidator; - QValidator *mSourceCountValidator; - QValidator *mEffectSlotValidator; - QValidator *mSourceSendValidator; - QValidator *mSampleRateValidator; - QValidator *mJackBufferValidator; + QValidator *mPeriodSizeValidator{}; + QValidator *mPeriodCountValidator{}; + QValidator *mSourceCountValidator{}; + QValidator *mEffectSlotValidator{}; + QValidator *mSourceSendValidator{}; + QValidator *mSampleRateValidator{}; + QValidator *mJackBufferValidator{}; - bool mNeedsSave; + bool mNeedsSave{}; - void closeEvent(QCloseEvent *event); + void closeEvent(QCloseEvent *event) override; void selectDecoderFile(QLineEdit *line, const char *name); diff --git a/utils/makemhr/loaddef.cpp b/utils/makemhr/loaddef.cpp index c8a98511..54ba96a3 100644 --- a/utils/makemhr/loaddef.cpp +++ b/utils/makemhr/loaddef.cpp @@ -36,6 +36,7 @@ #include #include +#include "albit.h" #include "alfstream.h" #include "alspan.h" #include "alstring.h" @@ -144,7 +145,7 @@ struct SourceRefT { double mRadius; uint mSkip; uint mOffset; - char mPath[MAX_PATH_LEN+1]; + std::array mPath; }; @@ -389,22 +390,20 @@ static int TrReadIdent(TokenReaderT *tr, const uint maxLen, char *ident) // Reads and validates (including bounds) an integer token. static int TrReadInt(TokenReaderT *tr, const int loBound, const int hiBound, int *value) { - uint col, digis, len; - char ch, temp[64+1]; - - col = tr->mColumn; + uint col{tr->mColumn}; if(TrSkipWhitespace(tr)) { col = tr->mColumn; - len = 0; - ch = tr->mRing[tr->mOut&TR_RING_MASK]; + uint len{0}; + std::array temp{}; + char ch{tr->mRing[tr->mOut&TR_RING_MASK]}; if(ch == '+' || ch == '-') { temp[len] = ch; len++; tr->mOut++; } - digis = 0; + uint digis{0}; while(TrLoad(tr)) { ch = tr->mRing[tr->mOut&TR_RING_MASK]; @@ -424,7 +423,7 @@ static int TrReadInt(TokenReaderT *tr, const int loBound, const int hiBound, int return 0; } temp[len] = '\0'; - *value = static_cast(strtol(temp, nullptr, 10)); + *value = static_cast(strtol(temp.data(), nullptr, 10)); if(*value < loBound || *value > hiBound) { TrErrorAt(tr, tr->mLine, col, "Expected a value from %d to %d.\n", loBound, hiBound); @@ -440,15 +439,13 @@ static int TrReadInt(TokenReaderT *tr, const int loBound, const int hiBound, int // Reads and validates (including bounds) a float token. static int TrReadFloat(TokenReaderT *tr, const double loBound, const double hiBound, double *value) { - uint col, digis, len; - char ch, temp[64+1]; - - col = tr->mColumn; + uint col{tr->mColumn}; if(TrSkipWhitespace(tr)) { col = tr->mColumn; - len = 0; - ch = tr->mRing[tr->mOut&TR_RING_MASK]; + std::array temp{}; + uint len{0}; + char ch{tr->mRing[tr->mOut&TR_RING_MASK]}; if(ch == '+' || ch == '-') { temp[len] = ch; @@ -456,7 +453,7 @@ static int TrReadFloat(TokenReaderT *tr, const double loBound, const double hiBo tr->mOut++; } - digis = 0; + uint digis{0}; while(TrLoad(tr)) { ch = tr->mRing[tr->mOut&TR_RING_MASK]; @@ -520,7 +517,7 @@ static int TrReadFloat(TokenReaderT *tr, const double loBound, const double hiBo return 0; } temp[len] = '\0'; - *value = strtod(temp, nullptr); + *value = strtod(temp.data(), nullptr); if(*value < loBound || *value > hiBound) { TrErrorAt(tr, tr->mLine, col, "Expected a value from %f to %f.\n", loBound, hiBound); @@ -621,8 +618,8 @@ static int TrReadOperator(TokenReaderT *tr, const char *op) // storing it as a 32-bit unsigned integer. static int ReadBin4(std::istream &istream, const char *filename, const ByteOrderT order, const uint bytes, uint32_t *out) { - uint8_t in[4]; - istream.read(reinterpret_cast(in), static_cast(bytes)); + std::array in{}; + istream.read(reinterpret_cast(in.data()), static_cast(bytes)); if(istream.gcount() != bytes) { fprintf(stderr, "\nError: Bad read from file '%s'.\n", filename); @@ -650,29 +647,27 @@ static int ReadBin4(std::istream &istream, const char *filename, const ByteOrder // a 64-bit unsigned integer. static int ReadBin8(std::istream &istream, const char *filename, const ByteOrderT order, uint64_t *out) { - uint8_t in[8]; - uint64_t accum; - uint i; - - istream.read(reinterpret_cast(in), 8); + std::array in{}; + istream.read(reinterpret_cast(in.data()), 8); if(istream.gcount() != 8) { fprintf(stderr, "\nError: Bad read from file '%s'.\n", filename); return 0; } - accum = 0; + + uint64_t accum{}; switch(order) { - case BO_LITTLE: - for(i = 0;i < 8;i++) - accum = (accum<<8) | in[8 - i - 1]; - break; - case BO_BIG: - for(i = 0;i < 8;i++) - accum = (accum<<8) | in[i]; - break; - default: - break; + case BO_LITTLE: + for(uint i{0};i < 8;++i) + accum = (accum<<8) | in[8 - i - 1]; + break; + case BO_BIG: + for(uint i{0};i < 8;++i) + accum = (accum<<8) | in[i]; + break; + default: + break; } *out = accum; return 1; @@ -687,40 +682,32 @@ static int ReadBin8(std::istream &istream, const char *filename, const ByteOrder static int ReadBinAsDouble(std::istream &istream, const char *filename, const ByteOrderT order, const ElementTypeT type, const uint bytes, const int bits, double *out) { - union { - uint32_t ui; - int32_t i; - float f; - } v4; - union { - uint64_t ui; - double f; - } v8; - *out = 0.0; if(bytes > 4) { - if(!ReadBin8(istream, filename, order, &v8.ui)) + uint64_t val{}; + if(!ReadBin8(istream, filename, order, &val)) return 0; if(type == ET_FP) - *out = v8.f; + *out = al::bit_cast(val); } else { - if(!ReadBin4(istream, filename, order, bytes, &v4.ui)) + uint32_t val{}; + if(!ReadBin4(istream, filename, order, bytes, &val)) return 0; if(type == ET_FP) - *out = v4.f; + *out = al::bit_cast(val); else { if(bits > 0) - v4.ui >>= (8*bytes) - (static_cast(bits)); + val >>= (8*bytes) - (static_cast(bits)); else - v4.ui &= (0xFFFFFFFF >> (32+bits)); + val &= (0xFFFFFFFF >> (32+bits)); - if(v4.ui&static_cast(1<<(std::abs(bits)-1))) - v4.ui |= (0xFFFFFFFF << std::abs(bits)); - *out = v4.i / static_cast(1<<(std::abs(bits)-1)); + if(val&static_cast(1<<(std::abs(bits)-1))) + val |= (0xFFFFFFFF << std::abs(bits)); + *out = static_cast(val) / static_cast(1<<(std::abs(bits)-1)); } } return 1; @@ -776,20 +763,20 @@ static int ReadWaveFormat(std::istream &istream, const ByteOrderT order, const u do { if(chunkSize > 0) istream.seekg(static_cast(chunkSize), std::ios::cur); - if(!ReadBin4(istream, src->mPath, BO_LITTLE, 4, &fourCC) - || !ReadBin4(istream, src->mPath, order, 4, &chunkSize)) + if(!ReadBin4(istream, src->mPath.data(), BO_LITTLE, 4, &fourCC) + || !ReadBin4(istream, src->mPath.data(), order, 4, &chunkSize)) return 0; } while(fourCC != FOURCC_FMT); - if(!ReadBin4(istream, src->mPath, order, 2, &format) - || !ReadBin4(istream, src->mPath, order, 2, &channels) - || !ReadBin4(istream, src->mPath, order, 4, &rate) - || !ReadBin4(istream, src->mPath, order, 4, &dummy) - || !ReadBin4(istream, src->mPath, order, 2, &block)) + if(!ReadBin4(istream, src->mPath.data(), order, 2, &format) + || !ReadBin4(istream, src->mPath.data(), order, 2, &channels) + || !ReadBin4(istream, src->mPath.data(), order, 4, &rate) + || !ReadBin4(istream, src->mPath.data(), order, 4, &dummy) + || !ReadBin4(istream, src->mPath.data(), order, 2, &block)) return 0; block /= channels; if(chunkSize > 14) { - if(!ReadBin4(istream, src->mPath, order, 2, &size)) + if(!ReadBin4(istream, src->mPath.data(), order, 2, &size)) return 0; size /= 8; if(block > size) @@ -800,12 +787,12 @@ static int ReadWaveFormat(std::istream &istream, const ByteOrderT order, const u if(format == WAVE_FORMAT_EXTENSIBLE) { istream.seekg(2, std::ios::cur); - if(!ReadBin4(istream, src->mPath, order, 2, &bits)) + if(!ReadBin4(istream, src->mPath.data(), order, 2, &bits)) return 0; if(bits == 0) bits = 8 * size; istream.seekg(4, std::ios::cur); - if(!ReadBin4(istream, src->mPath, order, 2, &format)) + if(!ReadBin4(istream, src->mPath.data(), order, 2, &format)) return 0; istream.seekg(static_cast(chunkSize - 26), std::ios::cur); } @@ -819,29 +806,32 @@ static int ReadWaveFormat(std::istream &istream, const ByteOrderT order, const u } if(format != WAVE_FORMAT_PCM && format != WAVE_FORMAT_IEEE_FLOAT) { - fprintf(stderr, "\nError: Unsupported WAVE format in file '%s'.\n", src->mPath); + fprintf(stderr, "\nError: Unsupported WAVE format in file '%s'.\n", src->mPath.data()); return 0; } if(src->mChannel >= channels) { - fprintf(stderr, "\nError: Missing source channel in WAVE file '%s'.\n", src->mPath); + fprintf(stderr, "\nError: Missing source channel in WAVE file '%s'.\n", src->mPath.data()); return 0; } if(rate != hrirRate) { - fprintf(stderr, "\nError: Mismatched source sample rate in WAVE file '%s'.\n", src->mPath); + fprintf(stderr, "\nError: Mismatched source sample rate in WAVE file '%s'.\n", + src->mPath.data()); return 0; } if(format == WAVE_FORMAT_PCM) { if(size < 2 || size > 4) { - fprintf(stderr, "\nError: Unsupported sample size in WAVE file '%s'.\n", src->mPath); + fprintf(stderr, "\nError: Unsupported sample size in WAVE file '%s'.\n", + src->mPath.data()); return 0; } if(bits < 16 || bits > (8*size)) { - fprintf(stderr, "\nError: Bad significant bits in WAVE file '%s'.\n", src->mPath); + fprintf(stderr, "\nError: Bad significant bits in WAVE file '%s'.\n", + src->mPath.data()); return 0; } src->mType = ET_INT; @@ -850,7 +840,8 @@ static int ReadWaveFormat(std::istream &istream, const ByteOrderT order, const u { if(size != 4 && size != 8) { - fprintf(stderr, "\nError: Unsupported sample size in WAVE file '%s'.\n", src->mPath); + fprintf(stderr, "\nError: Unsupported sample size in WAVE file '%s'.\n", + src->mPath.data()); return 0; } src->mType = ET_FP; @@ -876,7 +867,8 @@ static int ReadWaveData(std::istream &istream, const SourceRefT *src, const Byte skip += pre; if(skip > 0) istream.seekg(skip, std::ios::cur); - if(!ReadBinAsDouble(istream, src->mPath, order, src->mType, src->mSize, src->mBits, &hrir[i])) + if(!ReadBinAsDouble(istream, src->mPath.data(), order, src->mType, src->mSize, src->mBits, + &hrir[i])) return 0; skip = post; } @@ -896,8 +888,8 @@ static int ReadWaveList(std::istream &istream, const SourceRefT *src, const Byte for(;;) { - if(!ReadBin4(istream, src->mPath, BO_LITTLE, 4, &fourCC) - || !ReadBin4(istream, src->mPath, order, 4, &chunkSize)) + if(!ReadBin4(istream, src->mPath.data(), BO_LITTLE, 4, &fourCC) + || !ReadBin4(istream, src->mPath.data(), order, 4, &chunkSize)) return 0; if(fourCC == FOURCC_DATA) @@ -906,7 +898,7 @@ static int ReadWaveList(std::istream &istream, const SourceRefT *src, const Byte count = chunkSize / block; if(count < (src->mOffset + n)) { - fprintf(stderr, "\nError: Bad read from file '%s'.\n", src->mPath); + fprintf(stderr, "\nError: Bad read from file '%s'.\n", src->mPath.data()); return 0; } istream.seekg(static_cast(src->mOffset * block), std::ios::cur); @@ -916,7 +908,7 @@ static int ReadWaveList(std::istream &istream, const SourceRefT *src, const Byte } else if(fourCC == FOURCC_LIST) { - if(!ReadBin4(istream, src->mPath, BO_LITTLE, 4, &fourCC)) + if(!ReadBin4(istream, src->mPath.data(), BO_LITTLE, 4, &fourCC)) return 0; chunkSize -= 4; if(fourCC == FOURCC_WAVL) @@ -932,8 +924,8 @@ static int ReadWaveList(std::istream &istream, const SourceRefT *src, const Byte lastSample = 0.0; while(offset < n && listSize > 8) { - if(!ReadBin4(istream, src->mPath, BO_LITTLE, 4, &fourCC) - || !ReadBin4(istream, src->mPath, order, 4, &chunkSize)) + if(!ReadBin4(istream, src->mPath.data(), BO_LITTLE, 4, &fourCC) + || !ReadBin4(istream, src->mPath.data(), order, 4, &chunkSize)) return 0; listSize -= 8 + chunkSize; if(fourCC == FOURCC_DATA) @@ -961,7 +953,7 @@ static int ReadWaveList(std::istream &istream, const SourceRefT *src, const Byte } else if(fourCC == FOURCC_SLNT) { - if(!ReadBin4(istream, src->mPath, order, 4, &count)) + if(!ReadBin4(istream, src->mPath.data(), order, 4, &count)) return 0; chunkSize -= 4; if(count > skip) @@ -985,7 +977,7 @@ static int ReadWaveList(std::istream &istream, const SourceRefT *src, const Byte } if(offset < n) { - fprintf(stderr, "\nError: Bad read from file '%s'.\n", src->mPath); + fprintf(stderr, "\nError: Bad read from file '%s'.\n", src->mPath.data()); return 0; } return 1; @@ -997,22 +989,25 @@ static int LoadAsciiSource(std::istream &istream, const SourceRefT *src, const uint n, double *hrir) { TokenReaderT tr{istream}; - uint i, j; - double dummy; TrSetup(nullptr, 0, nullptr, &tr); - for(i = 0;i < src->mOffset;i++) + for(uint i{0};i < src->mOffset;++i) { - if(!ReadAsciiAsDouble(&tr, src->mPath, src->mType, static_cast(src->mBits), &dummy)) + double dummy{}; + if(!ReadAsciiAsDouble(&tr, src->mPath.data(), src->mType, static_cast(src->mBits), + &dummy)) return 0; } - for(i = 0;i < n;i++) + for(uint i{0};i < n;++i) { - if(!ReadAsciiAsDouble(&tr, src->mPath, src->mType, static_cast(src->mBits), &hrir[i])) + if(!ReadAsciiAsDouble(&tr, src->mPath.data(), src->mType, static_cast(src->mBits), + &hrir[i])) return 0; - for(j = 0;j < src->mSkip;j++) + for(uint j{0};j < src->mSkip;++j) { - if(!ReadAsciiAsDouble(&tr, src->mPath, src->mType, static_cast(src->mBits), &dummy)) + double dummy{}; + if(!ReadAsciiAsDouble(&tr, src->mPath.data(), src->mType, + static_cast(src->mBits), &dummy)) return 0; } } @@ -1026,7 +1021,8 @@ static int LoadBinarySource(std::istream &istream, const SourceRefT *src, const istream.seekg(static_cast(src->mOffset), std::ios::beg); for(uint i{0};i < n;i++) { - if(!ReadBinAsDouble(istream, src->mPath, order, src->mType, src->mSize, src->mBits, &hrir[i])) + if(!ReadBinAsDouble(istream, src->mPath.data(), order, src->mType, src->mSize, src->mBits, + &hrir[i])) return 0; if(src->mSkip > 0) istream.seekg(static_cast(src->mSkip), std::ios::cur); @@ -1041,8 +1037,8 @@ static int LoadWaveSource(std::istream &istream, SourceRefT *src, const uint hri uint32_t fourCC, dummy; ByteOrderT order; - if(!ReadBin4(istream, src->mPath, BO_LITTLE, 4, &fourCC) - || !ReadBin4(istream, src->mPath, BO_LITTLE, 4, &dummy)) + if(!ReadBin4(istream, src->mPath.data(), BO_LITTLE, 4, &fourCC) + || !ReadBin4(istream, src->mPath.data(), BO_LITTLE, 4, &dummy)) return 0; if(fourCC == FOURCC_RIFF) order = BO_LITTLE; @@ -1050,15 +1046,15 @@ static int LoadWaveSource(std::istream &istream, SourceRefT *src, const uint hri order = BO_BIG; else { - fprintf(stderr, "\nError: No RIFF/RIFX chunk in file '%s'.\n", src->mPath); + fprintf(stderr, "\nError: No RIFF/RIFX chunk in file '%s'.\n", src->mPath.data()); return 0; } - if(!ReadBin4(istream, src->mPath, BO_LITTLE, 4, &fourCC)) + if(!ReadBin4(istream, src->mPath.data(), BO_LITTLE, 4, &fourCC)) return 0; if(fourCC != FOURCC_WAVE) { - fprintf(stderr, "\nError: Not a RIFF/RIFX WAVE file '%s'.\n", src->mPath); + fprintf(stderr, "\nError: Not a RIFF/RIFX WAVE file '%s'.\n", src->mPath.data()); return 0; } if(!ReadWaveFormat(istream, order, hrirRate, src)) @@ -1073,7 +1069,7 @@ static int LoadWaveSource(std::istream &istream, SourceRefT *src, const uint hri // Load a Spatially Oriented Format for Accoustics (SOFA) file. static MYSOFA_EASY* LoadSofaFile(SourceRefT *src, const uint hrirRate, const uint n) { - struct MYSOFA_EASY *sofa{mysofa_cache_lookup(src->mPath, static_cast(hrirRate))}; + MYSOFA_EASY *sofa{mysofa_cache_lookup(src->mPath.data(), static_cast(hrirRate))}; if(sofa) return sofa; sofa = static_cast(calloc(1, sizeof(*sofa))); @@ -1086,27 +1082,27 @@ static MYSOFA_EASY* LoadSofaFile(SourceRefT *src, const uint hrirRate, const uin sofa->neighborhood = nullptr; int err; - sofa->hrtf = mysofa_load(src->mPath, &err); + sofa->hrtf = mysofa_load(src->mPath.data(), &err); if(!sofa->hrtf) { mysofa_close(sofa); - fprintf(stderr, "\nError: Could not load source file '%s'.\n", src->mPath); + fprintf(stderr, "\nError: Could not load source file '%s'.\n", src->mPath.data()); return nullptr; } /* NOTE: Some valid SOFA files are failing this check. */ err = mysofa_check(sofa->hrtf); if(err != MYSOFA_OK) - fprintf(stderr, "\nWarning: Supposedly malformed source file '%s'.\n", src->mPath); + fprintf(stderr, "\nWarning: Supposedly malformed source file '%s'.\n", src->mPath.data()); if((src->mOffset + n) > sofa->hrtf->N) { mysofa_close(sofa); - fprintf(stderr, "\nError: Not enough samples in SOFA file '%s'.\n", src->mPath); + fprintf(stderr, "\nError: Not enough samples in SOFA file '%s'.\n", src->mPath.data()); return nullptr; } if(src->mChannel >= sofa->hrtf->R) { mysofa_close(sofa); - fprintf(stderr, "\nError: Missing source receiver in SOFA file '%s'.\n", src->mPath); + fprintf(stderr, "\nError: Missing source receiver in SOFA file '%s'.\n",src->mPath.data()); return nullptr; } mysofa_tocartesian(sofa->hrtf); @@ -1117,7 +1113,7 @@ static MYSOFA_EASY* LoadSofaFile(SourceRefT *src, const uint hrirRate, const uin fprintf(stderr, "\nError: Out of memory.\n"); return nullptr; } - return mysofa_cache_store(sofa, src->mPath, static_cast(hrirRate)); + return mysofa_cache_store(sofa, src->mPath.data(), static_cast(hrirRate)); } // Copies the HRIR data from a particular SOFA measurement. @@ -1131,40 +1127,39 @@ static void ExtractSofaHrir(const MYSOFA_EASY *sofa, const uint index, const uin // file. static int LoadSofaSource(SourceRefT *src, const uint hrirRate, const uint n, double *hrir) { - struct MYSOFA_EASY *sofa; - float target[3]; - int nearest; - float *coords; + MYSOFA_EASY *sofa{LoadSofaFile(src, hrirRate, n)}; + if(sofa == nullptr) return 0; - sofa = LoadSofaFile(src, hrirRate, n); - if(sofa == nullptr) - return 0; - - /* NOTE: At some point it may be benficial or necessary to consider the + /* NOTE: At some point it may be beneficial or necessary to consider the various coordinate systems, listener/source orientations, and - direciontal vectors defined in the SOFA file. + directional vectors defined in the SOFA file. */ - target[0] = static_cast(src->mAzimuth); - target[1] = static_cast(src->mElevation); - target[2] = static_cast(src->mRadius); - mysofa_s2c(target); - - nearest = mysofa_lookup(sofa->lookup, target); + std::array target{ + static_cast(src->mAzimuth), + static_cast(src->mElevation), + static_cast(src->mRadius) + }; + mysofa_s2c(target.data()); + + int nearest{mysofa_lookup(sofa->lookup, target.data())}; if(nearest < 0) { - fprintf(stderr, "\nError: Lookup failed in source file '%s'.\n", src->mPath); + fprintf(stderr, "\nError: Lookup failed in source file '%s'.\n", src->mPath.data()); return 0; } - coords = &sofa->hrtf->SourcePosition.values[3 * nearest]; - if(std::abs(coords[0] - target[0]) > 0.001 || std::abs(coords[1] - target[1]) > 0.001 || std::abs(coords[2] - target[2]) > 0.001) + al::span coords{&sofa->hrtf->SourcePosition.values[3 * nearest], 3}; + if(std::abs(coords[0] - target[0]) > 0.001 || std::abs(coords[1] - target[1]) > 0.001 + || std::abs(coords[2] - target[2]) > 0.001) { - fprintf(stderr, "\nError: No impulse response at coordinates (%.3fr, %.1fev, %.1faz) in file '%s'.\n", src->mRadius, src->mElevation, src->mAzimuth, src->mPath); + fprintf(stderr, "\nError: No impulse response at coordinates (%.3fr, %.1fev, %.1faz) in file '%s'.\n", + src->mRadius, src->mElevation, src->mAzimuth, src->mPath.data()); target[0] = coords[0]; target[1] = coords[1]; target[2] = coords[2]; - mysofa_c2s(target); - fprintf(stderr, " Nearest candidate at (%.3fr, %.1fev, %.1faz).\n", target[2], target[1], target[0]); + mysofa_c2s(target.data()); + fprintf(stderr, " Nearest candidate at (%.3fr, %.1fev, %.1faz).\n", target[2], + target[1], target[0]); return 0; } @@ -1180,12 +1175,12 @@ static int LoadSource(SourceRefT *src, const uint hrirRate, const uint n, double if(src->mFormat != SF_SOFA) { if(src->mFormat == SF_ASCII) - istream.reset(new al::ifstream{src->mPath}); + istream = std::make_unique(src->mPath.data()); else - istream.reset(new al::ifstream{src->mPath, std::ios::binary}); + istream = std::make_unique(src->mPath.data(), std::ios::binary); if(!istream->good()) { - fprintf(stderr, "\nError: Could not open source file '%s'.\n", src->mPath); + fprintf(stderr, "\nError: Could not open source file '%s'.\n", src->mPath.data()); return 0; } } @@ -1230,14 +1225,14 @@ static int ProcessMetrics(TokenReaderT *tr, const uint fftSize, const uint trunc { int hasRate = 0, hasType = 0, hasPoints = 0, hasRadius = 0; int hasDistance = 0, hasAzimuths = 0; - char ident[MAX_IDENT_LEN+1]; + std::array ident; uint line, col; double fpVal; uint points; int intVal; - double distances[MAX_FD_COUNT]; + std::array distances; uint fdCount = 0; - uint evCounts[MAX_FD_COUNT]; + std::array evCounts; auto azCounts = std::vector>(MAX_FD_COUNT); for(auto &azs : azCounts) azs.fill(0u); @@ -1245,9 +1240,9 @@ static int ProcessMetrics(TokenReaderT *tr, const uint fftSize, const uint trunc while(TrIsIdent(tr)) { TrIndication(tr, &line, &col); - if(!TrReadIdent(tr, MAX_IDENT_LEN, ident)) + if(!TrReadIdent(tr, MAX_IDENT_LEN, ident.data())) return 0; - if(al::strcasecmp(ident, "rate") == 0) + if(al::strcasecmp(ident.data(), "rate") == 0) { if(hasRate) { @@ -1261,9 +1256,9 @@ static int ProcessMetrics(TokenReaderT *tr, const uint fftSize, const uint trunc hData->mIrRate = static_cast(intVal); hasRate = 1; } - else if(al::strcasecmp(ident, "type") == 0) + else if(al::strcasecmp(ident.data(), "type") == 0) { - char type[MAX_IDENT_LEN+1]; + std::array type; if(hasType) { @@ -1273,9 +1268,9 @@ static int ProcessMetrics(TokenReaderT *tr, const uint fftSize, const uint trunc if(!TrReadOperator(tr, "=")) return 0; - if(!TrReadIdent(tr, MAX_IDENT_LEN, type)) + if(!TrReadIdent(tr, MAX_IDENT_LEN, type.data())) return 0; - hData->mChannelType = MatchChannelType(type); + hData->mChannelType = MatchChannelType(type.data()); if(hData->mChannelType == CT_NONE) { TrErrorAt(tr, line, col, "Expected a channel type.\n"); @@ -1288,7 +1283,7 @@ static int ProcessMetrics(TokenReaderT *tr, const uint fftSize, const uint trunc } hasType = 1; } - else if(al::strcasecmp(ident, "points") == 0) + else if(al::strcasecmp(ident.data(), "points") == 0) { if(hasPoints) { @@ -1318,7 +1313,7 @@ static int ProcessMetrics(TokenReaderT *tr, const uint fftSize, const uint trunc hData->mIrSize = points; hasPoints = 1; } - else if(al::strcasecmp(ident, "radius") == 0) + else if(al::strcasecmp(ident.data(), "radius") == 0) { if(hasRadius) { @@ -1332,7 +1327,7 @@ static int ProcessMetrics(TokenReaderT *tr, const uint fftSize, const uint trunc hData->mRadius = fpVal; hasRadius = 1; } - else if(al::strcasecmp(ident, "distance") == 0) + else if(al::strcasecmp(ident.data(), "distance") == 0) { uint count = 0; @@ -1371,7 +1366,7 @@ static int ProcessMetrics(TokenReaderT *tr, const uint fftSize, const uint trunc fdCount = count; hasDistance = 1; } - else if(al::strcasecmp(ident, "azimuths") == 0) + else if(al::strcasecmp(ident.data(), "azimuths") == 0) { uint count = 0; @@ -1451,7 +1446,7 @@ static int ProcessMetrics(TokenReaderT *tr, const uint fftSize, const uint trunc if(hData->mChannelType == CT_NONE) hData->mChannelType = CT_MONO; const auto azs = al::span{azCounts}.first(); - if(!PrepareHrirData({distances, fdCount}, evCounts, azs, hData)) + if(!PrepareHrirData(al::span{distances}.first(fdCount), evCounts, azs, hData)) { fprintf(stderr, "Error: Out of memory.\n"); exit(-1); @@ -1516,15 +1511,15 @@ static ElementTypeT MatchElementType(const char *ident) // Parse and validate a source reference from the data set definition. static int ReadSourceRef(TokenReaderT *tr, SourceRefT *src) { - char ident[MAX_IDENT_LEN+1]; + std::array ident; uint line, col; double fpVal; int intVal; TrIndication(tr, &line, &col); - if(!TrReadIdent(tr, MAX_IDENT_LEN, ident)) + if(!TrReadIdent(tr, MAX_IDENT_LEN, ident.data())) return 0; - src->mFormat = MatchSourceFormat(ident); + src->mFormat = MatchSourceFormat(ident.data()); if(src->mFormat == SF_NONE) { TrErrorAt(tr, line, col, "Expected a source format.\n"); @@ -1570,9 +1565,9 @@ static int ReadSourceRef(TokenReaderT *tr, SourceRefT *src) else { TrIndication(tr, &line, &col); - if(!TrReadIdent(tr, MAX_IDENT_LEN, ident)) + if(!TrReadIdent(tr, MAX_IDENT_LEN, ident.data())) return 0; - src->mType = MatchElementType(ident); + src->mType = MatchElementType(ident.data()); if(src->mType == ET_NONE) { TrErrorAt(tr, line, col, "Expected a source element type.\n"); @@ -1655,7 +1650,7 @@ static int ReadSourceRef(TokenReaderT *tr, SourceRefT *src) src->mOffset = 0; if(!TrReadOperator(tr, ":")) return 0; - if(!TrReadString(tr, MAX_PATH_LEN, src->mPath)) + if(!TrReadString(tr, MAX_PATH_LEN, src->mPath.data())) return 0; return 1; } @@ -1663,14 +1658,14 @@ static int ReadSourceRef(TokenReaderT *tr, SourceRefT *src) // Parse and validate a SOFA source reference from the data set definition. static int ReadSofaRef(TokenReaderT *tr, SourceRefT *src) { - char ident[MAX_IDENT_LEN+1]; + std::array ident; uint line, col; int intVal; TrIndication(tr, &line, &col); - if(!TrReadIdent(tr, MAX_IDENT_LEN, ident)) + if(!TrReadIdent(tr, MAX_IDENT_LEN, ident.data())) return 0; - src->mFormat = MatchSourceFormat(ident); + src->mFormat = MatchSourceFormat(ident.data()); if(src->mFormat != SF_SOFA) { TrErrorAt(tr, line, col, "Expected the SOFA source format.\n"); @@ -1694,7 +1689,7 @@ static int ReadSofaRef(TokenReaderT *tr, SourceRefT *src) src->mOffset = 0; if(!TrReadOperator(tr, ":")) return 0; - if(!TrReadString(tr, MAX_PATH_LEN, src->mPath)) + if(!TrReadString(tr, MAX_PATH_LEN, src->mPath.data())) return 0; return 1; } @@ -1747,7 +1742,7 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData, const uint outRate const uint channels{(hData->mChannelType == CT_STEREO) ? 2u : 1u}; hData->mHrirsBase.resize(channels * hData->mIrCount * hData->mIrSize); double *hrirs = hData->mHrirsBase.data(); - auto hrir = std::make_unique(hData->mIrSize); + auto hrir = std::vector(hData->mIrSize); uint line, col, fi, ei, ai; std::vector onsetSamples(OnsetRateMultiple * hData->mIrPoints); @@ -1767,57 +1762,50 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData, const uint outRate int count{0}; while(TrIsOperator(tr, "[")) { - double factor[2]{ 1.0, 1.0 }; + std::array factor{1.0, 1.0}; TrIndication(tr, &line, &col); TrReadOperator(tr, "["); if(TrIsOperator(tr, "*")) { - SourceRefT src; - struct MYSOFA_EASY *sofa; - uint si; - TrReadOperator(tr, "*"); if(!TrReadOperator(tr, "]") || !TrReadOperator(tr, "=")) return 0; TrIndication(tr, &line, &col); + SourceRefT src{}; if(!ReadSofaRef(tr, &src)) return 0; if(hData->mChannelType == CT_STEREO) { - char type[MAX_IDENT_LEN+1]; - ChannelTypeT channelType; + std::array type{}; - if(!TrReadIdent(tr, MAX_IDENT_LEN, type)) + if(!TrReadIdent(tr, MAX_IDENT_LEN, type.data())) return 0; - channelType = MatchChannelType(type); - + const ChannelTypeT channelType{MatchChannelType(type.data())}; switch(channelType) { - case CT_NONE: - TrErrorAt(tr, line, col, "Expected a channel type.\n"); - return 0; - case CT_MONO: - src.mChannel = 0; - break; - case CT_STEREO: - src.mChannel = 1; - break; + case CT_NONE: + TrErrorAt(tr, line, col, "Expected a channel type.\n"); + return 0; + case CT_MONO: + src.mChannel = 0; + break; + case CT_STEREO: + src.mChannel = 1; + break; } } else { - char type[MAX_IDENT_LEN+1]; - ChannelTypeT channelType; - - if(!TrReadIdent(tr, MAX_IDENT_LEN, type)) + std::array type{}; + if(!TrReadIdent(tr, MAX_IDENT_LEN, type.data())) return 0; - channelType = MatchChannelType(type); + ChannelTypeT channelType{MatchChannelType(type.data())}; if(channelType != CT_MONO) { TrErrorAt(tr, line, col, "Expected a mono channel type.\n"); @@ -1826,20 +1814,20 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData, const uint outRate src.mChannel = 0; } - sofa = LoadSofaFile(&src, hData->mIrRate, hData->mIrPoints); + MYSOFA_EASY *sofa{LoadSofaFile(&src, hData->mIrRate, hData->mIrPoints)}; if(!sofa) return 0; - for(si = 0;si < sofa->hrtf->M;si++) + for(uint si{0};si < sofa->hrtf->M;++si) { printf("\rLoading sources... %d of %d", si+1, sofa->hrtf->M); fflush(stdout); - float aer[3] = { + std::array aer{ sofa->hrtf->SourcePosition.values[3*si], sofa->hrtf->SourcePosition.values[3*si + 1], sofa->hrtf->SourcePosition.values[3*si + 2] }; - mysofa_c2s(aer); + mysofa_c2s(aer.data()); if(std::fabs(aer[1]) >= 89.999f) aer[0] = 0.0f; @@ -1875,24 +1863,25 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData, const uint outRate return 0; } - ExtractSofaHrir(sofa, si, 0, src.mOffset, hData->mIrPoints, hrir.get()); + ExtractSofaHrir(sofa, si, 0, src.mOffset, hData->mIrPoints, hrir.data()); azd->mIrs[0] = &hrirs[hData->mIrSize * azd->mIndex]; azd->mDelays[0] = AverageHrirOnset(onsetResampler, onsetSamples, hData->mIrRate, - hData->mIrPoints, hrir.get(), 1.0, azd->mDelays[0]); + hData->mIrPoints, hrir.data(), 1.0, azd->mDelays[0]); if(resampler) - resampler->process(hData->mIrPoints, hrir.get(), hData->mIrSize, hrir.get()); - AverageHrirMagnitude(irPoints, hData->mFftSize, hrir.get(), 1.0, azd->mIrs[0]); + resampler->process(hData->mIrPoints, hrir.data(), hData->mIrSize, hrir.data()); + AverageHrirMagnitude(irPoints, hData->mFftSize, hrir.data(), 1.0, azd->mIrs[0]); if(src.mChannel == 1) { - ExtractSofaHrir(sofa, si, 1, src.mOffset, hData->mIrPoints, hrir.get()); + ExtractSofaHrir(sofa, si, 1, src.mOffset, hData->mIrPoints, hrir.data()); azd->mIrs[1] = &hrirs[hData->mIrSize * (hData->mIrCount + azd->mIndex)]; azd->mDelays[1] = AverageHrirOnset(onsetResampler, onsetSamples, - hData->mIrRate, hData->mIrPoints, hrir.get(), 1.0, azd->mDelays[1]); + hData->mIrRate, hData->mIrPoints, hrir.data(), 1.0, azd->mDelays[1]); if(resampler) - resampler->process(hData->mIrPoints, hrir.get(), hData->mIrSize, - hrir.get()); - AverageHrirMagnitude(irPoints, hData->mFftSize, hrir.get(), 1.0, azd->mIrs[1]); + resampler->process(hData->mIrPoints, hrir.data(), hData->mIrSize, + hrir.data()); + AverageHrirMagnitude(irPoints, hData->mFftSize, hrir.data(), 1.0, + azd->mIrs[1]); } // TODO: Since some SOFA files contain minimum phase HRIRs, @@ -1917,10 +1906,9 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData, const uint outRate if(!TrReadOperator(tr, "=")) return 0; - for(;;) + while(true) { - SourceRefT src; - + SourceRefT src{}; if(!ReadSourceRef(tr, &src)) return 0; @@ -1931,17 +1919,16 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData, const uint outRate printf("\rLoading sources... %d file%s", count, (count==1)?"":"s"); fflush(stdout); - if(!LoadSource(&src, hData->mIrRate, hData->mIrPoints, hrir.get())) + if(!LoadSource(&src, hData->mIrRate, hData->mIrPoints, hrir.data())) return 0; uint ti{0}; if(hData->mChannelType == CT_STEREO) { - char ident[MAX_IDENT_LEN+1]; - - if(!TrReadIdent(tr, MAX_IDENT_LEN, ident)) + std::array ident{}; + if(!TrReadIdent(tr, MAX_IDENT_LEN, ident.data())) return 0; - ti = static_cast(MatchTargetEar(ident)); + ti = static_cast(MatchTargetEar(ident.data())); if(static_cast(ti) < 0) { TrErrorAt(tr, line, col, "Expected a target ear.\n"); @@ -1950,10 +1937,10 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData, const uint outRate } azd->mIrs[ti] = &hrirs[hData->mIrSize * (ti * hData->mIrCount + azd->mIndex)]; azd->mDelays[ti] = AverageHrirOnset(onsetResampler, onsetSamples, hData->mIrRate, - hData->mIrPoints, hrir.get(), 1.0 / factor[ti], azd->mDelays[ti]); + hData->mIrPoints, hrir.data(), 1.0 / factor[ti], azd->mDelays[ti]); if(resampler) - resampler->process(hData->mIrPoints, hrir.get(), hData->mIrSize, hrir.get()); - AverageHrirMagnitude(irPoints, hData->mFftSize, hrir.get(), 1.0 / factor[ti], + resampler->process(hData->mIrPoints, hrir.data(), hData->mIrSize, hrir.data()); + AverageHrirMagnitude(irPoints, hData->mFftSize, hrir.data(), 1.0 / factor[ti], azd->mIrs[ti]); factor[ti] += 1.0; if(!TrIsOperator(tr, "+")) @@ -1975,7 +1962,7 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData, const uint outRate } } printf("\n"); - hrir = nullptr; + hrir.clear(); if(resampler) { hData->mIrRate = outRate; diff --git a/utils/makemhr/loadsofa.cpp b/utils/makemhr/loadsofa.cpp index 9bcfc38d..4b2ba2f4 100644 --- a/utils/makemhr/loadsofa.cpp +++ b/utils/makemhr/loadsofa.cpp @@ -65,8 +65,8 @@ static bool PrepareLayout(const uint m, const float *xyzs, HrirDataT *hData) return false; } - double distances[MAX_FD_COUNT]{}; - uint evCounts[MAX_FD_COUNT]{}; + std::array distances{}; + std::array evCounts{}; auto azCounts = std::vector>(MAX_FD_COUNT); for(auto &azs : azCounts) azs.fill(0u); @@ -88,7 +88,7 @@ static bool PrepareLayout(const uint m, const float *xyzs, HrirDataT *hData) } fprintf(stdout, "Using %u of %u IRs.\n", ir_total, m); const auto azs = al::span{azCounts}.first(); - return PrepareHrirData({distances, fi}, evCounts, azs, hData); + return PrepareHrirData(al::span{distances}.first(fi), evCounts, azs, hData); } @@ -264,24 +264,24 @@ static bool LoadResponses(MYSOFA_HRTF *sofaHrtf, HrirDataT *hData, const DelayTy hData->mHrirsBase.resize(channels * hData->mIrCount * hData->mIrSize, 0.0); double *hrirs = hData->mHrirsBase.data(); - std::unique_ptr restmp; + std::vector restmp; std::optional resampler; if(outRate && outRate != hData->mIrRate) { resampler.emplace().init(hData->mIrRate, outRate); - restmp = std::make_unique(sofaHrtf->N); + restmp.resize(sofaHrtf->N); } for(uint si{0u};si < sofaHrtf->M;++si) { loaded_count.fetch_add(1u); - float aer[3]{ + std::array aer{ sofaHrtf->SourcePosition.values[3*si], sofaHrtf->SourcePosition.values[3*si + 1], sofaHrtf->SourcePosition.values[3*si + 2] }; - mysofa_c2s(aer); + mysofa_c2s(aer.data()); if(std::abs(aer[1]) >= 89.999f) aer[0] = 0.0f; @@ -324,8 +324,8 @@ static bool LoadResponses(MYSOFA_HRTF *sofaHrtf, HrirDataT *hData, const DelayTy else { std::copy_n(&sofaHrtf->DataIR.values[(si*sofaHrtf->R + ti)*sofaHrtf->N], - sofaHrtf->N, restmp.get()); - resampler->process(sofaHrtf->N, restmp.get(), hData->mIrSize, azd->mIrs[ti]); + sofaHrtf->N, restmp.data()); + resampler->process(sofaHrtf->N, restmp.data(), hData->mIrSize, azd->mIrs[ti]); } } @@ -382,7 +382,7 @@ struct MagCalculator { { auto htemp = std::vector(mFftSize); - while(1) + while(true) { /* Load the current index to process. */ size_t idx{mCurrent.load()}; diff --git a/utils/makemhr/makemhr.cpp b/utils/makemhr/makemhr.cpp index 8291ac0f..3c0da19f 100644 --- a/utils/makemhr/makemhr.cpp +++ b/utils/makemhr/makemhr.cpp @@ -324,13 +324,11 @@ static int WriteAscii(const char *out, FILE *fp, const char *filename) // loading it from a 32-bit unsigned integer. static int WriteBin4(const uint bytes, const uint32_t in, FILE *fp, const char *filename) { - uint8_t out[4]; - uint i; - - for(i = 0;i < bytes;i++) + std::array out{}; + for(uint i{0};i < bytes;i++) out[i] = (in>>(i*8)) & 0x000000FF; - if(fwrite(out, 1, bytes, fp) != bytes) + if(fwrite(out.data(), 1, bytes, fp) != bytes) { fprintf(stderr, "\nError: Bad write to file '%s'.\n", filename); return 0; @@ -387,11 +385,11 @@ static int StoreMhr(const HrirDataT *hData, const char *filename) for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzs.size();ai++) { HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai]; - double out[2 * MAX_TRUNCSIZE]; + std::array out{}; - TpdfDither(out, azd->mIrs[0], scale, n, channels, &dither_seed); + TpdfDither(out.data(), azd->mIrs[0], scale, n, channels, &dither_seed); if(hData->mChannelType == CT_STEREO) - TpdfDither(out+1, azd->mIrs[1], scale, n, channels, &dither_seed); + TpdfDither(out.data()+1, azd->mIrs[1], scale, n, channels, &dither_seed); for(i = 0;i < (channels * n);i++) { const auto v = static_cast(Clamp(out[i], -scale-1.0, scale)); @@ -732,12 +730,12 @@ static void SynthesizeOnsets(HrirDataT *hData) double az{field.mEvs[ei].mAzs[ai].mAzimuth}; CalcAzIndices(field, upperElevReal, az, &a0, &a1, &af0); CalcAzIndices(field, lowerElevFake, az, &a2, &a3, &af1); - double blend[4]{ + std::array blend{{ (1.0-ef) * (1.0-af0), (1.0-ef) * ( af0), ( ef) * (1.0-af1), ( ef) * ( af1) - }; + }}; for(uint ti{0u};ti < channels;ti++) { @@ -794,7 +792,7 @@ static void SynthesizeHrirs(HrirDataT *hData) { const double of{static_cast(ei) / field.mEvStart}; const double b{(1.0 - of) * beta}; - double lp[4]{}; + std::array lp{}; /* Calculate a low-pass filter to simulate body occlusion. */ lp[0] = Lerp(1.0, lp[0], b); @@ -839,7 +837,7 @@ static void SynthesizeHrirs(HrirDataT *hData) } } const double b{beta}; - double lp[4]{}; + std::array lp{}; lp[0] = Lerp(1.0, lp[0], b); lp[1] = Lerp(lp[0], lp[1], b); lp[2] = Lerp(lp[1], lp[2], b); @@ -885,7 +883,7 @@ struct HrirReconstructor { auto mags = std::vector(mFftSize); size_t m{(mFftSize/2) + 1}; - while(1) + while(true) { /* Load the current index to process. */ size_t idx{mCurrent.load()}; @@ -988,7 +986,7 @@ static void NormalizeHrirs(HrirDataT *hData) return LevelPair{std::max(current.amp, levels.amp), std::max(current.rms, levels.rms)}; }; auto measure_azi = [channels,mesasure_channel](const LevelPair levels, const HrirAzT &azi) - { return std::accumulate(azi.mIrs, azi.mIrs+channels, levels, mesasure_channel); }; + { return std::accumulate(azi.mIrs.begin(), azi.mIrs.begin()+channels, levels, mesasure_channel); }; auto measure_elev = [measure_azi](const LevelPair levels, const HrirEvT &elev) { return std::accumulate(elev.mAzs.cbegin(), elev.mAzs.cend(), levels, measure_azi); }; auto measure_field = [measure_elev](const LevelPair levels, const HrirFdT &field) @@ -1015,7 +1013,7 @@ static void NormalizeHrirs(HrirDataT *hData) auto proc_channel = [irSize,factor](double *ir) { std::transform(ir, ir+irSize, ir, [factor](double s){ return s * factor; }); }; auto proc_azi = [channels,proc_channel](HrirAzT &azi) - { std::for_each(azi.mIrs, azi.mIrs+channels, proc_channel); }; + { std::for_each(azi.mIrs.begin(), azi.mIrs.begin()+channels, proc_channel); }; auto proc_elev = [proc_azi](HrirEvT &elev) { std::for_each(elev.mAzs.begin(), elev.mAzs.end(), proc_azi); }; auto proc1_field = [proc_elev](HrirFdT &field) @@ -1196,10 +1194,10 @@ static int ProcessDefinition(const char *inName, const uint outRate, const Chann return 0; } - char startbytes[4]{}; - input->read(startbytes, sizeof(startbytes)); + std::array startbytes{}; + input->read(startbytes.data(), startbytes.size()); std::streamsize startbytecount{input->gcount()}; - if(startbytecount != sizeof(startbytes) || !input->good()) + if(startbytecount != startbytes.size() || !input->good()) { fprintf(stderr, "Error: Could not read input file '%s'\n", inName); return 0; @@ -1216,7 +1214,8 @@ static int ProcessDefinition(const char *inName, const uint outRate, const Chann else { fprintf(stdout, "Reading HRIR definition from %s...\n", inName); - if(!LoadDefInput(*input, startbytes, startbytecount, inName, fftSize, truncSize, outRate, chanMode, &hData)) + if(!LoadDefInput(*input, startbytes.data(), startbytecount, inName, fftSize, truncSize, + outRate, chanMode, &hData)) return 0; } } diff --git a/utils/makemhr/makemhr.h b/utils/makemhr/makemhr.h index aa18134d..3a105fc2 100644 --- a/utils/makemhr/makemhr.h +++ b/utils/makemhr/makemhr.h @@ -68,8 +68,8 @@ enum ChannelTypeT { struct HrirAzT { double mAzimuth{0.0}; uint mIndex{0u}; - double mDelays[2]{0.0, 0.0}; - double *mIrs[2]{nullptr, nullptr}; + std::array mDelays{}; + std::array mIrs{}; }; struct HrirEvT { diff --git a/utils/sofa-info.cpp b/utils/sofa-info.cpp index 6dffef44..7775b8e3 100644 --- a/utils/sofa-info.cpp +++ b/utils/sofa-info.cpp @@ -21,8 +21,7 @@ * Or visit: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html */ -#include - +#include #include #include diff --git a/utils/sofa-support.cpp b/utils/sofa-support.cpp index e37789d5..ceb3067a 100644 --- a/utils/sofa-support.cpp +++ b/utils/sofa-support.cpp @@ -24,11 +24,11 @@ #include "sofa-support.h" -#include #include #include #include +#include #include #include @@ -47,7 +47,7 @@ using double3 = std::array; * equality of unique elements. */ std::vector GetUniquelySortedElems(const std::vector &aers, const uint axis, - const double *const (&filters)[3], const double (&epsilons)[3]) + const std::array filters, const std::array epsilons) { std::vector elems; for(const double3 &aer : aers) @@ -183,8 +183,8 @@ std::vector GetCompatibleLayout(const size_t m, const float *xyzs) auto aers = std::vector(m, double3{}); for(size_t i{0u};i < m;++i) { - float vals[3]{xyzs[i*3], xyzs[i*3 + 1], xyzs[i*3 + 2]}; - mysofa_c2s(&vals[0]); + std::array vals{xyzs[i*3], xyzs[i*3 + 1], xyzs[i*3 + 2]}; + mysofa_c2s(vals.data()); aers[i] = {vals[0], vals[1], vals[2]}; } diff --git a/utils/uhjdecoder.cpp b/utils/uhjdecoder.cpp index c7efa376..feca0a35 100644 --- a/utils/uhjdecoder.cpp +++ b/utils/uhjdecoder.cpp @@ -66,22 +66,22 @@ using complex_d = std::complex; using byte4 = std::array; -constexpr ubyte SUBTYPE_BFORMAT_FLOAT[]{ +constexpr std::array SUBTYPE_BFORMAT_FLOAT{ 0x03, 0x00, 0x00, 0x00, 0x21, 0x07, 0xd3, 0x11, 0x86, 0x44, 0xc8, 0xc1, 0xca, 0x00, 0x00, 0x00 }; void fwrite16le(ushort val, FILE *f) { - ubyte data[2]{ static_cast(val&0xff), static_cast((val>>8)&0xff) }; - fwrite(data, 1, 2, f); + std::array data{static_cast(val&0xff), static_cast((val>>8)&0xff)}; + fwrite(data.data(), 1, data.size(), f); } void fwrite32le(uint val, FILE *f) { - ubyte data[4]{ static_cast(val&0xff), static_cast((val>>8)&0xff), - static_cast((val>>16)&0xff), static_cast((val>>24)&0xff) }; - fwrite(data, 1, 4, f); + std::array data{static_cast(val&0xff), static_cast((val>>8)&0xff), + static_cast((val>>16)&0xff), static_cast((val>>24)&0xff)}; + fwrite(data.data(), 1, data.size(), f); } template @@ -389,7 +389,7 @@ int main(int argc, char **argv) fprintf(stderr, "Failed to open %s\n", argv[fidx]); continue; } - if(sf_command(infile.get(), SFC_WAVEX_GET_AMBISONIC, NULL, 0) == SF_AMBISONIC_B_FORMAT) + if(sf_command(infile.get(), SFC_WAVEX_GET_AMBISONIC, nullptr, 0) == SF_AMBISONIC_B_FORMAT) { fprintf(stderr, "%s is already B-Format\n", argv[fidx]); continue; @@ -438,7 +438,7 @@ int main(int argc, char **argv) // 32-bit val, frequency fwrite32le(static_cast(ininfo.samplerate), outfile.get()); // 32-bit val, bytes per second - fwrite32le(static_cast(ininfo.samplerate)*sizeof(float)*outchans, outfile.get()); + fwrite32le(static_cast(ininfo.samplerate)*outchans*sizeof(float), outfile.get()); // 16-bit val, frame size fwrite16le(static_cast(sizeof(float)*outchans), outfile.get()); // 16-bit val, bits per sample @@ -450,7 +450,7 @@ int main(int argc, char **argv) // 32-bit val, channel mask fwrite32le(0, outfile.get()); // 16 byte GUID, sub-type format - fwrite(SUBTYPE_BFORMAT_FLOAT, 1, 16, outfile.get()); + fwrite(SUBTYPE_BFORMAT_FLOAT.data(), 1, SUBTYPE_BFORMAT_FLOAT.size(), outfile.get()); fputs("data", outfile.get()); fwrite32le(0xFFFFFFFF, outfile.get()); // 'data' header len; filled in at close @@ -463,9 +463,9 @@ int main(int argc, char **argv) auto DataStart = ftell(outfile.get()); auto decoder = std::make_unique(); - auto inmem = std::make_unique(BufferLineSize*static_cast(ininfo.channels)); + auto inmem = std::vector(BufferLineSize*static_cast(ininfo.channels)); auto decmem = al::vector, 16>(outchans); - auto outmem = std::make_unique(BufferLineSize*outchans); + auto outmem = std::vector(BufferLineSize*outchans); /* A number of initial samples need to be skipped to cut the lead-in * from the all-pass filter delay. The same number of samples need to @@ -476,21 +476,21 @@ int main(int argc, char **argv) sf_count_t LeadOut{UhjDecoder::sFilterDelay}; while(LeadOut > 0) { - sf_count_t sgot{sf_readf_float(infile.get(), inmem.get(), BufferLineSize)}; + sf_count_t sgot{sf_readf_float(infile.get(), inmem.data(), BufferLineSize)}; sgot = std::max(sgot, 0); if(sgot < BufferLineSize) { const sf_count_t remaining{std::min(BufferLineSize - sgot, LeadOut)}; - std::fill_n(inmem.get() + sgot*ininfo.channels, remaining*ininfo.channels, 0.0f); + std::fill_n(inmem.data() + sgot*ininfo.channels, remaining*ininfo.channels, 0.0f); sgot += remaining; LeadOut -= remaining; } auto got = static_cast(sgot); if(ininfo.channels > 2 || use_general) - decoder->decode(inmem.get(), static_cast(ininfo.channels), decmem, got); + decoder->decode(inmem.data(), static_cast(ininfo.channels), decmem, got); else - decoder->decode2(inmem.get(), decmem, got); + decoder->decode2(inmem.data(), decmem, got); if(LeadIn >= got) { LeadIn -= got; @@ -507,7 +507,7 @@ int main(int argc, char **argv) } LeadIn = 0; - std::size_t wrote{fwrite(outmem.get(), sizeof(byte4)*outchans, got, outfile.get())}; + std::size_t wrote{fwrite(outmem.data(), sizeof(byte4)*outchans, got, outfile.get())}; if(wrote < got) { fprintf(stderr, "Error writing wave data: %s (%d)\n", strerror(errno), errno); diff --git a/utils/uhjencoder.cpp b/utils/uhjencoder.cpp index 154a1155..8673dd59 100644 --- a/utils/uhjencoder.cpp +++ b/utils/uhjencoder.cpp @@ -26,9 +26,9 @@ #include #include +#include #include #include -#include #include #include #include @@ -179,50 +179,55 @@ struct SpeakerPos { }; /* Azimuth is counter-clockwise. */ -constexpr SpeakerPos StereoMap[2]{ - { SF_CHANNEL_MAP_LEFT, 30.0f, 0.0f }, - { SF_CHANNEL_MAP_RIGHT, -30.0f, 0.0f }, -}, QuadMap[4]{ - { SF_CHANNEL_MAP_LEFT, 45.0f, 0.0f }, - { SF_CHANNEL_MAP_RIGHT, -45.0f, 0.0f }, - { SF_CHANNEL_MAP_REAR_LEFT, 135.0f, 0.0f }, - { SF_CHANNEL_MAP_REAR_RIGHT, -135.0f, 0.0f }, -}, X51Map[6]{ - { SF_CHANNEL_MAP_LEFT, 30.0f, 0.0f }, - { SF_CHANNEL_MAP_RIGHT, -30.0f, 0.0f }, - { SF_CHANNEL_MAP_CENTER, 0.0f, 0.0f }, - { SF_CHANNEL_MAP_LFE, 0.0f, 0.0f }, - { SF_CHANNEL_MAP_SIDE_LEFT, 110.0f, 0.0f }, - { SF_CHANNEL_MAP_SIDE_RIGHT, -110.0f, 0.0f }, -}, X51RearMap[6]{ - { SF_CHANNEL_MAP_LEFT, 30.0f, 0.0f }, - { SF_CHANNEL_MAP_RIGHT, -30.0f, 0.0f }, - { SF_CHANNEL_MAP_CENTER, 0.0f, 0.0f }, - { SF_CHANNEL_MAP_LFE, 0.0f, 0.0f }, - { SF_CHANNEL_MAP_REAR_LEFT, 110.0f, 0.0f }, - { SF_CHANNEL_MAP_REAR_RIGHT, -110.0f, 0.0f }, -}, X71Map[8]{ - { SF_CHANNEL_MAP_LEFT, 30.0f, 0.0f }, - { SF_CHANNEL_MAP_RIGHT, -30.0f, 0.0f }, - { SF_CHANNEL_MAP_CENTER, 0.0f, 0.0f }, - { SF_CHANNEL_MAP_LFE, 0.0f, 0.0f }, - { SF_CHANNEL_MAP_REAR_LEFT, 150.0f, 0.0f }, - { SF_CHANNEL_MAP_REAR_RIGHT, -150.0f, 0.0f }, - { SF_CHANNEL_MAP_SIDE_LEFT, 90.0f, 0.0f }, - { SF_CHANNEL_MAP_SIDE_RIGHT, -90.0f, 0.0f }, -}, X714Map[12]{ - { SF_CHANNEL_MAP_LEFT, 30.0f, 0.0f }, - { SF_CHANNEL_MAP_RIGHT, -30.0f, 0.0f }, - { SF_CHANNEL_MAP_CENTER, 0.0f, 0.0f }, - { SF_CHANNEL_MAP_LFE, 0.0f, 0.0f }, - { SF_CHANNEL_MAP_REAR_LEFT, 150.0f, 0.0f }, - { SF_CHANNEL_MAP_REAR_RIGHT, -150.0f, 0.0f }, - { SF_CHANNEL_MAP_SIDE_LEFT, 90.0f, 0.0f }, - { SF_CHANNEL_MAP_SIDE_RIGHT, -90.0f, 0.0f }, - { SF_CHANNEL_MAP_TOP_FRONT_LEFT, 45.0f, 35.0f }, - { SF_CHANNEL_MAP_TOP_FRONT_RIGHT, -45.0f, 35.0f }, - { SF_CHANNEL_MAP_TOP_REAR_LEFT, 135.0f, 35.0f }, - { SF_CHANNEL_MAP_TOP_REAR_RIGHT, -135.0f, 35.0f }, +constexpr std::array StereoMap{ + SpeakerPos{SF_CHANNEL_MAP_LEFT, 30.0f, 0.0f}, + SpeakerPos{SF_CHANNEL_MAP_RIGHT, -30.0f, 0.0f}, +}; +constexpr std::array QuadMap{ + SpeakerPos{SF_CHANNEL_MAP_LEFT, 45.0f, 0.0f}, + SpeakerPos{SF_CHANNEL_MAP_RIGHT, -45.0f, 0.0f}, + SpeakerPos{SF_CHANNEL_MAP_REAR_LEFT, 135.0f, 0.0f}, + SpeakerPos{SF_CHANNEL_MAP_REAR_RIGHT, -135.0f, 0.0f}, +}; +constexpr std::array X51Map{ + SpeakerPos{SF_CHANNEL_MAP_LEFT, 30.0f, 0.0f}, + SpeakerPos{SF_CHANNEL_MAP_RIGHT, -30.0f, 0.0f}, + SpeakerPos{SF_CHANNEL_MAP_CENTER, 0.0f, 0.0f}, + SpeakerPos{SF_CHANNEL_MAP_LFE, 0.0f, 0.0f}, + SpeakerPos{SF_CHANNEL_MAP_SIDE_LEFT, 110.0f, 0.0f}, + SpeakerPos{SF_CHANNEL_MAP_SIDE_RIGHT, -110.0f, 0.0f}, +}; +constexpr std::array X51RearMap{ + SpeakerPos{SF_CHANNEL_MAP_LEFT, 30.0f, 0.0f}, + SpeakerPos{SF_CHANNEL_MAP_RIGHT, -30.0f, 0.0f}, + SpeakerPos{SF_CHANNEL_MAP_CENTER, 0.0f, 0.0f}, + SpeakerPos{SF_CHANNEL_MAP_LFE, 0.0f, 0.0f}, + SpeakerPos{SF_CHANNEL_MAP_REAR_LEFT, 110.0f, 0.0f}, + SpeakerPos{SF_CHANNEL_MAP_REAR_RIGHT, -110.0f, 0.0f}, +}; +constexpr std::array X71Map{ + SpeakerPos{SF_CHANNEL_MAP_LEFT, 30.0f, 0.0f}, + SpeakerPos{SF_CHANNEL_MAP_RIGHT, -30.0f, 0.0f}, + SpeakerPos{SF_CHANNEL_MAP_CENTER, 0.0f, 0.0f}, + SpeakerPos{SF_CHANNEL_MAP_LFE, 0.0f, 0.0f}, + SpeakerPos{SF_CHANNEL_MAP_REAR_LEFT, 150.0f, 0.0f}, + SpeakerPos{SF_CHANNEL_MAP_REAR_RIGHT, -150.0f, 0.0f}, + SpeakerPos{SF_CHANNEL_MAP_SIDE_LEFT, 90.0f, 0.0f}, + SpeakerPos{SF_CHANNEL_MAP_SIDE_RIGHT, -90.0f, 0.0f}, +}; +constexpr std::array X714Map{ + SpeakerPos{SF_CHANNEL_MAP_LEFT, 30.0f, 0.0f}, + SpeakerPos{SF_CHANNEL_MAP_RIGHT, -30.0f, 0.0f}, + SpeakerPos{SF_CHANNEL_MAP_CENTER, 0.0f, 0.0f}, + SpeakerPos{SF_CHANNEL_MAP_LFE, 0.0f, 0.0f}, + SpeakerPos{SF_CHANNEL_MAP_REAR_LEFT, 150.0f, 0.0f}, + SpeakerPos{SF_CHANNEL_MAP_REAR_RIGHT, -150.0f, 0.0f}, + SpeakerPos{SF_CHANNEL_MAP_SIDE_LEFT, 90.0f, 0.0f}, + SpeakerPos{SF_CHANNEL_MAP_SIDE_RIGHT, -90.0f, 0.0f}, + SpeakerPos{SF_CHANNEL_MAP_TOP_FRONT_LEFT, 45.0f, 35.0f}, + SpeakerPos{SF_CHANNEL_MAP_TOP_FRONT_RIGHT, -45.0f, 35.0f}, + SpeakerPos{SF_CHANNEL_MAP_TOP_REAR_LEFT, 135.0f, 35.0f}, + SpeakerPos{SF_CHANNEL_MAP_TOP_REAR_RIGHT, -135.0f, 35.0f}, }; constexpr auto GenCoeffs(double x /*+front*/, double y /*+left*/, double z /*+up*/) noexcept -- cgit v1.2.3 From 32dbdd9d0443e9fdd150a2ccc6c0682f5fd8206e Mon Sep 17 00:00:00 2001 From: "Boris I. Bendovsky" Date: Thu, 21 Dec 2023 21:44:29 +0200 Subject: [EAX] Fix error handling (#953) - Set error on EAX call failure if context is available. - Reset error on successful retreiving the last error code. Reference: EAX 4.0 - Programmer's Guide (pg.37) --- al/eax/api.h | 1 + alc/context.cpp | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'al/eax') diff --git a/al/eax/api.h b/al/eax/api.h index 038fdf75..0b019f11 100644 --- a/al/eax/api.h +++ b/al/eax/api.h @@ -362,6 +362,7 @@ constexpr auto EAXCONTEXT_MINMACROFXFACTOR = 0.0F; constexpr auto EAXCONTEXT_MAXMACROFXFACTOR = 1.0F; constexpr auto EAXCONTEXT_DEFAULTMACROFXFACTOR = 0.0F; +constexpr auto EAXCONTEXT_DEFAULTLASTERROR = EAX_OK; extern const GUID EAXPROPERTYID_EAX40_FXSlot0; extern const GUID EAXPROPERTYID_EAX50_FXSlot0; diff --git a/alc/context.cpp b/alc/context.cpp index ff22acdf..b5db03f9 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -586,7 +586,7 @@ void ALCcontext::eax_update_speaker_configuration() void ALCcontext::eax_set_last_error_defaults() noexcept { - mEaxLastError = EAX_OK; + mEaxLastError = EAXCONTEXT_DEFAULTLASTERROR; } void ALCcontext::eax_session_set_defaults() noexcept @@ -675,6 +675,7 @@ void ALCcontext::eax_get_misc(const EaxCall& call) break; case EAXCONTEXT_LASTERROR: call.set_value(mEaxLastError); + mEaxLastError = EAX_OK; break; case EAXCONTEXT_SPEAKERCONFIG: call.set_value(mEaxSpeakerConfig); @@ -1045,6 +1046,7 @@ try } catch(...) { + context->eaxSetLastError(); eax_log_exception(__func__); return AL_INVALID_OPERATION; } @@ -1072,6 +1074,7 @@ try } catch(...) { + context->eaxSetLastError(); eax_log_exception(__func__); return AL_INVALID_OPERATION; } -- cgit v1.2.3 From 2be61898ff31a7ada524a1fa06be30ddb4b78a22 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 22 Dec 2023 01:22:49 -0800 Subject: Use std::visit instead of manually checking the set type --- al/eax/effect.h | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) (limited to 'al/eax') diff --git a/al/eax/effect.h b/al/eax/effect.h index afe4d94d..14506846 100644 --- a/al/eax/effect.h +++ b/al/eax/effect.h @@ -296,31 +296,21 @@ public: #define EAXCALL(Props, Callable, ...) \ - if(std::holds_alternative(Props)) \ - return Callable(__VA_ARGS__); \ - if(std::holds_alternative(Props)) \ - return Callable(__VA_ARGS__); \ - if(std::holds_alternative(Props)) \ - return Callable(__VA_ARGS__); \ - if(std::holds_alternative(Props)) \ - return Callable(__VA_ARGS__); \ - if(std::holds_alternative(Props)) \ - return Callable(__VA_ARGS__); \ - if(std::holds_alternative(Props)) \ - return Callable(__VA_ARGS__); \ - if(std::holds_alternative(Props)) \ - return Callable(__VA_ARGS__); \ - if(std::holds_alternative(Props)) \ - return Callable(__VA_ARGS__); \ - if(std::holds_alternative(Props)) \ - return Callable(__VA_ARGS__); \ - if(std::holds_alternative(Props)) \ - return Callable(__VA_ARGS__); \ - if(std::holds_alternative(Props)) \ - return Callable(__VA_ARGS__); \ - if(std::holds_alternative(Props)) \ - return Callable(__VA_ARGS__); \ - return Callable(__VA_ARGS__) + return std::visit(overloaded{ \ + [&](const std::monostate&) { return Callable(__VA_ARGS__); }, \ + [&](const EAXREVERBPROPERTIES&) { return Callable(__VA_ARGS__); }, \ + [&](const EAXCHORUSPROPERTIES&) { return Callable(__VA_ARGS__); }, \ + [&](const EAXAUTOWAHPROPERTIES&) { return Callable(__VA_ARGS__); }, \ + [&](const EAXAGCCOMPRESSORPROPERTIES&) { return Callable(__VA_ARGS__); }, \ + [&](const EAXDISTORTIONPROPERTIES&) { return Callable(__VA_ARGS__); }, \ + [&](const EAXECHOPROPERTIES&) { return Callable(__VA_ARGS__); }, \ + [&](const EAXEQUALIZERPROPERTIES&) { return Callable(__VA_ARGS__); }, \ + [&](const EAXFLANGERPROPERTIES&) { return Callable(__VA_ARGS__); }, \ + [&](const EAXFREQUENCYSHIFTERPROPERTIES&) { return Callable(__VA_ARGS__); }, \ + [&](const EAXRINGMODULATORPROPERTIES&) { return Callable(__VA_ARGS__); }, \ + [&](const EAXPITCHSHIFTERPROPERTIES&) { return Callable(__VA_ARGS__); }, \ + [&](const EAXVOCALMORPHERPROPERTIES&) { return Callable(__VA_ARGS__); } \ + }, Props) template static void call_set(Args&& ...args) -- cgit v1.2.3 From 8346f77af0068d175cc9ecbf4c8894a2d1bcd617 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 22 Dec 2023 01:36:47 -0800 Subject: Replace a series of if statements with a switch --- al/eax/effect.h | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) (limited to 'al/eax') diff --git a/al/eax/effect.h b/al/eax/effect.h index 14506846..a24f85fa 100644 --- a/al/eax/effect.h +++ b/al/eax/effect.h @@ -239,30 +239,22 @@ public: void call_set_defaults(const ALenum altype, EaxEffectProps &props) { - if(altype == AL_EFFECT_EAXREVERB) - return call_set_defaults(props); - if(altype == AL_EFFECT_CHORUS) - return call_set_defaults(props); - if(altype == AL_EFFECT_AUTOWAH) - return call_set_defaults(props); - if(altype == AL_EFFECT_COMPRESSOR) - return call_set_defaults(props); - if(altype == AL_EFFECT_DISTORTION) - return call_set_defaults(props); - if(altype == AL_EFFECT_ECHO) - return call_set_defaults(props); - if(altype == AL_EFFECT_EQUALIZER) - return call_set_defaults(props); - if(altype == AL_EFFECT_FLANGER) - return call_set_defaults(props); - if(altype == AL_EFFECT_FREQUENCY_SHIFTER) - return call_set_defaults(props); - if(altype == AL_EFFECT_RING_MODULATOR) - return call_set_defaults(props); - if(altype == AL_EFFECT_PITCH_SHIFTER) - return call_set_defaults(props); - if(altype == AL_EFFECT_VOCAL_MORPHER) - return call_set_defaults(props); + switch(altype) + { + case AL_EFFECT_EAXREVERB: return call_set_defaults(props); + case AL_EFFECT_CHORUS: return call_set_defaults(props); + case AL_EFFECT_AUTOWAH: return call_set_defaults(props); + case AL_EFFECT_COMPRESSOR: return call_set_defaults(props); + case AL_EFFECT_DISTORTION: return call_set_defaults(props); + case AL_EFFECT_ECHO: return call_set_defaults(props); + case AL_EFFECT_EQUALIZER: return call_set_defaults(props); + case AL_EFFECT_FLANGER: return call_set_defaults(props); + case AL_EFFECT_FREQUENCY_SHIFTER: return call_set_defaults(props); + case AL_EFFECT_RING_MODULATOR: return call_set_defaults(props); + case AL_EFFECT_PITCH_SHIFTER: return call_set_defaults(props); + case AL_EFFECT_VOCAL_MORPHER: return call_set_defaults(props); + case AL_EFFECT_NULL: break; + } return call_set_defaults(props); } -- cgit v1.2.3 From a80efab1749615e7cc0301ca7515e7a28db93191 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 22 Dec 2023 13:44:08 -0800 Subject: Avoid a function-like macro for calling to EAX effects --- al/eax/effect.h | 55 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 20 deletions(-) (limited to 'al/eax') diff --git a/al/eax/effect.h b/al/eax/effect.h index a24f85fa..4108f65f 100644 --- a/al/eax/effect.h +++ b/al/eax/effect.h @@ -189,6 +189,26 @@ struct EaxNullCommitter : public EaxCommitter { using EaxCommitter::EaxCommitter; }; +template +struct CommitterFromProps { }; + +template<> struct CommitterFromProps { using type = EaxNullCommitter; }; +template<> struct CommitterFromProps { using type = EaxReverbCommitter; }; +template<> struct CommitterFromProps { using type = EaxChorusCommitter; }; +template<> struct CommitterFromProps { using type = EaxCompressorCommitter; }; +template<> struct CommitterFromProps { using type = EaxAutowahCommitter; }; +template<> struct CommitterFromProps { using type = EaxDistortionCommitter; }; +template<> struct CommitterFromProps { using type = EaxEchoCommitter; }; +template<> struct CommitterFromProps { using type = EaxEqualizerCommitter; }; +template<> struct CommitterFromProps { using type = EaxFlangerCommitter; }; +template<> struct CommitterFromProps { using type = EaxFrequencyShifterCommitter; }; +template<> struct CommitterFromProps { using type = EaxModulatorCommitter; }; +template<> struct CommitterFromProps { using type = EaxPitchShifterCommitter; }; +template<> struct CommitterFromProps { using type = EaxVocalMorpherCommitter; }; + +template +using CommitterFor = typename CommitterFromProps>>::type; + class EaxEffect { public: @@ -287,29 +307,16 @@ public: } -#define EAXCALL(Props, Callable, ...) \ - return std::visit(overloaded{ \ - [&](const std::monostate&) { return Callable(__VA_ARGS__); }, \ - [&](const EAXREVERBPROPERTIES&) { return Callable(__VA_ARGS__); }, \ - [&](const EAXCHORUSPROPERTIES&) { return Callable(__VA_ARGS__); }, \ - [&](const EAXAUTOWAHPROPERTIES&) { return Callable(__VA_ARGS__); }, \ - [&](const EAXAGCCOMPRESSORPROPERTIES&) { return Callable(__VA_ARGS__); }, \ - [&](const EAXDISTORTIONPROPERTIES&) { return Callable(__VA_ARGS__); }, \ - [&](const EAXECHOPROPERTIES&) { return Callable(__VA_ARGS__); }, \ - [&](const EAXEQUALIZERPROPERTIES&) { return Callable(__VA_ARGS__); }, \ - [&](const EAXFLANGERPROPERTIES&) { return Callable(__VA_ARGS__); }, \ - [&](const EAXFREQUENCYSHIFTERPROPERTIES&) { return Callable(__VA_ARGS__); }, \ - [&](const EAXRINGMODULATORPROPERTIES&) { return Callable(__VA_ARGS__); }, \ - [&](const EAXPITCHSHIFTERPROPERTIES&) { return Callable(__VA_ARGS__); }, \ - [&](const EAXVOCALMORPHERPROPERTIES&) { return Callable(__VA_ARGS__); } \ - }, Props) - template static void call_set(Args&& ...args) { return T::Set(std::forward(args)...); } static void call_set(const EaxCall &call, EaxEffectProps &props) - { EAXCALL(props, call_set, call, props); } + { + return std::visit([&](const auto &arg) + { return call_set>(call, props); }, + props); + } void set(const EaxCall &call) { @@ -330,7 +337,11 @@ public: { return T::Get(std::forward(args)...); } static void call_get(const EaxCall &call, const EaxEffectProps &props) - { EAXCALL(props, call_get, call, props); } + { + return std::visit([&](const auto &arg) + { return call_get>(call, props); }, + props); + } void get(const EaxCall &call) { @@ -350,7 +361,11 @@ public: { return T{props_, al_effect_props_}.commit(std::forward(args)...); } bool call_commit(const EaxEffectProps &props) - { EAXCALL(props, call_commit, props); } + { + return std::visit([&](const auto &arg) + { return call_commit>(props); }, + props); + } bool commit(int eax_version) { -- cgit v1.2.3 From c253a4353227be00ecd7995b8c7443ebfcd6d5a9 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 22 Dec 2023 22:21:33 -0800 Subject: Avoid some template hackery for EAX effect type functions --- al/eax/effect.h | 156 ++++++++++++++++++++++++++++++---------------- al/effects/autowah.cpp | 12 ++-- al/effects/chorus.cpp | 24 +++---- al/effects/compressor.cpp | 12 ++-- al/effects/distortion.cpp | 12 ++-- al/effects/echo.cpp | 12 ++-- al/effects/equalizer.cpp | 12 ++-- al/effects/fshifter.cpp | 12 ++-- al/effects/modulator.cpp | 12 ++-- al/effects/null.cpp | 12 ++-- al/effects/pshifter.cpp | 12 ++-- al/effects/vmorpher.cpp | 96 +++++++--------------------- 12 files changed, 169 insertions(+), 215 deletions(-) (limited to 'al/eax') diff --git a/al/eax/effect.h b/al/eax/effect.h index 4108f65f..ce581990 100644 --- a/al/eax/effect.h +++ b/al/eax/effect.h @@ -144,6 +144,10 @@ struct EaxCommitter { [[noreturn]] static void fail(const char *message); [[noreturn]] static void fail_unknown_property_id() { fail(EaxEffectErrorMessages::unknown_property_id()); } +}; + +struct EaxAutowahCommitter : public EaxCommitter { + using EaxCommitter::EaxCommitter; bool commit(const EaxEffectProps &props); @@ -151,42 +155,104 @@ struct EaxCommitter { static void Get(const EaxCall &call, const EaxEffectProps &props); static void Set(const EaxCall &call, EaxEffectProps &props); }; - -struct EaxAutowahCommitter : public EaxCommitter { - using EaxCommitter::EaxCommitter; -}; struct EaxChorusCommitter : public EaxCommitter { using EaxCommitter::EaxCommitter; + + bool commit(const EaxEffectProps &props); + + static void SetDefaults(EaxEffectProps &props); + static void Get(const EaxCall &call, const EaxEffectProps &props); + static void Set(const EaxCall &call, EaxEffectProps &props); }; struct EaxCompressorCommitter : public EaxCommitter { using EaxCommitter::EaxCommitter; + + bool commit(const EaxEffectProps &props); + + static void SetDefaults(EaxEffectProps &props); + static void Get(const EaxCall &call, const EaxEffectProps &props); + static void Set(const EaxCall &call, EaxEffectProps &props); }; struct EaxDistortionCommitter : public EaxCommitter { using EaxCommitter::EaxCommitter; + + bool commit(const EaxEffectProps &props); + + static void SetDefaults(EaxEffectProps &props); + static void Get(const EaxCall &call, const EaxEffectProps &props); + static void Set(const EaxCall &call, EaxEffectProps &props); }; struct EaxEchoCommitter : public EaxCommitter { using EaxCommitter::EaxCommitter; + + bool commit(const EaxEffectProps &props); + + static void SetDefaults(EaxEffectProps &props); + static void Get(const EaxCall &call, const EaxEffectProps &props); + static void Set(const EaxCall &call, EaxEffectProps &props); }; struct EaxEqualizerCommitter : public EaxCommitter { using EaxCommitter::EaxCommitter; + + bool commit(const EaxEffectProps &props); + + static void SetDefaults(EaxEffectProps &props); + static void Get(const EaxCall &call, const EaxEffectProps &props); + static void Set(const EaxCall &call, EaxEffectProps &props); }; struct EaxFlangerCommitter : public EaxCommitter { using EaxCommitter::EaxCommitter; + + bool commit(const EaxEffectProps &props); + + static void SetDefaults(EaxEffectProps &props); + static void Get(const EaxCall &call, const EaxEffectProps &props); + static void Set(const EaxCall &call, EaxEffectProps &props); }; struct EaxFrequencyShifterCommitter : public EaxCommitter { using EaxCommitter::EaxCommitter; + + bool commit(const EaxEffectProps &props); + + static void SetDefaults(EaxEffectProps &props); + static void Get(const EaxCall &call, const EaxEffectProps &props); + static void Set(const EaxCall &call, EaxEffectProps &props); }; struct EaxModulatorCommitter : public EaxCommitter { using EaxCommitter::EaxCommitter; + + bool commit(const EaxEffectProps &props); + + static void SetDefaults(EaxEffectProps &props); + static void Get(const EaxCall &call, const EaxEffectProps &props); + static void Set(const EaxCall &call, EaxEffectProps &props); }; struct EaxPitchShifterCommitter : public EaxCommitter { using EaxCommitter::EaxCommitter; + + bool commit(const EaxEffectProps &props); + + static void SetDefaults(EaxEffectProps &props); + static void Get(const EaxCall &call, const EaxEffectProps &props); + static void Set(const EaxCall &call, EaxEffectProps &props); }; struct EaxVocalMorpherCommitter : public EaxCommitter { using EaxCommitter::EaxCommitter; + + bool commit(const EaxEffectProps &props); + + static void SetDefaults(EaxEffectProps &props); + static void Get(const EaxCall &call, const EaxEffectProps &props); + static void Set(const EaxCall &call, EaxEffectProps &props); }; struct EaxNullCommitter : public EaxCommitter { using EaxCommitter::EaxCommitter; + + bool commit(const EaxEffectProps &props); + + static void SetDefaults(EaxEffectProps &props); + static void Get(const EaxCall &call, const EaxEffectProps &props); + static void Set(const EaxCall &call, EaxEffectProps &props); }; template @@ -253,43 +319,39 @@ public: State4 state5_{}; - template - void call_set_defaults(Args&& ...args) - { return T::SetDefaults(std::forward(args)...); } - void call_set_defaults(const ALenum altype, EaxEffectProps &props) { switch(altype) { - case AL_EFFECT_EAXREVERB: return call_set_defaults(props); - case AL_EFFECT_CHORUS: return call_set_defaults(props); - case AL_EFFECT_AUTOWAH: return call_set_defaults(props); - case AL_EFFECT_COMPRESSOR: return call_set_defaults(props); - case AL_EFFECT_DISTORTION: return call_set_defaults(props); - case AL_EFFECT_ECHO: return call_set_defaults(props); - case AL_EFFECT_EQUALIZER: return call_set_defaults(props); - case AL_EFFECT_FLANGER: return call_set_defaults(props); - case AL_EFFECT_FREQUENCY_SHIFTER: return call_set_defaults(props); - case AL_EFFECT_RING_MODULATOR: return call_set_defaults(props); - case AL_EFFECT_PITCH_SHIFTER: return call_set_defaults(props); - case AL_EFFECT_VOCAL_MORPHER: return call_set_defaults(props); + case AL_EFFECT_EAXREVERB: return EaxReverbCommitter::SetDefaults(props); + case AL_EFFECT_CHORUS: return EaxChorusCommitter::SetDefaults(props); + case AL_EFFECT_AUTOWAH: return EaxAutowahCommitter::SetDefaults(props); + case AL_EFFECT_COMPRESSOR: return EaxCompressorCommitter::SetDefaults(props); + case AL_EFFECT_DISTORTION: return EaxDistortionCommitter::SetDefaults(props); + case AL_EFFECT_ECHO: return EaxEchoCommitter::SetDefaults(props); + case AL_EFFECT_EQUALIZER: return EaxEqualizerCommitter::SetDefaults(props); + case AL_EFFECT_FLANGER: return EaxFlangerCommitter::SetDefaults(props); + case AL_EFFECT_FREQUENCY_SHIFTER: return EaxFrequencyShifterCommitter::SetDefaults(props); + case AL_EFFECT_RING_MODULATOR: return EaxModulatorCommitter::SetDefaults(props); + case AL_EFFECT_PITCH_SHIFTER: return EaxPitchShifterCommitter::SetDefaults(props); + case AL_EFFECT_VOCAL_MORPHER: return EaxVocalMorpherCommitter::SetDefaults(props); case AL_EFFECT_NULL: break; } - return call_set_defaults(props); + return EaxNullCommitter::SetDefaults(props); } template void init() { - call_set_defaults(state1_.d); + EaxReverbCommitter::SetDefaults(state1_.d); state1_.i = state1_.d; - call_set_defaults(state2_.d); + EaxReverbCommitter::SetDefaults(state2_.d); state2_.i = state2_.d; - call_set_defaults(state3_.d); + EaxReverbCommitter::SetDefaults(state3_.d); state3_.i = state3_.d; - call_set_defaults(state4_.d); + T::SetDefaults(state4_.d); state4_.i = state4_.d; - call_set_defaults(state5_.d); + T::SetDefaults(state5_.d); state5_.i = state5_.d; } @@ -297,9 +359,9 @@ public: { switch(eax_version) { - case 1: call_set_defaults(state1_.d); break; - case 2: call_set_defaults(state2_.d); break; - case 3: call_set_defaults(state3_.d); break; + case 1: EaxReverbCommitter::SetDefaults(state1_.d); break; + case 2: EaxReverbCommitter::SetDefaults(state2_.d); break; + case 3: EaxReverbCommitter::SetDefaults(state3_.d); break; case 4: call_set_defaults(altype, state4_.d); break; case 5: call_set_defaults(altype, state5_.d); break; } @@ -307,14 +369,10 @@ public: } - template - static void call_set(Args&& ...args) - { return T::Set(std::forward(args)...); } - static void call_set(const EaxCall &call, EaxEffectProps &props) { return std::visit([&](const auto &arg) - { return call_set>(call, props); }, + { return CommitterFor::Set(call, props); }, props); } @@ -322,9 +380,9 @@ public: { switch(call.get_version()) { - case 1: call_set(call, state1_.d); break; - case 2: call_set(call, state2_.d); break; - case 3: call_set(call, state3_.d); break; + case 1: EaxReverbCommitter::Set(call, state1_.d); break; + case 2: EaxReverbCommitter::Set(call, state2_.d); break; + case 3: EaxReverbCommitter::Set(call, state3_.d); break; case 4: call_set(call, state4_.d); break; case 5: call_set(call, state5_.d); break; } @@ -332,14 +390,10 @@ public: } - template - static void call_get(Args&& ...args) - { return T::Get(std::forward(args)...); } - static void call_get(const EaxCall &call, const EaxEffectProps &props) { return std::visit([&](const auto &arg) - { return call_get>(call, props); }, + { return CommitterFor::Get(call, props); }, props); } @@ -347,23 +401,19 @@ public: { switch(call.get_version()) { - case 1: call_get(call, state1_.d); break; - case 2: call_get(call, state2_.d); break; - case 3: call_get(call, state3_.d); break; + case 1: EaxReverbCommitter::Get(call, state1_.d); break; + case 2: EaxReverbCommitter::Get(call, state2_.d); break; + case 3: EaxReverbCommitter::Get(call, state3_.d); break; case 4: call_get(call, state4_.d); break; case 5: call_get(call, state5_.d); break; } } - template - bool call_commit(Args&& ...args) - { return T{props_, al_effect_props_}.commit(std::forward(args)...); } - bool call_commit(const EaxEffectProps &props) { return std::visit([&](const auto &arg) - { return call_commit>(props); }, + { return CommitterFor{props_, al_effect_props_}.commit(props); }, props); } @@ -380,15 +430,15 @@ public: { case 1: state1_.i = state1_.d; - ret |= call_commit(state1_.d); + ret |= EaxReverbCommitter{props_, al_effect_props_}.commit(state1_.d); break; case 2: state2_.i = state2_.d; - ret |= call_commit(state2_.d); + ret |= EaxReverbCommitter{props_, al_effect_props_}.commit(state2_.d); break; case 3: state3_.i = state3_.d; - ret |= call_commit(state3_.d); + ret |= EaxReverbCommitter{props_, al_effect_props_}.commit(state3_.d); break; case 4: state4_.i = state4_.d; diff --git a/al/effects/autowah.cpp b/al/effects/autowah.cpp index 1a8b43fc..c7ddbdb5 100644 --- a/al/effects/autowah.cpp +++ b/al/effects/autowah.cpp @@ -189,8 +189,7 @@ template<> throw Exception{message}; } -template<> -bool AutowahCommitter::commit(const EaxEffectProps &props) +bool EaxAutowahCommitter::commit(const EaxEffectProps &props) { if(props == mEaxProps) return false; @@ -206,8 +205,7 @@ bool AutowahCommitter::commit(const EaxEffectProps &props) return true; } -template<> -void AutowahCommitter::SetDefaults(EaxEffectProps &props) +void EaxAutowahCommitter::SetDefaults(EaxEffectProps &props) { static constexpr EAXAUTOWAHPROPERTIES defprops{[] { @@ -221,8 +219,7 @@ void AutowahCommitter::SetDefaults(EaxEffectProps &props) props = defprops; } -template<> -void AutowahCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) +void EaxAutowahCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) { auto &props = std::get(props_); switch(call.get_property_id()) @@ -237,8 +234,7 @@ void AutowahCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) } } -template<> -void AutowahCommitter::Set(const EaxCall &call, EaxEffectProps &props_) +void EaxAutowahCommitter::Set(const EaxCall &call, EaxEffectProps &props_) { auto &props = std::get(props_); switch(call.get_property_id()) diff --git a/al/effects/chorus.cpp b/al/effects/chorus.cpp index 90b38e4d..61aab28f 100644 --- a/al/effects/chorus.cpp +++ b/al/effects/chorus.cpp @@ -638,29 +638,25 @@ template<> throw Exception{message}; } -template<> -bool ChorusCommitter::commit(const EaxEffectProps &props) +bool EaxChorusCommitter::commit(const EaxEffectProps &props) { using Committer = ChorusFlangerEffect; return Committer::Commit(props, mEaxProps, mAlProps); } -template<> -void ChorusCommitter::SetDefaults(EaxEffectProps &props) +void EaxChorusCommitter::SetDefaults(EaxEffectProps &props) { using Committer = ChorusFlangerEffect; Committer::SetDefaults(props); } -template<> -void ChorusCommitter::Get(const EaxCall &call, const EaxEffectProps &props) +void EaxChorusCommitter::Get(const EaxCall &call, const EaxEffectProps &props) { using Committer = ChorusFlangerEffect; Committer::Get(call, props); } -template<> -void ChorusCommitter::Set(const EaxCall &call, EaxEffectProps &props) +void EaxChorusCommitter::Set(const EaxCall &call, EaxEffectProps &props) { using Committer = ChorusFlangerEffect; Committer::Set(call, props); @@ -679,29 +675,25 @@ template<> throw Exception{message}; } -template<> -bool FlangerCommitter::commit(const EaxEffectProps &props) +bool EaxFlangerCommitter::commit(const EaxEffectProps &props) { using Committer = ChorusFlangerEffect; return Committer::Commit(props, mEaxProps, mAlProps); } -template<> -void FlangerCommitter::SetDefaults(EaxEffectProps &props) +void EaxFlangerCommitter::SetDefaults(EaxEffectProps &props) { using Committer = ChorusFlangerEffect; Committer::SetDefaults(props); } -template<> -void FlangerCommitter::Get(const EaxCall &call, const EaxEffectProps &props) +void EaxFlangerCommitter::Get(const EaxCall &call, const EaxEffectProps &props) { using Committer = ChorusFlangerEffect; Committer::Get(call, props); } -template<> -void FlangerCommitter::Set(const EaxCall &call, EaxEffectProps &props) +void EaxFlangerCommitter::Set(const EaxCall &call, EaxEffectProps &props) { using Committer = ChorusFlangerEffect; Committer::Set(call, props); diff --git a/al/effects/compressor.cpp b/al/effects/compressor.cpp index ca8af84f..6dc96a20 100644 --- a/al/effects/compressor.cpp +++ b/al/effects/compressor.cpp @@ -115,8 +115,7 @@ template<> throw Exception{message}; } -template<> -bool CompressorCommitter::commit(const EaxEffectProps &props) +bool EaxCompressorCommitter::commit(const EaxEffectProps &props) { if(props == mEaxProps) return false; @@ -127,14 +126,12 @@ bool CompressorCommitter::commit(const EaxEffectProps &props) return true; } -template<> -void CompressorCommitter::SetDefaults(EaxEffectProps &props) +void EaxCompressorCommitter::SetDefaults(EaxEffectProps &props) { props = EAXAGCCOMPRESSORPROPERTIES{EAXAGCCOMPRESSOR_DEFAULTONOFF}; } -template<> -void CompressorCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) +void EaxCompressorCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) { auto &props = std::get(props_); switch(call.get_property_id()) @@ -146,8 +143,7 @@ void CompressorCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) } } -template<> -void CompressorCommitter::Set(const EaxCall &call, EaxEffectProps &props_) +void EaxCompressorCommitter::Set(const EaxCall &call, EaxEffectProps &props_) { auto &props = std::get(props_); switch(call.get_property_id()) diff --git a/al/effects/distortion.cpp b/al/effects/distortion.cpp index e046d8e7..9142398b 100644 --- a/al/effects/distortion.cpp +++ b/al/effects/distortion.cpp @@ -204,8 +204,7 @@ template<> throw Exception{message}; } -template<> -bool DistortionCommitter::commit(const EaxEffectProps &props) +bool EaxDistortionCommitter::commit(const EaxEffectProps &props) { if(props == mEaxProps) return false; @@ -222,8 +221,7 @@ bool DistortionCommitter::commit(const EaxEffectProps &props) return true; } -template<> -void DistortionCommitter::SetDefaults(EaxEffectProps &props) +void EaxDistortionCommitter::SetDefaults(EaxEffectProps &props) { static constexpr EAXDISTORTIONPROPERTIES defprops{[] { @@ -238,8 +236,7 @@ void DistortionCommitter::SetDefaults(EaxEffectProps &props) props = defprops; } -template<> -void DistortionCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) +void EaxDistortionCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) { auto &props = std::get(props_); switch(call.get_property_id()) @@ -255,8 +252,7 @@ void DistortionCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) } } -template<> -void DistortionCommitter::Set(const EaxCall &call, EaxEffectProps &props_) +void EaxDistortionCommitter::Set(const EaxCall &call, EaxEffectProps &props_) { auto &props = std::get(props_); switch(call.get_property_id()) diff --git a/al/effects/echo.cpp b/al/effects/echo.cpp index 48aacef3..bfec6885 100644 --- a/al/effects/echo.cpp +++ b/al/effects/echo.cpp @@ -201,8 +201,7 @@ template<> throw Exception{message}; } -template<> -bool EchoCommitter::commit(const EaxEffectProps &props) +bool EaxEchoCommitter::commit(const EaxEffectProps &props) { if(props == mEaxProps) return false; @@ -219,8 +218,7 @@ bool EchoCommitter::commit(const EaxEffectProps &props) return true; } -template<> -void EchoCommitter::SetDefaults(EaxEffectProps &props) +void EaxEchoCommitter::SetDefaults(EaxEffectProps &props) { static constexpr EAXECHOPROPERTIES defprops{[] { @@ -235,8 +233,7 @@ void EchoCommitter::SetDefaults(EaxEffectProps &props) props = defprops; } -template<> -void EchoCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) +void EaxEchoCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) { auto &props = std::get(props_); switch(call.get_property_id()) @@ -252,8 +249,7 @@ void EchoCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) } } -template<> -void EchoCommitter::Set(const EaxCall &call, EaxEffectProps &props_) +void EaxEchoCommitter::Set(const EaxCall &call, EaxEffectProps &props_) { auto &props = std::get(props_); switch(call.get_property_id()) diff --git a/al/effects/equalizer.cpp b/al/effects/equalizer.cpp index 76d5bdef..b16be2a5 100644 --- a/al/effects/equalizer.cpp +++ b/al/effects/equalizer.cpp @@ -319,8 +319,7 @@ template<> throw Exception{message}; } -template<> -bool EqualizerCommitter::commit(const EaxEffectProps &props) +bool EaxEqualizerCommitter::commit(const EaxEffectProps &props) { if(props == mEaxProps) return false; @@ -342,8 +341,7 @@ bool EqualizerCommitter::commit(const EaxEffectProps &props) return true; } -template<> -void EqualizerCommitter::SetDefaults(EaxEffectProps &props) +void EaxEqualizerCommitter::SetDefaults(EaxEffectProps &props) { static constexpr EAXEQUALIZERPROPERTIES defprops{[] { @@ -363,8 +361,7 @@ void EqualizerCommitter::SetDefaults(EaxEffectProps &props) props = defprops; } -template<> -void EqualizerCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) +void EaxEqualizerCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) { auto &props = std::get(props_); switch(call.get_property_id()) @@ -385,8 +382,7 @@ void EqualizerCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) } } -template<> -void EqualizerCommitter::Set(const EaxCall &call, EaxEffectProps &props_) +void EaxEqualizerCommitter::Set(const EaxCall &call, EaxEffectProps &props_) { auto &props = std::get(props_); switch(call.get_property_id()) diff --git a/al/effects/fshifter.cpp b/al/effects/fshifter.cpp index 37c372c3..45253563 100644 --- a/al/effects/fshifter.cpp +++ b/al/effects/fshifter.cpp @@ -197,8 +197,7 @@ template<> throw Exception{message}; } -template<> -bool FrequencyShifterCommitter::commit(const EaxEffectProps &props) +bool EaxFrequencyShifterCommitter::commit(const EaxEffectProps &props) { if(props == mEaxProps) return false; @@ -222,8 +221,7 @@ bool FrequencyShifterCommitter::commit(const EaxEffectProps &props) return true; } -template<> -void FrequencyShifterCommitter::SetDefaults(EaxEffectProps &props) +void EaxFrequencyShifterCommitter::SetDefaults(EaxEffectProps &props) { static constexpr EAXFREQUENCYSHIFTERPROPERTIES defprops{[] { @@ -236,8 +234,7 @@ void FrequencyShifterCommitter::SetDefaults(EaxEffectProps &props) props = defprops; } -template<> -void FrequencyShifterCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) +void EaxFrequencyShifterCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) { auto &props = std::get(props_); switch(call.get_property_id()) @@ -251,8 +248,7 @@ void FrequencyShifterCommitter::Get(const EaxCall &call, const EaxEffectProps &p } } -template<> -void FrequencyShifterCommitter::Set(const EaxCall &call, EaxEffectProps &props_) +void EaxFrequencyShifterCommitter::Set(const EaxCall &call, EaxEffectProps &props_) { auto &props = std::get(props_); switch(call.get_property_id()) diff --git a/al/effects/modulator.cpp b/al/effects/modulator.cpp index 366e7ef7..8bab41c9 100644 --- a/al/effects/modulator.cpp +++ b/al/effects/modulator.cpp @@ -203,8 +203,7 @@ template<> throw Exception{message}; } -template<> -bool ModulatorCommitter::commit(const EaxEffectProps &props) +bool EaxModulatorCommitter::commit(const EaxEffectProps &props) { if(props == mEaxProps) return false; @@ -230,8 +229,7 @@ bool ModulatorCommitter::commit(const EaxEffectProps &props) return true; } -template<> -void ModulatorCommitter::SetDefaults(EaxEffectProps &props) +void EaxModulatorCommitter::SetDefaults(EaxEffectProps &props) { static constexpr EAXRINGMODULATORPROPERTIES defprops{[] { @@ -244,8 +242,7 @@ void ModulatorCommitter::SetDefaults(EaxEffectProps &props) props = defprops; } -template<> -void ModulatorCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) +void EaxModulatorCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) { auto &props = std::get(props_); switch(call.get_property_id()) @@ -259,8 +256,7 @@ void ModulatorCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) } } -template<> -void ModulatorCommitter::Set(const EaxCall &call, EaxEffectProps &props_) +void EaxModulatorCommitter::Set(const EaxCall &call, EaxEffectProps &props_) { auto &props = std::get(props_); switch (call.get_property_id()) diff --git a/al/effects/null.cpp b/al/effects/null.cpp index 1e8787e7..5d8e717e 100644 --- a/al/effects/null.cpp +++ b/al/effects/null.cpp @@ -117,29 +117,25 @@ template<> throw Exception{message}; } -template<> -bool NullCommitter::commit(const EaxEffectProps &props) +bool EaxNullCommitter::commit(const EaxEffectProps &props) { const bool ret{props != mEaxProps}; mEaxProps = props; return ret; } -template<> -void NullCommitter::SetDefaults(EaxEffectProps &props) +void EaxNullCommitter::SetDefaults(EaxEffectProps &props) { props.emplace(); } -template<> -void NullCommitter::Get(const EaxCall &call, const EaxEffectProps&) +void EaxNullCommitter::Get(const EaxCall &call, const EaxEffectProps&) { if(call.get_property_id() != 0) fail_unknown_property_id(); } -template<> -void NullCommitter::Set(const EaxCall &call, EaxEffectProps&) +void EaxNullCommitter::Set(const EaxCall &call, EaxEffectProps&) { if(call.get_property_id() != 0) fail_unknown_property_id(); diff --git a/al/effects/pshifter.cpp b/al/effects/pshifter.cpp index 10824016..93b4fefe 100644 --- a/al/effects/pshifter.cpp +++ b/al/effects/pshifter.cpp @@ -138,8 +138,7 @@ template<> throw Exception{message}; } -template<> -bool PitchShifterCommitter::commit(const EaxEffectProps &props) +bool EaxPitchShifterCommitter::commit(const EaxEffectProps &props) { if(props == mEaxProps) return false; @@ -153,15 +152,13 @@ bool PitchShifterCommitter::commit(const EaxEffectProps &props) return true; } -template<> -void PitchShifterCommitter::SetDefaults(EaxEffectProps &props) +void EaxPitchShifterCommitter::SetDefaults(EaxEffectProps &props) { props = EAXPITCHSHIFTERPROPERTIES{EAXPITCHSHIFTER_DEFAULTCOARSETUNE, EAXPITCHSHIFTER_DEFAULTFINETUNE}; } -template<> -void PitchShifterCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) +void EaxPitchShifterCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) { auto &props = std::get(props_); switch(call.get_property_id()) @@ -174,8 +171,7 @@ void PitchShifterCommitter::Get(const EaxCall &call, const EaxEffectProps &props } } -template<> -void PitchShifterCommitter::Set(const EaxCall &call, EaxEffectProps &props_) +void EaxPitchShifterCommitter::Set(const EaxCall &call, EaxEffectProps &props_) { auto &props = std::get(props_); switch(call.get_property_id()) diff --git a/al/effects/vmorpher.cpp b/al/effects/vmorpher.cpp index f2551229..b747d216 100644 --- a/al/effects/vmorpher.cpp +++ b/al/effects/vmorpher.cpp @@ -352,8 +352,7 @@ template<> throw Exception{message}; } -template<> -bool VocalMorpherCommitter::commit(const EaxEffectProps &props) +bool EaxVocalMorpherCommitter::commit(const EaxEffectProps &props) { if(props == mEaxProps) return false; @@ -418,8 +417,7 @@ bool VocalMorpherCommitter::commit(const EaxEffectProps &props) return true; } -template<> -void VocalMorpherCommitter::SetDefaults(EaxEffectProps &props) +void EaxVocalMorpherCommitter::SetDefaults(EaxEffectProps &props) { static constexpr EAXVOCALMORPHERPROPERTIES defprops{[] { @@ -435,87 +433,37 @@ void VocalMorpherCommitter::SetDefaults(EaxEffectProps &props) props = defprops; } -template<> -void VocalMorpherCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) +void EaxVocalMorpherCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) { auto &props = std::get(props_); switch(call.get_property_id()) { - case EAXVOCALMORPHER_NONE: - break; - - case EAXVOCALMORPHER_ALLPARAMETERS: - call.set_value(props); - break; - - case EAXVOCALMORPHER_PHONEMEA: - call.set_value(props.ulPhonemeA); - break; - - case EAXVOCALMORPHER_PHONEMEACOARSETUNING: - call.set_value(props.lPhonemeACoarseTuning); - break; - - case EAXVOCALMORPHER_PHONEMEB: - call.set_value(props.ulPhonemeB); - break; - - case EAXVOCALMORPHER_PHONEMEBCOARSETUNING: - call.set_value(props.lPhonemeBCoarseTuning); - break; - - case EAXVOCALMORPHER_WAVEFORM: - call.set_value(props.ulWaveform); - break; - - case EAXVOCALMORPHER_RATE: - call.set_value(props.flRate); - break; - - default: - fail_unknown_property_id(); + case EAXVOCALMORPHER_NONE: break; + case EAXVOCALMORPHER_ALLPARAMETERS: call.set_value(props); break; + case EAXVOCALMORPHER_PHONEMEA: call.set_value(props.ulPhonemeA); break; + case EAXVOCALMORPHER_PHONEMEACOARSETUNING: call.set_value(props.lPhonemeACoarseTuning); break; + case EAXVOCALMORPHER_PHONEMEB: call.set_value(props.ulPhonemeB); break; + case EAXVOCALMORPHER_PHONEMEBCOARSETUNING: call.set_value(props.lPhonemeBCoarseTuning); break; + case EAXVOCALMORPHER_WAVEFORM: call.set_value(props.ulWaveform); break; + case EAXVOCALMORPHER_RATE: call.set_value(props.flRate); break; + default: fail_unknown_property_id(); } } -template<> -void VocalMorpherCommitter::Set(const EaxCall &call, EaxEffectProps &props_) +void EaxVocalMorpherCommitter::Set(const EaxCall &call, EaxEffectProps &props_) { auto &props = std::get(props_); switch(call.get_property_id()) { - case EAXVOCALMORPHER_NONE: - break; - - case EAXVOCALMORPHER_ALLPARAMETERS: - defer(call, props); - break; - - case EAXVOCALMORPHER_PHONEMEA: - defer(call, props.ulPhonemeA); - break; - - case EAXVOCALMORPHER_PHONEMEACOARSETUNING: - defer(call, props.lPhonemeACoarseTuning); - break; - - case EAXVOCALMORPHER_PHONEMEB: - defer(call, props.ulPhonemeB); - break; - - case EAXVOCALMORPHER_PHONEMEBCOARSETUNING: - defer(call, props.lPhonemeBCoarseTuning); - break; - - case EAXVOCALMORPHER_WAVEFORM: - defer(call, props.ulWaveform); - break; - - case EAXVOCALMORPHER_RATE: - defer(call, props.flRate); - break; - - default: - fail_unknown_property_id(); + case EAXVOCALMORPHER_NONE: break; + case EAXVOCALMORPHER_ALLPARAMETERS: defer(call, props); break; + case EAXVOCALMORPHER_PHONEMEA: defer(call, props.ulPhonemeA); break; + case EAXVOCALMORPHER_PHONEMEACOARSETUNING: defer(call, props.lPhonemeACoarseTuning); break; + case EAXVOCALMORPHER_PHONEMEB: defer(call, props.ulPhonemeB); break; + case EAXVOCALMORPHER_PHONEMEBCOARSETUNING: defer(call, props.lPhonemeBCoarseTuning); break; + case EAXVOCALMORPHER_WAVEFORM: defer(call, props.ulWaveform); break; + case EAXVOCALMORPHER_RATE: defer(call, props.flRate); break; + default: fail_unknown_property_id(); } } -- cgit v1.2.3 From d7304c49a1d2cea2dae0ae38fdd9706dbcdb561f Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 23 Dec 2023 00:11:26 -0800 Subject: Pass the effect props directly to the eax committer functions Rather than the variant that was already checked for what it's holding. --- al/eax/effect.h | 92 ++++++------- al/effects/autowah.cpp | 19 ++- al/effects/chorus.cpp | 35 +++-- al/effects/compressor.cpp | 12 +- al/effects/distortion.cpp | 21 ++- al/effects/echo.cpp | 21 ++- al/effects/equalizer.cpp | 31 ++--- al/effects/fshifter.cpp | 17 +-- al/effects/modulator.cpp | 19 ++- al/effects/null.cpp | 8 +- al/effects/pshifter.cpp | 15 +- al/effects/reverb.cpp | 341 +++++++++++++--------------------------------- al/effects/vmorpher.cpp | 23 ++-- 13 files changed, 236 insertions(+), 418 deletions(-) (limited to 'al/eax') diff --git a/al/eax/effect.h b/al/eax/effect.h index ce581990..a735fe6c 100644 --- a/al/eax/effect.h +++ b/al/eax/effect.h @@ -100,7 +100,6 @@ struct EaxReverbCommitter { bool commit(const EAX_REVERBPROPERTIES &props); bool commit(const EAX20LISTENERPROPERTIES &props); bool commit(const EAXREVERBPROPERTIES &props); - bool commit(const EaxEffectProps &props); static void SetDefaults(EAX_REVERBPROPERTIES &props); static void SetDefaults(EAX20LISTENERPROPERTIES &props); @@ -110,16 +109,13 @@ struct EaxReverbCommitter { static void Get(const EaxCall &call, const EAX_REVERBPROPERTIES &props); static void Get(const EaxCall &call, const EAX20LISTENERPROPERTIES &props); static void Get(const EaxCall &call, const EAXREVERBPROPERTIES &props); - static void Get(const EaxCall &call, const EaxEffectProps &props); static void Set(const EaxCall &call, EAX_REVERBPROPERTIES &props); static void Set(const EaxCall &call, EAX20LISTENERPROPERTIES &props); static void Set(const EaxCall &call, EAXREVERBPROPERTIES &props); - static void Set(const EaxCall &call, EaxEffectProps &props); - static void translate(const EAX_REVERBPROPERTIES& src, EaxEffectProps& dst) noexcept; - static void translate(const EAX20LISTENERPROPERTIES& src, EaxEffectProps& dst) noexcept; - static void translate(const EAXREVERBPROPERTIES& src, EaxEffectProps& dst) noexcept; + static void translate(const EAX_REVERBPROPERTIES& src, EAXREVERBPROPERTIES& dst) noexcept; + static void translate(const EAX20LISTENERPROPERTIES& src, EAXREVERBPROPERTIES& dst) noexcept; }; template @@ -149,110 +145,110 @@ struct EaxCommitter { struct EaxAutowahCommitter : public EaxCommitter { using EaxCommitter::EaxCommitter; - bool commit(const EaxEffectProps &props); + bool commit(const EAXAUTOWAHPROPERTIES &props); static void SetDefaults(EaxEffectProps &props); - static void Get(const EaxCall &call, const EaxEffectProps &props); - static void Set(const EaxCall &call, EaxEffectProps &props); + static void Get(const EaxCall &call, const EAXAUTOWAHPROPERTIES &props); + static void Set(const EaxCall &call, EAXAUTOWAHPROPERTIES &props); }; struct EaxChorusCommitter : public EaxCommitter { using EaxCommitter::EaxCommitter; - bool commit(const EaxEffectProps &props); + bool commit(const EAXCHORUSPROPERTIES &props); static void SetDefaults(EaxEffectProps &props); - static void Get(const EaxCall &call, const EaxEffectProps &props); - static void Set(const EaxCall &call, EaxEffectProps &props); + static void Get(const EaxCall &call, const EAXCHORUSPROPERTIES &props); + static void Set(const EaxCall &call, EAXCHORUSPROPERTIES &props); }; struct EaxCompressorCommitter : public EaxCommitter { using EaxCommitter::EaxCommitter; - bool commit(const EaxEffectProps &props); + bool commit(const EAXAGCCOMPRESSORPROPERTIES &props); static void SetDefaults(EaxEffectProps &props); - static void Get(const EaxCall &call, const EaxEffectProps &props); - static void Set(const EaxCall &call, EaxEffectProps &props); + static void Get(const EaxCall &call, const EAXAGCCOMPRESSORPROPERTIES &props); + static void Set(const EaxCall &call, EAXAGCCOMPRESSORPROPERTIES &props); }; struct EaxDistortionCommitter : public EaxCommitter { using EaxCommitter::EaxCommitter; - bool commit(const EaxEffectProps &props); + bool commit(const EAXDISTORTIONPROPERTIES &props); static void SetDefaults(EaxEffectProps &props); - static void Get(const EaxCall &call, const EaxEffectProps &props); - static void Set(const EaxCall &call, EaxEffectProps &props); + static void Get(const EaxCall &call, const EAXDISTORTIONPROPERTIES &props); + static void Set(const EaxCall &call, EAXDISTORTIONPROPERTIES &props); }; struct EaxEchoCommitter : public EaxCommitter { using EaxCommitter::EaxCommitter; - bool commit(const EaxEffectProps &props); + bool commit(const EAXECHOPROPERTIES &props); static void SetDefaults(EaxEffectProps &props); - static void Get(const EaxCall &call, const EaxEffectProps &props); - static void Set(const EaxCall &call, EaxEffectProps &props); + static void Get(const EaxCall &call, const EAXECHOPROPERTIES &props); + static void Set(const EaxCall &call, EAXECHOPROPERTIES &props); }; struct EaxEqualizerCommitter : public EaxCommitter { using EaxCommitter::EaxCommitter; - bool commit(const EaxEffectProps &props); + bool commit(const EAXEQUALIZERPROPERTIES &props); static void SetDefaults(EaxEffectProps &props); - static void Get(const EaxCall &call, const EaxEffectProps &props); - static void Set(const EaxCall &call, EaxEffectProps &props); + static void Get(const EaxCall &call, const EAXEQUALIZERPROPERTIES &props); + static void Set(const EaxCall &call, EAXEQUALIZERPROPERTIES &props); }; struct EaxFlangerCommitter : public EaxCommitter { using EaxCommitter::EaxCommitter; - bool commit(const EaxEffectProps &props); + bool commit(const EAXFLANGERPROPERTIES &props); static void SetDefaults(EaxEffectProps &props); - static void Get(const EaxCall &call, const EaxEffectProps &props); - static void Set(const EaxCall &call, EaxEffectProps &props); + static void Get(const EaxCall &call, const EAXFLANGERPROPERTIES &props); + static void Set(const EaxCall &call, EAXFLANGERPROPERTIES &props); }; struct EaxFrequencyShifterCommitter : public EaxCommitter { using EaxCommitter::EaxCommitter; - bool commit(const EaxEffectProps &props); + bool commit(const EAXFREQUENCYSHIFTERPROPERTIES &props); static void SetDefaults(EaxEffectProps &props); - static void Get(const EaxCall &call, const EaxEffectProps &props); - static void Set(const EaxCall &call, EaxEffectProps &props); + static void Get(const EaxCall &call, const EAXFREQUENCYSHIFTERPROPERTIES &props); + static void Set(const EaxCall &call, EAXFREQUENCYSHIFTERPROPERTIES &props); }; struct EaxModulatorCommitter : public EaxCommitter { using EaxCommitter::EaxCommitter; - bool commit(const EaxEffectProps &props); + bool commit(const EAXRINGMODULATORPROPERTIES &props); static void SetDefaults(EaxEffectProps &props); - static void Get(const EaxCall &call, const EaxEffectProps &props); - static void Set(const EaxCall &call, EaxEffectProps &props); + static void Get(const EaxCall &call, const EAXRINGMODULATORPROPERTIES &props); + static void Set(const EaxCall &call, EAXRINGMODULATORPROPERTIES &props); }; struct EaxPitchShifterCommitter : public EaxCommitter { using EaxCommitter::EaxCommitter; - bool commit(const EaxEffectProps &props); + bool commit(const EAXPITCHSHIFTERPROPERTIES &props); static void SetDefaults(EaxEffectProps &props); - static void Get(const EaxCall &call, const EaxEffectProps &props); - static void Set(const EaxCall &call, EaxEffectProps &props); + static void Get(const EaxCall &call, const EAXPITCHSHIFTERPROPERTIES &props); + static void Set(const EaxCall &call, EAXPITCHSHIFTERPROPERTIES &props); }; struct EaxVocalMorpherCommitter : public EaxCommitter { using EaxCommitter::EaxCommitter; - bool commit(const EaxEffectProps &props); + bool commit(const EAXVOCALMORPHERPROPERTIES &props); static void SetDefaults(EaxEffectProps &props); - static void Get(const EaxCall &call, const EaxEffectProps &props); - static void Set(const EaxCall &call, EaxEffectProps &props); + static void Get(const EaxCall &call, const EAXVOCALMORPHERPROPERTIES &props); + static void Set(const EaxCall &call, EAXVOCALMORPHERPROPERTIES &props); }; struct EaxNullCommitter : public EaxCommitter { using EaxCommitter::EaxCommitter; - bool commit(const EaxEffectProps &props); + bool commit(const std::monostate &props); static void SetDefaults(EaxEffectProps &props); - static void Get(const EaxCall &call, const EaxEffectProps &props); - static void Set(const EaxCall &call, EaxEffectProps &props); + static void Get(const EaxCall &call, const std::monostate &props); + static void Set(const EaxCall &call, std::monostate &props); }; template @@ -371,8 +367,8 @@ public: static void call_set(const EaxCall &call, EaxEffectProps &props) { - return std::visit([&](const auto &arg) - { return CommitterFor::Set(call, props); }, + return std::visit([&](auto &arg) + { return CommitterFor::Set(call, arg); }, props); } @@ -392,8 +388,8 @@ public: static void call_get(const EaxCall &call, const EaxEffectProps &props) { - return std::visit([&](const auto &arg) - { return CommitterFor::Get(call, props); }, + return std::visit([&](auto &arg) + { return CommitterFor::Get(call, arg); }, props); } @@ -412,8 +408,8 @@ public: bool call_commit(const EaxEffectProps &props) { - return std::visit([&](const auto &arg) - { return CommitterFor{props_, al_effect_props_}.commit(props); }, + return std::visit([&](auto &arg) + { return CommitterFor{props_, al_effect_props_}.commit(arg); }, props); } diff --git a/al/effects/autowah.cpp b/al/effects/autowah.cpp index c7ddbdb5..c0f845ac 100644 --- a/al/effects/autowah.cpp +++ b/al/effects/autowah.cpp @@ -189,18 +189,17 @@ template<> throw Exception{message}; } -bool EaxAutowahCommitter::commit(const EaxEffectProps &props) +bool EaxAutowahCommitter::commit(const EAXAUTOWAHPROPERTIES &props) { - if(props == mEaxProps) + if(auto *cur = std::get_if(&mEaxProps); cur && *cur == props) return false; mEaxProps = props; - auto &eaxprops = std::get(props); - mAlProps.Autowah.AttackTime = eaxprops.flAttackTime; - mAlProps.Autowah.ReleaseTime = eaxprops.flReleaseTime; - mAlProps.Autowah.Resonance = level_mb_to_gain(static_cast(eaxprops.lResonance)); - mAlProps.Autowah.PeakGain = level_mb_to_gain(static_cast(eaxprops.lPeakLevel)); + mAlProps.Autowah.AttackTime = props.flAttackTime; + mAlProps.Autowah.ReleaseTime = props.flReleaseTime; + mAlProps.Autowah.Resonance = level_mb_to_gain(static_cast(props.lResonance)); + mAlProps.Autowah.PeakGain = level_mb_to_gain(static_cast(props.lPeakLevel)); return true; } @@ -219,9 +218,8 @@ void EaxAutowahCommitter::SetDefaults(EaxEffectProps &props) props = defprops; } -void EaxAutowahCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) +void EaxAutowahCommitter::Get(const EaxCall &call, const EAXAUTOWAHPROPERTIES &props) { - auto &props = std::get(props_); switch(call.get_property_id()) { case EAXAUTOWAH_NONE: break; @@ -234,9 +232,8 @@ void EaxAutowahCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) } } -void EaxAutowahCommitter::Set(const EaxCall &call, EaxEffectProps &props_) +void EaxAutowahCommitter::Set(const EaxCall &call, EAXAUTOWAHPROPERTIES &props) { - auto &props = std::get(props_); switch(call.get_property_id()) { case EAXAUTOWAH_NONE: break; diff --git a/al/effects/chorus.cpp b/al/effects/chorus.cpp index 61aab28f..aabeff97 100644 --- a/al/effects/chorus.cpp +++ b/al/effects/chorus.cpp @@ -518,9 +518,8 @@ public: } - static void Get(const EaxCall &call, const EaxEffectProps &props) + static void Get(const EaxCall &call, const typename Traits::Props &all) { - auto&& all = std::get(props); switch(call.get_property_id()) { case Traits::eax_none_param_id(): @@ -559,9 +558,8 @@ public: } } - static void Set(const EaxCall &call, EaxEffectProps &props) + static void Set(const EaxCall &call, typename Traits::Props &all) { - auto&& all = std::get(props); switch(call.get_property_id()) { case Traits::eax_none_param_id(): @@ -600,20 +598,19 @@ public: } } - static bool Commit(const EaxEffectProps &props, EaxEffectProps &props_, EffectProps &al_props_) + static bool Commit(const typename Traits::Props &props, EaxEffectProps &props_, EffectProps &al_props_) { - if(props == props_) + if(auto *cur = std::get_if(&props_); cur && *cur == props) return false; props_ = props; - auto&& dst = std::get(props); - al_props_.Chorus.Waveform = Traits::eax_waveform(dst.ulWaveform); - al_props_.Chorus.Phase = static_cast(dst.lPhase); - al_props_.Chorus.Rate = dst.flRate; - al_props_.Chorus.Depth = dst.flDepth; - al_props_.Chorus.Feedback = dst.flFeedback; - al_props_.Chorus.Delay = dst.flDelay; + al_props_.Chorus.Waveform = Traits::eax_waveform(props.ulWaveform); + al_props_.Chorus.Phase = static_cast(props.lPhase); + al_props_.Chorus.Rate = props.flRate; + al_props_.Chorus.Depth = props.flDepth; + al_props_.Chorus.Feedback = props.flFeedback; + al_props_.Chorus.Delay = props.flDelay; return true; } @@ -638,7 +635,7 @@ template<> throw Exception{message}; } -bool EaxChorusCommitter::commit(const EaxEffectProps &props) +bool EaxChorusCommitter::commit(const EAXCHORUSPROPERTIES &props) { using Committer = ChorusFlangerEffect; return Committer::Commit(props, mEaxProps, mAlProps); @@ -650,13 +647,13 @@ void EaxChorusCommitter::SetDefaults(EaxEffectProps &props) Committer::SetDefaults(props); } -void EaxChorusCommitter::Get(const EaxCall &call, const EaxEffectProps &props) +void EaxChorusCommitter::Get(const EaxCall &call, const EAXCHORUSPROPERTIES &props) { using Committer = ChorusFlangerEffect; Committer::Get(call, props); } -void EaxChorusCommitter::Set(const EaxCall &call, EaxEffectProps &props) +void EaxChorusCommitter::Set(const EaxCall &call, EAXCHORUSPROPERTIES &props) { using Committer = ChorusFlangerEffect; Committer::Set(call, props); @@ -675,7 +672,7 @@ template<> throw Exception{message}; } -bool EaxFlangerCommitter::commit(const EaxEffectProps &props) +bool EaxFlangerCommitter::commit(const EAXFLANGERPROPERTIES &props) { using Committer = ChorusFlangerEffect; return Committer::Commit(props, mEaxProps, mAlProps); @@ -687,13 +684,13 @@ void EaxFlangerCommitter::SetDefaults(EaxEffectProps &props) Committer::SetDefaults(props); } -void EaxFlangerCommitter::Get(const EaxCall &call, const EaxEffectProps &props) +void EaxFlangerCommitter::Get(const EaxCall &call, const EAXFLANGERPROPERTIES &props) { using Committer = ChorusFlangerEffect; Committer::Get(call, props); } -void EaxFlangerCommitter::Set(const EaxCall &call, EaxEffectProps &props) +void EaxFlangerCommitter::Set(const EaxCall &call, EAXFLANGERPROPERTIES &props) { using Committer = ChorusFlangerEffect; Committer::Set(call, props); diff --git a/al/effects/compressor.cpp b/al/effects/compressor.cpp index 6dc96a20..9c4308f4 100644 --- a/al/effects/compressor.cpp +++ b/al/effects/compressor.cpp @@ -115,14 +115,14 @@ template<> throw Exception{message}; } -bool EaxCompressorCommitter::commit(const EaxEffectProps &props) +bool EaxCompressorCommitter::commit(const EAXAGCCOMPRESSORPROPERTIES &props) { - if(props == mEaxProps) + if(auto *cur = std::get_if(&mEaxProps); cur && *cur == props) return false; mEaxProps = props; - mAlProps.Compressor.OnOff = (std::get(props).ulOnOff != 0); + mAlProps.Compressor.OnOff = props.ulOnOff != 0; return true; } @@ -131,9 +131,8 @@ void EaxCompressorCommitter::SetDefaults(EaxEffectProps &props) props = EAXAGCCOMPRESSORPROPERTIES{EAXAGCCOMPRESSOR_DEFAULTONOFF}; } -void EaxCompressorCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) +void EaxCompressorCommitter::Get(const EaxCall &call, const EAXAGCCOMPRESSORPROPERTIES &props) { - auto &props = std::get(props_); switch(call.get_property_id()) { case EAXAGCCOMPRESSOR_NONE: break; @@ -143,9 +142,8 @@ void EaxCompressorCommitter::Get(const EaxCall &call, const EaxEffectProps &prop } } -void EaxCompressorCommitter::Set(const EaxCall &call, EaxEffectProps &props_) +void EaxCompressorCommitter::Set(const EaxCall &call, EAXAGCCOMPRESSORPROPERTIES &props) { - auto &props = std::get(props_); switch(call.get_property_id()) { case EAXAGCCOMPRESSOR_NONE: break; diff --git a/al/effects/distortion.cpp b/al/effects/distortion.cpp index 9142398b..bec2af53 100644 --- a/al/effects/distortion.cpp +++ b/al/effects/distortion.cpp @@ -204,19 +204,18 @@ template<> throw Exception{message}; } -bool EaxDistortionCommitter::commit(const EaxEffectProps &props) +bool EaxDistortionCommitter::commit(const EAXDISTORTIONPROPERTIES &props) { - if(props == mEaxProps) + if(auto *cur = std::get_if(&mEaxProps); cur && *cur == props) return false; mEaxProps = props; - auto &eaxprops = std::get(props); - mAlProps.Distortion.Edge = eaxprops.flEdge; - mAlProps.Distortion.Gain = level_mb_to_gain(static_cast(eaxprops.lGain)); - mAlProps.Distortion.LowpassCutoff = eaxprops.flLowPassCutOff; - mAlProps.Distortion.EQCenter = eaxprops.flEQCenter; - mAlProps.Distortion.EQBandwidth = eaxprops.flEdge; + mAlProps.Distortion.Edge = props.flEdge; + mAlProps.Distortion.Gain = level_mb_to_gain(static_cast(props.lGain)); + mAlProps.Distortion.LowpassCutoff = props.flLowPassCutOff; + mAlProps.Distortion.EQCenter = props.flEQCenter; + mAlProps.Distortion.EQBandwidth = props.flEdge; return true; } @@ -236,9 +235,8 @@ void EaxDistortionCommitter::SetDefaults(EaxEffectProps &props) props = defprops; } -void EaxDistortionCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) +void EaxDistortionCommitter::Get(const EaxCall &call, const EAXDISTORTIONPROPERTIES &props) { - auto &props = std::get(props_); switch(call.get_property_id()) { case EAXDISTORTION_NONE: break; @@ -252,9 +250,8 @@ void EaxDistortionCommitter::Get(const EaxCall &call, const EaxEffectProps &prop } } -void EaxDistortionCommitter::Set(const EaxCall &call, EaxEffectProps &props_) +void EaxDistortionCommitter::Set(const EaxCall &call, EAXDISTORTIONPROPERTIES &props) { - auto &props = std::get(props_); switch(call.get_property_id()) { case EAXDISTORTION_NONE: break; diff --git a/al/effects/echo.cpp b/al/effects/echo.cpp index bfec6885..90f109da 100644 --- a/al/effects/echo.cpp +++ b/al/effects/echo.cpp @@ -201,19 +201,18 @@ template<> throw Exception{message}; } -bool EaxEchoCommitter::commit(const EaxEffectProps &props) +bool EaxEchoCommitter::commit(const EAXECHOPROPERTIES &props) { - if(props == mEaxProps) + if(auto *cur = std::get_if(&mEaxProps); cur && *cur == props) return false; mEaxProps = props; - auto &eaxprops = std::get(props); - mAlProps.Echo.Delay = eaxprops.flDelay; - mAlProps.Echo.LRDelay = eaxprops.flLRDelay; - mAlProps.Echo.Damping = eaxprops.flDamping; - mAlProps.Echo.Feedback = eaxprops.flFeedback; - mAlProps.Echo.Spread = eaxprops.flSpread; + mAlProps.Echo.Delay = props.flDelay; + mAlProps.Echo.LRDelay = props.flLRDelay; + mAlProps.Echo.Damping = props.flDamping; + mAlProps.Echo.Feedback = props.flFeedback; + mAlProps.Echo.Spread = props.flSpread; return true; } @@ -233,9 +232,8 @@ void EaxEchoCommitter::SetDefaults(EaxEffectProps &props) props = defprops; } -void EaxEchoCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) +void EaxEchoCommitter::Get(const EaxCall &call, const EAXECHOPROPERTIES &props) { - auto &props = std::get(props_); switch(call.get_property_id()) { case EAXECHO_NONE: break; @@ -249,9 +247,8 @@ void EaxEchoCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) } } -void EaxEchoCommitter::Set(const EaxCall &call, EaxEffectProps &props_) +void EaxEchoCommitter::Set(const EaxCall &call, EAXECHOPROPERTIES &props) { - auto &props = std::get(props_); switch(call.get_property_id()) { case EAXECHO_NONE: break; diff --git a/al/effects/equalizer.cpp b/al/effects/equalizer.cpp index b16be2a5..921d1090 100644 --- a/al/effects/equalizer.cpp +++ b/al/effects/equalizer.cpp @@ -319,24 +319,23 @@ template<> throw Exception{message}; } -bool EaxEqualizerCommitter::commit(const EaxEffectProps &props) +bool EaxEqualizerCommitter::commit(const EAXEQUALIZERPROPERTIES &props) { - if(props == mEaxProps) + if(auto *cur = std::get_if(&mEaxProps); cur && *cur == props) return false; mEaxProps = props; - auto &eaxprops = std::get(props); - mAlProps.Equalizer.LowGain = level_mb_to_gain(static_cast(eaxprops.lLowGain)); - mAlProps.Equalizer.LowCutoff = eaxprops.flLowCutOff; - mAlProps.Equalizer.Mid1Gain = level_mb_to_gain(static_cast(eaxprops.lMid1Gain)); - mAlProps.Equalizer.Mid1Center = eaxprops.flMid1Center; - mAlProps.Equalizer.Mid1Width = eaxprops.flMid1Width; - mAlProps.Equalizer.Mid2Gain = level_mb_to_gain(static_cast(eaxprops.lMid2Gain)); - mAlProps.Equalizer.Mid2Center = eaxprops.flMid2Center; - mAlProps.Equalizer.Mid2Width = eaxprops.flMid2Width; - mAlProps.Equalizer.HighGain = level_mb_to_gain(static_cast(eaxprops.lHighGain)); - mAlProps.Equalizer.HighCutoff = eaxprops.flHighCutOff; + mAlProps.Equalizer.LowGain = level_mb_to_gain(static_cast(props.lLowGain)); + mAlProps.Equalizer.LowCutoff = props.flLowCutOff; + mAlProps.Equalizer.Mid1Gain = level_mb_to_gain(static_cast(props.lMid1Gain)); + mAlProps.Equalizer.Mid1Center = props.flMid1Center; + mAlProps.Equalizer.Mid1Width = props.flMid1Width; + mAlProps.Equalizer.Mid2Gain = level_mb_to_gain(static_cast(props.lMid2Gain)); + mAlProps.Equalizer.Mid2Center = props.flMid2Center; + mAlProps.Equalizer.Mid2Width = props.flMid2Width; + mAlProps.Equalizer.HighGain = level_mb_to_gain(static_cast(props.lHighGain)); + mAlProps.Equalizer.HighCutoff = props.flHighCutOff; return true; } @@ -361,9 +360,8 @@ void EaxEqualizerCommitter::SetDefaults(EaxEffectProps &props) props = defprops; } -void EaxEqualizerCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) +void EaxEqualizerCommitter::Get(const EaxCall &call, const EAXEQUALIZERPROPERTIES &props) { - auto &props = std::get(props_); switch(call.get_property_id()) { case EAXEQUALIZER_NONE: break; @@ -382,9 +380,8 @@ void EaxEqualizerCommitter::Get(const EaxCall &call, const EaxEffectProps &props } } -void EaxEqualizerCommitter::Set(const EaxCall &call, EaxEffectProps &props_) +void EaxEqualizerCommitter::Set(const EaxCall &call, EAXEQUALIZERPROPERTIES &props) { - auto &props = std::get(props_); switch(call.get_property_id()) { case EAXEQUALIZER_NONE: break; diff --git a/al/effects/fshifter.cpp b/al/effects/fshifter.cpp index 45253563..a6b3c86c 100644 --- a/al/effects/fshifter.cpp +++ b/al/effects/fshifter.cpp @@ -197,9 +197,9 @@ template<> throw Exception{message}; } -bool EaxFrequencyShifterCommitter::commit(const EaxEffectProps &props) +bool EaxFrequencyShifterCommitter::commit(const EAXFREQUENCYSHIFTERPROPERTIES &props) { - if(props == mEaxProps) + if(auto *cur = std::get_if(&mEaxProps); cur && *cur == props) return false; mEaxProps = props; @@ -213,10 +213,9 @@ bool EaxFrequencyShifterCommitter::commit(const EaxEffectProps &props) return FShifterDirection::Off; }; - auto &eaxprops = std::get(props); - mAlProps.Fshifter.Frequency = eaxprops.flFrequency; - mAlProps.Fshifter.LeftDirection = get_direction(eaxprops.ulLeftDirection); - mAlProps.Fshifter.RightDirection = get_direction(eaxprops.ulRightDirection); + mAlProps.Fshifter.Frequency = props.flFrequency; + mAlProps.Fshifter.LeftDirection = get_direction(props.ulLeftDirection); + mAlProps.Fshifter.RightDirection = get_direction(props.ulRightDirection); return true; } @@ -234,9 +233,8 @@ void EaxFrequencyShifterCommitter::SetDefaults(EaxEffectProps &props) props = defprops; } -void EaxFrequencyShifterCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) +void EaxFrequencyShifterCommitter::Get(const EaxCall &call, const EAXFREQUENCYSHIFTERPROPERTIES &props) { - auto &props = std::get(props_); switch(call.get_property_id()) { case EAXFREQUENCYSHIFTER_NONE: break; @@ -248,9 +246,8 @@ void EaxFrequencyShifterCommitter::Get(const EaxCall &call, const EaxEffectProps } } -void EaxFrequencyShifterCommitter::Set(const EaxCall &call, EaxEffectProps &props_) +void EaxFrequencyShifterCommitter::Set(const EaxCall &call, EAXFREQUENCYSHIFTERPROPERTIES &props) { - auto &props = std::get(props_); switch(call.get_property_id()) { case EAXFREQUENCYSHIFTER_NONE: break; diff --git a/al/effects/modulator.cpp b/al/effects/modulator.cpp index 8bab41c9..d0a2df02 100644 --- a/al/effects/modulator.cpp +++ b/al/effects/modulator.cpp @@ -203,9 +203,9 @@ template<> throw Exception{message}; } -bool EaxModulatorCommitter::commit(const EaxEffectProps &props) +bool EaxModulatorCommitter::commit(const EAXRINGMODULATORPROPERTIES &props) { - if(props == mEaxProps) + if(auto *cur = std::get_if(&mEaxProps); cur && *cur == props) return false; mEaxProps = props; @@ -221,10 +221,9 @@ bool EaxModulatorCommitter::commit(const EaxEffectProps &props) return ModulatorWaveform::Sinusoid; }; - auto &eaxprops = std::get(props); - mAlProps.Modulator.Frequency = eaxprops.flFrequency; - mAlProps.Modulator.HighPassCutoff = eaxprops.flHighPassCutOff; - mAlProps.Modulator.Waveform = get_waveform(eaxprops.ulWaveform); + mAlProps.Modulator.Frequency = props.flFrequency; + mAlProps.Modulator.HighPassCutoff = props.flHighPassCutOff; + mAlProps.Modulator.Waveform = get_waveform(props.ulWaveform); return true; } @@ -242,9 +241,8 @@ void EaxModulatorCommitter::SetDefaults(EaxEffectProps &props) props = defprops; } -void EaxModulatorCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) +void EaxModulatorCommitter::Get(const EaxCall &call, const EAXRINGMODULATORPROPERTIES &props) { - auto &props = std::get(props_); switch(call.get_property_id()) { case EAXRINGMODULATOR_NONE: break; @@ -256,10 +254,9 @@ void EaxModulatorCommitter::Get(const EaxCall &call, const EaxEffectProps &props } } -void EaxModulatorCommitter::Set(const EaxCall &call, EaxEffectProps &props_) +void EaxModulatorCommitter::Set(const EaxCall &call, EAXRINGMODULATORPROPERTIES &props) { - auto &props = std::get(props_); - switch (call.get_property_id()) + switch(call.get_property_id()) { case EAXRINGMODULATOR_NONE: break; case EAXRINGMODULATOR_ALLPARAMETERS: defer(call, props); break; diff --git a/al/effects/null.cpp b/al/effects/null.cpp index 5d8e717e..4b68a28f 100644 --- a/al/effects/null.cpp +++ b/al/effects/null.cpp @@ -117,9 +117,9 @@ template<> throw Exception{message}; } -bool EaxNullCommitter::commit(const EaxEffectProps &props) +bool EaxNullCommitter::commit(const std::monostate &props) { - const bool ret{props != mEaxProps}; + const bool ret{std::holds_alternative(mEaxProps)}; mEaxProps = props; return ret; } @@ -129,13 +129,13 @@ void EaxNullCommitter::SetDefaults(EaxEffectProps &props) props.emplace(); } -void EaxNullCommitter::Get(const EaxCall &call, const EaxEffectProps&) +void EaxNullCommitter::Get(const EaxCall &call, const std::monostate&) { if(call.get_property_id() != 0) fail_unknown_property_id(); } -void EaxNullCommitter::Set(const EaxCall &call, EaxEffectProps&) +void EaxNullCommitter::Set(const EaxCall &call, std::monostate&) { if(call.get_property_id() != 0) fail_unknown_property_id(); diff --git a/al/effects/pshifter.cpp b/al/effects/pshifter.cpp index 93b4fefe..f29a3593 100644 --- a/al/effects/pshifter.cpp +++ b/al/effects/pshifter.cpp @@ -138,16 +138,15 @@ template<> throw Exception{message}; } -bool EaxPitchShifterCommitter::commit(const EaxEffectProps &props) +bool EaxPitchShifterCommitter::commit(const EAXPITCHSHIFTERPROPERTIES &props) { - if(props == mEaxProps) + if(auto *cur = std::get_if(&mEaxProps); cur && *cur == props) return false; mEaxProps = props; - auto &eaxprops = std::get(props); - mAlProps.Pshifter.CoarseTune = static_cast(eaxprops.lCoarseTune); - mAlProps.Pshifter.FineTune = static_cast(eaxprops.lFineTune); + mAlProps.Pshifter.CoarseTune = static_cast(props.lCoarseTune); + mAlProps.Pshifter.FineTune = static_cast(props.lFineTune); return true; } @@ -158,9 +157,8 @@ void EaxPitchShifterCommitter::SetDefaults(EaxEffectProps &props) EAXPITCHSHIFTER_DEFAULTFINETUNE}; } -void EaxPitchShifterCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) +void EaxPitchShifterCommitter::Get(const EaxCall &call, const EAXPITCHSHIFTERPROPERTIES &props) { - auto &props = std::get(props_); switch(call.get_property_id()) { case EAXPITCHSHIFTER_NONE: break; @@ -171,9 +169,8 @@ void EaxPitchShifterCommitter::Get(const EaxCall &call, const EaxEffectProps &pr } } -void EaxPitchShifterCommitter::Set(const EaxCall &call, EaxEffectProps &props_) +void EaxPitchShifterCommitter::Set(const EaxCall &call, EAXPITCHSHIFTERPROPERTIES &props) { - auto &props = std::get(props_); switch(call.get_property_id()) { case EAXPITCHSHIFTER_NONE: break; diff --git a/al/effects/reverb.cpp b/al/effects/reverb.cpp index b037443f..7f549f04 100644 --- a/al/effects/reverb.cpp +++ b/al/effects/reverb.cpp @@ -1086,98 +1086,85 @@ struct EaxReverbCommitter::Exception : public EaxReverbEffectException throw Exception{message}; } -void EaxReverbCommitter::translate(const EAX_REVERBPROPERTIES& src, EaxEffectProps& dst) noexcept +void EaxReverbCommitter::translate(const EAX_REVERBPROPERTIES& src, EAXREVERBPROPERTIES& dst) noexcept { assert(src.environment <= EAX1REVERB_MAXENVIRONMENT); - auto&& eaxprops = dst.emplace(EAXREVERB_PRESETS[src.environment]); - eaxprops.flDecayTime = src.fDecayTime_sec; - eaxprops.flDecayHFRatio = src.fDamping; - eaxprops.lReverb = mini(static_cast(gain_to_level_mb(src.fVolume)), 0); + dst = EAXREVERB_PRESETS[src.environment]; + dst.flDecayTime = src.fDecayTime_sec; + dst.flDecayHFRatio = src.fDamping; + dst.lReverb = mini(static_cast(gain_to_level_mb(src.fVolume)), 0); } -void EaxReverbCommitter::translate(const EAX20LISTENERPROPERTIES& src, EaxEffectProps& dst) noexcept +void EaxReverbCommitter::translate(const EAX20LISTENERPROPERTIES& src, EAXREVERBPROPERTIES& dst) noexcept { assert(src.dwEnvironment <= EAX1REVERB_MAXENVIRONMENT); - auto&& eaxprops = dst.emplace(EAXREVERB_PRESETS[src.dwEnvironment]); - eaxprops.ulEnvironment = src.dwEnvironment; - eaxprops.flEnvironmentSize = src.flEnvironmentSize; - eaxprops.flEnvironmentDiffusion = src.flEnvironmentDiffusion; - eaxprops.lRoom = src.lRoom; - eaxprops.lRoomHF = src.lRoomHF; - eaxprops.flDecayTime = src.flDecayTime; - eaxprops.flDecayHFRatio = src.flDecayHFRatio; - eaxprops.lReflections = src.lReflections; - eaxprops.flReflectionsDelay = src.flReflectionsDelay; - eaxprops.lReverb = src.lReverb; - eaxprops.flReverbDelay = src.flReverbDelay; - eaxprops.flAirAbsorptionHF = src.flAirAbsorptionHF; - eaxprops.flRoomRolloffFactor = src.flRoomRolloffFactor; - eaxprops.ulFlags = src.dwFlags; -} - -void EaxReverbCommitter::translate(const EAXREVERBPROPERTIES& src, EaxEffectProps& dst) noexcept -{ - dst = src; + dst = EAXREVERB_PRESETS[src.dwEnvironment]; + dst.ulEnvironment = src.dwEnvironment; + dst.flEnvironmentSize = src.flEnvironmentSize; + dst.flEnvironmentDiffusion = src.flEnvironmentDiffusion; + dst.lRoom = src.lRoom; + dst.lRoomHF = src.lRoomHF; + dst.flDecayTime = src.flDecayTime; + dst.flDecayHFRatio = src.flDecayHFRatio; + dst.lReflections = src.lReflections; + dst.flReflectionsDelay = src.flReflectionsDelay; + dst.lReverb = src.lReverb; + dst.flReverbDelay = src.flReverbDelay; + dst.flAirAbsorptionHF = src.flAirAbsorptionHF; + dst.flRoomRolloffFactor = src.flRoomRolloffFactor; + dst.ulFlags = src.dwFlags; } bool EaxReverbCommitter::commit(const EAX_REVERBPROPERTIES &props) { - EaxEffectProps dst{}; + EAXREVERBPROPERTIES dst{}; translate(props, dst); return commit(dst); } bool EaxReverbCommitter::commit(const EAX20LISTENERPROPERTIES &props) { - EaxEffectProps dst{}; + EAXREVERBPROPERTIES dst{}; translate(props, dst); return commit(dst); } bool EaxReverbCommitter::commit(const EAXREVERBPROPERTIES &props) { - EaxEffectProps dst{}; - translate(props, dst); - return commit(dst); -} - -bool EaxReverbCommitter::commit(const EaxEffectProps &props) -{ - if(props == mEaxProps) + if(auto *cur = std::get_if(&mEaxProps); cur && *cur == props) return false; mEaxProps = props; - auto &eaxprops = std::get(props); - const auto size = eaxprops.flEnvironmentSize; - const auto density = (size * size * size) / 16.0F; + const auto size = props.flEnvironmentSize; + const auto density = (size * size * size) / 16.0f; mAlProps.Reverb.Density = std::min(density, AL_EAXREVERB_MAX_DENSITY); - mAlProps.Reverb.Diffusion = eaxprops.flEnvironmentDiffusion; - mAlProps.Reverb.Gain = level_mb_to_gain(static_cast(eaxprops.lRoom)); - mAlProps.Reverb.GainHF = level_mb_to_gain(static_cast(eaxprops.lRoomHF)); - mAlProps.Reverb.GainLF = level_mb_to_gain(static_cast(eaxprops.lRoomLF)); - mAlProps.Reverb.DecayTime = eaxprops.flDecayTime; - mAlProps.Reverb.DecayHFRatio = eaxprops.flDecayHFRatio; - mAlProps.Reverb.DecayLFRatio = eaxprops.flDecayLFRatio; - mAlProps.Reverb.ReflectionsGain = level_mb_to_gain(static_cast(eaxprops.lReflections)); - mAlProps.Reverb.ReflectionsDelay = eaxprops.flReflectionsDelay; - mAlProps.Reverb.ReflectionsPan[0] = eaxprops.vReflectionsPan.x; - mAlProps.Reverb.ReflectionsPan[1] = eaxprops.vReflectionsPan.y; - mAlProps.Reverb.ReflectionsPan[2] = eaxprops.vReflectionsPan.z; - mAlProps.Reverb.LateReverbGain = level_mb_to_gain(static_cast(eaxprops.lReverb)); - mAlProps.Reverb.LateReverbDelay = eaxprops.flReverbDelay; - mAlProps.Reverb.LateReverbPan[0] = eaxprops.vReverbPan.x; - mAlProps.Reverb.LateReverbPan[1] = eaxprops.vReverbPan.y; - mAlProps.Reverb.LateReverbPan[2] = eaxprops.vReverbPan.z; - mAlProps.Reverb.EchoTime = eaxprops.flEchoTime; - mAlProps.Reverb.EchoDepth = eaxprops.flEchoDepth; - mAlProps.Reverb.ModulationTime = eaxprops.flModulationTime; - mAlProps.Reverb.ModulationDepth = eaxprops.flModulationDepth; - mAlProps.Reverb.AirAbsorptionGainHF = level_mb_to_gain(eaxprops.flAirAbsorptionHF); - mAlProps.Reverb.HFReference = eaxprops.flHFReference; - mAlProps.Reverb.LFReference = eaxprops.flLFReference; - mAlProps.Reverb.RoomRolloffFactor = eaxprops.flRoomRolloffFactor; - mAlProps.Reverb.DecayHFLimit = ((eaxprops.ulFlags & EAXREVERBFLAGS_DECAYHFLIMIT) != 0); + mAlProps.Reverb.Diffusion = props.flEnvironmentDiffusion; + mAlProps.Reverb.Gain = level_mb_to_gain(static_cast(props.lRoom)); + mAlProps.Reverb.GainHF = level_mb_to_gain(static_cast(props.lRoomHF)); + mAlProps.Reverb.GainLF = level_mb_to_gain(static_cast(props.lRoomLF)); + mAlProps.Reverb.DecayTime = props.flDecayTime; + mAlProps.Reverb.DecayHFRatio = props.flDecayHFRatio; + mAlProps.Reverb.DecayLFRatio = props.flDecayLFRatio; + mAlProps.Reverb.ReflectionsGain = level_mb_to_gain(static_cast(props.lReflections)); + mAlProps.Reverb.ReflectionsDelay = props.flReflectionsDelay; + mAlProps.Reverb.ReflectionsPan[0] = props.vReflectionsPan.x; + mAlProps.Reverb.ReflectionsPan[1] = props.vReflectionsPan.y; + mAlProps.Reverb.ReflectionsPan[2] = props.vReflectionsPan.z; + mAlProps.Reverb.LateReverbGain = level_mb_to_gain(static_cast(props.lReverb)); + mAlProps.Reverb.LateReverbDelay = props.flReverbDelay; + mAlProps.Reverb.LateReverbPan[0] = props.vReverbPan.x; + mAlProps.Reverb.LateReverbPan[1] = props.vReverbPan.y; + mAlProps.Reverb.LateReverbPan[2] = props.vReverbPan.z; + mAlProps.Reverb.EchoTime = props.flEchoTime; + mAlProps.Reverb.EchoDepth = props.flEchoDepth; + mAlProps.Reverb.ModulationTime = props.flModulationTime; + mAlProps.Reverb.ModulationDepth = props.flModulationDepth; + mAlProps.Reverb.AirAbsorptionGainHF = level_mb_to_gain(props.flAirAbsorptionHF); + mAlProps.Reverb.HFReference = props.flHFReference; + mAlProps.Reverb.LFReference = props.flLFReference; + mAlProps.Reverb.RoomRolloffFactor = props.flRoomRolloffFactor; + mAlProps.Reverb.DecayHFLimit = ((props.ulFlags & EAXREVERBFLAGS_DECAYHFLIMIT) != 0); return true; } @@ -1274,11 +1261,6 @@ void EaxReverbCommitter::Get(const EaxCall &call, const EAXREVERBPROPERTIES &pro } } -void EaxReverbCommitter::Get(const EaxCall &call, const EaxEffectProps &props) -{ - Get(call, std::get(props)); -} - void EaxReverbCommitter::Set(const EaxCall &call, EAX_REVERBPROPERTIES &props) { @@ -1297,71 +1279,23 @@ void EaxReverbCommitter::Set(const EaxCall &call, EAX20LISTENERPROPERTIES &props { switch(call.get_property_id()) { - case DSPROPERTY_EAX20LISTENER_NONE: - break; - - case DSPROPERTY_EAX20LISTENER_ALLPARAMETERS: - defer(call, props); - break; - - case DSPROPERTY_EAX20LISTENER_ROOM: - defer(call, props.lRoom); - break; - - case DSPROPERTY_EAX20LISTENER_ROOMHF: - defer(call, props.lRoomHF); - break; - - case DSPROPERTY_EAX20LISTENER_ROOMROLLOFFFACTOR: - defer(call, props.flRoomRolloffFactor); - break; - - case DSPROPERTY_EAX20LISTENER_DECAYTIME: - defer(call, props.flDecayTime); - break; - - case DSPROPERTY_EAX20LISTENER_DECAYHFRATIO: - defer(call, props.flDecayHFRatio); - break; - - case DSPROPERTY_EAX20LISTENER_REFLECTIONS: - defer(call, props.lReflections); - break; - - case DSPROPERTY_EAX20LISTENER_REFLECTIONSDELAY: - defer(call, props.flReverbDelay); - break; - - case DSPROPERTY_EAX20LISTENER_REVERB: - defer(call, props.lReverb); - break; - - case DSPROPERTY_EAX20LISTENER_REVERBDELAY: - defer(call, props.flReverbDelay); - break; - - case DSPROPERTY_EAX20LISTENER_ENVIRONMENT: - defer(call, props, props.dwEnvironment); - break; - - case DSPROPERTY_EAX20LISTENER_ENVIRONMENTSIZE: - defer(call, props, props.flEnvironmentSize); - break; - - case DSPROPERTY_EAX20LISTENER_ENVIRONMENTDIFFUSION: - defer(call, props.flEnvironmentDiffusion); - break; - - case DSPROPERTY_EAX20LISTENER_AIRABSORPTIONHF: - defer(call, props.flAirAbsorptionHF); - break; - - case DSPROPERTY_EAX20LISTENER_FLAGS: - defer(call, props.dwFlags); - break; - - default: - fail_unknown_property_id(); + case DSPROPERTY_EAX20LISTENER_NONE: break; + case DSPROPERTY_EAX20LISTENER_ALLPARAMETERS: defer(call, props); break; + case DSPROPERTY_EAX20LISTENER_ROOM: defer(call, props.lRoom); break; + case DSPROPERTY_EAX20LISTENER_ROOMHF: defer(call, props.lRoomHF); break; + case DSPROPERTY_EAX20LISTENER_ROOMROLLOFFFACTOR: defer(call, props.flRoomRolloffFactor); break; + case DSPROPERTY_EAX20LISTENER_DECAYTIME: defer(call, props.flDecayTime); break; + case DSPROPERTY_EAX20LISTENER_DECAYHFRATIO: defer(call, props.flDecayHFRatio); break; + case DSPROPERTY_EAX20LISTENER_REFLECTIONS: defer(call, props.lReflections); break; + case DSPROPERTY_EAX20LISTENER_REFLECTIONSDELAY: defer(call, props.flReverbDelay); break; + case DSPROPERTY_EAX20LISTENER_REVERB: defer(call, props.lReverb); break; + case DSPROPERTY_EAX20LISTENER_REVERBDELAY: defer(call, props.flReverbDelay); break; + case DSPROPERTY_EAX20LISTENER_ENVIRONMENT: defer(call, props, props.dwEnvironment); break; + case DSPROPERTY_EAX20LISTENER_ENVIRONMENTSIZE: defer(call, props, props.flEnvironmentSize); break; + case DSPROPERTY_EAX20LISTENER_ENVIRONMENTDIFFUSION: defer(call, props.flEnvironmentDiffusion); break; + case DSPROPERTY_EAX20LISTENER_AIRABSORPTIONHF: defer(call, props.flAirAbsorptionHF); break; + case DSPROPERTY_EAX20LISTENER_FLAGS: defer(call, props.dwFlags); break; + default: fail_unknown_property_id(); } } @@ -1369,117 +1303,34 @@ void EaxReverbCommitter::Set(const EaxCall &call, EAXREVERBPROPERTIES &props) { switch(call.get_property_id()) { - case EAXREVERB_NONE: - break; - - case EAXREVERB_ALLPARAMETERS: - defer(call, props); - break; - - case EAXREVERB_ENVIRONMENT: - defer(call, props, props.ulEnvironment); - break; - - case EAXREVERB_ENVIRONMENTSIZE: - defer(call, props, props.flEnvironmentSize); - break; - - case EAXREVERB_ENVIRONMENTDIFFUSION: - defer3(call, props, props.flEnvironmentDiffusion); - break; - - case EAXREVERB_ROOM: - defer3(call, props, props.lRoom); - break; - - case EAXREVERB_ROOMHF: - defer3(call, props, props.lRoomHF); - break; - - case EAXREVERB_ROOMLF: - defer3(call, props, props.lRoomLF); - break; - - case EAXREVERB_DECAYTIME: - defer3(call, props, props.flDecayTime); - break; - - case EAXREVERB_DECAYHFRATIO: - defer3(call, props, props.flDecayHFRatio); - break; - - case EAXREVERB_DECAYLFRATIO: - defer3(call, props, props.flDecayLFRatio); - break; - - case EAXREVERB_REFLECTIONS: - defer3(call, props, props.lReflections); - break; - - case EAXREVERB_REFLECTIONSDELAY: - defer3(call, props, props.flReflectionsDelay); - break; - - case EAXREVERB_REFLECTIONSPAN: - defer3(call, props, props.vReflectionsPan); - break; - - case EAXREVERB_REVERB: - defer3(call, props, props.lReverb); - break; - - case EAXREVERB_REVERBDELAY: - defer3(call, props, props.flReverbDelay); - break; - - case EAXREVERB_REVERBPAN: - defer3(call, props, props.vReverbPan); - break; - - case EAXREVERB_ECHOTIME: - defer3(call, props, props.flEchoTime); - break; - - case EAXREVERB_ECHODEPTH: - defer3(call, props, props.flEchoDepth); - break; - - case EAXREVERB_MODULATIONTIME: - defer3(call, props, props.flModulationTime); - break; - - case EAXREVERB_MODULATIONDEPTH: - defer3(call, props, props.flModulationDepth); - break; - - case EAXREVERB_AIRABSORPTIONHF: - defer3(call, props, props.flAirAbsorptionHF); - break; - - case EAXREVERB_HFREFERENCE: - defer3(call, props, props.flHFReference); - break; - - case EAXREVERB_LFREFERENCE: - defer3(call, props, props.flLFReference); - break; - - case EAXREVERB_ROOMROLLOFFFACTOR: - defer3(call, props, props.flRoomRolloffFactor); - break; - - case EAXREVERB_FLAGS: - defer3(call, props, props.ulFlags); - break; - - default: - fail_unknown_property_id(); + case EAXREVERB_NONE: break; + case EAXREVERB_ALLPARAMETERS: defer(call, props); break; + case EAXREVERB_ENVIRONMENT: defer(call, props, props.ulEnvironment); break; + case EAXREVERB_ENVIRONMENTSIZE: defer(call, props, props.flEnvironmentSize); break; + case EAXREVERB_ENVIRONMENTDIFFUSION: defer3(call, props, props.flEnvironmentDiffusion); break; + case EAXREVERB_ROOM: defer3(call, props, props.lRoom); break; + case EAXREVERB_ROOMHF: defer3(call, props, props.lRoomHF); break; + case EAXREVERB_ROOMLF: defer3(call, props, props.lRoomLF); break; + case EAXREVERB_DECAYTIME: defer3(call, props, props.flDecayTime); break; + case EAXREVERB_DECAYHFRATIO: defer3(call, props, props.flDecayHFRatio); break; + case EAXREVERB_DECAYLFRATIO: defer3(call, props, props.flDecayLFRatio); break; + case EAXREVERB_REFLECTIONS: defer3(call, props, props.lReflections); break; + case EAXREVERB_REFLECTIONSDELAY: defer3(call, props, props.flReflectionsDelay); break; + case EAXREVERB_REFLECTIONSPAN: defer3(call, props, props.vReflectionsPan); break; + case EAXREVERB_REVERB: defer3(call, props, props.lReverb); break; + case EAXREVERB_REVERBDELAY: defer3(call, props, props.flReverbDelay); break; + case EAXREVERB_REVERBPAN: defer3(call, props, props.vReverbPan); break; + case EAXREVERB_ECHOTIME: defer3(call, props, props.flEchoTime); break; + case EAXREVERB_ECHODEPTH: defer3(call, props, props.flEchoDepth); break; + case EAXREVERB_MODULATIONTIME: defer3(call, props, props.flModulationTime); break; + case EAXREVERB_MODULATIONDEPTH: defer3(call, props, props.flModulationDepth); break; + case EAXREVERB_AIRABSORPTIONHF: defer3(call, props, props.flAirAbsorptionHF); break; + case EAXREVERB_HFREFERENCE: defer3(call, props, props.flHFReference); break; + case EAXREVERB_LFREFERENCE: defer3(call, props, props.flLFReference); break; + case EAXREVERB_ROOMROLLOFFFACTOR: defer3(call, props, props.flRoomRolloffFactor); break; + case EAXREVERB_FLAGS: defer3(call, props, props.ulFlags); break; + default: fail_unknown_property_id(); } } -void EaxReverbCommitter::Set(const EaxCall &call, EaxEffectProps &props) -{ - Set(call, std::get(props)); -} - #endif // ALSOFT_EAX diff --git a/al/effects/vmorpher.cpp b/al/effects/vmorpher.cpp index b747d216..240c7b54 100644 --- a/al/effects/vmorpher.cpp +++ b/al/effects/vmorpher.cpp @@ -352,9 +352,9 @@ template<> throw Exception{message}; } -bool EaxVocalMorpherCommitter::commit(const EaxEffectProps &props) +bool EaxVocalMorpherCommitter::commit(const EAXVOCALMORPHERPROPERTIES &props) { - if(props == mEaxProps) + if(auto *cur = std::get_if(&mEaxProps); cur && *cur == props) return false; mEaxProps = props; @@ -406,13 +406,12 @@ bool EaxVocalMorpherCommitter::commit(const EaxEffectProps &props) return VMorpherWaveform::Sinusoid; }; - auto &eaxprops = std::get(props); - mAlProps.Vmorpher.PhonemeA = get_phoneme(eaxprops.ulPhonemeA); - mAlProps.Vmorpher.PhonemeACoarseTuning = static_cast(eaxprops.lPhonemeACoarseTuning); - mAlProps.Vmorpher.PhonemeB = get_phoneme(eaxprops.ulPhonemeB); - mAlProps.Vmorpher.PhonemeBCoarseTuning = static_cast(eaxprops.lPhonemeBCoarseTuning); - mAlProps.Vmorpher.Waveform = get_waveform(eaxprops.ulWaveform); - mAlProps.Vmorpher.Rate = eaxprops.flRate; + mAlProps.Vmorpher.PhonemeA = get_phoneme(props.ulPhonemeA); + mAlProps.Vmorpher.PhonemeACoarseTuning = static_cast(props.lPhonemeACoarseTuning); + mAlProps.Vmorpher.PhonemeB = get_phoneme(props.ulPhonemeB); + mAlProps.Vmorpher.PhonemeBCoarseTuning = static_cast(props.lPhonemeBCoarseTuning); + mAlProps.Vmorpher.Waveform = get_waveform(props.ulWaveform); + mAlProps.Vmorpher.Rate = props.flRate; return true; } @@ -433,9 +432,8 @@ void EaxVocalMorpherCommitter::SetDefaults(EaxEffectProps &props) props = defprops; } -void EaxVocalMorpherCommitter::Get(const EaxCall &call, const EaxEffectProps &props_) +void EaxVocalMorpherCommitter::Get(const EaxCall &call, const EAXVOCALMORPHERPROPERTIES &props) { - auto &props = std::get(props_); switch(call.get_property_id()) { case EAXVOCALMORPHER_NONE: break; @@ -450,9 +448,8 @@ void EaxVocalMorpherCommitter::Get(const EaxCall &call, const EaxEffectProps &pr } } -void EaxVocalMorpherCommitter::Set(const EaxCall &call, EaxEffectProps &props_) +void EaxVocalMorpherCommitter::Set(const EaxCall &call, EAXVOCALMORPHERPROPERTIES &props) { - auto &props = std::get(props_); switch(call.get_property_id()) { case EAXVOCALMORPHER_NONE: break; -- cgit v1.2.3