diff options
author | Chris Robinson <[email protected]> | 2023-12-10 22:15:17 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2023-12-10 22:15:17 -0800 |
commit | bb3387b0fc5d3071a30c6d003b415dc6e77f3d62 (patch) | |
tree | 1645291391b412040ce55ae8dc34232cde5d22e0 /core | |
parent | cf37d92442ccf3c7f4b979bd97282dcbe28ca64a (diff) |
Much more clang-tidy cleanup
Diffstat (limited to 'core')
-rw-r--r-- | core/ambdec.cpp | 31 | ||||
-rw-r--r-- | core/ambdec.h | 10 | ||||
-rw-r--r-- | core/buffer_storage.cpp | 2 | ||||
-rw-r--r-- | core/converter.cpp | 26 | ||||
-rw-r--r-- | core/converter.h | 16 | ||||
-rw-r--r-- | core/cubic_tables.cpp | 4 | ||||
-rw-r--r-- | core/dbus_wrap.cpp | 2 | ||||
-rw-r--r-- | core/effectslot.cpp | 2 | ||||
-rw-r--r-- | core/filters/biquad.cpp | 4 | ||||
-rw-r--r-- | core/filters/nfc.cpp | 12 | ||||
-rw-r--r-- | core/helpers.cpp | 2 | ||||
-rw-r--r-- | core/hrtf.cpp | 57 | ||||
-rw-r--r-- | core/hrtf.h | 3 | ||||
-rw-r--r-- | core/mastering.cpp | 11 | ||||
-rw-r--r-- | core/mixer/mixer_neon.cpp | 7 | ||||
-rw-r--r-- | core/mixer/mixer_sse2.cpp | 2 | ||||
-rw-r--r-- | core/mixer/mixer_sse41.cpp | 2 | ||||
-rw-r--r-- | core/rtkit.cpp | 4 | ||||
-rw-r--r-- | core/uhjfilter.cpp | 14 |
19 files changed, 107 insertions, 104 deletions
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. |