Fix compilation with -Werror=float-conversion

Better make the conversions explicit so that we don't get any surprises.

Fixes #4065
This commit is contained in:
Wim Taymans 2024-06-18 12:17:56 +02:00
parent 50870aac57
commit 1ae4374ccf
71 changed files with 286 additions and 284 deletions

View file

@ -388,7 +388,7 @@ static int cmd_set_volume(struct data *data, const struct command *cmd, int argc
return -EINVAL;
}
dev_id = atoi(argv[1]);
vol = atof(argv[2]);
vol = (float)atof(argv[2]);
if (dev_id >= card->n_devices)
return -EINVAL;
@ -418,12 +418,12 @@ static int adjust_volume(struct data *data, const struct command *cmd, int argc,
static int cmd_inc_volume(struct data *data, const struct command *cmd, int argc, char *argv[])
{
return adjust_volume(data, cmd, argc, argv, 0.2);
return adjust_volume(data, cmd, argc, argv, 0.2f);
}
static int cmd_dec_volume(struct data *data, const struct command *cmd, int argc, char *argv[])
{
return adjust_volume(data, cmd, argc, argv, -0.2);
return adjust_volume(data, cmd, argc, argv, -0.2f);
}
static int cmd_get_mute(struct data *data, const struct command *cmd, int argc, char *argv[])

View file

@ -1335,7 +1335,7 @@ static void mixer_volume_init(pa_card *impl, pa_alsa_device *dev)
pa_log_info("Using hardware volume control. Hardware dB scale %s.",
dev->mixer_path->has_dB ? "supported" : "not supported");
}
dev->device.base_volume = pa_sw_volume_to_linear(dev->base_volume);
dev->device.base_volume = (float)pa_sw_volume_to_linear(dev->base_volume);
dev->device.volume_step = 1.0f / dev->n_volume_steps;
if (impl->soft_mixer || !dev->mixer_path || !dev->mixer_path->has_mute) {
@ -2022,7 +2022,7 @@ static int get_volume(pa_cvolume *v, float *volume, uint32_t n_volume)
if (v->channels == 0)
return -EIO;
for (i = 0; i < n_volume; i++)
volume[i] = pa_sw_volume_to_linear(v->values[i % v->channels]);
volume[i] = (float)pa_sw_volume_to_linear(v->values[i % v->channels]);
return 0;
}

View file

