audio: introduce AUD_set_volume_{in,out}_lr()

There are 2 sets of functions since the introduction of multi-channel
Volume structure: AUD_set_volume_{in,out} and audio_set_volume_{in,out}.

Use the AUD_ prefix for consistency with other audio.c functions. Rename
the stereo function with "_lr" suffix.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
This commit is contained in:
Marc-André Lureau 2025-10-14 13:56:14 +04:00
parent eaeafe3074
commit d2b15ae407
11 changed files with 36 additions and 37 deletions

View file

@ -1949,13 +1949,7 @@ void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque)
}
}
void AUD_set_volume_out (SWVoiceOut *sw, int mute, uint8_t lvol, uint8_t rvol)
{
Volume vol = { .mute = mute, .channels = 2, .vol = { lvol, rvol } };
audio_set_volume_out(sw, &vol);
}
void audio_set_volume_out(SWVoiceOut *sw, Volume *vol)
void AUD_set_volume_out(SWVoiceOut *sw, Volume *vol)
{
if (sw) {
HWVoiceOut *hw = sw->hw;
@ -1971,13 +1965,7 @@ void audio_set_volume_out(SWVoiceOut *sw, Volume *vol)
}
}
void AUD_set_volume_in (SWVoiceIn *sw, int mute, uint8_t lvol, uint8_t rvol)
{
Volume vol = { .mute = mute, .channels = 2, .vol = { lvol, rvol } };
audio_set_volume_in(sw, &vol);
}
void audio_set_volume_in(SWVoiceIn *sw, Volume *vol)
void AUD_set_volume_in(SWVoiceIn *sw, Volume *vol)
{
if (sw) {
HWVoiceIn *hw = sw->hw;

View file

@ -119,9 +119,6 @@ int AUD_is_active_out (SWVoiceOut *sw);
void AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
void AUD_set_volume_out (SWVoiceOut *sw, int mute, uint8_t lvol, uint8_t rvol);
void AUD_set_volume_in (SWVoiceIn *sw, int mute, uint8_t lvol, uint8_t rvol);
#define AUDIO_MAX_CHANNELS 16
typedef struct Volume {
bool mute;
@ -129,8 +126,22 @@ typedef struct Volume {
uint8_t vol[AUDIO_MAX_CHANNELS];
} Volume;
void audio_set_volume_out(SWVoiceOut *sw, Volume *vol);
void audio_set_volume_in(SWVoiceIn *sw, Volume *vol);
void AUD_set_volume_out(SWVoiceOut *sw, Volume *vol);
void AUD_set_volume_in(SWVoiceIn *sw, Volume *vol);
static inline void
AUD_set_volume_out_lr(SWVoiceOut *sw, bool mut, uint8_t lvol, uint8_t rvol) {
AUD_set_volume_out(sw, &(Volume) {
.mute = mut, .channels = 2, .vol = { lvol, rvol }
});
}
static inline void
AUD_set_volume_in_lr(SWVoiceIn *sw, bool mut, uint8_t lvol, uint8_t rvol) {
AUD_set_volume_in(sw, &(Volume) {
.mute = mut, .channels = 2, .vol = { lvol, rvol }
});
}
SWVoiceIn *AUD_open_in (
QEMUSoundCard *card,

View file

@ -416,7 +416,7 @@ static void update_combined_volume_out(AC97LinkState *s)
lvol = (lvol * plvol) / 255;
rvol = (rvol * prvol) / 255;
AUD_set_volume_out(s->voice_po, mute, lvol, rvol);
AUD_set_volume_out_lr(s->voice_po, mute, lvol, rvol);
}
static void update_volume_in(AC97LinkState *s)
@ -427,7 +427,7 @@ static void update_volume_in(AC97LinkState *s)
get_volume(mixer_load(s, AC97_Record_Gain_Mute), 0x0f, 0,
&mute, &lvol, &rvol);
AUD_set_volume_in(s->voice_pi, mute, lvol, rvol);
AUD_set_volume_in_lr(s->voice_pi, mute, lvol, rvol);
}
static void set_volume(AC97LinkState *s, int index, uint32_t val)

View file

@ -489,7 +489,7 @@ static void asc_write(void *opaque, hwaddr addr, uint64_t value,
{
int vol = (value & 0xe0);
AUD_set_volume_out(s->voice, 0, vol, vol);
AUD_set_volume_out_lr(s->voice, 0, vol, vol);
break;
}
}

View file

@ -466,9 +466,9 @@ static void hda_audio_set_amp(HDAAudioStream *st)
return;
}
if (st->output) {
AUD_set_volume_out(st->voice.out, muted, left, right);
AUD_set_volume_out_lr(st->voice.out, muted, left, right);
} else {
AUD_set_volume_in(st->voice.in, muted, left, right);
AUD_set_volume_in_lr(st->voice.in, muted, left, right);
}
}

View file

@ -308,7 +308,7 @@ void lm4549_init(lm4549_state *s, lm4549_callback data_req_cb, void* opaque,
&as
);
AUD_set_volume_out(s->voice, 0, 255, 255);
AUD_set_volume_out_lr(s->voice, 0, 255, 255);
s->voice_is_active = 0;

View file

