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.

162 lines
4.7 KiB

  1. From 2a8e7c50743ec6a20c7bd9c8e84ccd36d59e69ad Mon Sep 17 00:00:00 2001
  2. From: Rosen Penev <rosenp@gmail.com>
  3. Date: Mon, 3 Feb 2020 15:50:46 -0800
  4. Subject: [PATCH] treewide: get rid of C math function usage
  5. Boost does not seem to offer an overload for lrint.
  6. Signed-off-by: Rosen Penev <rosenp@gmail.com>
  7. ---
  8. src/ReplayGainGlobal.cxx | 2 +-
  9. src/ReplayGainInfo.cxx | 3 +--
  10. src/decoder/Bridge.cxx | 5 +++--
  11. src/decoder/plugins/MpcdecDecoderPlugin.cxx | 3 +--
  12. src/mixer/plugins/AlsaMixerPlugin.cxx | 3 +--
  13. src/mixer/plugins/SoftwareMixerPlugin.cxx | 5 +++--
  14. src/util/Math.hxx | 6 ++++++
  15. 7 files changed, 16 insertions(+), 11 deletions(-)
  16. diff --git a/src/ReplayGainGlobal.cxx b/src/ReplayGainGlobal.cxx
  17. index 741381dcb..01ba8769d 100644
  18. --- a/src/ReplayGainGlobal.cxx
  19. +++ b/src/ReplayGainGlobal.cxx
  20. @@ -21,11 +21,11 @@
  21. #include "ReplayGainConfig.hxx"
  22. #include "config/Param.hxx"
  23. #include "config/Data.hxx"
  24. +#include "util/Math.hxx"
  25. #include "util/RuntimeError.hxx"
  26. #include <assert.h>
  27. #include <stdlib.h>
  28. -#include <math.h>
  29. static float
  30. ParsePreamp(const char *s)
  31. diff --git a/src/ReplayGainInfo.cxx b/src/ReplayGainInfo.cxx
  32. index a0685507a..76713aded 100644
  33. --- a/src/ReplayGainInfo.cxx
  34. +++ b/src/ReplayGainInfo.cxx
  35. @@ -19,8 +19,7 @@
  36. #include "ReplayGainInfo.hxx"
  37. #include "ReplayGainConfig.hxx"
  38. -
  39. -#include <math.h>
  40. +#include "util/Math.hxx"
  41. float
  42. ReplayGainTuple::CalculateScale(const ReplayGainConfig &config) const noexcept
  43. diff --git a/src/decoder/Bridge.cxx b/src/decoder/Bridge.cxx
  44. index 27d1a577a..7f9ffe02d 100644
  45. --- a/src/decoder/Bridge.cxx
  46. +++ b/src/decoder/Bridge.cxx
  47. @@ -31,11 +31,11 @@
  48. #include "Log.hxx"
  49. #include "input/InputStream.hxx"
  50. #include "util/ConstBuffer.hxx"
  51. +#include "util/Math.hxx"
  52. #include "util/StringBuffer.hxx"
  53. #include <assert.h>
  54. #include <string.h>
  55. -#include <math.h>
  56. DecoderBridge::~DecoderBridge()
  57. {
  58. @@ -591,7 +592,7 @@ DecoderBridge::SubmitReplayGain(const ReplayGainInfo *new_replay_gain_info) noex
  59. const auto &tuple = new_replay_gain_info->Get(rgm);
  60. const auto scale =
  61. tuple.CalculateScale(dc.replay_gain_config);
  62. - dc.replay_gain_db = 20.0 * log10f(scale);
  63. + dc.replay_gain_db = 20.0 * std::log10(scale);
  64. }
  65. replay_gain_info = *new_replay_gain_info;
  66. diff --git a/src/decoder/plugins/MpcdecDecoderPlugin.cxx b/src/decoder/plugins/MpcdecDecoderPlugin.cxx
  67. index c19aee75c..4e9ef798e 100644
  68. --- a/src/decoder/plugins/MpcdecDecoderPlugin.cxx
  69. +++ b/src/decoder/plugins/MpcdecDecoderPlugin.cxx
  70. @@ -26,6 +26,7 @@
  71. #include "util/Domain.hxx"
  72. #include "util/Macros.hxx"
  73. #include "util/Clamp.hxx"
  74. +#include "util/Math.hxx"
  75. #include "util/ScopeExit.hxx"
  76. #include "Log.hxx"
  77. @@ -33,8 +34,6 @@
  78. #include <exception>
  79. -#include <math.h>
  80. -
  81. struct mpc_decoder_data {
  82. InputStream &is;
  83. DecoderClient *client;
  84. diff --git a/src/mixer/plugins/AlsaMixerPlugin.cxx b/src/mixer/plugins/AlsaMixerPlugin.cxx
  85. index e3d774194..4b916319b 100644
  86. --- a/src/mixer/plugins/AlsaMixerPlugin.cxx
  87. +++ b/src/mixer/plugins/AlsaMixerPlugin.cxx
  88. @@ -26,6 +26,7 @@
  89. #include "event/Call.hxx"
  90. #include "util/ASCII.hxx"
  91. #include "util/Domain.hxx"
  92. +#include "util/Math.hxx"
  93. #include "util/RuntimeError.hxx"
  94. #include "Log.hxx"
  95. @@ -35,8 +36,6 @@ extern "C" {
  96. #include <alsa/asoundlib.h>
  97. -#include <math.h>
  98. -
  99. #define VOLUME_MIXER_ALSA_DEFAULT "default"
  100. #define VOLUME_MIXER_ALSA_CONTROL_DEFAULT "PCM"
  101. static constexpr unsigned VOLUME_MIXER_ALSA_INDEX_DEFAULT = 0;
  102. diff --git a/src/mixer/plugins/SoftwareMixerPlugin.cxx b/src/mixer/plugins/SoftwareMixerPlugin.cxx
  103. index c394a9628..9c48279f9 100644
  104. --- a/src/mixer/plugins/SoftwareMixerPlugin.cxx
  105. +++ b/src/mixer/plugins/SoftwareMixerPlugin.cxx
  106. @@ -22,8 +22,9 @@
  107. #include "filter/plugins/VolumeFilterPlugin.hxx"
  108. #include "pcm/Volume.hxx"
  109. +#include <cmath>
  110. +
  111. #include <assert.h>
  112. -#include <math.h>
  113. class SoftwareMixer final : public Mixer {
  114. Filter *filter = nullptr;
  115. @@ -73,7 +74,7 @@ PercentVolumeToSoftwareVolume(unsigned volume) noexcept
  116. if (volume >= 100)
  117. return PCM_VOLUME_1;
  118. else if (volume > 0)
  119. - return pcm_float_to_volume((exp(volume / 25.0) - 1) /
  120. + return pcm_float_to_volume((std::exp(volume / 25.0) - 1) /
  121. (54.5981500331F - 1));
  122. else
  123. return 0;
  124. diff --git a/src/util/Math.hxx b/src/util/Math.hxx
  125. index bd856f5a9..2206b045f 100644
  126. --- a/src/util/Math.hxx
  127. +++ b/src/util/Math.hxx
  128. @@ -31,10 +31,16 @@
  129. #define MATH_HXX
  130. #ifdef __UCLIBC__
  131. +#include <boost/math/special_functions/pow.hpp>
  132. #include <boost/math/special_functions/round.hpp>
  133. +using boost::math::iround;
  134. +using boost::math::pow;
  135. using boost::math::lround;
  136. +#define lrint iround
  137. #else
  138. #include <cmath>
  139. +using std::pow;
  140. +using std::lrint;
  141. using std::lround;
  142. #endif