From 85c27840a303145e887d7d30f0141236c21aafef Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sun, 2 Feb 2020 21:21:57 -0800 Subject: [PATCH] treewide: use boost::lround when std::round is unavailable This is the case with uClibc-ng currently. Signed-off-by: Rosen Penev (cherry picked from commit 769cd0ee9f0cf8ceb026aa751b5d4a390bb5dbdc) (changed define to match master) --- src/Stats.cxx | 4 +-- src/command/PlayerCommands.cxx | 5 ++- src/decoder/plugins/FaadDecoderPlugin.cxx | 2 +- src/mixer/plugins/WinmmMixerPlugin.cxx | 2 +- src/output/plugins/HaikuOutputPlugin.cxx | 3 +- src/pcm/PcmMix.cxx | 5 ++- src/player/CrossFade.cxx | 5 ++- src/util/Math.hxx | 41 +++++++++++++++++++++++ 8 files changed, 52 insertions(+), 15 deletions(-) create mode 100644 src/util/Math.hxx diff --git a/src/Stats.cxx b/src/Stats.cxx index 2bf4458fc..045ac3b7a 100644 --- a/src/Stats.cxx +++ b/src/Stats.cxx @@ -29,9 +29,9 @@ #include "system/Clock.hxx" #include "Log.hxx" #include "time/ChronoUtil.hxx" +#include "util/Math.hxx" #include -#include #ifndef _WIN32 /** @@ -121,7 +121,7 @@ stats_print(Response &r, const Partition &partition) #else (unsigned)std::chrono::duration_cast(std::chrono::steady_clock::now() - start_time).count(), #endif - std::lround(partition.pc.GetTotalPlayTime().count())); + lround(partition.pc.GetTotalPlayTime().count())); #ifdef ENABLE_DATABASE const Database *db = partition.instance.GetDatabase(); diff --git a/src/command/PlayerCommands.cxx b/src/command/PlayerCommands.cxx index 716f9a221..6a38de830 100644 --- a/src/command/PlayerCommands.cxx +++ b/src/command/PlayerCommands.cxx @@ -34,13 +34,12 @@ #include "util/StringBuffer.hxx" #include "util/ScopeExit.hxx" #include "util/Exception.hxx" +#include "util/Math.hxx" #ifdef ENABLE_DATABASE #include "db/update/Service.hxx" #endif -#include - #define COMMAND_STATUS_STATE "state" #define COMMAND_STATUS_REPEAT "repeat" #define COMMAND_STATUS_SINGLE "single" @@ -154,7 +153,7 @@ handle_status(Client &client, gcc_unused Request args, Response &r) if (pc.GetCrossFade() > FloatDuration::zero()) r.Format(COMMAND_STATUS_CROSSFADE ": %lu\n", - std::lround(pc.GetCrossFade().count())); + lround(pc.GetCrossFade().count())); if (pc.GetMixRampDelay() > FloatDuration::zero()) r.Format(COMMAND_STATUS_MIXRAMPDELAY ": %f\n", diff --git a/src/decoder/plugins/FaadDecoderPlugin.cxx b/src/decoder/plugins/FaadDecoderPlugin.cxx index 418f5f688..2f3d4e991 100644 --- a/src/decoder/plugins/FaadDecoderPlugin.cxx +++ b/src/decoder/plugins/FaadDecoderPlugin.cxx @@ -26,11 +26,11 @@ #include "util/ScopeExit.hxx" #include "util/ConstBuffer.hxx" #include "util/Domain.hxx" +#include "util/Math.hxx" #include "Log.hxx" #include -#include #include #include diff --git a/src/mixer/plugins/WinmmMixerPlugin.cxx b/src/mixer/plugins/WinmmMixerPlugin.cxx index 08e2b11b9..4da01c37e 100644 --- a/src/mixer/plugins/WinmmMixerPlugin.cxx +++ b/src/mixer/plugins/WinmmMixerPlugin.cxx @@ -20,13 +20,13 @@ #include "mixer/MixerInternal.hxx" #include "output/OutputAPI.hxx" #include "output/plugins/WinmmOutputPlugin.hxx" +#include "util/Math.hxx" #include #include #include -#include #include class WinmmMixer final : public Mixer { diff --git a/src/output/plugins/HaikuOutputPlugin.cxx b/src/output/plugins/HaikuOutputPlugin.cxx index 86fa7baf5..0d4f3d361 100644 --- a/src/output/plugins/HaikuOutputPlugin.cxx +++ b/src/output/plugins/HaikuOutputPlugin.cxx @@ -22,6 +22,7 @@ #include "../OutputAPI.hxx" #include "mixer/MixerList.hxx" #include "util/Domain.hxx" +#include "util/Math.hxx" #include "system/Error.hxx" #include "Log.hxx" @@ -37,8 +38,6 @@ #include #include -#include - #include #define UTF8_PLAY "\xE2\x96\xB6" diff --git a/src/pcm/PcmMix.cxx b/src/pcm/PcmMix.cxx index 13f558d5e..bbb26d1c4 100644 --- a/src/pcm/PcmMix.cxx +++ b/src/pcm/PcmMix.cxx @@ -22,11 +22,10 @@ #include "Clamp.hxx" #include "Traits.hxx" #include "util/Clamp.hxx" +#include "util/Math.hxx" #include "PcmDither.cxx" // including the .cxx file to get inlined templates -#include - #include template> @@ -225,7 +224,7 @@ pcm_mix(PcmDither &dither, void *buffer1, const void *buffer2, size_t size, s = sin(M_PI_2 * portion1); s *= s; - int vol1 = std::lround(s * PCM_VOLUME_1S); + int vol1 = lround(s * PCM_VOLUME_1S); vol1 = Clamp(vol1, 0, PCM_VOLUME_1S); return pcm_add_vol(dither, buffer1, buffer2, size, diff --git a/src/player/CrossFade.cxx b/src/player/CrossFade.cxx index 72b3598bb..b31610e66 100644 --- a/src/player/CrossFade.cxx +++ b/src/player/CrossFade.cxx @@ -23,10 +23,9 @@ #include "AudioFormat.hxx" #include "util/NumberParser.hxx" #include "util/Domain.hxx" +#include "util/Math.hxx" #include "Log.hxx" -#include - #include static constexpr Domain cross_fade_domain("cross_fade"); @@ -112,7 +111,7 @@ CrossFadeSettings::Calculate(SignedSongTime total_time, if (mixramp_delay <= FloatDuration::zero() || !mixramp_start || !mixramp_prev_end) { - chunks = std::lround(duration / chunk_duration); + chunks = lround(duration / chunk_duration); } else { /* Calculate mixramp overlap. */ const auto mixramp_overlap_current = diff --git a/src/util/Math.hxx b/src/util/Math.hxx new file mode 100644 index 000000000..9784c0b64 --- /dev/null +++ b/src/util/Math.hxx @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2018 Max Kellermann + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef MATH_HXX +#define MATH_HXX + +#if (defined(__GLIBCPP__) || defined(__GLIBCXX__)) && !defined(_GLIBCXX_USE_C99_MATH) +#include +using boost::math::lround; +#else +#include +using std::lround; +#endif + +#endif