diff mbox series

[v2,11/11] alsaaudio: reintroduce default recording settings

Message ID 20230121094735.11644-11-vr_qemu@t-online.de (mailing list archive)
State New, archived
Headers show
Series audio: more improvements | expand

Commit Message

Volker Rümelin Jan. 21, 2023, 9:47 a.m. UTC
Audio recording with ALSA default settings currently doesn't
work. The debug log shows updates every 0.75s and 1.5s.

audio: Elapsed since last alsa run (running): 0.743030
audio: Elapsed since last alsa run (running): 1.486048
audio: Elapsed since last alsa run (running): 0.743008
audio: Elapsed since last alsa run (running): 1.485878
audio: Elapsed since last alsa run (running): 1.486040
audio: Elapsed since last alsa run (running): 1.485886

The time between updates should be in the 10ms range. Audio
recording with ALSA has the same timing contraints as playback.
Reintroduce the default recording settings and use the same
default settings for recording as for playback.

The term "reintroduce" is correct because commit a93f328177
("alsaaudio: port to -audiodev config") removed the default
settings for recording.

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

Comments

Philippe Mathieu-Daudé Jan. 23, 2023, 7:44 a.m. UTC | #1
On 21/1/23 10:47, Volker Rümelin wrote:
> Audio recording with ALSA default settings currently doesn't
> work. The debug log shows updates every 0.75s and 1.5s.
> 
> audio: Elapsed since last alsa run (running): 0.743030
> audio: Elapsed since last alsa run (running): 1.486048
> audio: Elapsed since last alsa run (running): 0.743008
> audio: Elapsed since last alsa run (running): 1.485878
> audio: Elapsed since last alsa run (running): 1.486040
> audio: Elapsed since last alsa run (running): 1.485886
> 
> The time between updates should be in the 10ms range. Audio
> recording with ALSA has the same timing contraints as playback.
> Reintroduce the default recording settings and use the same
> default settings for recording as for playback.
> 
> The term "reintroduce" is correct because commit a93f328177
> ("alsaaudio: port to -audiodev config") removed the default
> settings for recording.
> 
> Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
> ---
>   audio/alsaaudio.c | 10 ++++------
>   1 file changed, 4 insertions(+), 6 deletions(-)

> -    /*
> -     * OptsVisitor sets unspecified optional fields to zero, but do not depend
> -     * on it...
> -     */
>       if (!dev->u.alsa.in->has_period_length) {
> -        dev->u.alsa.in->period_length = 0;
> +        /* 256 frames assuming 44100Hz */
> +        dev->u.alsa.in->period_length = 5805;
>       }
>       if (!dev->u.alsa.in->has_buffer_length) {
> -        dev->u.alsa.in->buffer_length = 0;
> +        /* 4096 frames assuming 44100Hz */
> +        dev->u.alsa.in->buffer_length = 92880;
>       }

Please use DIV_ROUND_UP(). Maybe worth adding definitions?
diff mbox series

Patch

diff --git a/audio/alsaaudio.c b/audio/alsaaudio.c
index 0cc982e61f..057571dd1e 100644
--- a/audio/alsaaudio.c
+++ b/audio/alsaaudio.c
@@ -923,15 +923,13 @@  static void *alsa_audio_init(Audiodev *dev)
         dev->u.alsa.out->buffer_length = 92880;
     }
 
-    /*
-     * OptsVisitor sets unspecified optional fields to zero, but do not depend
-     * on it...
-     */
     if (!dev->u.alsa.in->has_period_length) {
-        dev->u.alsa.in->period_length = 0;
+        /* 256 frames assuming 44100Hz */
+        dev->u.alsa.in->period_length = 5805;
     }
     if (!dev->u.alsa.in->has_buffer_length) {
-        dev->u.alsa.in->buffer_length = 0;
+        /* 4096 frames assuming 44100Hz */
+        dev->u.alsa.in->buffer_length = 92880;
     }
 
     return dev;