[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 05/12] audio: add more audio rate control functions
From: |
Volker Rümelin |
Subject: |
[PATCH 05/12] audio: add more audio rate control functions |
Date: |
Fri, 23 Sep 2022 20:36:33 +0200 |
The next patch needs two new rate control functions. The first
one returns the bytes needed at call time to maintain the
selected rate. The second one adjusts the bytes actually sent.
Split the audio_rate_get_bytes() function into these two
functions and reintroduce audio_rate_get_bytes().
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
---
audio/audio.c | 35 ++++++++++++++++++++++++-----------
audio/audio_int.h | 2 ++
2 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/audio/audio.c b/audio/audio.c
index 9e55834909..557538a7b7 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -2250,26 +2250,39 @@ void audio_rate_start(RateCtl *rate)
rate->start_ticks = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
}
-size_t audio_rate_get_bytes(struct audio_pcm_info *info, RateCtl *rate,
- size_t bytes_avail)
+size_t audio_rate_peek_bytes(RateCtl *rate, struct audio_pcm_info *info)
{
int64_t now;
int64_t ticks;
int64_t bytes;
- int64_t samples;
- size_t ret;
+ int64_t frames;
now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
ticks = now - rate->start_ticks;
bytes = muldiv64(ticks, info->bytes_per_second, NANOSECONDS_PER_SECOND);
- samples = (bytes - rate->bytes_sent) / info->bytes_per_frame;
- if (samples < 0 || samples > 65536) {
- AUD_log(NULL, "Resetting rate control (%" PRId64 " samples)\n",
samples);
+ frames = (bytes - rate->bytes_sent) / info->bytes_per_frame;
+ if (frames < 0 || frames > 65536) {
+ AUD_log(NULL, "Resetting rate control (%" PRId64 " frames)\n", frames);
audio_rate_start(rate);
- samples = 0;
+ frames = 0;
}
- ret = MIN(samples * info->bytes_per_frame, bytes_avail);
- rate->bytes_sent += ret;
- return ret;
+ return frames * info->bytes_per_frame;
+}
+
+void audio_rate_add_bytes(RateCtl *rate, size_t bytes_used)
+{
+ rate->bytes_sent += bytes_used;
+}
+
+size_t audio_rate_get_bytes(struct audio_pcm_info *info, RateCtl *rate,
+ size_t bytes_avail)
+{
+ size_t bytes;
+
+ bytes = audio_rate_peek_bytes(rate, info);
+ bytes = MIN(bytes, bytes_avail);
+ audio_rate_add_bytes(rate, bytes);
+
+ return bytes;
}
diff --git a/audio/audio_int.h b/audio/audio_int.h
index 2a6914d2aa..97e20e8429 100644
--- a/audio/audio_int.h
+++ b/audio/audio_int.h
@@ -263,6 +263,8 @@ typedef struct RateCtl {
} RateCtl;
void audio_rate_start(RateCtl *rate);
+size_t audio_rate_peek_bytes(RateCtl *rate, struct audio_pcm_info *info);
+void audio_rate_add_bytes(RateCtl *rate, size_t bytes_used);
size_t audio_rate_get_bytes(struct audio_pcm_info *info, RateCtl *rate,
size_t bytes_avail);
--
2.35.3
- [PATCH 00/12] audio: misc. improvements and bug fixes, Volker Rümelin, 2022/09/23
- [PATCH 02/12] audio: fix GUS audio playback with out.mixing-engine=off, Volker Rümelin, 2022/09/23
- [PATCH 01/12] audio: refactor code in audio_run_out(), Volker Rümelin, 2022/09/23
- [PATCH 05/12] audio: add more audio rate control functions,
Volker Rümelin <=
- [PATCH 03/12] audio: run downstream playback queue unconditionally, Volker Rümelin, 2022/09/23
- [PATCH 11/12] audio: fix sw->buf size for audio recording, Volker Rümelin, 2022/09/23
- [PATCH 10/12] audio: refactor audio_get_avail(), Volker Rümelin, 2022/09/23
- [PATCH 04/12] alsaaudio: reduce playback latency, Volker Rümelin, 2022/09/23
- [PATCH 12/12] audio: prevent an integer overflow in resampling code, Volker Rümelin, 2022/09/23