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.

196 lines
6.0 KiB

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