aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2023-12-10 22:15:17 -0800
committerChris Robinson <[email protected]>2023-12-10 22:15:17 -0800
commitbb3387b0fc5d3071a30c6d003b415dc6e77f3d62 (patch)
tree1645291391b412040ce55ae8dc34232cde5d22e0
parentcf37d92442ccf3c7f4b979bd97282dcbe28ca64a (diff)
Much more clang-tidy cleanup
-rw-r--r--al/auxeffectslot.cpp40
-rw-r--r--al/debug.cpp2
-rw-r--r--al/eax/call.cpp3
-rw-r--r--al/eax/call.h14
-rw-r--r--al/effect.cpp47
-rw-r--r--al/filter.cpp2
-rw-r--r--al/state.cpp2
-rw-r--r--alc/backends/null.cpp1
-rw-r--r--alc/backends/pipewire.cpp12
-rw-r--r--alc/backends/portaudio.cpp3
-rw-r--r--alc/backends/sdl2.cpp3
-rw-r--r--alc/context.cpp2
-rw-r--r--alc/device.cpp2
-rw-r--r--alc/effects/convolution.cpp2
-rw-r--r--alc/effects/null.cpp2
-rw-r--r--alc/panning.cpp247
-rw-r--r--common/phase_shifter.h10
-rw-r--r--common/ringbuffer.cpp2
-rw-r--r--core/ambdec.cpp31
-rw-r--r--core/ambdec.h10
-rw-r--r--core/buffer_storage.cpp2
-rw-r--r--core/converter.cpp26
-rw-r--r--core/converter.h16
-rw-r--r--core/cubic_tables.cpp4
-rw-r--r--core/dbus_wrap.cpp2
-rw-r--r--core/effectslot.cpp2
-rw-r--r--core/filters/biquad.cpp4
-rw-r--r--core/filters/nfc.cpp12
-rw-r--r--core/helpers.cpp2
-rw-r--r--core/hrtf.cpp57
-rw-r--r--core/hrtf.h3
-rw-r--r--core/mastering.cpp11
-rw-r--r--core/mixer/mixer_neon.cpp7
-rw-r--r--core/mixer/mixer_sse2.cpp2
-rw-r--r--core/mixer/mixer_sse41.cpp2
-rw-r--r--core/rtkit.cpp4
-rw-r--r--core/uhjfilter.cpp14
-rw-r--r--examples/alffplay.cpp52
-rw-r--r--examples/alstreamcb.cpp32
-rw-r--r--include/AL/al.h2
-rw-r--r--include/AL/alc.h2
-rw-r--r--include/AL/alext.h2
-rw-r--r--include/AL/efx-presets.h2
-rw-r--r--include/AL/efx.h2
-rw-r--r--utils/alsoft-config/mainwindow.h25
-rw-r--r--utils/makemhr/loaddef.cpp385
-rw-r--r--utils/makemhr/loadsofa.cpp20
-rw-r--r--utils/makemhr/makemhr.cpp37
-rw-r--r--utils/makemhr/makemhr.h4
-rw-r--r--utils/sofa-info.cpp3
-rw-r--r--utils/sofa-support.cpp8
-rw-r--r--utils/uhjdecoder.cpp32
-rw-r--r--utils/uhjencoder.cpp95
53 files changed, 659 insertions, 651 deletions
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 <algorithm>
#include <array>
+#include <cstddef>
#include <cstring>
#include <mutex>
#include <optional>
-#include <stddef.h>
#include <stdexcept>
#include <string>
#include <utility>
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<Resampler rtype> 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<float*[]> mChannelPtrs;
- uint mNumChannels{};
+ std::vector<float*> mChannelPtrs;
static constexpr pw_stream_events CreateEvents()
{
@@ -1468,7 +1467,7 @@ void PipeWirePlayback::outputCallback() noexcept
if(!pw_buf) UNLIKELY return;
const al::span<spa_data> 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<float*[]>(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 <algorithm>
#include <array>
+#include <cstddef>
#include <cstring>
#include <functional>
#include <limits>
#include <numeric>
-#include <stddef.h>
#include <stdexcept>
#include <string_view>
#include <utility>
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 <cstddef>
#include <numeric>
-#include <stddef.h>
#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 <array>
#include <complex>
#include <cstddef>
+#include <cstdint>
#include <functional>
#include <iterator>
#include <memory>
-#include <stdint.h>
#include <utility>
#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 <stddef.h>
+#include <cstddef>
#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<DualBand, 0> {
using DecoderView = DecoderConfig<DualBand, 0>;
-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<uint,MaxAmbiOrder+1> chans_per_order2d{{1, 2, 2, 2}};
+ static const std::array<uint,MaxAmbiOrder+1> 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<float>(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<const AmbDecConf::SpeakerConf>;
- for(auto &speaker : const_speaker_span{conf->Speakers.get(), conf->NumSpeakers})
+ for(auto &speaker : al::span<const AmbDecConf::SpeakerConf>{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<float>};
- 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<float>};
+ 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<float,MaxAmbiChannels>{{1.250000000e-01f, 1.250000000e-01f, 1.250000000e-01f, 1.250000000e-01f}},
+ std::array<float,MaxAmbiChannels>{{1.250000000e-01f, 1.250000000e-01f, 1.250000000e-01f, -1.250000000e-01f}},
+ std::array<float,MaxAmbiChannels>{{1.250000000e-01f, -1.250000000e-01f, 1.250000000e-01f, 1.250000000e-01f}},
+ std::array<float,MaxAmbiChannels>{{1.250000000e-01f, -1.250000000e-01f, 1.250000000e-01f, -1.250000000e-01f}},
+ std::array<float,MaxAmbiChannels>{{1.250000000e-01f, 1.250000000e-01f, -1.250000000e-01f, 1.250000000e-01f}},
+ std::array<float,MaxAmbiChannels>{{1.250000000e-01f, 1.250000000e-01f, -1.250000000e-01f, -1.250000000e-01f}},
+ std::array<float,MaxAmbiChannels>{{1.250000000e-01f, -1.250000000e-01f, -1.250000000e-01f, 1.250000000e-01f}},
+ std::array<float,MaxAmbiChannels>{{1.250000000e-01f, -1.250000000e-01f, -1.250000000e-01f, -1.250000000e-01f}},
+ };
+ static constexpr std::array AmbiMatrix2O{
+ std::array<float,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}},
+ std::array<float,MaxAmbiChannels>{{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<float,MaxAmbiChannels>{{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<float,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}},
+ std::array<float,MaxAmbiChannels>{{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<float,MaxAmbiChannels>{{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<float,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}},
+ std::array<float,MaxAmbiChannels>{{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<float,MaxAmbiChannels>{{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<float,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}},
+ std::array<float,MaxAmbiChannels>{{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<float,MaxAmbiChannels>{{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<float,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}},
+ std::array<float,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}},
+ std::array<float,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}},
+ std::array<float,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}},
+ std::array<float,MaxAmbiChannels>{{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<float,MaxAmbiChannels>{{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<float,MaxAmbiChannels>{{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<float,MaxAmbiChannels>{{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<float,MaxAmbiChannels>{{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<float,MaxAmbiChannels>{{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<float,MaxAmbiChannels>{{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<float,MaxAmbiChannels>{{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<float,MaxAmbiChannels>{{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<float,MaxAmbiChannels>{{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<float,MaxAmbiChannels>{{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<float,MaxAmbiChannels>{{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<float,MaxAmbiChannels>{{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<float,MaxAmbiChannels>{{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<float,MaxAmbiChannels>{{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<float,MaxAmbiChannels>{{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<float,MaxAmbiOrder+1> AmbiOrderHFGain1O{
/*ENRGY*/ 2.000000000e+00f, 1.154700538e+00f
- }, AmbiOrderHFGain2O[MaxAmbiOrder+1]{
+ };
+ static constexpr std::array<float,MaxAmbiOrder+1> 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<float,MaxAmbiOrder+1> 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<std::string>(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<const AngularPoint> AmbiPoints{AmbiPoints1O};
- const float (*AmbiMatrix)[MaxAmbiChannels]{AmbiMatrix1O};
- al::span<const float,MaxAmbiOrder+1> 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::optional<StereoEncodin
ERR(" %s\n", err->c_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 <array>
#include <stddef.h>
#include <type_traits>
+#include <vector>
#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<complex_d[]>(fft_size);
- std::fill_n(fftBuffer.get(), fft_size, complex_d{});
+ auto fftBuffer = std::vector<complex_d>(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<double>::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<double>::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<float>(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 <algorithm>
#include <climits>
+#include <cstdint>
#include <limits>
#include <stdexcept>
-#include <stdint.h>
#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<std::string> 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<std::string> 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<std::string> 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<SpeakerConf[]>(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<std::string> 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<CoeffArray[]>(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<std::string> 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 <memory>
#include <optional>
#include <string>
+#include <vector>
#include "core/ambidefs.h"
@@ -34,17 +35,16 @@ struct AmbDecConf {
float Elevation{0.0f};
std::string Connection;
};
- size_t NumSpeakers{0};
- std::unique_ptr<SpeakerConf[]> Speakers;
+ std::vector<SpeakerConf> Speakers;
using CoeffArray = std::array<float,MaxAmbiChannels>;
- std::unique_ptr<CoeffArray[]> Matrix;
+ std::vector<CoeffArray> Matrix;
/* Unused when FreqBands == 1 */
- float LFOrderGain[MaxAmbiOrder+1]{};
+ std::array<float,MaxAmbiOrder+1> LFOrderGain{};
CoeffArray *LFMatrix;
- float HFOrderGain[MaxAmbiOrder+1]{};
+ std::array<float,MaxAmbiOrder+1> 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 <stdint.h>
+#include <cstdint>
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 <cstddef>
#include <cstdint>
#include <iterator>
-#include <limits.h>
+#include <climits>
#include "albit.h"
#include "alnumeric.h"
@@ -51,7 +51,7 @@ template<DevFmtType T>
inline void LoadSampleArray(float *RESTRICT dst, const void *src, const size_t srcstep,
const size_t samples) noexcept
{
- const DevFmtType_t<T> *ssrc = static_cast<const DevFmtType_t<T>*>(src);
+ auto *ssrc = static_cast<const DevFmtType_t<T>*>(src);
for(size_t i{0u};i < samples;i++)
dst[i] = LoadSample<T>(ssrc[i*srcstep]);
}
@@ -99,7 +99,7 @@ template<DevFmtType T>
inline void StoreSampleArray(void *dst, const float *RESTRICT src, const size_t dststep,
const size_t samples) noexcept
{
- DevFmtType_t<T> *sdst = static_cast<DevFmtType_t<T>*>(dst);
+ auto *sdst = static_cast<DevFmtType_t<T>*>(dst);
for(size_t i{0u};i < samples;i++)
sdst[i*dststep] = StoreSample<T>(src[i]);
}
@@ -127,7 +127,7 @@ void StoreSamples(void *dst, const float *src, const size_t dststep, const DevFm
template<DevFmtType T>
void Mono2Stereo(float *RESTRICT dst, const void *src, const size_t frames) noexcept
{
- const DevFmtType_t<T> *ssrc = static_cast<const DevFmtType_t<T>*>(src);
+ auto *ssrc = static_cast<const DevFmtType_t<T>*>(src);
for(size_t i{0u};i < frames;i++)
dst[i*2 + 1] = dst[i*2 + 0] = LoadSample<T>(ssrc[i]) * 0.707106781187f;
}
@@ -136,7 +136,7 @@ template<DevFmtType T>
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<T> *ssrc = static_cast<const DevFmtType_t<T>*>(src);
+ auto *ssrc = static_cast<const DevFmtType_t<T>*>(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<float,MaxResamplerPadding> PrevSamples;
};
al::FlexArray<ChanSamples> 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<int64_t, std::ratio<1,MixerFracOne>>;
- SampleOffset currentInputDelay() const noexcept
+ [[nodiscard]] auto currentInputDelay() const noexcept -> SampleOffset
{
const int64_t prep{int64_t{mSrcPrepCount} - MaxResamplerEdge};
return SampleOffset{(prep<<MixerFracBits) + mFracOffset};
@@ -60,7 +60,7 @@ struct ChannelConverter {
uint mChanMask{};
DevFmtChannels mDstChans{};
- bool is_active() const noexcept { return mChanMask != 0; }
+ [[nodiscard]] auto is_active() const noexcept -> 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 <array>
-#include <stddef.h>
+#include <cstddef>
#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<std::remove_reference_t<decltype(f)>>(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 <stddef.h>
+#include <cstddef>
#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<Real>::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<Real,3> a{{1.0f, 0.0f, 0.0f}};
+ std::array<Real,3> 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<size_t,4> 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<float,4> 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> DirectHrtfState::Create(size_t num_chans)
{ return std::unique_ptr<DirectHrtfState>{new(FamCount(num_chans)) DirectHrtfState{num_chans}}; }
void DirectHrtfState::build(const HrtfStore *Hrtf, const uint irSize, const bool perHrirMin,
- const al::span<const AngularPoint> AmbiPoints, const float (*AmbiMatrix)[MaxAmbiChannels],
+ const al::span<const AngularPoint> AmbiPoints,
+ const al::span<const std::array<float,MaxAmbiChannels>> AmbiMatrix,
const float XOverFreq, const al::span<const float,MaxAmbiOrder+1> AmbiOrderHFGain)
{
using double2 = std::array<double,2>;
@@ -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<size_t,4> 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<char*>(b), num_bits/8))
+ std::array<std::byte,sizeof(T)> b{};
+ if(!data.read(reinterpret_cast<char*>(b.data()), num_bits/8))
return static_cast<T>(EOF);
- std::reverse_copy(std::begin(b), std::end(b), reinterpret_cast<std::byte*>(&ret));
+ std::reverse_copy(b.begin(), b.end(), reinterpret_cast<std::byte*>(&ret));
return fixsign<num_bits>(ret);
}
@@ -598,9 +601,9 @@ std::unique_ptr<HrtfStore> 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<uint8_t>(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<uint8_t>(irSize), field, elevs, coeffs.data(),
+ delays.data(), filename);
}
std::unique_ptr<HrtfStore> LoadHrtf01(std::istream &data, const char *filename)
@@ -676,9 +679,8 @@ std::unique_ptr<HrtfStore> 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<HrtfStore> LoadHrtf02(std::istream &data, const char *filename)
@@ -946,8 +948,7 @@ std::unique_ptr<HrtfStore> 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<HrtfStore> LoadHrtf03(std::istream &data, const char *filename)
@@ -1115,8 +1116,7 @@ std::unique_ptr<HrtfStore> 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<const char> 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<HrtfStore> hrtf;
- char magic[sizeof(magicMarker03)];
- stream->read(magic, sizeof(magic));
+ std::array<char,sizeof(magicMarker03)> magic{};
+ stream->read(magic.data(), magic.size());
if(stream->gcount() < static_cast<std::streamsize>(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<HrirArray&>(hrtf->mCoeffs[i]);
+ auto &coeffs = const_cast<HrirArray&>(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<ubyte2&>(hrtf->mDelays[i]);
+ auto &delays = const_cast<ubyte2&>(hrtf->mDelays[i]);
for(size_t j{0};j < 2;++j)
delays[j] = static_cast<ubyte>(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<const AngularPoint> AmbiPoints, const float (*AmbiMatrix)[MaxAmbiChannels],
+ const al::span<const AngularPoint> AmbiPoints,
+ const al::span<const std::array<float,MaxAmbiChannels>> AmbiMatrix,
const float XOverFreq, const al::span<const float,MaxAmbiOrder+1> AmbiOrderHFGain);
static std::unique_ptr<DirectHrtfState> 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<uint,BufferLineSize> 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<float(&)(float)>(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_<LerpTag,NEONTag>(const InterpState*, const float *RESTRICT src, u
const int32x4_t increment4 = vdupq_n_s32(static_cast<int>(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<uint,4> pos_, frac_;
InitPosArrays(frac, increment, al::span{frac_}, al::span{pos_});
- frac4 = vld1q_s32(reinterpret_cast<int*>(frac_));
- pos4 = vld1q_s32(reinterpret_cast<int*>(pos_));
+ int32x4_t frac4 = vld1q_s32(reinterpret_cast<int*>(frac_));
+ int32x4_t pos4 = vld1q_s32(reinterpret_cast<int*>(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_<LerpTag,SSE2Tag>(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<uint,4> pos_, frac_;
InitPosArrays(frac, increment, al::span{frac_}, al::span{pos_});
__m128i frac4{_mm_setr_epi32(static_cast<int>(frac_[0]), static_cast<int>(frac_[1]),
static_cast<int>(frac_[2]), static_cast<int>(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_<LerpTag,SSE4Tag>(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<uint,4> pos_, frac_;
InitPosArrays(frac, increment, al::span{frac_}, al::span{pos_});
__m128i frac4{_mm_setr_epi32(static_cast<int>(frac_[0]), static_cast<int>(frac_[1]),
static_cast<int>(frac_[2]), static_cast<int>(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 <errno.h>
+#include <cerrno>
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <memory>
-#include <string.h>
+#include <cstring>
#include <unistd.h>
#include <sys/types.h>
#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 <algorithm>
#include <iterator>
+#include <vector>
#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<complex_d[]>(fft_size);
- std::fill_n(fftBuffer.get(), fft_size, complex_d{});
+ auto fftBuffer = std::vector<complex_d>(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<double>::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<double>::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<complex_d[]>(sFftLength);
+ auto fftBuffer2 = std::vector<complex_d>(sFftLength);
auto fftTmp = al::vector<float,16>(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<uint8_t[]> mBufferData;
- size_t mBufferDataSize{0};
+ std::vector<uint8_t> mBufferData_;
+ //std::unique_ptr<uint8_t[]> mBufferData;
+ //size_t mBufferDataSize{0};
std::atomic<size_t> mReadPos{0};
std::atomic<size_t> 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<size_t>(nsamples, static_cast<ALuint>(-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<ALuint>(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<size_t>(todo, static_cast<ALuint>(size-got));
- memcpy(data, &mBufferData[roffset], todo);
+ memcpy(data, &mBufferData_[roffset], todo);
data = static_cast<ALbyte*>(data) + todo;
got += static_cast<ALsizei>(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<uint8_t[]> samples;
+ std::vector<uint8_t> samples;
ALsizei buffer_len{0};
/* Find a suitable format for OpenAL. */
@@ -1235,13 +1236,12 @@ int AudioState::handler()
}
else
{
- mBufferDataSize = static_cast<size_t>(duration_cast<seconds>(mCodecCtx->sample_rate *
- AudioBufferTotalTime).count()) * mFrameSize;
- mBufferData = std::make_unique<uint8_t[]>(mBufferDataSize);
- std::fill_n(mBufferData.get(), mBufferDataSize, uint8_t{});
+ mBufferData_.resize(static_cast<size_t>(duration_cast<seconds>(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<int>(duration_cast<seconds>(mCodecCtx->sample_rate *
AudioBufferTime).count() * mFrameSize);
if(buffer_len > 0)
- samples = std::make_unique<uint8_t[]>(static_cast<ALuint>(buffer_len));
+ samples.resize(static_cast<ALuint>(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<ALuint>(buffer_len), sync_skip))
+ if(!readAudio(samples.data(), static_cast<ALuint>(buffer_len), sync_skip))
break;
const ALuint bufid{mBuffers[mBufferIdx]};
mBufferIdx = static_cast<ALuint>((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 <string.h>
-#include <stdlib.h>
-#include <stdio.h>
#include <atomic>
#include <chrono>
+#include <cstring>
+#include <cstdlib>
+#include <cstdio>
#include <memory>
#include <stdexcept>
#include <string>
@@ -58,8 +58,7 @@ struct StreamPlayer {
/* A lockless ring-buffer (supports single-provider, single-consumer
* operation).
*/
- std::unique_ptr<ALbyte[]> mBufferData;
- size_t mBufferDataSize{0};
+ std::vector<ALbyte> mBufferData;
std::atomic<size_t> mReadPos{0};
std::atomic<size_t> 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<ALuint>(mSfInfo.samplerate) + mSamplesPerBlock-1)
/ mSamplesPerBlock};
- mBufferDataSize = static_cast<ALuint>(numblocks * mBytesPerBlock);
- mBufferData.reset(new ALbyte[mBufferDataSize]);
+ mBufferData.resize(static_cast<ALuint>(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<size_t>(todo, static_cast<ALuint>(size-got));
/* Copy from the ring buffer to the provided output buffer. Wrap
@@ -317,7 +315,7 @@ struct StreamPlayer {
got += static_cast<ALsizei>(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<ALuint>(pos) + mStartOffset/mBytesPerBlock*mSamplesPerBlock))
/ static_cast<ALuint>(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 <stddef.h>
/* 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 <float.h>
#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 <optional>
#include <vector>
+#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<char,MAX_PATH_LEN+1> 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<char,64+1> 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<int>(strtol(temp, nullptr, 10));
+ *value = static_cast<int>(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<char,64+1> 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<char*>(in), static_cast<int>(bytes));
+ std::array<uint8_t,4> in{};
+ istream.read(reinterpret_cast<char*>(in.data()), static_cast<int>(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<char*>(in), 8);
+ std::array<uint8_t,8> in{};
+ istream.read(reinterpret_cast<char*>(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<double>(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<float>(val);
else
{
if(bits > 0)
- v4.ui >>= (8*bytes) - (static_cast<uint>(bits));
+ val >>= (8*bytes) - (static_cast<uint>(bits));
else
- v4.ui &= (0xFFFFFFFF >> (32+bits));
+ val &= (0xFFFFFFFF >> (32+bits));
- if(v4.ui&static_cast<uint>(1<<(std::abs(bits)-1)))
- v4.ui |= (0xFFFFFFFF << std::abs(bits));
- *out = v4.i / static_cast<double>(1<<(std::abs(bits)-1));
+ if(val&static_cast<uint>(1<<(std::abs(bits)-1)))
+ val |= (0xFFFFFFFF << std::abs(bits));
+ *out = static_cast<int32_t>(val) / static_cast<double>(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<int>(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<int>(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<long>(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<uint>(src->mBits), &dummy))
+ double dummy{};
+ if(!ReadAsciiAsDouble(&tr, src->mPath.data(), src->mType, static_cast<uint>(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<uint>(src->mBits), &hrir[i]))
+ if(!ReadAsciiAsDouble(&tr, src->mPath.data(), src->mType, static_cast<uint>(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<uint>(src->mBits), &dummy))
+ double dummy{};
+ if(!ReadAsciiAsDouble(&tr, src->mPath.data(), src->mType,
+ static_cast<uint>(src->mBits), &dummy))
return 0;
}
}
@@ -1026,7 +1021,8 @@ static int LoadBinarySource(std::istream &istream, const SourceRefT *src, const
istream.seekg(static_cast<long>(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<long>(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<float>(hrirRate))};
+ MYSOFA_EASY *sofa{mysofa_cache_lookup(src->mPath.data(), static_cast<float>(hrirRate))};
if(sofa) return sofa;
sofa = static_cast<MYSOFA_EASY*>(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<float>(hrirRate));
+ return mysofa_cache_store(sofa, src->mPath.data(), static_cast<float>(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<float>(src->mAzimuth);
- target[1] = static_cast<float>(src->mElevation);
- target[2] = static_cast<float>(src->mRadius);
- mysofa_s2c(target);
-
- nearest = mysofa_lookup(sofa->lookup, target);
+ std::array target{
+ static_cast<float>(src->mAzimuth),
+ static_cast<float>(src->mElevation),
+ static_cast<float>(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<float,3> 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<al::ifstream>(src->mPath.data());
else
- istream.reset(new al::ifstream{src->mPath, std::ios::binary});
+ istream = std::make_unique<al::ifstream>(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<char,MAX_IDENT_LEN+1> ident;
uint line, col;
double fpVal;
uint points;
int intVal;
- double distances[MAX_FD_COUNT];
+ std::array<double,MAX_FD_COUNT> distances;
uint fdCount = 0;
- uint evCounts[MAX_FD_COUNT];
+ std::array<uint,MAX_FD_COUNT> evCounts;
auto azCounts = std::vector<std::array<uint,MAX_EV_COUNT>>(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<uint>(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<char,MAX_IDENT_LEN+1> 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<MAX_FD_COUNT>();
- 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<char,MAX_IDENT_LEN+1> 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<char,MAX_IDENT_LEN+1> 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<double[]>(hData->mIrSize);
+ auto hrir = std::vector<double>(hData->mIrSize);
uint line, col, fi, ei, ai;
std::vector<double> 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<char,MAX_IDENT_LEN+1> 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<char,MAX_IDENT_LEN+1> 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<char,MAX_IDENT_LEN+1> ident{};
+ if(!TrReadIdent(tr, MAX_IDENT_LEN, ident.data()))
return 0;
- ti = static_cast<uint>(MatchTargetEar(ident));
+ ti = static_cast<uint>(MatchTargetEar(ident.data()));
if(static_cast<int>(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<double,MAX_FD_COUNT> distances{};
+ std::array<uint,MAX_FD_COUNT> evCounts{};
auto azCounts = std::vector<std::array<uint,MAX_EV_COUNT>>(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<MAX_FD_COUNT>();
- 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<double[]> restmp;
+ std::vector<double> restmp;
std::optional<PPhaseResampler> resampler;
if(outRate && outRate != hData->mIrRate)
{
resampler.emplace().init(hData->mIrRate, outRate);
- restmp = std::make_unique<double[]>(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<complex_d>(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<uint8_t,4> 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<double,2*MAX_TRUNCSIZE> 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<int>(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<double,4> 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<double>(ei) / field.mEvStart};
const double b{(1.0 - of) * beta};
- double lp[4]{};
+ std::array<double,4> 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<double,4> 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<double>(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<char,4> 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<double,2> mDelays{};
+ std::array<double*,2> 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 <stdio.h>
-
+#include <cstdio>
#include <memory>
#include <vector>
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 <stdio.h>
#include <algorithm>
#include <array>
#include <cmath>
+#include <cstdio>
#include <utility>
#include <vector>
@@ -47,7 +47,7 @@ using double3 = std::array<double,3>;
* equality of unique elements.
*/
std::vector<double> GetUniquelySortedElems(const std::vector<double3> &aers, const uint axis,
- const double *const (&filters)[3], const double (&epsilons)[3])
+ const std::array<const double*,3> filters, const std::array<double,3> epsilons)
{
std::vector<double> elems;
for(const double3 &aer : aers)
@@ -183,8 +183,8 @@ std::vector<SofaField> GetCompatibleLayout(const size_t m, const float *xyzs)
auto aers = std::vector<double3>(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<double>;
using byte4 = std::array<std::byte,4>;
-constexpr ubyte SUBTYPE_BFORMAT_FLOAT[]{
+constexpr std::array<ubyte,16> 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<ubyte>(val&0xff), static_cast<ubyte>((val>>8)&0xff) };
- fwrite(data, 1, 2, f);
+ std::array data{static_cast<ubyte>(val&0xff), static_cast<ubyte>((val>>8)&0xff)};
+ fwrite(data.data(), 1, data.size(), f);
}
void fwrite32le(uint val, FILE *f)
{
- ubyte data[4]{ static_cast<ubyte>(val&0xff), static_cast<ubyte>((val>>8)&0xff),
- static_cast<ubyte>((val>>16)&0xff), static_cast<ubyte>((val>>24)&0xff) };
- fwrite(data, 1, 4, f);
+ std::array data{static_cast<ubyte>(val&0xff), static_cast<ubyte>((val>>8)&0xff),
+ static_cast<ubyte>((val>>16)&0xff), static_cast<ubyte>((val>>24)&0xff)};
+ fwrite(data.data(), 1, data.size(), f);
}
template<al::endian = al::endian::native>
@@ -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<uint>(ininfo.samplerate), outfile.get());
// 32-bit val, bytes per second
- fwrite32le(static_cast<uint>(ininfo.samplerate)*sizeof(float)*outchans, outfile.get());
+ fwrite32le(static_cast<uint>(ininfo.samplerate)*outchans*sizeof(float), outfile.get());
// 16-bit val, frame size
fwrite16le(static_cast<ushort>(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<UhjDecoder>();
- auto inmem = std::make_unique<float[]>(BufferLineSize*static_cast<uint>(ininfo.channels));
+ auto inmem = std::vector<float>(BufferLineSize*static_cast<uint>(ininfo.channels));
auto decmem = al::vector<std::array<float,BufferLineSize>, 16>(outchans);
- auto outmem = std::make_unique<byte4[]>(BufferLineSize*outchans);
+ auto outmem = std::vector<byte4>(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<sf_count_t>(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<std::size_t>(sgot);
if(ininfo.channels > 2 || use_general)
- decoder->decode(inmem.get(), static_cast<uint>(ininfo.channels), decmem, got);
+ decoder->decode(inmem.data(), static_cast<uint>(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 <array>
#include <cinttypes>
+#include <cstddef>
#include <cstring>
#include <memory>
-#include <stddef.h>
#include <string>
#include <utility>
#include <vector>
@@ -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