summaryrefslogtreecommitdiffstats
path: root/audio/out/ao_pulse.c
diff options
context:
space:
mode:
authorThomas Weißschuh <thomas@t-8ch.de>2022-12-31 03:46:44 +0000
committerPhilip Langdale <github.philipl@overt.org>2023-01-25 15:49:21 -0800
commit870512eb84a5b8bc4d4fdd794eb11bb3598e234b (patch)
treec68417de22549377028006b72b51657535ecd3b7 /audio/out/ao_pulse.c
parent5510d9f6632c009c398ce48a4d5a89c7f95efc96 (diff)
downloadmpv-870512eb84a5b8bc4d4fdd794eb11bb3598e234b.tar.bz2
mpv-870512eb84a5b8bc4d4fdd794eb11bb3598e234b.tar.xz
audio: simplify implementation of property ao-volume
ao-volume is represented in the code with a `struct ao_control_vol_t` which contains volumes for two channels, left and right. However the code implementing this property in command.c never treats these values individually. They are always averaged together. On the other hand the code in the AOs handling these values also has to handle the case where *not* exactly two channels are handled. So let's remove the `struct ao_control_vol_t` and replace it with a simple float. This makes the semantics clear to AO authors and allows us to drop some code from the AOs and command.c.
Diffstat (limited to 'audio/out/ao_pulse.c')
-rw-r--r--audio/out/ao_pulse.c19
1 files changed, 4 insertions, 15 deletions
diff --git a/audio/out/ao_pulse.c b/audio/out/ao_pulse.c
index 619824b954..a90f248962 100644
--- a/audio/out/ao_pulse.c
+++ b/audio/out/ao_pulse.c
@@ -680,14 +680,8 @@ static int control(struct ao *ao, enum aocontrol cmd, void *arg)
// we naively copied the struct, without updating pointers etc.
// Pointers might point to invalid data, accessors might fail.
if (cmd == AOCONTROL_GET_VOLUME) {
- ao_control_vol_t *vol = arg;
- if (priv->pi.volume.channels != 2)
- vol->left = vol->right =
- VOL_PA2MP(pa_cvolume_avg(&priv->pi.volume));
- else {
- vol->left = VOL_PA2MP(priv->pi.volume.values[0]);
- vol->right = VOL_PA2MP(priv->pi.volume.values[1]);
- }
+ float *vol = arg;
+ *vol = VOL_PA2MP(pa_cvolume_avg(&priv->pi.volume));
} else if (cmd == AOCONTROL_GET_MUTE) {
bool *mute = arg;
*mute = priv->pi.mute;
@@ -701,16 +695,11 @@ static int control(struct ao *ao, enum aocontrol cmd, void *arg)
priv->retval = 0;
uint32_t stream_index = pa_stream_get_index(priv->stream);
if (cmd == AOCONTROL_SET_VOLUME) {
- const ao_control_vol_t *vol = arg;
+ const float *vol = arg;
struct pa_cvolume volume;
pa_cvolume_reset(&volume, ao->channels.num);
- if (volume.channels != 2)
- pa_cvolume_set(&volume, volume.channels, VOL_MP2PA(vol->left));
- else {
- volume.values[0] = VOL_MP2PA(vol->left);
- volume.values[1] = VOL_MP2PA(vol->right);
- }
+ pa_cvolume_set(&volume, volume.channels, VOL_MP2PA(*vol));
if (!waitop(priv, pa_context_set_sink_input_volume(priv->context,
stream_index,
&volume,