/* SPDX-License-Identifier: BSD-3-Clause */ /* SPDX-FileCopyrightText: Olivier Lapicque */ /* SPDX-FileCopyrightText: OpenMPT Project Developers and Contributors */ #pragma once #include "openmpt/all/BuildSettings.hpp" #include "mpt/base/arithmetic_shift.hpp" #include "mpt/base/macros.hpp" #include "mpt/random/random.hpp" #include "openmpt/base/Types.hpp" #include "openmpt/random/ModPlug.hpp" #include "openmpt/soundbase/MixSample.hpp" #include "openmpt/soundbase/MixSampleConvert.hpp" OPENMPT_NAMESPACE_BEGIN struct Dither_ModPlug { public: using prng_type = mpt::rng::modplug_dither; template static prng_type prng_init(Trd &) { return prng_type{0, 0}; } public: template MPT_FORCEINLINE MixSampleInt process(MixSampleInt sample, Trng &rng) { if constexpr(targetbits == 0) { MPT_UNREFERENCED_PARAMETER(rng); return sample; } else if constexpr(targetbits + MixSampleIntTraits::mix_headroom_bits + 1 >= 32) { MPT_UNREFERENCED_PARAMETER(rng); return sample; } else { sample += mpt::rshift_signed(static_cast(mpt::random(rng)), (targetbits + MixSampleIntTraits::mix_headroom_bits + 1)); return sample; } } template MPT_FORCEINLINE MixSampleFloat process(MixSampleFloat sample, Trng &prng) { return mix_sample_cast(process(mix_sample_cast(sample), prng)); } }; OPENMPT_NAMESPACE_END