diff options
author | Chris Robinson <[email protected]> | 2023-12-09 10:02:27 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2023-12-09 10:02:27 -0800 |
commit | decc10da2bdbb611cce63916f8c6f8b17ea45da1 (patch) | |
tree | f2bea89f5da0ad72dc0cd95eebe936c7b64f67dc /core | |
parent | 8ba2208f5e6e6460c338c5b3168ee6be485b4e10 (diff) |
More clang-tidy fixes
Diffstat (limited to 'core')
-rw-r--r-- | core/bs2b.cpp | 127 | ||||
-rw-r--r-- | core/bs2b.h | 81 | ||||
-rw-r--r-- | core/bsinc_tables.cpp | 13 | ||||
-rw-r--r-- | core/bsinc_tables.h | 6 | ||||
-rw-r--r-- | core/cubic_defs.h | 6 | ||||
-rw-r--r-- | core/device.h | 4 | ||||
-rw-r--r-- | core/mastering.cpp | 16 | ||||
-rw-r--r-- | core/mastering.h | 7 | ||||
-rw-r--r-- | core/mixer/mixer_c.cpp | 4 | ||||
-rw-r--r-- | core/mixer/mixer_neon.cpp | 4 | ||||
-rw-r--r-- | core/mixer/mixer_sse.cpp | 4 |
11 files changed, 140 insertions, 132 deletions
diff --git a/core/bs2b.cpp b/core/bs2b.cpp index 303bf9bd..9157c4d7 100644 --- a/core/bs2b.cpp +++ b/core/bs2b.cpp @@ -26,72 +26,74 @@ #include <algorithm> #include <cmath> #include <iterator> +#include <stdexcept> #include "alnumbers.h" #include "bs2b.h" +namespace { /* Set up all data. */ -static void init(struct bs2b *bs2b) +void init(Bs2b::bs2b *bs2b) { float Fc_lo, Fc_hi; float G_lo, G_hi; - float x, g; switch(bs2b->level) { - case BS2B_LOW_CLEVEL: /* Low crossfeed level */ + case Bs2b::LowCLevel: /* Low crossfeed level */ Fc_lo = 360.0f; Fc_hi = 501.0f; G_lo = 0.398107170553497f; G_hi = 0.205671765275719f; break; - case BS2B_MIDDLE_CLEVEL: /* Middle crossfeed level */ + case Bs2b::MiddleCLevel: /* Middle crossfeed level */ Fc_lo = 500.0f; Fc_hi = 711.0f; G_lo = 0.459726988530872f; G_hi = 0.228208484414988f; break; - case BS2B_HIGH_CLEVEL: /* High crossfeed level (virtual speakers are closer to itself) */ + case Bs2b::HighCLevel: /* High crossfeed level (virtual speakers are closer to itself) */ Fc_lo = 700.0f; Fc_hi = 1021.0f; G_lo = 0.530884444230988f; G_hi = 0.250105790667544f; break; - case BS2B_LOW_ECLEVEL: /* Low easy crossfeed level */ + case Bs2b::LowECLevel: /* Low easy crossfeed level */ Fc_lo = 360.0f; Fc_hi = 494.0f; G_lo = 0.316227766016838f; G_hi = 0.168236228897329f; break; - case BS2B_MIDDLE_ECLEVEL: /* Middle easy crossfeed level */ + case Bs2b::MiddleECLevel: /* Middle easy crossfeed level */ Fc_lo = 500.0f; Fc_hi = 689.0f; G_lo = 0.354813389233575f; G_hi = 0.187169483835901f; break; - default: /* High easy crossfeed level */ - bs2b->level = BS2B_HIGH_ECLEVEL; + case Bs2b::HighECLevel: /* High easy crossfeed level */ + default: + bs2b->level = Bs2b::HighECLevel; Fc_lo = 700.0f; Fc_hi = 975.0f; G_lo = 0.398107170553497f; G_hi = 0.205671765275719f; break; - } /* switch */ + } - g = 1.0f / (1.0f - G_hi + G_lo); + float g{1.0f / (1.0f - G_hi + G_lo)}; /* $fc = $Fc / $s; * $d = 1 / 2 / pi / $fc; * $x = exp(-1 / $d); */ - x = std::exp(-al::numbers::pi_v<float>*2.0f*Fc_lo/static_cast<float>(bs2b->srate)); + float x{ std::exp(-al::numbers::pi_v<float>*2.0f*Fc_lo/static_cast<float>(bs2b->srate))}; bs2b->b1_lo = x; bs2b->a0_lo = G_lo * (1.0f - x) * g; @@ -99,85 +101,84 @@ static void init(struct bs2b *bs2b) bs2b->b1_hi = x; bs2b->a0_hi = (1.0f - G_hi * (1.0f - x)) * g; bs2b->a1_hi = -x * g; -} /* init */ +} +} // namespace /* Exported functions. * See descriptions in "bs2b.h" */ +namespace Bs2b { -void bs2b_set_params(struct bs2b *bs2b, int level, int srate) -{ - if(srate <= 0) srate = 1; - - bs2b->level = level; - bs2b->srate = srate; - init(bs2b); -} /* bs2b_set_params */ - -int bs2b_get_level(struct bs2b *bs2b) +void bs2b::set_params(int level_, int srate_) { - return bs2b->level; -} /* bs2b_get_level */ + if(srate_ < 1) + throw std::runtime_error{"BS2B srate < 1"}; -int bs2b_get_srate(struct bs2b *bs2b) -{ - return bs2b->srate; -} /* bs2b_get_srate */ + level = level_; + srate = srate_; + init(this); +} -void bs2b_clear(struct bs2b *bs2b) +void bs2b::clear() { - std::fill(std::begin(bs2b->history), std::end(bs2b->history), bs2b::t_last_sample{}); -} /* bs2b_clear */ + history.fill(bs2b::t_last_sample{}); +} -void bs2b_cross_feed(struct bs2b *bs2b, float *Left, float *Right, size_t SamplesToDo) +void bs2b::cross_feed(float *RESTRICT Left, float *RESTRICT Right, size_t SamplesToDo) { - const float a0_lo{bs2b->a0_lo}; - const float b1_lo{bs2b->b1_lo}; - const float a0_hi{bs2b->a0_hi}; - const float a1_hi{bs2b->a1_hi}; - const float b1_hi{bs2b->b1_hi}; - float lsamples[128][2]; - float rsamples[128][2]; + const float a0lo{a0_lo}; + const float b1lo{b1_lo}; + const float a0hi{a0_hi}; + const float a1hi{a1_hi}; + const float b1hi{b1_hi}; + std::array<std::array<float,2>,128> samples; for(size_t base{0};base < SamplesToDo;) { - const size_t todo{std::min<size_t>(128, SamplesToDo-base)}; + const size_t todo{std::min(samples.size(), SamplesToDo-base)}; /* Process left input */ - float z_lo{bs2b->history[0].lo}; - float z_hi{bs2b->history[0].hi}; + float z_lo{history[0].lo}; + float z_hi{history[0].hi}; for(size_t i{0};i < todo;i++) { - lsamples[i][0] = a0_lo*Left[i] + z_lo; - z_lo = b1_lo*lsamples[i][0]; - - lsamples[i][1] = a0_hi*Left[i] + z_hi; - z_hi = a1_hi*Left[i] + b1_hi*lsamples[i][1]; + const float x{Left[i]}; + float y{a0hi*x + z_hi}; + z_hi = a1hi*x + b1hi*y; + samples[i][0] = y; + + y = a0lo*x + z_lo; + z_lo = b1lo*y; + samples[i][1] = y; } - bs2b->history[0].lo = z_lo; - bs2b->history[0].hi = z_hi; + history[0].lo = z_lo; + history[0].hi = z_hi; /* Process right input */ - z_lo = bs2b->history[1].lo; - z_hi = bs2b->history[1].hi; + z_lo = history[1].lo; + z_hi = history[1].hi; for(size_t i{0};i < todo;i++) { - rsamples[i][0] = a0_lo*Right[i] + z_lo; - z_lo = b1_lo*rsamples[i][0]; - - rsamples[i][1] = a0_hi*Right[i] + z_hi; - z_hi = a1_hi*Right[i] + b1_hi*rsamples[i][1]; + const float x{Right[i]}; + float y{a0lo*x + z_lo}; + z_lo = b1lo*y; + samples[i][0] += y; + + y = a0hi*x + z_hi; + z_hi = a1hi*x + b1hi*y; + samples[i][1] += y; } - bs2b->history[1].lo = z_lo; - bs2b->history[1].hi = z_hi; + history[1].lo = z_lo; + history[1].hi = z_hi; - /* Crossfeed */ for(size_t i{0};i < todo;i++) - *(Left++) = lsamples[i][1] + rsamples[i][0]; + *(Left++) = samples[i][0]; for(size_t i{0};i < todo;i++) - *(Right++) = rsamples[i][1] + lsamples[i][0]; + *(Right++) = samples[i][1]; base += todo; } -} /* bs2b_cross_feed */ +} + +} // namespace Bs2b diff --git a/core/bs2b.h b/core/bs2b.h index 4d0b9dd8..6fb54c0c 100644 --- a/core/bs2b.h +++ b/core/bs2b.h @@ -24,66 +24,65 @@ #ifndef CORE_BS2B_H #define CORE_BS2B_H -#include "almalloc.h" +#include <array> -/* Number of crossfeed levels */ -#define BS2B_CLEVELS 3 +namespace Bs2b { -/* Normal crossfeed levels */ -#define BS2B_HIGH_CLEVEL 3 -#define BS2B_MIDDLE_CLEVEL 2 -#define BS2B_LOW_CLEVEL 1 +enum { + /* Normal crossfeed levels */ + LowCLevel = 1, + MiddleCLevel = 2, + HighCLevel = 3, -/* Easy crossfeed levels */ -#define BS2B_HIGH_ECLEVEL BS2B_HIGH_CLEVEL + BS2B_CLEVELS -#define BS2B_MIDDLE_ECLEVEL BS2B_MIDDLE_CLEVEL + BS2B_CLEVELS -#define BS2B_LOW_ECLEVEL BS2B_LOW_CLEVEL + BS2B_CLEVELS + /* Easy crossfeed levels */ + LowECLevel = 4, + MiddleECLevel = 5, + HighECLevel = 6, -/* Default crossfeed levels */ -#define BS2B_DEFAULT_CLEVEL BS2B_HIGH_ECLEVEL -/* Default sample rate (Hz) */ -#define BS2B_DEFAULT_SRATE 44100 + DefaultCLevel = HighECLevel +}; struct bs2b { - int level; /* Crossfeed level */ - int srate; /* Sample rate (Hz) */ + int level{}; /* Crossfeed level */ + int srate{}; /* Sample rate (Hz) */ /* Lowpass IIR filter coefficients */ - float a0_lo; - float b1_lo; + float a0_lo{}; + float b1_lo{}; /* Highboost IIR filter coefficients */ - float a0_hi; - float a1_hi; - float b1_hi; + float a0_hi{}; + float a1_hi{}; + float b1_hi{}; /* Buffer of filter history * [0] - first channel, [1] - second channel */ struct t_last_sample { - float lo; - float hi; - } history[2]; - - DEF_NEWDEL(bs2b) -}; + float lo{}; + float hi{}; + }; + std::array<t_last_sample,2> history{}; + + /* Clear buffers and set new coefficients with new crossfeed level and + * sample rate values. + * level - crossfeed level of *Level enum values. + * srate - sample rate by Hz. + */ + void set_params(int level, int srate); -/* Clear buffers and set new coefficients with new crossfeed level and sample - * rate values. - * level - crossfeed level of *LEVEL values. - * srate - sample rate by Hz. - */ -void bs2b_set_params(bs2b *bs2b, int level, int srate); + /* Return current crossfeed level value */ + [[nodiscard]] auto get_level() const noexcept -> int { return level; } -/* Return current crossfeed level value */ -int bs2b_get_level(bs2b *bs2b); + /* Return current sample rate value */ + [[nodiscard]] auto get_srate() const noexcept -> int { return srate; } -/* Return current sample rate value */ -int bs2b_get_srate(bs2b *bs2b); + /* Clear buffer */ + void clear(); -/* Clear buffer */ -void bs2b_clear(bs2b *bs2b); + void cross_feed(float *Left, float *Right, size_t SamplesToDo); +}; -void bs2b_cross_feed(bs2b *bs2b, float *Left, float *Right, size_t SamplesToDo); +} // namespace Bs2b #endif /* CORE_BS2B_H */ diff --git a/core/bsinc_tables.cpp b/core/bsinc_tables.cpp index 41102e9a..03eb4341 100644 --- a/core/bsinc_tables.cpp +++ b/core/bsinc_tables.cpp @@ -5,9 +5,9 @@ #include <array> #include <cassert> #include <cmath> +#include <cstddef> #include <limits> #include <memory> -#include <stddef.h> #include <stdexcept> #include "alnumbers.h" @@ -123,7 +123,7 @@ struct BSincHeader { double beta{}; double scaleBase{}; - uint a[BSincScaleCount]{}; + std::array<uint,BSincScaleCount> a{}; uint total_size{}; constexpr BSincHeader(uint Rejection, uint Order) noexcept @@ -162,8 +162,9 @@ struct BSincFilterArray { constexpr uint BSincPointsMax{(hdr.a[0]*2 + 3) & ~3u}; static_assert(BSincPointsMax <= MaxResamplerPadding, "MaxResamplerPadding is too small"); - using filter_type = double[BSincPhaseCount+1][BSincPointsMax]; - auto filter = std::make_unique<filter_type[]>(BSincScaleCount); + using filter_type = std::array<std::array<double,BSincPointsMax>,BSincPhaseCount+1>; + auto filterptr = std::make_unique<std::array<filter_type,BSincScaleCount>>(); + const auto filter = filterptr->begin(); const double besseli_0_beta{cyl_bessel_i(0, hdr.beta)}; @@ -254,8 +255,8 @@ struct BSincFilterArray { assert(idx == hdr.total_size); } - constexpr const BSincHeader &getHeader() const noexcept { return hdr; } - constexpr const float *getTable() const noexcept { return &mTable.front(); } + [[nodiscard]] constexpr auto getHeader() const noexcept -> const BSincHeader& { return hdr; } + [[nodiscard]] constexpr auto getTable() const noexcept -> const float* { return mTable.data(); } }; const BSincFilterArray<bsinc12_hdr> bsinc12_filter{}; diff --git a/core/bsinc_tables.h b/core/bsinc_tables.h index aca4b274..6c33bd56 100644 --- a/core/bsinc_tables.h +++ b/core/bsinc_tables.h @@ -1,13 +1,15 @@ #ifndef CORE_BSINC_TABLES_H #define CORE_BSINC_TABLES_H +#include <array> + #include "bsinc_defs.h" struct BSincTable { float scaleBase, scaleRange; - unsigned int m[BSincScaleCount]; - unsigned int filterOffset[BSincScaleCount]; + std::array<unsigned int,BSincScaleCount> m; + std::array<unsigned int,BSincScaleCount> filterOffset; const float *Tab; }; diff --git a/core/cubic_defs.h b/core/cubic_defs.h index 33751c97..f3ded415 100644 --- a/core/cubic_defs.h +++ b/core/cubic_defs.h @@ -1,13 +1,15 @@ #ifndef CORE_CUBIC_DEFS_H #define CORE_CUBIC_DEFS_H +#include <array> + /* The number of distinct phase intervals within the cubic filter tables. */ constexpr unsigned int CubicPhaseBits{5}; constexpr unsigned int CubicPhaseCount{1 << CubicPhaseBits}; struct CubicCoefficients { - float mCoeffs[4]; - float mDeltas[4]; + std::array<float,4> mCoeffs; + std::array<float,4> mDeltas; }; #endif /* CORE_CUBIC_DEFS_H */ diff --git a/core/device.h b/core/device.h index 8cc15310..f5b5d971 100644 --- a/core/device.h +++ b/core/device.h @@ -25,7 +25,9 @@ #include "vector.h" class BFormatDec; +namespace Bs2b { struct bs2b; +} // namespace Bs2b struct Compressor; struct ContextBase; struct DirectHrtfState; @@ -265,7 +267,7 @@ struct DeviceBase { std::unique_ptr<BFormatDec> AmbiDecoder; /* Stereo-to-binaural filter */ - std::unique_ptr<bs2b> Bs2b; + std::unique_ptr<Bs2b::bs2b> Bs2b; using PostProc = void(DeviceBase::*)(const size_t SamplesToDo); PostProc PostProcess{nullptr}; diff --git a/core/mastering.cpp b/core/mastering.cpp index 4445719b..1f8ad921 100644 --- a/core/mastering.cpp +++ b/core/mastering.cpp @@ -198,7 +198,7 @@ void GainCompressor(Compressor *Comp, const uint SamplesToDo) const float release{Comp->mRelease}; const float c_est{Comp->mGainEstimate}; const float a_adp{Comp->mAdaptCoeff}; - const float *crestFactor{Comp->mCrestFactor}; + const float *crestFactor{Comp->mCrestFactor.data()}; float postGain{Comp->mPostGain}; float knee{Comp->mKnee}; float t_att{attack}; @@ -211,7 +211,7 @@ void GainCompressor(Compressor *Comp, const uint SamplesToDo) ASSUME(SamplesToDo > 0); - for(float &sideChain : al::span<float>{Comp->mSideChain, SamplesToDo}) + for(float &sideChain : al::span{Comp->mSideChain.data(), SamplesToDo}) { if(autoKnee) knee = maxf(0.0f, 2.5f * (c_dev + c_est)); @@ -424,16 +424,16 @@ void Compressor::process(const uint SamplesToDo, FloatBufferLine *OutBuffer) if(mDelay) SignalDelay(this, SamplesToDo, OutBuffer); - const float (&sideChain)[BufferLineSize*2] = mSideChain; - auto apply_comp = [SamplesToDo,&sideChain](FloatBufferLine &input) noexcept -> void + const auto sideChain = al::span{mSideChain}; + auto apply_comp = [SamplesToDo,sideChain](FloatBufferLine &input) noexcept -> void { float *buffer{al::assume_aligned<16>(input.data())}; - const float *gains{al::assume_aligned<16>(&sideChain[0])}; + const float *gains{al::assume_aligned<16>(sideChain.data())}; std::transform(gains, gains+SamplesToDo, buffer, buffer, - [](float g, float s) { return g * s; }); + [](const float g, const float s) noexcept { return g * s; }); }; std::for_each(OutBuffer, OutBuffer+numChans, apply_comp); - auto side_begin = std::begin(mSideChain) + SamplesToDo; - std::copy(side_begin, side_begin+mLookAhead, std::begin(mSideChain)); + auto side_begin = mSideChain.begin() + SamplesToDo; + std::copy(side_begin, side_begin+mLookAhead, mSideChain.begin()); } diff --git a/core/mastering.h b/core/mastering.h index 1a36937c..0d4f5fa1 100644 --- a/core/mastering.h +++ b/core/mastering.h @@ -1,6 +1,7 @@ #ifndef CORE_MASTERING_H #define CORE_MASTERING_H +#include <array> #include <memory> #include "almalloc.h" @@ -44,8 +45,8 @@ struct Compressor { float mAttack{0.0f}; float mRelease{0.0f}; - alignas(16) float mSideChain[2*BufferLineSize]{}; - alignas(16) float mCrestFactor[BufferLineSize]{}; + alignas(16) std::array<float,2*BufferLineSize> mSideChain{}; + alignas(16) std::array<float,BufferLineSize> mCrestFactor{}; SlidingHold *mHold{nullptr}; FloatBufferLine *mDelay{nullptr}; @@ -63,7 +64,7 @@ struct Compressor { ~Compressor(); void process(const uint SamplesToDo, FloatBufferLine *OutBuffer); - int getLookAhead() const noexcept { return static_cast<int>(mLookAhead); } + [[nodiscard]] auto getLookAhead() const noexcept -> int { return static_cast<int>(mLookAhead); } DEF_PLACE_NEWDEL() diff --git a/core/mixer/mixer_c.cpp b/core/mixer/mixer_c.cpp index 28a92ef7..0ad1c00e 100644 --- a/core/mixer/mixer_c.cpp +++ b/core/mixer/mixer_c.cpp @@ -38,8 +38,8 @@ inline float do_cubic(const InterpState &istate, const float *RESTRICT vals, con const uint pi{frac >> CubicPhaseDiffBits}; const float pf{static_cast<float>(frac&CubicPhaseDiffMask) * (1.0f/CubicPhaseDiffOne)}; - const float *RESTRICT fil{al::assume_aligned<16>(istate.cubic.filter[pi].mCoeffs)}; - const float *RESTRICT phd{al::assume_aligned<16>(istate.cubic.filter[pi].mDeltas)}; + const float *RESTRICT fil{al::assume_aligned<16>(istate.cubic.filter[pi].mCoeffs.data())}; + const float *RESTRICT phd{al::assume_aligned<16>(istate.cubic.filter[pi].mDeltas.data())}; /* Apply the phase interpolated filter. */ return (fil[0] + pf*phd[0])*vals[0] + (fil[1] + pf*phd[1])*vals[1] diff --git a/core/mixer/mixer_neon.cpp b/core/mixer/mixer_neon.cpp index f838b20d..a509e8ba 100644 --- a/core/mixer/mixer_neon.cpp +++ b/core/mixer/mixer_neon.cpp @@ -209,8 +209,8 @@ void Resample_<CubicTag,NEONTag>(const InterpState *state, const float *RESTRICT /* Apply the phase interpolated filter. */ /* f = fil + pf*phd */ - const float32x4_t f4 = vmlaq_f32(vld1q_f32(filter[pi].mCoeffs), pf4, - vld1q_f32(filter[pi].mDeltas)); + const float32x4_t f4 = vmlaq_f32(vld1q_f32(filter[pi].mCoeffs.data()), pf4, + vld1q_f32(filter[pi].mDeltas.data())); /* r = f*src */ float32x4_t r4{vmulq_f32(f4, vld1q_f32(src))}; diff --git a/core/mixer/mixer_sse.cpp b/core/mixer/mixer_sse.cpp index 70f77c14..a84230a5 100644 --- a/core/mixer/mixer_sse.cpp +++ b/core/mixer/mixer_sse.cpp @@ -171,8 +171,8 @@ void Resample_<CubicTag,SSETag>(const InterpState *state, const float *RESTRICT /* Apply the phase interpolated filter. */ /* f = fil + pf*phd */ - const __m128 f4 = MLA4(_mm_load_ps(filter[pi].mCoeffs), pf4, - _mm_load_ps(filter[pi].mDeltas)); + const __m128 f4 = MLA4(_mm_load_ps(filter[pi].mCoeffs.data()), pf4, + _mm_load_ps(filter[pi].mDeltas.data())); /* r = f*src */ __m128 r4{_mm_mul_ps(f4, _mm_loadu_ps(src))}; |