diff options
author | Sven Gothel <sgothel@jausoft.com> | 2023-11-28 12:51:46 +0100 |
---|---|---|
committer | Sven Gothel <sgothel@jausoft.com> | 2023-11-28 12:51:46 +0100 |
commit | 1aaf4f070011490bcece50394b9b32dfa593fd9e (patch) | |
tree | 17d68284e401a35eea3d3a574d986d446a60763a /utils | |
parent | 6e7cee4fa9a8af03f28ca26cd89f8357390dfc90 (diff) | |
parent | 571b546f35eead77ce109f8d4dd6c3de3199d573 (diff) |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'utils')
-rw-r--r-- | utils/makemhr/loaddef.cpp | 7 | ||||
-rw-r--r-- | utils/makemhr/loadsofa.cpp | 6 | ||||
-rw-r--r-- | utils/makemhr/makemhr.cpp | 5 | ||||
-rw-r--r-- | utils/makemhr/makemhr.h | 4 | ||||
-rw-r--r-- | utils/openal-info.c | 64 | ||||
-rw-r--r-- | utils/uhjdecoder.cpp | 53 | ||||
-rw-r--r-- | utils/uhjencoder.cpp | 10 |
7 files changed, 101 insertions, 48 deletions
diff --git a/utils/makemhr/loaddef.cpp b/utils/makemhr/loaddef.cpp index e8092363..c8a98511 100644 --- a/utils/makemhr/loaddef.cpp +++ b/utils/makemhr/loaddef.cpp @@ -33,11 +33,10 @@ #include <iterator> #include <limits> #include <memory> -#include <cstdarg> +#include <optional> #include <vector> #include "alfstream.h" -#include "aloptional.h" #include "alspan.h" #include "alstring.h" #include "makemhr.h" @@ -1451,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<MAX_FD_COUNT>(); + const auto azs = al::span{azCounts}.first<MAX_FD_COUNT>(); if(!PrepareHrirData({distances, fdCount}, evCounts, azs, hData)) { fprintf(stderr, "Error: Out of memory.\n"); @@ -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<PPhaseResampler> resampler; + std::optional<PPhaseResampler> resampler; if(outRate && outRate != hData->mIrRate) resampler.emplace().init(hData->mIrRate, outRate); const double rateScale{outRate ? static_cast<double>(outRate) / hData->mIrRate : 1.0}; diff --git a/utils/makemhr/loadsofa.cpp b/utils/makemhr/loadsofa.cpp index dcb0a35e..9bcfc38d 100644 --- a/utils/makemhr/loadsofa.cpp +++ b/utils/makemhr/loadsofa.cpp @@ -33,11 +33,11 @@ #include <iterator> #include <memory> #include <numeric> +#include <optional> #include <string> #include <thread> #include <vector> -#include "aloptional.h" #include "alspan.h" #include "makemhr.h" #include "polyphase_resampler.h" @@ -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<MAX_FD_COUNT>(); + const auto azs = al::span{azCounts}.first<MAX_FD_COUNT>(); return PrepareHrirData({distances, fi}, evCounts, azs, hData); } @@ -265,7 +265,7 @@ static bool LoadResponses(MYSOFA_HRTF *sofaHrtf, HrirDataT *hData, const DelayTy double *hrirs = hData->mHrirsBase.data(); std::unique_ptr<double[]> restmp; - al::optional<PPhaseResampler> resampler; + std::optional<PPhaseResampler> resampler; if(outRate && outRate != hData->mIrRate) { resampler.emplace().init(hData->mIrRate, outRate); diff --git a/utils/makemhr/makemhr.cpp b/utils/makemhr/makemhr.cpp index ae301dc3..98e1b73f 100644 --- a/utils/makemhr/makemhr.cpp +++ b/utils/makemhr/makemhr.cpp @@ -297,10 +297,7 @@ static void MinimumPhase(const uint n, double *mags, complex_d *out) // Remove any DC offset the filter has. mags[0] = EPSILON; for(i = 0;i < n;i++) - { - auto a = std::exp(complex_d{0.0, out[i].imag()}); - out[i] = a * mags[i]; - } + out[i] = std::polar(mags[i], out[i].imag()); } 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; diff --git a/utils/openal-info.c b/utils/openal-info.c index b646693c..8ef6ebde 100644 --- a/utils/openal-info.c +++ b/utils/openal-info.c @@ -167,11 +167,11 @@ static void printHRTFInfo(ALCdevice *device) alcGetIntegerv(device, ALC_NUM_HRTF_SPECIFIERS_SOFT, 1, &num_hrtfs); if(!num_hrtfs) - printf("No HRTFs found\n"); + printf("No HRTF profiles found\n"); else { ALCint i; - printf("Available HRTFs:\n"); + printf("Available HRTF profiles:\n"); for(i = 0;i < num_hrtfs;++i) { const ALCchar *name = alcGetStringiSOFT(device, ALC_HRTF_SPECIFIER_SOFT, i); @@ -213,6 +213,65 @@ static void printModeInfo(ALCdevice *device) alcGetIntegerv(device, ALC_FREQUENCY, 1, &srate); if(checkALCErrors(device) == ALC_NO_ERROR) printf("Device sample rate: %dhz\n", srate); + + if(alcIsExtensionPresent(device, "ALC_SOFT_HRTF")) + { + const ALCchar *hrtfname = "(disabled)"; + ALCint isenabled = 0; + + alcGetIntegerv(device, ALC_HRTF_SOFT, 1, &isenabled); + checkALCErrors(device); + if(isenabled == ALC_TRUE) + { + hrtfname = alcGetString(device, ALC_HRTF_SPECIFIER_SOFT); + checkALCErrors(device); + } + printf("Device HRTF profile: %s\n", hrtfname ? hrtfname : "<null>"); + } +} + +static void printALCSOFTSystemEventIsSupportedResult(LPALCEVENTISSUPPORTEDSOFT alcEventIsSupportedSOFT, ALCenum eventType, ALCenum deviceType) +{ + if (alcEventIsSupportedSOFT == NULL) + { + printf("ERROR (alcEventIsSupportedSOFT missing)\n"); + return; + } + ALCenum supported = alcEventIsSupportedSOFT(eventType, deviceType); + if (supported == ALC_EVENT_SUPPORTED_SOFT) + { + printf("SUPPORTED\n"); + } + else if (supported == ALC_EVENT_NOT_SUPPORTED_SOFT) + { + printf("NOT SUPPORTED\n"); + } + else + { + printf("UNEXPECTED VALUE : %d\n", supported); + } +} + +static void printALC_SOFT_system_event(void) +{ + if(alcIsExtensionPresent(NULL, "ALC_SOFT_system_events")) + { + LPALCEVENTISSUPPORTEDSOFT alcEventIsSupportedSOFT; + alcEventIsSupportedSOFT = FUNCTION_CAST(LPALCEVENTISSUPPORTEDSOFT, alGetProcAddress("alcEventIsSupportedSOFT")); + printf("Available events:\n"); + printf(" ALC_EVENT_TYPE_DEFAULT_DEVICE_CHANGED_SOFT for ALC_PLAYBACK_DEVICE_SOFT - "); + printALCSOFTSystemEventIsSupportedResult(alcEventIsSupportedSOFT, ALC_EVENT_TYPE_DEFAULT_DEVICE_CHANGED_SOFT, ALC_PLAYBACK_DEVICE_SOFT); + printf(" ALC_EVENT_TYPE_DEFAULT_DEVICE_CHANGED_SOFT for ALC_CAPTURE_DEVICE_SOFT - "); + printALCSOFTSystemEventIsSupportedResult(alcEventIsSupportedSOFT, ALC_EVENT_TYPE_DEFAULT_DEVICE_CHANGED_SOFT, ALC_CAPTURE_DEVICE_SOFT); + printf(" ALC_EVENT_TYPE_DEVICE_ADDED_SOFT for ALC_PLAYBACK_DEVICE_SOFT - "); + printALCSOFTSystemEventIsSupportedResult(alcEventIsSupportedSOFT, ALC_EVENT_TYPE_DEVICE_ADDED_SOFT, ALC_PLAYBACK_DEVICE_SOFT); + printf(" ALC_EVENT_TYPE_DEVICE_ADDED_SOFT for ALC_CAPTURE_DEVICE_SOFT - "); + printALCSOFTSystemEventIsSupportedResult(alcEventIsSupportedSOFT, ALC_EVENT_TYPE_DEVICE_ADDED_SOFT, ALC_CAPTURE_DEVICE_SOFT); + printf(" ALC_EVENT_TYPE_DEVICE_REMOVED_SOFT for ALC_PLAYBACK_DEVICE_SOFT - "); + printALCSOFTSystemEventIsSupportedResult(alcEventIsSupportedSOFT, ALC_EVENT_TYPE_DEVICE_REMOVED_SOFT, ALC_PLAYBACK_DEVICE_SOFT); + printf(" ALC_EVENT_TYPE_DEVICE_REMOVED_SOFT for ALC_CAPTURE_DEVICE_SOFT - "); + printALCSOFTSystemEventIsSupportedResult(alcEventIsSupportedSOFT, ALC_EVENT_TYPE_DEVICE_REMOVED_SOFT, ALC_CAPTURE_DEVICE_SOFT); + } } static void printALInfo(void) @@ -420,6 +479,7 @@ int main(int argc, char *argv[]) } printALCInfo(device); printHRTFInfo(device); + printALC_SOFT_system_event(); context = alcCreateContext(device, NULL); if(!context || alcMakeContextCurrent(context) == ALC_FALSE) diff --git a/utils/uhjdecoder.cpp b/utils/uhjdecoder.cpp index 6d992e30..c7efa376 100644 --- a/utils/uhjdecoder.cpp +++ b/utils/uhjdecoder.cpp @@ -26,15 +26,14 @@ #include <array> #include <complex> +#include <cstddef> #include <cstring> #include <memory> -#include <stddef.h> #include <string> #include <utility> #include <vector> #include "albit.h" -#include "albyte.h" #include "alcomplex.h" #include "almalloc.h" #include "alnumbers.h" @@ -64,7 +63,7 @@ using ushort = unsigned short; using uint = unsigned int; using complex_d = std::complex<double>; -using byte4 = std::array<al::byte,4>; +using byte4 = std::array<std::byte,4>; constexpr ubyte SUBTYPE_BFORMAT_FLOAT[]{ @@ -113,7 +112,7 @@ using FloatBufferSpan = al::span<float,BufferLineSize>; struct UhjDecoder { - constexpr static size_t sFilterDelay{1024}; + constexpr static std::size_t sFilterDelay{1024}; alignas(16) std::array<float,BufferLineSize+sFilterDelay> mS{}; alignas(16) std::array<float,BufferLineSize+sFilterDelay> mD{}; @@ -126,10 +125,10 @@ struct UhjDecoder { alignas(16) std::array<float,BufferLineSize + sFilterDelay*2> mTemp{}; - void decode(const float *RESTRICT InSamples, const size_t InChannels, - const al::span<FloatBufferLine> OutSamples, const size_t SamplesToDo); + void decode(const float *RESTRICT InSamples, const std::size_t InChannels, + const al::span<FloatBufferLine> OutSamples, const std::size_t SamplesToDo); void decode2(const float *RESTRICT InSamples, const al::span<FloatBufferLine> OutSamples, - const size_t SamplesToDo); + const std::size_t SamplesToDo); DEF_NEWDEL(UhjDecoder) }; @@ -210,8 +209,8 @@ const PhaseShifterT<UhjDecoder::sFilterDelay*2> PShift{}; * * Not halving produces a result matching the original input. */ -void UhjDecoder::decode(const float *RESTRICT InSamples, const size_t InChannels, - const al::span<FloatBufferLine> OutSamples, const size_t SamplesToDo) +void UhjDecoder::decode(const float *RESTRICT InSamples, const std::size_t InChannels, + const al::span<FloatBufferLine> OutSamples, const std::size_t SamplesToDo) { ASSUME(SamplesToDo > 0); @@ -224,23 +223,23 @@ void UhjDecoder::decode(const float *RESTRICT InSamples, const size_t InChannels */ /* S = Left + Right */ - for(size_t i{0};i < SamplesToDo;++i) + for(std::size_t i{0};i < SamplesToDo;++i) mS[sFilterDelay+i] = InSamples[i*InChannels + 0] + InSamples[i*InChannels + 1]; /* D = Left - Right */ - for(size_t i{0};i < SamplesToDo;++i) + for(std::size_t i{0};i < SamplesToDo;++i) mD[sFilterDelay+i] = InSamples[i*InChannels + 0] - InSamples[i*InChannels + 1]; if(InChannels > 2) { /* T */ - for(size_t i{0};i < SamplesToDo;++i) + for(std::size_t i{0};i < SamplesToDo;++i) mT[sFilterDelay+i] = InSamples[i*InChannels + 2]; } if(InChannels > 3) { /* Q */ - for(size_t i{0};i < SamplesToDo;++i) + for(std::size_t i{0};i < SamplesToDo;++i) mQ[sFilterDelay+i] = InSamples[i*InChannels + 3]; } @@ -251,7 +250,7 @@ void UhjDecoder::decode(const float *RESTRICT InSamples, const size_t InChannels std::copy_n(mTemp.cbegin()+SamplesToDo, mDTHistory.size(), mDTHistory.begin()); PShift.process({xoutput, SamplesToDo}, mTemp.data()); - for(size_t i{0};i < SamplesToDo;++i) + for(std::size_t i{0};i < SamplesToDo;++i) { /* W = 0.981532*S + 0.197484*j(0.828331*D + 0.767820*T) */ woutput[i] = 0.981532f*mS[i] + 0.197484f*xoutput[i]; @@ -265,7 +264,7 @@ void UhjDecoder::decode(const float *RESTRICT InSamples, const size_t InChannels std::copy_n(mTemp.cbegin()+SamplesToDo, mSHistory.size(), mSHistory.begin()); PShift.process({youtput, SamplesToDo}, mTemp.data()); - for(size_t i{0};i < SamplesToDo;++i) + for(std::size_t i{0};i < SamplesToDo;++i) { /* Y = 0.795968*D - 0.676392*T + j(0.186633*S) */ youtput[i] = 0.795968f*mD[i] - 0.676392f*mT[i] + 0.186633f*youtput[i]; @@ -275,7 +274,7 @@ void UhjDecoder::decode(const float *RESTRICT InSamples, const size_t InChannels { float *zoutput{OutSamples[3].data()}; /* Z = 1.023332*Q */ - for(size_t i{0};i < SamplesToDo;++i) + for(std::size_t i{0};i < SamplesToDo;++i) zoutput[i] = 1.023332f*mQ[i]; } @@ -305,7 +304,7 @@ void UhjDecoder::decode(const float *RESTRICT InSamples, const size_t InChannels * halving here is merely a -6dB reduction in output, but it's still incorrect. */ void UhjDecoder::decode2(const float *RESTRICT InSamples, - const al::span<FloatBufferLine> OutSamples, const size_t SamplesToDo) + const al::span<FloatBufferLine> OutSamples, const std::size_t SamplesToDo) { ASSUME(SamplesToDo > 0); @@ -314,11 +313,11 @@ void UhjDecoder::decode2(const float *RESTRICT InSamples, float *youtput{OutSamples[2].data()}; /* S = Left + Right */ - for(size_t i{0};i < SamplesToDo;++i) + for(std::size_t i{0};i < SamplesToDo;++i) mS[sFilterDelay+i] = InSamples[i*2 + 0] + InSamples[i*2 + 1]; /* D = Left - Right */ - for(size_t i{0};i < SamplesToDo;++i) + for(std::size_t i{0};i < SamplesToDo;++i) mD[sFilterDelay+i] = InSamples[i*2 + 0] - InSamples[i*2 + 1]; /* Precompute j*D and store in xoutput. */ @@ -327,7 +326,7 @@ void UhjDecoder::decode2(const float *RESTRICT InSamples, std::copy_n(mTemp.cbegin()+SamplesToDo, mDTHistory.size(), mDTHistory.begin()); PShift.process({xoutput, SamplesToDo}, mTemp.data()); - for(size_t i{0};i < SamplesToDo;++i) + for(std::size_t i{0};i < SamplesToDo;++i) { /* W = 0.981530*S + j*0.163585*D */ woutput[i] = 0.981530f*mS[i] + 0.163585f*xoutput[i]; @@ -341,7 +340,7 @@ void UhjDecoder::decode2(const float *RESTRICT InSamples, std::copy_n(mTemp.cbegin()+SamplesToDo, mSHistory.size(), mSHistory.begin()); PShift.process({youtput, SamplesToDo}, mTemp.data()); - for(size_t i{0};i < SamplesToDo;++i) + for(std::size_t i{0};i < SamplesToDo;++i) { /* Y = 0.762956*D + j*0.384230*S */ youtput[i] = 0.762956f*mD[i] + 0.384230f*youtput[i]; @@ -368,7 +367,7 @@ int main(int argc, char **argv) return 1; } - size_t num_files{0}, num_decoded{0}; + std::size_t num_files{0}, num_decoded{0}; bool use_general{true}; for(int fidx{1};fidx < argc;++fidx) { @@ -473,7 +472,7 @@ int main(int argc, char **argv) * be fed through the decoder after reaching the end of the input file * to ensure none of the original input is lost. */ - size_t LeadIn{UhjDecoder::sFilterDelay}; + std::size_t LeadIn{UhjDecoder::sFilterDelay}; sf_count_t LeadOut{UhjDecoder::sFilterDelay}; while(LeadOut > 0) { @@ -487,7 +486,7 @@ int main(int argc, char **argv) LeadOut -= remaining; } - auto got = static_cast<size_t>(sgot); + 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); else @@ -499,16 +498,16 @@ int main(int argc, char **argv) } got -= LeadIn; - for(size_t i{0};i < got;++i) + for(std::size_t i{0};i < got;++i) { /* Attenuate by -3dB for FuMa output levels. */ constexpr auto inv_sqrt2 = static_cast<float>(1.0/al::numbers::sqrt2); - for(size_t j{0};j < outchans;++j) + for(std::size_t j{0};j < outchans;++j) outmem[i*outchans + j] = f32AsLEBytes(decmem[j][LeadIn+i] * inv_sqrt2); } LeadIn = 0; - size_t wrote{fwrite(outmem.get(), sizeof(byte4)*outchans, got, outfile.get())}; + std::size_t wrote{fwrite(outmem.get(), 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 34698993..154a1155 100644 --- a/utils/uhjencoder.cpp +++ b/utils/uhjencoder.cpp @@ -25,8 +25,8 @@ #include "config.h" #include <array> +#include <cinttypes> #include <cstring> -#include <inttypes.h> #include <memory> #include <stddef.h> #include <string> @@ -325,7 +325,7 @@ int main(int argc, char **argv) return false; for(const int id : a) { - if(std::find(b.begin(), b.end(), id) != b.end()) + if(std::find(b.begin(), b.end(), id) == b.end()) return false; } return true; @@ -502,11 +502,9 @@ int main(int argc, char **argv) got -= LeadIn; for(size_t c{0};c < uhjchans;++c) { - constexpr float max_val{8388607.0f / 8388608.0f}; - auto clamp = [](float v, float mn, float mx) noexcept - { return std::min(std::max(v, mn), mx); }; + static constexpr float max_val{8388607.0f / 8388608.0f}; for(size_t i{0};i < got;++i) - outmem[i*uhjchans + c] = clamp(encmem[c][LeadIn+i], -1.0f, max_val); + outmem[i*uhjchans + c] = std::clamp(encmem[c][LeadIn+i], -1.0f, max_val); } LeadIn = 0; |