@ -1147,7 +1147,7 @@ static int element_set_volume(pa_alsa_element *e, snd_mixer_t *m, const pa_chann
int rounding;
if (e->volume_limit >= 0 && value > (e->max_dB * 100))
value = e->max_dB * 100;
value = (long) (e->max_dB * 100);
if (e->direction == PA_ALSA_DIRECTION_OUTPUT) {
/* If we call set_playback_volume() without checking first

View file

@ -1206,7 +1206,7 @@ static unsigned devset_playback_priority(pa_idxset *devices, bool invert) {
}
if (priority > 0 && invert)
return 1.0 / priority;
return (unsigned)(1.0 / priority);
return (unsigned) priority;
}
@ -1224,7 +1224,7 @@ static unsigned devset_capture_priority(pa_idxset *devices, bool invert) {
}
if (priority > 0 && invert)
return 1.0 / priority;
return (unsigned)(1.0 / priority);
return (unsigned) priority;
}

View file

@ -2283,11 +2283,11 @@ int spa_alsa_update_rate_match(struct state *state)
* means that to adjust the playback rate, we need to apply the inverse
* of the given rate. */
if (state->stream == SND_PCM_STREAM_CAPTURE) {
pitch = 1000000 * state->rate_match->rate;
last_pitch = 1000000 * state->last_rate;
pitch = (uint64_t)(1000000 * state->rate_match->rate);
last_pitch = (uint64_t)(1000000 * state->last_rate);
} else {
pitch = 1000000 / state->rate_match->rate;
last_pitch = 1000000 / state->last_rate;
pitch = (uint64_t)(1000000 / state->rate_match->rate);
last_pitch = (uint64_t)(1000000 / state->last_rate);
}
/* The pitch adjustment is limited to 1 ppm */
@ -2727,7 +2727,7 @@ static int update_time(struct state *state, uint64_t current_time, snd_pcm_sfram
corr = 1.0;
if (diff < 0)
state->next_time += diff / corr * 1e9 / state->rate;
state->next_time += (uint64_t)(diff / corr * 1e9 / state->rate);
if (SPA_UNLIKELY((state->next_time - state->base_time) > BW_PERIOD)) {
state->base_time = state->next_time;
@ -2751,7 +2751,7 @@ static int update_time(struct state *state, uint64_t current_time, snd_pcm_sfram
SPA_FLAG_UPDATE(state->rate_match->flags, SPA_IO_RATE_MATCH_FLAG_ACTIVE, state->matching);
}
state->next_time += state->threshold / corr * 1e9 / state->rate;
state->next_time += (uint64_t)(state->threshold / corr * 1e9 / state->rate);
if (SPA_LIKELY(!follower && state->clock)) {
state->clock->nsec = current_time;
@ -2859,7 +2859,7 @@ static int alsa_write_sync(struct state *state, uint64_t current_time)
if (SPA_UNLIKELY((res = get_status(state, current_time, &avail, &delay, &target)) < 0)) {
spa_log_error(state->log, "get_status error: %s", spa_strerror(res));
state->next_time += state->threshold * 1e9 / state->rate;
state->next_time += (uint64_t)(state->threshold * 1e9 / state->rate);
return res;
}
@ -3120,7 +3120,7 @@ static int alsa_read_sync(struct state *state, uint64_t current_time)
if (SPA_UNLIKELY((res = get_status(state, current_time, &avail, &delay, &target)) < 0)) {
spa_log_error(state->log, "get_status error: %s", spa_strerror(res));
state->next_time += state->threshold * 1e9 / state->rate;
state->next_time += (uint64_t)(state->threshold * 1e9 / state->rate);
return res;
}
@ -3442,7 +3442,7 @@ static void alsa_timer_wakeup_event(struct spa_source *source)
state->next_time - current_time, state->threshold,
state->sample_count, suppressed);
}
state->next_time = current_time + state->threshold * 1e9 / state->rate;
state->next_time = (uint64_t)(current_time + state->threshold * 1e9 / state->rate);
}
set_timeout(state, state->next_time);
}

View file

@ -797,9 +797,9 @@ static int update_time(struct seq_state *state, uint64_t nsec, bool follower)
* use the rate correction, else we will use the rate correction only for the new
* timeout. */
if (state->following)
state->queue_next += state->threshold * corr * 1e9 / state->rate.denom;
state->queue_next += (uint64_t)(state->threshold * corr * 1e9 / state->rate.denom);
else
state->queue_next += state->threshold * 1e9 / state->rate.denom;
state->queue_next += (uint64_t)(state->threshold * 1e9 / state->rate.denom);
if ((state->next_time - state->base_time) > BW_PERIOD) {
state->base_time = state->next_time;
@ -807,14 +807,14 @@ static int update_time(struct seq_state *state, uint64_t nsec, bool follower)
state, follower, corr, state->dll.bw, err,
state->dll.z1, state->dll.z2, state->dll.z3);
}
state->next_time += state->threshold / corr * 1e9 / state->rate.denom;
state->next_time += (uint64_t)(state->threshold / corr * 1e9 / state->rate.denom);
if (!follower && state->clock) {
state->clock->nsec = nsec;
state->clock->rate = state->rate;
state->clock->position += state->clock->duration;
state->clock->duration = state->duration;
state->clock->delay = state->duration * corr;
state->clock->delay = (int64_t)(state->duration * corr);
state->clock->rate_diff = corr;
state->clock->next_nsec = state->next_time;
}

View file

@ -16,7 +16,7 @@
#define DEFAULT_DEVICE "hw:0"
#define M_PI_M2 (M_PI + M_PI)
#define M_PI_M2f (M_PIf + M_PIf)
#define BW_PERIOD (SPA_NSEC_PER_SEC * 3)
@ -63,10 +63,10 @@ static int set_timeout(struct state *state, uint64_t time)
type *samples, v; \
samples = (type*)((uint8_t*)areas[0].addr + (areas[0].first + offset*areas[0].step) / 8); \
for (i = 0; i < frames; i++) { \
state->accumulator += M_PI_M2 * 440 / state->rate; \
if (state->accumulator >= M_PI_M2) \
state->accumulator -= M_PI_M2; \
v = sin(state->accumulator) * scale; \
state->accumulator += M_PI_M2f * 440.0f / state->rate; \
if (state->accumulator >= M_PI_M2f) \
state->accumulator -= M_PI_M2f; \
v = (type)(sin(state->accumulator) * scale); \
for (j = 0; j < state->channels; j++) \
*samples++ = v; \
} \
@ -135,7 +135,7 @@ static int on_timer_wakeup(struct state *state)
/* set our new adjusted timeout. alternatively, this value can
* instead be used to drive a resampler if this device is
* slaved. */
state->next_time += state->period / corr * 1e9 / state->rate;
state->next_time += (uint64_t)(state->period / corr * 1e9 / state->rate);
set_timeout(state, state->next_time);
if (state->next_time - state->prev_time > BW_PERIOD) {