mirror of
https://github.com/mpv-player/mpv
synced 2025-05-02 16:20:25 +00:00
ao: simplify hack for float atomics
stdatomic.h defines no atomic_float typedef. We can't just use _Atomic unconditionally, because we support compilers without C11 atomics. So just create a custom atomic_float typedef in the wrapper, which uses _Atomic in the C11 code path.
This commit is contained in:
parent
963eb15006
commit
6f8cf73f54
@ -642,19 +642,7 @@ void ao_print_devices(struct mpv_global *global, struct mp_log *log)
|
|||||||
|
|
||||||
void ao_set_gain(struct ao *ao, float gain)
|
void ao_set_gain(struct ao *ao, float gain)
|
||||||
{
|
{
|
||||||
uint_least32_t v = 0;
|
atomic_store(&ao->gain, gain);
|
||||||
assert(sizeof(gain) <= sizeof(v));
|
|
||||||
memcpy(&v, &gain, sizeof(gain));
|
|
||||||
atomic_store(&ao->gain_fi, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
static float ao_get_gain(struct ao *ao)
|
|
||||||
{
|
|
||||||
uint_least32_t v = atomic_load_explicit(&ao->gain_fi, memory_order_relaxed);
|
|
||||||
float gain;
|
|
||||||
assert(sizeof(gain) <= sizeof(v));
|
|
||||||
memcpy(&gain, &v, sizeof(gain));
|
|
||||||
return gain;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MUL_GAIN_i(d, num_samples, gain, low, center, high) \
|
#define MUL_GAIN_i(d, num_samples, gain, low, center, high) \
|
||||||
@ -669,7 +657,7 @@ static float ao_get_gain(struct ao *ao)
|
|||||||
|
|
||||||
static void process_plane(struct ao *ao, void *data, int num_samples)
|
static void process_plane(struct ao *ao, void *data, int num_samples)
|
||||||
{
|
{
|
||||||
float gain = ao_get_gain(ao);
|
float gain = atomic_load_explicit(&ao->gain, memory_order_relaxed);
|
||||||
int format = af_fmt_from_planar(ao->format);
|
int format = af_fmt_from_planar(ao->format);
|
||||||
if (gain == 1.0f)
|
if (gain == 1.0f)
|
||||||
return;
|
return;
|
||||||
|
@ -70,8 +70,8 @@ struct ao {
|
|||||||
// Internal events (use ao_request_reload(), ao_hotplug_event())
|
// Internal events (use ao_request_reload(), ao_hotplug_event())
|
||||||
atomic_int events_;
|
atomic_int events_;
|
||||||
|
|
||||||
// Float gain multiplicator, reinterpret-casted to int.
|
// Float gain multiplicator
|
||||||
atomic_uint_least32_t gain_fi;
|
mp_atomic_float gain;
|
||||||
|
|
||||||
int buffer;
|
int buffer;
|
||||||
double def_buffer;
|
double def_buffer;
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#if HAVE_STDATOMIC
|
#if HAVE_STDATOMIC
|
||||||
#include <stdatomic.h>
|
#include <stdatomic.h>
|
||||||
|
typedef _Atomic float mp_atomic_float;
|
||||||
#else
|
#else
|
||||||
|
|
||||||
// Emulate the parts of C11 stdatomic.h needed by mpv.
|
// Emulate the parts of C11 stdatomic.h needed by mpv.
|
||||||
@ -36,6 +37,8 @@ typedef struct { long long v; } atomic_llong;
|
|||||||
typedef struct { uint_least32_t v; } atomic_uint_least32_t;
|
typedef struct { uint_least32_t v; } atomic_uint_least32_t;
|
||||||
typedef struct { unsigned long long v; } atomic_ullong;
|
typedef struct { unsigned long long v; } atomic_ullong;
|
||||||
|
|
||||||
|
typedef struct { float v; } mp_atomic_float;
|
||||||
|
|
||||||
#define ATOMIC_VAR_INIT(x) \
|
#define ATOMIC_VAR_INIT(x) \
|
||||||
{.v = (x)}
|
{.v = (x)}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user