diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2018-06-22 13:11:58 +0200 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2018-06-25 13:57:57 +0200 |
commit | 8ced0669237b2bbedac3e4ce6fcf7aaaafaae663 (patch) | |
tree | 70d0a39a36200ceba2c2abd7c0556830d5ff08cb /hw/audio/hda-codec.c | |
parent | 0a373bb310c1533e24aa5e3edbf206507fb342ea (diff) | |
download | qemu-8ced0669237b2bbedac3e4ce6fcf7aaaafaae663.zip |
audio/hda: tweak timer adjust logic
We have some jitter in the audio timer call frequency and buffer sizes.
So it is rather pointless trying to be very exact, effect is a constant
up+down adjustment. So adjust only in case we are off too much.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Message-id: 20180622111200.30561-4-kraxel@redhat.com
Diffstat (limited to 'hw/audio/hda-codec.c')
-rw-r--r-- | hw/audio/hda-codec.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/hw/audio/hda-codec.c b/hw/audio/hda-codec.c index a08516cbf8..870448a687 100644 --- a/hw/audio/hda-codec.c +++ b/hw/audio/hda-codec.c @@ -129,7 +129,6 @@ static void hda_codec_parse_fmt(uint32_t format, struct audsettings *as) #include "hda-codec-common.h" #define HDA_TIMER_TICKS (SCALE_MS) -#define MAX_CORR (SCALE_US * 100) #define B_SIZE sizeof(st->buf) #define B_MASK (sizeof(st->buf) - 1) @@ -196,13 +195,20 @@ static inline int64_t hda_bytes_per_second(HDAAudioStream *st) static inline void hda_timer_sync_adjust(HDAAudioStream *st, int64_t target_pos) { - int64_t corr = - NANOSECONDS_PER_SECOND * target_pos / hda_bytes_per_second(st); - if (corr > MAX_CORR) { - corr = MAX_CORR; - } else if (corr < -MAX_CORR) { - corr = -MAX_CORR; + int64_t limit = B_SIZE / 8; + int64_t corr = 0; + + if (target_pos > limit) { + corr = HDA_TIMER_TICKS; + } + if (target_pos < -limit) { + corr = -HDA_TIMER_TICKS; } + if (corr == 0) { + return; + } + + trace_hda_audio_adjust(st->node->name, target_pos); atomic_fetch_add(&st->buft_start, corr); } |