From 7cda37a67c8f147536c53f0073df9a9e61d40587 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 4 May 2023 08:03:40 -0700 Subject: Replace al::optional with std::optional --- utils/makemhr/loaddef.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'utils/makemhr/loaddef.cpp') diff --git a/utils/makemhr/loaddef.cpp b/utils/makemhr/loaddef.cpp index e8092363..84fbb48b 100644 --- a/utils/makemhr/loaddef.cpp +++ b/utils/makemhr/loaddef.cpp @@ -33,11 +33,10 @@ #include #include #include -#include +#include #include #include "alfstream.h" -#include "aloptional.h" #include "alspan.h" #include "alstring.h" #include "makemhr.h" @@ -1755,7 +1754,7 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData, const uint outRate PPhaseResampler onsetResampler; onsetResampler.init(hData->mIrRate, OnsetRateMultiple*hData->mIrRate); - al::optional resampler; + std::optional resampler; if(outRate && outRate != hData->mIrRate) resampler.emplace().init(hData->mIrRate, outRate); const double rateScale{outRate ? static_cast(outRate) / hData->mIrRate : 1.0}; -- cgit v1.2.3 From 3ec03cadd2b5059e54e5e9b8f4d506b4c6ce727d Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 5 May 2023 06:46:00 -0700 Subject: Use deduction guides instead of helper functions for spans --- al/debug.cpp | 8 ++++---- al/eax/call.h | 2 +- alc/effects/convolution.cpp | 6 +++--- alc/effects/pshifter.cpp | 4 ++-- common/alspan.h | 46 ++++++++++++++++++++------------------------- common/phase_shifter.h | 4 ++-- core/cubic_tables.cpp | 2 +- core/hrtf.cpp | 2 +- core/logging.cpp | 8 ++++---- core/voice.cpp | 4 ++-- utils/makemhr/loaddef.cpp | 2 +- utils/makemhr/loadsofa.cpp | 2 +- utils/makemhr/makemhr.h | 4 ++-- 13 files changed, 44 insertions(+), 50 deletions(-) (limited to 'utils/makemhr/loaddef.cpp') diff --git a/al/debug.cpp b/al/debug.cpp index 3df85d62..a4b66ffb 100644 --- a/al/debug.cpp +++ b/al/debug.cpp @@ -311,7 +311,7 @@ FORCE_ALIGN void AL_APIENTRY alDebugMessageControlEXT(ALenum source, ALenum type static constexpr size_t ElemCount{DebugSourceCount + DebugTypeCount + DebugSeverityCount}; static constexpr auto Values = make_array(); - al::span srcIndices{al::as_span(Values).subspan()}; + al::span srcIndices{al::span{Values}.subspan()}; if(source != AL_DONT_CARE_EXT) { auto dsource = GetDebugSource(source); @@ -320,7 +320,7 @@ FORCE_ALIGN void AL_APIENTRY alDebugMessageControlEXT(ALenum source, ALenum type srcIndices = srcIndices.subspan(al::to_underlying(*dsource), 1); } - al::span typeIndices{al::as_span(Values).subspan()}; + al::span typeIndices{al::span{Values}.subspan()}; if(type != AL_DONT_CARE_EXT) { auto dtype = GetDebugType(type); @@ -329,7 +329,7 @@ FORCE_ALIGN void AL_APIENTRY alDebugMessageControlEXT(ALenum source, ALenum type typeIndices = typeIndices.subspan(al::to_underlying(*dtype), 1); } - al::span svrIndices{al::as_span(Values).subspan()}; + al::span svrIndices{al::span{Values}.subspan()}; if(severity != AL_DONT_CARE_EXT) { auto dseverity = GetDebugSeverity(severity); @@ -344,7 +344,7 @@ FORCE_ALIGN void AL_APIENTRY alDebugMessageControlEXT(ALenum source, ALenum type { const uint filterbase{(1u<(count))) + for(const uint id : al::span{ids, static_cast(count)}) { const uint64_t filter{filterbase | (uint64_t{id} << 32)}; diff --git a/al/eax/call.h b/al/eax/call.h index 5ec33b0f..f2ad529e 100644 --- a/al/eax/call.h +++ b/al/eax/call.h @@ -55,7 +55,7 @@ public: fail_too_small(); const auto count = minz(mPropertyBufferSize / sizeof(TValue), max_count); - return al::as_span(static_cast(mPropertyBuffer), count); + return {static_cast(mPropertyBuffer), count}; } template diff --git a/alc/effects/convolution.cpp b/alc/effects/convolution.cpp index 4ca31246..04b88f66 100644 --- a/alc/effects/convolution.cpp +++ b/alc/effects/convolution.cpp @@ -360,7 +360,7 @@ void ConvolutionState::deviceUpdate(const DeviceBase *device, const BufferStorag done += todo; std::fill(iter, fftbuffer.end(), std::complex{}); - forward_fft(al::as_span(fftbuffer)); + forward_fft(al::span{fftbuffer}); filteriter = std::copy_n(fftbuffer.cbegin(), m, filteriter); } } @@ -562,7 +562,7 @@ void ConvolutionState::process(const size_t samplesToDo, */ auto fftiter = std::copy_n(mInput.cbegin(), ConvolveUpdateSamples, mFftBuffer.begin()); std::fill(fftiter, mFftBuffer.end(), complex_f{}); - forward_fft(al::as_span(mFftBuffer)); + forward_fft(al::span{mFftBuffer}); std::copy_n(mFftBuffer.cbegin(), m, &mComplexData[curseg*m]); @@ -598,7 +598,7 @@ void ConvolutionState::process(const size_t samplesToDo, * second-half samples (and this output's second half is * subsequently saved for next time). */ - inverse_fft(al::as_span(mFftBuffer)); + inverse_fft(al::span{mFftBuffer}); /* The iFFT'd response is scaled up by the number of bins, so apply * the inverse to normalize the output. diff --git a/alc/effects/pshifter.cpp b/alc/effects/pshifter.cpp index 426a2264..3cec1df9 100644 --- a/alc/effects/pshifter.cpp +++ b/alc/effects/pshifter.cpp @@ -186,7 +186,7 @@ void PshifterState::process(const size_t samplesToDo, mFftBuffer[k] = mFIFO[src] * gWindow.mData[k]; for(size_t src{0u}, k{StftSize-mPos};src < mPos;++src,++k) mFftBuffer[k] = mFIFO[src] * gWindow.mData[k]; - forward_fft(al::as_span(mFftBuffer)); + forward_fft(al::span{mFftBuffer}); /* Analyze the obtained data. Since the real FFT is symmetric, only * StftHalfSize+1 samples are needed. @@ -274,7 +274,7 @@ void PshifterState::process(const size_t samplesToDo, /* Apply an inverse FFT to get the time-domain signal, and accumulate * for the output with windowing. */ - inverse_fft(al::as_span(mFftBuffer)); + inverse_fft(al::span{mFftBuffer}); static constexpr float scale{3.0f / OversampleFactor / StftSize}; for(size_t dst{mPos}, k{0u};dst < StftSize;++dst,++k) diff --git a/common/alspan.h b/common/alspan.h index 42b3e057..f75bc84f 100644 --- a/common/alspan.h +++ b/common/alspan.h @@ -39,12 +39,15 @@ namespace detail_ { std::void_t())),decltype(std::data(std::declval()))>> = true; + template + constexpr bool is_valid_container_type = !is_span_v && !is_std_array_v + && !std::is_array::value && has_size_and_data; + template constexpr bool is_array_compatible = std::is_convertible::value; template - constexpr bool is_valid_container = !is_span_v && !is_std_array_v - && !std::is_array::value && has_size_and_data + constexpr bool is_valid_container = is_valid_container_type && is_array_compatible()))>,T>; } // namespace detail_ @@ -297,30 +300,21 @@ constexpr inline auto span::subspan(size_t offset, size_t count) const span{mData+offset, mData+offset+count}; } -/* Helpers to deal with the lack of user-defined deduction guides (C++17). */ -template -constexpr auto as_span(T ptr, U count_or_end) -{ - using value_type = typename std::pointer_traits::element_type; - return span{ptr, count_or_end}; -} -template -constexpr auto as_span(T (&arr)[N]) noexcept { return span{std::data(arr), std::size(arr)}; } -template -constexpr auto as_span(std::array &arr) noexcept -{ return span{std::data(arr), std::size(arr)}; } -template -constexpr auto as_span(const std::array &arr) noexcept -{ return span,N>{std::data(arr), std::size(arr)}; } -template && !detail_::is_std_array_v - && !std::is_array::value && detail_::has_size_and_data)> -constexpr auto as_span(U&& cont) -{ - using value_type = std::remove_pointer_t()))>; - return span{std::data(cont), std::size(cont)}; -} -template -constexpr auto as_span(span span_) noexcept { return span_; } + +template +span(T, EndOrSize) -> span())>>; + +template +span(T (&)[N]) -> span; + +template +span(std::array&) -> span; + +template +span(const std::array&) -> span; + +template)> +span(C&&) -> span()))>>; #undef REQUIRES diff --git a/common/phase_shifter.h b/common/phase_shifter.h index 0d4166bc..061e9176 100644 --- a/common/phase_shifter.h +++ b/common/phase_shifter.h @@ -53,12 +53,12 @@ struct PhaseShifterT { std::fill_n(fftBuffer.get(), fft_size, complex_d{}); fftBuffer[half_size] = 1.0; - forward_fft(al::as_span(fftBuffer.get(), fft_size)); + forward_fft(al::span{fftBuffer.get(), fft_size}); for(size_t i{0};i < half_size+1;++i) fftBuffer[i] = complex_d{-fftBuffer[i].imag(), fftBuffer[i].real()}; for(size_t i{half_size+1};i < fft_size;++i) fftBuffer[i] = std::conj(fftBuffer[fft_size - i]); - inverse_fft(al::as_span(fftBuffer.get(), fft_size)); + inverse_fft(al::span{fftBuffer.get(), fft_size}); auto fftiter = fftBuffer.get() + half_size + (FilterSize/2 - 1); for(float &coeff : mCoeffs) diff --git a/core/cubic_tables.cpp b/core/cubic_tables.cpp index 73ec6b3f..66958735 100644 --- a/core/cubic_tables.cpp +++ b/core/cubic_tables.cpp @@ -49,7 +49,7 @@ struct SplineFilterArray { mTable[pi].mDeltas[3] = -mTable[pi].mCoeffs[3]; } - constexpr auto getTable() const noexcept { return al::as_span(mTable); } + constexpr auto& getTable() const noexcept { return mTable; } }; constexpr SplineFilterArray SplineFilter{}; diff --git a/core/hrtf.cpp b/core/hrtf.cpp index 1d9bc368..607e3d3d 100644 --- a/core/hrtf.cpp +++ b/core/hrtf.cpp @@ -425,7 +425,7 @@ std::unique_ptr CreateHrtfStore(uint rate, uint8_t irSize, std::uninitialized_copy_n(delays, irCount, delays_); /* Finally, assign the storage pointers. */ - Hrtf->mFields = al::as_span(field_, fields.size()); + Hrtf->mFields = {field_, fields.size()}; Hrtf->mElev = elev_; Hrtf->mCoeffs = coeffs_; Hrtf->mDelays = delays_; diff --git a/core/logging.cpp b/core/logging.cpp index 34a95e5a..8e0116ea 100644 --- a/core/logging.cpp +++ b/core/logging.cpp @@ -25,13 +25,13 @@ void al_print(LogLevel level, FILE *logfile, const char *fmt, ...) * that includes the null terminator, which we want to exclude from the * span. */ - auto prefix = al::as_span("[ALSOFT] (--) ").first<14>(); + auto prefix = al::span{"[ALSOFT] (--) "}.first<14>(); switch(level) { case LogLevel::Disable: break; - case LogLevel::Error: prefix = al::as_span("[ALSOFT] (EE) ").first<14>(); break; - case LogLevel::Warning: prefix = al::as_span("[ALSOFT] (WW) ").first<14>(); break; - case LogLevel::Trace: prefix = al::as_span("[ALSOFT] (II) ").first<14>(); break; + case LogLevel::Error: prefix = al::span{"[ALSOFT] (EE) "}.first<14>(); break; + case LogLevel::Warning: prefix = al::span{"[ALSOFT] (WW) "}.first<14>(); break; + case LogLevel::Trace: prefix = al::span{"[ALSOFT] (II) "}.first<14>(); break; } al::vector dynmsg; diff --git a/core/voice.cpp b/core/voice.cpp index db6b6d27..478ea81f 100644 --- a/core/voice.cpp +++ b/core/voice.cpp @@ -389,7 +389,7 @@ inline void LoadSamples(float *RESTRICT dstSamples, const std::byte sampleHistory[1] = int(input[2*srcChan + 0]) | (int(input[2*srcChan + 1])<<8); input += srcStep*2; - const auto coeffs = al::as_span(MSADPCMAdaptionCoeff[blockpred]); + const al::span coeffs{MSADPCMAdaptionCoeff[blockpred]}; delta = (delta^0x8000) - 32768; sampleHistory[0] = (sampleHistory[0]^0x8000) - 32768; sampleHistory[1] = (sampleHistory[1]^0x8000) - 32768; @@ -798,7 +798,7 @@ void Voice::mix(const State vstate, ContextBase *Context, const nanoseconds devi using ResBufType = decltype(DeviceBase::mResampleData); static constexpr uint srcSizeMax{static_cast(ResBufType{}.size()-MaxResamplerEdge)}; - const auto prevSamples = al::as_span(mPrevSamples[chan]); + const al::span prevSamples{mPrevSamples[chan]}; const auto resampleBuffer = std::copy(prevSamples.cbegin(), prevSamples.cend(), Device->mResampleData.begin()) - MaxResamplerEdge; int intPos{DataPosInt}; diff --git a/utils/makemhr/loaddef.cpp b/utils/makemhr/loaddef.cpp index 84fbb48b..c8a98511 100644 --- a/utils/makemhr/loaddef.cpp +++ b/utils/makemhr/loaddef.cpp @@ -1450,7 +1450,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::as_span(azCounts).first(); + const auto azs = al::span{azCounts}.first(); if(!PrepareHrirData({distances, fdCount}, evCounts, azs, hData)) { fprintf(stderr, "Error: Out of memory.\n"); diff --git a/utils/makemhr/loadsofa.cpp b/utils/makemhr/loadsofa.cpp index 9e661839..9bcfc38d 100644 --- a/utils/makemhr/loadsofa.cpp +++ b/utils/makemhr/loadsofa.cpp @@ -87,7 +87,7 @@ static bool PrepareLayout(const uint m, const float *xyzs, HrirDataT *hData) ++fi; } fprintf(stdout, "Using %u of %u IRs.\n", ir_total, m); - const auto azs = al::as_span(azCounts).first(); + const auto azs = al::span{azCounts}.first(); return PrepareHrirData({distances, fi}, evCounts, azs, hData); } diff --git a/utils/makemhr/makemhr.h b/utils/makemhr/makemhr.h index 13b5b2d1..aa18134d 100644 --- a/utils/makemhr/makemhr.h +++ b/utils/makemhr/makemhr.h @@ -113,12 +113,12 @@ void MagnitudeResponse(const uint n, const complex_d *in, double *out); // Performs a forward FFT. inline void FftForward(const uint n, complex_d *inout) -{ forward_fft(al::as_span(inout, n)); } +{ forward_fft(al::span{inout, n}); } // Performs an inverse FFT. inline void FftInverse(const uint n, complex_d *inout) { - inverse_fft(al::as_span(inout, n)); + inverse_fft(al::span{inout, n}); double f{1.0 / n}; for(uint i{0};i < n;i++) inout[i] *= f; -- cgit v1.2.3