qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/42] Audio clean-ups
@ 2025-10-22  6:55 marcandre.lureau
  2025-10-22  6:55 ` [PATCH v2 01/42] hw/audio: improve error reports marcandre.lureau
                   ` (43 more replies)
  0 siblings, 44 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Hi,

This is part of continuous and overdue clean up / modernization effort for the
audio subsystem. (there is more in the pipeline)

v2:
- renamed AudioBE AudioBackend
- "qdev: add qdev_find_default_bus()" report different error for full bus
- added "remove QEMUSoundCard" & drop AudioFE renaming patch
- added "docs: Update mentions of removed '-soundhw' command line option" patch from philmd
- added r-b tags

thanks

Marc-André Lureau (41):
  hw/audio: improve error reports
  hw/audio: rename model list function
  hw/audio: remove global pcspk
  hw/pcspk: use explicitly the required PIT types
  hw/pcspk: make 'pit' a class property
  hw/pcspk: check the "pit" is set
  docs: update -soundhw -> -device list
  qdev: add qdev_find_default_bus()
  hw/audio: look up the default bus from the device class
  audio: rename audio_define->audio_add_audiodev()
  hw/audio: use better naming for -audio model handling code
  hw/audio/virtio-snd-pci: remove custom model callback
  hw/audio: simplify 'hda' audio init code
  hw/audio: generalize audio_model.init()
  hw/audio: drop audio_model.isa
  audio: start making AudioState a QOM Object
  audio: register backends in /audiodevs container
  audio: use /audiodevs QOM container
  audio/paaudio: remove needless return value
  audio/dsound: simplify init()
  audio/dsound: report init error via **errp
  audio: simplify audio_driver_init()
  audio: move period tick initialization
  audio: drop needless error message
  audio: clean-up vmstate change handler on finalize
  audio: unregister vmstate description
  audio: initialize card_head during object init
  audio: remove some needless headers
  audio: remove AUDIO_HOST_ENDIANNESS
  audio: introduce AUD_set_volume_{in,out}_lr()
  hw/audio: replace AUD_log() usage
  audio/replay: fix type punning
  audio: move internal APIs to audio_int.h
  audio: rename AudioState -> AudioBackend
  audio: remove QEMUSoundCard
  audio/dbus: use a helper function to set the backend dbus server
  audio: move audio.h under include/qemu/
  audio: remove dependency on spice header
  audio: cleanup, use bool for booleans
  audio: move capture API to own header
  audio: drop needless audio_driver "descr" field

Philippe Mathieu-Daudé (1):
  docs: Update mentions of removed '-soundhw' command line option

 docs/qdev-device-use.txt                      |  10 +-
 audio/audio_int.h                             |  62 ++--
 audio/audio_template.h                        |  44 ++-
 audio/mixeng.h                                |   1 -
 hw/audio/lm4549.h                             |   4 +-
 include/hw/audio/asc.h                        |   4 +-
 include/hw/audio/model.h                      |  13 +
 include/hw/audio/soundhw.h                    |  13 -
 include/hw/audio/virtio-snd.h                 |   4 +-
 include/hw/display/xlnx_dp.h                  |   4 +-
 include/hw/isa/vt82c686.h                     |   4 +-
 include/hw/qdev-properties-system.h           |   2 +-
 include/hw/timer/i8254.h                      |   4 +-
 include/monitor/qdev.h                        |   3 +
 include/qemu/audio-capture.h                  |  43 +++
 {audio => include/qemu}/audio.h               | 121 ++-----
 include/system/replay.h                       |   3 +-
 ui/vnc.h                                      |   4 +-
 audio/alsaaudio.c                             |   5 +-
 audio/audio-hmp-cmds.c                        |   4 +-
 audio/audio.c                                 | 310 +++++++++---------
 audio/audio_win_int.c                         |   2 +-
 audio/dbusaudio.c                             |  17 +-
 audio/dsoundaudio.c                           | 213 +++++-------
 audio/jackaudio.c                             |   3 +-
 audio/mixeng.c                                |  12 +-
 audio/noaudio.c                               |   5 +-
 audio/ossaudio.c                              |   7 +-
 audio/paaudio.c                               |  16 +-
 audio/pwaudio.c                               |   3 +-
 audio/sdlaudio.c                              |   3 +-
 audio/sndioaudio.c                            |   3 +-
 audio/spiceaudio.c                            |   7 +-
 audio/wavaudio.c                              |   6 +-
 audio/wavcapture.c                            |   5 +-
 hw/arm/integratorcp.c                         |   2 +-
 hw/arm/musicpal.c                             |   2 +-
 hw/arm/realview.c                             |   2 +-
 hw/arm/versatilepb.c                          |   2 +-
 hw/arm/vexpress.c                             |   2 +-
 hw/arm/xlnx-zcu102.c                          |   2 +-
 hw/audio/ac97.c                               | 156 +++++----
 hw/audio/adlib.c                              |  37 +--
 hw/audio/asc.c                                |  15 +-
 hw/audio/cs4231a.c                            |  56 ++--
 hw/audio/es1370.c                             |  54 ++-
 hw/audio/gus.c                                |  38 +--
 hw/audio/hda-codec.c                          |  21 +-
 hw/audio/intel-hda.c                          |  20 +-
 hw/audio/lm4549.c                             |  12 +-
 hw/audio/marvell_88w8618.c                    |   2 +-
 hw/audio/model.c                              | 121 +++++++
 hw/audio/pcspk.c                              |  32 +-
 hw/audio/pl041.c                              |   2 +-
 hw/audio/sb16.c                               | 116 ++++---
 hw/audio/soundhw.c                            | 143 --------
 hw/audio/via-ac97.c                           |  11 +-
 hw/audio/virtio-snd-pci.c                     |  18 +-
 hw/audio/virtio-snd.c                         |  17 +-
 hw/audio/wm8750.c                             |  37 +--
 hw/core/machine.c                             |   4 +-
 hw/core/qdev-properties-system.c              |  17 +-
 hw/display/xlnx_dp.c                          |   8 +-
 hw/ppc/prep.c                                 |   2 +-
 hw/timer/i8254_common.c                       |   6 +-
 hw/usb/dev-audio.c                            |  17 +-
 qom/object.c                                  |   1 +
 replay/replay-audio.c                         |   4 +-
 replay/stubs-system.c                         |   2 +-
 system/qdev-monitor.c                         |  29 +-
 system/runstate.c                             |   2 +-
 system/vl.c                                   |  16 +-
 ui/dbus.c                                     |  13 +-
 ui/vnc.c                                      |  10 +-
 audio/coreaudio.m                             |   3 +-
 audio/meson.build                             |   2 +-
 hw/audio/meson.build                          |   2 +-
 .../codeconverter/test_regexps.py             |   4 +-
 78 files changed, 968 insertions(+), 1058 deletions(-)
 create mode 100644 include/hw/audio/model.h
 delete mode 100644 include/hw/audio/soundhw.h
 create mode 100644 include/qemu/audio-capture.h
 rename {audio => include/qemu}/audio.h (50%)
 create mode 100644 hw/audio/model.c
 delete mode 100644 hw/audio/soundhw.c

-- 
2.51.0



^ permalink raw reply	[flat|nested] 54+ messages in thread

* [PATCH v2 01/42] hw/audio: improve error reports
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
@ 2025-10-22  6:55 ` marcandre.lureau
  2025-10-22  6:55 ` [PATCH v2 02/42] hw/audio: rename model list function marcandre.lureau
                   ` (42 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann

From: Marc-André Lureau <marcandre.lureau@redhat.com>

The -audiodev argument is 'model=..', use same terminology.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/audio/soundhw.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/hw/audio/soundhw.c b/hw/audio/soundhw.c
index d18fd9fa05..b06552e7a8 100644
--- a/hw/audio/soundhw.c
+++ b/hw/audio/soundhw.c
@@ -70,7 +70,7 @@ void show_valid_soundhw(void)
     struct soundhw *c;
 
     if (soundhw_count) {
-         printf("Valid sound card names (comma separated):\n");
+         printf("Valid audio device model names:\n");
          for (c = soundhw; c->name; ++c) {
              printf ("%-11s %s\n", c->name, c->descr);
          }
@@ -88,7 +88,7 @@ void select_soundhw(const char *name, const char *audiodev)
     struct soundhw *c;
 
     if (selected) {
-        error_report("only one -soundhw option is allowed");
+        error_report("only one -audio option is allowed");
         exit(1);
     }
 
@@ -101,7 +101,7 @@ void select_soundhw(const char *name, const char *audiodev)
     }
 
     if (!c->name) {
-        error_report("Unknown sound card name `%s'", name);
+        error_report("Unknown audio device model `%s'", name);
         show_valid_soundhw();
         exit(1);
     }
@@ -140,4 +140,3 @@ void soundhw_init(void)
         c->init_pci(pci_bus, audiodev_id);
     }
 }
-
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 02/42] hw/audio: rename model list function
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
  2025-10-22  6:55 ` [PATCH v2 01/42] hw/audio: improve error reports marcandre.lureau
@ 2025-10-22  6:55 ` marcandre.lureau
  2025-10-22  6:55 ` [PATCH v2 03/42] hw/audio: remove global pcspk marcandre.lureau
                   ` (41 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/hw/audio/soundhw.h | 2 +-
 hw/audio/soundhw.c         | 4 ++--
 system/vl.c                | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/hw/audio/soundhw.h b/include/hw/audio/soundhw.h
index 474c5ff94e..83b3011083 100644
--- a/include/hw/audio/soundhw.h
+++ b/include/hw/audio/soundhw.h
@@ -7,7 +7,7 @@ void deprecated_register_soundhw(const char *name, const char *descr,
                                  int isa, const char *typename);
 
 void soundhw_init(void);
-void show_valid_soundhw(void);
+void audio_print_available_models(void);
 void select_soundhw(const char *name, const char *audiodev);
 
 #endif
diff --git a/hw/audio/soundhw.c b/hw/audio/soundhw.c
index b06552e7a8..aca077f5ae 100644
--- a/hw/audio/soundhw.c
+++ b/hw/audio/soundhw.c
@@ -65,7 +65,7 @@ void deprecated_register_soundhw(const char *name, const char *descr,
     soundhw_count++;
 }
 
-void show_valid_soundhw(void)
+void audio_print_available_models(void)
 {
     struct soundhw *c;
 
@@ -102,7 +102,7 @@ void select_soundhw(const char *name, const char *audiodev)
 
     if (!c->name) {
         error_report("Unknown audio device model `%s'", name);
-        show_valid_soundhw();
+        audio_print_available_models();
         exit(1);
     }
 }
diff --git a/system/vl.c b/system/vl.c
index 646239e4a6..d20a9cbe08 100644
--- a/system/vl.c
+++ b/system/vl.c
@@ -3077,7 +3077,7 @@ void qemu_init(int argc, char **argv)
                     model = g_strdup(qdict_get_str(dict, "model"));
                     qdict_del(dict, "model");
                     if (is_help_option(model)) {
-                        show_valid_soundhw();
+                        audio_print_available_models();
                         exit(0);
                     }
                 }
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 03/42] hw/audio: remove global pcspk
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
  2025-10-22  6:55 ` [PATCH v2 01/42] hw/audio: improve error reports marcandre.lureau
  2025-10-22  6:55 ` [PATCH v2 02/42] hw/audio: rename model list function marcandre.lureau
@ 2025-10-22  6:55 ` marcandre.lureau
  2025-10-22  6:55 ` [PATCH v2 04/42] hw/pcspk: use explicitly the required PIT types marcandre.lureau
                   ` (40 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann

From: Marc-André Lureau <marcandre.lureau@redhat.com>

It is no longer used since commit 6033b9ecd4 ("pc: remove -soundhw pcspk")

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/audio/pcspk.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index a419161b5b..1b0cc08119 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -60,7 +60,6 @@ struct PCSpkState {
 };
 
 static const char *s_spk = "pcspk";
-static PCSpkState *pcspk_state;
 
 static inline void generate_samples(PCSpkState *s)
 {
@@ -192,8 +191,6 @@ static void pcspk_realizefn(DeviceState *dev, Error **errp)
     if (s->card.state && AUD_register_card(s_spk, &s->card, errp)) {
         pcspk_audio_init(s);
     }
-
-    pcspk_state = s;
 }
 
 static bool migrate_needed(void *opaque)
@@ -229,7 +226,6 @@ static void pcspk_class_initfn(ObjectClass *klass, const void *data)
     set_bit(DEVICE_CATEGORY_SOUND, dc->categories);
     dc->vmsd = &vmstate_spk;
     device_class_set_props(dc, pcspk_properties);
-    /* Reason: realize sets global pcspk_state */
     /* Reason: pit object link */
     dc->user_creatable = false;
 }
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 04/42] hw/pcspk: use explicitly the required PIT types
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (2 preceding siblings ...)
  2025-10-22  6:55 ` [PATCH v2 03/42] hw/audio: remove global pcspk marcandre.lureau
@ 2025-10-22  6:55 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 05/42] hw/pcspk: make 'pit' a class property marcandre.lureau
                   ` (39 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann,
	Michael S. Tsirkin

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/hw/timer/i8254.h | 4 ++--
 hw/audio/pcspk.c         | 2 +-
 hw/timer/i8254_common.c  | 6 ++----
 3 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/include/hw/timer/i8254.h b/include/hw/timer/i8254.h
index 8402caad30..f7148d9286 100644
--- a/include/hw/timer/i8254.h
+++ b/include/hw/timer/i8254.h
@@ -75,7 +75,7 @@ static inline ISADevice *kvm_pit_init(ISABus *bus, int base)
     return d;
 }
 
-void pit_set_gate(ISADevice *dev, int channel, int val);
-void pit_get_channel_info(ISADevice *dev, int channel, PITChannelInfo *info);
+void pit_set_gate(PITCommonState *pit, int channel, int val);
+void pit_get_channel_info(PITCommonState *pit, int channel, PITChannelInfo *info);
 
 #endif /* HW_I8254_H */
diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index 1b0cc08119..60cedcb375 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -50,7 +50,7 @@ struct PCSpkState {
     uint8_t sample_buf[PCSPK_BUF_LEN];
     QEMUSoundCard card;
     SWVoiceOut *voice;
-    void *pit;
+    PITCommonState *pit;
     unsigned int pit_count;
     unsigned int samples;
     unsigned int play_pos;
diff --git a/hw/timer/i8254_common.c b/hw/timer/i8254_common.c
index ad091594cd..419d4cd6e5 100644
--- a/hw/timer/i8254_common.c
+++ b/hw/timer/i8254_common.c
@@ -32,9 +32,8 @@
 #include "migration/vmstate.h"
 
 /* val must be 0 or 1 */
-void pit_set_gate(ISADevice *dev, int channel, int val)
+void pit_set_gate(PITCommonState *pit, int channel, int val)
 {
-    PITCommonState *pit = PIT_COMMON(dev);
     PITChannelState *s = &pit->channels[channel];
     PITCommonClass *c = PIT_COMMON_GET_CLASS(pit);
 
@@ -139,9 +138,8 @@ void pit_get_channel_info_common(PITCommonState *s, PITChannelState *sc,
     info->out = pit_get_out(sc, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
 }
 
-void pit_get_channel_info(ISADevice *dev, int channel, PITChannelInfo *info)
+void pit_get_channel_info(PITCommonState *pit, int channel, PITChannelInfo *info)
 {
-    PITCommonState *pit = PIT_COMMON(dev);
     PITChannelState *s = &pit->channels[channel];
     PITCommonClass *c = PIT_COMMON_GET_CLASS(pit);
 
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 05/42] hw/pcspk: make 'pit' a class property
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (3 preceding siblings ...)
  2025-10-22  6:55 ` [PATCH v2 04/42] hw/pcspk: use explicitly the required PIT types marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 06/42] hw/pcspk: check the "pit" is set marcandre.lureau
                   ` (38 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/audio/pcspk.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index 60cedcb375..40572241cb 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -174,11 +174,6 @@ static void pcspk_initfn(Object *obj)
     PCSpkState *s = PC_SPEAKER(obj);
 
     memory_region_init_io(&s->ioport, OBJECT(s), &pcspk_io_ops, s, "pcspk", 1);
-
-    object_property_add_link(obj, "pit", TYPE_PIT_COMMON,
-                             (Object **)&s->pit,
-                             qdev_prop_allow_set_link_before_realize,
-                             0);
 }
 
 static void pcspk_realizefn(DeviceState *dev, Error **errp)
@@ -216,6 +211,7 @@ static const Property pcspk_properties[] = {
     DEFINE_AUDIO_PROPERTIES(PCSpkState, card),
     DEFINE_PROP_UINT32("iobase", PCSpkState, iobase,  0x61),
     DEFINE_PROP_BOOL("migrate", PCSpkState, migrate,  true),
+    DEFINE_PROP_LINK("pit", PCSpkState, pit, TYPE_PIT_COMMON, PITCommonState *),
 };
 
 static void pcspk_class_initfn(ObjectClass *klass, const void *data)
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 06/42] hw/pcspk: check the "pit" is set
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (4 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 05/42] hw/pcspk: make 'pit' a class property marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 07/42] docs: update -soundhw -> -device list marcandre.lureau
                   ` (37 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann

From: Marc-André Lureau <marcandre.lureau@redhat.com>

We don't let the user create a "isa-pcspk" via -device yet (in theory,
we could, and fallback on a lookup PIT), but we can add some safety
checks that the property was correctly set nonetheless.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/audio/pcspk.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index 40572241cb..8ea3a161a4 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -181,6 +181,11 @@ static void pcspk_realizefn(DeviceState *dev, Error **errp)
     ISADevice *isadev = ISA_DEVICE(dev);
     PCSpkState *s = PC_SPEAKER(dev);
 
+    if (!s->pit) {
+        error_setg(errp, "pcspk: No \"pit\" set or available");
+        return;
+    }
+
     isa_register_ioport(isadev, &s->ioport, s->iobase);
 
     if (s->card.state && AUD_register_card(s_spk, &s->card, errp)) {
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 07/42] docs: update -soundhw -> -device list
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (5 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 06/42] hw/pcspk: check the "pit" is set marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 08/42] qdev: add qdev_find_default_bus() marcandre.lureau
                   ` (36 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Daniel P. Berrangé,
	Eduardo Habkost

From: Marc-André Lureau <marcandre.lureau@redhat.com>

(note: it's unclear whether -soundhw pcspk was
working as expected, since it was not user-creatable)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
---
 docs/qdev-device-use.txt | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/docs/qdev-device-use.txt b/docs/qdev-device-use.txt
index c98c86d828..043ae46114 100644
--- a/docs/qdev-device-use.txt
+++ b/docs/qdev-device-use.txt
@@ -324,8 +324,10 @@ Map from -soundhw sound card name to -device:
     gus         -device gus,iobase=IOADDR,irq=IRQ,dma=DMA,freq=F
     hda         -device intel-hda,msi=MSI -device hda-duplex
     sb16        -device sb16,iobase=IOADDR,irq=IRQ,dma=DMA,dma16=DMA16,version=V
-    adlib       not yet available with -device
-    pcspk       not yet available with -device
+    adlib       -device adlib,iobase=IOADDR,freq=F
+
+    pcspk       Not available with -device,
+                but audiodev can be set with -machine pcspk-audiodev=<name>
 
 For PCI devices, you can add bus=PCI-BUS,addr=DEVFN to control the PCI
 device address, as usual.
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 08/42] qdev: add qdev_find_default_bus()
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (6 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 07/42] docs: update -soundhw -> -device list marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 09/42] hw/audio: look up the default bus from the device class marcandre.lureau
                   ` (35 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Daniel P. Berrangé,
	Eduardo Habkost

From: Marc-André Lureau <marcandre.lureau@redhat.com>

This helper is used next by -audio code.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/monitor/qdev.h |  3 +++
 system/qdev-monitor.c  | 25 +++++++++++++++++++++----
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/include/monitor/qdev.h b/include/monitor/qdev.h
index 1d57bf6577..de33637869 100644
--- a/include/monitor/qdev.h
+++ b/include/monitor/qdev.h
@@ -1,6 +1,8 @@
 #ifndef MONITOR_QDEV_H
 #define MONITOR_QDEV_H
 
+#include "hw/qdev-core.h"
+
 /*** monitor commands ***/
 
 void hmp_info_qtree(Monitor *mon, const QDict *qdict);
@@ -11,6 +13,7 @@ int qdev_device_help(QemuOpts *opts);
 DeviceState *qdev_device_add(QemuOpts *opts, Error **errp);
 DeviceState *qdev_device_add_from_qdict(const QDict *opts,
                                         bool from_json, Error **errp);
+BusState *qdev_find_default_bus(DeviceClass *dc, Error **errp);
 
 /**
  * qdev_set_id: parent the device and set its id if provided.
diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c
index 2ac92d0a07..9ed05d5d5a 100644
--- a/system/qdev-monitor.c
+++ b/system/qdev-monitor.c
@@ -621,6 +621,25 @@ const char *qdev_set_id(DeviceState *dev, char *id, Error **errp)
     return prop->name;
 }
 
+BusState *qdev_find_default_bus(DeviceClass *dc, Error **errp)
+{
+    BusState *bus = NULL;
+
+    assert(dc->bus_type != NULL);
+    bus = qbus_find_recursive(sysbus_get_default(), NULL, dc->bus_type);
+    if (!bus) {
+        error_setg(errp, "No '%s' bus found for device '%s'",
+                   dc->bus_type, object_class_get_name(OBJECT_CLASS(dc)));
+        return NULL;
+    }
+    if (qbus_is_full(bus)) {
+        error_setg(errp, "A '%s' bus was found but is full", dc->bus_type);
+        return NULL;
+    }
+
+    return bus;
+}
+
 DeviceState *qdev_device_add_from_qdict(const QDict *opts,
                                         bool from_json, Error **errp)
 {
@@ -657,10 +676,8 @@ DeviceState *qdev_device_add_from_qdict(const QDict *opts,
             return NULL;
         }
     } else if (dc->bus_type != NULL) {
-        bus = qbus_find_recursive(sysbus_get_default(), NULL, dc->bus_type);
-        if (!bus || qbus_is_full(bus)) {
-            error_setg(errp, "No '%s' bus found for device '%s'",
-                       dc->bus_type, driver);
+        bus = qdev_find_default_bus(dc, errp);
+        if (!bus) {
             return NULL;
         }
     }
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 09/42] hw/audio: look up the default bus from the device class
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (7 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 08/42] qdev: add qdev_find_default_bus() marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 10/42] audio: rename audio_define->audio_add_audiodev() marcandre.lureau
                   ` (34 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Generalize and simplify the device model creation.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 hw/audio/soundhw.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)

diff --git a/hw/audio/soundhw.c b/hw/audio/soundhw.c
index aca077f5ae..b4a87ff709 100644
--- a/hw/audio/soundhw.c
+++ b/hw/audio/soundhw.c
@@ -22,6 +22,8 @@
  * THE SOFTWARE.
  */
 #include "qemu/osdep.h"
+#include "hw/qdev-core.h"
+#include "monitor/qdev.h"
 #include "qemu/option.h"
 #include "qemu/help_option.h"
 #include "qemu/error-report.h"
@@ -110,33 +112,19 @@ void select_soundhw(const char *name, const char *audiodev)
 void soundhw_init(void)
 {
     struct soundhw *c = selected;
-    ISABus *isa_bus = (ISABus *) object_resolve_path_type("", TYPE_ISA_BUS, NULL);
-    PCIBus *pci_bus = (PCIBus *) object_resolve_path_type("", TYPE_PCI_BUS, NULL);
-    BusState *bus;
 
     if (!c) {
         return;
     }
-    if (c->isa) {
-        if (!isa_bus) {
-            error_report("ISA bus not available for %s", c->name);
-            exit(1);
-        }
-        bus = BUS(isa_bus);
-    } else {
-        if (!pci_bus) {
-            error_report("PCI bus not available for %s", c->name);
-            exit(1);
-        }
-        bus = BUS(pci_bus);
-    }
 
     if (c->typename) {
         DeviceState *dev = qdev_new(c->typename);
+        BusState *bus = qdev_find_default_bus(DEVICE_GET_CLASS(dev), &error_fatal);
         qdev_prop_set_string(dev, "audiodev", audiodev_id);
         qdev_realize_and_unref(dev, bus, &error_fatal);
     } else {
         assert(!c->isa);
+        PCIBus *pci_bus = (PCIBus *) object_resolve_path_type("", TYPE_PCI_BUS, NULL);
         c->init_pci(pci_bus, audiodev_id);
     }
 }
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 10/42] audio: rename audio_define->audio_add_audiodev()
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (8 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 09/42] hw/audio: look up the default bus from the device class marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 11/42] hw/audio: use better naming for -audio model handling code marcandre.lureau
                   ` (33 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann

From: Marc-André Lureau <marcandre.lureau@redhat.com>

For readability.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 audio/audio.h | 4 ++--
 audio/audio.c | 8 ++++----
 system/vl.c   | 6 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/audio/audio.h b/audio/audio.h
index fcc22307be..eb5b5d662d 100644
--- a/audio/audio.h
+++ b/audio/audio.h
@@ -168,8 +168,8 @@ void audio_sample_to_uint64(const void *samples, int pos,
 void audio_sample_from_uint64(void *samples, int pos,
                             uint64_t left, uint64_t right);
 
-void audio_define(Audiodev *audio);
-void audio_define_default(Audiodev *dev, Error **errp);
+void audio_add_audiodev(Audiodev *audio);
+void audio_add_default_audiodev(Audiodev *dev, Error **errp);
 void audio_parse_option(const char *opt);
 void audio_create_default_audiodevs(void);
 void audio_init_audiodevs(void);
diff --git a/audio/audio.c b/audio/audio.c
index 89f091bc88..6197fa1788 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -1712,7 +1712,7 @@ void audio_create_default_audiodevs(void)
             visit_type_Audiodev(v, NULL, &dev, &error_fatal);
             visit_free(v);
 
-            audio_define_default(dev, &error_abort);
+            audio_add_default_audiodev(dev, &error_abort);
         }
     }
 }
@@ -2142,10 +2142,10 @@ void audio_parse_option(const char *opt)
     visit_type_Audiodev(v, NULL, &dev, &error_fatal);
     visit_free(v);
 
-    audio_define(dev);
+    audio_add_audiodev(dev);
 }
 
-void audio_define(Audiodev *dev)
+void audio_add_audiodev(Audiodev *dev)
 {
     AudiodevListEntry *e;
 
@@ -2156,7 +2156,7 @@ void audio_define(Audiodev *dev)
     QSIMPLEQ_INSERT_TAIL(&audiodevs, e, next);
 }
 
-void audio_define_default(Audiodev *dev, Error **errp)
+void audio_add_default_audiodev(Audiodev *dev, Error **errp)
 {
     AudiodevListEntry *e;
 
diff --git a/system/vl.c b/system/vl.c
index d20a9cbe08..7187b24449 100644
--- a/system/vl.c
+++ b/system/vl.c
@@ -2264,7 +2264,7 @@ static void qemu_record_config_group(const char *group, QDict *dict,
         Audiodev *dev = NULL;
         Visitor *v = qobject_input_visitor_new_keyval(QOBJECT(dict));
         if (visit_type_Audiodev(v, NULL, &dev, errp)) {
-            audio_define(dev);
+            audio_add_audiodev(dev);
         }
         visit_free(v);
 
@@ -3086,11 +3086,11 @@ void qemu_init(int argc, char **argv)
                 visit_type_Audiodev(v, NULL, &dev, &error_fatal);
                 visit_free(v);
                 if (model) {
-                    audio_define(dev);
+                    audio_add_audiodev(dev);
                     select_soundhw(model, dev->id);
                     g_free(model);
                 } else {
-                    audio_define_default(dev, &error_fatal);
+                    audio_add_default_audiodev(dev, &error_fatal);
                 }
                 break;
             }
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 11/42] hw/audio: use better naming for -audio model handling code
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (9 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 10/42] audio: rename audio_define->audio_add_audiodev() marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  8:04   ` Philippe Mathieu-Daudé
  2025-10-22  6:56 ` [PATCH v2 12/42] hw/audio/virtio-snd-pci: remove custom model callback marcandre.lureau
                   ` (32 subsequent siblings)
  43 siblings, 1 reply; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann,
	Manos Pitsidianakis, Michael S. Tsirkin, Eduardo Habkost

From: Marc-André Lureau <marcandre.lureau@redhat.com>

All the functions are about "-audio model=" handling, a simpler
way to setup audio. Rename functions/variables to reflect this better.

audio_register_model_with_cb() dropped "pci" from the name, since it
will be generalized next.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/hw/audio/model.h                      | 13 +++++
 include/hw/audio/soundhw.h                    | 13 -----
 hw/audio/ac97.c                               |  5 +-
 hw/audio/adlib.c                              |  4 +-
 hw/audio/cs4231a.c                            |  4 +-
 hw/audio/es1370.c                             |  5 +-
 hw/audio/gus.c                                |  4 +-
 hw/audio/intel-hda.c                          |  4 +-
 hw/audio/{soundhw.c => model.c}               | 58 +++++++++----------
 hw/audio/pcspk.c                              |  2 +-
 hw/audio/sb16.c                               |  5 +-
 hw/audio/virtio-snd-pci.c                     |  4 +-
 system/vl.c                                   |  6 +-
 hw/audio/meson.build                          |  2 +-
 .../codeconverter/test_regexps.py             |  2 +-
 15 files changed, 64 insertions(+), 67 deletions(-)
 create mode 100644 include/hw/audio/model.h
 delete mode 100644 include/hw/audio/soundhw.h
 rename hw/audio/{soundhw.c => model.c} (68%)

diff --git a/include/hw/audio/model.h b/include/hw/audio/model.h
new file mode 100644
index 0000000000..27ae7dcc31
--- /dev/null
+++ b/include/hw/audio/model.h
@@ -0,0 +1,13 @@
+#ifndef HW_AUDIO_MODEL_H
+#define HW_AUDIO_MODEL_H
+
+void audio_register_model_with_cb(const char *name, const char *descr,
+                                  int (*init_pci)(PCIBus *bus, const char *audiodev));
+void audio_register_model(const char *name, const char *descr,
+                          int isa, const char *typename);
+
+void audio_model_init(void);
+void audio_print_available_models(void);
+void audio_set_model(const char *name, const char *audiodev);
+
+#endif
diff --git a/include/hw/audio/soundhw.h b/include/hw/audio/soundhw.h
deleted file mode 100644
index 83b3011083..0000000000
--- a/include/hw/audio/soundhw.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifndef HW_SOUNDHW_H
-#define HW_SOUNDHW_H
-
-void pci_register_soundhw(const char *name, const char *descr,
-                          int (*init_pci)(PCIBus *bus, const char *audiodev));
-void deprecated_register_soundhw(const char *name, const char *descr,
-                                 int isa, const char *typename);
-
-void soundhw_init(void);
-void audio_print_available_models(void);
-void select_soundhw(const char *name, const char *audiodev);
-
-#endif
diff --git a/hw/audio/ac97.c b/hw/audio/ac97.c
index eb7a847080..2e1be5089e 100644
--- a/hw/audio/ac97.c
+++ b/hw/audio/ac97.c
@@ -18,7 +18,7 @@
  */
 
 #include "qemu/osdep.h"
-#include "hw/audio/soundhw.h"
+#include "hw/audio/model.h"
 #include "audio/audio.h"
 #include "hw/pci/pci_device.h"
 #include "hw/qdev-properties.h"
@@ -1360,8 +1360,7 @@ static const TypeInfo ac97_info = {
 static void ac97_register_types(void)
 {
     type_register_static(&ac97_info);
-    deprecated_register_soundhw("ac97", "Intel 82801AA AC97 Audio",
-                                0, TYPE_AC97);
+    audio_register_model("ac97", "Intel 82801AA AC97 Audio", 0, TYPE_AC97);
 }
 
 type_init(ac97_register_types)
diff --git a/hw/audio/adlib.c b/hw/audio/adlib.c
index 1f29a7e319..a7c2efd87c 100644
--- a/hw/audio/adlib.c
+++ b/hw/audio/adlib.c
@@ -25,7 +25,7 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
 #include "qemu/module.h"
-#include "hw/audio/soundhw.h"
+#include "hw/audio/model.h"
 #include "audio/audio.h"
 #include "hw/isa/isa.h"
 #include "hw/qdev-properties.h"
@@ -323,7 +323,7 @@ static const TypeInfo adlib_info = {
 static void adlib_register_types (void)
 {
     type_register_static (&adlib_info);
-    deprecated_register_soundhw("adlib", ADLIB_DESC, 1, TYPE_ADLIB);
+    audio_register_model("adlib", ADLIB_DESC, 1, TYPE_ADLIB);
 }
 
 type_init (adlib_register_types)
diff --git a/hw/audio/cs4231a.c b/hw/audio/cs4231a.c
index 6dfff202ff..1f7e0a33c0 100644
--- a/hw/audio/cs4231a.c
+++ b/hw/audio/cs4231a.c
@@ -23,7 +23,7 @@
  */
 
 #include "qemu/osdep.h"
-#include "hw/audio/soundhw.h"
+#include "hw/audio/model.h"
 #include "audio/audio.h"
 #include "hw/irq.h"
 #include "hw/isa/isa.h"
@@ -723,7 +723,7 @@ static const TypeInfo cs4231a_info = {
 static void cs4231a_register_types (void)
 {
     type_register_static (&cs4231a_info);
-    deprecated_register_soundhw("cs4231a", "CS4231A", 1, TYPE_CS4231A);
+    audio_register_model("cs4231a", "CS4231A", 1, TYPE_CS4231A);
 }
 
 type_init (cs4231a_register_types)
diff --git a/hw/audio/es1370.c b/hw/audio/es1370.c
index a6a32a6348..913c9022f6 100644
--- a/hw/audio/es1370.c
+++ b/hw/audio/es1370.c
@@ -26,7 +26,7 @@
 #define VERBOSE_ES1370 0
 
 #include "qemu/osdep.h"
-#include "hw/audio/soundhw.h"
+#include "hw/audio/model.h"
 #include "audio/audio.h"
 #include "hw/pci/pci_device.h"
 #include "migration/vmstate.h"
@@ -905,8 +905,7 @@ static const TypeInfo es1370_info = {
 static void es1370_register_types (void)
 {
     type_register_static (&es1370_info);
-    deprecated_register_soundhw("es1370", "ENSONIQ AudioPCI ES1370",
-                                0, TYPE_ES1370);
+    audio_register_model("es1370", "ENSONIQ AudioPCI ES1370", 0, TYPE_ES1370);
 }
 
 type_init (es1370_register_types)
diff --git a/hw/audio/gus.c b/hw/audio/gus.c
index c36df0240f..ac9332ea3d 100644
--- a/hw/audio/gus.c
+++ b/hw/audio/gus.c
@@ -25,7 +25,7 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
 #include "qemu/module.h"
-#include "hw/audio/soundhw.h"
+#include "hw/audio/model.h"
 #include "audio/audio.h"
 #include "hw/irq.h"
 #include "hw/isa/isa.h"
@@ -319,7 +319,7 @@ static const TypeInfo gus_info = {
 static void gus_register_types (void)
 {
     type_register_static (&gus_info);
-    deprecated_register_soundhw("gus", "Gravis Ultrasound GF1", 1, TYPE_GUS);
+    audio_register_model("gus", "Gravis Ultrasound GF1", 1, TYPE_GUS);
 }
 
 type_init (gus_register_types)
diff --git a/hw/audio/intel-hda.c b/hw/audio/intel-hda.c
index b256c8ccea..6a0db0dd9e 100644
--- a/hw/audio/intel-hda.c
+++ b/hw/audio/intel-hda.c
@@ -26,7 +26,7 @@
 #include "qemu/log.h"
 #include "qemu/module.h"
 #include "qemu/error-report.h"
-#include "hw/audio/soundhw.h"
+#include "hw/audio/model.h"
 #include "intel-hda.h"
 #include "migration/vmstate.h"
 #include "intel-hda-defs.h"
@@ -1324,7 +1324,7 @@ static void intel_hda_register_types(void)
     type_register_static(&intel_hda_info_ich6);
     type_register_static(&intel_hda_info_ich9);
     type_register_static(&hda_codec_device_type_info);
-    pci_register_soundhw("hda", "Intel HD Audio", intel_hda_and_codec_init);
+    audio_register_model_with_cb("hda", "Intel HD Audio", intel_hda_and_codec_init);
 }
 
 type_init(intel_hda_register_types)
diff --git a/hw/audio/soundhw.c b/hw/audio/model.c
similarity index 68%
rename from hw/audio/soundhw.c
rename to hw/audio/model.c
index b4a87ff709..668349c69d 100644
--- a/hw/audio/soundhw.c
+++ b/hw/audio/model.c
@@ -32,9 +32,9 @@
 #include "hw/qdev-properties.h"
 #include "hw/isa/isa.h"
 #include "hw/pci/pci.h"
-#include "hw/audio/soundhw.h"
+#include "hw/audio/model.h"
 
-struct soundhw {
+struct audio_model {
     const char *name;
     const char *descr;
     const char *typename;
@@ -42,38 +42,38 @@ struct soundhw {
     int (*init_pci) (PCIBus *bus, const char *audiodev);
 };
 
-static struct soundhw soundhw[9];
-static int soundhw_count;
+static struct audio_model audio_models[9];
+static int audio_models_count;
 
-void pci_register_soundhw(const char *name, const char *descr,
-                          int (*init_pci)(PCIBus *bus, const char *audiodev))
+void audio_register_model_with_cb(const char *name, const char *descr,
+                                  int (*init_pci)(PCIBus *bus, const char *audiodev))
 {
-    assert(soundhw_count < ARRAY_SIZE(soundhw) - 1);
-    soundhw[soundhw_count].name = name;
-    soundhw[soundhw_count].descr = descr;
-    soundhw[soundhw_count].isa = 0;
-    soundhw[soundhw_count].init_pci = init_pci;
-    soundhw_count++;
+    assert(audio_models_count < ARRAY_SIZE(audio_models) - 1);
+    audio_models[audio_models_count].name = name;
+    audio_models[audio_models_count].descr = descr;
+    audio_models[audio_models_count].isa = 0;
+    audio_models[audio_models_count].init_pci = init_pci;
+    audio_models_count++;
 }
 
-void deprecated_register_soundhw(const char *name, const char *descr,
-                                 int isa, const char *typename)
+void audio_register_model(const char *name, const char *descr,
+                          int isa, const char *typename)
 {
-    assert(soundhw_count < ARRAY_SIZE(soundhw) - 1);
-    soundhw[soundhw_count].name = name;
-    soundhw[soundhw_count].descr = descr;
-    soundhw[soundhw_count].isa = isa;
-    soundhw[soundhw_count].typename = typename;
-    soundhw_count++;
+    assert(audio_models_count < ARRAY_SIZE(audio_models) - 1);
+    audio_models[audio_models_count].name = name;
+    audio_models[audio_models_count].descr = descr;
+    audio_models[audio_models_count].isa = isa;
+    audio_models[audio_models_count].typename = typename;
+    audio_models_count++;
 }
 
 void audio_print_available_models(void)
 {
-    struct soundhw *c;
+    struct audio_model *c;
 
-    if (soundhw_count) {
+    if (audio_models_count) {
          printf("Valid audio device model names:\n");
-         for (c = soundhw; c->name; ++c) {
+         for (c = audio_models; c->name; ++c) {
              printf ("%-11s %s\n", c->name, c->descr);
          }
     } else {
@@ -82,19 +82,19 @@ void audio_print_available_models(void)
     }
 }
 
-static struct soundhw *selected = NULL;
+static struct audio_model *selected = NULL;
 static const char *audiodev_id;
 
-void select_soundhw(const char *name, const char *audiodev)
+void audio_set_model(const char *name, const char *audiodev)
 {
-    struct soundhw *c;
+    struct audio_model *c;
 
     if (selected) {
         error_report("only one -audio option is allowed");
         exit(1);
     }
 
-    for (c = soundhw; c->name; ++c) {
+    for (c = audio_models; c->name; ++c) {
         if (g_str_equal(c->name, name)) {
             selected = c;
             audiodev_id = audiodev;
@@ -109,9 +109,9 @@ void select_soundhw(const char *name, const char *audiodev)
     }
 }
 
-void soundhw_init(void)
+void audio_model_init(void)
 {
-    struct soundhw *c = selected;
+    struct audio_model *c = selected;
 
     if (!c) {
         return;
diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index 8ea3a161a4..12a214c566 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -24,7 +24,7 @@
 
 #include "qemu/osdep.h"
 #include "hw/isa/isa.h"
-#include "hw/audio/soundhw.h"
+#include "hw/audio/model.h"
 #include "audio/audio.h"
 #include "qemu/module.h"
 #include "qemu/timer.h"
diff --git a/hw/audio/sb16.c b/hw/audio/sb16.c
index bac64118fe..0d9fa74108 100644
--- a/hw/audio/sb16.c
+++ b/hw/audio/sb16.c
@@ -23,7 +23,7 @@
  */
 
 #include "qemu/osdep.h"
-#include "hw/audio/soundhw.h"
+#include "hw/audio/model.h"
 #include "audio/audio.h"
 #include "hw/irq.h"
 #include "hw/isa/isa.h"
@@ -1471,8 +1471,7 @@ static const TypeInfo sb16_info = {
 static void sb16_register_types (void)
 {
     type_register_static (&sb16_info);
-    deprecated_register_soundhw("sb16", "Creative Sound Blaster 16",
-                                1, TYPE_SB16);
+    audio_register_model("sb16", "Creative Sound Blaster 16", 1, TYPE_SB16);
 }
 
 type_init (sb16_register_types)
diff --git a/hw/audio/virtio-snd-pci.c b/hw/audio/virtio-snd-pci.c
index 9eb0007392..613538e46f 100644
--- a/hw/audio/virtio-snd-pci.c
+++ b/hw/audio/virtio-snd-pci.c
@@ -11,7 +11,7 @@
 #include "qemu/osdep.h"
 #include "qom/object.h"
 #include "qapi/error.h"
-#include "hw/audio/soundhw.h"
+#include "hw/audio/model.h"
 #include "hw/virtio/virtio-pci.h"
 #include "hw/audio/virtio-snd.h"
 
@@ -88,7 +88,7 @@ static int virtio_snd_pci_init(PCIBus *bus, const char *audiodev)
 static void virtio_snd_pci_register(void)
 {
     virtio_pci_types_register(&virtio_snd_pci_info);
-    pci_register_soundhw("virtio", "Virtio Sound", virtio_snd_pci_init);
+    audio_register_model_with_cb("virtio", "Virtio Sound", virtio_snd_pci_init);
 }
 
 type_init(virtio_snd_pci_register);
diff --git a/system/vl.c b/system/vl.c
index 7187b24449..9245ec986c 100644
--- a/system/vl.c
+++ b/system/vl.c
@@ -86,7 +86,7 @@
 #include "migration/snapshot.h"
 #include "system/tpm.h"
 #include "system/dma.h"
-#include "hw/audio/soundhw.h"
+#include "hw/audio/model.h"
 #include "audio/audio.h"
 #include "system/cpus.h"
 #include "system/cpu-timers.h"
@@ -2731,7 +2731,7 @@ static void qemu_create_cli_devices(void)
 {
     DeviceOption *opt;
 
-    soundhw_init();
+    audio_model_init();
 
     qemu_opts_foreach(qemu_find_opts("fw_cfg"),
                       parse_fw_cfg, fw_cfg_find(), &error_fatal);
@@ -3087,7 +3087,7 @@ void qemu_init(int argc, char **argv)
                 visit_free(v);
                 if (model) {
                     audio_add_audiodev(dev);
-                    select_soundhw(model, dev->id);
+                    audio_set_model(model, dev->id);
                     g_free(model);
                 } else {
                     audio_add_default_audiodev(dev, &error_fatal);
diff --git a/hw/audio/meson.build b/hw/audio/meson.build
index 2990974449..2154cbdb57 100644
--- a/hw/audio/meson.build
+++ b/hw/audio/meson.build
@@ -1,4 +1,4 @@
-system_ss.add(files('soundhw.c'))
+system_ss.add(files('model.c'))
 system_ss.add(when: 'CONFIG_AC97', if_true: files('ac97.c'))
 system_ss.add(when: 'CONFIG_ADLIB', if_true: files('fmopl.c', 'adlib.c'))
 system_ss.add(when: 'CONFIG_ASC', if_true: files('asc.c'))
diff --git a/scripts/codeconverter/codeconverter/test_regexps.py b/scripts/codeconverter/codeconverter/test_regexps.py
index 4526268ae8..fe7354b473 100644
--- a/scripts/codeconverter/codeconverter/test_regexps.py
+++ b/scripts/codeconverter/codeconverter/test_regexps.py
@@ -264,7 +264,7 @@ def test_initial_includes():
 #define SILENT_ES1370
 
 #include "qemu/osdep.h"
-#include "hw/audio/soundhw.h"
+#include "hw/audio/model.h"
 #include "audio/audio.h"
 #include "hw/pci/pci.h"
 #include "migration/vmstate.h"
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 12/42] hw/audio/virtio-snd-pci: remove custom model callback
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (10 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 11/42] hw/audio: use better naming for -audio model handling code marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 13/42] hw/audio: simplify 'hda' audio init code marcandre.lureau
                   ` (31 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann,
	Manos Pitsidianakis, Michael S. Tsirkin

From: Marc-André Lureau <marcandre.lureau@redhat.com>

virtio-snd can rely on the default code to instantiate the device and
set the audiodev.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 hw/audio/virtio-snd-pci.c | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)

diff --git a/hw/audio/virtio-snd-pci.c b/hw/audio/virtio-snd-pci.c
index 613538e46f..b78eaff851 100644
--- a/hw/audio/virtio-snd-pci.c
+++ b/hw/audio/virtio-snd-pci.c
@@ -71,24 +71,10 @@ static const VirtioPCIDeviceTypeInfo virtio_snd_pci_info = {
     .class_init    = virtio_snd_pci_class_init,
 };
 
-/* Create a Virtio Sound PCI device, so '-audio driver,model=virtio' works. */
-static int virtio_snd_pci_init(PCIBus *bus, const char *audiodev)
-{
-    DeviceState *vdev = NULL;
-    VirtIOSoundPCI *dev = NULL;
-
-    vdev = qdev_new(TYPE_VIRTIO_SND_PCI);
-    assert(vdev);
-    dev = VIRTIO_SND_PCI(vdev);
-    qdev_prop_set_string(DEVICE(&dev->vdev), "audiodev", audiodev);
-    qdev_realize_and_unref(vdev, BUS(bus), &error_fatal);
-    return 0;
-}
-
 static void virtio_snd_pci_register(void)
 {
     virtio_pci_types_register(&virtio_snd_pci_info);
-    audio_register_model_with_cb("virtio", "Virtio Sound", virtio_snd_pci_init);
+    audio_register_model("virtio", "Virtio Sound", 0, TYPE_VIRTIO_SND_PCI);
 }
 
 type_init(virtio_snd_pci_register);
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 13/42] hw/audio: simplify 'hda' audio init code
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (11 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 12/42] hw/audio/virtio-snd-pci: remove custom model callback marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22 11:41   ` BALATON Zoltan
  2025-10-22  6:56 ` [PATCH v2 14/42] hw/audio: generalize audio_model.init() marcandre.lureau
                   ` (30 subsequent siblings)
  43 siblings, 1 reply; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann

From: Marc-André Lureau <marcandre.lureau@redhat.com>

For consistency, use only qdev_device_add() to instantiate the devices.
We can't rely on automatic bus lookup for the "hda-duplex" device though
as it may end up on a different "intel-hda" bus...

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 hw/audio/intel-hda.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/hw/audio/intel-hda.c b/hw/audio/intel-hda.c
index 6a0db0dd9e..14bcf1257d 100644
--- a/hw/audio/intel-hda.c
+++ b/hw/audio/intel-hda.c
@@ -21,6 +21,7 @@
 #include "hw/pci/pci.h"
 #include "hw/qdev-properties.h"
 #include "hw/pci/msi.h"
+#include "monitor/qdev.h"
 #include "qemu/timer.h"
 #include "qemu/bitops.h"
 #include "qemu/log.h"
@@ -30,6 +31,7 @@
 #include "intel-hda.h"
 #include "migration/vmstate.h"
 #include "intel-hda-defs.h"
+#include "qobject/qdict.h"
 #include "system/dma.h"
 #include "qapi/error.h"
 #include "qom/object.h"
@@ -1305,15 +1307,19 @@ static const TypeInfo hda_codec_device_type_info = {
  */
 static int intel_hda_and_codec_init(PCIBus *bus, const char *audiodev)
 {
-    DeviceState *controller;
+    g_autoptr(QDict) props = qdict_new();
+    DeviceState *intel_hda, *codec;
     BusState *hdabus;
-    DeviceState *codec;
 
-    controller = DEVICE(pci_create_simple(bus, -1, "intel-hda"));
-    hdabus = QLIST_FIRST(&controller->child_bus);
+    qdict_put_str(props, "driver", "intel-hda");
+    intel_hda = qdev_device_add_from_qdict(props, false, &error_fatal);
+    hdabus = QLIST_FIRST(&intel_hda->child_bus);
+
     codec = qdev_new("hda-duplex");
     qdev_prop_set_string(codec, "audiodev", audiodev);
     qdev_realize_and_unref(codec, hdabus, &error_fatal);
+    object_unref(intel_hda);
+
     return 0;
 }
 
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 14/42] hw/audio: generalize audio_model.init()
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (12 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 13/42] hw/audio: simplify 'hda' audio init code marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 15/42] hw/audio: drop audio_model.isa marcandre.lureau
                   ` (29 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann

From: Marc-André Lureau <marcandre.lureau@redhat.com>

It is no longer PCI bus only.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/hw/audio/model.h |  2 +-
 hw/audio/intel-hda.c     |  2 +-
 hw/audio/model.c         | 12 ++++--------
 3 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/include/hw/audio/model.h b/include/hw/audio/model.h
index 27ae7dcc31..55d6ac7f6e 100644
--- a/include/hw/audio/model.h
+++ b/include/hw/audio/model.h
@@ -2,7 +2,7 @@
 #define HW_AUDIO_MODEL_H
 
 void audio_register_model_with_cb(const char *name, const char *descr,
-                                  int (*init_pci)(PCIBus *bus, const char *audiodev));
+                                  int (*init_audio_model)(const char *audiodev));
 void audio_register_model(const char *name, const char *descr,
                           int isa, const char *typename);
 
diff --git a/hw/audio/intel-hda.c b/hw/audio/intel-hda.c
index 14bcf1257d..0d35afa4ab 100644
--- a/hw/audio/intel-hda.c
+++ b/hw/audio/intel-hda.c
@@ -1305,7 +1305,7 @@ static const TypeInfo hda_codec_device_type_info = {
  * create intel hda controller with codec attached to it,
  * so '-soundhw hda' works.
  */
-static int intel_hda_and_codec_init(PCIBus *bus, const char *audiodev)
+static int intel_hda_and_codec_init(const char *audiodev)
 {
     g_autoptr(QDict) props = qdict_new();
     DeviceState *intel_hda, *codec;
diff --git a/hw/audio/model.c b/hw/audio/model.c
index 668349c69d..4f6a234159 100644
--- a/hw/audio/model.c
+++ b/hw/audio/model.c
@@ -24,14 +24,11 @@
 #include "qemu/osdep.h"
 #include "hw/qdev-core.h"
 #include "monitor/qdev.h"
-#include "qemu/option.h"
-#include "qemu/help_option.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "qom/object.h"
 #include "hw/qdev-properties.h"
 #include "hw/isa/isa.h"
-#include "hw/pci/pci.h"
 #include "hw/audio/model.h"
 
 struct audio_model {
@@ -39,20 +36,20 @@ struct audio_model {
     const char *descr;
     const char *typename;
     int isa;
-    int (*init_pci) (PCIBus *bus, const char *audiodev);
+    int (*init)(const char *audiodev);
 };
 
 static struct audio_model audio_models[9];
 static int audio_models_count;
 
 void audio_register_model_with_cb(const char *name, const char *descr,
-                                  int (*init_pci)(PCIBus *bus, const char *audiodev))
+                                  int (*init_audio_model)(const char *audiodev))
 {
     assert(audio_models_count < ARRAY_SIZE(audio_models) - 1);
     audio_models[audio_models_count].name = name;
     audio_models[audio_models_count].descr = descr;
     audio_models[audio_models_count].isa = 0;
-    audio_models[audio_models_count].init_pci = init_pci;
+    audio_models[audio_models_count].init = init_audio_model;
     audio_models_count++;
 }
 
@@ -124,7 +121,6 @@ void audio_model_init(void)
         qdev_realize_and_unref(dev, bus, &error_fatal);
     } else {
         assert(!c->isa);
-        PCIBus *pci_bus = (PCIBus *) object_resolve_path_type("", TYPE_PCI_BUS, NULL);
-        c->init_pci(pci_bus, audiodev_id);
+        c->init(audiodev_id);
     }
 }
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 15/42] hw/audio: drop audio_model.isa
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (13 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 14/42] hw/audio: generalize audio_model.init() marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 16/42] audio: start making AudioState a QOM Object marcandre.lureau
                   ` (28 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann,
	Michael S. Tsirkin, Manos Pitsidianakis

From: Marc-André Lureau <marcandre.lureau@redhat.com>

That's no longer necessary, the code is bus-agnostic.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/hw/audio/model.h  | 2 +-
 hw/audio/ac97.c           | 2 +-
 hw/audio/adlib.c          | 2 +-
 hw/audio/cs4231a.c        | 2 +-
 hw/audio/es1370.c         | 2 +-
 hw/audio/gus.c            | 2 +-
 hw/audio/model.c          | 7 +------
 hw/audio/sb16.c           | 2 +-
 hw/audio/virtio-snd-pci.c | 2 +-
 9 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/include/hw/audio/model.h b/include/hw/audio/model.h
index 55d6ac7f6e..ebe456c22f 100644
--- a/include/hw/audio/model.h
+++ b/include/hw/audio/model.h
@@ -4,7 +4,7 @@
 void audio_register_model_with_cb(const char *name, const char *descr,
                                   int (*init_audio_model)(const char *audiodev));
 void audio_register_model(const char *name, const char *descr,
-                          int isa, const char *typename);
+                          const char *typename);
 
 void audio_model_init(void);
 void audio_print_available_models(void);
diff --git a/hw/audio/ac97.c b/hw/audio/ac97.c
index 2e1be5089e..3d3c667e86 100644
--- a/hw/audio/ac97.c
+++ b/hw/audio/ac97.c
@@ -1360,7 +1360,7 @@ static const TypeInfo ac97_info = {
 static void ac97_register_types(void)
 {
     type_register_static(&ac97_info);
-    audio_register_model("ac97", "Intel 82801AA AC97 Audio", 0, TYPE_AC97);
+    audio_register_model("ac97", "Intel 82801AA AC97 Audio", TYPE_AC97);
 }
 
 type_init(ac97_register_types)
diff --git a/hw/audio/adlib.c b/hw/audio/adlib.c
index a7c2efd87c..0bc0359ae6 100644
--- a/hw/audio/adlib.c
+++ b/hw/audio/adlib.c
@@ -323,7 +323,7 @@ static const TypeInfo adlib_info = {
 static void adlib_register_types (void)
 {
     type_register_static (&adlib_info);
-    audio_register_model("adlib", ADLIB_DESC, 1, TYPE_ADLIB);
+    audio_register_model("adlib", ADLIB_DESC, TYPE_ADLIB);
 }
 
 type_init (adlib_register_types)
diff --git a/hw/audio/cs4231a.c b/hw/audio/cs4231a.c
index 1f7e0a33c0..18db8da324 100644
--- a/hw/audio/cs4231a.c
+++ b/hw/audio/cs4231a.c
@@ -723,7 +723,7 @@ static const TypeInfo cs4231a_info = {
 static void cs4231a_register_types (void)
 {
     type_register_static (&cs4231a_info);
-    audio_register_model("cs4231a", "CS4231A", 1, TYPE_CS4231A);
+    audio_register_model("cs4231a", "CS4231A", TYPE_CS4231A);
 }
 
 type_init (cs4231a_register_types)
diff --git a/hw/audio/es1370.c b/hw/audio/es1370.c
index 913c9022f6..8cb47589c3 100644
--- a/hw/audio/es1370.c
+++ b/hw/audio/es1370.c
@@ -905,7 +905,7 @@ static const TypeInfo es1370_info = {
 static void es1370_register_types (void)
 {
     type_register_static (&es1370_info);
-    audio_register_model("es1370", "ENSONIQ AudioPCI ES1370", 0, TYPE_ES1370);
+    audio_register_model("es1370", "ENSONIQ AudioPCI ES1370", TYPE_ES1370);
 }
 
 type_init (es1370_register_types)
diff --git a/hw/audio/gus.c b/hw/audio/gus.c
index ac9332ea3d..16785ce226 100644
--- a/hw/audio/gus.c
+++ b/hw/audio/gus.c
@@ -319,7 +319,7 @@ static const TypeInfo gus_info = {
 static void gus_register_types (void)
 {
     type_register_static (&gus_info);
-    audio_register_model("gus", "Gravis Ultrasound GF1", 1, TYPE_GUS);
+    audio_register_model("gus", "Gravis Ultrasound GF1", TYPE_GUS);
 }
 
 type_init (gus_register_types)
diff --git a/hw/audio/model.c b/hw/audio/model.c
index 4f6a234159..924a41e0ac 100644
--- a/hw/audio/model.c
+++ b/hw/audio/model.c
@@ -28,14 +28,12 @@
 #include "qapi/error.h"
 #include "qom/object.h"
 #include "hw/qdev-properties.h"
-#include "hw/isa/isa.h"
 #include "hw/audio/model.h"
 
 struct audio_model {
     const char *name;
     const char *descr;
     const char *typename;
-    int isa;
     int (*init)(const char *audiodev);
 };
 
@@ -48,18 +46,16 @@ void audio_register_model_with_cb(const char *name, const char *descr,
     assert(audio_models_count < ARRAY_SIZE(audio_models) - 1);
     audio_models[audio_models_count].name = name;
     audio_models[audio_models_count].descr = descr;
-    audio_models[audio_models_count].isa = 0;
     audio_models[audio_models_count].init = init_audio_model;
     audio_models_count++;
 }
 
 void audio_register_model(const char *name, const char *descr,
-                          int isa, const char *typename)
+                          const char *typename)
 {
     assert(audio_models_count < ARRAY_SIZE(audio_models) - 1);
     audio_models[audio_models_count].name = name;
     audio_models[audio_models_count].descr = descr;
-    audio_models[audio_models_count].isa = isa;
     audio_models[audio_models_count].typename = typename;
     audio_models_count++;
 }
@@ -120,7 +116,6 @@ void audio_model_init(void)
         qdev_prop_set_string(dev, "audiodev", audiodev_id);
         qdev_realize_and_unref(dev, bus, &error_fatal);
     } else {
-        assert(!c->isa);
         c->init(audiodev_id);
     }
 }
diff --git a/hw/audio/sb16.c b/hw/audio/sb16.c
index 0d9fa74108..cd7e813d05 100644
--- a/hw/audio/sb16.c
+++ b/hw/audio/sb16.c
@@ -1471,7 +1471,7 @@ static const TypeInfo sb16_info = {
 static void sb16_register_types (void)
 {
     type_register_static (&sb16_info);
-    audio_register_model("sb16", "Creative Sound Blaster 16", 1, TYPE_SB16);
+    audio_register_model("sb16", "Creative Sound Blaster 16", TYPE_SB16);
 }
 
 type_init (sb16_register_types)
diff --git a/hw/audio/virtio-snd-pci.c b/hw/audio/virtio-snd-pci.c
index b78eaff851..230581ed63 100644
--- a/hw/audio/virtio-snd-pci.c
+++ b/hw/audio/virtio-snd-pci.c
@@ -74,7 +74,7 @@ static const VirtioPCIDeviceTypeInfo virtio_snd_pci_info = {
 static void virtio_snd_pci_register(void)
 {
     virtio_pci_types_register(&virtio_snd_pci_info);
-    audio_register_model("virtio", "Virtio Sound", 0, TYPE_VIRTIO_SND_PCI);
+    audio_register_model("virtio", "Virtio Sound", TYPE_VIRTIO_SND_PCI);
 }
 
 type_init(virtio_snd_pci_register);
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 16/42] audio: start making AudioState a QOM Object
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (14 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 15/42] hw/audio: drop audio_model.isa marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 17/42] audio: register backends in /audiodevs container marcandre.lureau
                   ` (27 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann

From: Marc-André Lureau <marcandre.lureau@redhat.com>

QOM brings some conveniences for introspection, type checking, reference
counting, interfaces etc. This is only the first step to introduce QOM
in audio/ (I have more in the pipeline)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 audio/audio.h     |  7 +++++++
 audio/audio_int.h |  2 ++
 audio/audio.c     | 43 ++++++++++++++++++++++++++++++++-----------
 3 files changed, 41 insertions(+), 11 deletions(-)

diff --git a/audio/audio.h b/audio/audio.h
index eb5b5d662d..e41c5bc55a 100644
--- a/audio/audio.h
+++ b/audio/audio.h
@@ -80,6 +80,10 @@ typedef struct SWVoiceOut SWVoiceOut;
 typedef struct CaptureVoiceOut CaptureVoiceOut;
 typedef struct SWVoiceIn SWVoiceIn;
 
+struct AudioStateClass {
+    ObjectClass parent_class;
+};
+
 typedef struct AudioState AudioState;
 typedef struct QEMUSoundCard {
     char *name;
@@ -182,4 +186,7 @@ const char *audio_get_id(QEMUSoundCard *card);
 #define DEFINE_AUDIO_PROPERTIES(_s, _f)         \
     DEFINE_PROP_AUDIODEV("audiodev", _s, _f)
 
+#define TYPE_AUDIO_STATE "audio-state"
+OBJECT_DECLARE_TYPE(AudioState, AudioStateClass, AUDIO_STATE)
+
 #endif /* QEMU_AUDIO_H */
diff --git a/audio/audio_int.h b/audio/audio_int.h
index f78ca05f92..b2b4d2d10e 100644
--- a/audio/audio_int.h
+++ b/audio/audio_int.h
@@ -217,6 +217,8 @@ struct SWVoiceCap {
 };
 
 typedef struct AudioState {
+    Object parent;
+
     struct audio_driver *drv;
     Audiodev *dev;
     void *drv_opaque;
diff --git a/audio/audio.c b/audio/audio.c
index 6197fa1788..754952ce58 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -1617,8 +1617,19 @@ static void audio_vm_change_state_handler (void *opaque, bool running,
     audio_reset_timer (s);
 }
 
-static void free_audio_state(AudioState *s)
+static void audio_state_init(Object *obj)
 {
+    AudioState *s = AUDIO_STATE(obj);
+
+    QLIST_INIT (&s->hw_head_out);
+    QLIST_INIT (&s->hw_head_in);
+    QLIST_INIT (&s->cap_head);
+    s->ts = timer_new_ns(QEMU_CLOCK_VIRTUAL, audio_timer, s);
+}
+
+static void audio_state_finalize(Object *obj)
+{
+    AudioState *s = AUDIO_STATE(obj);
     HWVoiceOut *hwo, *hwon;
     HWVoiceIn *hwi, *hwin;
 
@@ -1663,8 +1674,6 @@ static void free_audio_state(AudioState *s)
         timer_free(s->ts);
         s->ts = NULL;
     }
-
-    g_free(s);
 }
 
 void audio_cleanup(void)
@@ -1673,7 +1682,7 @@ void audio_cleanup(void)
     while (!QTAILQ_EMPTY(&audio_states)) {
         AudioState *s = QTAILQ_FIRST(&audio_states);
         QTAILQ_REMOVE(&audio_states, s, list);
-        free_audio_state(s);
+        object_unref(s);
     }
 }
 
@@ -1732,18 +1741,13 @@ static AudioState *audio_init(Audiodev *dev, Error **errp)
     AudioState *s;
     struct audio_driver *driver;
 
-    s = g_new0(AudioState, 1);
+    s = AUDIO_STATE(object_new(TYPE_AUDIO_STATE));
 
-    QLIST_INIT (&s->hw_head_out);
-    QLIST_INIT (&s->hw_head_in);
-    QLIST_INIT (&s->cap_head);
     if (!atexit_registered) {
         atexit(audio_cleanup);
         atexit_registered = true;
     }
 
-    s->ts = timer_new_ns(QEMU_CLOCK_VIRTUAL, audio_timer, s);
-
     if (dev) {
         /* -audiodev option */
         s->dev = dev;
@@ -1796,7 +1800,7 @@ static AudioState *audio_init(Audiodev *dev, Error **errp)
     return s;
 
 out:
-    free_audio_state(s);
+    object_unref(s);
     return NULL;
 }
 
@@ -2320,3 +2324,20 @@ AudiodevList *qmp_query_audiodevs(Error **errp)
     }
     return ret;
 }
+
+static const TypeInfo audio_state_info = {
+    .name = TYPE_AUDIO_STATE,
+    .parent = TYPE_OBJECT,
+    .instance_size = sizeof(AudioState),
+    .instance_init = audio_state_init,
+    .instance_finalize = audio_state_finalize,
+    .abstract = false, // todo, subclass and make it abstract
+    .class_size = sizeof(AudioStateClass),
+};
+
+static void register_types(void)
+{
+    type_register_static(&audio_state_info);
+}
+
+type_init(register_types);
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 17/42] audio: register backends in /audiodevs container
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (15 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 16/42] audio: start making AudioState a QOM Object marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 18/42] audio: use /audiodevs QOM container marcandre.lureau
                   ` (26 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann,
	Daniel P. Berrangé, Eduardo Habkost

From: Marc-André Lureau <marcandre.lureau@redhat.com>

QOM tree now has /audiodevs objects.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 audio/audio.c | 8 ++++++++
 qom/object.c  | 1 +
 2 files changed, 9 insertions(+)

diff --git a/audio/audio.c b/audio/audio.c
index 754952ce58..3f40120db0 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -1676,6 +1676,11 @@ static void audio_state_finalize(Object *obj)
     }
 }
 
+static Object *get_audiodevs_root(void)
+{
+    return object_get_container("audiodevs");
+}
+
 void audio_cleanup(void)
 {
     default_audio_state = NULL;
@@ -1742,6 +1747,9 @@ static AudioState *audio_init(Audiodev *dev, Error **errp)
     struct audio_driver *driver;
 
     s = AUDIO_STATE(object_new(TYPE_AUDIO_STATE));
+    if (!object_property_try_add_child(get_audiodevs_root(), dev->id, OBJECT(s), errp)) {
+        goto out;
+    }
 
     if (!atexit_registered) {
         atexit(audio_cleanup);
diff --git a/qom/object.c b/qom/object.c
index 1856bb36c7..4f32c1aba7 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1730,6 +1730,7 @@ const char *object_property_get_type(Object *obj, const char *name, Error **errp
 }
 
 static const char *const root_containers[] = {
+    "audiodevs",
     "chardevs",
     "objects",
     "backend"
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 18/42] audio: use /audiodevs QOM container
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (16 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 17/42] audio: register backends in /audiodevs container marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 19/42] audio/paaudio: remove needless return value marcandre.lureau
                   ` (25 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann

From: Marc-André Lureau <marcandre.lureau@redhat.com>

audio_cleanup() is already called at exit (similar to chardev)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 audio/audio_int.h |  2 --
 audio/audio.c     | 38 +++++++++++++-------------------------
 2 files changed, 13 insertions(+), 27 deletions(-)

diff --git a/audio/audio_int.h b/audio/audio_int.h
index b2b4d2d10e..4187a2dbfc 100644
--- a/audio/audio_int.h
+++ b/audio/audio_int.h
@@ -235,8 +235,6 @@ typedef struct AudioState {
 
     bool timer_running;
     uint64_t timer_last;
-
-    QTAILQ_ENTRY(AudioState) list;
 } AudioState;
 
 extern const struct mixeng_volume nominal_volume;
diff --git a/audio/audio.c b/audio/audio.c
index 3f40120db0..3af5f2670b 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -102,8 +102,6 @@ static audio_driver *audio_driver_lookup(const char *name)
     return NULL;
 }
 
-static QTAILQ_HEAD(AudioStateHead, AudioState) audio_states =
-    QTAILQ_HEAD_INITIALIZER(audio_states);
 static AudioState *default_audio_state;
 
 const struct mixeng_volume nominal_volume = {
@@ -1684,11 +1682,8 @@ static Object *get_audiodevs_root(void)
 void audio_cleanup(void)
 {
     default_audio_state = NULL;
-    while (!QTAILQ_EMPTY(&audio_states)) {
-        AudioState *s = QTAILQ_FIRST(&audio_states);
-        QTAILQ_REMOVE(&audio_states, s, list);
-        object_unref(s);
-    }
+
+    object_unparent(get_audiodevs_root());
 }
 
 static bool vmstate_audio_needed(void *opaque)
@@ -1739,7 +1734,6 @@ void audio_create_default_audiodevs(void)
  */
 static AudioState *audio_init(Audiodev *dev, Error **errp)
 {
-    static bool atexit_registered;
     int done = 0;
     const char *drvname;
     VMChangeStateEntry *vmse;
@@ -1747,14 +1741,6 @@ static AudioState *audio_init(Audiodev *dev, Error **errp)
     struct audio_driver *driver;
 
     s = AUDIO_STATE(object_new(TYPE_AUDIO_STATE));
-    if (!object_property_try_add_child(get_audiodevs_root(), dev->id, OBJECT(s), errp)) {
-        goto out;
-    }
-
-    if (!atexit_registered) {
-        atexit(audio_cleanup);
-        atexit_registered = true;
-    }
 
     if (dev) {
         /* -audiodev option */
@@ -1802,7 +1788,10 @@ static AudioState *audio_init(Audiodev *dev, Error **errp)
                "(Audio can continue looping even after stopping the VM)\n");
     }
 
-    QTAILQ_INSERT_TAIL(&audio_states, s, list);
+    if (!object_property_try_add_child(get_audiodevs_root(), dev->id, OBJECT(s), errp)) {
+        goto out;
+    }
+    object_unref(s);
     QLIST_INIT (&s->card_head);
     vmstate_register_any(NULL, &vmstate_audio, s);
     return s;
@@ -2249,15 +2238,14 @@ int audio_buffer_bytes(AudiodevPerDirectionOptions *pdo,
 
 AudioState *audio_state_by_name(const char *name, Error **errp)
 {
-    AudioState *s;
-    QTAILQ_FOREACH(s, &audio_states, list) {
-        assert(s->dev);
-        if (strcmp(name, s->dev->id) == 0) {
-            return s;
-        }
+    Object *obj = object_resolve_path_component(get_audiodevs_root(), name);
+
+    if (!obj) {
+        error_setg(errp, "audiodev '%s' not found", name);
+        return NULL;
+    } else {
+        return AUDIO_STATE(obj);
     }
-    error_setg(errp, "audiodev '%s' not found", name);
-    return NULL;
 }
 
 const char *audio_get_id(QEMUSoundCard *card)
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 19/42] audio/paaudio: remove needless return value
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (17 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 18/42] audio: use /audiodevs QOM container marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 20/42] audio/dsound: simplify init() marcandre.lureau
                   ` (24 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 audio/paaudio.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/audio/paaudio.c b/audio/paaudio.c
index f3193b08c3..93030f3fc8 100644
--- a/audio/paaudio.c
+++ b/audio/paaudio.c
@@ -747,14 +747,13 @@ static void qpa_volume_in(HWVoiceIn *hw, Volume *vol)
     pa_threaded_mainloop_unlock(c->mainloop);
 }
 
-static int qpa_validate_per_direction_opts(Audiodev *dev,
-                                           AudiodevPaPerDirectionOptions *pdo)
+static void qpa_validate_per_direction_opts(Audiodev *dev,
+                                            AudiodevPaPerDirectionOptions *pdo)
 {
     if (!pdo->has_latency) {
         pdo->has_latency = true;
         pdo->latency = 46440;
     }
-    return 1;
 }
 
 /* common */
@@ -844,12 +843,8 @@ static void *qpa_audio_init(Audiodev *dev, Error **errp)
         }
     }
 
-    if (!qpa_validate_per_direction_opts(dev, popts->in)) {
-        return NULL;
-    }
-    if (!qpa_validate_per_direction_opts(dev, popts->out)) {
-        return NULL;
-    }
+    qpa_validate_per_direction_opts(dev, popts->in);
+    qpa_validate_per_direction_opts(dev, popts->out);
 
     g = g_new0(paaudio, 1);
     server = popts->server;
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 20/42] audio/dsound: simplify init()
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (18 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 19/42] audio/paaudio: remove needless return value marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 21/42] audio/dsound: report init error via **errp marcandre.lureau
                   ` (23 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Use dsound_audio_fini() on error & fail if the capture failed to
initialize too.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 audio/dsoundaudio.c | 29 +++++++++++------------------
 1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/audio/dsoundaudio.c b/audio/dsoundaudio.c
index f3bb48d007..d54d79d41c 100644
--- a/audio/dsoundaudio.c
+++ b/audio/dsoundaudio.c
@@ -638,7 +638,7 @@ static void *dsound_audio_init(Audiodev *dev, Error **errp)
     hr = CoInitialize (NULL);
     if (FAILED (hr)) {
         dsound_logerr (hr, "Could not initialize COM\n");
-        g_free(s);
+        dsound_audio_fini(s);
         return NULL;
     }
 
@@ -651,19 +651,14 @@ static void *dsound_audio_init(Audiodev *dev, Error **errp)
         );
     if (FAILED (hr)) {
         dsound_logerr (hr, "Could not create DirectSound instance\n");
-        g_free(s);
+        dsound_audio_fini(s);
         return NULL;
     }
 
     hr = IDirectSound_Initialize (s->dsound, NULL);
     if (FAILED (hr)) {
         dsound_logerr (hr, "Could not initialize DirectSound\n");
-
-        hr = IDirectSound_Release (s->dsound);
-        if (FAILED (hr)) {
-            dsound_logerr (hr, "Could not release DirectSound\n");
-        }
-        g_free(s);
+        dsound_audio_fini(s);
         return NULL;
     }
 
@@ -676,17 +671,15 @@ static void *dsound_audio_init(Audiodev *dev, Error **errp)
         );
     if (FAILED (hr)) {
         dsound_logerr (hr, "Could not create DirectSoundCapture instance\n");
-    } else {
-        hr = IDirectSoundCapture_Initialize (s->dsound_capture, NULL);
-        if (FAILED (hr)) {
-            dsound_logerr (hr, "Could not initialize DirectSoundCapture\n");
+        dsound_audio_fini(s);
+        return NULL;
+    }
 
-            hr = IDirectSoundCapture_Release (s->dsound_capture);
-            if (FAILED (hr)) {
-                dsound_logerr (hr, "Could not release DirectSoundCapture\n");
-            }
-            s->dsound_capture = NULL;
-        }
+    hr = IDirectSoundCapture_Initialize (s->dsound_capture, NULL);
+    if (FAILED (hr)) {
+        dsound_logerr (hr, "Could not initialize DirectSoundCapture\n");
+        dsound_audio_fini(s);
+        return NULL;
     }
 
     err = dsound_set_cooperative_level(s);
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 21/42] audio/dsound: report init error via **errp
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (19 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 20/42] audio/dsound: simplify init() marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 22/42] audio: simplify audio_driver_init() marcandre.lureau
                   ` (22 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Whenever NULL is returned, errp should be set.

Inline SetCooperativeLevel call to simplify code.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 audio/dsoundaudio.c | 182 +++++++++++++++++++-------------------------
 1 file changed, 79 insertions(+), 103 deletions(-)

diff --git a/audio/dsoundaudio.c b/audio/dsoundaudio.c
index d54d79d41c..6a8b7f1a19 100644
--- a/audio/dsoundaudio.c
+++ b/audio/dsoundaudio.c
@@ -33,6 +33,7 @@
 #include "audio_int.h"
 #include "qemu/host-utils.h"
 #include "qemu/module.h"
+#include "qapi/error.h"
 
 #include <windows.h>
 #include <mmsystem.h>
@@ -64,162 +65,154 @@ typedef struct {
     dsound *s;
 } DSoundVoiceIn;
 
-static void dsound_log_hresult (HRESULT hr)
+static const char *dserror (HRESULT hr)
 {
-    const char *str = "BUG";
-
     switch (hr) {
     case DS_OK:
-        str = "The method succeeded";
-        break;
+        return "The method succeeded";
 #ifdef DS_NO_VIRTUALIZATION
     case DS_NO_VIRTUALIZATION:
-        str = "The buffer was created, but another 3D algorithm was substituted";
-        break;
+        return "The buffer was created, but another 3D algorithm was substituted";
 #endif
 #ifdef DS_INCOMPLETE
     case DS_INCOMPLETE:
-        str = "The method succeeded, but not all the optional effects were obtained";
-        break;
+        return "The method succeeded, but not all the optional effects were obtained";
 #endif
 #ifdef DSERR_ACCESSDENIED
     case DSERR_ACCESSDENIED:
-        str = "The request failed because access was denied";
-        break;
+        return "The request failed because access was denied";
 #endif
 #ifdef DSERR_ALLOCATED
     case DSERR_ALLOCATED:
-        str = "The request failed because resources, "
-              "such as a priority level, were already in use "
-              "by another caller";
-        break;
+        return "The request failed because resources, "
+               "such as a priority level, were already in use "
+               "by another caller";
 #endif
 #ifdef DSERR_ALREADYINITIALIZED
     case DSERR_ALREADYINITIALIZED:
-        str = "The object is already initialized";
-        break;
+        return "The object is already initialized";
 #endif
 #ifdef DSERR_BADFORMAT
     case DSERR_BADFORMAT:
-        str = "The specified wave format is not supported";
-        break;
+        return "The specified wave format is not supported";
 #endif
 #ifdef DSERR_BADSENDBUFFERGUID
     case DSERR_BADSENDBUFFERGUID:
-        str = "The GUID specified in an audiopath file "
-              "does not match a valid mix-in buffer";
-        break;
+        return "The GUID specified in an audiopath file "
+               "does not match a valid mix-in buffer";
 #endif
 #ifdef DSERR_BUFFERLOST
     case DSERR_BUFFERLOST:
-        str = "The buffer memory has been lost and must be restored";
-        break;
+        return "The buffer memory has been lost and must be restored";
 #endif
 #ifdef DSERR_BUFFERTOOSMALL
     case DSERR_BUFFERTOOSMALL:
-        str = "The buffer size is not great enough to "
-              "enable effects processing";
-        break;
+        return "The buffer size is not great enough to "
+               "enable effects processing";
 #endif
 #ifdef DSERR_CONTROLUNAVAIL
     case DSERR_CONTROLUNAVAIL:
-        str = "The buffer control (volume, pan, and so on) "
-              "requested by the caller is not available. "
-              "Controls must be specified when the buffer is created, "
-              "using the dwFlags member of DSBUFFERDESC";
-        break;
+        return "The buffer control (volume, pan, and so on) "
+               "requested by the caller is not available. "
+               "Controls must be specified when the buffer is created, "
+               "using the dwFlags member of DSBUFFERDESC";
 #endif
 #ifdef DSERR_DS8_REQUIRED
     case DSERR_DS8_REQUIRED:
-        str = "A DirectSound object of class CLSID_DirectSound8 or later "
-              "is required for the requested functionality. "
-              "For more information, see IDirectSound8 Interface";
-        break;
+        return "A DirectSound object of class CLSID_DirectSound8 or later "
+               "is required for the requested functionality. "
+               "For more information, see IDirectSound8 Interface";
 #endif
 #ifdef DSERR_FXUNAVAILABLE
     case DSERR_FXUNAVAILABLE:
-        str = "The effects requested could not be found on the system, "
-              "or they are in the wrong order or in the wrong location; "
-              "for example, an effect expected in hardware "
-              "was found in software";
-        break;
+        return "The effects requested could not be found on the system, "
+               "or they are in the wrong order or in the wrong location; "
+               "for example, an effect expected in hardware "
+               "was found in software";
 #endif
 #ifdef DSERR_GENERIC
     case DSERR_GENERIC:
-        str = "An undetermined error occurred inside the DirectSound subsystem";
-        break;
+        return "An undetermined error occurred inside the DirectSound subsystem";
 #endif
 #ifdef DSERR_INVALIDCALL
     case DSERR_INVALIDCALL:
-        str = "This function is not valid for the current state of this object";
-        break;
+        return "This function is not valid for the current state of this object";
 #endif
 #ifdef DSERR_INVALIDPARAM
     case DSERR_INVALIDPARAM:
-        str = "An invalid parameter was passed to the returning function";
-        break;
+        return "An invalid parameter was passed to the returning function";
 #endif
 #ifdef DSERR_NOAGGREGATION
     case DSERR_NOAGGREGATION:
-        str = "The object does not support aggregation";
-        break;
+        return "The object does not support aggregation";
 #endif
 #ifdef DSERR_NODRIVER
     case DSERR_NODRIVER:
-        str = "No sound driver is available for use, "
-              "or the given GUID is not a valid DirectSound device ID";
-        break;
+        return "No sound driver is available for use, "
+               "or the given GUID is not a valid DirectSound device ID";
 #endif
 #ifdef DSERR_NOINTERFACE
     case DSERR_NOINTERFACE:
-        str = "The requested COM interface is not available";
-        break;
+        return "The requested COM interface is not available";
 #endif
 #ifdef DSERR_OBJECTNOTFOUND
     case DSERR_OBJECTNOTFOUND:
-        str = "The requested object was not found";
-        break;
+        return "The requested object was not found";
 #endif
 #ifdef DSERR_OTHERAPPHASPRIO
     case DSERR_OTHERAPPHASPRIO:
-        str = "Another application has a higher priority level, "
+        return "Another application has a higher priority level, "
               "preventing this call from succeeding";
-        break;
 #endif
 #ifdef DSERR_OUTOFMEMORY
     case DSERR_OUTOFMEMORY:
-        str = "The DirectSound subsystem could not allocate "
+        return "The DirectSound subsystem could not allocate "
                "sufficient memory to complete the caller's request";
-        break;
 #endif
 #ifdef DSERR_PRIOLEVELNEEDED
     case DSERR_PRIOLEVELNEEDED:
-        str = "A cooperative level of DSSCL_PRIORITY or higher is required";
-        break;
+        return "A cooperative level of DSSCL_PRIORITY or higher is required";
 #endif
 #ifdef DSERR_SENDLOOP
     case DSERR_SENDLOOP:
-        str = "A circular loop of send effects was detected";
-        break;
+        return "A circular loop of send effects was detected";
 #endif
 #ifdef DSERR_UNINITIALIZED
     case DSERR_UNINITIALIZED:
-        str = "The Initialize method has not been called "
-              "or has not been called successfully "
-              "before other methods were called";
-        break;
+        return "The Initialize method has not been called "
+               "or has not been called successfully "
+               "before other methods were called";
 #endif
 #ifdef DSERR_UNSUPPORTED
     case DSERR_UNSUPPORTED:
-        str = "The function called is not supported at this time";
-        break;
+        return "The function called is not supported at this time";
 #endif
     default:
-        AUD_log (AUDIO_CAP, "Reason: Unknown (HRESULT 0x%lx)\n", hr);
-        return;
+        return NULL;
+    }
+
+}
+
+static void dserror_set(Error **errp, HRESULT hr, const char *msg)
+{
+    const char *str = dserror(hr);
+
+    if (str) {
+        error_setg(errp, "%s: %s", msg, str);
+    } else {
+        error_setg(errp, "%s: Unknown (HRESULT: 0x%lx)", msg, hr);
     }
+}
+
+static void dsound_log_hresult (HRESULT hr)
+{
+    const char *str = dserror(hr);
 
-    AUD_log (AUDIO_CAP, "Reason: %s\n", str);
+    if (str) {
+        AUD_log (AUDIO_CAP, "Reason: %s\n", str);
+    } else {
+        AUD_log (AUDIO_CAP, "Reason: Unknown (HRESULT: 0x%lx)\n", hr);
+    }
 }
 
 static void G_GNUC_PRINTF (2, 3) dsound_logerr (
@@ -359,27 +352,6 @@ static void dsound_clear_sample (HWVoiceOut *hw, LPDIRECTSOUNDBUFFER dsb,
     dsound_unlock_out (dsb, p1, p2, blen1, blen2);
 }
 
-static int dsound_set_cooperative_level(dsound *s)
-{
-    HRESULT hr;
-    HWND hwnd;
-
-    hwnd = GetDesktopWindow();
-    hr = IDirectSound_SetCooperativeLevel (
-        s->dsound,
-        hwnd,
-        DSSCL_PRIORITY
-        );
-
-    if (FAILED (hr)) {
-        dsound_logerr (hr, "Could not set cooperative level for window %p\n",
-                       hwnd);
-        return -1;
-    }
-
-    return 0;
-}
-
 static void dsound_enable_out(HWVoiceOut *hw, bool enable)
 {
     HRESULT hr;
@@ -621,7 +593,6 @@ static void dsound_audio_fini (void *opaque)
 
 static void *dsound_audio_init(Audiodev *dev, Error **errp)
 {
-    int err;
     HRESULT hr;
     dsound *s = g_new0(dsound, 1);
     AudiodevDsoundOptions *dso;
@@ -637,7 +608,7 @@ static void *dsound_audio_init(Audiodev *dev, Error **errp)
 
     hr = CoInitialize (NULL);
     if (FAILED (hr)) {
-        dsound_logerr (hr, "Could not initialize COM\n");
+        dserror_set(errp, hr, "Could not initialize COM");
         dsound_audio_fini(s);
         return NULL;
     }
@@ -650,14 +621,14 @@ static void *dsound_audio_init(Audiodev *dev, Error **errp)
         (void **) &s->dsound
         );
     if (FAILED (hr)) {
-        dsound_logerr (hr, "Could not create DirectSound instance\n");
+        dserror_set(errp, hr, "Could not create DirectSound instance");
         dsound_audio_fini(s);
         return NULL;
     }
 
     hr = IDirectSound_Initialize (s->dsound, NULL);
     if (FAILED (hr)) {
-        dsound_logerr (hr, "Could not initialize DirectSound\n");
+        dserror_set(errp, hr, "Could not initialize DirectSound");
         dsound_audio_fini(s);
         return NULL;
     }
@@ -670,21 +641,26 @@ static void *dsound_audio_init(Audiodev *dev, Error **errp)
         (void **) &s->dsound_capture
         );
     if (FAILED (hr)) {
-        dsound_logerr (hr, "Could not create DirectSoundCapture instance\n");
+        dserror_set(errp, hr, "Could not create DirectSoundCapture instance");
         dsound_audio_fini(s);
         return NULL;
     }
 
     hr = IDirectSoundCapture_Initialize (s->dsound_capture, NULL);
     if (FAILED (hr)) {
-        dsound_logerr (hr, "Could not initialize DirectSoundCapture\n");
+        dserror_set(errp, hr, "Could not initialize DirectSoundCapture");
         dsound_audio_fini(s);
         return NULL;
     }
 
-    err = dsound_set_cooperative_level(s);
-    if (err) {
-        dsound_audio_fini (s);
+    hr = IDirectSound_SetCooperativeLevel (
+        s->dsound,
+        GetDesktopWindow(),
+        DSSCL_PRIORITY
+    );
+    if (FAILED (hr)) {
+        dserror_set(errp, hr, "Could not set cooperative level");
+        dsound_audio_fini(s);
         return NULL;
     }
 
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 22/42] audio: simplify audio_driver_init()
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (20 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 21/42] audio/dsound: report init error via **errp marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 23/42] audio: move period tick initialization marcandre.lureau
                   ` (21 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Catch and return from error early to avoid indentations and ease the
flow & return a bool for success value. All driver init() calls have
been checked to set errp on error.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 audio/audio.c | 48 ++++++++++++++++++++----------------------------
 1 file changed, 20 insertions(+), 28 deletions(-)

diff --git a/audio/audio.c b/audio/audio.c
index 3af5f2670b..bffb8cddb0 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -1562,35 +1562,27 @@ size_t audio_generic_read(HWVoiceIn *hw, void *buf, size_t size)
     return total;
 }
 
-static int audio_driver_init(AudioState *s, struct audio_driver *drv,
-                             Audiodev *dev, Error **errp)
+static bool audio_driver_init(AudioState *s, struct audio_driver *drv,
+                              Audiodev *dev, Error **errp)
 {
-    Error *local_err = NULL;
-
-    s->drv_opaque = drv->init(dev, &local_err);
-
-    if (s->drv_opaque) {
-        if (!drv->pcm_ops->get_buffer_in) {
-            drv->pcm_ops->get_buffer_in = audio_generic_get_buffer_in;
-            drv->pcm_ops->put_buffer_in = audio_generic_put_buffer_in;
-        }
-        if (!drv->pcm_ops->get_buffer_out) {
-            drv->pcm_ops->get_buffer_out = audio_generic_get_buffer_out;
-            drv->pcm_ops->put_buffer_out = audio_generic_put_buffer_out;
-        }
+    s->drv_opaque = drv->init(dev, errp);
+    if (!s->drv_opaque) {
+        return false;
+    }
 
-        audio_init_nb_voices_out(s, drv, 1);
-        audio_init_nb_voices_in(s, drv, 0);
-        s->drv = drv;
-        return 0;
-    } else {
-        if (local_err) {
-            error_propagate(errp, local_err);
-        } else {
-            error_setg(errp, "Could not init `%s' audio driver", drv->name);
-        }
-        return -1;
+    if (!drv->pcm_ops->get_buffer_in) {
+        drv->pcm_ops->get_buffer_in = audio_generic_get_buffer_in;
+        drv->pcm_ops->put_buffer_in = audio_generic_put_buffer_in;
     }
+    if (!drv->pcm_ops->get_buffer_out) {
+        drv->pcm_ops->get_buffer_out = audio_generic_get_buffer_out;
+        drv->pcm_ops->put_buffer_out = audio_generic_put_buffer_out;
+    }
+
+    audio_init_nb_voices_out(s, drv, 1);
+    audio_init_nb_voices_in(s, drv, 0);
+    s->drv = drv;
+    return true;
 }
 
 static void audio_vm_change_state_handler (void *opaque, bool running,
@@ -1748,7 +1740,7 @@ static AudioState *audio_init(Audiodev *dev, Error **errp)
         drvname = AudiodevDriver_str(dev->driver);
         driver = audio_driver_lookup(drvname);
         if (driver) {
-            done = !audio_driver_init(s, driver, dev, errp);
+            done = audio_driver_init(s, driver, dev, errp);
         } else {
             error_setg(errp, "Unknown audio driver `%s'", drvname);
         }
@@ -1768,7 +1760,7 @@ static AudioState *audio_init(Audiodev *dev, Error **errp)
             g_free(e);
             drvname = AudiodevDriver_str(dev->driver);
             driver = audio_driver_lookup(drvname);
-            if (!audio_driver_init(s, driver, dev, NULL)) {
+            if (audio_driver_init(s, driver, dev, NULL)) {
                 break;
             }
             qapi_free_Audiodev(dev);
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 23/42] audio: move period tick initialization
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (21 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 22/42] audio: simplify audio_driver_init() marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 24/42] audio: drop needless error message marcandre.lureau
                   ` (20 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Part of QOM-ification.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 audio/audio.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/audio/audio.c b/audio/audio.c
index bffb8cddb0..dcaf86a586 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -1582,6 +1582,13 @@ static bool audio_driver_init(AudioState *s, struct audio_driver *drv,
     audio_init_nb_voices_out(s, drv, 1);
     audio_init_nb_voices_in(s, drv, 0);
     s->drv = drv;
+
+    if (dev->timer_period <= 0) {
+        s->period_ticks = 1;
+    } else {
+        s->period_ticks = dev->timer_period * (int64_t)SCALE_US;
+    }
+
     return true;
 }
 
@@ -1768,12 +1775,6 @@ static AudioState *audio_init(Audiodev *dev, Error **errp)
         }
     }
 
-    if (dev->timer_period <= 0) {
-        s->period_ticks = 1;
-    } else {
-        s->period_ticks = dev->timer_period * (int64_t)SCALE_US;
-    }
-
     vmse = qemu_add_vm_change_state_handler (audio_vm_change_state_handler, s);
     if (!vmse) {
         dolog ("warning: Could not register change state handler\n"
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 24/42] audio: drop needless error message
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (22 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 23/42] audio: move period tick initialization marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 25/42] audio: clean-up vmstate change handler on finalize marcandre.lureau
                   ` (19 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann

From: Marc-André Lureau <marcandre.lureau@redhat.com>

The only reason it would fail to add the handler is if it's calling a
stub. But this cannot happen as audio is only supported with system qemu.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 audio/audio.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/audio/audio.c b/audio/audio.c
index dcaf86a586..4478041e5d 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -1776,10 +1776,7 @@ static AudioState *audio_init(Audiodev *dev, Error **errp)
     }
 
     vmse = qemu_add_vm_change_state_handler (audio_vm_change_state_handler, s);
-    if (!vmse) {
-        dolog ("warning: Could not register change state handler\n"
-               "(Audio can continue looping even after stopping the VM)\n");
-    }
+    assert(vmse != NULL);
 
     if (!object_property_try_add_child(get_audiodevs_root(), dev->id, OBJECT(s), errp)) {
         goto out;
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 25/42] audio: clean-up vmstate change handler on finalize
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (23 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 24/42] audio: drop needless error message marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 26/42] audio: unregister vmstate description marcandre.lureau
                   ` (18 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann

From: Marc-André Lureau <marcandre.lureau@redhat.com>

QOM-ification continues.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 audio/audio_int.h |  1 +
 audio/audio.c     | 12 ++++++++----
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/audio/audio_int.h b/audio/audio_int.h
index 4187a2dbfc..4a4d69f2bf 100644
--- a/audio/audio_int.h
+++ b/audio/audio_int.h
@@ -235,6 +235,7 @@ typedef struct AudioState {
 
     bool timer_running;
     uint64_t timer_last;
+    VMChangeStateEntry *vmse;
 } AudioState;
 
 extern const struct mixeng_volume nominal_volume;
diff --git a/audio/audio.c b/audio/audio.c
index 4478041e5d..b39b86cc2e 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -1622,6 +1622,9 @@ static void audio_state_init(Object *obj)
     QLIST_INIT (&s->hw_head_in);
     QLIST_INIT (&s->cap_head);
     s->ts = timer_new_ns(QEMU_CLOCK_VIRTUAL, audio_timer, s);
+
+    s->vmse = qemu_add_vm_change_state_handler(audio_vm_change_state_handler, s);
+    assert(s->vmse != NULL);
 }
 
 static void audio_state_finalize(Object *obj)
@@ -1671,6 +1674,11 @@ static void audio_state_finalize(Object *obj)
         timer_free(s->ts);
         s->ts = NULL;
     }
+
+    if (s->vmse) {
+        qemu_del_vm_change_state_handler(s->vmse);
+        s->vmse = NULL;
+    }
 }
 
 static Object *get_audiodevs_root(void)
@@ -1735,7 +1743,6 @@ static AudioState *audio_init(Audiodev *dev, Error **errp)
 {
     int done = 0;
     const char *drvname;
-    VMChangeStateEntry *vmse;
     AudioState *s;
     struct audio_driver *driver;
 
@@ -1775,9 +1782,6 @@ static AudioState *audio_init(Audiodev *dev, Error **errp)
         }
     }
 
-    vmse = qemu_add_vm_change_state_handler (audio_vm_change_state_handler, s);
-    assert(vmse != NULL);
-
     if (!object_property_try_add_child(get_audiodevs_root(), dev->id, OBJECT(s), errp)) {
         goto out;
     }
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 26/42] audio: unregister vmstate description
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (24 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 25/42] audio: clean-up vmstate change handler on finalize marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 27/42] audio: initialize card_head during object init marcandre.lureau
                   ` (17 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 audio/audio.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/audio/audio.c b/audio/audio.c
index b39b86cc2e..e610e8453a 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -1614,6 +1614,8 @@ static void audio_vm_change_state_handler (void *opaque, bool running,
     audio_reset_timer (s);
 }
 
+static const VMStateDescription vmstate_audio;
+
 static void audio_state_init(Object *obj)
 {
     AudioState *s = AUDIO_STATE(obj);
@@ -1625,6 +1627,8 @@ static void audio_state_init(Object *obj)
 
     s->vmse = qemu_add_vm_change_state_handler(audio_vm_change_state_handler, s);
     assert(s->vmse != NULL);
+
+    vmstate_register_any(NULL, &vmstate_audio, s);
 }
 
 static void audio_state_finalize(Object *obj)
@@ -1679,6 +1683,8 @@ static void audio_state_finalize(Object *obj)
         qemu_del_vm_change_state_handler(s->vmse);
         s->vmse = NULL;
     }
+
+    vmstate_unregister(NULL, &vmstate_audio, s);
 }
 
 static Object *get_audiodevs_root(void)
@@ -1787,7 +1793,6 @@ static AudioState *audio_init(Audiodev *dev, Error **errp)
     }
     object_unref(s);
     QLIST_INIT (&s->card_head);
-    vmstate_register_any(NULL, &vmstate_audio, s);
     return s;
 
 out:
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 27/42] audio: initialize card_head during object init
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (25 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 26/42] audio: unregister vmstate description marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 28/42] audio: remove some needless headers marcandre.lureau
                   ` (16 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 audio/audio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/audio/audio.c b/audio/audio.c
index e610e8453a..934a67ad19 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -1623,6 +1623,7 @@ static void audio_state_init(Object *obj)
     QLIST_INIT (&s->hw_head_out);
     QLIST_INIT (&s->hw_head_in);
     QLIST_INIT (&s->cap_head);
+    QLIST_INIT (&s->card_head);
     s->ts = timer_new_ns(QEMU_CLOCK_VIRTUAL, audio_timer, s);
 
     s->vmse = qemu_add_vm_change_state_handler(audio_vm_change_state_handler, s);
@@ -1792,7 +1793,6 @@ static AudioState *audio_init(Audiodev *dev, Error **errp)
         goto out;
     }
     object_unref(s);
-    QLIST_INIT (&s->card_head);
     return s;
 
 out:
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 28/42] audio: remove some needless headers
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (26 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 27/42] audio: initialize card_head during object init marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 29/42] audio: remove AUDIO_HOST_ENDIANNESS marcandre.lureau
                   ` (15 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 audio/audio.h       | 1 -
 audio/audio.c       | 3 ---
 audio/dbusaudio.c   | 2 --
 audio/dsoundaudio.c | 1 -
 audio/mixeng.c      | 4 +++-
 audio/noaudio.c     | 2 --
 audio/wavaudio.c    | 3 ---
 audio/wavcapture.c  | 1 -
 8 files changed, 3 insertions(+), 14 deletions(-)

diff --git a/audio/audio.h b/audio/audio.h
index e41c5bc55a..3be0c4f24f 100644
--- a/audio/audio.h
+++ b/audio/audio.h
@@ -27,7 +27,6 @@
 
 #include "qemu/queue.h"
 #include "qapi/qapi-types-audio.h"
-#include "hw/qdev-properties.h"
 #include "hw/qdev-properties-system.h"
 
 typedef void (*audio_callback_fn) (void *opaque, int avail);
diff --git a/audio/audio.c b/audio/audio.c
index 934a67ad19..0f3093ad59 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -25,7 +25,6 @@
 #include "qemu/osdep.h"
 #include "audio.h"
 #include "migration/vmstate.h"
-#include "monitor/monitor.h"
 #include "qemu/timer.h"
 #include "qapi/error.h"
 #include "qapi/clone-visitor.h"
@@ -33,7 +32,6 @@
 #include "qapi/qapi-visit-audio.h"
 #include "qapi/qapi-commands-audio.h"
 #include "qobject/qdict.h"
-#include "qemu/cutils.h"
 #include "qemu/error-report.h"
 #include "qemu/log.h"
 #include "qemu/module.h"
@@ -41,7 +39,6 @@
 #include "system/system.h"
 #include "system/replay.h"
 #include "system/runstate.h"
-#include "ui/qemu-spice.h"
 #include "trace.h"
 
 #define AUDIO_CAP "audio"
diff --git a/audio/dbusaudio.c b/audio/dbusaudio.c
index b44fdd1511..908214a170 100644
--- a/audio/dbusaudio.c
+++ b/audio/dbusaudio.c
@@ -24,9 +24,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu/error-report.h"
-#include "qemu/host-utils.h"
 #include "qemu/module.h"
-#include "qemu/timer.h"
 #include "qemu/dbus.h"
 
 #ifdef G_OS_UNIX
diff --git a/audio/dsoundaudio.c b/audio/dsoundaudio.c
index 6a8b7f1a19..003ef27365 100644
--- a/audio/dsoundaudio.c
+++ b/audio/dsoundaudio.c
@@ -31,7 +31,6 @@
 
 #define AUDIO_CAP "dsound"
 #include "audio_int.h"
-#include "qemu/host-utils.h"
 #include "qemu/module.h"
 #include "qapi/error.h"
 
diff --git a/audio/mixeng.c b/audio/mixeng.c
index 703ee5448f..be38617e9b 100644
--- a/audio/mixeng.c
+++ b/audio/mixeng.c
@@ -24,11 +24,13 @@
  */
 #include "qemu/osdep.h"
 #include "qemu/bswap.h"
-#include "qemu/error-report.h"
 #include "audio.h"
 
 #define AUDIO_CAP "mixeng"
 #include "audio_int.h"
+#ifdef FLOAT_MIXENG
+#include "qemu/error-report.h"
+#endif
 
 /* 8 bit */
 #define ENDIAN_CONVERSION natural
diff --git a/audio/noaudio.c b/audio/noaudio.c
index 1b60d8518a..34ff1d2a27 100644
--- a/audio/noaudio.c
+++ b/audio/noaudio.c
@@ -23,10 +23,8 @@
  */
 
 #include "qemu/osdep.h"
-#include "qemu/host-utils.h"
 #include "qemu/module.h"
 #include "audio.h"
-#include "qemu/timer.h"
 
 #define AUDIO_CAP "noaudio"
 #include "audio_int.h"
diff --git a/audio/wavaudio.c b/audio/wavaudio.c
index a8798a1c42..a098b20cad 100644
--- a/audio/wavaudio.c
+++ b/audio/wavaudio.c
@@ -23,10 +23,7 @@
  */
 
 #include "qemu/osdep.h"
-#include "qemu/host-utils.h"
 #include "qemu/module.h"
-#include "qemu/timer.h"
-#include "qapi/opts-visitor.h"
 #include "audio.h"
 
 #define AUDIO_CAP "wav"
diff --git a/audio/wavcapture.c b/audio/wavcapture.c
index c60286e162..b990844d48 100644
--- a/audio/wavcapture.c
+++ b/audio/wavcapture.c
@@ -1,6 +1,5 @@
 #include "qemu/osdep.h"
 #include "qemu/qemu-print.h"
-#include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "audio.h"
 
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 29/42] audio: remove AUDIO_HOST_ENDIANNESS
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (27 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 28/42] audio: remove some needless headers marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  7:11   ` Philippe Mathieu-Daudé
  2025-10-22  6:56 ` [PATCH v2 30/42] audio: introduce AUD_set_volume_{in,out}_lr() marcandre.lureau
                   ` (14 subsequent siblings)
  43 siblings, 1 reply; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann,
	Laurent Vivier

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 audio/audio.h      | 6 ------
 audio/audio.c      | 6 +++---
 audio/spiceaudio.c | 4 ++--
 hw/audio/adlib.c   | 2 +-
 hw/audio/asc.c     | 2 +-
 hw/audio/cs4231a.c | 2 +-
 hw/audio/gus.c     | 2 +-
 7 files changed, 9 insertions(+), 15 deletions(-)

diff --git a/audio/audio.h b/audio/audio.h
index 3be0c4f24f..0af911fd9a 100644
--- a/audio/audio.h
+++ b/audio/audio.h
@@ -31,12 +31,6 @@
 
 typedef void (*audio_callback_fn) (void *opaque, int avail);
 
-#if HOST_BIG_ENDIAN
-#define AUDIO_HOST_ENDIANNESS 1
-#else
-#define AUDIO_HOST_ENDIANNESS 0
-#endif
-
 typedef struct audsettings {
     int freq;
     int nchannels;
diff --git a/audio/audio.c b/audio/audio.c
index 0f3093ad59..284ea13289 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -274,7 +274,7 @@ static int audio_pcm_info_eq (struct audio_pcm_info *info, struct audsettings *a
         && info->is_signed == is_signed
         && info->is_float == is_float
         && info->bits == bits
-        && info->swap_endianness == (as->endianness != AUDIO_HOST_ENDIANNESS);
+        && info->swap_endianness == (as->endianness != HOST_BIG_ENDIAN);
 }
 
 void audio_pcm_init_info (struct audio_pcm_info *info, struct audsettings *as)
@@ -320,7 +320,7 @@ void audio_pcm_init_info (struct audio_pcm_info *info, struct audsettings *as)
     info->nchannels = as->nchannels;
     info->bytes_per_frame = as->nchannels * mul;
     info->bytes_per_second = info->freq * info->bytes_per_frame;
-    info->swap_endianness = (as->endianness != AUDIO_HOST_ENDIANNESS);
+    info->swap_endianness = (as->endianness != HOST_BIG_ENDIAN);
 }
 
 void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len)
@@ -2179,7 +2179,7 @@ audsettings audiodev_to_audsettings(AudiodevPerDirectionOptions *pdo)
         .freq = pdo->frequency,
         .nchannels = pdo->channels,
         .fmt = pdo->format,
-        .endianness = AUDIO_HOST_ENDIANNESS,
+        .endianness = HOST_BIG_ENDIAN,
     };
 }
 
diff --git a/audio/spiceaudio.c b/audio/spiceaudio.c
index 7f02f7285c..7e737bff9a 100644
--- a/audio/spiceaudio.c
+++ b/audio/spiceaudio.c
@@ -102,7 +102,7 @@ static int line_out_init(HWVoiceOut *hw, struct audsettings *as,
 #endif
     settings.nchannels  = SPICE_INTERFACE_PLAYBACK_CHAN;
     settings.fmt        = AUDIO_FORMAT_S16;
-    settings.endianness = AUDIO_HOST_ENDIANNESS;
+    settings.endianness = HOST_BIG_ENDIAN;
 
     audio_pcm_init_info (&hw->info, &settings);
     hw->samples = LINE_OUT_SAMPLES;
@@ -218,7 +218,7 @@ static int line_in_init(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
 #endif
     settings.nchannels  = SPICE_INTERFACE_RECORD_CHAN;
     settings.fmt        = AUDIO_FORMAT_S16;
-    settings.endianness = AUDIO_HOST_ENDIANNESS;
+    settings.endianness = HOST_BIG_ENDIAN;
 
     audio_pcm_init_info (&hw->info, &settings);
     hw->samples = LINE_IN_SAMPLES;
diff --git a/hw/audio/adlib.c b/hw/audio/adlib.c
index 0bc0359ae6..50bbb97a56 100644
--- a/hw/audio/adlib.c
+++ b/hw/audio/adlib.c
@@ -272,7 +272,7 @@ static void adlib_realizefn (DeviceState *dev, Error **errp)
     as.freq = s->freq;
     as.nchannels = SHIFT;
     as.fmt = AUDIO_FORMAT_S16;
-    as.endianness = AUDIO_HOST_ENDIANNESS;
+    as.endianness = HOST_BIG_ENDIAN;
 
     s->voice = AUD_open_out (
         &s->card,
diff --git a/hw/audio/asc.c b/hw/audio/asc.c
index edd42d6d91..41472dc2e3 100644
--- a/hw/audio/asc.c
+++ b/hw/audio/asc.c
@@ -650,7 +650,7 @@ static void asc_realize(DeviceState *dev, Error **errp)
     as.freq = ASC_FREQ;
     as.nchannels = 2;
     as.fmt = AUDIO_FORMAT_U8;
-    as.endianness = AUDIO_HOST_ENDIANNESS;
+    as.endianness = HOST_BIG_ENDIAN;
 
     s->voice = AUD_open_out(&s->card, s->voice, "asc.out", s, asc_out_cb,
                             &as);
diff --git a/hw/audio/cs4231a.c b/hw/audio/cs4231a.c
index 18db8da324..c8837fe269 100644
--- a/hw/audio/cs4231a.c
+++ b/hw/audio/cs4231a.c
@@ -305,7 +305,7 @@ static void cs_reset_voices (CSState *s, uint32_t val)
         s->tab = ALawDecompressTable;
     x_law:
         as.fmt = AUDIO_FORMAT_S16;
-        as.endianness = AUDIO_HOST_ENDIANNESS;
+        as.endianness = HOST_BIG_ENDIAN;
         s->shift = as.nchannels == 2;
         break;
 
diff --git a/hw/audio/gus.c b/hw/audio/gus.c
index 16785ce226..2c84740adf 100644
--- a/hw/audio/gus.c
+++ b/hw/audio/gus.c
@@ -254,7 +254,7 @@ static void gus_realizefn (DeviceState *dev, Error **errp)
     as.freq = s->freq;
     as.nchannels = 2;
     as.fmt = AUDIO_FORMAT_S16;
-    as.endianness = AUDIO_HOST_ENDIANNESS;
+    as.endianness = HOST_BIG_ENDIAN;
 
     s->voice = AUD_open_out (
         &s->card,
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 30/42] audio: introduce AUD_set_volume_{in,out}_lr()
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (28 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 29/42] audio: remove AUDIO_HOST_ENDIANNESS marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 31/42] hw/audio: replace AUD_log() usage marcandre.lureau
                   ` (13 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann,
	Laurent Vivier, Manos Pitsidianakis, Michael S. Tsirkin,
	Alistair Francis, Edgar E. Iglesias, Peter Maydell,
	open list:Xilinx ZynqMP and...

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Keep the AUD_ prefix for consistency. Introduce a macro to call the
more flexible Volume function.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 audio/audio.h         |  8 ++++----
 audio/audio.c         | 16 ++--------------
 hw/audio/ac97.c       |  4 ++--
 hw/audio/asc.c        |  2 +-
 hw/audio/hda-codec.c  |  4 ++--
 hw/audio/lm4549.c     |  2 +-
 hw/audio/via-ac97.c   |  2 +-
 hw/audio/virtio-snd.c |  4 ++--
 hw/audio/wm8750.c     | 12 ++++++------
 hw/display/xlnx_dp.c  |  2 +-
 hw/usb/dev-audio.c    |  4 ++--
 11 files changed, 24 insertions(+), 36 deletions(-)

diff --git a/audio/audio.h b/audio/audio.h
index 0af911fd9a..2175223ef6 100644
--- a/audio/audio.h
+++ b/audio/audio.h
@@ -119,8 +119,8 @@ 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 AUD_set_volume_out_lr(sw, mut, lvol, rvol) AUD_set_volume_out(sw, &(Volume) { .mute = mut, .channels = 2, .vol = { lvol, rvol } })
+#define AUD_set_volume_in_lr(sw, mut, lvol, rvol) AUD_set_volume_in(sw, &(Volume) { .mute = mut, .channels = 2, .vol = { lvol, rvol } })
 
 #define AUDIO_MAX_CHANNELS 16
 typedef struct Volume {
@@ -129,8 +129,8 @@ 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);
 
 SWVoiceIn *AUD_open_in (
     QEMUSoundCard *card,
diff --git a/audio/audio.c b/audio/audio.c
index 284ea13289..9e6d79b4e3 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -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;
diff --git a/hw/audio/ac97.c b/hw/audio/ac97.c
index 3d3c667e86..9157588dbc 100644
--- a/hw/audio/ac97.c
+++ b/hw/audio/ac97.c
@@ -414,7 +414,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)
@@ -425,7 +425,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)
diff --git a/hw/audio/asc.c b/hw/audio/asc.c
index 41472dc2e3..991316e984 100644
--- a/hw/audio/asc.c
+++ b/hw/audio/asc.c
@@ -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;
         }
     }
diff --git a/hw/audio/hda-codec.c b/hw/audio/hda-codec.c
index 66edad280f..cc87557954 100644
--- a/hw/audio/hda-codec.c
+++ b/hw/audio/hda-codec.c
@@ -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);
     }
 }
 
diff --git a/hw/audio/lm4549.c b/hw/audio/lm4549.c
index a4a77c8dc6..dccbf56068 100644
--- a/hw/audio/lm4549.c
+++ b/hw/audio/lm4549.c
@@ -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;
 
diff --git a/hw/audio/via-ac97.c b/hw/audio/via-ac97.c
index d5231e1cf2..62341e5600 100644
--- a/hw/audio/via-ac97.c
+++ b/hw/audio/via-ac97.c
@@ -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)
diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c
index eca3319e59..88777977a9 100644
--- a/hw/audio/virtio-snd.c
+++ b/hw/audio/virtio-snd.c
@@ -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);
diff --git a/hw/audio/wm8750.c b/hw/audio/wm8750.c
index 2846b55fe2..7a36c4bd3f 100644
--- a/hw/audio/wm8750.c
+++ b/hw/audio/wm8750.c
@@ -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]));
 }
diff --git a/hw/display/xlnx_dp.c b/hw/display/xlnx_dp.c
index ef73e1815f..882ae3c4b4 100644
--- a/hw/display/xlnx_dp.c
+++ b/hw/display/xlnx_dp.c
@@ -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);
diff --git a/hw/usb/dev-audio.c b/hw/usb/dev-audio.c
index 26af709f31..f59e5a53f0 100644
--- a/hw/usb/dev-audio.c
+++ b/hw/usb/dev-audio.c
@@ -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);
 }
 
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 31/42] hw/audio: replace AUD_log() usage
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (29 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 30/42] audio: introduce AUD_set_volume_{in,out}_lr() marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 32/42] audio/replay: fix type punning marcandre.lureau
                   ` (12 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann

From: Marc-André Lureau <marcandre.lureau@redhat.com>

AUD_log() is just printf(stderr, "prefix: "..), we can use
error_report() or warn_report() appropriately instead.

Ideally it should be converted to traces, but there are many places to
convert, this is left for another day.

Avoid bit-rot by using conditionals.

The patch could be splitted if necessary.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/audio/ac97.c    | 120 ++++++++++++++++++++++-----------------------
 hw/audio/adlib.c   |  20 +++-----
 hw/audio/cs4231a.c |  40 +++++++--------
 hw/audio/es1370.c  |  24 ++++-----
 hw/audio/gus.c     |  21 ++++----
 hw/audio/pcspk.c   |   2 +-
 hw/audio/sb16.c    |  93 +++++++++++++++++------------------
 7 files changed, 151 insertions(+), 169 deletions(-)

diff --git a/hw/audio/ac97.c b/hw/audio/ac97.c
index 9157588dbc..1b2ce601a6 100644
--- a/hw/audio/ac97.c
+++ b/hw/audio/ac97.c
@@ -26,6 +26,7 @@
 #include "qemu/module.h"
 #include "system/dma.h"
 #include "qom/object.h"
+#include "qemu/error-report.h"
 #include "ac97.h"
 
 #define SOFT_VOLUME
@@ -141,11 +142,8 @@ enum {
     BUP_LAST = 2
 };
 
-#ifdef DEBUG_AC97
-#define dolog(...) AUD_log("ac97", __VA_ARGS__)
-#else
-#define dolog(...)
-#endif
+#define DEBUG_AC97 0
+#define dolog(fmt, ...) do { if (DEBUG_AC97) error_report("ac97: " fmt, ##__VA_ARGS__); } while (0)
 
 #define MKREGS(prefix, start)                   \
 enum {                                          \
@@ -190,7 +188,7 @@ static void fetch_bd(AC97LinkState *s, AC97BusMasterRegs *r)
     r->bd.addr = le32_to_cpu(*(uint32_t *) &b[0]) & ~3;
     r->bd.ctl_len = le32_to_cpu(*(uint32_t *) &b[4]);
     r->picb = r->bd.ctl_len & 0xffff;
-    dolog("bd %2d addr=0x%x ctl=0x%06x len=0x%x(%d bytes)\n",
+    dolog("bd %2d addr=0x%x ctl=0x%06x len=0x%x(%d bytes)",
           r->civ, r->bd.addr, r->bd.ctl_len >> 16,
           r->bd.ctl_len & 0xffff, (r->bd.ctl_len & 0xffff) << 1);
 }
@@ -222,7 +220,7 @@ static void update_sr(AC97LinkState *s, AC97BusMasterRegs *r, uint32_t new_sr)
 
     r->sr = new_sr;
 
-    dolog("IOC%d LVB%d sr=0x%x event=%d level=%d\n",
+    dolog("IOC%d LVB%d sr=0x%x event=%d level=%d",
           r->sr & SR_BCIS, r->sr & SR_LVBCI, r->sr, event, level);
 
     if (!event) {
@@ -231,11 +229,11 @@ static void update_sr(AC97LinkState *s, AC97BusMasterRegs *r, uint32_t new_sr)
 
     if (level) {
         s->glob_sta |= masks[r - s->bm_regs];
-        dolog("set irq level=1\n");
+        dolog("set irq level=1");
         pci_irq_assert(&s->dev);
     } else {
         s->glob_sta &= ~masks[r - s->bm_regs];
-        dolog("set irq level=0\n");
+        dolog("set irq level=0");
         pci_irq_deassert(&s->dev);
     }
 }
@@ -256,14 +254,14 @@ static void voice_set_active(AC97LinkState *s, int bm_index, int on)
         break;
 
     default:
-        AUD_log("ac97", "invalid bm_index(%d) in voice_set_active", bm_index);
+        error_report("ac97: invalid bm_index(%d) in voice_set_active", bm_index);
         break;
     }
 }
 
 static void reset_bm_regs(AC97LinkState *s, AC97BusMasterRegs *r)
 {
-    dolog("reset_bm_regs\n");
+    dolog("reset_bm_regs");
     r->bdbar = 0;
     r->civ = 0;
     r->lvi = 0;
@@ -281,7 +279,7 @@ static void reset_bm_regs(AC97LinkState *s, AC97BusMasterRegs *r)
 static void mixer_store(AC97LinkState *s, uint32_t i, uint16_t v)
 {
     if (i + 2 > sizeof(s->mixer_data)) {
-        dolog("mixer_store: index %d out of bounds %zd\n",
+        dolog("mixer_store: index %d out of bounds %zd",
               i, sizeof(s->mixer_data));
         return;
     }
@@ -295,7 +293,7 @@ static uint16_t mixer_load(AC97LinkState *s, uint32_t i)
     uint16_t val = 0xffff;
 
     if (i + 2 > sizeof(s->mixer_data)) {
-        dolog("mixer_load: index %d out of bounds %zd\n",
+        dolog("mixer_load: index %d out of bounds %zd",
               i, sizeof(s->mixer_data));
     } else {
         val = s->mixer_data[i + 0] | (s->mixer_data[i + 1] << 8);
@@ -460,7 +458,7 @@ static void mixer_reset(AC97LinkState *s)
 {
     uint8_t active[LAST_INDEX];
 
-    dolog("mixer_reset\n");
+    dolog("mixer_reset");
     memset(s->mixer_data, 0, sizeof(s->mixer_data));
     memset(active, 0, sizeof(active));
     mixer_store(s, AC97_Reset, 0x0000); /* 6940 */
@@ -508,7 +506,7 @@ static void mixer_reset(AC97LinkState *s)
 static uint32_t nam_readb(void *opaque, uint32_t addr)
 {
     AC97LinkState *s = opaque;
-    dolog("U nam readb 0x%x\n", addr);
+    dolog("U nam readb 0x%x", addr);
     s->cas = 0;
     return ~0U;
 }
@@ -523,7 +521,7 @@ static uint32_t nam_readw(void *opaque, uint32_t addr)
 static uint32_t nam_readl(void *opaque, uint32_t addr)
 {
     AC97LinkState *s = opaque;
-    dolog("U nam readl 0x%x\n", addr);
+    dolog("U nam readl 0x%x", addr);
     s->cas = 0;
     return ~0U;
 }
@@ -535,7 +533,7 @@ static uint32_t nam_readl(void *opaque, uint32_t addr)
 static void nam_writeb(void *opaque, uint32_t addr, uint32_t val)
 {
     AC97LinkState *s = opaque;
-    dolog("U nam writeb 0x%x <- 0x%x\n", addr, val);
+    dolog("U nam writeb 0x%x <- 0x%x", addr, val);
     s->cas = 0;
 }
 
@@ -563,10 +561,10 @@ static void nam_writew(void *opaque, uint32_t addr, uint32_t val)
         break;
     case AC97_Vendor_ID1:
     case AC97_Vendor_ID2:
-        dolog("Attempt to write vendor ID to 0x%x\n", val);
+        dolog("Attempt to write vendor ID to 0x%x", val);
         break;
     case AC97_Extended_Audio_ID:
-        dolog("Attempt to write extended audio ID to 0x%x\n", val);
+        dolog("Attempt to write extended audio ID to 0x%x", val);
         break;
     case AC97_Extended_Audio_Ctrl_Stat:
         if (!(val & EACS_VRA)) {
@@ -579,36 +577,36 @@ static void nam_writew(void *opaque, uint32_t addr, uint32_t val)
             mixer_store(s, AC97_MIC_ADC_Rate, 0xbb80);
             open_voice(s, MC_INDEX, 48000);
         }
-        dolog("Setting extended audio control to 0x%x\n", val);
+        dolog("Setting extended audio control to 0x%x", val);
         mixer_store(s, AC97_Extended_Audio_Ctrl_Stat, val);
         break;
     case AC97_PCM_Front_DAC_Rate:
         if (mixer_load(s, AC97_Extended_Audio_Ctrl_Stat) & EACS_VRA) {
             mixer_store(s, addr, val);
-            dolog("Set front DAC rate to %d\n", val);
+            dolog("Set front DAC rate to %d", val);
             open_voice(s, PO_INDEX, val);
         } else {
-            dolog("Attempt to set front DAC rate to %d, but VRA is not set\n",
+            dolog("Attempt to set front DAC rate to %d, but VRA is not set",
                   val);
         }
         break;
     case AC97_MIC_ADC_Rate:
         if (mixer_load(s, AC97_Extended_Audio_Ctrl_Stat) & EACS_VRM) {
             mixer_store(s, addr, val);
-            dolog("Set MIC ADC rate to %d\n", val);
+            dolog("Set MIC ADC rate to %d", val);
             open_voice(s, MC_INDEX, val);
         } else {
-            dolog("Attempt to set MIC ADC rate to %d, but VRM is not set\n",
+            dolog("Attempt to set MIC ADC rate to %d, but VRM is not set",
                   val);
         }
         break;
     case AC97_PCM_LR_ADC_Rate:
         if (mixer_load(s, AC97_Extended_Audio_Ctrl_Stat) & EACS_VRA) {
             mixer_store(s, addr, val);
-            dolog("Set front LR ADC rate to %d\n", val);
+            dolog("Set front LR ADC rate to %d", val);
             open_voice(s, PI_INDEX, val);
         } else {
-            dolog("Attempt to set LR ADC rate to %d, but VRA is not set\n",
+            dolog("Attempt to set LR ADC rate to %d, but VRA is not set",
                   val);
         }
         break;
@@ -630,7 +628,7 @@ static void nam_writew(void *opaque, uint32_t addr, uint32_t val)
         /* None of the features in these regs are emulated, so they are RO */
         break;
     default:
-        dolog("U nam writew 0x%x <- 0x%x\n", addr, val);
+        dolog("U nam writew 0x%x <- 0x%x", addr, val);
         mixer_store(s, addr, val);
         break;
     }
@@ -639,7 +637,7 @@ static void nam_writew(void *opaque, uint32_t addr, uint32_t val)
 static void nam_writel(void *opaque, uint32_t addr, uint32_t val)
 {
     AC97LinkState *s = opaque;
-    dolog("U nam writel 0x%x <- 0x%x\n", addr, val);
+    dolog("U nam writel 0x%x <- 0x%x", addr, val);
     s->cas = 0;
 }
 
@@ -655,7 +653,7 @@ static uint32_t nabm_readb(void *opaque, uint32_t addr)
 
     switch (addr) {
     case CAS:
-        dolog("CAS %d\n", s->cas);
+        dolog("CAS %d", s->cas);
         val = s->cas;
         s->cas = 1;
         break;
@@ -664,38 +662,38 @@ static uint32_t nabm_readb(void *opaque, uint32_t addr)
     case MC_CIV:
         r = &s->bm_regs[GET_BM(addr)];
         val = r->civ;
-        dolog("CIV[%d] -> 0x%x\n", GET_BM(addr), val);
+        dolog("CIV[%d] -> 0x%x", GET_BM(addr), val);
         break;
     case PI_LVI:
     case PO_LVI:
     case MC_LVI:
         r = &s->bm_regs[GET_BM(addr)];
         val = r->lvi;
-        dolog("LVI[%d] -> 0x%x\n", GET_BM(addr), val);
+        dolog("LVI[%d] -> 0x%x", GET_BM(addr), val);
         break;
     case PI_PIV:
     case PO_PIV:
     case MC_PIV:
         r = &s->bm_regs[GET_BM(addr)];
         val = r->piv;
-        dolog("PIV[%d] -> 0x%x\n", GET_BM(addr), val);
+        dolog("PIV[%d] -> 0x%x", GET_BM(addr), val);
         break;
     case PI_CR:
     case PO_CR:
     case MC_CR:
         r = &s->bm_regs[GET_BM(addr)];
         val = r->cr;
-        dolog("CR[%d] -> 0x%x\n", GET_BM(addr), val);
+        dolog("CR[%d] -> 0x%x", GET_BM(addr), val);
         break;
     case PI_SR:
     case PO_SR:
     case MC_SR:
         r = &s->bm_regs[GET_BM(addr)];
         val = r->sr & 0xff;
-        dolog("SRb[%d] -> 0x%x\n", GET_BM(addr), val);
+        dolog("SRb[%d] -> 0x%x", GET_BM(addr), val);
         break;
     default:
-        dolog("U nabm readb 0x%x -> 0x%x\n", addr, val);
+        dolog("U nabm readb 0x%x -> 0x%x", addr, val);
         break;
     }
     return val;
@@ -713,17 +711,17 @@ static uint32_t nabm_readw(void *opaque, uint32_t addr)
     case MC_SR:
         r = &s->bm_regs[GET_BM(addr)];
         val = r->sr;
-        dolog("SR[%d] -> 0x%x\n", GET_BM(addr), val);
+        dolog("SR[%d] -> 0x%x", GET_BM(addr), val);
         break;
     case PI_PICB:
     case PO_PICB:
     case MC_PICB:
         r = &s->bm_regs[GET_BM(addr)];
         val = r->picb;
-        dolog("PICB[%d] -> 0x%x\n", GET_BM(addr), val);
+        dolog("PICB[%d] -> 0x%x", GET_BM(addr), val);
         break;
     default:
-        dolog("U nabm readw 0x%x -> 0x%x\n", addr, val);
+        dolog("U nabm readw 0x%x -> 0x%x", addr, val);
         break;
     }
     return val;
@@ -741,14 +739,14 @@ static uint32_t nabm_readl(void *opaque, uint32_t addr)
     case MC_BDBAR:
         r = &s->bm_regs[GET_BM(addr)];
         val = r->bdbar;
-        dolog("BMADDR[%d] -> 0x%x\n", GET_BM(addr), val);
+        dolog("BMADDR[%d] -> 0x%x", GET_BM(addr), val);
         break;
     case PI_CIV:
     case PO_CIV:
     case MC_CIV:
         r = &s->bm_regs[GET_BM(addr)];
         val = r->civ | (r->lvi << 8) | (r->sr << 16);
-        dolog("CIV LVI SR[%d] -> 0x%x, 0x%x, 0x%x\n", GET_BM(addr),
+        dolog("CIV LVI SR[%d] -> 0x%x, 0x%x, 0x%x", GET_BM(addr),
                r->civ, r->lvi, r->sr);
         break;
     case PI_PICB:
@@ -756,19 +754,19 @@ static uint32_t nabm_readl(void *opaque, uint32_t addr)
     case MC_PICB:
         r = &s->bm_regs[GET_BM(addr)];
         val = r->picb | (r->piv << 16) | (r->cr << 24);
-        dolog("PICB PIV CR[%d] -> 0x%x 0x%x 0x%x 0x%x\n", GET_BM(addr),
+        dolog("PICB PIV CR[%d] -> 0x%x 0x%x 0x%x 0x%x", GET_BM(addr),
                val, r->picb, r->piv, r->cr);
         break;
     case GLOB_CNT:
         val = s->glob_cnt;
-        dolog("glob_cnt -> 0x%x\n", val);
+        dolog("glob_cnt -> 0x%x", val);
         break;
     case GLOB_STA:
         val = s->glob_sta | GS_S0CR;
-        dolog("glob_sta -> 0x%x\n", val);
+        dolog("glob_sta -> 0x%x", val);
         break;
     default:
-        dolog("U nabm readl 0x%x -> 0x%x\n", addr, val);
+        dolog("U nabm readl 0x%x -> 0x%x", addr, val);
         break;
     }
     return val;
@@ -795,7 +793,7 @@ static void nabm_writeb(void *opaque, uint32_t addr, uint32_t val)
             fetch_bd(s, r);
         }
         r->lvi = val % 32;
-        dolog("LVI[%d] <- 0x%x\n", GET_BM(addr), val);
+        dolog("LVI[%d] <- 0x%x", GET_BM(addr), val);
         break;
     case PI_CR:
     case PO_CR:
@@ -816,7 +814,7 @@ static void nabm_writeb(void *opaque, uint32_t addr, uint32_t val)
                 voice_set_active(s, r - s->bm_regs, 1);
             }
         }
-        dolog("CR[%d] <- 0x%x (cr 0x%x)\n", GET_BM(addr), val, r->cr);
+        dolog("CR[%d] <- 0x%x (cr 0x%x)", GET_BM(addr), val, r->cr);
         break;
     case PI_SR:
     case PO_SR:
@@ -824,10 +822,10 @@ static void nabm_writeb(void *opaque, uint32_t addr, uint32_t val)
         r = &s->bm_regs[GET_BM(addr)];
         r->sr |= val & ~(SR_RO_MASK | SR_WCLEAR_MASK);
         update_sr(s, r, r->sr & ~(val & SR_WCLEAR_MASK));
-        dolog("SR[%d] <- 0x%x (sr 0x%x)\n", GET_BM(addr), val, r->sr);
+        dolog("SR[%d] <- 0x%x (sr 0x%x)", GET_BM(addr), val, r->sr);
         break;
     default:
-        dolog("U nabm writeb 0x%x <- 0x%x\n", addr, val);
+        dolog("U nabm writeb 0x%x <- 0x%x", addr, val);
         break;
     }
 }
@@ -844,10 +842,10 @@ static void nabm_writew(void *opaque, uint32_t addr, uint32_t val)
         r = &s->bm_regs[GET_BM(addr)];
         r->sr |= val & ~(SR_RO_MASK | SR_WCLEAR_MASK);
         update_sr(s, r, r->sr & ~(val & SR_WCLEAR_MASK));
-        dolog("SR[%d] <- 0x%x (sr 0x%x)\n", GET_BM(addr), val, r->sr);
+        dolog("SR[%d] <- 0x%x (sr 0x%x)", GET_BM(addr), val, r->sr);
         break;
     default:
-        dolog("U nabm writew 0x%x <- 0x%x\n", addr, val);
+        dolog("U nabm writew 0x%x <- 0x%x", addr, val);
         break;
     }
 }
@@ -863,22 +861,22 @@ static void nabm_writel(void *opaque, uint32_t addr, uint32_t val)
     case MC_BDBAR:
         r = &s->bm_regs[GET_BM(addr)];
         r->bdbar = val & ~3;
-        dolog("BDBAR[%d] <- 0x%x (bdbar 0x%x)\n", GET_BM(addr), val, r->bdbar);
+        dolog("BDBAR[%d] <- 0x%x (bdbar 0x%x)", GET_BM(addr), val, r->bdbar);
         break;
     case GLOB_CNT:
         /* TODO: Handle WR or CR being set (warm/cold reset requests) */
         if (!(val & (GC_WR | GC_CR))) {
             s->glob_cnt = val & GC_VALID_MASK;
         }
-        dolog("glob_cnt <- 0x%x (glob_cnt 0x%x)\n", val, s->glob_cnt);
+        dolog("glob_cnt <- 0x%x (glob_cnt 0x%x)", val, s->glob_cnt);
         break;
     case GLOB_STA:
         s->glob_sta &= ~(val & GS_WCLEAR_MASK);
         s->glob_sta |= (val & ~(GS_WCLEAR_MASK | GS_RO_MASK)) & GS_VALID_MASK;
-        dolog("glob_sta <- 0x%x (glob_sta 0x%x)\n", val, s->glob_sta);
+        dolog("glob_sta <- 0x%x (glob_sta 0x%x)", val, s->glob_sta);
         break;
     default:
-        dolog("U nabm writel 0x%x <- 0x%x\n", addr, val);
+        dolog("U nabm writel 0x%x <- 0x%x", addr, val);
         break;
     }
 }
@@ -903,7 +901,7 @@ static int write_audio(AC97LinkState *s, AC97BusMasterRegs *r,
         to_copy = MIN(temp, sizeof(tmpbuf));
         pci_dma_read(&s->dev, addr, tmpbuf, to_copy);
         copied = AUD_write(s->voice_po, tmpbuf, to_copy);
-        dolog("write_audio max=%x to_copy=%x copied=%x\n",
+        dolog("write_audio max=%x to_copy=%x copied=%x",
               max, to_copy, copied);
         if (!copied) {
             *stop = 1;
@@ -916,7 +914,7 @@ static int write_audio(AC97LinkState *s, AC97BusMasterRegs *r,
 
     if (!temp) {
         if (to_copy < 4) {
-            dolog("whoops\n");
+            dolog("whoops");
             s->last_samp = 0;
         } else {
             s->last_samp = *(uint32_t *)&tmpbuf[to_copy - 4];
@@ -929,7 +927,7 @@ static int write_audio(AC97LinkState *s, AC97BusMasterRegs *r,
 
 static void write_bup(AC97LinkState *s, int elapsed)
 {
-    dolog("write_bup\n");
+    dolog("write_bup");
     if (!(s->bup_flag & BUP_SET)) {
         if (s->bup_flag & BUP_LAST) {
             int i;
@@ -997,7 +995,7 @@ static void transfer_audio(AC97LinkState *s, int index, int elapsed)
     int stop = 0;
 
     if (s->invalid_freq[index]) {
-        AUD_log("ac97", "attempt to use voice %d with invalid frequency %d\n",
+        error_report("ac97: attempt to use voice %d with invalid frequency %d",
                 index, s->invalid_freq[index]);
         return;
     }
@@ -1017,12 +1015,12 @@ static void transfer_audio(AC97LinkState *s, int index, int elapsed)
         int temp;
 
         if (!r->bd_valid) {
-            dolog("invalid bd\n");
+            dolog("invalid bd");
             fetch_bd(s, r);
         }
 
         if (!r->picb) {
-            dolog("fresh bd %d is empty 0x%x 0x%x\n",
+            dolog("fresh bd %d is empty 0x%x 0x%x",
                   r->civ, r->bd.addr, r->bd.ctl_len);
             if (r->civ == r->lvi) {
                 r->sr |= SR_DCH; /* CELV? */
@@ -1059,7 +1057,7 @@ static void transfer_audio(AC97LinkState *s, int index, int elapsed)
             }
 
             if (r->civ == r->lvi) {
-                dolog("Underrun civ (%d) == lvi (%d)\n", r->civ, r->lvi);
+                dolog("Underrun civ (%d) == lvi (%d)", r->civ, r->lvi);
 
                 new_sr |= SR_LVBCI | SR_DCH | SR_CELV;
                 stop = 1;
diff --git a/hw/audio/adlib.c b/hw/audio/adlib.c
index 50bbb97a56..231055b8b5 100644
--- a/hw/audio/adlib.c
+++ b/hw/audio/adlib.c
@@ -29,24 +29,20 @@
 #include "audio/audio.h"
 #include "hw/isa/isa.h"
 #include "hw/qdev-properties.h"
+#include "qemu/error-report.h"
 #include "qom/object.h"
 
-//#define DEBUG
+#define DEBUG 0
 
 #define ADLIB_KILL_TIMERS 1
 
 #define ADLIB_DESC "Yamaha YM3812 (OPL2)"
 
-#ifdef DEBUG
+#if DEBUG
 #include "qemu/timer.h"
 #endif
 
-#define dolog(...) AUD_log ("adlib", __VA_ARGS__)
-#ifdef DEBUG
-#define ldebug(...) dolog (__VA_ARGS__)
-#else
-#define ldebug(...)
-#endif
+#define ldebug(fmt, ...) do { if (DEBUG) error_report("adlib: " fmt, ##__VA_ARGS__); } while(0)
 
 #include "fmopl.h"
 #define SHIFT 1
@@ -64,7 +60,7 @@ struct AdlibState {
     int enabled;
     int active;
     int bufpos;
-#ifdef DEBUG
+#if DEBUG
     int64_t exp[2];
 #endif
     int16_t *mixbuf;
@@ -92,7 +88,7 @@ static void adlib_kill_timers (AdlibState *s)
 
             delta = AUD_get_elapsed_usec_out (s->voice, &s->ats);
             ldebug (
-                "delta = %f dexp = %f expired => %d\n",
+                "delta = %f dexp = %f expired => %d",
                 delta / 1000000.0,
                 s->dexp[i] / 1000000.0,
                 delta >= s->dexp[i]
@@ -131,7 +127,7 @@ static void timer_handler (void *opaque, int c, double interval_Sec)
 {
     AdlibState *s = opaque;
     unsigned n = c & 1;
-#ifdef DEBUG
+#if DEBUG
     double interval;
     int64_t exp;
 #endif
@@ -142,7 +138,7 @@ static void timer_handler (void *opaque, int c, double interval_Sec)
     }
 
     s->ticking[n] = 1;
-#ifdef DEBUG
+#if DEBUG
     interval = NANOSECONDS_PER_SECOND * interval_Sec;
     exp = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + interval;
     s->exp[n] = exp;
diff --git a/hw/audio/cs4231a.c b/hw/audio/cs4231a.c
index c8837fe269..062af7628b 100644
--- a/hw/audio/cs4231a.c
+++ b/hw/audio/cs4231a.c
@@ -30,7 +30,7 @@
 #include "hw/qdev-properties.h"
 #include "migration/vmstate.h"
 #include "qemu/module.h"
-#include "qemu/timer.h"
+#include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "qom/object.h"
 
@@ -43,21 +43,17 @@
   More...
 */
 
-/* #define DEBUG */
+#define DEBUG 0
 /* #define DEBUG_XLAW */
 
 static struct {
     int aci_counter;
 } conf = {1};
 
-#ifdef DEBUG
-#define dolog(...) AUD_log ("cs4231a", __VA_ARGS__)
-#else
-#define dolog(...)
-#endif
+#define dolog(fmt, ...) do { if (DEBUG) error_report("cs4231a: " fmt, ##__VA_ARGS__); } while(0)
 
-#define lwarn(...) AUD_log ("cs4231a", "warning: " __VA_ARGS__)
-#define lerr(...) AUD_log ("cs4231a", "error: " __VA_ARGS__)
+#define lwarn(fmt, ...) warn_report("cs4231a: " fmt, ##__VA_ARGS__)
+#define lerr(fmt, ...) error_report("cs4231a: " fmt, ##__VA_ARGS__)
 
 #define CS_REGS 16
 #define CS_DREGS 32
@@ -284,7 +280,7 @@ static void cs_reset_voices (CSState *s, uint32_t val)
     as.freq = freqs[xtal][(val >> 1) & 7];
 
     if (as.freq == -1) {
-        lerr ("unsupported frequency (val=%#x)\n", val);
+        lerr ("unsupported frequency (val=%#x)", val);
         goto error;
     }
 
@@ -319,11 +315,11 @@ static void cs_reset_voices (CSState *s, uint32_t val)
 
     case 7:
     case 4:
-        lerr ("attempt to use reserved format value (%#x)\n", val);
+        lerr ("attempt to use reserved format value (%#x)", val);
         goto error;
 
     case 5:
-        lerr ("ADPCM 4 bit IMA compatible format is not supported\n");
+        lerr ("ADPCM 4 bit IMA compatible format is not supported");
         goto error;
     }
 
@@ -393,7 +389,7 @@ static uint64_t cs_read (void *opaque, hwaddr addr, unsigned size)
         ret = s->regs[saddr];
         break;
     }
-    dolog ("read %d:%d -> %d\n", saddr, iaddr, ret);
+    dolog ("read %d:%d -> %d", saddr, iaddr, ret);
     return ret;
 }
 
@@ -425,7 +421,7 @@ static void cs_write (void *opaque, hwaddr addr,
         case RESERVED:
         case RESERVED_2:
         case RESERVED_3:
-            lwarn ("attempt to write %#x to reserved indirect register %d\n",
+            lwarn ("attempt to write %#x to reserved indirect register %d",
                    val, iaddr);
             break;
 
@@ -439,7 +435,7 @@ static void cs_write (void *opaque, hwaddr addr,
                     cs_reset_voices (s, val);
                 }
                 else {
-                    lwarn ("[P]MCE(%#x, %#x) is not set, val=%#x\n",
+                    lwarn ("[P]MCE(%#x, %#x) is not set, val=%#x",
                            s->regs[Index_Address],
                            s->dregs[Alternate_Feature_Status],
                            val);
@@ -453,7 +449,7 @@ static void cs_write (void *opaque, hwaddr addr,
             val &= ~(1 << 5);   /* D5 is reserved */
             s->dregs[iaddr] = val;
             if (val & PPIO) {
-                lwarn ("PIO is not supported (%#x)\n", val);
+                lwarn ("PIO is not supported (%#x)", val);
                 break;
             }
             if (val & PEN) {
@@ -472,11 +468,11 @@ static void cs_write (void *opaque, hwaddr addr,
             break;
 
         case Error_Status_And_Initialization:
-            lwarn ("attempt to write to read only register %d\n", iaddr);
+            lwarn ("attempt to write to read only register %d", iaddr);
             break;
 
         case MODE_And_ID:
-            dolog ("val=%#x\n", val);
+            dolog ("val=%#x", val);
             if (val & MODE2)
                 s->dregs[iaddr] |= MODE2;
             else
@@ -485,7 +481,7 @@ static void cs_write (void *opaque, hwaddr addr,
 
         case Alternate_Feature_Enable_I:
             if (val & TE)
-                lerr ("timer is not yet supported\n");
+                lerr ("timer is not yet supported");
             s->dregs[iaddr] = val;
             break;
 
@@ -499,7 +495,7 @@ static void cs_write (void *opaque, hwaddr addr,
             break;
 
         case Version_Chip_ID:
-            lwarn ("write to Version_Chip_ID register %#x\n", val);
+            lwarn ("write to Version_Chip_ID register %#x", val);
             s->dregs[iaddr] = val;
             break;
 
@@ -507,7 +503,7 @@ static void cs_write (void *opaque, hwaddr addr,
             s->dregs[iaddr] = val;
             break;
         }
-        dolog ("written value %#x to indirect register %d\n", val, iaddr);
+        dolog ("written value %#x to indirect register %d", val, iaddr);
         break;
 
     case Status:
@@ -519,7 +515,7 @@ static void cs_write (void *opaque, hwaddr addr,
         break;
 
     case PIO_Data:
-        lwarn ("attempt to write value %#x to PIO register\n", val);
+        lwarn ("attempt to write value %#x to PIO register", val);
         break;
     }
 }
diff --git a/hw/audio/es1370.c b/hw/audio/es1370.c
index 8cb47589c3..ac5a6aba85 100644
--- a/hw/audio/es1370.c
+++ b/hw/audio/es1370.c
@@ -32,7 +32,7 @@
 #include "migration/vmstate.h"
 #include "qemu/cutils.h"
 #include "qemu/module.h"
-#include "system/dma.h"
+#include "qemu/error-report.h"
 #include "qom/object.h"
 #include "trace.h"
 
@@ -190,7 +190,7 @@ static void print_ctl(uint32_t val)
         a(CDC_EN);
         a(SERR_DIS);
 #undef a
-        AUD_log("es1370", "ctl - PCLKDIV %d(DAC2 freq %d), freq %d,%s\n",
+        error_report("es1370: ctl - PCLKDIV %d(DAC2 freq %d), freq %d,%s\n",
                 (val & CTRL_PCLKDIV) >> CTRL_SH_PCLKDIV,
                 DAC2_DIVTOSR((val & CTRL_PCLKDIV) >> CTRL_SH_PCLKDIV),
                 dac1_samplerate[(val & CTRL_WTSRSEL) >> CTRL_SH_WTSRSEL],
@@ -226,7 +226,7 @@ static void print_sctl(uint32_t val)
         }
 #undef b
 #undef a
-        AUD_log("es1370",
+        error_report("es1370: "
                 "%s p2_end_inc %d, p2_st_inc %d,"
                 " r1_fmt %s, p2_fmt %s, p1_fmt %s\n",
                 buf,
@@ -238,10 +238,10 @@ static void print_sctl(uint32_t val)
     }
 }
 
-#define lwarn(...) \
+#define lwarn(fmt, ...) \
 do { \
     if (VERBOSE_ES1370) { \
-        AUD_log("es1370: warning", __VA_ARGS__); \
+        error_report("es1370: " fmt, ##__VA_ARGS__); \
     } \
 } while (0)
 
@@ -502,10 +502,10 @@ static void es1370_write(void *opaque, hwaddr addr, uint64_t val, unsigned size)
         break;
 
     case ES1370_REG_PHANTOM_FRAMECNT:
-        lwarn("writing to phantom frame count 0x%" PRIx64 "\n", val);
+        lwarn("writing to phantom frame count 0x%" PRIx64, val);
         break;
     case ES1370_REG_PHANTOM_FRAMEADR:
-        lwarn("writing to phantom frame address 0x%" PRIx64 "\n", val);
+        lwarn("writing to phantom frame address 0x%" PRIx64, val);
         break;
 
     case ES1370_REG_ADC_FRAMECNT:
@@ -522,7 +522,7 @@ static void es1370_write(void *opaque, hwaddr addr, uint64_t val, unsigned size)
         break;
 
     default:
-        lwarn("writel 0x%" PRIx64 " <- 0x%" PRIx64 "\n", addr, val);
+        lwarn("writel 0x%" PRIx64 " <- 0x%" PRIx64, addr, val);
         break;
     }
 }
@@ -586,16 +586,16 @@ static uint64_t es1370_read(void *opaque, hwaddr addr, unsigned size)
 
     case ES1370_REG_PHANTOM_FRAMECNT:
         val = ~0U;
-        lwarn("reading from phantom frame count\n");
+        lwarn("reading from phantom frame count");
         break;
     case ES1370_REG_PHANTOM_FRAMEADR:
         val = ~0U;
-        lwarn("reading from phantom frame address\n");
+        lwarn("reading from phantom frame address");
         break;
 
     default:
         val = ~0U;
-        lwarn("readl 0x%" PRIx64 " -> 0x%x\n", addr, val);
+        lwarn("readl 0x%" PRIx64 " -> 0x%x", addr, val);
         break;
     }
     return val;
@@ -677,7 +677,7 @@ static void es1370_transfer_audio (ES1370State *s, struct chan *d, int loop_sel,
          * when the sample count reaches zero) or 1 for stop mode (set
          * interrupt and stop recording).
          */
-        AUD_log ("es1370: warning", "non looping mode\n");
+        warn_report("es1370: non looping mode");
     } else {
         d->frame_cnt = size;
 
diff --git a/hw/audio/gus.c b/hw/audio/gus.c
index 2c84740adf..40073f2d4f 100644
--- a/hw/audio/gus.c
+++ b/hw/audio/gus.c
@@ -32,15 +32,12 @@
 #include "hw/qdev-properties.h"
 #include "migration/vmstate.h"
 #include "gusemu.h"
-#include "gustate.h"
+#include "qemu/error-report.h"
 #include "qom/object.h"
 
-#define dolog(...) AUD_log ("audio", __VA_ARGS__)
-#ifdef DEBUG
-#define ldebug(...) dolog (__VA_ARGS__)
-#else
-#define ldebug(...)
-#endif
+#define DEBUG 0
+
+#define ldebug(fmt, ...) do { if (DEBUG) error_report("gus: " fmt, ##__VA_ARGS__); } while (0)
 
 #define TYPE_GUS "gus"
 OBJECT_DECLARE_SIMPLE_TYPE(GUSState, GUS)
@@ -154,14 +151,14 @@ int GUS_irqrequest (GUSEmuState *emu, int hwirq, int n)
     /* qemu_irq_lower (s->pic); */
     qemu_irq_raise (s->pic);
     s->irqs += n;
-    ldebug ("irqrequest %d %d %d\n", hwirq, n, s->irqs);
+    ldebug("irqrequest %d %d %d", hwirq, n, s->irqs);
     return n;
 }
 
 void GUS_irqclear (GUSEmuState *emu, int hwirq)
 {
     GUSState *s = emu->opaque;
-    ldebug ("irqclear %d %d\n", hwirq, s->irqs);
+    ldebug("irqclear %d %d", hwirq, s->irqs);
     qemu_irq_lower (s->pic);
     s->irqs -= 1;
 #ifdef IRQ_STORM
@@ -175,7 +172,7 @@ void GUS_dmarequest (GUSEmuState *emu)
 {
     GUSState *s = emu->opaque;
     IsaDmaClass *k = ISADMA_GET_CLASS(s->isa_dma);
-    ldebug ("dma request %d\n", der->gusdma);
+    ldebug("dma request %d", s->emu.gusdma);
     k->hold_DREQ(s->isa_dma, s->emu.gusdma);
 }
 
@@ -186,13 +183,13 @@ static int GUS_read_DMA (void *opaque, int nchan, int dma_pos, int dma_len)
     QEMU_UNINITIALIZED char tmpbuf[4096];
     int pos = dma_pos, mode, left = dma_len - dma_pos;
 
-    ldebug ("read DMA %#x %d\n", dma_pos, dma_len);
+    ldebug("read DMA %#x %d", dma_pos, dma_len);
     mode = k->has_autoinitialization(s->isa_dma, s->emu.gusdma);
     while (left) {
         int to_copy = MIN ((size_t) left, sizeof (tmpbuf));
         int copied;
 
-        ldebug ("left=%d to_copy=%d pos=%d\n", left, to_copy, pos);
+        ldebug("left=%d to_copy=%d pos=%d", left, to_copy, pos);
         copied = k->read_memory(s->isa_dma, nchan, tmpbuf, pos, to_copy);
         gus_dma_transferdata (&s->emu, tmpbuf, copied, left == copied);
         left -= copied;
diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index 12a214c566..c8c63b7915 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -124,7 +124,7 @@ static int pcspk_audio_init(PCSpkState *s)
 
     s->voice = AUD_open_out(&s->card, s->voice, s_spk, s, pcspk_callback, &as);
     if (!s->voice) {
-        AUD_log(s_spk, "Could not open voice\n");
+        error_report("pcspk: Could not open voice");
         return -1;
     }
 
diff --git a/hw/audio/sb16.c b/hw/audio/sb16.c
index cd7e813d05..069cf6e120 100644
--- a/hw/audio/sb16.c
+++ b/hw/audio/sb16.c
@@ -30,22 +30,17 @@
 #include "hw/qdev-properties.h"
 #include "migration/vmstate.h"
 #include "qemu/timer.h"
+#include "qemu/error-report.h"
 #include "qemu/host-utils.h"
 #include "qemu/log.h"
 #include "qemu/module.h"
 #include "qapi/error.h"
 #include "qom/object.h"
 
-#define dolog(...) AUD_log ("sb16", __VA_ARGS__)
-
-/* #define DEBUG */
+#define DEBUG 0
 /* #define DEBUG_SB16_MOST */
 
-#ifdef DEBUG
-#define ldebug(...) dolog (__VA_ARGS__)
-#else
-#define ldebug(...)
-#endif
+#define ldebug(fmt, ...) do { if (DEBUG) error_report("sb16: " fmt, ##__VA_ARGS__); } while (0)
 
 static const char e3[] = "COPYRIGHT (C) CREATIVE TECHNOLOGY LTD, 1992.";
 
@@ -157,7 +152,7 @@ static int irq_of_magic (int magic)
 #if 0
 static void log_dsp (SB16State *dsp)
 {
-    ldebug ("%s:%s:%d:%s:dmasize=%d:freq=%d:const=%d:speaker=%d\n",
+    ldebug ("%s:%s:%d:%s:dmasize=%d:freq=%d:const=%d:speaker=%d",
             dsp->fmt_stereo ? "Stereo" : "Mono",
             dsp->fmt_signed ? "Signed" : "Unsigned",
             dsp->fmt_bits,
@@ -182,7 +177,7 @@ static void control (SB16State *s, int hold)
     IsaDmaClass *k = ISADMA_GET_CLASS(isa_dma);
     s->dma_running = hold;
 
-    ldebug ("hold %d high %d dma %d\n", hold, s->use_hdma, dma);
+    ldebug ("hold %d high %d dma %d", hold, s->use_hdma, dma);
 
     if (hold) {
         k->hold_DREQ(isa_dma, dma);
@@ -290,7 +285,7 @@ static void dma_cmd8 (SB16State *s, int mask, int dma_len)
     }
 
     ldebug ("freq %d, stereo %d, sign %d, bits %d, "
-            "dma %d, auto %d, fifo %d, high %d\n",
+            "dma %d, auto %d, fifo %d, high %d",
             s->freq, s->fmt_stereo, s->fmt_signed, s->fmt_bits,
             s->block_size, s->dma_auto, s->fifo, s->highspeed);
 
@@ -338,7 +333,7 @@ static void dma_cmd (SB16State *s, uint8_t cmd, uint8_t d0, int dma_len)
     }
 
     ldebug ("freq %d, stereo %d, sign %d, bits %d, "
-            "dma %d, auto %d, fifo %d, high %d\n",
+            "dma %d, auto %d, fifo %d, high %d",
             s->freq, s->fmt_stereo, s->fmt_signed, s->fmt_bits,
             s->block_size, s->dma_auto, s->fifo, s->highspeed);
 
@@ -395,7 +390,7 @@ static void dma_cmd (SB16State *s, uint8_t cmd, uint8_t d0, int dma_len)
 
 static inline void dsp_out_data (SB16State *s, uint8_t val)
 {
-    ldebug ("outdata %#x\n", val);
+    ldebug ("outdata %#x", val);
     if ((size_t) s->out_data_len < sizeof (s->out_data)) {
         s->out_data[s->out_data_len++] = val;
     }
@@ -407,14 +402,14 @@ static inline uint8_t dsp_get_data (SB16State *s)
         return s->in2_data[--s->in_index];
     }
     else {
-        dolog ("buffer underflow\n");
+        warn_report("sb16: buffer underflow");
         return 0;
     }
 }
 
 static void command (SB16State *s, uint8_t cmd)
 {
-    ldebug ("command %#x\n", cmd);
+    ldebug ("command %#x", cmd);
 
     if (cmd > 0xaf && cmd < 0xd0) {
         if (cmd & 8) {
@@ -651,7 +646,7 @@ static void command (SB16State *s, uint8_t cmd)
     }
 
     if (!s->needed_bytes) {
-        ldebug ("\n");
+        ldebug ("!needed_bytes");
     }
 
  exit:
@@ -687,7 +682,7 @@ static uint16_t dsp_get_hilo (SB16State *s)
 static void complete (SB16State *s)
 {
     int d0, d1, d2;
-    ldebug ("complete command %#x, in_index %d, needed_bytes %d\n",
+    ldebug ("complete command %#x, in_index %d, needed_bytes %d",
             s->cmd, s->in_index, s->needed_bytes);
 
     if (s->cmd > 0xaf && s->cmd < 0xd0) {
@@ -696,11 +691,11 @@ static void complete (SB16State *s)
         d0 = dsp_get_data (s);
 
         if (s->cmd & 8) {
-            dolog ("ADC params cmd = %#x d0 = %d, d1 = %d, d2 = %d\n",
+            warn_report("sb16: ADC params cmd = %#x d0 = %d, d1 = %d, d2 = %d",
                    s->cmd, d0, d1, d2);
         }
         else {
-            ldebug ("cmd = %#x d0 = %d, d1 = %d, d2 = %d\n",
+            ldebug ("cmd = %#x d0 = %d, d1 = %d, d2 = %d",
                     s->cmd, d0, d1, d2);
             dma_cmd (s, s->cmd, d0, d1 + (d2 << 8));
         }
@@ -711,13 +706,13 @@ static void complete (SB16State *s)
             s->csp_mode = dsp_get_data (s);
             s->csp_reg83r = 0;
             s->csp_reg83w = 0;
-            ldebug ("CSP command 0x04: mode=%#x\n", s->csp_mode);
+            ldebug ("CSP command 0x04: mode=%#x", s->csp_mode);
             break;
 
         case 0x05:
             s->csp_param = dsp_get_data (s);
             s->csp_value = dsp_get_data (s);
-            ldebug ("CSP command 0x05: param=%#x value=%#x\n",
+            ldebug ("CSP command 0x05: param=%#x value=%#x",
                     s->csp_param,
                     s->csp_value);
             break;
@@ -725,9 +720,9 @@ static void complete (SB16State *s)
         case 0x0e:
             d0 = dsp_get_data (s);
             d1 = dsp_get_data (s);
-            ldebug ("write CSP register %d <- %#x\n", d1, d0);
+            ldebug ("write CSP register %d <- %#x", d1, d0);
             if (d1 == 0x83) {
-                ldebug ("0x83[%d] <- %#x\n", s->csp_reg83r, d0);
+                ldebug ("0x83[%d] <- %#x", s->csp_reg83r, d0);
                 s->csp_reg83[s->csp_reg83r % 4] = d0;
                 s->csp_reg83r += 1;
             }
@@ -738,10 +733,10 @@ static void complete (SB16State *s)
 
         case 0x0f:
             d0 = dsp_get_data (s);
-            ldebug ("read CSP register %#x -> %#x, mode=%#x\n",
+            ldebug ("read CSP register %#x -> %#x, mode=%#x",
                     d0, s->csp_regs[d0], s->csp_mode);
             if (d0 == 0x83) {
-                ldebug ("0x83[%d] -> %#x\n",
+                ldebug ("0x83[%d] -> %#x",
                         s->csp_reg83w,
                         s->csp_reg83[s->csp_reg83w % 4]);
                 dsp_out_data (s, s->csp_reg83[s->csp_reg83w % 4]);
@@ -754,7 +749,7 @@ static void complete (SB16State *s)
 
         case 0x10:
             d0 = dsp_get_data (s);
-            dolog ("cmd 0x10 d0=%#x\n", d0);
+            warn_report("sb16: cmd 0x10 d0=%#x\n", d0);
             break;
 
         case 0x14:
@@ -763,7 +758,7 @@ static void complete (SB16State *s)
 
         case 0x40:
             s->time_const = dsp_get_data (s);
-            ldebug ("set time const %d\n", s->time_const);
+            ldebug ("set time const %d", s->time_const);
             break;
 
         case 0x41:
@@ -776,12 +771,12 @@ static void complete (SB16State *s)
              * http://homepages.cae.wisc.edu/~brodskye/sb16doc/sb16doc.html#SamplingRate
              */
             s->freq = restrict_sampling_rate(dsp_get_hilo(s));
-            ldebug ("set freq %d\n", s->freq);
+            ldebug ("set freq %d", s->freq);
             break;
 
         case 0x48:
             s->block_size = dsp_get_lohi (s) + 1;
-            ldebug ("set dma block len %d\n", s->block_size);
+            ldebug ("set dma block len %d", s->block_size);
             break;
 
         case 0x74:
@@ -811,21 +806,21 @@ static void complete (SB16State *s)
                             );
                     }
                 }
-                ldebug ("mix silence %d %d %" PRId64 "\n", samples, bytes, ticks);
+                ldebug ("mix silence %d %d %" PRId64, samples, bytes, ticks);
             }
             break;
 
         case 0xe0:
             d0 = dsp_get_data (s);
             s->out_data_len = 0;
-            ldebug ("E0 data = %#x\n", d0);
+            ldebug ("E0 data = %#x", d0);
             dsp_out_data (s, ~d0);
             break;
 
         case 0xe2:
-#ifdef DEBUG
+#if DEBUG
             d0 = dsp_get_data (s);
-            dolog ("E2 = %#x\n", d0);
+            warn_report("sb16: E2 = %#x", d0);
 #endif
             break;
 
@@ -835,7 +830,7 @@ static void complete (SB16State *s)
 
         case 0xf9:
             d0 = dsp_get_data (s);
-            ldebug ("command 0xf9 with %#x\n", d0);
+            ldebug ("command 0xf9 with %#x", d0);
             switch (d0) {
             case 0x0e:
                 dsp_out_data (s, 0xff);
@@ -862,7 +857,7 @@ static void complete (SB16State *s)
         }
     }
 
-    ldebug ("\n");
+    ldebug ("");
     s->cmd = -1;
 }
 
@@ -926,7 +921,7 @@ static void dsp_write(void *opaque, uint32_t nport, uint32_t val)
 
     iport = nport - s->port;
 
-    ldebug ("write %#x <- %#x\n", nport, val);
+    ldebug ("write %#x <- %#x", nport, val);
     switch (iport) {
     case 0x06:
         switch (val) {
@@ -976,7 +971,7 @@ static void dsp_write(void *opaque, uint32_t nport, uint32_t val)
         }
         else {
             if (s->in_index == sizeof (s->in2_data)) {
-                dolog ("in data overrun\n");
+                warn_report("sb16: in data overrun");
             }
             else {
                 s->in2_data[s->in_index++] = val;
@@ -992,7 +987,7 @@ static void dsp_write(void *opaque, uint32_t nport, uint32_t val)
         break;
 
     default:
-        ldebug ("(nport=%#x, val=%#x)\n", nport, val);
+        ldebug ("(nport=%#x, val=%#x)", nport, val);
         break;
     }
 }
@@ -1016,7 +1011,7 @@ static uint32_t dsp_read(void *opaque, uint32_t nport)
         }
         else {
             if (s->cmd != -1) {
-                dolog ("empty output buffer for command %#x\n",
+                warn_report("sb16: empty output buffer for command %#x",
                        s->cmd);
             }
             retval = s->last_read_byte;
@@ -1029,7 +1024,7 @@ static uint32_t dsp_read(void *opaque, uint32_t nport)
         break;
 
     case 0x0d:                  /* timer interrupt clear */
-        /* dolog ("timer interrupt clear\n"); */
+        /* warn_report("sb16: timer interrupt clear"); */
         retval = 0;
         break;
 
@@ -1056,13 +1051,13 @@ static uint32_t dsp_read(void *opaque, uint32_t nport)
     }
 
     if (!ack) {
-        ldebug ("read %#x -> %#x\n", nport, retval);
+        ldebug ("read %#x -> %#x", nport, retval);
     }
 
     return retval;
 
  error:
-    dolog ("warning: dsp_read %#x error\n", nport);
+    warn_report("sb16: dsp_read %#x error", nport);
     return 0xff;
 }
 
@@ -1108,7 +1103,7 @@ static void mixer_write_datab(void *opaque, uint32_t nport, uint32_t val)
     SB16State *s = opaque;
 
     (void) nport;
-    ldebug ("mixer_write [%#x] <- %#x\n", s->mixer_nreg, val);
+    ldebug ("mixer_write [%#x] <- %#x", s->mixer_nreg, val);
 
     switch (s->mixer_nreg) {
     case 0x00:
@@ -1118,7 +1113,7 @@ static void mixer_write_datab(void *opaque, uint32_t nport, uint32_t val)
     case 0x80:
         {
             int irq = irq_of_magic (val);
-            ldebug ("setting irq to %d (val=%#x)\n", irq, val);
+            ldebug ("setting irq to %d (val=%#x)", irq, val);
             if (irq > 0) {
                 s->irq = irq;
             }
@@ -1150,7 +1145,7 @@ static void mixer_write_datab(void *opaque, uint32_t nport, uint32_t val)
 
     default:
         if (s->mixer_nreg >= 0x80) {
-            ldebug ("attempt to write mixer[%#x] <- %#x\n", s->mixer_nreg, val);
+            ldebug ("attempt to write mixer[%#x] <- %#x", s->mixer_nreg, val);
         }
         break;
     }
@@ -1165,11 +1160,11 @@ static uint32_t mixer_read(void *opaque, uint32_t nport)
     (void) nport;
 #ifndef DEBUG_SB16_MOST
     if (s->mixer_nreg != 0x82) {
-        ldebug ("mixer_read[%#x] -> %#x\n",
+        ldebug ("mixer_read[%#x] -> %#x",
                 s->mixer_nreg, s->mixer_regs[s->mixer_nreg]);
     }
 #else
-    ldebug ("mixer_read[%#x] -> %#x\n",
+    ldebug ("mixer_read[%#x] -> %#x",
             s->mixer_nreg, s->mixer_regs[s->mixer_nreg]);
 #endif
     return s->mixer_regs[s->mixer_nreg];
@@ -1241,7 +1236,7 @@ static int SB_read_DMA (void *opaque, int nchan, int dma_pos, int dma_len)
     till = s->left_till_irq;
 
 #ifdef DEBUG_SB16_MOST
-    dolog ("pos:%06d %d till:%d len:%d\n",
+    warn_report("sb16: pos:%06d %d till:%d len:%d",
            dma_pos, free, till, dma_len);
 #endif
 
@@ -1265,7 +1260,7 @@ static int SB_read_DMA (void *opaque, int nchan, int dma_pos, int dma_len)
     }
 
 #ifdef DEBUG_SB16_MOST
-    ldebug ("pos %5d free %5d size %5d till % 5d copy %5d written %5d size %5d\n",
+    ldebug ("pos %5d free %5d size %5d till % 5d copy %5d written %5d size %5d",
             dma_pos, free, dma_len, s->left_till_irq, copy, written,
             s->block_size);
 #endif
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 32/42] audio/replay: fix type punning
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (30 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 31/42] hw/audio: replace AUD_log() usage marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 33/42] audio: move internal APIs to audio_int.h marcandre.lureau
                   ` (11 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann,
	Alex Bennée

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 audio/audio.h           | 6 ++++--
 audio/mixeng.h          | 1 -
 include/system/replay.h | 3 ++-
 audio/mixeng.c          | 6 ++----
 replay/replay-audio.c   | 2 +-
 replay/stubs-system.c   | 2 +-
 6 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/audio/audio.h b/audio/audio.h
index 2175223ef6..68509fed58 100644
--- a/audio/audio.h
+++ b/audio/audio.h
@@ -160,9 +160,11 @@ int wav_start_capture(AudioState *state, CaptureState *s, const char *path,
 
 void audio_cleanup(void);
 
-void audio_sample_to_uint64(const void *samples, int pos,
+typedef struct st_sample st_sample;
+
+void audio_sample_to_uint64(const st_sample *sample, int pos,
                             uint64_t *left, uint64_t *right);
-void audio_sample_from_uint64(void *samples, int pos,
+void audio_sample_from_uint64(st_sample *sample, int pos,
                             uint64_t left, uint64_t right);
 
 void audio_add_audiodev(Audiodev *audio);
diff --git a/audio/mixeng.h b/audio/mixeng.h
index ead93ac2f7..f63283f408 100644
--- a/audio/mixeng.h
+++ b/audio/mixeng.h
@@ -33,7 +33,6 @@ struct st_sample { mixeng_real l; mixeng_real r; };
 struct mixeng_volume { int mute; int64_t r; int64_t l; };
 struct st_sample { int64_t l; int64_t r; };
 #endif
-typedef struct st_sample st_sample;
 
 typedef void (t_sample) (struct st_sample *dst, const void *src, int samples);
 typedef void (f_sample) (void *dst, const struct st_sample *src, int samples);
diff --git a/include/system/replay.h b/include/system/replay.h
index 1c87c97fdd..1e63c0784c 100644
--- a/include/system/replay.h
+++ b/include/system/replay.h
@@ -16,6 +16,7 @@
 #include "qapi/qapi-types-run-state.h"
 #include "qapi/qapi-types-ui.h"
 #include "block/aio.h"
+#include "audio/audio.h"
 
 /* replay clock kinds */
 enum ReplayClockKind {
@@ -165,7 +166,7 @@ void replay_net_packet_event(ReplayNetState *rns, unsigned flags,
 /*! Saves/restores number of played samples of audio out operation. */
 void replay_audio_out(size_t *played);
 /*! Saves/restores recorded samples of audio in operation. */
-void replay_audio_in(size_t *recorded, void *samples, size_t *wpos, size_t size);
+void replay_audio_in(size_t *recorded, st_sample *samples, size_t *wpos, size_t size);
 
 /* VM state operations */
 
diff --git a/audio/mixeng.c b/audio/mixeng.c
index be38617e9b..af9ec3d4d2 100644
--- a/audio/mixeng.c
+++ b/audio/mixeng.c
@@ -404,7 +404,7 @@ f_sample *mixeng_clip_float[2][2] = {
     }
 };
 
-void audio_sample_to_uint64(const void *samples, int pos,
+void audio_sample_to_uint64(const st_sample *sample, int pos,
                             uint64_t *left, uint64_t *right)
 {
 #ifdef FLOAT_MIXENG
@@ -412,14 +412,13 @@ void audio_sample_to_uint64(const void *samples, int pos,
         "Coreaudio and floating point samples are not supported by replay yet");
     abort();
 #else
-    const struct st_sample *sample = samples;
     sample += pos;
     *left = sample->l;
     *right = sample->r;
 #endif
 }
 
-void audio_sample_from_uint64(void *samples, int pos,
+void audio_sample_from_uint64(st_sample *sample, int pos,
                             uint64_t left, uint64_t right)
 {
 #ifdef FLOAT_MIXENG
@@ -427,7 +426,6 @@ void audio_sample_from_uint64(void *samples, int pos,
         "Coreaudio and floating point samples are not supported by replay yet");
     abort();
 #else
-    struct st_sample *sample = samples;
     sample += pos;
     sample->l = left;
     sample->r = right;
diff --git a/replay/replay-audio.c b/replay/replay-audio.c
index ed2ba2164b..3413801062 100644
--- a/replay/replay-audio.c
+++ b/replay/replay-audio.c
@@ -35,7 +35,7 @@ void replay_audio_out(size_t *played)
     }
 }
 
-void replay_audio_in(size_t *recorded, void *samples, size_t *wpos, size_t size)
+void replay_audio_in(size_t *recorded, st_sample *samples, size_t *wpos, size_t size)
 {
     int pos;
     uint64_t left, right;
diff --git a/replay/stubs-system.c b/replay/stubs-system.c
index 8f2b2d326e..7f85764936 100644
--- a/replay/stubs-system.c
+++ b/replay/stubs-system.c
@@ -15,7 +15,7 @@ void replay_input_sync_event(void)
 void replay_add_blocker(const char *feature)
 {
 }
-void replay_audio_in(size_t *recorded, void *samples, size_t *wpos, size_t size)
+void replay_audio_in(size_t *recorded, st_sample *samples, size_t *wpos, size_t size)
 {
 }
 void replay_audio_out(size_t *played)
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 33/42] audio: move internal APIs to audio_int.h
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (31 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 32/42] audio/replay: fix type punning marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  7:08   ` Philippe Mathieu-Daudé
  2025-10-22  6:56 ` [PATCH v2 34/42] audio: rename AudioState -> AudioBackend marcandre.lureau
                   ` (10 subsequent siblings)
  43 siblings, 1 reply; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 audio/audio.h          | 21 ---------------------
 audio/audio_int.h      | 22 ++++++++++++++++++++++
 audio/audio-hmp-cmds.c |  2 +-
 audio/wavcapture.c     |  2 +-
 4 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/audio/audio.h b/audio/audio.h
index 68509fed58..b8b9715896 100644
--- a/audio/audio.h
+++ b/audio/audio.h
@@ -38,15 +38,6 @@ typedef struct audsettings {
     int endianness;
 } audsettings;
 
-audsettings audiodev_to_audsettings(AudiodevPerDirectionOptions *pdo);
-int audioformat_bytes_per_sample(AudioFormat fmt);
-int audio_buffer_frames(AudiodevPerDirectionOptions *pdo,
-                        audsettings *as, int def_usecs);
-int audio_buffer_samples(AudiodevPerDirectionOptions *pdo,
-                         audsettings *as, int def_usecs);
-int audio_buffer_bytes(AudiodevPerDirectionOptions *pdo,
-                       audsettings *as, int def_usecs);
-
 typedef enum {
     AUD_CNOTIFY_ENABLE,
     AUD_CNOTIFY_DISABLE
@@ -88,9 +79,6 @@ typedef struct QEMUAudioTimeStamp {
     uint64_t old_ts;
 } QEMUAudioTimeStamp;
 
-void AUD_vlog (const char *cap, const char *fmt, va_list ap) G_GNUC_PRINTF(2, 0);
-void AUD_log (const char *cap, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
-
 bool AUD_register_card (const char *name, QEMUSoundCard *card, Error **errp);
 void AUD_remove_card (QEMUSoundCard *card);
 CaptureVoiceOut *AUD_add_capture(
@@ -149,15 +137,6 @@ int  AUD_is_active_in (SWVoiceIn *sw);
 void     AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
 uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
 
-static inline void *advance (void *p, int incr)
-{
-    uint8_t *d = p;
-    return (d + incr);
-}
-
-int wav_start_capture(AudioState *state, CaptureState *s, const char *path,
-                      int freq, int bits, int nchannels);
-
 void audio_cleanup(void);
 
 typedef struct st_sample st_sample;
diff --git a/audio/audio_int.h b/audio/audio_int.h
index 4a4d69f2bf..cc7a6fe087 100644
--- a/audio/audio_int.h
+++ b/audio/audio_int.h
@@ -29,12 +29,16 @@
 #define FLOAT_MIXENG
 /* #define RECIPROCAL */
 #endif
+#include "audio.h"
 #include "mixeng.h"
 
 #ifdef CONFIG_GIO
 #include <gio/gio.h>
 #endif
 
+void AUD_vlog (const char *cap, const char *fmt, va_list ap) G_GNUC_PRINTF(2, 0);
+void AUD_log (const char *cap, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
+
 struct audio_pcm_ops;
 
 struct audio_callback {
@@ -187,6 +191,24 @@ struct audio_pcm_ops {
     void   (*volume_in)(HWVoiceIn *hw, Volume *vol);
 };
 
+audsettings audiodev_to_audsettings(AudiodevPerDirectionOptions *pdo);
+int audioformat_bytes_per_sample(AudioFormat fmt);
+int audio_buffer_frames(AudiodevPerDirectionOptions *pdo,
+                        audsettings *as, int def_usecs);
+int audio_buffer_samples(AudiodevPerDirectionOptions *pdo,
+                         audsettings *as, int def_usecs);
+int audio_buffer_bytes(AudiodevPerDirectionOptions *pdo,
+                       audsettings *as, int def_usecs);
+
+static inline void *advance (void *p, int incr)
+{
+    uint8_t *d = p;
+    return (d + incr);
+}
+
+int wav_start_capture(AudioState *state, CaptureState *s, const char *path,
+                      int freq, int bits, int nchannels);
+
 void audio_generic_run_buffer_in(HWVoiceIn *hw);
 void *audio_generic_get_buffer_in(HWVoiceIn *hw, size_t *size);
 void audio_generic_put_buffer_in(HWVoiceIn *hw, void *buf, size_t size);
diff --git a/audio/audio-hmp-cmds.c b/audio/audio-hmp-cmds.c
index 8774c09f18..819f8fa9d8 100644
--- a/audio/audio-hmp-cmds.c
+++ b/audio/audio-hmp-cmds.c
@@ -23,7 +23,7 @@
  */
 
 #include "qemu/osdep.h"
-#include "audio/audio.h"
+#include "audio_int.h"
 #include "monitor/hmp.h"
 #include "monitor/monitor.h"
 #include "qapi/error.h"
diff --git a/audio/wavcapture.c b/audio/wavcapture.c
index b990844d48..0fbc695d23 100644
--- a/audio/wavcapture.c
+++ b/audio/wavcapture.c
@@ -1,7 +1,7 @@
 #include "qemu/osdep.h"
 #include "qemu/qemu-print.h"
 #include "qemu/error-report.h"
-#include "audio.h"
+#include "audio_int.h"
 
 typedef struct {
     FILE *f;
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 34/42] audio: rename AudioState -> AudioBackend
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (32 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 33/42] audio: move internal APIs to audio_int.h marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 35/42] audio: remove QEMUSoundCard marcandre.lureau
                   ` (9 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann,
	Christian Schoenebeck, Eduardo Habkost, Marcel Apfelbaum,
	Yanan Wang, Zhao Liu, Daniel P. Berrangé

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Naming is hard. But in general in QEMU, a host "backend" is the term
used to fullfill the request made by the device or frontend.

AudioBackend will become an abstract base class in a follow-up series.

Currently the frontend is QEMUSoundCard, we are going to drop that next.

Note that "audiodev" is the corresponding QAPI type name (or configuration).

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 audio/audio.h                    | 16 +++---
 audio/audio_int.h                | 20 +++----
 audio/audio_template.h           | 20 +++----
 ui/vnc.h                         |  2 +-
 audio/alsaaudio.c                |  2 +-
 audio/audio-hmp-cmds.c           |  2 +-
 audio/audio.c                    | 90 ++++++++++++++++----------------
 audio/dbusaudio.c                |  8 +--
 audio/ossaudio.c                 |  4 +-
 audio/wavcapture.c               |  2 +-
 hw/audio/pcspk.c                 |  2 +-
 hw/core/machine.c                |  2 +-
 hw/core/qdev-properties-system.c |  6 +--
 ui/dbus.c                        |  8 +--
 ui/vnc.c                         | 10 ++--
 15 files changed, 97 insertions(+), 97 deletions(-)

diff --git a/audio/audio.h b/audio/audio.h
index b8b9715896..69ba1e8b94 100644
--- a/audio/audio.h
+++ b/audio/audio.h
@@ -64,14 +64,14 @@ typedef struct SWVoiceOut SWVoiceOut;
 typedef struct CaptureVoiceOut CaptureVoiceOut;
 typedef struct SWVoiceIn SWVoiceIn;
 
-struct AudioStateClass {
+struct AudioBackendClass {
     ObjectClass parent_class;
 };
 
-typedef struct AudioState AudioState;
+typedef struct AudioBackend AudioBackend;
 typedef struct QEMUSoundCard {
     char *name;
-    AudioState *state;
+    AudioBackend *be;
     QLIST_ENTRY (QEMUSoundCard) entries;
 } QEMUSoundCard;
 
@@ -82,7 +82,7 @@ typedef struct QEMUAudioTimeStamp {
 bool AUD_register_card (const char *name, QEMUSoundCard *card, Error **errp);
 void AUD_remove_card (QEMUSoundCard *card);
 CaptureVoiceOut *AUD_add_capture(
-    AudioState *s,
+    AudioBackend *s,
     struct audsettings *as,
     struct audio_capture_ops *ops,
     void *opaque
@@ -153,14 +153,14 @@ void audio_create_default_audiodevs(void);
 void audio_init_audiodevs(void);
 void audio_help(void);
 
-AudioState *audio_state_by_name(const char *name, Error **errp);
-AudioState *audio_get_default_audio_state(Error **errp);
+AudioBackend *audio_be_by_name(const char *name, Error **errp);
+AudioBackend *audio_get_default_audio_be(Error **errp);
 const char *audio_get_id(QEMUSoundCard *card);
 
 #define DEFINE_AUDIO_PROPERTIES(_s, _f)         \
     DEFINE_PROP_AUDIODEV("audiodev", _s, _f)
 
-#define TYPE_AUDIO_STATE "audio-state"
-OBJECT_DECLARE_TYPE(AudioState, AudioStateClass, AUDIO_STATE)
+#define TYPE_AUDIO_BACKEND "audio-backend"
+OBJECT_DECLARE_TYPE(AudioBackend, AudioBackendClass, AUDIO_BACKEND)
 
 #endif /* QEMU_AUDIO_H */
diff --git a/audio/audio_int.h b/audio/audio_int.h
index cc7a6fe087..d3929034b3 100644
--- a/audio/audio_int.h
+++ b/audio/audio_int.h
@@ -57,7 +57,7 @@ struct audio_pcm_info {
     int swap_endianness;
 };
 
-typedef struct AudioState AudioState;
+typedef struct AudioBackend AudioBackend;
 typedef struct SWVoiceCap SWVoiceCap;
 
 typedef struct STSampleBuffer {
@@ -66,7 +66,7 @@ typedef struct STSampleBuffer {
 } STSampleBuffer;
 
 typedef struct HWVoiceOut {
-    AudioState *s;
+    AudioBackend *s;
     int enabled;
     int poll_mode;
     int pending_disable;
@@ -87,7 +87,7 @@ typedef struct HWVoiceOut {
 } HWVoiceOut;
 
 typedef struct HWVoiceIn {
-    AudioState *s;
+    AudioBackend *s;
     int enabled;
     int poll_mode;
     struct audio_pcm_info info;
@@ -109,7 +109,7 @@ typedef struct HWVoiceIn {
 
 struct SWVoiceOut {
     QEMUSoundCard *card;
-    AudioState *s;
+    AudioBackend *s;
     struct audio_pcm_info info;
     t_sample *conv;
     STSampleBuffer resample_buf;
@@ -126,7 +126,7 @@ struct SWVoiceOut {
 
 struct SWVoiceIn {
     QEMUSoundCard *card;
-    AudioState *s;
+    AudioBackend *s;
     int active;
     struct audio_pcm_info info;
     void *rate;
@@ -147,7 +147,7 @@ struct audio_driver {
     void *(*init) (Audiodev *, Error **);
     void (*fini) (void *);
 #ifdef CONFIG_GIO
-    void (*set_dbus_server) (AudioState *s, GDBusObjectManagerServer *manager, bool p2p);
+    void (*set_dbus_server) (AudioBackend *s, GDBusObjectManagerServer *manager, bool p2p);
 #endif
     struct audio_pcm_ops *pcm_ops;
     int max_voices_out;
@@ -206,7 +206,7 @@ static inline void *advance (void *p, int incr)
     return (d + incr);
 }
 
-int wav_start_capture(AudioState *state, CaptureState *s, const char *path,
+int wav_start_capture(AudioBackend *state, CaptureState *s, const char *path,
                       int freq, int bits, int nchannels);
 
 void audio_generic_run_buffer_in(HWVoiceIn *hw);
@@ -238,7 +238,7 @@ struct SWVoiceCap {
     QLIST_ENTRY (SWVoiceCap) entries;
 };
 
-typedef struct AudioState {
+typedef struct AudioBackend {
     Object parent;
 
     struct audio_driver *drv;
@@ -258,7 +258,7 @@ typedef struct AudioState {
     bool timer_running;
     uint64_t timer_last;
     VMChangeStateEntry *vmse;
-} AudioState;
+} AudioBackend;
 
 extern const struct mixeng_volume nominal_volume;
 
@@ -271,7 +271,7 @@ void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len);
 
 int audio_bug (const char *funcname, int cond);
 
-void audio_run(AudioState *s, const char *msg);
+void audio_run(AudioBackend *s, const char *msg);
 
 const char *audio_application_name(void);
 
diff --git a/audio/audio_template.h b/audio/audio_template.h
index c29d79c443..b3c10a0709 100644
--- a/audio/audio_template.h
+++ b/audio/audio_template.h
@@ -36,7 +36,7 @@
 #define HWBUF hw->conv_buf
 #endif
 
-static void glue(audio_init_nb_voices_, TYPE)(AudioState *s,
+static void glue(audio_init_nb_voices_, TYPE)(AudioBackend *s,
                                               struct audio_driver *drv, int min_voices)
 {
     int max_voices = glue (drv->max_voices_, TYPE);
@@ -221,7 +221,7 @@ static void glue (audio_pcm_hw_del_sw_, TYPE) (SW *sw)
 static void glue (audio_pcm_hw_gc_, TYPE) (HW **hwp)
 {
     HW *hw = *hwp;
-    AudioState *s = hw->s;
+    AudioBackend *s = hw->s;
 
     if (!hw->sw_head.lh_first) {
 #ifdef DAC
@@ -236,12 +236,12 @@ static void glue (audio_pcm_hw_gc_, TYPE) (HW **hwp)
     }
 }
 
-static HW *glue(audio_pcm_hw_find_any_, TYPE)(AudioState *s, HW *hw)
+static HW *glue(audio_pcm_hw_find_any_, TYPE)(AudioBackend *s, HW *hw)
 {
     return hw ? hw->entries.le_next : glue (s->hw_head_, TYPE).lh_first;
 }
 
-static HW *glue(audio_pcm_hw_find_any_enabled_, TYPE)(AudioState *s, HW *hw)
+static HW *glue(audio_pcm_hw_find_any_enabled_, TYPE)(AudioBackend *s, HW *hw)
 {
     while ((hw = glue(audio_pcm_hw_find_any_, TYPE)(s, hw))) {
         if (hw->enabled) {
@@ -251,7 +251,7 @@ static HW *glue(audio_pcm_hw_find_any_enabled_, TYPE)(AudioState *s, HW *hw)
     return NULL;
 }
 
-static HW *glue(audio_pcm_hw_find_specific_, TYPE)(AudioState *s, HW *hw,
+static HW *glue(audio_pcm_hw_find_specific_, TYPE)(AudioBackend *s, HW *hw,
                                                    struct audsettings *as)
 {
     while ((hw = glue(audio_pcm_hw_find_any_, TYPE)(s, hw))) {
@@ -262,7 +262,7 @@ static HW *glue(audio_pcm_hw_find_specific_, TYPE)(AudioState *s, HW *hw,
     return NULL;
 }
 
-static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioState *s,
+static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioBackend *s,
                                              struct audsettings *as)
 {
     HW *hw;
@@ -398,7 +398,7 @@ AudiodevPerDirectionOptions *glue(audio_get_pdo_, TYPE)(Audiodev *dev)
     abort();
 }
 
-static HW *glue(audio_pcm_hw_add_, TYPE)(AudioState *s, struct audsettings *as)
+static HW *glue(audio_pcm_hw_add_, TYPE)(AudioBackend *s, struct audsettings *as)
 {
     HW *hw;
     AudiodevPerDirectionOptions *pdo = glue(audio_get_pdo_, TYPE)(s->dev);
@@ -424,7 +424,7 @@ static HW *glue(audio_pcm_hw_add_, TYPE)(AudioState *s, struct audsettings *as)
 }
 
 static SW *glue(audio_pcm_create_voice_pair_, TYPE)(
-    AudioState *s,
+    AudioBackend *s,
     const char *sw_name,
     struct audsettings *as
     )
@@ -494,7 +494,7 @@ SW *glue (AUD_open_, TYPE) (
     struct audsettings *as
     )
 {
-    AudioState *s;
+    AudioBackend *s;
     AudiodevPerDirectionOptions *pdo;
 
     if (audio_bug(__func__, !card || !name || !callback_fn || !as)) {
@@ -503,7 +503,7 @@ SW *glue (AUD_open_, TYPE) (
         goto fail;
     }
 
-    s = card->state;
+    s = card->be;
     pdo = glue(audio_get_pdo_, TYPE)(s->dev);
 
     ldebug ("open %s, freq %d, nchannels %d, fmt %d\n",
diff --git a/ui/vnc.h b/ui/vnc.h
index f2dab2f4d9..e2137c5ed1 100644
--- a/ui/vnc.h
+++ b/ui/vnc.h
@@ -184,7 +184,7 @@ struct VncDisplay
     VncDisplaySASL sasl;
 #endif
 
-    AudioState *audio_state;
+    AudioBackend *audio_be;
 
     VMChangeStateEntry *vmstate_handler_entry;
 };
diff --git a/audio/alsaaudio.c b/audio/alsaaudio.c
index 9b6c01c0ef..797cb478e6 100644
--- a/audio/alsaaudio.c
+++ b/audio/alsaaudio.c
@@ -41,7 +41,7 @@ struct pollhlp {
     struct pollfd *pfds;
     int count;
     int mask;
-    AudioState *s;
+    AudioBackend *s;
 };
 
 typedef struct ALSAVoiceOut {
diff --git a/audio/audio-hmp-cmds.c b/audio/audio-hmp-cmds.c
index 819f8fa9d8..1e56af21ab 100644
--- a/audio/audio-hmp-cmds.c
+++ b/audio/audio-hmp-cmds.c
@@ -67,7 +67,7 @@ void hmp_wavcapture(Monitor *mon, const QDict *qdict)
     const char *audiodev = qdict_get_str(qdict, "audiodev");
     CaptureState *s;
     Error *local_err = NULL;
-    AudioState *as = audio_state_by_name(audiodev, &local_err);
+    AudioBackend *as = audio_be_by_name(audiodev, &local_err);
 
     if (!as) {
         error_report_err(local_err);
diff --git a/audio/audio.c b/audio/audio.c
index 9e6d79b4e3..8a7489ec82 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -99,7 +99,7 @@ static audio_driver *audio_driver_lookup(const char *name)
     return NULL;
 }
 
-static AudioState *default_audio_state;
+static AudioBackend *default_audio_be;
 
 const struct mixeng_volume nominal_volume = {
     .mute = 0,
@@ -380,7 +380,7 @@ void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len)
 /*
  * Capture
  */
-static CaptureVoiceOut *audio_pcm_capture_find_specific(AudioState *s,
+static CaptureVoiceOut *audio_pcm_capture_find_specific(AudioBackend *s,
                                                         struct audsettings *as)
 {
     CaptureVoiceOut *cap;
@@ -460,7 +460,7 @@ static void audio_detach_capture (HWVoiceOut *hw)
 
 static int audio_attach_capture (HWVoiceOut *hw)
 {
-    AudioState *s = hw->s;
+    AudioBackend *s = hw->s;
     CaptureVoiceOut *cap;
 
     audio_detach_capture (hw);
@@ -798,7 +798,7 @@ static void audio_pcm_print_info (const char *cap, struct audio_pcm_info *info)
 /*
  * Timer
  */
-static int audio_is_timer_needed(AudioState *s)
+static int audio_is_timer_needed(AudioBackend *s)
 {
     HWVoiceIn *hwi = NULL;
     HWVoiceOut *hwo = NULL;
@@ -816,7 +816,7 @@ static int audio_is_timer_needed(AudioState *s)
     return 0;
 }
 
-static void audio_reset_timer (AudioState *s)
+static void audio_reset_timer (AudioBackend *s)
 {
     if (audio_is_timer_needed(s)) {
         timer_mod_anticipate_ns(s->ts,
@@ -838,7 +838,7 @@ static void audio_reset_timer (AudioState *s)
 static void audio_timer (void *opaque)
 {
     int64_t now, diff;
-    AudioState *s = opaque;
+    AudioBackend *s = opaque;
 
     now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
     diff = now - s->timer_last;
@@ -921,7 +921,7 @@ void AUD_set_active_out (SWVoiceOut *sw, int on)
 
     hw = sw->hw;
     if (sw->active != on) {
-        AudioState *s = sw->s;
+        AudioBackend *s = sw->s;
         SWVoiceOut *temp_sw;
         SWVoiceCap *sc;
 
@@ -969,7 +969,7 @@ void AUD_set_active_in (SWVoiceIn *sw, int on)
 
     hw = sw->hw;
     if (sw->active != on) {
-        AudioState *s = sw->s;
+        AudioBackend *s = sw->s;
         SWVoiceIn *temp_sw;
 
         if (on) {
@@ -1137,7 +1137,7 @@ static size_t audio_pcm_hw_run_out(HWVoiceOut *hw, size_t live)
     return clipped;
 }
 
-static void audio_run_out (AudioState *s)
+static void audio_run_out (AudioBackend *s)
 {
     HWVoiceOut *hw = NULL;
     SWVoiceOut *sw;
@@ -1291,7 +1291,7 @@ static size_t audio_pcm_hw_run_in(HWVoiceIn *hw, size_t samples)
     return conv;
 }
 
-static void audio_run_in (AudioState *s)
+static void audio_run_in (AudioBackend *s)
 {
     HWVoiceIn *hw = NULL;
 
@@ -1339,7 +1339,7 @@ static void audio_run_in (AudioState *s)
     }
 }
 
-static void audio_run_capture (AudioState *s)
+static void audio_run_capture (AudioBackend *s)
 {
     CaptureVoiceOut *cap;
 
@@ -1386,7 +1386,7 @@ static void audio_run_capture (AudioState *s)
     }
 }
 
-void audio_run(AudioState *s, const char *msg)
+void audio_run(AudioBackend *s, const char *msg)
 {
     audio_run_out(s);
     audio_run_in(s);
@@ -1559,7 +1559,7 @@ size_t audio_generic_read(HWVoiceIn *hw, void *buf, size_t size)
     return total;
 }
 
-static bool audio_driver_init(AudioState *s, struct audio_driver *drv,
+static bool audio_driver_init(AudioBackend *s, struct audio_driver *drv,
                               Audiodev *dev, Error **errp)
 {
     s->drv_opaque = drv->init(dev, errp);
@@ -1592,7 +1592,7 @@ static bool audio_driver_init(AudioState *s, struct audio_driver *drv,
 static void audio_vm_change_state_handler (void *opaque, bool running,
                                            RunState state)
 {
-    AudioState *s = opaque;
+    AudioBackend *s = opaque;
     HWVoiceOut *hwo = NULL;
     HWVoiceIn *hwi = NULL;
 
@@ -1613,9 +1613,9 @@ static void audio_vm_change_state_handler (void *opaque, bool running,
 
 static const VMStateDescription vmstate_audio;
 
-static void audio_state_init(Object *obj)
+static void audio_be_init(Object *obj)
 {
-    AudioState *s = AUDIO_STATE(obj);
+    AudioBackend *s = AUDIO_BACKEND(obj);
 
     QLIST_INIT (&s->hw_head_out);
     QLIST_INIT (&s->hw_head_in);
@@ -1629,9 +1629,9 @@ static void audio_state_init(Object *obj)
     vmstate_register_any(NULL, &vmstate_audio, s);
 }
 
-static void audio_state_finalize(Object *obj)
+static void audio_be_finalize(Object *obj)
 {
-    AudioState *s = AUDIO_STATE(obj);
+    AudioBackend *s = AUDIO_BACKEND(obj);
     HWVoiceOut *hwo, *hwon;
     HWVoiceIn *hwi, *hwin;
 
@@ -1692,7 +1692,7 @@ static Object *get_audiodevs_root(void)
 
 void audio_cleanup(void)
 {
-    default_audio_state = NULL;
+    default_audio_be = NULL;
 
     object_unparent(get_audiodevs_root());
 }
@@ -1743,14 +1743,14 @@ void audio_create_default_audiodevs(void)
  * if dev == NULL => legacy implicit initialization, return the already created
  *   state or create a new one
  */
-static AudioState *audio_init(Audiodev *dev, Error **errp)
+static AudioBackend *audio_init(Audiodev *dev, Error **errp)
 {
     int done = 0;
     const char *drvname;
-    AudioState *s;
+    AudioBackend *s;
     struct audio_driver *driver;
 
-    s = AUDIO_STATE(object_new(TYPE_AUDIO_STATE));
+    s = AUDIO_BACKEND(object_new(TYPE_AUDIO_BACKEND));
 
     if (dev) {
         /* -audiodev option */
@@ -1766,7 +1766,7 @@ static AudioState *audio_init(Audiodev *dev, Error **errp)
             goto out;
         }
     } else {
-        assert(!default_audio_state);
+        assert(!default_audio_be);
         for (;;) {
             AudiodevListEntry *e = QSIMPLEQ_FIRST(&default_audiodevs);
             if (!e) {
@@ -1797,11 +1797,11 @@ out:
     return NULL;
 }
 
-AudioState *audio_get_default_audio_state(Error **errp)
+AudioBackend *audio_get_default_audio_be(Error **errp)
 {
-    if (!default_audio_state) {
-        default_audio_state = audio_init(NULL, errp);
-        if (!default_audio_state) {
+    if (!default_audio_be) {
+        default_audio_be = audio_init(NULL, errp);
+        if (!default_audio_be) {
             if (!QSIMPLEQ_EMPTY(&audiodevs)) {
                 error_append_hint(errp, "Perhaps you wanted to use -audio or set audiodev=%s?\n",
                                   QSIMPLEQ_FIRST(&audiodevs)->dev->id);
@@ -1809,21 +1809,21 @@ AudioState *audio_get_default_audio_state(Error **errp)
         }
     }
 
-    return default_audio_state;
+    return default_audio_be;
 }
 
 bool AUD_register_card (const char *name, QEMUSoundCard *card, Error **errp)
 {
-    if (!card->state) {
-        card->state = audio_get_default_audio_state(errp);
-        if (!card->state) {
+    if (!card->be) {
+        card->be = audio_get_default_audio_be(errp);
+        if (!card->be) {
             return false;
         }
     }
 
     card->name = g_strdup (name);
     memset (&card->entries, 0, sizeof (card->entries));
-    QLIST_INSERT_HEAD(&card->state->card_head, card, entries);
+    QLIST_INSERT_HEAD(&card->be->card_head, card, entries);
 
     return true;
 }
@@ -1837,7 +1837,7 @@ void AUD_remove_card (QEMUSoundCard *card)
 static struct audio_pcm_ops capture_pcm_ops;
 
 CaptureVoiceOut *AUD_add_capture(
-    AudioState *s,
+    AudioBackend *s,
     struct audsettings *as,
     struct audio_capture_ops *ops,
     void *cb_opaque
@@ -2220,7 +2220,7 @@ int audio_buffer_bytes(AudiodevPerDirectionOptions *pdo,
         audioformat_bytes_per_sample(as->fmt);
 }
 
-AudioState *audio_state_by_name(const char *name, Error **errp)
+AudioBackend *audio_be_by_name(const char *name, Error **errp)
 {
     Object *obj = object_resolve_path_component(get_audiodevs_root(), name);
 
@@ -2228,15 +2228,15 @@ AudioState *audio_state_by_name(const char *name, Error **errp)
         error_setg(errp, "audiodev '%s' not found", name);
         return NULL;
     } else {
-        return AUDIO_STATE(obj);
+        return AUDIO_BACKEND(obj);
     }
 }
 
 const char *audio_get_id(QEMUSoundCard *card)
 {
-    if (card->state) {
-        assert(card->state->dev);
-        return card->state->dev->id;
+    if (card->be) {
+        assert(card->be->dev);
+        return card->be->dev->id;
     } else {
         return "";
     }
@@ -2305,19 +2305,19 @@ AudiodevList *qmp_query_audiodevs(Error **errp)
     return ret;
 }
 
-static const TypeInfo audio_state_info = {
-    .name = TYPE_AUDIO_STATE,
+static const TypeInfo audio_be_info = {
+    .name = TYPE_AUDIO_BACKEND,
     .parent = TYPE_OBJECT,
-    .instance_size = sizeof(AudioState),
-    .instance_init = audio_state_init,
-    .instance_finalize = audio_state_finalize,
+    .instance_size = sizeof(AudioBackend),
+    .instance_init = audio_be_init,
+    .instance_finalize = audio_be_finalize,
     .abstract = false, // todo, subclass and make it abstract
-    .class_size = sizeof(AudioStateClass),
+    .class_size = sizeof(AudioBackendClass),
 };
 
 static void register_types(void)
 {
-    type_register_static(&audio_state_info);
+    type_register_static(&audio_be_info);
 }
 
 type_init(register_types);
diff --git a/audio/dbusaudio.c b/audio/dbusaudio.c
index 908214a170..49cef38e3e 100644
--- a/audio/dbusaudio.c
+++ b/audio/dbusaudio.c
@@ -458,7 +458,7 @@ listener_in_vanished_cb(GDBusConnection *connection,
 }
 
 static gboolean
-dbus_audio_register_listener(AudioState *s,
+dbus_audio_register_listener(AudioBackend *s,
                              GDBusMethodInvocation *invocation,
 #ifdef G_OS_UNIX
                              GUnixFDList *fd_list,
@@ -615,7 +615,7 @@ dbus_audio_register_listener(AudioState *s,
 }
 
 static gboolean
-dbus_audio_register_out_listener(AudioState *s,
+dbus_audio_register_out_listener(AudioBackend *s,
                                  GDBusMethodInvocation *invocation,
 #ifdef G_OS_UNIX
                                  GUnixFDList *fd_list,
@@ -631,7 +631,7 @@ dbus_audio_register_out_listener(AudioState *s,
 }
 
 static gboolean
-dbus_audio_register_in_listener(AudioState *s,
+dbus_audio_register_in_listener(AudioBackend *s,
                                 GDBusMethodInvocation *invocation,
 #ifdef G_OS_UNIX
                                 GUnixFDList *fd_list,
@@ -646,7 +646,7 @@ dbus_audio_register_in_listener(AudioState *s,
 }
 
 static void
-dbus_audio_set_server(AudioState *s, GDBusObjectManagerServer *server, bool p2p)
+dbus_audio_set_server(AudioBackend *s, GDBusObjectManagerServer *server, bool p2p)
 {
     DBusAudio *da = s->drv_opaque;
 
diff --git a/audio/ossaudio.c b/audio/ossaudio.c
index c5858284a1..4a549b26a2 100644
--- a/audio/ossaudio.c
+++ b/audio/ossaudio.c
@@ -107,13 +107,13 @@ static void oss_anal_close (int *fdp)
 
 static void oss_helper_poll_out (void *opaque)
 {
-    AudioState *s = opaque;
+    AudioBackend *s = opaque;
     audio_run(s, "oss_poll_out");
 }
 
 static void oss_helper_poll_in (void *opaque)
 {
-    AudioState *s = opaque;
+    AudioBackend *s = opaque;
     audio_run(s, "oss_poll_in");
 }
 
diff --git a/audio/wavcapture.c b/audio/wavcapture.c
index 0fbc695d23..b33a38ff45 100644
--- a/audio/wavcapture.c
+++ b/audio/wavcapture.c
@@ -103,7 +103,7 @@ static struct capture_ops wav_capture_ops = {
     .info = wav_capture_info
 };
 
-int wav_start_capture(AudioState *state, CaptureState *s, const char *path,
+int wav_start_capture(AudioBackend *state, CaptureState *s, const char *path,
                       int freq, int bits, int nchannels)
 {
     WAVState *wav;
diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index c8c63b7915..e9ab5ac41b 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -188,7 +188,7 @@ static void pcspk_realizefn(DeviceState *dev, Error **errp)
 
     isa_register_ioport(isadev, &s->ioport, s->iobase);
 
-    if (s->card.state && AUD_register_card(s_spk, &s->card, errp)) {
+    if (s->card.be && AUD_register_card(s_spk, &s->card, errp)) {
         pcspk_audio_init(s);
     }
 }
diff --git a/hw/core/machine.c b/hw/core/machine.c
index 681adbb7ac..2de8b89606 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -763,7 +763,7 @@ static void machine_set_audiodev(Object *obj, const char *value,
 {
     MachineState *ms = MACHINE(obj);
 
-    if (!audio_state_by_name(value, errp)) {
+    if (!audio_be_by_name(value, errp)) {
         return;
     }
 
diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index 1f810b7ddf..c83a52fc62 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -499,16 +499,16 @@ static void set_audiodev(Object *obj, Visitor *v, const char* name,
 {
     const Property *prop = opaque;
     QEMUSoundCard *card = object_field_prop_ptr(obj, prop);
-    AudioState *state;
+    AudioBackend *state;
     g_autofree char *str = NULL;
 
     if (!visit_type_str(v, name, &str, errp)) {
         return;
     }
 
-    state = audio_state_by_name(str, errp);
+    state = audio_be_by_name(str, errp);
     if (state) {
-        card->state = state;
+        card->be = state;
     }
 }
 
diff --git a/ui/dbus.c b/ui/dbus.c
index dd0336702d..84cff47ec7 100644
--- a/ui/dbus.c
+++ b/ui/dbus.c
@@ -220,16 +220,16 @@ dbus_display_complete(UserCreatable *uc, Error **errp)
     }
 
     if (dd->audiodev && *dd->audiodev) {
-        AudioState *audio_state = audio_state_by_name(dd->audiodev, errp);
-        if (!audio_state) {
+        AudioBackend *audio_be = audio_be_by_name(dd->audiodev, errp);
+        if (!audio_be) {
             return;
         }
-        if (!g_str_equal(audio_state->drv->name, "dbus")) {
+        if (!g_str_equal(audio_be->drv->name, "dbus")) {
             error_setg(errp, "Audiodev '%s' is not compatible with DBus",
                        dd->audiodev);
             return;
         }
-        audio_state->drv->set_dbus_server(audio_state, dd->server, dd->p2p);
+        audio_be->drv->set_dbus_server(audio_be, dd->server, dd->p2p);
     }
 
     consoles = g_array_new(FALSE, FALSE, sizeof(guint32));
diff --git a/ui/vnc.c b/ui/vnc.c
index 77c823bf2e..0094ec680c 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -1276,7 +1276,7 @@ static void audio_add(VncState *vs)
     ops.destroy = audio_capture_destroy;
     ops.capture = audio_capture;
 
-    vs->audio_cap = AUD_add_capture(vs->vd->audio_state, &vs->as, &ops, vs);
+    vs->audio_cap = AUD_add_capture(vs->vd->audio_be, &vs->as, &ops, vs);
     if (!vs->audio_cap) {
         error_report("Failed to add audio capture");
     }
@@ -2193,7 +2193,7 @@ static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings)
             send_ext_key_event_ack(vs);
             break;
         case VNC_ENCODING_AUDIO:
-            if (vs->vd->audio_state) {
+            if (vs->vd->audio_be) {
                 vnc_set_feature(vs, VNC_FEATURE_AUDIO);
                 send_ext_audio_ack(vs);
             }
@@ -4236,12 +4236,12 @@ void vnc_display_open(const char *id, Error **errp)
 
     audiodev = qemu_opt_get(opts, "audiodev");
     if (audiodev) {
-        vd->audio_state = audio_state_by_name(audiodev, errp);
-        if (!vd->audio_state) {
+        vd->audio_be = audio_be_by_name(audiodev, errp);
+        if (!vd->audio_be) {
             goto fail;
         }
     } else {
-        vd->audio_state = audio_get_default_audio_state(NULL);
+        vd->audio_be = audio_get_default_audio_be(NULL);
     }
 
     device_id = qemu_opt_get(opts, "display");
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 35/42] audio: remove QEMUSoundCard
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (33 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 34/42] audio: rename AudioState -> AudioBackend marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 36/42] audio/dbus: use a helper function to set the backend dbus server marcandre.lureau
                   ` (8 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann,
	Laurent Vivier, Michael S. Tsirkin, Manos Pitsidianakis,
	Daniel P. Berrangé, Eduardo Habkost, Alistair Francis,
	Edgar E. Iglesias, Peter Maydell, Jiaxun Yang,
	open list:Xilinx ZynqMP and...

From: Marc-André Lureau <marcandre.lureau@redhat.com>

There is no clear need for this extra intermediary structure between
the audio backend and its user.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 audio/audio.h                       | 18 ++++++------------
 audio/audio_int.h                   |  3 ---
 audio/audio_template.h              | 22 ++++++++++------------
 hw/audio/lm4549.h                   |  2 +-
 include/hw/audio/asc.h              |  2 +-
 include/hw/audio/virtio-snd.h       |  2 +-
 include/hw/display/xlnx_dp.h        |  2 +-
 include/hw/isa/vt82c686.h           |  2 +-
 include/hw/qdev-properties-system.h |  2 +-
 audio/audio.c                       | 29 ++++++++++-------------------
 hw/audio/ac97.c                     | 25 ++++++++++++-------------
 hw/audio/adlib.c                    |  9 ++++-----
 hw/audio/asc.c                      |  9 +++------
 hw/audio/cs4231a.c                  |  8 ++++----
 hw/audio/es1370.c                   | 23 +++++++++++------------
 hw/audio/gus.c                      |  9 ++++-----
 hw/audio/hda-codec.c                | 15 +++++++--------
 hw/audio/lm4549.c                   |  8 ++++----
 hw/audio/pcspk.c                    |  9 +++++----
 hw/audio/pl041.c                    |  2 +-
 hw/audio/sb16.c                     | 16 ++++++++--------
 hw/audio/via-ac97.c                 |  9 ++++-----
 hw/audio/virtio-snd.c               | 13 ++++++-------
 hw/audio/wm8750.c                   | 23 +++++++++++------------
 hw/core/qdev-properties-system.c    | 11 +++++------
 hw/display/xlnx_dp.c                |  6 +++---
 hw/usb/dev-audio.c                  | 11 +++++------
 27 files changed, 129 insertions(+), 161 deletions(-)

diff --git a/audio/audio.h b/audio/audio.h
index 69ba1e8b94..4c596fcc7f 100644
--- a/audio/audio.h
+++ b/audio/audio.h
@@ -69,18 +69,12 @@ struct AudioBackendClass {
 };
 
 typedef struct AudioBackend AudioBackend;
-typedef struct QEMUSoundCard {
-    char *name;
-    AudioBackend *be;
-    QLIST_ENTRY (QEMUSoundCard) entries;
-} QEMUSoundCard;
 
 typedef struct QEMUAudioTimeStamp {
     uint64_t old_ts;
 } QEMUAudioTimeStamp;
 
-bool AUD_register_card (const char *name, QEMUSoundCard *card, Error **errp);
-void AUD_remove_card (QEMUSoundCard *card);
+bool AUD_backend_check (AudioBackend **be, Error **errp);
 CaptureVoiceOut *AUD_add_capture(
     AudioBackend *s,
     struct audsettings *as,
@@ -90,7 +84,7 @@ CaptureVoiceOut *AUD_add_capture(
 void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque);
 
 SWVoiceOut *AUD_open_out (
-    QEMUSoundCard *card,
+    AudioBackend *be,
     SWVoiceOut *sw,
     const char *name,
     void *callback_opaque,
@@ -98,7 +92,7 @@ SWVoiceOut *AUD_open_out (
     struct audsettings *settings
     );
 
-void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw);
+void AUD_close_out (AudioBackend *be, SWVoiceOut *sw);
 size_t AUD_write (SWVoiceOut *sw, void *pcm_buf, size_t size);
 int  AUD_get_buffer_size_out (SWVoiceOut *sw);
 void AUD_set_active_out (SWVoiceOut *sw, int on);
@@ -121,7 +115,7 @@ void AUD_set_volume_out(SWVoiceOut *sw, Volume *vol);
 void AUD_set_volume_in(SWVoiceIn *sw, Volume *vol);
 
 SWVoiceIn *AUD_open_in (
-    QEMUSoundCard *card,
+    AudioBackend *be,
     SWVoiceIn *sw,
     const char *name,
     void *callback_opaque,
@@ -129,7 +123,7 @@ SWVoiceIn *AUD_open_in (
     struct audsettings *settings
     );
 
-void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw);
+void AUD_close_in (AudioBackend *be, SWVoiceIn *sw);
 size_t AUD_read (SWVoiceIn *sw, void *pcm_buf, size_t size);
 void AUD_set_active_in (SWVoiceIn *sw, int on);
 int  AUD_is_active_in (SWVoiceIn *sw);
@@ -155,7 +149,7 @@ void audio_help(void);
 
 AudioBackend *audio_be_by_name(const char *name, Error **errp);
 AudioBackend *audio_get_default_audio_be(Error **errp);
-const char *audio_get_id(QEMUSoundCard *card);
+const char *audio_be_get_id(AudioBackend *be);
 
 #define DEFINE_AUDIO_PROPERTIES(_s, _f)         \
     DEFINE_PROP_AUDIODEV("audiodev", _s, _f)
diff --git a/audio/audio_int.h b/audio/audio_int.h
index d3929034b3..210457e0c4 100644
--- a/audio/audio_int.h
+++ b/audio/audio_int.h
@@ -108,7 +108,6 @@ typedef struct HWVoiceIn {
 } HWVoiceIn;
 
 struct SWVoiceOut {
-    QEMUSoundCard *card;
     AudioBackend *s;
     struct audio_pcm_info info;
     t_sample *conv;
@@ -125,7 +124,6 @@ struct SWVoiceOut {
 };
 
 struct SWVoiceIn {
-    QEMUSoundCard *card;
     AudioBackend *s;
     int active;
     struct audio_pcm_info info;
@@ -246,7 +244,6 @@ typedef struct AudioBackend {
     void *drv_opaque;
 
     QEMUTimer *ts;
-    QLIST_HEAD (card_listhead, QEMUSoundCard) card_head;
     QLIST_HEAD (hw_in_listhead, HWVoiceIn) hw_head_in;
     QLIST_HEAD (hw_out_listhead, HWVoiceOut) hw_head_out;
     QLIST_HEAD (cap_listhead, CaptureVoiceOut) cap_head;
diff --git a/audio/audio_template.h b/audio/audio_template.h
index b3c10a0709..97305445c8 100644
--- a/audio/audio_template.h
+++ b/audio/audio_template.h
@@ -473,11 +473,11 @@ static void glue (audio_close_, TYPE) (SW *sw)
     g_free (sw);
 }
 
-void glue (AUD_close_, TYPE) (QEMUSoundCard *card, SW *sw)
+void glue (AUD_close_, TYPE) (AudioBackend *be, SW *sw)
 {
     if (sw) {
-        if (audio_bug(__func__, !card)) {
-            dolog ("card=%p\n", card);
+        if (audio_bug(__func__, !be)) {
+            dolog ("backend=%p\n", be);
             return;
         }
 
@@ -486,7 +486,7 @@ void glue (AUD_close_, TYPE) (QEMUSoundCard *card, SW *sw)
 }
 
 SW *glue (AUD_open_, TYPE) (
-    QEMUSoundCard *card,
+    AudioBackend *be,
     SW *sw,
     const char *name,
     void *callback_opaque ,
@@ -494,16 +494,15 @@ SW *glue (AUD_open_, TYPE) (
     struct audsettings *as
     )
 {
-    AudioBackend *s;
+    AudioBackend *s = be;
     AudiodevPerDirectionOptions *pdo;
 
-    if (audio_bug(__func__, !card || !name || !callback_fn || !as)) {
-        dolog ("card=%p name=%p callback_fn=%p as=%p\n",
-               card, name, callback_fn, as);
+    if (audio_bug(__func__, !be || !name || !callback_fn || !as)) {
+        dolog ("backend=%p name=%p callback_fn=%p as=%p\n",
+               be, name, callback_fn, as);
         goto fail;
     }
 
-    s = card->be;
     pdo = glue(audio_get_pdo_, TYPE)(s->dev);
 
     ldebug ("open %s, freq %d, nchannels %d, fmt %d\n",
@@ -524,7 +523,7 @@ SW *glue (AUD_open_, TYPE) (
     }
 
     if (!pdo->fixed_settings && sw) {
-        glue (AUD_close_, TYPE) (card, sw);
+        glue (AUD_close_, TYPE) (be, sw);
         sw = NULL;
     }
 
@@ -548,7 +547,6 @@ SW *glue (AUD_open_, TYPE) (
         }
     }
 
-    sw->card = card;
     sw->vol = nominal_volume;
     sw->callback.fn = callback_fn;
     sw->callback.opaque = callback_opaque;
@@ -562,7 +560,7 @@ SW *glue (AUD_open_, TYPE) (
     return sw;
 
  fail:
-    glue (AUD_close_, TYPE) (card, sw);
+    glue (AUD_close_, TYPE) (be, sw);
     return NULL;
 }
 
diff --git a/hw/audio/lm4549.h b/hw/audio/lm4549.h
index 61c3ab12dd..1d858e2a04 100644
--- a/hw/audio/lm4549.h
+++ b/hw/audio/lm4549.h
@@ -21,7 +21,7 @@ typedef void (*lm4549_callback)(void *opaque);
 
 
 typedef struct {
-    QEMUSoundCard card;
+    AudioBackend *audio_be;
     SWVoiceOut *voice;
     uint32_t voice_is_active;
 
diff --git a/include/hw/audio/asc.h b/include/hw/audio/asc.h
index 04fac270b6..a60c2f597c 100644
--- a/include/hw/audio/asc.h
+++ b/include/hw/audio/asc.h
@@ -61,7 +61,7 @@ struct ASCState {
     MemoryRegion mem_regs;
     MemoryRegion mem_extregs;
 
-    QEMUSoundCard card;
+    AudioBackend *audio_be;
     SWVoiceOut *voice;
     uint8_t *mixbuf;
     int samples;
diff --git a/include/hw/audio/virtio-snd.h b/include/hw/audio/virtio-snd.h
index 8dafedb276..0ad80bc9be 100644
--- a/include/hw/audio/virtio-snd.h
+++ b/include/hw/audio/virtio-snd.h
@@ -216,7 +216,7 @@ struct VirtIOSound {
     VirtQueue *queues[VIRTIO_SND_VQ_MAX];
     uint64_t features;
     VirtIOSoundPCM *pcm;
-    QEMUSoundCard card;
+    AudioBackend *audio_be;
     VMChangeStateEntry *vmstate;
     virtio_snd_config snd_conf;
     QemuMutex cmdq_mutex;
diff --git a/include/hw/display/xlnx_dp.h b/include/hw/display/xlnx_dp.h
index e86a87f235..802a1427c9 100644
--- a/include/hw/display/xlnx_dp.h
+++ b/include/hw/display/xlnx_dp.h
@@ -84,7 +84,7 @@ struct XlnxDPState {
     struct PixmanPlane v_plane;
     struct PixmanPlane bout_plane;
 
-    QEMUSoundCard aud_card;
+    AudioBackend *audio_be;
     SWVoiceOut *amixer_output_stream;
     int16_t audio_buffer_0[AUD_CHBUF_MAX_DEPTH];
     int16_t audio_buffer_1[AUD_CHBUF_MAX_DEPTH];
diff --git a/include/hw/isa/vt82c686.h b/include/hw/isa/vt82c686.h
index da1722daf2..48c412ce81 100644
--- a/include/hw/isa/vt82c686.h
+++ b/include/hw/isa/vt82c686.h
@@ -24,7 +24,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(ViaAC97State, VIA_AC97);
 
 struct ViaAC97State {
     PCIDevice dev;
-    QEMUSoundCard card;
+    AudioBackend *audio_be;
     MemoryRegion sgd;
     MemoryRegion fm;
     MemoryRegion midi;
diff --git a/include/hw/qdev-properties-system.h b/include/hw/qdev-properties-system.h
index 9601a11a09..1bd7a7634b 100644
--- a/include/hw/qdev-properties-system.h
+++ b/include/hw/qdev-properties-system.h
@@ -87,7 +87,7 @@ extern const PropertyInfo qdev_prop_virtio_gpu_output_list;
                 .set_default = true)
 
 #define DEFINE_PROP_AUDIODEV(_n, _s, _f) \
-    DEFINE_PROP(_n, _s, _f, qdev_prop_audiodev, QEMUSoundCard)
+    DEFINE_PROP(_n, _s, _f, qdev_prop_audiodev, AudioBackend *)
 
 #define DEFINE_PROP_UUID_NODEFAULT(_name, _state, _field) \
     DEFINE_PROP(_name, _state, _field, qdev_prop_uuid, QemuUUID)
diff --git a/audio/audio.c b/audio/audio.c
index 8a7489ec82..a2350cfe23 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -1620,7 +1620,6 @@ static void audio_be_init(Object *obj)
     QLIST_INIT (&s->hw_head_out);
     QLIST_INIT (&s->hw_head_in);
     QLIST_INIT (&s->cap_head);
-    QLIST_INIT (&s->card_head);
     s->ts = timer_new_ns(QEMU_CLOCK_VIRTUAL, audio_timer, s);
 
     s->vmse = qemu_add_vm_change_state_handler(audio_vm_change_state_handler, s);
@@ -1812,28 +1811,20 @@ AudioBackend *audio_get_default_audio_be(Error **errp)
     return default_audio_be;
 }
 
-bool AUD_register_card (const char *name, QEMUSoundCard *card, Error **errp)
+bool AUD_backend_check (AudioBackend **be, Error **errp)
 {
-    if (!card->be) {
-        card->be = audio_get_default_audio_be(errp);
-        if (!card->be) {
+    assert(be != NULL);
+
+    if (!*be) {
+        *be = audio_get_default_audio_be(errp);
+        if (!*be) {
             return false;
         }
     }
 
-    card->name = g_strdup (name);
-    memset (&card->entries, 0, sizeof (card->entries));
-    QLIST_INSERT_HEAD(&card->be->card_head, card, entries);
-
     return true;
 }
 
-void AUD_remove_card (QEMUSoundCard *card)
-{
-    QLIST_REMOVE (card, entries);
-    g_free (card->name);
-}
-
 static struct audio_pcm_ops capture_pcm_ops;
 
 CaptureVoiceOut *AUD_add_capture(
@@ -2232,11 +2223,11 @@ AudioBackend *audio_be_by_name(const char *name, Error **errp)
     }
 }
 
-const char *audio_get_id(QEMUSoundCard *card)
+const char *audio_be_get_id(AudioBackend *be)
 {
-    if (card->be) {
-        assert(card->be->dev);
-        return card->be->dev->id;
+    if (be) {
+        assert(be->dev);
+        return be->dev->id;
     } else {
         return "";
     }
diff --git a/hw/audio/ac97.c b/hw/audio/ac97.c
index 1b2ce601a6..d23cfcf325 100644
--- a/hw/audio/ac97.c
+++ b/hw/audio/ac97.c
@@ -120,7 +120,7 @@ typedef struct AC97BusMasterRegs {
 
 struct AC97LinkState {
     PCIDevice dev;
-    QEMUSoundCard card;
+    AudioBackend *audio_be;
     uint32_t glob_cnt;
     uint32_t glob_sta;
     uint32_t cas;
@@ -316,7 +316,7 @@ static void open_voice(AC97LinkState *s, int index, int freq)
         switch (index) {
         case PI_INDEX:
             s->voice_pi = AUD_open_in(
-                &s->card,
+                s->audio_be,
                 s->voice_pi,
                 "ac97.pi",
                 s,
@@ -327,7 +327,7 @@ static void open_voice(AC97LinkState *s, int index, int freq)
 
         case PO_INDEX:
             s->voice_po = AUD_open_out(
-                &s->card,
+                s->audio_be,
                 s->voice_po,
                 "ac97.po",
                 s,
@@ -338,7 +338,7 @@ static void open_voice(AC97LinkState *s, int index, int freq)
 
         case MC_INDEX:
             s->voice_mc = AUD_open_in(
-                &s->card,
+                s->audio_be,
                 s->voice_mc,
                 "ac97.mc",
                 s,
@@ -351,17 +351,17 @@ static void open_voice(AC97LinkState *s, int index, int freq)
         s->invalid_freq[index] = freq;
         switch (index) {
         case PI_INDEX:
-            AUD_close_in(&s->card, s->voice_pi);
+            AUD_close_in(s->audio_be, s->voice_pi);
             s->voice_pi = NULL;
             break;
 
         case PO_INDEX:
-            AUD_close_out(&s->card, s->voice_po);
+            AUD_close_out(s->audio_be, s->voice_po);
             s->voice_po = NULL;
             break;
 
         case MC_INDEX:
-            AUD_close_in(&s->card, s->voice_mc);
+            AUD_close_in(s->audio_be, s->voice_mc);
             s->voice_mc = NULL;
             break;
         }
@@ -1271,7 +1271,7 @@ static void ac97_realize(PCIDevice *dev, Error **errp)
     AC97LinkState *s = AC97(dev);
     uint8_t *c = s->dev.config;
 
-    if (!AUD_register_card ("ac97", &s->card, errp)) {
+    if (!AUD_backend_check (&s->audio_be, errp)) {
         return;
     }
 
@@ -1316,14 +1316,13 @@ static void ac97_exit(PCIDevice *dev)
 {
     AC97LinkState *s = AC97(dev);
 
-    AUD_close_in(&s->card, s->voice_pi);
-    AUD_close_out(&s->card, s->voice_po);
-    AUD_close_in(&s->card, s->voice_mc);
-    AUD_remove_card(&s->card);
+    AUD_close_in(s->audio_be, s->voice_pi);
+    AUD_close_out(s->audio_be, s->voice_po);
+    AUD_close_in(s->audio_be, s->voice_mc);
 }
 
 static const Property ac97_properties[] = {
-    DEFINE_AUDIO_PROPERTIES(AC97LinkState, card),
+    DEFINE_AUDIO_PROPERTIES(AC97LinkState, audio_be),
 };
 
 static void ac97_class_init(ObjectClass *klass, const void *data)
diff --git a/hw/audio/adlib.c b/hw/audio/adlib.c
index 231055b8b5..1b3d2b8bfc 100644
--- a/hw/audio/adlib.c
+++ b/hw/audio/adlib.c
@@ -53,7 +53,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(AdlibState, ADLIB)
 struct AdlibState {
     ISADevice parent_obj;
 
-    QEMUSoundCard card;
+    AudioBackend *audio_be;
     uint32_t freq;
     uint32_t port;
     int ticking[2];
@@ -236,7 +236,6 @@ static void Adlib_fini (AdlibState *s)
 
     s->active = 0;
     s->enabled = 0;
-    AUD_remove_card (&s->card);
 }
 
 static MemoryRegionPortio adlib_portio_list[] = {
@@ -251,7 +250,7 @@ static void adlib_realizefn (DeviceState *dev, Error **errp)
     AdlibState *s = ADLIB(dev);
     struct audsettings as;
 
-    if (!AUD_register_card ("adlib", &s->card, errp)) {
+    if (!AUD_backend_check(&s->audio_be, errp)) {
         return;
     }
 
@@ -271,7 +270,7 @@ static void adlib_realizefn (DeviceState *dev, Error **errp)
     as.endianness = HOST_BIG_ENDIAN;
 
     s->voice = AUD_open_out (
-        &s->card,
+        s->audio_be,
         s->voice,
         "adlib",
         s,
@@ -294,7 +293,7 @@ static void adlib_realizefn (DeviceState *dev, Error **errp)
 }
 
 static const Property adlib_properties[] = {
-    DEFINE_AUDIO_PROPERTIES(AdlibState, card),
+    DEFINE_AUDIO_PROPERTIES(AdlibState, audio_be),
     DEFINE_PROP_UINT32 ("iobase",  AdlibState, port, 0x220),
     DEFINE_PROP_UINT32 ("freq",    AdlibState, freq,  44100),
 };
diff --git a/hw/audio/asc.c b/hw/audio/asc.c
index 991316e984..5c3f6c8f86 100644
--- a/hw/audio/asc.c
+++ b/hw/audio/asc.c
@@ -634,8 +634,6 @@ static void asc_unrealize(DeviceState *dev)
 
     g_free(s->mixbuf);
     g_free(s->silentbuf);
-
-    AUD_remove_card(&s->card);
 }
 
 static void asc_realize(DeviceState *dev, Error **errp)
@@ -643,7 +641,7 @@ static void asc_realize(DeviceState *dev, Error **errp)
     ASCState *s = ASC(dev);
     struct audsettings as;
 
-    if (!AUD_register_card("Apple Sound Chip", &s->card, errp)) {
+    if (!AUD_backend_check(&s->audio_be, errp)) {
         return;
     }
 
@@ -652,10 +650,9 @@ static void asc_realize(DeviceState *dev, Error **errp)
     as.fmt = AUDIO_FORMAT_U8;
     as.endianness = HOST_BIG_ENDIAN;
 
-    s->voice = AUD_open_out(&s->card, s->voice, "asc.out", s, asc_out_cb,
+    s->voice = AUD_open_out(s->audio_be, s->voice, "asc.out", s, asc_out_cb,
                             &as);
     if (!s->voice) {
-        AUD_remove_card(&s->card);
         error_setg(errp, "Initializing audio stream failed");
         return;
     }
@@ -702,7 +699,7 @@ static void asc_init(Object *obj)
 }
 
 static const Property asc_properties[] = {
-    DEFINE_AUDIO_PROPERTIES(ASCState, card),
+    DEFINE_AUDIO_PROPERTIES(ASCState, audio_be),
     DEFINE_PROP_UINT8("asctype", ASCState, type, ASC_TYPE_ASC),
 };
 
diff --git a/hw/audio/cs4231a.c b/hw/audio/cs4231a.c
index 062af7628b..9049065a0e 100644
--- a/hw/audio/cs4231a.c
+++ b/hw/audio/cs4231a.c
@@ -65,7 +65,7 @@ DECLARE_INSTANCE_CHECKER(CSState, CS4231A,
 
 struct CSState {
     ISADevice dev;
-    QEMUSoundCard card;
+    AudioBackend *audio_be;
     MemoryRegion ioports;
     qemu_irq pic;
     uint32_t regs[CS_REGS];
@@ -324,7 +324,7 @@ static void cs_reset_voices (CSState *s, uint32_t val)
     }
 
     s->voice = AUD_open_out (
-        &s->card,
+        s->audio_be,
         s->voice,
         "cs4231a",
         s,
@@ -674,7 +674,7 @@ static void cs4231a_realizefn (DeviceState *dev, Error **errp)
         return;
     }
 
-    if (!AUD_register_card ("cs4231a", &s->card, errp)) {
+    if (!AUD_backend_check(&s->audio_be, errp)) {
         return;
     }
 
@@ -690,7 +690,7 @@ static void cs4231a_realizefn (DeviceState *dev, Error **errp)
 }
 
 static const Property cs4231a_properties[] = {
-    DEFINE_AUDIO_PROPERTIES(CSState, card),
+    DEFINE_AUDIO_PROPERTIES(CSState, audio_be),
     DEFINE_PROP_UINT32 ("iobase",  CSState, port, 0x534),
     DEFINE_PROP_UINT32 ("irq",     CSState, irq,  9),
     DEFINE_PROP_UINT32 ("dma",     CSState, dma,  3),
diff --git a/hw/audio/es1370.c b/hw/audio/es1370.c
index ac5a6aba85..a8ca2045b3 100644
--- a/hw/audio/es1370.c
+++ b/hw/audio/es1370.c
@@ -258,7 +258,7 @@ struct chan {
 
 struct ES1370State {
     PCIDevice dev;
-    QEMUSoundCard card;
+    AudioBackend *audio_be;
     MemoryRegion io;
     struct chan chan[NB_CHANNELS];
     SWVoiceOut *dac_voice[2];
@@ -330,10 +330,10 @@ static void es1370_reset (ES1370State *s)
         d->scount = 0;
         d->leftover = 0;
         if (i == ADC_CHANNEL) {
-            AUD_close_in (&s->card, s->adc_voice);
+            AUD_close_in(s->audio_be, s->adc_voice);
             s->adc_voice = NULL;
         } else {
-            AUD_close_out (&s->card, s->dac_voice[i]);
+            AUD_close_out(s->audio_be, s->dac_voice[i]);
             s->dac_voice[i] = NULL;
         }
     }
@@ -412,7 +412,7 @@ static void es1370_update_voices (ES1370State *s, uint32_t ctl, uint32_t sctl)
                 if (i == ADC_CHANNEL) {
                     s->adc_voice =
                         AUD_open_in (
-                            &s->card,
+                            s->audio_be,
                             s->adc_voice,
                             "es1370.adc",
                             s,
@@ -422,7 +422,7 @@ static void es1370_update_voices (ES1370State *s, uint32_t ctl, uint32_t sctl)
                 } else {
                     s->dac_voice[i] =
                         AUD_open_out (
-                            &s->card,
+                            s->audio_be,
                             s->dac_voice[i],
                             i ? "es1370.dac2" : "es1370.dac1",
                             s,
@@ -784,12 +784,12 @@ static int es1370_post_load (void *opaque, int version_id)
     for (i = 0; i < NB_CHANNELS; ++i) {
         if (i == ADC_CHANNEL) {
             if (s->adc_voice) {
-                AUD_close_in (&s->card, s->adc_voice);
+                AUD_close_in(s->audio_be, s->adc_voice);
                 s->adc_voice = NULL;
             }
         } else {
             if (s->dac_voice[i]) {
-                AUD_close_out (&s->card, s->dac_voice[i]);
+                AUD_close_out(s->audio_be, s->dac_voice[i]);
                 s->dac_voice[i] = NULL;
             }
         }
@@ -833,7 +833,7 @@ static void es1370_realize(PCIDevice *dev, Error **errp)
     ES1370State *s = ES1370(dev);
     uint8_t *c = s->dev.config;
 
-    if (!AUD_register_card ("es1370", &s->card, errp)) {
+    if (!AUD_backend_check(&s->audio_be, errp)) {
         return;
     }
 
@@ -861,15 +861,14 @@ static void es1370_exit(PCIDevice *dev)
     int i;
 
     for (i = 0; i < 2; ++i) {
-        AUD_close_out(&s->card, s->dac_voice[i]);
+        AUD_close_out(s->audio_be, s->dac_voice[i]);
     }
 
-    AUD_close_in(&s->card, s->adc_voice);
-    AUD_remove_card(&s->card);
+    AUD_close_in(s->audio_be, s->adc_voice);
 }
 
 static const Property es1370_properties[] = {
-    DEFINE_AUDIO_PROPERTIES(ES1370State, card),
+    DEFINE_AUDIO_PROPERTIES(ES1370State, audio_be),
 };
 
 static void es1370_class_init(ObjectClass *klass, const void *data)
diff --git a/hw/audio/gus.c b/hw/audio/gus.c
index 40073f2d4f..434fa58136 100644
--- a/hw/audio/gus.c
+++ b/hw/audio/gus.c
@@ -45,7 +45,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(GUSState, GUS)
 struct GUSState {
     ISADevice dev;
     GUSEmuState emu;
-    QEMUSoundCard card;
+    AudioBackend *audio_be;
     uint32_t freq;
     uint32_t port;
     int pos, left, shift, irqs;
@@ -238,7 +238,7 @@ static void gus_realizefn (DeviceState *dev, Error **errp)
     IsaDmaClass *k;
     struct audsettings as;
 
-    if (!AUD_register_card ("gus", &s->card, errp)) {
+    if (!AUD_backend_check(&s->audio_be, errp)) {
         return;
     }
 
@@ -254,7 +254,7 @@ static void gus_realizefn (DeviceState *dev, Error **errp)
     as.endianness = HOST_BIG_ENDIAN;
 
     s->voice = AUD_open_out (
-        &s->card,
+        s->audio_be,
         NULL,
         "gus",
         s,
@@ -263,7 +263,6 @@ static void gus_realizefn (DeviceState *dev, Error **errp)
         );
 
     if (!s->voice) {
-        AUD_remove_card (&s->card);
         error_setg(errp, "No voice");
         return;
     }
@@ -288,7 +287,7 @@ static void gus_realizefn (DeviceState *dev, Error **errp)
 }
 
 static const Property gus_properties[] = {
-    DEFINE_AUDIO_PROPERTIES(GUSState, card),
+    DEFINE_AUDIO_PROPERTIES(GUSState, audio_be),
     DEFINE_PROP_UINT32 ("freq",    GUSState, freq,        44100),
     DEFINE_PROP_UINT32 ("iobase",  GUSState, port,        0x240),
     DEFINE_PROP_UINT32 ("irq",     GUSState, emu.gusirq,  7),
diff --git a/hw/audio/hda-codec.c b/hw/audio/hda-codec.c
index cc87557954..f7ae2aa1fd 100644
--- a/hw/audio/hda-codec.c
+++ b/hw/audio/hda-codec.c
@@ -178,7 +178,7 @@ struct HDAAudioState {
     HDACodecDevice hda;
     const char *name;
 
-    QEMUSoundCard card;
+    AudioBackend *audio_be;
     const desc_codec *desc;
     HDAAudioStream st[4];
     bool running_compat[16];
@@ -491,7 +491,7 @@ static void hda_audio_setup(HDAAudioStream *st)
         } else {
             cb = hda_audio_compat_output_cb;
         }
-        st->voice.out = AUD_open_out(&st->state->card, st->voice.out,
+        st->voice.out = AUD_open_out(st->state->audio_be, st->voice.out,
                                      st->node->name, st, cb, &st->as);
     } else {
         if (use_timer) {
@@ -500,7 +500,7 @@ static void hda_audio_setup(HDAAudioStream *st)
         } else {
             cb = hda_audio_compat_input_cb;
         }
-        st->voice.in = AUD_open_in(&st->state->card, st->voice.in,
+        st->voice.in = AUD_open_in(st->state->audio_be, st->voice.in,
                                    st->node->name, st, cb, &st->as);
     }
 }
@@ -696,7 +696,7 @@ static void hda_audio_init(HDACodecDevice *hda,
     const desc_param *param;
     uint32_t i, type;
 
-    if (!AUD_register_card("hda", &a->card, errp)) {
+    if (!AUD_backend_check(&a->audio_be, errp)) {
         return;
     }
 
@@ -754,12 +754,11 @@ static void hda_audio_exit(HDACodecDevice *hda)
         }
         timer_free(st->buft);
         if (st->output) {
-            AUD_close_out(&a->card, st->voice.out);
+            AUD_close_out(a->audio_be, st->voice.out);
         } else {
-            AUD_close_in(&a->card, st->voice.in);
+            AUD_close_in(a->audio_be, st->voice.in);
         }
     }
-    AUD_remove_card(&a->card);
 }
 
 static int hda_audio_post_load(void *opaque, int version)
@@ -858,7 +857,7 @@ static const VMStateDescription vmstate_hda_audio = {
 };
 
 static const Property hda_audio_properties[] = {
-    DEFINE_AUDIO_PROPERTIES(HDAAudioState, card),
+    DEFINE_AUDIO_PROPERTIES(HDAAudioState, audio_be),
     DEFINE_PROP_UINT32("debug", HDAAudioState, debug,   0),
     DEFINE_PROP_BOOL("mixer", HDAAudioState, mixer,  true),
     DEFINE_PROP_BOOL("use-timer", HDAAudioState, use_timer,  true),
diff --git a/hw/audio/lm4549.c b/hw/audio/lm4549.c
index dccbf56068..c51ec0e66f 100644
--- a/hw/audio/lm4549.c
+++ b/hw/audio/lm4549.c
@@ -190,7 +190,7 @@ void lm4549_write(lm4549_state *s,
         as.endianness = 0;
 
         s->voice = AUD_open_out(
-            &s->card,
+            s->audio_be,
             s->voice,
             "lm4549.out",
             s,
@@ -260,7 +260,7 @@ static int lm4549_post_load(void *opaque, int version_id)
     as.endianness = 0;
 
     s->voice = AUD_open_out(
-        &s->card,
+        s->audio_be,
         s->voice,
         "lm4549.out",
         s,
@@ -282,7 +282,7 @@ void lm4549_init(lm4549_state *s, lm4549_callback data_req_cb, void* opaque,
     struct audsettings as;
 
     /* Register an audio card */
-    if (!AUD_register_card("lm4549", &s->card, errp)) {
+    if (!AUD_backend_check(&s->audio_be, errp)) {
         return;
     }
 
@@ -300,7 +300,7 @@ void lm4549_init(lm4549_state *s, lm4549_callback data_req_cb, void* opaque,
     as.endianness = 0;
 
     s->voice = AUD_open_out(
-        &s->card,
+        s->audio_be,
         s->voice,
         "lm4549.out",
         s,
diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index e9ab5ac41b..36efb038f3 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -48,7 +48,7 @@ struct PCSpkState {
     MemoryRegion ioport;
     uint32_t iobase;
     uint8_t sample_buf[PCSPK_BUF_LEN];
-    QEMUSoundCard card;
+    AudioBackend *audio_be;
     SWVoiceOut *voice;
     PITCommonState *pit;
     unsigned int pit_count;
@@ -122,7 +122,7 @@ static int pcspk_audio_init(PCSpkState *s)
         return 0;
     }
 
-    s->voice = AUD_open_out(&s->card, s->voice, s_spk, s, pcspk_callback, &as);
+    s->voice = AUD_open_out(s->audio_be, s->voice, s_spk, s, pcspk_callback, &as);
     if (!s->voice) {
         error_report("pcspk: Could not open voice");
         return -1;
@@ -188,8 +188,9 @@ static void pcspk_realizefn(DeviceState *dev, Error **errp)
 
     isa_register_ioport(isadev, &s->ioport, s->iobase);
 
-    if (s->card.be && AUD_register_card(s_spk, &s->card, errp)) {
+    if (s->audio_be && AUD_backend_check(&s->audio_be, errp)) {
         pcspk_audio_init(s);
+        return;
     }
 }
 
@@ -213,7 +214,7 @@ static const VMStateDescription vmstate_spk = {
 };
 
 static const Property pcspk_properties[] = {
-    DEFINE_AUDIO_PROPERTIES(PCSpkState, card),
+    DEFINE_AUDIO_PROPERTIES(PCSpkState, audio_be),
     DEFINE_PROP_UINT32("iobase", PCSpkState, iobase,  0x61),
     DEFINE_PROP_BOOL("migrate", PCSpkState, migrate,  true),
     DEFINE_PROP_LINK("pit", PCSpkState, pit, TYPE_PIT_COMMON, PITCommonState *),
diff --git a/hw/audio/pl041.c b/hw/audio/pl041.c
index 5d9d6c1178..fd3d09611f 100644
--- a/hw/audio/pl041.c
+++ b/hw/audio/pl041.c
@@ -626,7 +626,7 @@ static const VMStateDescription vmstate_pl041 = {
 };
 
 static const Property pl041_device_properties[] = {
-    DEFINE_AUDIO_PROPERTIES(PL041State, codec.card),
+    DEFINE_AUDIO_PROPERTIES(PL041State, codec.audio_be),
     /* Non-compact FIFO depth property */
     DEFINE_PROP_UINT32("nc_fifo_depth", PL041State, fifo_depth,
                        DEFAULT_FIFO_DEPTH),
diff --git a/hw/audio/sb16.c b/hw/audio/sb16.c
index 069cf6e120..4978c2c014 100644
--- a/hw/audio/sb16.c
+++ b/hw/audio/sb16.c
@@ -50,7 +50,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(SB16State, SB16)
 struct SB16State {
     ISADevice parent_obj;
 
-    QEMUSoundCard card;
+    AudioBackend *audio_be;
     qemu_irq pic;
     uint32_t irq;
     uint32_t dma;
@@ -212,7 +212,7 @@ static void continue_dma8 (SB16State *s)
         as.endianness = 0;
 
         s->voice = AUD_open_out (
-            &s->card,
+            s->audio_be,
             s->voice,
             "sb16",
             s,
@@ -375,7 +375,7 @@ static void dma_cmd (SB16State *s, uint8_t cmd, uint8_t d0, int dma_len)
         as.endianness = 0;
 
         s->voice = AUD_open_out (
-            &s->card,
+            s->audio_be,
             s->voice,
             "sb16",
             s,
@@ -876,7 +876,7 @@ static void legacy_reset (SB16State *s)
     as.endianness = 0;
 
     s->voice = AUD_open_out (
-        &s->card,
+        s->audio_be,
         s->voice,
         "sb16",
         s,
@@ -1283,7 +1283,7 @@ static int sb16_post_load (void *opaque, int version_id)
     SB16State *s = opaque;
 
     if (s->voice) {
-        AUD_close_out (&s->card, s->voice);
+        AUD_close_out(s->audio_be, s->voice);
         s->voice = NULL;
     }
 
@@ -1299,7 +1299,7 @@ static int sb16_post_load (void *opaque, int version_id)
             as.endianness = 0;
 
             s->voice = AUD_open_out (
-                &s->card,
+                s->audio_be,
                 s->voice,
                 "sb16",
                 s,
@@ -1397,7 +1397,7 @@ static void sb16_realizefn (DeviceState *dev, Error **errp)
     SB16State *s = SB16 (dev);
     IsaDmaClass *k;
 
-    if (!AUD_register_card ("sb16", &s->card, errp)) {
+    if (!AUD_backend_check(&s->audio_be, errp)) {
         return;
     }
 
@@ -1436,7 +1436,7 @@ static void sb16_realizefn (DeviceState *dev, Error **errp)
 }
 
 static const Property sb16_properties[] = {
-    DEFINE_AUDIO_PROPERTIES(SB16State, card),
+    DEFINE_AUDIO_PROPERTIES(SB16State, audio_be),
     DEFINE_PROP_UINT32 ("version", SB16State, ver,  0x0405), /* 4.5 */
     DEFINE_PROP_UINT32 ("iobase",  SB16State, port, 0x220),
     DEFINE_PROP_UINT32 ("irq",     SB16State, irq,  5),
diff --git a/hw/audio/via-ac97.c b/hw/audio/via-ac97.c
index 62341e5600..019d296853 100644
--- a/hw/audio/via-ac97.c
+++ b/hw/audio/via-ac97.c
@@ -239,7 +239,7 @@ static void open_voice_out(ViaAC97State *s)
         .fmt = s->aur.type & BIT(5) ? AUDIO_FORMAT_S16 : AUDIO_FORMAT_S8,
         .endianness = 0,
     };
-    s->vo = AUD_open_out(&s->card, s->vo, "via-ac97.out", s, out_cb, &as);
+    s->vo = AUD_open_out(s->audio_be, s->vo, "via-ac97.out", s, out_cb, &as);
 }
 
 static uint64_t sgd_read(void *opaque, hwaddr addr, unsigned size)
@@ -426,7 +426,7 @@ static void via_ac97_realize(PCIDevice *pci_dev, Error **errp)
     ViaAC97State *s = VIA_AC97(pci_dev);
     Object *o = OBJECT(s);
 
-    if (!AUD_register_card ("via-ac97", &s->card, errp)) {
+    if (!AUD_backend_check(&s->audio_be, errp)) {
         return;
     }
 
@@ -455,12 +455,11 @@ static void via_ac97_exit(PCIDevice *dev)
 {
     ViaAC97State *s = VIA_AC97(dev);
 
-    AUD_close_out(&s->card, s->vo);
-    AUD_remove_card(&s->card);
+    AUD_close_out(s->audio_be, s->vo);
 }
 
 static const Property via_ac97_properties[] = {
-    DEFINE_AUDIO_PROPERTIES(ViaAC97State, card),
+    DEFINE_AUDIO_PROPERTIES(ViaAC97State, audio_be),
 };
 
 static void via_ac97_class_init(ObjectClass *klass, const void *data)
diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c
index 88777977a9..9101560f38 100644
--- a/hw/audio/virtio-snd.c
+++ b/hw/audio/virtio-snd.c
@@ -78,7 +78,7 @@ static const VMStateDescription vmstate_virtio_snd = {
 };
 
 static const Property virtio_snd_properties[] = {
-    DEFINE_AUDIO_PROPERTIES(VirtIOSound, card),
+    DEFINE_AUDIO_PROPERTIES(VirtIOSound, audio_be),
     DEFINE_PROP_UINT32("jacks", VirtIOSound, snd_conf.jacks,
                        VIRTIO_SOUND_JACK_DEFAULT),
     DEFINE_PROP_UINT32("streams", VirtIOSound, snd_conf.streams,
@@ -391,10 +391,10 @@ static void virtio_snd_pcm_close(VirtIOSoundPCMStream *stream)
     if (stream) {
         virtio_snd_pcm_flush(stream);
         if (stream->info.direction == VIRTIO_SND_D_OUTPUT) {
-            AUD_close_out(&stream->pcm->snd->card, stream->voice.out);
+            AUD_close_out(stream->pcm->snd->audio_be, stream->voice.out);
             stream->voice.out = NULL;
         } else if (stream->info.direction == VIRTIO_SND_D_INPUT) {
-            AUD_close_in(&stream->pcm->snd->card, stream->voice.in);
+            AUD_close_in(stream->pcm->snd->audio_be, stream->voice.in);
             stream->voice.in = NULL;
         }
     }
@@ -457,7 +457,7 @@ static uint32_t virtio_snd_pcm_prepare(VirtIOSound *s, uint32_t stream_id)
     stream->as = as;
 
     if (stream->info.direction == VIRTIO_SND_D_OUTPUT) {
-        stream->voice.out = AUD_open_out(&s->card,
+        stream->voice.out = AUD_open_out(s->audio_be,
                                          stream->voice.out,
                                          "virtio-sound.out",
                                          stream,
@@ -465,7 +465,7 @@ static uint32_t virtio_snd_pcm_prepare(VirtIOSound *s, uint32_t stream_id)
                                          &as);
         AUD_set_volume_out_lr(stream->voice.out, 0, 255, 255);
     } else {
-        stream->voice.in = AUD_open_in(&s->card,
+        stream->voice.in = AUD_open_in(s->audio_be,
                                         stream->voice.in,
                                         "virtio-sound.in",
                                         stream,
@@ -1053,7 +1053,7 @@ static void virtio_snd_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    if (!AUD_register_card("virtio-sound", &vsnd->card, errp)) {
+    if (!AUD_backend_check(&vsnd->audio_be, errp)) {
         return;
     }
 
@@ -1330,7 +1330,6 @@ static void virtio_snd_unrealize(DeviceState *dev)
         g_free(vsnd->pcm);
         vsnd->pcm = NULL;
     }
-    AUD_remove_card(&vsnd->card);
     qemu_mutex_destroy(&vsnd->cmdq_mutex);
     virtio_delete_queue(vsnd->queues[VIRTIO_SND_VQ_CONTROL]);
     virtio_delete_queue(vsnd->queues[VIRTIO_SND_VQ_EVENT]);
diff --git a/hw/audio/wm8750.c b/hw/audio/wm8750.c
index 7a36c4bd3f..d399c335c3 100644
--- a/hw/audio/wm8750.c
+++ b/hw/audio/wm8750.c
@@ -34,7 +34,7 @@ struct WM8750State {
 
     uint8_t i2c_data[2];
     int i2c_len;
-    QEMUSoundCard card;
+    AudioBackend *audio_be;
     SWVoiceIn *adc_voice[IN_PORT_N];
     SWVoiceOut *dac_voice[OUT_PORT_N];
     int enable;
@@ -188,12 +188,12 @@ static void wm8750_set_format(WM8750State *s)
 
     for (i = 0; i < IN_PORT_N; i ++)
         if (s->adc_voice[i]) {
-            AUD_close_in(&s->card, s->adc_voice[i]);
+            AUD_close_in(s->audio_be, s->adc_voice[i]);
             s->adc_voice[i] = NULL;
         }
     for (i = 0; i < OUT_PORT_N; i ++)
         if (s->dac_voice[i]) {
-            AUD_close_out(&s->card, s->dac_voice[i]);
+            AUD_close_out(s->audio_be, s->dac_voice[i]);
             s->dac_voice[i] = NULL;
         }
 
@@ -206,11 +206,11 @@ static void wm8750_set_format(WM8750State *s)
     in_fmt.freq = s->adc_hz;
     in_fmt.fmt = AUDIO_FORMAT_S16;
 
-    s->adc_voice[0] = AUD_open_in(&s->card, s->adc_voice[0],
+    s->adc_voice[0] = AUD_open_in(s->audio_be, s->adc_voice[0],
                     CODEC ".input1", s, wm8750_audio_in_cb, &in_fmt);
-    s->adc_voice[1] = AUD_open_in(&s->card, s->adc_voice[1],
+    s->adc_voice[1] = AUD_open_in(s->audio_be, s->adc_voice[1],
                     CODEC ".input2", s, wm8750_audio_in_cb, &in_fmt);
-    s->adc_voice[2] = AUD_open_in(&s->card, s->adc_voice[2],
+    s->adc_voice[2] = AUD_open_in(s->audio_be, s->adc_voice[2],
                     CODEC ".input3", s, wm8750_audio_in_cb, &in_fmt);
 
     /* Setup output */
@@ -219,12 +219,12 @@ static void wm8750_set_format(WM8750State *s)
     out_fmt.freq = s->dac_hz;
     out_fmt.fmt = AUDIO_FORMAT_S16;
 
-    s->dac_voice[0] = AUD_open_out(&s->card, s->dac_voice[0],
+    s->dac_voice[0] = AUD_open_out(s->audio_be, s->dac_voice[0],
                     CODEC ".speaker", s, wm8750_audio_out_cb, &out_fmt);
-    s->dac_voice[1] = AUD_open_out(&s->card, s->dac_voice[1],
+    s->dac_voice[1] = AUD_open_out(s->audio_be, s->dac_voice[1],
                     CODEC ".headphone", s, wm8750_audio_out_cb, &out_fmt);
     /* MONOMIX is also in stereo for simplicity */
-    s->dac_voice[2] = AUD_open_out(&s->card, s->dac_voice[2],
+    s->dac_voice[2] = AUD_open_out(s->audio_be, s->dac_voice[2],
                     CODEC ".monomix", s, wm8750_audio_out_cb, &out_fmt);
     /* no sense emulating OUT3 which is a mix of other outputs */
 
@@ -624,7 +624,7 @@ static void wm8750_realize(DeviceState *dev, Error **errp)
 {
     WM8750State *s = WM8750(dev);
 
-    if (!AUD_register_card(CODEC, &s->card, errp)) {
+    if (!AUD_backend_check(&s->audio_be, errp)) {
         return;
     }
 
@@ -637,7 +637,6 @@ static void wm8750_fini(I2CSlave *i2c)
     WM8750State *s = WM8750(i2c);
 
     wm8750_reset(I2C_SLAVE(s));
-    AUD_remove_card(&s->card);
     g_free(s);
 }
 #endif
@@ -707,7 +706,7 @@ void wm8750_set_bclk_in(void *opaque, int new_hz)
 }
 
 static const Property wm8750_properties[] = {
-    DEFINE_AUDIO_PROPERTIES(WM8750State, card),
+    DEFINE_AUDIO_PROPERTIES(WM8750State, audio_be),
 };
 
 static void wm8750_class_init(ObjectClass *klass, const void *data)
diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index c83a52fc62..578cbdc015 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -487,18 +487,17 @@ static void get_audiodev(Object *obj, Visitor *v, const char* name,
                          void *opaque, Error **errp)
 {
     const Property *prop = opaque;
-    QEMUSoundCard *card = object_field_prop_ptr(obj, prop);
-    char *p = g_strdup(audio_get_id(card));
+    AudioBackend **be = object_field_prop_ptr(obj, prop);
+    g_autofree char *id = g_strdup(audio_be_get_id(*be));
 
-    visit_type_str(v, name, &p, errp);
-    g_free(p);
+    visit_type_str(v, name, (char **)&id, errp);
 }
 
 static void set_audiodev(Object *obj, Visitor *v, const char* name,
                          void *opaque, Error **errp)
 {
     const Property *prop = opaque;
-    QEMUSoundCard *card = object_field_prop_ptr(obj, prop);
+    AudioBackend **be = object_field_prop_ptr(obj, prop);
     AudioBackend *state;
     g_autofree char *str = NULL;
 
@@ -508,7 +507,7 @@ static void set_audiodev(Object *obj, Visitor *v, const char* name,
 
     state = audio_be_by_name(str, errp);
     if (state) {
-        card->be = state;
+        *be = state;
     }
 }
 
diff --git a/hw/display/xlnx_dp.c b/hw/display/xlnx_dp.c
index 882ae3c4b4..96cbb1b3a7 100644
--- a/hw/display/xlnx_dp.c
+++ b/hw/display/xlnx_dp.c
@@ -1306,7 +1306,7 @@ static void xlnx_dp_realize(DeviceState *dev, Error **errp)
     DisplaySurface *surface;
     struct audsettings as;
 
-    if (!AUD_register_card("xlnx_dp.audio", &s->aud_card, errp)) {
+    if (!AUD_backend_check(&s->audio_be, errp)) {
         return;
     }
 
@@ -1328,7 +1328,7 @@ static void xlnx_dp_realize(DeviceState *dev, Error **errp)
     as.fmt = AUDIO_FORMAT_S16;
     as.endianness = 0;
 
-    s->amixer_output_stream = AUD_open_out(&s->aud_card,
+    s->amixer_output_stream = AUD_open_out(s->audio_be,
                                            s->amixer_output_stream,
                                            "xlnx_dp.audio.out",
                                            s,
@@ -1392,7 +1392,7 @@ static void xlnx_dp_reset(DeviceState *dev)
 }
 
 static const Property xlnx_dp_device_properties[] = {
-    DEFINE_AUDIO_PROPERTIES(XlnxDPState, aud_card),
+    DEFINE_AUDIO_PROPERTIES(XlnxDPState, audio_be),
 };
 
 static void xlnx_dp_class_init(ObjectClass *oc, const void *data)
diff --git a/hw/usb/dev-audio.c b/hw/usb/dev-audio.c
index f59e5a53f0..c8e032ab64 100644
--- a/hw/usb/dev-audio.c
+++ b/hw/usb/dev-audio.c
@@ -635,7 +635,7 @@ static uint8_t *streambuf_get(struct streambuf *buf, size_t *len)
 struct USBAudioState {
     /* qemu interfaces */
     USBDevice dev;
-    QEMUSoundCard card;
+    AudioBackend *audio_be;
 
     /* state */
     struct {
@@ -931,8 +931,7 @@ static void usb_audio_unrealize(USBDevice *dev)
     }
 
     usb_audio_set_output_altset(s, ALTSET_OFF);
-    AUD_close_out(&s->card, s->out.voice);
-    AUD_remove_card(&s->card);
+    AUD_close_out(s->audio_be, s->out.voice);
 
     streambuf_fini(&s->out.buf);
 }
@@ -942,7 +941,7 @@ static void usb_audio_realize(USBDevice *dev, Error **errp)
     USBAudioState *s = USB_AUDIO(dev);
     int i;
 
-    if (!AUD_register_card(TYPE_USB_AUDIO, &s->card, errp)) {
+    if (!AUD_backend_check(&s->audio_be, errp)) {
         return;
     }
 
@@ -979,7 +978,7 @@ static void usb_audio_reinit(USBDevice *dev, unsigned channels)
     s->out.as.endianness = 0;
     streambuf_init(&s->out.buf, s->buffer, s->out.channels);
 
-    s->out.voice = AUD_open_out(&s->card, s->out.voice, TYPE_USB_AUDIO,
+    s->out.voice = AUD_open_out(s->audio_be, s->out.voice, TYPE_USB_AUDIO,
                                 s, output_callback, &s->out.as);
     AUD_set_volume_out(s->out.voice, &s->out.vol);
     AUD_set_active_out(s->out.voice, 0);
@@ -991,7 +990,7 @@ static const VMStateDescription vmstate_usb_audio = {
 };
 
 static const Property usb_audio_properties[] = {
-    DEFINE_AUDIO_PROPERTIES(USBAudioState, card),
+    DEFINE_AUDIO_PROPERTIES(USBAudioState, audio_be),
     DEFINE_PROP_UINT32("debug", USBAudioState, debug, 0),
     DEFINE_PROP_UINT32("buffer", USBAudioState, buffer_user, 0),
     DEFINE_PROP_BOOL("multi", USBAudioState, multi, false),
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 36/42] audio/dbus: use a helper function to set the backend dbus server
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (34 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 35/42] audio: remove QEMUSoundCard marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 37/42] audio: move audio.h under include/qemu/ marcandre.lureau
                   ` (7 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 audio/audio.h     |  6 ++++++
 audio/audio_int.h |  2 +-
 audio/audio.c     | 14 ++++++++++++++
 audio/dbusaudio.c |  6 ++++--
 ui/dbus.c         |  8 +-------
 5 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/audio/audio.h b/audio/audio.h
index 4c596fcc7f..216b95eb4f 100644
--- a/audio/audio.h
+++ b/audio/audio.h
@@ -28,6 +28,9 @@
 #include "qemu/queue.h"
 #include "qapi/qapi-types-audio.h"
 #include "hw/qdev-properties-system.h"
+#ifdef CONFIG_GIO
+#include "gio/gio.h"
+#endif
 
 typedef void (*audio_callback_fn) (void *opaque, int avail);
 
@@ -150,6 +153,9 @@ void audio_help(void);
 AudioBackend *audio_be_by_name(const char *name, Error **errp);
 AudioBackend *audio_get_default_audio_be(Error **errp);
 const char *audio_be_get_id(AudioBackend *be);
+#ifdef CONFIG_GIO
+bool audio_be_set_dbus_server(AudioBackend *be, GDBusObjectManagerServer *server, bool p2p, Error **errp);
+#endif
 
 #define DEFINE_AUDIO_PROPERTIES(_s, _f)         \
     DEFINE_PROP_AUDIODEV("audiodev", _s, _f)
diff --git a/audio/audio_int.h b/audio/audio_int.h
index 210457e0c4..f077f741c8 100644
--- a/audio/audio_int.h
+++ b/audio/audio_int.h
@@ -145,7 +145,7 @@ struct audio_driver {
     void *(*init) (Audiodev *, Error **);
     void (*fini) (void *);
 #ifdef CONFIG_GIO
-    void (*set_dbus_server) (AudioBackend *s, GDBusObjectManagerServer *manager, bool p2p);
+    bool (*set_dbus_server) (AudioBackend *be, GDBusObjectManagerServer *manager, bool p2p, Error **errp);
 #endif
     struct audio_pcm_ops *pcm_ops;
     int max_voices_out;
diff --git a/audio/audio.c b/audio/audio.c
index a2350cfe23..92768fc81c 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -2223,6 +2223,20 @@ AudioBackend *audio_be_by_name(const char *name, Error **errp)
     }
 }
 
+#ifdef CONFIG_GIO
+bool audio_be_set_dbus_server(AudioBackend *be, GDBusObjectManagerServer *server, bool p2p, Error **errp)
+{
+    assert(be != NULL);
+
+    if (!be->drv->set_dbus_server) {
+        error_setg(errp, "Audiodev '%s' is not compatible with DBus", be->dev->id);
+        return false;
+    }
+
+    return be->drv->set_dbus_server(be, server, p2p, errp);
+}
+#endif
+
 const char *audio_be_get_id(AudioBackend *be)
 {
     if (be) {
diff --git a/audio/dbusaudio.c b/audio/dbusaudio.c
index 49cef38e3e..33d6365811 100644
--- a/audio/dbusaudio.c
+++ b/audio/dbusaudio.c
@@ -645,8 +645,8 @@ dbus_audio_register_in_listener(AudioBackend *s,
                                         arg_listener, false);
 }
 
-static void
-dbus_audio_set_server(AudioBackend *s, GDBusObjectManagerServer *server, bool p2p)
+static bool
+dbus_audio_set_server(AudioBackend *s, GDBusObjectManagerServer *server, bool p2p, Error **errp)
 {
     DBusAudio *da = s->drv_opaque;
 
@@ -669,6 +669,8 @@ dbus_audio_set_server(AudioBackend *s, GDBusObjectManagerServer *server, bool p2
     g_dbus_object_skeleton_add_interface(G_DBUS_OBJECT_SKELETON(da->audio),
                                          G_DBUS_INTERFACE_SKELETON(da->iface));
     g_dbus_object_manager_server_export(da->server, da->audio);
+
+    return true;
 }
 
 static struct audio_pcm_ops dbus_pcm_ops = {
diff --git a/ui/dbus.c b/ui/dbus.c
index 84cff47ec7..fbe108af1e 100644
--- a/ui/dbus.c
+++ b/ui/dbus.c
@@ -221,15 +221,9 @@ dbus_display_complete(UserCreatable *uc, Error **errp)
 
     if (dd->audiodev && *dd->audiodev) {
         AudioBackend *audio_be = audio_be_by_name(dd->audiodev, errp);
-        if (!audio_be) {
+        if (!audio_be || !audio_be_set_dbus_server(audio_be, dd->server, dd->p2p, errp)) {
             return;
         }
-        if (!g_str_equal(audio_be->drv->name, "dbus")) {
-            error_setg(errp, "Audiodev '%s' is not compatible with DBus",
-                       dd->audiodev);
-            return;
-        }
-        audio_be->drv->set_dbus_server(audio_be, dd->server, dd->p2p);
     }
 
     consoles = g_array_new(FALSE, FALSE, sizeof(guint32));
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 37/42] audio: move audio.h under include/qemu/
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (35 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 36/42] audio/dbus: use a helper function to set the backend dbus server marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 38/42] audio: remove dependency on spice header marcandre.lureau
                   ` (6 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann,
	Christian Schoenebeck, Akihiko Odaki, Thomas Huth,
	Alexandre Ratchov, Peter Maydell, Jan Kiszka, Alistair Francis,
	Edgar E. Iglesias, Laurent Vivier, Eduardo Habkost,
	Marcel Apfelbaum, Yanan Wang, Zhao Liu, Daniel P. Berrangé,
	Hervé Poussineau, Manos Pitsidianakis, Jiaxun Yang,
	Alex Bennée, open list:Integrator CP, open list:PReP

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 audio/audio_int.h                                   | 2 +-
 hw/audio/lm4549.h                                   | 2 +-
 include/hw/audio/asc.h                              | 2 +-
 include/hw/audio/virtio-snd.h                       | 2 +-
 include/hw/display/xlnx_dp.h                        | 2 +-
 include/hw/isa/vt82c686.h                           | 2 +-
 {audio => include/qemu}/audio.h                     | 0
 include/system/replay.h                             | 2 +-
 ui/vnc.h                                            | 2 +-
 audio/alsaaudio.c                                   | 2 +-
 audio/audio.c                                       | 2 +-
 audio/audio_win_int.c                               | 2 +-
 audio/dbusaudio.c                                   | 2 +-
 audio/dsoundaudio.c                                 | 2 +-
 audio/jackaudio.c                                   | 2 +-
 audio/mixeng.c                                      | 2 +-
 audio/noaudio.c                                     | 2 +-
 audio/ossaudio.c                                    | 2 +-
 audio/paaudio.c                                     | 2 +-
 audio/pwaudio.c                                     | 2 +-
 audio/sdlaudio.c                                    | 2 +-
 audio/sndioaudio.c                                  | 2 +-
 audio/spiceaudio.c                                  | 2 +-
 audio/wavaudio.c                                    | 2 +-
 hw/arm/integratorcp.c                               | 2 +-
 hw/arm/musicpal.c                                   | 2 +-
 hw/arm/realview.c                                   | 2 +-
 hw/arm/versatilepb.c                                | 2 +-
 hw/arm/vexpress.c                                   | 2 +-
 hw/arm/xlnx-zcu102.c                                | 2 +-
 hw/audio/ac97.c                                     | 2 +-
 hw/audio/adlib.c                                    | 2 +-
 hw/audio/asc.c                                      | 2 +-
 hw/audio/cs4231a.c                                  | 2 +-
 hw/audio/es1370.c                                   | 2 +-
 hw/audio/gus.c                                      | 2 +-
 hw/audio/hda-codec.c                                | 2 +-
 hw/audio/lm4549.c                                   | 2 +-
 hw/audio/marvell_88w8618.c                          | 2 +-
 hw/audio/pcspk.c                                    | 2 +-
 hw/audio/sb16.c                                     | 2 +-
 hw/audio/wm8750.c                                   | 2 +-
 hw/core/machine.c                                   | 2 +-
 hw/core/qdev-properties-system.c                    | 2 +-
 hw/ppc/prep.c                                       | 2 +-
 hw/usb/dev-audio.c                                  | 2 +-
 replay/replay-audio.c                               | 2 +-
 system/runstate.c                                   | 2 +-
 system/vl.c                                         | 2 +-
 ui/dbus.c                                           | 3 +--
 audio/coreaudio.m                                   | 2 +-
 scripts/codeconverter/codeconverter/test_regexps.py | 2 +-
 52 files changed, 51 insertions(+), 52 deletions(-)
 rename {audio => include/qemu}/audio.h (100%)

diff --git a/audio/audio_int.h b/audio/audio_int.h
index f077f741c8..a97edd77dd 100644
--- a/audio/audio_int.h
+++ b/audio/audio_int.h
@@ -29,7 +29,7 @@
 #define FLOAT_MIXENG
 /* #define RECIPROCAL */
 #endif
-#include "audio.h"
+#include "qemu/audio.h"
 #include "mixeng.h"
 
 #ifdef CONFIG_GIO
diff --git a/hw/audio/lm4549.h b/hw/audio/lm4549.h
index 1d858e2a04..bbd73057bf 100644
--- a/hw/audio/lm4549.h
+++ b/hw/audio/lm4549.h
@@ -12,7 +12,7 @@
 #ifndef HW_LM4549_H
 #define HW_LM4549_H
 
-#include "audio/audio.h"
+#include "qemu/audio.h"
 #include "exec/hwaddr.h"
 
 typedef void (*lm4549_callback)(void *opaque);
diff --git a/include/hw/audio/asc.h b/include/hw/audio/asc.h
index a60c2f597c..bb51e9a3d1 100644
--- a/include/hw/audio/asc.h
+++ b/include/hw/audio/asc.h
@@ -14,7 +14,7 @@
 #define HW_AUDIO_ASC_H
 
 #include "hw/sysbus.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 
 #define ASC_FREQ 22257
 
diff --git a/include/hw/audio/virtio-snd.h b/include/hw/audio/virtio-snd.h
index 0ad80bc9be..c176066584 100644
--- a/include/hw/audio/virtio-snd.h
+++ b/include/hw/audio/virtio-snd.h
@@ -17,7 +17,7 @@
 #define QEMU_VIRTIO_SOUND_H
 
 #include "hw/virtio/virtio.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 #include "standard-headers/linux/virtio_ids.h"
 #include "standard-headers/linux/virtio_snd.h"
 
diff --git a/include/hw/display/xlnx_dp.h b/include/hw/display/xlnx_dp.h
index 802a1427c9..af859e477d 100644
--- a/include/hw/display/xlnx_dp.h
+++ b/include/hw/display/xlnx_dp.h
@@ -33,7 +33,7 @@
 #include "qemu/fifo8.h"
 #include "qemu/units.h"
 #include "hw/dma/xlnx_dpdma.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 #include "qom/object.h"
 #include "hw/ptimer.h"
 
diff --git a/include/hw/isa/vt82c686.h b/include/hw/isa/vt82c686.h
index 48c412ce81..ace9e6650e 100644
--- a/include/hw/isa/vt82c686.h
+++ b/include/hw/isa/vt82c686.h
@@ -2,7 +2,7 @@
 #define HW_VT82C686_H
 
 #include "hw/pci/pci_device.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 
 #define TYPE_VT82C686B_ISA "vt82c686b-isa"
 #define TYPE_VT82C686B_USB_UHCI "vt82c686b-usb-uhci"
diff --git a/audio/audio.h b/include/qemu/audio.h
similarity index 100%
rename from audio/audio.h
rename to include/qemu/audio.h
diff --git a/include/system/replay.h b/include/system/replay.h
index 1e63c0784c..68f91bdfbf 100644
--- a/include/system/replay.h
+++ b/include/system/replay.h
@@ -16,7 +16,7 @@
 #include "qapi/qapi-types-run-state.h"
 #include "qapi/qapi-types-ui.h"
 #include "block/aio.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 
 /* replay clock kinds */
 enum ReplayClockKind {
diff --git a/ui/vnc.h b/ui/vnc.h
index e2137c5ed1..4d8363ebf3 100644
--- a/ui/vnc.h
+++ b/ui/vnc.h
@@ -31,7 +31,7 @@
 #include "qemu/thread.h"
 #include "ui/clipboard.h"
 #include "ui/console.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 #include "qemu/bitmap.h"
 #include "crypto/tlssession.h"
 #include "qemu/buffer.h"
diff --git a/audio/alsaaudio.c b/audio/alsaaudio.c
index 797cb478e6..d1e4817081 100644
--- a/audio/alsaaudio.c
+++ b/audio/alsaaudio.c
@@ -26,7 +26,7 @@
 #include <alsa/asoundlib.h>
 #include "qemu/main-loop.h"
 #include "qemu/module.h"
-#include "audio.h"
+#include "qemu/audio.h"
 #include "trace.h"
 
 #pragma GCC diagnostic ignored "-Waddress"
diff --git a/audio/audio.c b/audio/audio.c
index 92768fc81c..5d3fb799f9 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -23,7 +23,7 @@
  */
 
 #include "qemu/osdep.h"
-#include "audio.h"
+#include "qemu/audio.h"
 #include "migration/vmstate.h"
 #include "qemu/timer.h"
 #include "qapi/error.h"
diff --git a/audio/audio_win_int.c b/audio/audio_win_int.c
index 316f118f50..44a8ff24a6 100644
--- a/audio/audio_win_int.c
+++ b/audio/audio_win_int.c
@@ -7,7 +7,7 @@
 #include <mmreg.h>
 #include <mmsystem.h>
 
-#include "audio.h"
+#include "qemu/audio.h"
 #include "audio_int.h"
 #include "audio_win_int.h"
 
diff --git a/audio/dbusaudio.c b/audio/dbusaudio.c
index 33d6365811..abae8d20ae 100644
--- a/audio/dbusaudio.c
+++ b/audio/dbusaudio.c
@@ -35,7 +35,7 @@
 #include "ui/dbus-display1.h"
 
 #define AUDIO_CAP "dbus"
-#include "audio.h"
+#include "qemu/audio.h"
 #include "audio_int.h"
 #include "trace.h"
 
diff --git a/audio/dsoundaudio.c b/audio/dsoundaudio.c
index 003ef27365..fbb8890f5c 100644
--- a/audio/dsoundaudio.c
+++ b/audio/dsoundaudio.c
@@ -27,7 +27,7 @@
  */
 
 #include "qemu/osdep.h"
-#include "audio.h"
+#include "qemu/audio.h"
 
 #define AUDIO_CAP "dsound"
 #include "audio_int.h"
diff --git a/audio/jackaudio.c b/audio/jackaudio.c
index 974a3caad3..28face9989 100644
--- a/audio/jackaudio.c
+++ b/audio/jackaudio.c
@@ -26,7 +26,7 @@
 #include "qemu/module.h"
 #include "qemu/atomic.h"
 #include "qemu/main-loop.h"
-#include "audio.h"
+#include "qemu/audio.h"
 
 #define AUDIO_CAP "jack"
 #include "audio_int.h"
diff --git a/audio/mixeng.c b/audio/mixeng.c
index af9ec3d4d2..e63c76e021 100644
--- a/audio/mixeng.c
+++ b/audio/mixeng.c
@@ -24,7 +24,7 @@
  */
 #include "qemu/osdep.h"
 #include "qemu/bswap.h"
-#include "audio.h"
+#include "qemu/audio.h"
 
 #define AUDIO_CAP "mixeng"
 #include "audio_int.h"
diff --git a/audio/noaudio.c b/audio/noaudio.c
index 34ff1d2a27..b136b74e26 100644
--- a/audio/noaudio.c
+++ b/audio/noaudio.c
@@ -24,7 +24,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu/module.h"
-#include "audio.h"
+#include "qemu/audio.h"
 
 #define AUDIO_CAP "noaudio"
 #include "audio_int.h"
diff --git a/audio/ossaudio.c b/audio/ossaudio.c
index 4a549b26a2..5ba91f6793 100644
--- a/audio/ossaudio.c
+++ b/audio/ossaudio.c
@@ -29,7 +29,7 @@
 #include "qemu/module.h"
 #include "qemu/host-utils.h"
 #include "qapi/error.h"
-#include "audio.h"
+#include "qemu/audio.h"
 #include "trace.h"
 
 #define AUDIO_CAP "oss"
diff --git a/audio/paaudio.c b/audio/paaudio.c
index 93030f3fc8..8eb80ede45 100644
--- a/audio/paaudio.c
+++ b/audio/paaudio.c
@@ -2,7 +2,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu/module.h"
-#include "audio.h"
+#include "qemu/audio.h"
 #include "qapi/error.h"
 
 #include <pulse/pulseaudio.h>
diff --git a/audio/pwaudio.c b/audio/pwaudio.c
index 8e13b58286..8f6c0900c8 100644
--- a/audio/pwaudio.c
+++ b/audio/pwaudio.c
@@ -10,7 +10,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu/module.h"
-#include "audio.h"
+#include "qemu/audio.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include <spa/param/audio/format-utils.h>
diff --git a/audio/sdlaudio.c b/audio/sdlaudio.c
index 641357e5ee..4ef73c8dfb 100644
--- a/audio/sdlaudio.c
+++ b/audio/sdlaudio.c
@@ -27,7 +27,7 @@
 #include <SDL_thread.h>
 #include "qemu/module.h"
 #include "qapi/error.h"
-#include "audio.h"
+#include "qemu/audio.h"
 
 #ifndef _WIN32
 #ifdef __sun__
diff --git a/audio/sndioaudio.c b/audio/sndioaudio.c
index 8eb35e1e53..f4f53b1c6f 100644
--- a/audio/sndioaudio.c
+++ b/audio/sndioaudio.c
@@ -18,7 +18,7 @@
 #include <poll.h>
 #include <sndio.h>
 #include "qemu/main-loop.h"
-#include "audio.h"
+#include "qemu/audio.h"
 #include "trace.h"
 
 #define AUDIO_CAP "sndio"
diff --git a/audio/spiceaudio.c b/audio/spiceaudio.c
index 7e737bff9a..77ba89ffaa 100644
--- a/audio/spiceaudio.c
+++ b/audio/spiceaudio.c
@@ -26,7 +26,7 @@
 #include "ui/qemu-spice.h"
 
 #define AUDIO_CAP "spice"
-#include "audio.h"
+#include "qemu/audio.h"
 #include "audio_int.h"
 
 #if SPICE_INTERFACE_PLAYBACK_MAJOR > 1 || SPICE_INTERFACE_PLAYBACK_MINOR >= 3
diff --git a/audio/wavaudio.c b/audio/wavaudio.c
index a098b20cad..4d9c921305 100644
--- a/audio/wavaudio.c
+++ b/audio/wavaudio.c
@@ -24,7 +24,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu/module.h"
-#include "audio.h"
+#include "qemu/audio.h"
 
 #define AUDIO_CAP "wav"
 #include "audio_int.h"
diff --git a/hw/arm/integratorcp.c b/hw/arm/integratorcp.c
index b1d8fbd470..81ed051b98 100644
--- a/hw/arm/integratorcp.c
+++ b/hw/arm/integratorcp.c
@@ -26,7 +26,7 @@
 #include "hw/irq.h"
 #include "hw/sd/sd.h"
 #include "qom/object.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 #include "target/arm/cpu-qom.h"
 
 #define TYPE_INTEGRATOR_CM "integrator_core"
diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c
index 329b162eb2..6032301bb6 100644
--- a/hw/arm/musicpal.c
+++ b/hw/arm/musicpal.c
@@ -36,7 +36,7 @@
 #include "qemu/cutils.h"
 #include "qom/object.h"
 #include "hw/net/mv88w8618_eth.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 #include "qemu/error-report.h"
 #include "target/arm/cpu-qom.h"
 
diff --git a/hw/arm/realview.c b/hw/arm/realview.c
index 5c9050490b..892bdc8db2 100644
--- a/hw/arm/realview.c
+++ b/hw/arm/realview.c
@@ -29,7 +29,7 @@
 #include "hw/irq.h"
 #include "hw/i2c/arm_sbcon_i2c.h"
 #include "hw/sd/sd.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 #include "target/arm/cpu-qom.h"
 
 #define SMP_BOOT_ADDR 0xe0000000
diff --git a/hw/arm/versatilepb.c b/hw/arm/versatilepb.c
index 5cf1a70d10..cba77864e8 100644
--- a/hw/arm/versatilepb.c
+++ b/hw/arm/versatilepb.c
@@ -25,7 +25,7 @@
 #include "hw/char/pl011.h"
 #include "hw/sd/sd.h"
 #include "qom/object.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 #include "target/arm/cpu-qom.h"
 #include "qemu/log.h"
 
diff --git a/hw/arm/vexpress.c b/hw/arm/vexpress.c
index 35f8d05ea1..14d38cea8b 100644
--- a/hw/arm/vexpress.c
+++ b/hw/arm/vexpress.c
@@ -44,7 +44,7 @@
 #include "hw/sd/sd.h"
 #include "qobject/qlist.h"
 #include "qom/object.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 #include "target/arm/cpu-qom.h"
 
 #define VEXPRESS_BOARD_ID 0x8e0
diff --git a/hw/arm/xlnx-zcu102.c b/hw/arm/xlnx-zcu102.c
index 14b6641a71..4ed346a88d 100644
--- a/hw/arm/xlnx-zcu102.c
+++ b/hw/arm/xlnx-zcu102.c
@@ -25,7 +25,7 @@
 #include "system/device_tree.h"
 #include "qom/object.h"
 #include "net/can_emu.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 
 struct XlnxZCU102 {
     MachineState parent_obj;
diff --git a/hw/audio/ac97.c b/hw/audio/ac97.c
index d23cfcf325..d2298e02b2 100644
--- a/hw/audio/ac97.c
+++ b/hw/audio/ac97.c
@@ -19,7 +19,7 @@
 
 #include "qemu/osdep.h"
 #include "hw/audio/model.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 #include "hw/pci/pci_device.h"
 #include "hw/qdev-properties.h"
 #include "migration/vmstate.h"
diff --git a/hw/audio/adlib.c b/hw/audio/adlib.c
index 1b3d2b8bfc..27a4030bda 100644
--- a/hw/audio/adlib.c
+++ b/hw/audio/adlib.c
@@ -26,7 +26,7 @@
 #include "qapi/error.h"
 #include "qemu/module.h"
 #include "hw/audio/model.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 #include "hw/isa/isa.h"
 #include "hw/qdev-properties.h"
 #include "qemu/error-report.h"
diff --git a/hw/audio/asc.c b/hw/audio/asc.c
index 5c3f6c8f86..0abb106979 100644
--- a/hw/audio/asc.c
+++ b/hw/audio/asc.c
@@ -15,7 +15,7 @@
 #include "qapi/error.h"
 #include "hw/sysbus.h"
 #include "hw/irq.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 #include "hw/audio/asc.h"
 #include "hw/qdev-properties.h"
 #include "migration/vmstate.h"
diff --git a/hw/audio/cs4231a.c b/hw/audio/cs4231a.c
index 9049065a0e..8f3a49e9b8 100644
--- a/hw/audio/cs4231a.c
+++ b/hw/audio/cs4231a.c
@@ -24,7 +24,7 @@
 
 #include "qemu/osdep.h"
 #include "hw/audio/model.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 #include "hw/irq.h"
 #include "hw/isa/isa.h"
 #include "hw/qdev-properties.h"
diff --git a/hw/audio/es1370.c b/hw/audio/es1370.c
index a8ca2045b3..4abb32c170 100644
--- a/hw/audio/es1370.c
+++ b/hw/audio/es1370.c
@@ -27,7 +27,7 @@
 
 #include "qemu/osdep.h"
 #include "hw/audio/model.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 #include "hw/pci/pci_device.h"
 #include "migration/vmstate.h"
 #include "qemu/cutils.h"
diff --git a/hw/audio/gus.c b/hw/audio/gus.c
index 434fa58136..bfd5b0a8af 100644
--- a/hw/audio/gus.c
+++ b/hw/audio/gus.c
@@ -26,7 +26,7 @@
 #include "qapi/error.h"
 #include "qemu/module.h"
 #include "hw/audio/model.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 #include "hw/irq.h"
 #include "hw/isa/isa.h"
 #include "hw/qdev-properties.h"
diff --git a/hw/audio/hda-codec.c b/hw/audio/hda-codec.c
index f7ae2aa1fd..e90c9de046 100644
--- a/hw/audio/hda-codec.c
+++ b/hw/audio/hda-codec.c
@@ -25,7 +25,7 @@
 #include "qemu/host-utils.h"
 #include "qemu/module.h"
 #include "intel-hda-defs.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 #include "trace.h"
 #include "qom/object.h"
 
diff --git a/hw/audio/lm4549.c b/hw/audio/lm4549.c
index c51ec0e66f..745441bd79 100644
--- a/hw/audio/lm4549.c
+++ b/hw/audio/lm4549.c
@@ -15,7 +15,7 @@
 
 #include "qemu/osdep.h"
 #include "hw/hw.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 #include "lm4549.h"
 #include "migration/vmstate.h"
 
diff --git a/hw/audio/marvell_88w8618.c b/hw/audio/marvell_88w8618.c
index c5c79d083a..a483f4e70d 100644
--- a/hw/audio/marvell_88w8618.c
+++ b/hw/audio/marvell_88w8618.c
@@ -16,7 +16,7 @@
 #include "hw/irq.h"
 #include "hw/qdev-properties.h"
 #include "hw/audio/wm8750.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 #include "qapi/error.h"
 #include "qemu/module.h"
 #include "qom/object.h"
diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index 36efb038f3..5f045b670e 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -25,7 +25,7 @@
 #include "qemu/osdep.h"
 #include "hw/isa/isa.h"
 #include "hw/audio/model.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 #include "qemu/module.h"
 #include "qemu/timer.h"
 #include "qemu/error-report.h"
diff --git a/hw/audio/sb16.c b/hw/audio/sb16.c
index 4978c2c014..c8af6fa441 100644
--- a/hw/audio/sb16.c
+++ b/hw/audio/sb16.c
@@ -24,7 +24,7 @@
 
 #include "qemu/osdep.h"
 #include "hw/audio/model.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 #include "hw/irq.h"
 #include "hw/isa/isa.h"
 #include "hw/qdev-properties.h"
diff --git a/hw/audio/wm8750.c b/hw/audio/wm8750.c
index d399c335c3..336fb6d20b 100644
--- a/hw/audio/wm8750.c
+++ b/hw/audio/wm8750.c
@@ -12,7 +12,7 @@
 #include "migration/vmstate.h"
 #include "qemu/module.h"
 #include "hw/audio/wm8750.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 #include "qom/object.h"
 
 #define IN_PORT_N	3
diff --git a/hw/core/machine.c b/hw/core/machine.c
index 2de8b89606..a82eb86415 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -36,7 +36,7 @@
 #include "hw/virtio/virtio-net.h"
 #include "hw/virtio/virtio-iommu.h"
 #include "hw/acpi/generic_event_device.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 
 GlobalProperty hw_compat_10_1[] = {
     { TYPE_ACPI_GED, "x-has-hest-addr", "false" },
diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index 578cbdc015..6560205f9f 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -27,7 +27,7 @@
 #include "qemu/error-report.h"
 #include "qdev-prop-internal.h"
 
-#include "audio/audio.h"
+#include "qemu/audio.h"
 #include "chardev/char-fe.h"
 #include "system/block-backend.h"
 #include "system/blockdev.h"
diff --git a/hw/ppc/prep.c b/hw/ppc/prep.c
index 982e40e53e..8e4ee71c0a 100644
--- a/hw/ppc/prep.c
+++ b/hw/ppc/prep.c
@@ -46,7 +46,7 @@
 #include "trace.h"
 #include "elf.h"
 #include "qemu/units.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 
 /* SMP is not enabled, for now */
 #define MAX_CPUS 1
diff --git a/hw/usb/dev-audio.c b/hw/usb/dev-audio.c
index c8e032ab64..8dd9d26599 100644
--- a/hw/usb/dev-audio.c
+++ b/hw/usb/dev-audio.c
@@ -35,7 +35,7 @@
 #include "hw/usb.h"
 #include "migration/vmstate.h"
 #include "desc.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 #include "qom/object.h"
 
 static void usb_audio_reinit(USBDevice *dev, unsigned channels);
diff --git a/replay/replay-audio.c b/replay/replay-audio.c
index 3413801062..1b614f4137 100644
--- a/replay/replay-audio.c
+++ b/replay/replay-audio.c
@@ -13,7 +13,7 @@
 #include "qemu/error-report.h"
 #include "system/replay.h"
 #include "replay-internal.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 
 void replay_audio_out(size_t *played)
 {
diff --git a/system/runstate.c b/system/runstate.c
index 32467aa882..e3ec16ab74 100644
--- a/system/runstate.c
+++ b/system/runstate.c
@@ -23,7 +23,7 @@
  */
 
 #include "qemu/osdep.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 #include "block/block.h"
 #include "block/export.h"
 #include "chardev/char.h"
diff --git a/system/vl.c b/system/vl.c
index 9245ec986c..7bc6c44ebe 100644
--- a/system/vl.c
+++ b/system/vl.c
@@ -87,7 +87,7 @@
 #include "system/tpm.h"
 #include "system/dma.h"
 #include "hw/audio/model.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 #include "system/cpus.h"
 #include "system/cpu-timers.h"
 #include "exec/icount.h"
diff --git a/ui/dbus.c b/ui/dbus.c
index fbe108af1e..d2dff33258 100644
--- a/ui/dbus.c
+++ b/ui/dbus.c
@@ -34,8 +34,7 @@
 #include "ui/egl-helpers.h"
 #include "ui/egl-context.h"
 #endif
-#include "audio/audio.h"
-#include "audio/audio_int.h"
+#include "qemu/audio.h"
 #include "qapi/error.h"
 #include "trace.h"
 
diff --git a/audio/coreaudio.m b/audio/coreaudio.m
index cadd729d50..8b3cd6db16 100644
--- a/audio/coreaudio.m
+++ b/audio/coreaudio.m
@@ -28,7 +28,7 @@
 
 #include "qemu/main-loop.h"
 #include "qemu/module.h"
-#include "audio.h"
+#include "qemu/audio.h"
 
 #define AUDIO_CAP "coreaudio"
 #include "audio_int.h"
diff --git a/scripts/codeconverter/codeconverter/test_regexps.py b/scripts/codeconverter/codeconverter/test_regexps.py
index fe7354b473..b00e9ef15b 100644
--- a/scripts/codeconverter/codeconverter/test_regexps.py
+++ b/scripts/codeconverter/codeconverter/test_regexps.py
@@ -265,7 +265,7 @@ def test_initial_includes():
 
 #include "qemu/osdep.h"
 #include "hw/audio/model.h"
-#include "audio/audio.h"
+#include "qemu/audio.h"
 #include "hw/pci/pci.h"
 #include "migration/vmstate.h"
 #include "qemu/module.h"
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 38/42] audio: remove dependency on spice header
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (36 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 37/42] audio: move audio.h under include/qemu/ marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 39/42] audio: cleanup, use bool for booleans marcandre.lureau
                   ` (5 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann

From: Marc-André Lureau <marcandre.lureau@redhat.com>

It is no longer required.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 audio/meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/audio/meson.build b/audio/meson.build
index 59f0a431d5..37789437fb 100644
--- a/audio/meson.build
+++ b/audio/meson.build
@@ -1,5 +1,5 @@
-system_ss.add([spice_headers, files('audio.c')])
 system_ss.add(files(
+  'audio.c',
   'audio-hmp-cmds.c',
   'mixeng.c',
   'noaudio.c',
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 39/42] audio: cleanup, use bool for booleans
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (37 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 38/42] audio: remove dependency on spice header marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  7:05   ` Philippe Mathieu-Daudé
  2025-10-22 12:01   ` BALATON Zoltan
  2025-10-22  6:56 ` [PATCH v2 40/42] audio: move capture API to own header marcandre.lureau
                   ` (4 subsequent siblings)
  43 siblings, 2 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Use slightly better types for the job.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 audio/audio_int.h      | 12 ++++++------
 audio/audio_template.h |  6 +++---
 include/qemu/audio.h   |  8 ++++----
 audio/audio.c          | 30 +++++++++++++++---------------
 4 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/audio/audio_int.h b/audio/audio_int.h
index a97edd77dd..c804302e51 100644
--- a/audio/audio_int.h
+++ b/audio/audio_int.h
@@ -67,9 +67,9 @@ typedef struct STSampleBuffer {
 
 typedef struct HWVoiceOut {
     AudioBackend *s;
-    int enabled;
+    bool enabled;
     int poll_mode;
-    int pending_disable;
+    bool pending_disable;
     struct audio_pcm_info info;
 
     f_sample *clip;
@@ -88,7 +88,7 @@ typedef struct HWVoiceOut {
 
 typedef struct HWVoiceIn {
     AudioBackend *s;
-    int enabled;
+    bool enabled;
     int poll_mode;
     struct audio_pcm_info info;
 
@@ -114,8 +114,8 @@ struct SWVoiceOut {
     STSampleBuffer resample_buf;
     void *rate;
     size_t total_hw_samples_mixed;
-    int active;
-    int empty;
+    bool active;
+    bool empty;
     HWVoiceOut *hw;
     char *name;
     struct mixeng_volume vol;
@@ -125,7 +125,7 @@ struct SWVoiceOut {
 
 struct SWVoiceIn {
     AudioBackend *s;
-    int active;
+    bool active;
     struct audio_pcm_info info;
     void *rate;
     size_t total_hw_samples_acquired;
diff --git a/audio/audio_template.h b/audio/audio_template.h
index 97305445c8..f9dfc0eabd 100644
--- a/audio/audio_template.h
+++ b/audio/audio_template.h
@@ -166,10 +166,10 @@ static int glue (audio_pcm_sw_init_, TYPE) (
 
     audio_pcm_init_info (&sw->info, as);
     sw->hw = hw;
-    sw->active = 0;
+    sw->active = false;
 #ifdef DAC
     sw->total_hw_samples_mixed = 0;
-    sw->empty = 1;
+    sw->empty = true;
 #endif
 
     if (sw->info.is_float) {
@@ -564,7 +564,7 @@ SW *glue (AUD_open_, TYPE) (
     return NULL;
 }
 
-int glue (AUD_is_active_, TYPE) (SW *sw)
+bool glue (AUD_is_active_, TYPE) (SW *sw)
 {
     return sw ? sw->active : 0;
 }
diff --git a/include/qemu/audio.h b/include/qemu/audio.h
index 216b95eb4f..f5c32550dc 100644
--- a/include/qemu/audio.h
+++ b/include/qemu/audio.h
@@ -98,8 +98,8 @@ SWVoiceOut *AUD_open_out (
 void AUD_close_out (AudioBackend *be, SWVoiceOut *sw);
 size_t AUD_write (SWVoiceOut *sw, void *pcm_buf, size_t size);
 int  AUD_get_buffer_size_out (SWVoiceOut *sw);
-void AUD_set_active_out (SWVoiceOut *sw, int on);
-int  AUD_is_active_out (SWVoiceOut *sw);
+void AUD_set_active_out (SWVoiceOut *sw, bool on);
+bool 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);
@@ -128,8 +128,8 @@ SWVoiceIn *AUD_open_in (
 
 void AUD_close_in (AudioBackend *be, SWVoiceIn *sw);
 size_t AUD_read (SWVoiceIn *sw, void *pcm_buf, size_t size);
-void AUD_set_active_in (SWVoiceIn *sw, int on);
-int  AUD_is_active_in (SWVoiceIn *sw);
+void AUD_set_active_in (SWVoiceIn *sw, bool on);
+bool AUD_is_active_in (SWVoiceIn *sw);
 
 void     AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
 uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
diff --git a/audio/audio.c b/audio/audio.c
index 5d3fb799f9..a9df7d73cd 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -405,7 +405,7 @@ static void audio_notify_capture (CaptureVoiceOut *cap, audcnotification_e cmd)
     }
 }
 
-static void audio_capture_maybe_changed (CaptureVoiceOut *cap, int enabled)
+static void audio_capture_maybe_changed (CaptureVoiceOut *cap, bool enabled)
 {
     if (cap->hw.enabled != enabled) {
         audcnotification_e cmd;
@@ -419,11 +419,11 @@ static void audio_recalc_and_notify_capture (CaptureVoiceOut *cap)
 {
     HWVoiceOut *hw = &cap->hw;
     SWVoiceOut *sw;
-    int enabled = 0;
+    bool enabled = false;
 
     for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {
         if (sw->active) {
-            enabled = 1;
+            enabled = true;
             break;
         }
     }
@@ -475,7 +475,7 @@ static int audio_attach_capture (HWVoiceOut *hw)
         sw = &sc->sw;
         sw->hw = hw_cap;
         sw->info = hw->info;
-        sw->empty = 1;
+        sw->empty = true;
         sw->active = hw->enabled;
         sw->vol = nominal_volume;
         sw->rate = st_rate_start (sw->info.freq, hw_cap->info.freq);
@@ -911,7 +911,7 @@ int AUD_get_buffer_size_out(SWVoiceOut *sw)
     return sw->hw->samples * sw->hw->info.bytes_per_frame;
 }
 
-void AUD_set_active_out (SWVoiceOut *sw, int on)
+void AUD_set_active_out (SWVoiceOut *sw, bool on)
 {
     HWVoiceOut *hw;
 
@@ -928,7 +928,7 @@ void AUD_set_active_out (SWVoiceOut *sw, int on)
         if (on) {
             hw->pending_disable = 0;
             if (!hw->enabled) {
-                hw->enabled = 1;
+                hw->enabled = true;
                 if (s->vm_running) {
                     if (hw->pcm_ops->enable_out) {
                         hw->pcm_ops->enable_out(hw, true);
@@ -959,7 +959,7 @@ void AUD_set_active_out (SWVoiceOut *sw, int on)
     }
 }
 
-void AUD_set_active_in (SWVoiceIn *sw, int on)
+void AUD_set_active_in (SWVoiceIn *sw, bool on)
 {
     HWVoiceIn *hw;
 
@@ -974,7 +974,7 @@ void AUD_set_active_in (SWVoiceIn *sw, int on)
 
         if (on) {
             if (!hw->enabled) {
-                hw->enabled = 1;
+                hw->enabled = true;
                 if (s->vm_running) {
                     if (hw->pcm_ops->enable_in) {
                         hw->pcm_ops->enable_in(hw, true);
@@ -993,7 +993,7 @@ void AUD_set_active_in (SWVoiceIn *sw, int on)
                 }
 
                 if (nb_active == 1) {
-                    hw->enabled = 0;
+                    hw->enabled = false;
                     if (hw->pcm_ops->enable_in) {
                         hw->pcm_ops->enable_in(hw, false);
                     }
@@ -1152,8 +1152,8 @@ static void audio_run_out (AudioBackend *s)
             sw = hw->sw_head.lh_first;
 
             if (hw->pending_disable) {
-                hw->enabled = 0;
-                hw->pending_disable = 0;
+                hw->enabled = false;
+                hw->pending_disable = false;
                 if (hw->pcm_ops->enable_out) {
                     hw->pcm_ops->enable_out(hw, false);
                 }
@@ -1206,13 +1206,13 @@ static void audio_run_out (AudioBackend *s)
 #ifdef DEBUG_OUT
             dolog ("Disabling voice\n");
 #endif
-            hw->enabled = 0;
-            hw->pending_disable = 0;
+            hw->enabled = false;
+            hw->pending_disable = false;
             if (hw->pcm_ops->enable_out) {
                 hw->pcm_ops->enable_out(hw, false);
             }
             for (sc = hw->cap_head.lh_first; sc; sc = sc->entries.le_next) {
-                sc->sw.active = 0;
+                sc->sw.active = false;
                 audio_recalc_and_notify_capture (sc->cap);
             }
             continue;
@@ -1257,7 +1257,7 @@ static void audio_run_out (AudioBackend *s)
             sw->total_hw_samples_mixed -= played;
 
             if (!sw->total_hw_samples_mixed) {
-                sw->empty = 1;
+                sw->empty = true;
             }
         }
     }
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 40/42] audio: move capture API to own header
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (38 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 39/42] audio: cleanup, use bool for booleans marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 41/42] audio: drop needless audio_driver "descr" field marcandre.lureau
                   ` (3 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann

From: Marc-André Lureau <marcandre.lureau@redhat.com>

For modularity/clarity reasons, move the capture API in a specific
header.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 audio/audio_int.h            |  1 +
 include/qemu/audio-capture.h | 43 ++++++++++++++++++++++++++++++++++++
 include/qemu/audio.h         | 30 -------------------------
 ui/vnc.h                     |  2 +-
 4 files changed, 45 insertions(+), 31 deletions(-)
 create mode 100644 include/qemu/audio-capture.h

diff --git a/audio/audio_int.h b/audio/audio_int.h
index c804302e51..c669a0e36f 100644
--- a/audio/audio_int.h
+++ b/audio/audio_int.h
@@ -30,6 +30,7 @@
 /* #define RECIPROCAL */
 #endif
 #include "qemu/audio.h"
+#include "qemu/audio-capture.h"
 #include "mixeng.h"
 
 #ifdef CONFIG_GIO
diff --git a/include/qemu/audio-capture.h b/include/qemu/audio-capture.h
new file mode 100644
index 0000000000..f07e70d06e
--- /dev/null
+++ b/include/qemu/audio-capture.h
@@ -0,0 +1,43 @@
+/*
+ * QEMU Audio subsystem
+ *
+ * SPDX-License-Identifier: MIT
+ */
+#ifndef QEMU_AUDIO_CAPTURE_H
+#define QEMU_AUDIO_CAPTURE_H
+
+#include "audio.h"
+
+typedef struct CaptureVoiceOut CaptureVoiceOut;
+
+typedef enum {
+    AUD_CNOTIFY_ENABLE,
+    AUD_CNOTIFY_DISABLE
+} audcnotification_e;
+
+struct audio_capture_ops {
+    void (*notify) (void *opaque, audcnotification_e cmd);
+    void (*capture) (void *opaque, const void *buf, int size);
+    void (*destroy) (void *opaque);
+};
+
+struct capture_ops {
+    void (*info) (void *opaque);
+    void (*destroy) (void *opaque);
+};
+
+typedef struct CaptureState {
+    void *opaque;
+    struct capture_ops ops;
+    QLIST_ENTRY (CaptureState) entries;
+} CaptureState;
+
+CaptureVoiceOut *AUD_add_capture(
+    AudioBackend *be,
+    struct audsettings *as,
+    struct audio_capture_ops *ops,
+    void *opaque
+    );
+void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque);
+
+#endif /* QEMU_AUDIO_CAPTURE_H */
diff --git a/include/qemu/audio.h b/include/qemu/audio.h
index f5c32550dc..f2de1fa5b3 100644
--- a/include/qemu/audio.h
+++ b/include/qemu/audio.h
@@ -41,30 +41,7 @@ typedef struct audsettings {
     int endianness;
 } audsettings;
 
-typedef enum {
-    AUD_CNOTIFY_ENABLE,
-    AUD_CNOTIFY_DISABLE
-} audcnotification_e;
-
-struct audio_capture_ops {
-    void (*notify) (void *opaque, audcnotification_e cmd);
-    void (*capture) (void *opaque, const void *buf, int size);
-    void (*destroy) (void *opaque);
-};
-
-struct capture_ops {
-    void (*info) (void *opaque);
-    void (*destroy) (void *opaque);
-};
-
-typedef struct CaptureState {
-    void *opaque;
-    struct capture_ops ops;
-    QLIST_ENTRY (CaptureState) entries;
-} CaptureState;
-
 typedef struct SWVoiceOut SWVoiceOut;
-typedef struct CaptureVoiceOut CaptureVoiceOut;
 typedef struct SWVoiceIn SWVoiceIn;
 
 struct AudioBackendClass {
@@ -78,13 +55,6 @@ typedef struct QEMUAudioTimeStamp {
 } QEMUAudioTimeStamp;
 
 bool AUD_backend_check (AudioBackend **be, Error **errp);
-CaptureVoiceOut *AUD_add_capture(
-    AudioBackend *s,
-    struct audsettings *as,
-    struct audio_capture_ops *ops,
-    void *opaque
-    );
-void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque);
 
 SWVoiceOut *AUD_open_out (
     AudioBackend *be,
diff --git a/ui/vnc.h b/ui/vnc.h
index 4d8363ebf3..ec8d0c91b5 100644
--- a/ui/vnc.h
+++ b/ui/vnc.h
@@ -31,7 +31,7 @@
 #include "qemu/thread.h"
 #include "ui/clipboard.h"
 #include "ui/console.h"
-#include "qemu/audio.h"
+#include "qemu/audio-capture.h"
 #include "qemu/bitmap.h"
 #include "crypto/tlssession.h"
 #include "qemu/buffer.h"
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 41/42] audio: drop needless audio_driver "descr" field
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (39 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 40/42] audio: move capture API to own header marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  6:56 ` [PATCH v2 42/42] docs: Update mentions of removed '-soundhw' command line option marcandre.lureau
                   ` (2 subsequent siblings)
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Marc-André Lureau, Gerd Hoffmann,
	Christian Schoenebeck, Akihiko Odaki, Thomas Huth,
	Alexandre Ratchov

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Was it ever used?

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 audio/audio_int.h   | 1 -
 audio/alsaaudio.c   | 1 -
 audio/dbusaudio.c   | 1 -
 audio/dsoundaudio.c | 1 -
 audio/jackaudio.c   | 1 -
 audio/noaudio.c     | 1 -
 audio/ossaudio.c    | 1 -
 audio/paaudio.c     | 1 -
 audio/pwaudio.c     | 1 -
 audio/sdlaudio.c    | 1 -
 audio/sndioaudio.c  | 1 -
 audio/spiceaudio.c  | 1 -
 audio/wavaudio.c    | 1 -
 audio/coreaudio.m   | 1 -
 14 files changed, 14 deletions(-)

diff --git a/audio/audio_int.h b/audio/audio_int.h
index c669a0e36f..e0e4da5b70 100644
--- a/audio/audio_int.h
+++ b/audio/audio_int.h
@@ -142,7 +142,6 @@ struct SWVoiceIn {
 typedef struct audio_driver audio_driver;
 struct audio_driver {
     const char *name;
-    const char *descr;
     void *(*init) (Audiodev *, Error **);
     void (*fini) (void *);
 #ifdef CONFIG_GIO
diff --git a/audio/alsaaudio.c b/audio/alsaaudio.c
index d1e4817081..89f6dad1a9 100644
--- a/audio/alsaaudio.c
+++ b/audio/alsaaudio.c
@@ -956,7 +956,6 @@ static struct audio_pcm_ops alsa_pcm_ops = {
 
 static struct audio_driver alsa_audio_driver = {
     .name           = "alsa",
-    .descr          = "ALSA http://www.alsa-project.org",
     .init           = alsa_audio_init,
     .fini           = alsa_audio_fini,
     .pcm_ops        = &alsa_pcm_ops,
diff --git a/audio/dbusaudio.c b/audio/dbusaudio.c
index abae8d20ae..9a6b5e586f 100644
--- a/audio/dbusaudio.c
+++ b/audio/dbusaudio.c
@@ -692,7 +692,6 @@ static struct audio_pcm_ops dbus_pcm_ops = {
 
 static struct audio_driver dbus_audio_driver = {
     .name            = "dbus",
-    .descr           = "Timer based audio exposed with DBus interface",
     .init            = dbus_audio_init,
     .fini            = dbus_audio_fini,
     .set_dbus_server = dbus_audio_set_server,
diff --git a/audio/dsoundaudio.c b/audio/dsoundaudio.c
index fbb8890f5c..e75d235514 100644
--- a/audio/dsoundaudio.c
+++ b/audio/dsoundaudio.c
@@ -685,7 +685,6 @@ static struct audio_pcm_ops dsound_pcm_ops = {
 
 static struct audio_driver dsound_audio_driver = {
     .name           = "dsound",
-    .descr          = "DirectSound http://wikipedia.org/wiki/DirectSound",
     .init           = dsound_audio_init,
     .fini           = dsound_audio_fini,
     .pcm_ops        = &dsound_pcm_ops,
diff --git a/audio/jackaudio.c b/audio/jackaudio.c
index 28face9989..7a3fcaedba 100644
--- a/audio/jackaudio.c
+++ b/audio/jackaudio.c
@@ -672,7 +672,6 @@ static struct audio_pcm_ops jack_pcm_ops = {
 
 static struct audio_driver jack_driver = {
     .name           = "jack",
-    .descr          = "JACK Audio Connection Kit Client",
     .init           = qjack_init,
     .fini           = qjack_fini,
     .pcm_ops        = &jack_pcm_ops,
diff --git a/audio/noaudio.c b/audio/noaudio.c
index b136b74e26..4ed9d2156c 100644
--- a/audio/noaudio.c
+++ b/audio/noaudio.c
@@ -129,7 +129,6 @@ static struct audio_pcm_ops no_pcm_ops = {
 
 static struct audio_driver no_audio_driver = {
     .name           = "none",
-    .descr          = "Timer based audio emulation",
     .init           = no_audio_init,
     .fini           = no_audio_fini,
     .pcm_ops        = &no_pcm_ops,
diff --git a/audio/ossaudio.c b/audio/ossaudio.c
index 5ba91f6793..ab8791bece 100644
--- a/audio/ossaudio.c
+++ b/audio/ossaudio.c
@@ -779,7 +779,6 @@ static struct audio_pcm_ops oss_pcm_ops = {
 
 static struct audio_driver oss_audio_driver = {
     .name           = "oss",
-    .descr          = "OSS http://www.opensound.com",
     .init           = oss_audio_init,
     .fini           = oss_audio_fini,
     .pcm_ops        = &oss_pcm_ops,
diff --git a/audio/paaudio.c b/audio/paaudio.c
index 8eb80ede45..6b9b6d219a 100644
--- a/audio/paaudio.c
+++ b/audio/paaudio.c
@@ -922,7 +922,6 @@ static struct audio_pcm_ops qpa_pcm_ops = {
 
 static struct audio_driver pa_audio_driver = {
     .name           = "pa",
-    .descr          = "http://www.pulseaudio.org/",
     .init           = qpa_audio_init,
     .fini           = qpa_audio_fini,
     .pcm_ops        = &qpa_pcm_ops,
diff --git a/audio/pwaudio.c b/audio/pwaudio.c
index 8f6c0900c8..0fd59d9fe6 100644
--- a/audio/pwaudio.c
+++ b/audio/pwaudio.c
@@ -838,7 +838,6 @@ static struct audio_pcm_ops qpw_pcm_ops = {
 
 static struct audio_driver pw_audio_driver = {
     .name = "pipewire",
-    .descr = "http://www.pipewire.org/",
     .init = qpw_audio_init,
     .fini = qpw_audio_fini,
     .pcm_ops = &qpw_pcm_ops,
diff --git a/audio/sdlaudio.c b/audio/sdlaudio.c
index 4ef73c8dfb..a7a9652d29 100644
--- a/audio/sdlaudio.c
+++ b/audio/sdlaudio.c
@@ -490,7 +490,6 @@ static struct audio_pcm_ops sdl_pcm_ops = {
 
 static struct audio_driver sdl_audio_driver = {
     .name           = "sdl",
-    .descr          = "SDL http://www.libsdl.org",
     .init           = sdl_audio_init,
     .fini           = sdl_audio_fini,
     .pcm_ops        = &sdl_pcm_ops,
diff --git a/audio/sndioaudio.c b/audio/sndioaudio.c
index f4f53b1c6f..8197b8b0b4 100644
--- a/audio/sndioaudio.c
+++ b/audio/sndioaudio.c
@@ -546,7 +546,6 @@ static struct audio_pcm_ops sndio_pcm_ops = {
 
 static struct audio_driver sndio_audio_driver = {
     .name           = "sndio",
-    .descr          = "sndio https://sndio.org",
     .init           = sndio_audio_init,
     .fini           = sndio_audio_fini,
     .pcm_ops        = &sndio_pcm_ops,
diff --git a/audio/spiceaudio.c b/audio/spiceaudio.c
index 77ba89ffaa..7db2d1f0df 100644
--- a/audio/spiceaudio.c
+++ b/audio/spiceaudio.c
@@ -316,7 +316,6 @@ static struct audio_pcm_ops audio_callbacks = {
 
 static struct audio_driver spice_audio_driver = {
     .name           = "spice",
-    .descr          = "spice audio driver",
     .init           = spice_audio_init,
     .fini           = spice_audio_fini,
     .pcm_ops        = &audio_callbacks,
diff --git a/audio/wavaudio.c b/audio/wavaudio.c
index 4d9c921305..46460a5d57 100644
--- a/audio/wavaudio.c
+++ b/audio/wavaudio.c
@@ -205,7 +205,6 @@ static struct audio_pcm_ops wav_pcm_ops = {
 
 static struct audio_driver wav_audio_driver = {
     .name           = "wav",
-    .descr          = "WAV renderer http://wikipedia.org/wiki/WAV",
     .init           = wav_audio_init,
     .fini           = wav_audio_fini,
     .pcm_ops        = &wav_pcm_ops,
diff --git a/audio/coreaudio.m b/audio/coreaudio.m
index 8b3cd6db16..997017a1e9 100644
--- a/audio/coreaudio.m
+++ b/audio/coreaudio.m
@@ -664,7 +664,6 @@ static void coreaudio_audio_fini (void *opaque)
 
 static struct audio_driver coreaudio_audio_driver = {
     .name           = "coreaudio",
-    .descr          = "CoreAudio http://developer.apple.com/audio/coreaudio.html",
     .init           = coreaudio_audio_init,
     .fini           = coreaudio_audio_fini,
     .pcm_ops        = &coreaudio_pcm_ops,
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 42/42] docs: Update mentions of removed '-soundhw' command line option
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (40 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 41/42] audio: drop needless audio_driver "descr" field marcandre.lureau
@ 2025-10-22  6:56 ` marcandre.lureau
  2025-10-22  7:53 ` [PATCH v2 43/42] audio: Remove pointless local variables Philippe Mathieu-Daudé
  2025-10-22  7:53 ` [PATCH v2 44/42] audio: Rename @endianness argument as @big_endian for clarity Philippe Mathieu-Daudé
  43 siblings, 0 replies; 54+ messages in thread
From: marcandre.lureau @ 2025-10-22  6:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Volker Rümelin, Paolo Bonzini,
	BALATON Zoltan, Daniel P. Berrangé, Eduardo Habkost

From: Philippe Mathieu-Daudé <philmd@linaro.org>

The `-soundhw` CLI was removed in commit 039a68373c4 ("introduce
-audio as a replacement for -soundhw"). Remove outdated comments
and update the document mentioning the old usage.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 docs/qdev-device-use.txt | 4 ++--
 system/qdev-monitor.c    | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/docs/qdev-device-use.txt b/docs/qdev-device-use.txt
index 043ae46114..fb420da2a9 100644
--- a/docs/qdev-device-use.txt
+++ b/docs/qdev-device-use.txt
@@ -311,9 +311,9 @@ constraints.
 
 Host and guest part of audio devices have always been separate.
 
-The old way to define guest audio devices is -soundhw C1,...
+The old way to define guest audio devices was -soundhw C1,...
 
-The new way is to define each guest audio device separately with
+The current way is to define each guest audio device separately with
 -device.
 
 Map from -soundhw sound card name to -device:
diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c
index 9ed05d5d5a..f2aa400a77 100644
--- a/system/qdev-monitor.c
+++ b/system/qdev-monitor.c
@@ -73,9 +73,9 @@ typedef struct QDevAlias
 
 /* Please keep this table sorted by typename. */
 static const QDevAlias qdev_alias_table[] = {
-    { "AC97", "ac97" }, /* -soundhw name */
+    { "AC97", "ac97" },
     { "e1000", "e1000-82540em" },
-    { "ES1370", "es1370" }, /* -soundhw name */
+    { "ES1370", "es1370" },
     { "ich9-ahci", "ahci" },
     { "lsi53c895a", "lsi" },
     { "virtio-9p-device", "virtio-9p", QEMU_ARCH_VIRTIO_MMIO },
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* Re: [PATCH v2 39/42] audio: cleanup, use bool for booleans
  2025-10-22  6:56 ` [PATCH v2 39/42] audio: cleanup, use bool for booleans marcandre.lureau
@ 2025-10-22  7:05   ` Philippe Mathieu-Daudé
  2025-10-22 12:01   ` BALATON Zoltan
  1 sibling, 0 replies; 54+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-22  7:05 UTC (permalink / raw)
  To: marcandre.lureau, qemu-devel
  Cc: Volker Rümelin, Paolo Bonzini, BALATON Zoltan, Gerd Hoffmann

On 22/10/25 08:56, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Use slightly better types for the job.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>   audio/audio_int.h      | 12 ++++++------
>   audio/audio_template.h |  6 +++---
>   include/qemu/audio.h   |  8 ++++----
>   audio/audio.c          | 30 +++++++++++++++---------------
>   4 files changed, 28 insertions(+), 28 deletions(-)


> diff --git a/include/qemu/audio.h b/include/qemu/audio.h
> index 216b95eb4f..f5c32550dc 100644
> --- a/include/qemu/audio.h
> +++ b/include/qemu/audio.h
> @@ -98,8 +98,8 @@ SWVoiceOut *AUD_open_out (
>   void AUD_close_out (AudioBackend *be, SWVoiceOut *sw);
>   size_t AUD_write (SWVoiceOut *sw, void *pcm_buf, size_t size);
>   int  AUD_get_buffer_size_out (SWVoiceOut *sw);
> -void AUD_set_active_out (SWVoiceOut *sw, int on);
> -int  AUD_is_active_out (SWVoiceOut *sw);
> +void AUD_set_active_out (SWVoiceOut *sw, bool on);
> +bool 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);
> @@ -128,8 +128,8 @@ SWVoiceIn *AUD_open_in (
>   
>   void AUD_close_in (AudioBackend *be, SWVoiceIn *sw);
>   size_t AUD_read (SWVoiceIn *sw, void *pcm_buf, size_t size);
> -void AUD_set_active_in (SWVoiceIn *sw, int on);
> -int  AUD_is_active_in (SWVoiceIn *sw);
> +void AUD_set_active_in (SWVoiceIn *sw, bool on);
> +bool AUD_is_active_in (SWVoiceIn *sw);
>   
>   void     AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
>   uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
> diff --git a/audio/audio.c b/audio/audio.c
> index 5d3fb799f9..a9df7d73cd 100644
> --- a/audio/audio.c
> +++ b/audio/audio.c
> @@ -405,7 +405,7 @@ static void audio_notify_capture (CaptureVoiceOut *cap, audcnotification_e cmd)
>       }
>   }
>   
> -static void audio_capture_maybe_changed (CaptureVoiceOut *cap, int enabled)
> +static void audio_capture_maybe_changed (CaptureVoiceOut *cap, bool enabled)

Please fix checkpatch.pl errors while modifying these lines, otherwise:
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v2 33/42] audio: move internal APIs to audio_int.h
  2025-10-22  6:56 ` [PATCH v2 33/42] audio: move internal APIs to audio_int.h marcandre.lureau
@ 2025-10-22  7:08   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 54+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-22  7:08 UTC (permalink / raw)
  To: marcandre.lureau, qemu-devel
  Cc: Volker Rümelin, Paolo Bonzini, BALATON Zoltan, Gerd Hoffmann

On 22/10/25 08:56, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>   audio/audio.h          | 21 ---------------------
>   audio/audio_int.h      | 22 ++++++++++++++++++++++
>   audio/audio-hmp-cmds.c |  2 +-
>   audio/wavcapture.c     |  2 +-
>   4 files changed, 24 insertions(+), 23 deletions(-)


> diff --git a/audio/audio_int.h b/audio/audio_int.h
> index 4a4d69f2bf..cc7a6fe087 100644
> --- a/audio/audio_int.h
> +++ b/audio/audio_int.h
> @@ -29,12 +29,16 @@
>   #define FLOAT_MIXENG
>   /* #define RECIPROCAL */
>   #endif
> +#include "audio.h"
>   #include "mixeng.h"
>   
>   #ifdef CONFIG_GIO
>   #include <gio/gio.h>
>   #endif
>   
> +void AUD_vlog (const char *cap, const char *fmt, va_list ap) G_GNUC_PRINTF(2, 0);
> +void AUD_log (const char *cap, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
> +
>   struct audio_pcm_ops;
>   
>   struct audio_callback {
> @@ -187,6 +191,24 @@ struct audio_pcm_ops {
>       void   (*volume_in)(HWVoiceIn *hw, Volume *vol);
>   };
>   
> +audsettings audiodev_to_audsettings(AudiodevPerDirectionOptions *pdo);
> +int audioformat_bytes_per_sample(AudioFormat fmt);
> +int audio_buffer_frames(AudiodevPerDirectionOptions *pdo,
> +                        audsettings *as, int def_usecs);
> +int audio_buffer_samples(AudiodevPerDirectionOptions *pdo,
> +                         audsettings *as, int def_usecs);
> +int audio_buffer_bytes(AudiodevPerDirectionOptions *pdo,
> +                       audsettings *as, int def_usecs);
> +
> +static inline void *advance (void *p, int incr)
> +{
> +    uint8_t *d = p;
> +    return (d + incr);
> +}

Modulo checkpatch.pl errors,
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v2 29/42] audio: remove AUDIO_HOST_ENDIANNESS
  2025-10-22  6:56 ` [PATCH v2 29/42] audio: remove AUDIO_HOST_ENDIANNESS marcandre.lureau
@ 2025-10-22  7:11   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 54+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-22  7:11 UTC (permalink / raw)
  To: marcandre.lureau, qemu-devel
  Cc: Volker Rümelin, Paolo Bonzini, BALATON Zoltan, Gerd Hoffmann,
	Laurent Vivier

On 22/10/25 08:56, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>   audio/audio.h      | 6 ------
>   audio/audio.c      | 6 +++---
>   audio/spiceaudio.c | 4 ++--
>   hw/audio/adlib.c   | 2 +-
>   hw/audio/asc.c     | 2 +-
>   hw/audio/cs4231a.c | 2 +-
>   hw/audio/gus.c     | 2 +-
>   7 files changed, 9 insertions(+), 15 deletions(-)
> 
> diff --git a/audio/audio.h b/audio/audio.h
> index 3be0c4f24f..0af911fd9a 100644
> --- a/audio/audio.h
> +++ b/audio/audio.h
> @@ -31,12 +31,6 @@
>   
>   typedef void (*audio_callback_fn) (void *opaque, int avail);
>   
> -#if HOST_BIG_ENDIAN
> -#define AUDIO_HOST_ENDIANNESS 1
> -#else
> -#define AUDIO_HOST_ENDIANNESS 0
> -#endif
> -
>   typedef struct audsettings {
>       int freq;
>       int nchannels;
> diff --git a/audio/audio.c b/audio/audio.c
> index 0f3093ad59..284ea13289 100644
> --- a/audio/audio.c
> +++ b/audio/audio.c
> @@ -274,7 +274,7 @@ static int audio_pcm_info_eq (struct audio_pcm_info *info, struct audsettings *a
>           && info->is_signed == is_signed
>           && info->is_float == is_float
>           && info->bits == bits
> -        && info->swap_endianness == (as->endianness != AUDIO_HOST_ENDIANNESS);
> +        && info->swap_endianness == (as->endianness != HOST_BIG_ENDIAN);
>   }
>   
>   void audio_pcm_init_info (struct audio_pcm_info *info, struct audsettings *as)
> @@ -320,7 +320,7 @@ void audio_pcm_init_info (struct audio_pcm_info *info, struct audsettings *as)
>       info->nchannels = as->nchannels;
>       info->bytes_per_frame = as->nchannels * mul;
>       info->bytes_per_second = info->freq * info->bytes_per_frame;
> -    info->swap_endianness = (as->endianness != AUDIO_HOST_ENDIANNESS);
> +    info->swap_endianness = (as->endianness != HOST_BIG_ENDIAN);
>   }
>   
>   void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len)
> @@ -2179,7 +2179,7 @@ audsettings audiodev_to_audsettings(AudiodevPerDirectionOptions *pdo)
>           .freq = pdo->frequency,
>           .nchannels = pdo->channels,
>           .fmt = pdo->format,
> -        .endianness = AUDIO_HOST_ENDIANNESS,
> +        .endianness = HOST_BIG_ENDIAN,
>       };
>   }

Nice. Even better would be to use QAPI EndianMode.

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



^ permalink raw reply	[flat|nested] 54+ messages in thread

* [PATCH v2 43/42] audio: Remove pointless local variables
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (41 preceding siblings ...)
  2025-10-22  6:56 ` [PATCH v2 42/42] docs: Update mentions of removed '-soundhw' command line option marcandre.lureau
@ 2025-10-22  7:53 ` Philippe Mathieu-Daudé
  2025-10-22  7:56   ` Marc-André Lureau
  2025-10-22  7:53 ` [PATCH v2 44/42] audio: Rename @endianness argument as @big_endian for clarity Philippe Mathieu-Daudé
  43 siblings, 1 reply; 54+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-22  7:53 UTC (permalink / raw)
  To: qemu-devel
  Cc: Gerd Hoffmann, Christian Schoenebeck, Marc-André Lureau,
	Thomas Huth, Philippe Mathieu-Daudé

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 audio/ossaudio.c | 12 ++----------
 audio/sdlaudio.c | 12 ++----------
 2 files changed, 4 insertions(+), 20 deletions(-)

diff --git a/audio/ossaudio.c b/audio/ossaudio.c
index ab8791bece9..86c4805675e 100644
--- a/audio/ossaudio.c
+++ b/audio/ossaudio.c
@@ -493,10 +493,8 @@ static int oss_init_out(HWVoiceOut *hw, struct audsettings *as,
 {
     OSSVoiceOut *oss = (OSSVoiceOut *) hw;
     struct oss_params req, obt;
-    int endianness;
     int err;
     int fd;
-    AudioFormat effective_fmt;
     struct audsettings obt_as;
     Audiodev *dev = drv_opaque;
     AudiodevOssOptions *oopts = &dev->u.oss;
@@ -511,7 +509,7 @@ static int oss_init_out(HWVoiceOut *hw, struct audsettings *as,
         return -1;
     }
 
-    err = oss_to_audfmt (obt.fmt, &effective_fmt, &endianness);
+    err = oss_to_audfmt(obt.fmt, &obt_as.fmt, &obt_as.endianness);
     if (err) {
         oss_anal_close (&fd);
         return -1;
@@ -519,8 +517,6 @@ static int oss_init_out(HWVoiceOut *hw, struct audsettings *as,
 
     obt_as.freq = obt.freq;
     obt_as.nchannels = obt.nchannels;
-    obt_as.fmt = effective_fmt;
-    obt_as.endianness = endianness;
 
     audio_pcm_init_info (&hw->info, &obt_as);
     oss->nfrags = obt.nfrags;
@@ -628,10 +624,8 @@ static int oss_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
 {
     OSSVoiceIn *oss = (OSSVoiceIn *) hw;
     struct oss_params req, obt;
-    int endianness;
     int err;
     int fd;
-    AudioFormat effective_fmt;
     struct audsettings obt_as;
     Audiodev *dev = drv_opaque;
 
@@ -644,7 +638,7 @@ static int oss_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
         return -1;
     }
 
-    err = oss_to_audfmt (obt.fmt, &effective_fmt, &endianness);
+    err = oss_to_audfmt(obt.fmt, &obt_as.fmt, &obt_as.endianness);
     if (err) {
         oss_anal_close (&fd);
         return -1;
@@ -652,8 +646,6 @@ static int oss_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
 
     obt_as.freq = obt.freq;
     obt_as.nchannels = obt.nchannels;
-    obt_as.fmt = effective_fmt;
-    obt_as.endianness = endianness;
 
     audio_pcm_init_info (&hw->info, &obt_as);
     oss->nfrags = obt.nfrags;
diff --git a/audio/sdlaudio.c b/audio/sdlaudio.c
index a7a9652d29d..707110973ac 100644
--- a/audio/sdlaudio.c
+++ b/audio/sdlaudio.c
@@ -338,9 +338,7 @@ static int sdl_init_out(HWVoiceOut *hw, struct audsettings *as,
 {
     SDLVoiceOut *sdl = (SDLVoiceOut *)hw;
     SDL_AudioSpec req, obt;
-    int endianness;
     int err;
-    AudioFormat effective_fmt;
     Audiodev *dev = drv_opaque;
     AudiodevSdlPerDirectionOptions *spdo = dev->u.sdl.out;
     struct audsettings obt_as;
@@ -360,7 +358,7 @@ static int sdl_init_out(HWVoiceOut *hw, struct audsettings *as,
         return -1;
     }
 
-    err = sdl_to_audfmt(obt.format, &effective_fmt, &endianness);
+    err = sdl_to_audfmt(obt.format, &obt_as.fmt, &obt_as.endianness);
     if (err) {
         sdl_close_out(sdl);
         return -1;
@@ -368,8 +366,6 @@ static int sdl_init_out(HWVoiceOut *hw, struct audsettings *as,
 
     obt_as.freq = obt.freq;
     obt_as.nchannels = obt.channels;
-    obt_as.fmt = effective_fmt;
-    obt_as.endianness = endianness;
 
     audio_pcm_init_info (&hw->info, &obt_as);
     hw->samples = (spdo->has_buffer_count ? spdo->buffer_count : 4) *
@@ -398,9 +394,7 @@ static int sdl_init_in(HWVoiceIn *hw, audsettings *as, void *drv_opaque)
 {
     SDLVoiceIn *sdl = (SDLVoiceIn *)hw;
     SDL_AudioSpec req, obt;
-    int endianness;
     int err;
-    AudioFormat effective_fmt;
     Audiodev *dev = drv_opaque;
     AudiodevSdlPerDirectionOptions *spdo = dev->u.sdl.in;
     struct audsettings obt_as;
@@ -420,7 +414,7 @@ static int sdl_init_in(HWVoiceIn *hw, audsettings *as, void *drv_opaque)
         return -1;
     }
 
-    err = sdl_to_audfmt(obt.format, &effective_fmt, &endianness);
+    err = sdl_to_audfmt(obt.format, &obt_as.fmt, &obt_as.endianness);
     if (err) {
         sdl_close_in(sdl);
         return -1;
@@ -428,8 +422,6 @@ static int sdl_init_in(HWVoiceIn *hw, audsettings *as, void *drv_opaque)
 
     obt_as.freq = obt.freq;
     obt_as.nchannels = obt.channels;
-    obt_as.fmt = effective_fmt;
-    obt_as.endianness = endianness;
 
     audio_pcm_init_info(&hw->info, &obt_as);
     hw->samples = (spdo->has_buffer_count ? spdo->buffer_count : 4) *
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v2 44/42] audio: Rename @endianness argument as @big_endian for clarity
  2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
                   ` (42 preceding siblings ...)
  2025-10-22  7:53 ` [PATCH v2 43/42] audio: Remove pointless local variables Philippe Mathieu-Daudé
@ 2025-10-22  7:53 ` Philippe Mathieu-Daudé
  2025-10-22  7:59   ` Marc-André Lureau
  43 siblings, 1 reply; 54+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-22  7:53 UTC (permalink / raw)
  To: qemu-devel
  Cc: Gerd Hoffmann, Christian Schoenebeck, Marc-André Lureau,
	Thomas Huth, Philippe Mathieu-Daudé

@endianness is used as a boolean, rename for clarity.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 audio/alsaaudio.c | 32 ++++++--------------------------
 audio/ossaudio.c  | 14 +++-----------
 audio/paaudio.c   |  8 ++++----
 audio/pwaudio.c   | 12 ++++++------
 4 files changed, 19 insertions(+), 47 deletions(-)

diff --git a/audio/alsaaudio.c b/audio/alsaaudio.c
index 89f6dad1a97..7d7da576dc9 100644
--- a/audio/alsaaudio.c
+++ b/audio/alsaaudio.c
@@ -264,7 +264,7 @@ static int alsa_poll_in (HWVoiceIn *hw)
     return alsa_poll_helper (alsa->handle, &alsa->pollhlp, POLLIN);
 }
 
-static snd_pcm_format_t aud_to_alsafmt (AudioFormat fmt, int endianness)
+static snd_pcm_format_t aud_to_alsafmt(AudioFormat fmt, bool big_endian)
 {
     switch (fmt) {
     case AUDIO_FORMAT_S8:
@@ -274,39 +274,19 @@ static snd_pcm_format_t aud_to_alsafmt (AudioFormat fmt, int endianness)
         return SND_PCM_FORMAT_U8;
 
     case AUDIO_FORMAT_S16:
-        if (endianness) {
-            return SND_PCM_FORMAT_S16_BE;
-        } else {
-            return SND_PCM_FORMAT_S16_LE;
-        }
+        return big_endian ? SND_PCM_FORMAT_S16_BE : SND_PCM_FORMAT_S16_LE;
 
     case AUDIO_FORMAT_U16:
-        if (endianness) {
-            return SND_PCM_FORMAT_U16_BE;
-        } else {
-            return SND_PCM_FORMAT_U16_LE;
-        }
+        return big_endian ? SND_PCM_FORMAT_U16_BE : SND_PCM_FORMAT_U16_LE;
 
     case AUDIO_FORMAT_S32:
-        if (endianness) {
-            return SND_PCM_FORMAT_S32_BE;
-        } else {
-            return SND_PCM_FORMAT_S32_LE;
-        }
+        return big_endian ? SND_PCM_FORMAT_S32_BE : SND_PCM_FORMAT_S32_LE;
 
     case AUDIO_FORMAT_U32:
-        if (endianness) {
-            return SND_PCM_FORMAT_U32_BE;
-        } else {
-            return SND_PCM_FORMAT_U32_LE;
-        }
+        return big_endian ? SND_PCM_FORMAT_U32_BE : SND_PCM_FORMAT_U32_LE;
 
     case AUDIO_FORMAT_F32:
-        if (endianness) {
-            return SND_PCM_FORMAT_FLOAT_BE;
-        } else {
-            return SND_PCM_FORMAT_FLOAT_LE;
-        }
+        return big_endian ? SND_PCM_FORMAT_FLOAT_BE : SND_PCM_FORMAT_FLOAT_LE;
 
     default:
         dolog ("Internal logic error: Bad audio format %d\n", fmt);
diff --git a/audio/ossaudio.c b/audio/ossaudio.c
index 86c4805675e..c6cad47a015 100644
--- a/audio/ossaudio.c
+++ b/audio/ossaudio.c
@@ -131,7 +131,7 @@ static void oss_poll_in (HWVoiceIn *hw)
     qemu_set_fd_handler(oss->fd, oss_helper_poll_in, NULL, hw->s);
 }
 
-static int aud_to_ossfmt (AudioFormat fmt, int endianness)
+static int aud_to_ossfmt(AudioFormat fmt, bool big_endian)
 {
     switch (fmt) {
     case AUDIO_FORMAT_S8:
@@ -141,18 +141,10 @@ static int aud_to_ossfmt (AudioFormat fmt, int endianness)
         return AFMT_U8;
 
     case AUDIO_FORMAT_S16:
-        if (endianness) {
-            return AFMT_S16_BE;
-        } else {
-            return AFMT_S16_LE;
-        }
+        return big_endian ? AFMT_S16_BE : AFMT_S16_LE;
 
     case AUDIO_FORMAT_U16:
-        if (endianness) {
-            return AFMT_U16_BE;
-        } else {
-            return AFMT_U16_LE;
-        }
+        return big_endian ? AFMT_U16_BE : AFMT_U16_LE;
 
     default:
         dolog ("Internal logic error: Bad audio format %d\n", fmt);
diff --git a/audio/paaudio.c b/audio/paaudio.c
index 6b9b6d219ab..0c06a397195 100644
--- a/audio/paaudio.c
+++ b/audio/paaudio.c
@@ -316,7 +316,7 @@ unlock_and_fail:
     return 0;
 }
 
-static pa_sample_format_t audfmt_to_pa (AudioFormat afmt, int endianness)
+static pa_sample_format_t audfmt_to_pa(AudioFormat afmt, bool big_endian)
 {
     int format;
 
@@ -327,14 +327,14 @@ static pa_sample_format_t audfmt_to_pa (AudioFormat afmt, int endianness)
         break;
     case AUDIO_FORMAT_S16:
     case AUDIO_FORMAT_U16:
-        format = endianness ? PA_SAMPLE_S16BE : PA_SAMPLE_S16LE;
+        format = big_endian ? PA_SAMPLE_S16BE : PA_SAMPLE_S16LE;
         break;
     case AUDIO_FORMAT_S32:
     case AUDIO_FORMAT_U32:
-        format = endianness ? PA_SAMPLE_S32BE : PA_SAMPLE_S32LE;
+        format = big_endian ? PA_SAMPLE_S32BE : PA_SAMPLE_S32LE;
         break;
     case AUDIO_FORMAT_F32:
-        format = endianness ? PA_SAMPLE_FLOAT32BE : PA_SAMPLE_FLOAT32LE;
+        format = big_endian ? PA_SAMPLE_FLOAT32BE : PA_SAMPLE_FLOAT32LE;
         break;
     default:
         dolog ("Internal logic error: Bad audio format %d\n", afmt);
diff --git a/audio/pwaudio.c b/audio/pwaudio.c
index 0fd59d9fe60..30f717ccacf 100644
--- a/audio/pwaudio.c
+++ b/audio/pwaudio.c
@@ -324,7 +324,7 @@ done_unlock:
 }
 
 static int
-audfmt_to_pw(AudioFormat fmt, int endianness)
+audfmt_to_pw(AudioFormat fmt, bool big_endian)
 {
     int format;
 
@@ -336,19 +336,19 @@ audfmt_to_pw(AudioFormat fmt, int endianness)
         format = SPA_AUDIO_FORMAT_U8;
         break;
     case AUDIO_FORMAT_S16:
-        format = endianness ? SPA_AUDIO_FORMAT_S16_BE : SPA_AUDIO_FORMAT_S16_LE;
+        format = big_endian ? SPA_AUDIO_FORMAT_S16_BE : SPA_AUDIO_FORMAT_S16_LE;
         break;
     case AUDIO_FORMAT_U16:
-        format = endianness ? SPA_AUDIO_FORMAT_U16_BE : SPA_AUDIO_FORMAT_U16_LE;
+        format = big_endian ? SPA_AUDIO_FORMAT_U16_BE : SPA_AUDIO_FORMAT_U16_LE;
         break;
     case AUDIO_FORMAT_S32:
-        format = endianness ? SPA_AUDIO_FORMAT_S32_BE : SPA_AUDIO_FORMAT_S32_LE;
+        format = big_endian ? SPA_AUDIO_FORMAT_S32_BE : SPA_AUDIO_FORMAT_S32_LE;
         break;
     case AUDIO_FORMAT_U32:
-        format = endianness ? SPA_AUDIO_FORMAT_U32_BE : SPA_AUDIO_FORMAT_U32_LE;
+        format = big_endian ? SPA_AUDIO_FORMAT_U32_BE : SPA_AUDIO_FORMAT_U32_LE;
         break;
     case AUDIO_FORMAT_F32:
-        format = endianness ? SPA_AUDIO_FORMAT_F32_BE : SPA_AUDIO_FORMAT_F32_LE;
+        format = big_endian ? SPA_AUDIO_FORMAT_F32_BE : SPA_AUDIO_FORMAT_F32_LE;
         break;
     default:
         dolog("Internal logic error: Bad audio format %d\n", fmt);
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* Re: [PATCH v2 43/42] audio: Remove pointless local variables
  2025-10-22  7:53 ` [PATCH v2 43/42] audio: Remove pointless local variables Philippe Mathieu-Daudé
@ 2025-10-22  7:56   ` Marc-André Lureau
  0 siblings, 0 replies; 54+ messages in thread
From: Marc-André Lureau @ 2025-10-22  7:56 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, Gerd Hoffmann, Christian Schoenebeck, Thomas Huth

[-- Attachment #1: Type: text/plain, Size: 5020 bytes --]

On Wed, Oct 22, 2025 at 11:54 AM Philippe Mathieu-Daudé <philmd@linaro.org>
wrote:

> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>


> ---
>  audio/ossaudio.c | 12 ++----------
>  audio/sdlaudio.c | 12 ++----------
>  2 files changed, 4 insertions(+), 20 deletions(-)
>
> diff --git a/audio/ossaudio.c b/audio/ossaudio.c
> index ab8791bece9..86c4805675e 100644
> --- a/audio/ossaudio.c
> +++ b/audio/ossaudio.c
> @@ -493,10 +493,8 @@ static int oss_init_out(HWVoiceOut *hw, struct
> audsettings *as,
>  {
>      OSSVoiceOut *oss = (OSSVoiceOut *) hw;
>      struct oss_params req, obt;
> -    int endianness;
>      int err;
>      int fd;
> -    AudioFormat effective_fmt;
>      struct audsettings obt_as;
>      Audiodev *dev = drv_opaque;
>      AudiodevOssOptions *oopts = &dev->u.oss;
> @@ -511,7 +509,7 @@ static int oss_init_out(HWVoiceOut *hw, struct
> audsettings *as,
>          return -1;
>      }
>
> -    err = oss_to_audfmt (obt.fmt, &effective_fmt, &endianness);
> +    err = oss_to_audfmt(obt.fmt, &obt_as.fmt, &obt_as.endianness);
>      if (err) {
>          oss_anal_close (&fd);
>          return -1;
> @@ -519,8 +517,6 @@ static int oss_init_out(HWVoiceOut *hw, struct
> audsettings *as,
>
>      obt_as.freq = obt.freq;
>      obt_as.nchannels = obt.nchannels;
> -    obt_as.fmt = effective_fmt;
> -    obt_as.endianness = endianness;
>
>      audio_pcm_init_info (&hw->info, &obt_as);
>      oss->nfrags = obt.nfrags;
> @@ -628,10 +624,8 @@ static int oss_init_in(HWVoiceIn *hw, struct
> audsettings *as, void *drv_opaque)
>  {
>      OSSVoiceIn *oss = (OSSVoiceIn *) hw;
>      struct oss_params req, obt;
> -    int endianness;
>      int err;
>      int fd;
> -    AudioFormat effective_fmt;
>      struct audsettings obt_as;
>      Audiodev *dev = drv_opaque;
>
> @@ -644,7 +638,7 @@ static int oss_init_in(HWVoiceIn *hw, struct
> audsettings *as, void *drv_opaque)
>          return -1;
>      }
>
> -    err = oss_to_audfmt (obt.fmt, &effective_fmt, &endianness);
> +    err = oss_to_audfmt(obt.fmt, &obt_as.fmt, &obt_as.endianness);
>      if (err) {
>          oss_anal_close (&fd);
>          return -1;
> @@ -652,8 +646,6 @@ static int oss_init_in(HWVoiceIn *hw, struct
> audsettings *as, void *drv_opaque)
>
>      obt_as.freq = obt.freq;
>      obt_as.nchannels = obt.nchannels;
> -    obt_as.fmt = effective_fmt;
> -    obt_as.endianness = endianness;
>
>      audio_pcm_init_info (&hw->info, &obt_as);
>      oss->nfrags = obt.nfrags;
> diff --git a/audio/sdlaudio.c b/audio/sdlaudio.c
> index a7a9652d29d..707110973ac 100644
> --- a/audio/sdlaudio.c
> +++ b/audio/sdlaudio.c
> @@ -338,9 +338,7 @@ static int sdl_init_out(HWVoiceOut *hw, struct
> audsettings *as,
>  {
>      SDLVoiceOut *sdl = (SDLVoiceOut *)hw;
>      SDL_AudioSpec req, obt;
> -    int endianness;
>      int err;
> -    AudioFormat effective_fmt;
>      Audiodev *dev = drv_opaque;
>      AudiodevSdlPerDirectionOptions *spdo = dev->u.sdl.out;
>      struct audsettings obt_as;
> @@ -360,7 +358,7 @@ static int sdl_init_out(HWVoiceOut *hw, struct
> audsettings *as,
>          return -1;
>      }
>
> -    err = sdl_to_audfmt(obt.format, &effective_fmt, &endianness);
> +    err = sdl_to_audfmt(obt.format, &obt_as.fmt, &obt_as.endianness);
>      if (err) {
>          sdl_close_out(sdl);
>          return -1;
> @@ -368,8 +366,6 @@ static int sdl_init_out(HWVoiceOut *hw, struct
> audsettings *as,
>
>      obt_as.freq = obt.freq;
>      obt_as.nchannels = obt.channels;
> -    obt_as.fmt = effective_fmt;
> -    obt_as.endianness = endianness;
>
>      audio_pcm_init_info (&hw->info, &obt_as);
>      hw->samples = (spdo->has_buffer_count ? spdo->buffer_count : 4) *
> @@ -398,9 +394,7 @@ static int sdl_init_in(HWVoiceIn *hw, audsettings *as,
> void *drv_opaque)
>  {
>      SDLVoiceIn *sdl = (SDLVoiceIn *)hw;
>      SDL_AudioSpec req, obt;
> -    int endianness;
>      int err;
> -    AudioFormat effective_fmt;
>      Audiodev *dev = drv_opaque;
>      AudiodevSdlPerDirectionOptions *spdo = dev->u.sdl.in;
>      struct audsettings obt_as;
> @@ -420,7 +414,7 @@ static int sdl_init_in(HWVoiceIn *hw, audsettings *as,
> void *drv_opaque)
>          return -1;
>      }
>
> -    err = sdl_to_audfmt(obt.format, &effective_fmt, &endianness);
> +    err = sdl_to_audfmt(obt.format, &obt_as.fmt, &obt_as.endianness);
>      if (err) {
>          sdl_close_in(sdl);
>          return -1;
> @@ -428,8 +422,6 @@ static int sdl_init_in(HWVoiceIn *hw, audsettings *as,
> void *drv_opaque)
>
>      obt_as.freq = obt.freq;
>      obt_as.nchannels = obt.channels;
> -    obt_as.fmt = effective_fmt;
> -    obt_as.endianness = endianness;
>
>      audio_pcm_init_info(&hw->info, &obt_as);
>      hw->samples = (spdo->has_buffer_count ? spdo->buffer_count : 4) *
> --
> 2.51.0
>
>

[-- Attachment #2: Type: text/html, Size: 6338 bytes --]

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v2 44/42] audio: Rename @endianness argument as @big_endian for clarity
  2025-10-22  7:53 ` [PATCH v2 44/42] audio: Rename @endianness argument as @big_endian for clarity Philippe Mathieu-Daudé
@ 2025-10-22  7:59   ` Marc-André Lureau
  0 siblings, 0 replies; 54+ messages in thread
From: Marc-André Lureau @ 2025-10-22  7:59 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, Gerd Hoffmann, Christian Schoenebeck, Thomas Huth

On Wed, Oct 22, 2025 at 11:55 AM Philippe Mathieu-Daudé
<philmd@linaro.org> wrote:
>
> @endianness is used as a boolean, rename for clarity.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

> ---
>  audio/alsaaudio.c | 32 ++++++--------------------------
>  audio/ossaudio.c  | 14 +++-----------
>  audio/paaudio.c   |  8 ++++----
>  audio/pwaudio.c   | 12 ++++++------
>  4 files changed, 19 insertions(+), 47 deletions(-)
>
> diff --git a/audio/alsaaudio.c b/audio/alsaaudio.c
> index 89f6dad1a97..7d7da576dc9 100644
> --- a/audio/alsaaudio.c
> +++ b/audio/alsaaudio.c
> @@ -264,7 +264,7 @@ static int alsa_poll_in (HWVoiceIn *hw)
>      return alsa_poll_helper (alsa->handle, &alsa->pollhlp, POLLIN);
>  }
>
> -static snd_pcm_format_t aud_to_alsafmt (AudioFormat fmt, int endianness)
> +static snd_pcm_format_t aud_to_alsafmt(AudioFormat fmt, bool big_endian)
>  {
>      switch (fmt) {
>      case AUDIO_FORMAT_S8:
> @@ -274,39 +274,19 @@ static snd_pcm_format_t aud_to_alsafmt (AudioFormat fmt, int endianness)
>          return SND_PCM_FORMAT_U8;
>
>      case AUDIO_FORMAT_S16:
> -        if (endianness) {
> -            return SND_PCM_FORMAT_S16_BE;
> -        } else {
> -            return SND_PCM_FORMAT_S16_LE;
> -        }
> +        return big_endian ? SND_PCM_FORMAT_S16_BE : SND_PCM_FORMAT_S16_LE;
>
>      case AUDIO_FORMAT_U16:
> -        if (endianness) {
> -            return SND_PCM_FORMAT_U16_BE;
> -        } else {
> -            return SND_PCM_FORMAT_U16_LE;
> -        }
> +        return big_endian ? SND_PCM_FORMAT_U16_BE : SND_PCM_FORMAT_U16_LE;
>
>      case AUDIO_FORMAT_S32:
> -        if (endianness) {
> -            return SND_PCM_FORMAT_S32_BE;
> -        } else {
> -            return SND_PCM_FORMAT_S32_LE;
> -        }
> +        return big_endian ? SND_PCM_FORMAT_S32_BE : SND_PCM_FORMAT_S32_LE;
>
>      case AUDIO_FORMAT_U32:
> -        if (endianness) {
> -            return SND_PCM_FORMAT_U32_BE;
> -        } else {
> -            return SND_PCM_FORMAT_U32_LE;
> -        }
> +        return big_endian ? SND_PCM_FORMAT_U32_BE : SND_PCM_FORMAT_U32_LE;
>
>      case AUDIO_FORMAT_F32:
> -        if (endianness) {
> -            return SND_PCM_FORMAT_FLOAT_BE;
> -        } else {
> -            return SND_PCM_FORMAT_FLOAT_LE;
> -        }
> +        return big_endian ? SND_PCM_FORMAT_FLOAT_BE : SND_PCM_FORMAT_FLOAT_LE;
>
>      default:
>          dolog ("Internal logic error: Bad audio format %d\n", fmt);
> diff --git a/audio/ossaudio.c b/audio/ossaudio.c
> index 86c4805675e..c6cad47a015 100644
> --- a/audio/ossaudio.c
> +++ b/audio/ossaudio.c
> @@ -131,7 +131,7 @@ static void oss_poll_in (HWVoiceIn *hw)
>      qemu_set_fd_handler(oss->fd, oss_helper_poll_in, NULL, hw->s);
>  }
>
> -static int aud_to_ossfmt (AudioFormat fmt, int endianness)
> +static int aud_to_ossfmt(AudioFormat fmt, bool big_endian)
>  {
>      switch (fmt) {
>      case AUDIO_FORMAT_S8:
> @@ -141,18 +141,10 @@ static int aud_to_ossfmt (AudioFormat fmt, int endianness)
>          return AFMT_U8;
>
>      case AUDIO_FORMAT_S16:
> -        if (endianness) {
> -            return AFMT_S16_BE;
> -        } else {
> -            return AFMT_S16_LE;
> -        }
> +        return big_endian ? AFMT_S16_BE : AFMT_S16_LE;
>
>      case AUDIO_FORMAT_U16:
> -        if (endianness) {
> -            return AFMT_U16_BE;
> -        } else {
> -            return AFMT_U16_LE;
> -        }
> +        return big_endian ? AFMT_U16_BE : AFMT_U16_LE;
>
>      default:
>          dolog ("Internal logic error: Bad audio format %d\n", fmt);
> diff --git a/audio/paaudio.c b/audio/paaudio.c
> index 6b9b6d219ab..0c06a397195 100644
> --- a/audio/paaudio.c
> +++ b/audio/paaudio.c
> @@ -316,7 +316,7 @@ unlock_and_fail:
>      return 0;
>  }
>
> -static pa_sample_format_t audfmt_to_pa (AudioFormat afmt, int endianness)
> +static pa_sample_format_t audfmt_to_pa(AudioFormat afmt, bool big_endian)
>  {
>      int format;
>
> @@ -327,14 +327,14 @@ static pa_sample_format_t audfmt_to_pa (AudioFormat afmt, int endianness)
>          break;
>      case AUDIO_FORMAT_S16:
>      case AUDIO_FORMAT_U16:
> -        format = endianness ? PA_SAMPLE_S16BE : PA_SAMPLE_S16LE;
> +        format = big_endian ? PA_SAMPLE_S16BE : PA_SAMPLE_S16LE;
>          break;
>      case AUDIO_FORMAT_S32:
>      case AUDIO_FORMAT_U32:
> -        format = endianness ? PA_SAMPLE_S32BE : PA_SAMPLE_S32LE;
> +        format = big_endian ? PA_SAMPLE_S32BE : PA_SAMPLE_S32LE;
>          break;
>      case AUDIO_FORMAT_F32:
> -        format = endianness ? PA_SAMPLE_FLOAT32BE : PA_SAMPLE_FLOAT32LE;
> +        format = big_endian ? PA_SAMPLE_FLOAT32BE : PA_SAMPLE_FLOAT32LE;
>          break;
>      default:
>          dolog ("Internal logic error: Bad audio format %d\n", afmt);
> diff --git a/audio/pwaudio.c b/audio/pwaudio.c
> index 0fd59d9fe60..30f717ccacf 100644
> --- a/audio/pwaudio.c
> +++ b/audio/pwaudio.c
> @@ -324,7 +324,7 @@ done_unlock:
>  }
>
>  static int
> -audfmt_to_pw(AudioFormat fmt, int endianness)
> +audfmt_to_pw(AudioFormat fmt, bool big_endian)
>  {
>      int format;
>
> @@ -336,19 +336,19 @@ audfmt_to_pw(AudioFormat fmt, int endianness)
>          format = SPA_AUDIO_FORMAT_U8;
>          break;
>      case AUDIO_FORMAT_S16:
> -        format = endianness ? SPA_AUDIO_FORMAT_S16_BE : SPA_AUDIO_FORMAT_S16_LE;
> +        format = big_endian ? SPA_AUDIO_FORMAT_S16_BE : SPA_AUDIO_FORMAT_S16_LE;
>          break;
>      case AUDIO_FORMAT_U16:
> -        format = endianness ? SPA_AUDIO_FORMAT_U16_BE : SPA_AUDIO_FORMAT_U16_LE;
> +        format = big_endian ? SPA_AUDIO_FORMAT_U16_BE : SPA_AUDIO_FORMAT_U16_LE;
>          break;
>      case AUDIO_FORMAT_S32:
> -        format = endianness ? SPA_AUDIO_FORMAT_S32_BE : SPA_AUDIO_FORMAT_S32_LE;
> +        format = big_endian ? SPA_AUDIO_FORMAT_S32_BE : SPA_AUDIO_FORMAT_S32_LE;
>          break;
>      case AUDIO_FORMAT_U32:
> -        format = endianness ? SPA_AUDIO_FORMAT_U32_BE : SPA_AUDIO_FORMAT_U32_LE;
> +        format = big_endian ? SPA_AUDIO_FORMAT_U32_BE : SPA_AUDIO_FORMAT_U32_LE;
>          break;
>      case AUDIO_FORMAT_F32:
> -        format = endianness ? SPA_AUDIO_FORMAT_F32_BE : SPA_AUDIO_FORMAT_F32_LE;
> +        format = big_endian ? SPA_AUDIO_FORMAT_F32_BE : SPA_AUDIO_FORMAT_F32_LE;
>          break;
>      default:
>          dolog("Internal logic error: Bad audio format %d\n", fmt);
> --
> 2.51.0
>
>


-- 
Marc-André Lureau


^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v2 11/42] hw/audio: use better naming for -audio model handling code
  2025-10-22  6:56 ` [PATCH v2 11/42] hw/audio: use better naming for -audio model handling code marcandre.lureau
@ 2025-10-22  8:04   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 54+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-22  8:04 UTC (permalink / raw)
  To: marcandre.lureau, qemu-devel
  Cc: Volker Rümelin, Paolo Bonzini, BALATON Zoltan, Gerd Hoffmann,
	Manos Pitsidianakis, Michael S. Tsirkin, Eduardo Habkost

On 22/10/25 08:56, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> All the functions are about "-audio model=" handling, a simpler
> way to setup audio. Rename functions/variables to reflect this better.
> 
> audio_register_model_with_cb() dropped "pci" from the name, since it
> will be generalized next.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>   include/hw/audio/model.h                      | 13 +++++
>   include/hw/audio/soundhw.h                    | 13 -----
>   hw/audio/ac97.c                               |  5 +-
>   hw/audio/adlib.c                              |  4 +-
>   hw/audio/cs4231a.c                            |  4 +-
>   hw/audio/es1370.c                             |  5 +-
>   hw/audio/gus.c                                |  4 +-
>   hw/audio/intel-hda.c                          |  4 +-
>   hw/audio/{soundhw.c => model.c}               | 58 +++++++++----------
>   hw/audio/pcspk.c                              |  2 +-
>   hw/audio/sb16.c                               |  5 +-
>   hw/audio/virtio-snd-pci.c                     |  4 +-
>   system/vl.c                                   |  6 +-
>   hw/audio/meson.build                          |  2 +-
>   .../codeconverter/test_regexps.py             |  2 +-
>   15 files changed, 64 insertions(+), 67 deletions(-)
>   create mode 100644 include/hw/audio/model.h
>   delete mode 100644 include/hw/audio/soundhw.h
>   rename hw/audio/{soundhw.c => model.c} (68%)
> 
> diff --git a/include/hw/audio/model.h b/include/hw/audio/model.h
> new file mode 100644
> index 0000000000..27ae7dcc31
> --- /dev/null
> +++ b/include/hw/audio/model.h
> @@ -0,0 +1,13 @@
> +#ifndef HW_AUDIO_MODEL_H
> +#define HW_AUDIO_MODEL_H

Pre-existing, but add missing license tag?

> +
> +void audio_register_model_with_cb(const char *name, const char *descr,
> +                                  int (*init_pci)(PCIBus *bus, const char *audiodev));
> +void audio_register_model(const char *name, const char *descr,
> +                          int isa, const char *typename);
> +
> +void audio_model_init(void);
> +void audio_print_available_models(void);
> +void audio_set_model(const char *name, const char *audiodev);
> +
> +#endif
> diff --git a/include/hw/audio/soundhw.h b/include/hw/audio/soundhw.h
> deleted file mode 100644
> index 83b3011083..0000000000
> --- a/include/hw/audio/soundhw.h
> +++ /dev/null
> @@ -1,13 +0,0 @@
> -#ifndef HW_SOUNDHW_H
> -#define HW_SOUNDHW_H
> -
> -void pci_register_soundhw(const char *name, const char *descr,
> -                          int (*init_pci)(PCIBus *bus, const char *audiodev));
> -void deprecated_register_soundhw(const char *name, const char *descr,
> -                                 int isa, const char *typename);

Please mention in patch description why this interface is not
anymore deprecated.

Otherwise,
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

> -
> -void soundhw_init(void);
> -void audio_print_available_models(void);
> -void select_soundhw(const char *name, const char *audiodev);
> -
> -#endif



^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v2 13/42] hw/audio: simplify 'hda' audio init code
  2025-10-22  6:56 ` [PATCH v2 13/42] hw/audio: simplify 'hda' audio init code marcandre.lureau
@ 2025-10-22 11:41   ` BALATON Zoltan
  2025-10-22 11:49     ` Marc-André Lureau
  0 siblings, 1 reply; 54+ messages in thread
From: BALATON Zoltan @ 2025-10-22 11:41 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, Philippe Mathieu-Daudé, Volker Rümelin,
	Paolo Bonzini, Gerd Hoffmann

[-- Attachment #1: Type: text/plain, Size: 2229 bytes --]

On Wed, 22 Oct 2025, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> For consistency, use only qdev_device_add() to instantiate the devices.
> We can't rely on automatic bus lookup for the "hda-duplex" device though
> as it may end up on a different "intel-hda" bus...

Maybe this needs a better commit message. My first question was how is 
this simpler when it's 6 lines more and at least to me less obvious what 
it does. The real goal may be to make it independent from PCI for the next 
patch so maybe that's what the commit message should also say.

Regards,
BALATON Zoltan

> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> hw/audio/intel-hda.c | 14 ++++++++++----
> 1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/hw/audio/intel-hda.c b/hw/audio/intel-hda.c
> index 6a0db0dd9e..14bcf1257d 100644
> --- a/hw/audio/intel-hda.c
> +++ b/hw/audio/intel-hda.c
> @@ -21,6 +21,7 @@
> #include "hw/pci/pci.h"
> #include "hw/qdev-properties.h"
> #include "hw/pci/msi.h"
> +#include "monitor/qdev.h"
> #include "qemu/timer.h"
> #include "qemu/bitops.h"
> #include "qemu/log.h"
> @@ -30,6 +31,7 @@
> #include "intel-hda.h"
> #include "migration/vmstate.h"
> #include "intel-hda-defs.h"
> +#include "qobject/qdict.h"
> #include "system/dma.h"
> #include "qapi/error.h"
> #include "qom/object.h"
> @@ -1305,15 +1307,19 @@ static const TypeInfo hda_codec_device_type_info = {
>  */
> static int intel_hda_and_codec_init(PCIBus *bus, const char *audiodev)
> {
> -    DeviceState *controller;
> +    g_autoptr(QDict) props = qdict_new();
> +    DeviceState *intel_hda, *codec;
>     BusState *hdabus;
> -    DeviceState *codec;
>
> -    controller = DEVICE(pci_create_simple(bus, -1, "intel-hda"));
> -    hdabus = QLIST_FIRST(&controller->child_bus);
> +    qdict_put_str(props, "driver", "intel-hda");
> +    intel_hda = qdev_device_add_from_qdict(props, false, &error_fatal);
> +    hdabus = QLIST_FIRST(&intel_hda->child_bus);
> +
>     codec = qdev_new("hda-duplex");
>     qdev_prop_set_string(codec, "audiodev", audiodev);
>     qdev_realize_and_unref(codec, hdabus, &error_fatal);
> +    object_unref(intel_hda);
> +
>     return 0;
> }
>
>

^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v2 13/42] hw/audio: simplify 'hda' audio init code
  2025-10-22 11:41   ` BALATON Zoltan
@ 2025-10-22 11:49     ` Marc-André Lureau
  0 siblings, 0 replies; 54+ messages in thread
From: Marc-André Lureau @ 2025-10-22 11:49 UTC (permalink / raw)
  To: BALATON Zoltan
  Cc: qemu-devel, Philippe Mathieu-Daudé, Volker Rümelin,
	Paolo Bonzini, Gerd Hoffmann

Hi

On Wed, Oct 22, 2025 at 3:42 PM BALATON Zoltan <balaton@eik.bme.hu> wrote:
>
> On Wed, 22 Oct 2025, marcandre.lureau@redhat.com wrote:
> > From: Marc-André Lureau <marcandre.lureau@redhat.com>
> >
> > For consistency, use only qdev_device_add() to instantiate the devices.
> > We can't rely on automatic bus lookup for the "hda-duplex" device though
> > as it may end up on a different "intel-hda" bus...
>
> Maybe this needs a better commit message. My first question was how is
> this simpler when it's 6 lines more and at least to me less obvious what
> it does. The real goal may be to make it independent from PCI for the next
> patch so maybe that's what the commit message should also say.

I agree it's not as simple and generalized as I wish it would have ended.

But this allows to make init() callback bus-agnostic though. I will
add this to the commit message.

There might be other ways to do that.

> Regards,
> BALATON Zoltan
>
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> > hw/audio/intel-hda.c | 14 ++++++++++----
> > 1 file changed, 10 insertions(+), 4 deletions(-)
> >
> > diff --git a/hw/audio/intel-hda.c b/hw/audio/intel-hda.c
> > index 6a0db0dd9e..14bcf1257d 100644
> > --- a/hw/audio/intel-hda.c
> > +++ b/hw/audio/intel-hda.c
> > @@ -21,6 +21,7 @@
> > #include "hw/pci/pci.h"
> > #include "hw/qdev-properties.h"
> > #include "hw/pci/msi.h"
> > +#include "monitor/qdev.h"
> > #include "qemu/timer.h"
> > #include "qemu/bitops.h"
> > #include "qemu/log.h"
> > @@ -30,6 +31,7 @@
> > #include "intel-hda.h"
> > #include "migration/vmstate.h"
> > #include "intel-hda-defs.h"
> > +#include "qobject/qdict.h"
> > #include "system/dma.h"
> > #include "qapi/error.h"
> > #include "qom/object.h"
> > @@ -1305,15 +1307,19 @@ static const TypeInfo hda_codec_device_type_info = {
> >  */
> > static int intel_hda_and_codec_init(PCIBus *bus, const char *audiodev)
> > {
> > -    DeviceState *controller;
> > +    g_autoptr(QDict) props = qdict_new();
> > +    DeviceState *intel_hda, *codec;
> >     BusState *hdabus;
> > -    DeviceState *codec;
> >
> > -    controller = DEVICE(pci_create_simple(bus, -1, "intel-hda"));
> > -    hdabus = QLIST_FIRST(&controller->child_bus);
> > +    qdict_put_str(props, "driver", "intel-hda");
> > +    intel_hda = qdev_device_add_from_qdict(props, false, &error_fatal);
> > +    hdabus = QLIST_FIRST(&intel_hda->child_bus);
> > +
> >     codec = qdev_new("hda-duplex");
> >     qdev_prop_set_string(codec, "audiodev", audiodev);
> >     qdev_realize_and_unref(codec, hdabus, &error_fatal);
> > +    object_unref(intel_hda);
> > +
> >     return 0;
> > }
> >
> >



-- 
Marc-André Lureau


^ permalink raw reply	[flat|nested] 54+ messages in thread

* Re: [PATCH v2 39/42] audio: cleanup, use bool for booleans
  2025-10-22  6:56 ` [PATCH v2 39/42] audio: cleanup, use bool for booleans marcandre.lureau
  2025-10-22  7:05   ` Philippe Mathieu-Daudé
@ 2025-10-22 12:01   ` BALATON Zoltan
  1 sibling, 0 replies; 54+ messages in thread
From: BALATON Zoltan @ 2025-10-22 12:01 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, Philippe Mathieu-Daudé, Volker Rümelin,
	Paolo Bonzini, Gerd Hoffmann

[-- Attachment #1: Type: text/plain, Size: 1154 bytes --]

On Wed, 22 Oct 2025, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> Use slightly better types for the job.
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> audio/audio_int.h      | 12 ++++++------
> audio/audio_template.h |  6 +++---
> include/qemu/audio.h   |  8 ++++----
> audio/audio.c          | 30 +++++++++++++++---------------
> 4 files changed, 28 insertions(+), 28 deletions(-)
>
> diff --git a/audio/audio_int.h b/audio/audio_int.h
> index a97edd77dd..c804302e51 100644
> --- a/audio/audio_int.h
> +++ b/audio/audio_int.h
> @@ -67,9 +67,9 @@ typedef struct STSampleBuffer {
>
> typedef struct HWVoiceOut {
>     AudioBackend *s;
> -    int enabled;
> +    bool enabled;
>     int poll_mode;
> -    int pending_disable;
> +    bool pending_disable;

I don't know if this is part of a state for migration but if not maybe 
it's better to also move pending_disable up before poll_mode to group the 
bools that enable/disable something together (and the struct may need less 
padding that way depending on what type by the compiler uses for bool).

Regards,
BALATON Zoltan

^ permalink raw reply	[flat|nested] 54+ messages in thread

end of thread, other threads:[~2025-10-22 12:02 UTC | newest]

Thread overview: 54+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-22  6:55 [PATCH v2 00/42] Audio clean-ups marcandre.lureau
2025-10-22  6:55 ` [PATCH v2 01/42] hw/audio: improve error reports marcandre.lureau
2025-10-22  6:55 ` [PATCH v2 02/42] hw/audio: rename model list function marcandre.lureau
2025-10-22  6:55 ` [PATCH v2 03/42] hw/audio: remove global pcspk marcandre.lureau
2025-10-22  6:55 ` [PATCH v2 04/42] hw/pcspk: use explicitly the required PIT types marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 05/42] hw/pcspk: make 'pit' a class property marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 06/42] hw/pcspk: check the "pit" is set marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 07/42] docs: update -soundhw -> -device list marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 08/42] qdev: add qdev_find_default_bus() marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 09/42] hw/audio: look up the default bus from the device class marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 10/42] audio: rename audio_define->audio_add_audiodev() marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 11/42] hw/audio: use better naming for -audio model handling code marcandre.lureau
2025-10-22  8:04   ` Philippe Mathieu-Daudé
2025-10-22  6:56 ` [PATCH v2 12/42] hw/audio/virtio-snd-pci: remove custom model callback marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 13/42] hw/audio: simplify 'hda' audio init code marcandre.lureau
2025-10-22 11:41   ` BALATON Zoltan
2025-10-22 11:49     ` Marc-André Lureau
2025-10-22  6:56 ` [PATCH v2 14/42] hw/audio: generalize audio_model.init() marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 15/42] hw/audio: drop audio_model.isa marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 16/42] audio: start making AudioState a QOM Object marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 17/42] audio: register backends in /audiodevs container marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 18/42] audio: use /audiodevs QOM container marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 19/42] audio/paaudio: remove needless return value marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 20/42] audio/dsound: simplify init() marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 21/42] audio/dsound: report init error via **errp marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 22/42] audio: simplify audio_driver_init() marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 23/42] audio: move period tick initialization marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 24/42] audio: drop needless error message marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 25/42] audio: clean-up vmstate change handler on finalize marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 26/42] audio: unregister vmstate description marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 27/42] audio: initialize card_head during object init marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 28/42] audio: remove some needless headers marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 29/42] audio: remove AUDIO_HOST_ENDIANNESS marcandre.lureau
2025-10-22  7:11   ` Philippe Mathieu-Daudé
2025-10-22  6:56 ` [PATCH v2 30/42] audio: introduce AUD_set_volume_{in,out}_lr() marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 31/42] hw/audio: replace AUD_log() usage marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 32/42] audio/replay: fix type punning marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 33/42] audio: move internal APIs to audio_int.h marcandre.lureau
2025-10-22  7:08   ` Philippe Mathieu-Daudé
2025-10-22  6:56 ` [PATCH v2 34/42] audio: rename AudioState -> AudioBackend marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 35/42] audio: remove QEMUSoundCard marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 36/42] audio/dbus: use a helper function to set the backend dbus server marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 37/42] audio: move audio.h under include/qemu/ marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 38/42] audio: remove dependency on spice header marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 39/42] audio: cleanup, use bool for booleans marcandre.lureau
2025-10-22  7:05   ` Philippe Mathieu-Daudé
2025-10-22 12:01   ` BALATON Zoltan
2025-10-22  6:56 ` [PATCH v2 40/42] audio: move capture API to own header marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 41/42] audio: drop needless audio_driver "descr" field marcandre.lureau
2025-10-22  6:56 ` [PATCH v2 42/42] docs: Update mentions of removed '-soundhw' command line option marcandre.lureau
2025-10-22  7:53 ` [PATCH v2 43/42] audio: Remove pointless local variables Philippe Mathieu-Daudé
2025-10-22  7:56   ` Marc-André Lureau
2025-10-22  7:53 ` [PATCH v2 44/42] audio: Rename @endianness argument as @big_endian for clarity Philippe Mathieu-Daudé
2025-10-22  7:59   ` Marc-André Lureau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).