diff mbox series

[09/12] audio: rename audio_sw_bytes_free()

Message ID 20220923183640.8314-9-vr_qemu@t-online.de (mailing list archive)
State New, archived
Headers show
Series audio: misc. improvements and bug fixes | expand

Commit Message

Volker Rümelin Sept. 23, 2022, 6:36 p.m. UTC
Rename and refactor audio_sw_bytes_free(). This function is not
limited to calculate the free audio buffer size. The renamed
function returns the number of frames instead of bytes.

Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
---
 audio/audio.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

Comments

Marc-André Lureau Sept. 27, 2022, 11:54 a.m. UTC | #1
On Fri, Sep 23, 2022 at 10:38 PM Volker Rümelin <vr_qemu@t-online.de> wrote:

> Rename and refactor audio_sw_bytes_free(). This function is not
> limited to calculate the free audio buffer size. The renamed
> function returns the number of frames instead of bytes.
>
> Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>



> ---
>  audio/audio.c | 20 ++++++++++++++------
>  1 file changed, 14 insertions(+), 6 deletions(-)
>
> diff --git a/audio/audio.c b/audio/audio.c
> index 233a86c440..dd66b745e5 100644
> --- a/audio/audio.c
> +++ b/audio/audio.c
> @@ -1010,9 +1010,16 @@ static size_t audio_get_avail (SWVoiceIn *sw)
>      return (((int64_t) live << 32) / sw->ratio) *
> sw->info.bytes_per_frame;
>  }
>
> -static size_t audio_sw_bytes_free(SWVoiceOut *sw, size_t free)
> +/**
> + * audio_frontend_frames_out() - returns the number of frames needed to
> + * get frames_out frames after resampling
> + *
> + * @sw: audio playback frontend
> + * @frames_out: number of frames
> + */
> +static size_t audio_frontend_frames_out(SWVoiceOut *sw, size_t frames_out)
>  {
> -    return (((int64_t)free << 32) / sw->ratio) * sw->info.bytes_per_frame;
> +    return ((int64_t)frames_out << 32) / sw->ratio;
>  }
>
>  static size_t audio_get_free(SWVoiceOut *sw)
> @@ -1034,8 +1041,8 @@ static size_t audio_get_free(SWVoiceOut *sw)
>      dead = sw->hw->mix_buf->size - live;
>
>  #ifdef DEBUG_OUT
> -    dolog("%s: get_free live %zu dead %zu sw_bytes %zu\n",
> -          SW_NAME(sw), live, dead, audio_sw_bytes_free(sw, dead));
> +    dolog("%s: get_free live %zu dead %zu frontend frames %zu\n",
> +          SW_NAME(sw), live, dead, audio_frontend_frames_out(sw, dead));
>  #endif
>
>      return dead;
> @@ -1156,13 +1163,14 @@ static void audio_run_out (AudioState *s)
>                  size_t free;
>
>                  if (hw_free > sw->total_hw_samples_mixed) {
> -                    free = audio_sw_bytes_free(sw,
> +                    free = audio_frontend_frames_out(sw,
>                          MIN(sw_free, hw_free -
> sw->total_hw_samples_mixed));
>                  } else {
>                      free = 0;
>                  }
>                  if (free > 0) {
> -                    sw->callback.fn(sw->callback.opaque, free);
> +                    sw->callback.fn(sw->callback.opaque,
> +                                    free * sw->info.bytes_per_frame);
>                  }
>              }
>          }
> --
> 2.35.3
>
>
>
diff mbox series

Patch

diff --git a/audio/audio.c b/audio/audio.c
index 233a86c440..dd66b745e5 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -1010,9 +1010,16 @@  static size_t audio_get_avail (SWVoiceIn *sw)
     return (((int64_t) live << 32) / sw->ratio) * sw->info.bytes_per_frame;
 }
 
-static size_t audio_sw_bytes_free(SWVoiceOut *sw, size_t free)
+/**
+ * audio_frontend_frames_out() - returns the number of frames needed to
+ * get frames_out frames after resampling
+ *
+ * @sw: audio playback frontend
+ * @frames_out: number of frames
+ */
+static size_t audio_frontend_frames_out(SWVoiceOut *sw, size_t frames_out)
 {
-    return (((int64_t)free << 32) / sw->ratio) * sw->info.bytes_per_frame;
+    return ((int64_t)frames_out << 32) / sw->ratio;
 }
 
 static size_t audio_get_free(SWVoiceOut *sw)
@@ -1034,8 +1041,8 @@  static size_t audio_get_free(SWVoiceOut *sw)
     dead = sw->hw->mix_buf->size - live;
 
 #ifdef DEBUG_OUT
-    dolog("%s: get_free live %zu dead %zu sw_bytes %zu\n",
-          SW_NAME(sw), live, dead, audio_sw_bytes_free(sw, dead));
+    dolog("%s: get_free live %zu dead %zu frontend frames %zu\n",
+          SW_NAME(sw), live, dead, audio_frontend_frames_out(sw, dead));
 #endif
 
     return dead;
@@ -1156,13 +1163,14 @@  static void audio_run_out (AudioState *s)
                 size_t free;
 
                 if (hw_free > sw->total_hw_samples_mixed) {
-                    free = audio_sw_bytes_free(sw,
+                    free = audio_frontend_frames_out(sw,
                         MIN(sw_free, hw_free - sw->total_hw_samples_mixed));
                 } else {
                     free = 0;
                 }
                 if (free > 0) {
-                    sw->callback.fn(sw->callback.opaque, free);
+                    sw->callback.fn(sw->callback.opaque,
+                                    free * sw->info.bytes_per_frame);
                 }
             }
         }