Skip to content

Commit 6bb7366

Browse files
committed
libcanberra: Fix sound not playing on Colibri iMX8X
Canberra does not specify a buffer size, which leads to ALSA rejecting the settings. By specfiying a buffer time of 500ms and a period time with a fourth of that, an appropriate buffer size can be calculated. This behaviour is mimicked from aplay for compatibility. Signed-off-by: Patrick Zacharias <[email protected]>
1 parent 01dd622 commit 6bb7366

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
From 86488a7fc209ac08dd92c9d50a77e3330e7aedd9 Mon Sep 17 00:00:00 2001
2+
From: Patrick Zacharias <[email protected]>
3+
Date: Thu, 7 Nov 2024 14:03:29 +0100
4+
Subject: [PATCH] Determine audio buffer size for a time of 500ms
5+
6+
On some hardware like the SGTL5000, not specifying a buffer size
7+
results to EINVAL being returned.
8+
9+
This code sets the buffer time to 500ms and the period time to a fourth of that,
10+
or whatever is nearest to that.
11+
---
12+
src/alsa.c | 15 +++++++++++++++
13+
1 file changed, 15 insertions(+)
14+
15+
diff --git a/src/alsa.c b/src/alsa.c
16+
index bebcc4a..ac26578 100644
17+
--- a/src/alsa.c
18+
+++ b/src/alsa.c
19+
@@ -258,6 +258,21 @@ static int open_alsa(ca_context *c, struct outstanding *out) {
20+
if ((ret = snd_pcm_hw_params_set_channels(out->pcm, hwparams, ca_sound_file_get_nchannels(out->file))) < 0)
21+
goto finish;
22+
23+
+ unsigned int buffer_time = 0;
24+
+ if ((ret = snd_pcm_hw_params_get_buffer_time_max(hwparams, &buffer_time, 0)) < 0)
25+
+ goto finish;
26+
+
27+
+ // Cap the buffer time to 500ms
28+
+ if (buffer_time > 500000)
29+
+ buffer_time = 500000;
30+
+
31+
+ unsigned int period_time = buffer_time / 4;
32+
+ if ((ret = snd_pcm_hw_params_set_period_time_near(out->pcm, hwparams, &period_time, 0)) < 0)
33+
+ goto finish;
34+
+
35+
+ if ((ret = snd_pcm_hw_params_set_buffer_time_near(out->pcm, hwparams, &buffer_time, 0)) < 0)
36+
+ goto finish;
37+
+
38+
if ((ret = snd_pcm_hw_params(out->pcm, hwparams)) < 0)
39+
goto finish;
40+

meta-oe/recipes-support/libcanberra/libcanberra_0.30.bb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ SRC_URI = " \
1313
file://0001-build-gtk-and-gtk3-version-for-canberra_gtk_play.patch \
1414
file://0001-gtk-Don-t-assume-all-GdkDisplays-are-GdkX11Displays-.patch \
1515
file://0001-remove-dropped-templates.patch \
16+
file://0001-Determine-audio-buffer-size-for-a-time-of-500ms.patch \
1617
"
1718
SRC_URI[md5sum] = "34cb7e4430afaf6f447c4ebdb9b42072"
1819
SRC_URI[sha256sum] = "c2b671e67e0c288a69fc33dc1b6f1b534d07882c2aceed37004bf48c601afa72"

0 commit comments

Comments
 (0)