[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 13/17] audio/mixeng: calculate number of output frames
From: |
Volker Rümelin |
Subject: |
[PATCH 13/17] audio/mixeng: calculate number of output frames |
Date: |
Sun, 15 Jan 2023 14:12:20 +0100 |
From: Volker Rümelin <vr_qemu@t-online.de>
Calculate the exact number of audio output frames the resampling
code can generate from a given number of audio input frames.
When upsampling, this function returns the maximum number of
output frames.
This function will later replace the audio_frontend_frames_in()
function, which calculates the average number of output frames
rounded down to the nearest integer.
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
---
audio/mixeng.c | 37 +++++++++++++++++++++++++++++++++++++
audio/mixeng.h | 1 +
2 files changed, 38 insertions(+)
diff --git a/audio/mixeng.c b/audio/mixeng.c
index 6bb3d54f77..92a3a1ac58 100644
--- a/audio/mixeng.c
+++ b/audio/mixeng.c
@@ -440,6 +440,43 @@ void st_rate_stop (void *opaque)
g_free (opaque);
}
+/**
+ * st_rate_frames_out() - returns the number of frames the resampling code
+ * generates from frames_in frames
+ *
+ * @opaque: pointer to struct rate
+ * @frames_in: number of frames
+ */
+uint32_t st_rate_frames_out(void *opaque, uint32_t frames_in)
+{
+ struct rate *rate = opaque;
+ uint64_t opos_end, opos_delta;
+ uint32_t ipos_end;
+ uint32_t frames_out;
+
+ if (rate->opos_inc == 1ULL << 32) {
+ return frames_in;
+ }
+
+ /* no output frame without at least one input frame */
+ if (!frames_in) {
+ return 0;
+ }
+
+ /* last frame read was at rate->ipos - 1 */
+ ipos_end = rate->ipos - 1 + frames_in;
+ opos_end = (uint64_t)ipos_end << 32;
+
+ /* last frame written was at rate->opos - rate->opos_inc */
+ if (opos_end + rate->opos_inc <= rate->opos) {
+ return 0;
+ }
+ opos_delta = opos_end - rate->opos + rate->opos_inc;
+ frames_out = opos_delta / rate->opos_inc;
+
+ return opos_delta % rate->opos_inc ? frames_out : frames_out - 1;
+}
+
/**
* st_rate_frames_in() - returns the number of frames needed to
* get frames_out frames after resampling
diff --git a/audio/mixeng.h b/audio/mixeng.h
index 64c1e231cc..f9de7cffeb 100644
--- a/audio/mixeng.h
+++ b/audio/mixeng.h
@@ -52,6 +52,7 @@ void st_rate_flow(void *opaque, st_sample *ibuf, st_sample
*obuf,
void st_rate_flow_mix(void *opaque, st_sample *ibuf, st_sample *obuf,
size_t *isamp, size_t *osamp);
void st_rate_stop (void *opaque);
+uint32_t st_rate_frames_out(void *opaque, uint32_t frames_in);
uint32_t st_rate_frames_in(void *opaque, uint32_t frames_out);
void mixeng_clear (struct st_sample *buf, int len);
void mixeng_volume (struct st_sample *buf, int len, struct mixeng_volume *vol);
--
2.35.3
- [PATCH 05/17] audio: remove sw == NULL check, (continued)
- [PATCH 05/17] audio: remove sw == NULL check, Volker Rümelin, 2023/01/15
- [PATCH 07/17] audio: don't misuse audio_pcm_sw_write(), Volker Rümelin, 2023/01/15
- [PATCH 06/17] audio: rename variables in audio_pcm_sw_write(), Volker Rümelin, 2023/01/15
- [PATCH 08/17] audio: remove unused noop_conv() function, Volker Rümelin, 2023/01/15
- [PATCH 09/17] audio/mixeng: calculate number of input frames, Volker Rümelin, 2023/01/15
- [PATCH 10/17] audio: wire up st_rate_frames_in(), Volker Rümelin, 2023/01/15
- [PATCH 11/17] audio: replace the resampling loop in audio_pcm_sw_read(), Volker Rümelin, 2023/01/15
- [PATCH 12/17] audio: rename variables in audio_pcm_sw_read(), Volker Rümelin, 2023/01/15
- [PATCH 14/17] audio: wire up st_rate_frames_out(), Volker Rümelin, 2023/01/15
- [PATCH 16/17] audio/audio_template: substitute sw->hw with hw, Volker Rümelin, 2023/01/15
- [PATCH 13/17] audio/mixeng: calculate number of output frames,
Volker Rümelin <=
- [PATCH 15/17] audio: handle leftover audio frame from upsampling, Volker Rümelin, 2023/01/15
- [PATCH 17/17] audio: remove sw->ratio, Volker Rümelin, 2023/01/15
- Re: [PATCH 00/17] audio: improve callback interface for audio frontends, Volker Rümelin, 2023/01/15
- Re: [PATCH 00/17] audio: improve callback interface for audio frontends, Marc-André Lureau, 2023/01/31