Commit 333a08eb authored by Max Kellermann's avatar Max Kellermann

replay_gain_info, ...: use cmath instead of math.h in C++ mode

Fixes build problems with mingw32.
parent 989c9a73
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#include "audio_format.h" #include "audio_format.h"
#include "tag.h" #include "tag.h"
#include <cmath>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -82,9 +84,8 @@ static float mixramp_interpolate(char *ramp_list, float required_db) ...@@ -82,9 +84,8 @@ static float mixramp_interpolate(char *ramp_list, float required_db)
} }
/* If required db < any stored value, use the least. */ /* If required db < any stored value, use the least. */
if (isnan(last_db)) { if (std::isnan(last_db))
return secs; return secs;
}
/* Finally, interpolate linearly. */ /* Finally, interpolate linearly. */
secs = last_secs + (required_db - last_db) * (secs - last_secs) / (db - last_db); secs = last_secs + (required_db - last_db) * (secs - last_secs) / (db - last_db);
...@@ -114,13 +115,14 @@ unsigned cross_fade_calc(float duration, float total_time, ...@@ -114,13 +115,14 @@ unsigned cross_fade_calc(float duration, float total_time,
chunks_f = (float)audio_format_time_to_size(af) / (float)CHUNK_SIZE; chunks_f = (float)audio_format_time_to_size(af) / (float)CHUNK_SIZE;
if (isnan(mixramp_delay) || !(mixramp_start) || !(mixramp_prev_end)) { if (std::isnan(mixramp_delay) || !mixramp_start || !mixramp_prev_end) {
chunks = (chunks_f * duration + 0.5); chunks = (chunks_f * duration + 0.5);
} else { } else {
/* Calculate mixramp overlap. */ /* Calculate mixramp overlap. */
mixramp_overlap = mixramp_interpolate(mixramp_start, mixramp_db - replay_gain_db) mixramp_overlap = mixramp_interpolate(mixramp_start, mixramp_db - replay_gain_db)
+ mixramp_interpolate(mixramp_prev_end, mixramp_db - replay_gain_prev_db); + mixramp_interpolate(mixramp_prev_end, mixramp_db - replay_gain_prev_db);
if (!isnan(mixramp_overlap) && (mixramp_delay <= mixramp_overlap)) { if (!std::isnan(mixramp_overlap) &&
mixramp_delay <= mixramp_overlap) {
chunks = (chunks_f * (mixramp_overlap - mixramp_delay)); chunks = (chunks_f * (mixramp_overlap - mixramp_delay));
g_debug("will overlap %d chunks, %fs", chunks, g_debug("will overlap %d chunks, %fs", chunks,
mixramp_overlap - mixramp_delay); mixramp_overlap - mixramp_delay);
......
...@@ -28,9 +28,10 @@ extern "C" { ...@@ -28,9 +28,10 @@ extern "C" {
#include "DecoderControl.hxx" #include "DecoderControl.hxx"
#include "Main.hxx" #include "Main.hxx"
#include <cmath>
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <math.h>
static void static void
pc_enqueue_song_locked(struct player_control *pc, struct song *song); pc_enqueue_song_locked(struct player_control *pc, struct song *song);
...@@ -49,7 +50,7 @@ player_control::player_control(unsigned _buffer_chunks, ...@@ -49,7 +50,7 @@ player_control::player_control(unsigned _buffer_chunks,
next_song(nullptr), next_song(nullptr),
cross_fade_seconds(0), cross_fade_seconds(0),
mixramp_db(0), mixramp_db(0),
mixramp_delay_seconds(nanf("")), mixramp_delay_seconds(std::nanf("")),
total_play_time(0) total_play_time(0)
{ {
} }
......
...@@ -37,6 +37,8 @@ extern "C" { ...@@ -37,6 +37,8 @@ extern "C" {
#include "idle.h" #include "idle.h"
} }
#include <cmath>
#include <glib.h> #include <glib.h>
#undef G_LOG_DOMAIN #undef G_LOG_DOMAIN
...@@ -759,7 +761,7 @@ play_next_chunk(struct player *player) ...@@ -759,7 +761,7 @@ play_next_chunk(struct player *player)
other_chunk->tag); other_chunk->tag);
other_chunk->tag = NULL; other_chunk->tag = NULL;
if (isnan(pc->mixramp_delay_seconds)) { if (std::isnan(pc->mixramp_delay_seconds)) {
chunk->mix_ratio = ((float)cross_fade_position) chunk->mix_ratio = ((float)cross_fade_position)
/ player->cross_fade_chunks; / player->cross_fade_chunks;
} else { } else {
......
...@@ -33,7 +33,6 @@ extern "C" { ...@@ -33,7 +33,6 @@ extern "C" {
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <math.h>
enum replay_gain_mode replay_gain_mode = REPLAY_GAIN_OFF; enum replay_gain_mode replay_gain_mode = REPLAY_GAIN_OFF;
......
...@@ -22,8 +22,12 @@ ...@@ -22,8 +22,12 @@
#include "check.h" #include "check.h"
#ifdef __cplusplus
#include <cmath>
#else
#include <stdbool.h> #include <stdbool.h>
#include <math.h> #include <math.h>
#endif
enum replay_gain_mode { enum replay_gain_mode {
REPLAY_GAIN_AUTO = -2, REPLAY_GAIN_AUTO = -2,
...@@ -58,7 +62,11 @@ replay_gain_info_init(struct replay_gain_info *info) ...@@ -58,7 +62,11 @@ replay_gain_info_init(struct replay_gain_info *info)
static inline bool static inline bool
replay_gain_tuple_defined(const struct replay_gain_tuple *tuple) replay_gain_tuple_defined(const struct replay_gain_tuple *tuple)
{ {
#ifdef __cplusplus
return !std::isinf(tuple->gain);
#else
return !isinf(tuple->gain); return !isinf(tuple->gain);
#endif
} }
#ifdef __cplusplus #ifdef __cplusplus
......
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