Browse Source

audio: fix audio timer rate conversion bug

Currently the default audio timer frequency is 10000Hz instead of
a period of 10000us. Also the audiodev timer-period property gets
converted like a frequency. Only handling of the legacy
QEMU_AUDIO_TIMER_PERIOD environment variable is correct because
it's actually a frequency.

With this patch the property timer-period is really a timer period
and QEMU_AUDIO_TIMER_PERIOD remains a frequency.

Fixes: 71830221fb "-audiodev command line option basic implementation."
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Reviewed-by: Zoltán Kővágó <DirtY.iCE.hu@gmail.com>
Message-id: 90b95e4f-39ef-2b01-da6a-857ebaee1e@t-online.de
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
tags/v4.0.0-rc2
Volker Rümelin 2 months ago
parent
commit
be1092afa0
2 changed files with 7 additions and 1 deletions
  1. 1
    1
      audio/audio.c
  2. 6
    0
      audio/audio_legacy.c

+ 1
- 1
audio/audio.c View File

@@ -1471,7 +1471,7 @@ static int audio_init(Audiodev *dev)
1471 1471
     if (dev->timer_period <= 0) {
1472 1472
         s->period_ticks = 1;
1473 1473
     } else {
1474
-        s->period_ticks = NANOSECONDS_PER_SECOND / dev->timer_period;
1474
+        s->period_ticks = dev->timer_period * SCALE_US;
1475 1475
     }
1476 1476
 
1477 1477
     e = qemu_add_vm_change_state_handler (audio_vm_change_state_handler, s);

+ 6
- 0
audio/audio_legacy.c View File

@@ -26,6 +26,7 @@
26 26
 #include "audio_int.h"
27 27
 #include "qemu-common.h"
28 28
 #include "qemu/cutils.h"
29
+#include "qemu/timer.h"
29 30
 #include "qapi/error.h"
30 31
 #include "qapi/qapi-visit-audio.h"
31 32
 #include "qapi/visitor-impl.h"
@@ -338,8 +339,13 @@ static AudiodevListEntry *legacy_opt(const char *drvname)
338 339
     handle_per_direction(audio_get_pdo_in(e->dev), "QEMU_AUDIO_ADC_");
339 340
     handle_per_direction(audio_get_pdo_out(e->dev), "QEMU_AUDIO_DAC_");
340 341
 
342
+    /* Original description: Timer period in HZ (0 - use lowest possible) */
341 343
     get_int("QEMU_AUDIO_TIMER_PERIOD",
342 344
             &e->dev->timer_period, &e->dev->has_timer_period);
345
+    if (e->dev->has_timer_period && e->dev->timer_period) {
346
+        e->dev->timer_period = NANOSECONDS_PER_SECOND / 1000 /
347
+                               e->dev->timer_period;
348
+    }
343 349
 
344 350
     switch (e->dev->driver) {
345 351
     case AUDIODEV_DRIVER_ALSA:

Loading…
Cancel
Save