[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 15/27] audio: make the resampling code greedy
From: |
marcandre . lureau |
Subject: |
[PULL 15/27] audio: make the resampling code greedy |
Date: |
Mon, 6 Mar 2023 10:51:50 +0400 |
From: Volker Rümelin <vr_qemu@t-online.de>
Read the maximum possible number of audio frames instead of the
minimum necessary number of frames when the audio stream is
downsampled and the output buffer is limited. This makes the
function symmetrical to upsampling when the input buffer is
limited. The maximum possible number of frames is written here.
With this change it's easier to calculate the exact number of
audio frames the resample function will read or write. These two
functions will be introduced later.
Acked-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20230224190555.7409-3-vr_qemu@t-online.de>
---
audio/rate_template.h | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/audio/rate_template.h b/audio/rate_template.h
index b432719ebb..6648f0d2e5 100644
--- a/audio/rate_template.h
+++ b/audio/rate_template.h
@@ -40,8 +40,6 @@ void NAME (void *opaque, struct st_sample *ibuf, struct
st_sample *obuf,
int64_t t;
#endif
- ilast = rate->ilast;
-
istart = ibuf;
iend = ibuf + *isamp;
@@ -59,15 +57,17 @@ void NAME (void *opaque, struct st_sample *ibuf, struct
st_sample *obuf,
return;
}
- while (obuf < oend) {
+ /* without input samples, there's nothing to do */
+ if (ibuf >= iend) {
+ *osamp = 0;
+ return;
+ }
- /* Safety catch to make sure we have input samples. */
- if (ibuf >= iend) {
- break;
- }
+ ilast = rate->ilast;
- /* read as many input samples so that ipos > opos */
+ while (true) {
+ /* read as many input samples so that ipos > opos */
while (rate->ipos <= (rate->opos >> 32)) {
ilast = *ibuf++;
rate->ipos++;
@@ -78,6 +78,11 @@ void NAME (void *opaque, struct st_sample *ibuf, struct
st_sample *obuf,
}
}
+ /* make sure that the next output sample can be written */
+ if (obuf >= oend) {
+ break;
+ }
+
icur = *ibuf;
/* wrap ipos and opos around long before they overflow */
--
2.39.2
- [PULL 05/27] audio: remove unused #define AUDIO_STRINGIFY, (continued)
- [PULL 05/27] audio: remove unused #define AUDIO_STRINGIFY, marcandre . lureau, 2023/03/06
- [PULL 06/27] audio/mixeng: use g_new0() instead of audio_calloc(), marcandre . lureau, 2023/03/06
- [PULL 09/27] audio/audio_template: use g_new0() to replace audio_calloc(), marcandre . lureau, 2023/03/06
- [PULL 07/27] audio/alsaaudio: use g_new0() instead of audio_calloc(), marcandre . lureau, 2023/03/06
- [PULL 10/27] audio: remove audio_calloc() function, marcandre . lureau, 2023/03/06
- [PULL 08/27] audio/audio_template: use g_malloc0() to replace audio_calloc(), marcandre . lureau, 2023/03/06
- [PULL 11/27] alsaaudio: change default playback settings, marcandre . lureau, 2023/03/06
- [PULL 12/27] alsaaudio: reintroduce default recording settings, marcandre . lureau, 2023/03/06
- [PULL 13/27] audio: change type of mix_buf and conv_buf, marcandre . lureau, 2023/03/06
- [PULL 14/27] audio: change type and name of the resample buffer, marcandre . lureau, 2023/03/06
- [PULL 15/27] audio: make the resampling code greedy,
marcandre . lureau <=
- [PULL 16/27] audio: replace the resampling loop in audio_pcm_sw_write(), marcandre . lureau, 2023/03/06
- [PULL 17/27] audio: remove sw == NULL check, marcandre . lureau, 2023/03/06
- [PULL 18/27] audio: rename variables in audio_pcm_sw_write(), marcandre . lureau, 2023/03/06
- [PULL 19/27] audio: don't misuse audio_pcm_sw_write(), marcandre . lureau, 2023/03/06
- [PULL 20/27] audio: remove unused noop_conv() function, marcandre . lureau, 2023/03/06
- [PULL 22/27] audio: replace the resampling loop in audio_pcm_sw_read(), marcandre . lureau, 2023/03/06
- [PULL 21/27] audio: make playback packet length calculation exact, marcandre . lureau, 2023/03/06
- [PULL 23/27] audio: rename variables in audio_pcm_sw_read(), marcandre . lureau, 2023/03/06
- [PULL 24/27] audio: make recording packet length calculation exact, marcandre . lureau, 2023/03/06
- [PULL 25/27] audio: handle leftover audio frame from upsampling, marcandre . lureau, 2023/03/06