@ -53,7 +53,7 @@ static void codec_volume_set_out(ViaAC97State *s)
rvol /= 255;
mute = CODEC_REG(s, AC97_Master_Volume_Mute) >> MUTE_SHIFT;
mute |= CODEC_REG(s, AC97_PCM_Out_Volume_Mute) >> MUTE_SHIFT;
AUD_set_volume_out(s->vo, mute, lvol, rvol);
AUD_set_volume_out_lr(s->vo, mute, lvol, rvol);
}
static void codec_reset(ViaAC97State *s)

View file

@ -463,7 +463,7 @@ static uint32_t virtio_snd_pcm_prepare(VirtIOSound *s, uint32_t stream_id)
stream,
virtio_snd_pcm_out_cb,
&as);
AUD_set_volume_out(stream->voice.out, 0, 255, 255);
AUD_set_volume_out_lr(stream->voice.out, 0, 255, 255);
} else {
stream->voice.in = AUD_open_in(&s->card,
stream->voice.in,
@ -471,7 +471,7 @@ static uint32_t virtio_snd_pcm_prepare(VirtIOSound *s, uint32_t stream_id)
stream,
virtio_snd_pcm_in_cb,
&as);
AUD_set_volume_in(stream->voice.in, 0, 255, 255);
AUD_set_volume_in_lr(stream->voice.in, 0, 255, 255);
}
return cpu_to_le32(VIRTIO_SND_S_OK);

View file

@ -145,30 +145,30 @@ static void wm8750_vol_update(WM8750State *s)
{
/* FIXME: multiply all volumes by s->invol[2], s->invol[3] */
AUD_set_volume_in(s->adc_voice[0], s->mute,
AUD_set_volume_in_lr(s->adc_voice[0], s->mute,
s->inmute[0] ? 0 : WM8750_INVOL_TRANSFORM(s->invol[0]),
s->inmute[1] ? 0 : WM8750_INVOL_TRANSFORM(s->invol[1]));
AUD_set_volume_in(s->adc_voice[1], s->mute,
AUD_set_volume_in_lr(s->adc_voice[1], s->mute,
s->inmute[0] ? 0 : WM8750_INVOL_TRANSFORM(s->invol[0]),
s->inmute[1] ? 0 : WM8750_INVOL_TRANSFORM(s->invol[1]));
AUD_set_volume_in(s->adc_voice[2], s->mute,
AUD_set_volume_in_lr(s->adc_voice[2], s->mute,
s->inmute[0] ? 0 : WM8750_INVOL_TRANSFORM(s->invol[0]),
s->inmute[1] ? 0 : WM8750_INVOL_TRANSFORM(s->invol[1]));
/* FIXME: multiply all volumes by s->outvol[0], s->outvol[1] */
/* Speaker: LOUT2VOL ROUT2VOL */
AUD_set_volume_out(s->dac_voice[0], s->mute,
AUD_set_volume_out_lr(s->dac_voice[0], s->mute,
s->outmute[0] ? 0 : WM8750_OUTVOL_TRANSFORM(s->outvol[4]),
s->outmute[1] ? 0 : WM8750_OUTVOL_TRANSFORM(s->outvol[5]));
/* Headphone: LOUT1VOL ROUT1VOL */
AUD_set_volume_out(s->dac_voice[1], s->mute,
AUD_set_volume_out_lr(s->dac_voice[1], s->mute,
s->outmute[0] ? 0 : WM8750_OUTVOL_TRANSFORM(s->outvol[2]),
s->outmute[1] ? 0 : WM8750_OUTVOL_TRANSFORM(s->outvol[3]));
/* MONOOUT: MONOVOL MONOVOL */
AUD_set_volume_out(s->dac_voice[2], s->mute,
AUD_set_volume_out_lr(s->dac_voice[2], s->mute,
s->outmute[0] ? 0 : WM8750_OUTVOL_TRANSFORM(s->outvol[6]),
s->outmute[1] ? 0 : WM8750_OUTVOL_TRANSFORM(s->outvol[6]));
}

View file

@ -1334,7 +1334,7 @@ static void xlnx_dp_realize(DeviceState *dev, Error **errp)
s,
xlnx_dp_audio_callback,
&as);
AUD_set_volume_out(s->amixer_output_stream, 0, 255, 255);
AUD_set_volume_out_lr(s->amixer_output_stream, 0, 255, 255);
xlnx_dp_audio_activate(s);
s->vblank = ptimer_init(vblank_hit, s, DP_VBLANK_PTIMER_POLICY);
ptimer_transaction_begin(s->vblank);

View file

@ -805,7 +805,7 @@ static int usb_audio_set_control(USBAudioState *s, uint8_t attrib,
}
fprintf(stderr, "\n");
}
audio_set_volume_out(s->out.voice, &s->out.vol);
AUD_set_volume_out(s->out.voice, &s->out.vol);
}
return ret;
@ -981,7 +981,7 @@ static void usb_audio_reinit(USBDevice *dev, unsigned channels)
s->out.voice = AUD_open_out(&s->card, s->out.voice, TYPE_USB_AUDIO,
s, output_callback, &s->out.as);
audio_set_volume_out(s->out.voice, &s->out.vol);
AUD_set_volume_out(s->out.voice, &s->out.vol);
AUD_set_active_out(s->out.voice, 0);
}