You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

227 lines
7.2 KiB

  1. From 769cd0ee9f0cf8ceb026aa751b5d4a390bb5dbdc Mon Sep 17 00:00:00 2001
  2. From: Rosen Penev <rosenp@gmail.com>
  3. Date: Sun, 2 Feb 2020 21:21:57 -0800
  4. Subject: [PATCH] treewide: use boost::lround when std::round is unavailable
  5. This is the case with uClibc-ng currently.
  6. Signed-off-by: Rosen Penev <rosenp@gmail.com>
  7. ---
  8. src/Stats.cxx | 4 +--
  9. src/command/PlayerCommands.cxx | 5 ++-
  10. src/decoder/plugins/FaadDecoderPlugin.cxx | 3 +-
  11. src/mixer/plugins/WinmmMixerPlugin.cxx | 2 +-
  12. src/output/plugins/HaikuOutputPlugin.cxx | 3 +-
  13. src/pcm/PcmMix.cxx | 5 ++-
  14. src/player/CrossFade.cxx | 5 ++-
  15. src/util/Math.hxx | 41 +++++++++++++++++++++++
  16. 8 files changed, 52 insertions(+), 16 deletions(-)
  17. create mode 100644 src/util/Math.hxx
  18. diff --git a/src/Stats.cxx b/src/Stats.cxx
  19. index 2208312d7..7467a3a17 100644
  20. --- a/src/Stats.cxx
  21. +++ b/src/Stats.cxx
  22. @@ -29,9 +29,9 @@
  23. #include "system/Clock.hxx"
  24. #include "Log.hxx"
  25. #include "time/ChronoUtil.hxx"
  26. +#include "util/Math.hxx"
  27. #include <chrono>
  28. -#include <cmath>
  29. #ifndef _WIN32
  30. /**
  31. @@ -121,7 +121,7 @@ stats_print(Response &r, const Partition &partition)
  32. #else
  33. (unsigned)std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now() - start_time).count(),
  34. #endif
  35. - std::lround(partition.pc.GetTotalPlayTime().count()));
  36. + lround(partition.pc.GetTotalPlayTime().count()));
  37. #ifdef ENABLE_DATABASE
  38. const Database *db = partition.instance.GetDatabase();
  39. diff --git a/src/command/PlayerCommands.cxx b/src/command/PlayerCommands.cxx
  40. index 7f3b4f296..4acb8f2ad 100644
  41. --- a/src/command/PlayerCommands.cxx
  42. +++ b/src/command/PlayerCommands.cxx
  43. @@ -34,13 +34,12 @@
  44. #include "util/StringBuffer.hxx"
  45. #include "util/ScopeExit.hxx"
  46. #include "util/Exception.hxx"
  47. +#include "util/Math.hxx"
  48. #ifdef ENABLE_DATABASE
  49. #include "db/update/Service.hxx"
  50. #endif
  51. -#include <cmath>
  52. -
  53. #define COMMAND_STATUS_STATE "state"
  54. #define COMMAND_STATUS_REPEAT "repeat"
  55. #define COMMAND_STATUS_SINGLE "single"
  56. @@ -154,7 +153,7 @@ handle_status(Client &client, gcc_unused Request args, Response &r)
  57. if (pc.GetCrossFade() > FloatDuration::zero())
  58. r.Format(COMMAND_STATUS_CROSSFADE ": %lu\n",
  59. - std::lround(pc.GetCrossFade().count()));
  60. + lround(pc.GetCrossFade().count()));
  61. if (pc.GetMixRampDelay() > FloatDuration::zero())
  62. r.Format(COMMAND_STATUS_MIXRAMPDELAY ": %f\n",
  63. diff --git a/src/decoder/plugins/FaadDecoderPlugin.cxx b/src/decoder/plugins/FaadDecoderPlugin.cxx
  64. index 983103e0e..e1c9576d3 100644
  65. --- a/src/decoder/plugins/FaadDecoderPlugin.cxx
  66. +++ b/src/decoder/plugins/FaadDecoderPlugin.cxx
  67. @@ -26,11 +26,11 @@
  68. #include "util/ScopeExit.hxx"
  69. #include "util/ConstBuffer.hxx"
  70. #include "util/Domain.hxx"
  71. +#include "util/Math.hxx"
  72. #include "Log.hxx"
  73. #include <neaacdec.h>
  74. -#include <cmath>
  75. #include <exception>
  76. #include <assert.h>
  77. diff --git a/src/mixer/plugins/WinmmMixerPlugin.cxx b/src/mixer/plugins/WinmmMixerPlugin.cxx
  78. index 9661d6551..905e650ef 100644
  79. --- a/src/mixer/plugins/WinmmMixerPlugin.cxx
  80. +++ b/src/mixer/plugins/WinmmMixerPlugin.cxx
  81. @@ -20,13 +20,13 @@
  82. #include "mixer/MixerInternal.hxx"
  83. #include "output/OutputAPI.hxx"
  84. #include "output/plugins/WinmmOutputPlugin.hxx"
  85. +#include "util/Math.hxx"
  86. #include <mmsystem.h>
  87. #include <stdexcept>
  88. #include <assert.h>
  89. -#include <math.h>
  90. #include <windows.h>
  91. class WinmmMixer final : public Mixer {
  92. diff --git a/src/output/plugins/HaikuOutputPlugin.cxx b/src/output/plugins/HaikuOutputPlugin.cxx
  93. index 952fb0c2f..01240aca9 100644
  94. --- a/src/output/plugins/HaikuOutputPlugin.cxx
  95. +++ b/src/output/plugins/HaikuOutputPlugin.cxx
  96. @@ -22,6 +22,7 @@
  97. #include "../OutputAPI.hxx"
  98. #include "mixer/MixerList.hxx"
  99. #include "util/Domain.hxx"
  100. +#include "util/Math.hxx"
  101. #include "system/Error.hxx"
  102. #include "Log.hxx"
  103. @@ -37,8 +38,6 @@
  104. #include <StringList.h>
  105. #include <SoundPlayer.h>
  106. -#include <cmath>
  107. -
  108. #include <string.h>
  109. #define UTF8_PLAY "\xE2\x96\xB6"
  110. diff --git a/src/pcm/PcmMix.cxx b/src/pcm/PcmMix.cxx
  111. index 17e34b005..59179f54e 100644
  112. --- a/src/pcm/PcmMix.cxx
  113. +++ b/src/pcm/PcmMix.cxx
  114. @@ -22,11 +22,10 @@
  115. #include "Clamp.hxx"
  116. #include "Traits.hxx"
  117. #include "util/Clamp.hxx"
  118. +#include "util/Math.hxx"
  119. #include "PcmDither.cxx" // including the .cxx file to get inlined templates
  120. -#include <cmath>
  121. -
  122. #include <assert.h>
  123. template<SampleFormat F, class Traits=SampleTraits<F>>
  124. @@ -225,7 +224,7 @@ pcm_mix(PcmDither &dither, void *buffer1, const void *buffer2, size_t size,
  125. s = sin(M_PI_2 * portion1);
  126. s *= s;
  127. - int vol1 = std::lround(s * PCM_VOLUME_1S);
  128. + int vol1 = lround(s * PCM_VOLUME_1S);
  129. vol1 = Clamp<int>(vol1, 0, PCM_VOLUME_1S);
  130. return pcm_add_vol(dither, buffer1, buffer2, size,
  131. diff --git a/src/player/CrossFade.cxx b/src/player/CrossFade.cxx
  132. index ce86d3f0a..8a91516f1 100644
  133. --- a/src/player/CrossFade.cxx
  134. +++ b/src/player/CrossFade.cxx
  135. @@ -23,10 +23,9 @@
  136. #include "AudioFormat.hxx"
  137. #include "util/NumberParser.hxx"
  138. #include "util/Domain.hxx"
  139. +#include "util/Math.hxx"
  140. #include "Log.hxx"
  141. -#include <cmath>
  142. -
  143. #include <assert.h>
  144. static constexpr Domain cross_fade_domain("cross_fade");
  145. @@ -112,7 +111,7 @@ CrossFadeSettings::Calculate(SignedSongTime total_time,
  146. if (mixramp_delay <= FloatDuration::zero() ||
  147. !mixramp_start || !mixramp_prev_end) {
  148. - chunks = std::lround(duration / chunk_duration);
  149. + chunks = lround(duration / chunk_duration);
  150. } else {
  151. /* Calculate mixramp overlap. */
  152. const auto mixramp_overlap_current =
  153. diff --git a/src/util/Math.hxx b/src/util/Math.hxx
  154. new file mode 100644
  155. index 000000000..bd856f5a9
  156. --- /dev/null
  157. +++ b/src/util/Math.hxx
  158. @@ -0,0 +1,41 @@
  159. +/*
  160. + * Copyright (C) 2018 Max Kellermann <max.kellermann@gmail.com>
  161. + *
  162. + * Redistribution and use in source and binary forms, with or without
  163. + * modification, are permitted provided that the following conditions
  164. + * are met:
  165. + *
  166. + * - Redistributions of source code must retain the above copyright
  167. + * notice, this list of conditions and the following disclaimer.
  168. + *
  169. + * - Redistributions in binary form must reproduce the above copyright
  170. + * notice, this list of conditions and the following disclaimer in the
  171. + * documentation and/or other materials provided with the
  172. + * distribution.
  173. + *
  174. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  175. + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  176. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  177. + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  178. + * FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  179. + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  180. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  181. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  182. + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  183. + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  184. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  185. + * OF THE POSSIBILITY OF SUCH DAMAGE.
  186. + */
  187. +
  188. +#ifndef MATH_HXX
  189. +#define MATH_HXX
  190. +
  191. +#ifdef __UCLIBC__
  192. +#include <boost/math/special_functions/round.hpp>
  193. +using boost::math::lround;
  194. +#else
  195. +#include <cmath>
  196. +using std::lround;
  197. +#endif
  198. +
  199. +#endif