Commit 86372254 authored by Max Kellermann's avatar Max Kellermann

player/CrossFade, ...: use lround()

parent d3d1d377
......@@ -31,6 +31,7 @@
#include "util/ChronoUtil.hxx"
#include <chrono>
#include <cmath>
#ifndef _WIN32
/**
......@@ -120,7 +121,7 @@ stats_print(Response &r, const Partition &partition)
#else
(unsigned)std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now() - start_time).count(),
#endif
(unsigned long)(partition.pc.GetTotalPlayTime().count() + 0.5));
std::lround(partition.pc.GetTotalPlayTime().count()));
#ifdef ENABLE_DATABASE
const Database *db = partition.instance.database;
......
......@@ -39,6 +39,8 @@
#include "db/update/Service.hxx"
#endif
#include <cmath>
#define COMMAND_STATUS_STATE "state"
#define COMMAND_STATUS_REPEAT "repeat"
#define COMMAND_STATUS_SINGLE "single"
......@@ -151,8 +153,8 @@ handle_status(Client &client, gcc_unused Request args, Response &r)
state);
if (pc.GetCrossFade() > 0)
r.Format(COMMAND_STATUS_CROSSFADE ": %i\n",
int(pc.GetCrossFade() + 0.5));
r.Format(COMMAND_STATUS_CROSSFADE ": %lu\n",
std::lround(pc.GetCrossFade()));
if (pc.GetMixRampDelay() > 0)
r.Format(COMMAND_STATUS_MIXRAMPDELAY ": %f\n",
......
......@@ -31,6 +31,7 @@
#include <neaacdec.h>
#include <cmath>
#include <exception>
#include <assert.h>
......@@ -386,9 +387,9 @@ faad_stream_decode(DecoderClient &client, InputStream &is,
/* update bit rate and position */
if (frame_info.samples > 0) {
bit_rate = frame_info.bytesconsumed * 8.0 *
frame_info.channels * audio_format.sample_rate /
frame_info.samples / 1000 + 0.5;
bit_rate = lround(frame_info.bytesconsumed * 8.0 *
frame_info.channels * audio_format.sample_rate /
frame_info.samples / 1000);
}
/* send PCM samples to MPD */
......
......@@ -38,6 +38,8 @@
#include <StringList.h>
#include <SoundPlayer.h>
#include <cmath>
#include <string.h>
#define UTF8_PLAY "\xE2\x96\xB6"
......@@ -439,7 +441,7 @@ haiku_output_get_volume(HaikuOutput &haiku)
if (soundPlayer == NULL || soundPlayer->InitCheck() != B_OK)
return 0;
return (int)(soundPlayer->Volume() * 100 + 0.5);
return lround(soundPlayer->Volume() * 100);
}
bool
......
......@@ -26,8 +26,9 @@
#include "PcmDither.cxx" // including the .cxx file to get inlined templates
#include <cmath>
#include <assert.h>
#include <math.h>
template<SampleFormat F, class Traits=SampleTraits<F>>
static typename Traits::value_type
......@@ -225,7 +226,7 @@ pcm_mix(PcmDither &dither, void *buffer1, const void *buffer2, size_t size,
s = sin(M_PI_2 * portion1);
s *= s;
int vol1 = s * PCM_VOLUME_1S + 0.5;
int vol1 = std::lround(s * PCM_VOLUME_1S);
vol1 = Clamp<int>(vol1, 0, PCM_VOLUME_1S);
return pcm_add_vol(dither, buffer1, buffer2, size,
......
......@@ -26,6 +26,8 @@
#include "util/Domain.hxx"
#include "Log.hxx"
#include <cmath>
#include <assert.h>
static constexpr Domain cross_fade_domain("cross_fade");
......@@ -108,7 +110,7 @@ CrossFadeSettings::Calculate(SignedSongTime total_time,
chunks_f = (float)af.GetTimeToSize() / (float)sizeof(MusicChunk::data);
if (mixramp_delay <= 0 || !mixramp_start || !mixramp_prev_end) {
chunks = (chunks_f * duration + 0.5);
chunks = std::lround(chunks_f * duration);
} else {
/* Calculate mixramp overlap. */
const float mixramp_overlap_current =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment