Skip to contentSkip to conversation

bat: Fix buffer time configuration

PATCH In review Alexander Stein 2 participants 3 messages Apr 10, 2025 – May 16, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bat: Fix buffer time configuration

By swapping time configuration some hardware constraints can be supported. Fixes the error: Set parameter to device error: buffer time: 500000 hw:tqmtlv320aic32: Invalid argument(-22)

---
Our common 'alsabat -Dhw:tqmtlv320aic32 -f S16_LE -c 2 -r 44100 -F 997:500' failed ona i.MX95 based platform, while it worked flawlessly on others, e.g. i.MX8M Plus. Upon searching I stumbled across [1], which this patch is inspired/based on.

[1] https://github.com/arkq/bluez-alsa/pull/290/commits/da78b82ff77310093b4b4a914d31e69b8ebb49eb

---
 bat/alsa.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
bat/alsa.c +9 -9
index 67489c4..457e79a 100644
@@ -221,23 +221,23 @@ static int set_snd_pcm_params(struct bat *bat, struct pcm_container *sndpcm)
 
 		period_time = buffer_time / DIV_BUFFERTIME;
 
-		/* Set buffer time and period time */
-		err = snd_pcm_hw_params_set_buffer_time_near(sndpcm->handle,
-				params, &buffer_time, 0);
+		/* Set period time and buffer time */
+		err = snd_pcm_hw_params_set_period_time_near(sndpcm->handle,
+			params, &period_time, 0);
 		if (err < 0) {
 			fprintf(bat->err, _("Set parameter to device error: "));
-			fprintf(bat->err, _("buffer time: %d %s: %s(%d)\n"),
-					buffer_time,
+			fprintf(bat->err, _("period time: %d %s: %s(%d)\n"),
+					period_time,
 					device_name, snd_strerror(err), err);
 			return err;
 		}
 
-		err = snd_pcm_hw_params_set_period_time_near(sndpcm->handle,
-				params, &period_time, 0);
+		err = snd_pcm_hw_params_set_buffer_time_near(sndpcm->handle,
+				params, &buffer_time, 0);
 		if (err < 0) {
 			fprintf(bat->err, _("Set parameter to device error: "));
-			fprintf(bat->err, _("period time: %d %s: %s(%d)\n"),
-					period_time,
+			fprintf(bat->err, _("buffer time: %d %s: %s(%d)\n"),
+					buffer_time,
 					device_name, snd_strerror(err), err);
 			return err;
 		}
Signature · 1 line
2.43.0
#1 lore raw

Hi,

Am Donnerstag, 10. April 2025, 13:01:19 CEST schrieb Alexander Stein:

Quoted 5 lines

By swapping time configuration some hardware constraints can be supported. Fixes the error: Set parameter to device error: buffer time: 500000 hw:tqmtlv320aic32: Invalid argument(-22)

Any feedback here? Or should I create a PR on github instead?

Thanks and best regards
Alexander

Quoted 49 lines

---
Our common 'alsabat -Dhw:tqmtlv320aic32 -f S16_LE -c 2 -r 44100 -F 997:500' failed ona i.MX95 based platform, while it worked flawlessly on others, e.g. i.MX8M Plus. Upon searching I stumbled across [1], which this patch is inspired/based on.

[1] https://github.com/arkq/bluez-alsa/pull/290/commits/da78b82ff77310093b4b4a914d31e69b8ebb49eb

---
 bat/alsa.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
bat/alsa.c +9 -9
index 67489c4..457e79a 100644
@@ -221,23 +221,23 @@ static int set_snd_pcm_params(struct bat *bat, struct pcm_container *sndpcm)
 
 		period_time = buffer_time / DIV_BUFFERTIME;
 
-		/* Set buffer time and period time */
-		err = snd_pcm_hw_params_set_buffer_time_near(sndpcm->handle,
-				params, &buffer_time, 0);
+		/* Set period time and buffer time */
+		err = snd_pcm_hw_params_set_period_time_near(sndpcm->handle,
+			params, &period_time, 0);
 		if (err < 0) {
 			fprintf(bat->err, _("Set parameter to device error: "));
-			fprintf(bat->err, _("buffer time: %d %s: %s(%d)\n"),
-					buffer_time,
+			fprintf(bat->err, _("period time: %d %s: %s(%d)\n"),
+					period_time,
 					device_name, snd_strerror(err), err);
 			return err;
 		}
 
-		err = snd_pcm_hw_params_set_period_time_near(sndpcm->handle,
-				params, &period_time, 0);
+		err = snd_pcm_hw_params_set_buffer_time_near(sndpcm->handle,
+				params, &buffer_time, 0);
 		if (err < 0) {
 			fprintf(bat->err, _("Set parameter to device error: "));
-			fprintf(bat->err, _("period time: %d %s: %s(%d)\n"),
-					period_time,
+			fprintf(bat->err, _("buffer time: %d %s: %s(%d)\n"),
+					buffer_time,
 					device_name, snd_strerror(err), err);
 			return err;
 		}
Signature · 4 lines
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
http://www.tq-group.com/
#2 lore raw
Quoted 11 lines · Alexander Stein

Hi,

Am Donnerstag, 10. April 2025, 13:01:19 CEST schrieb Alexander Stein:

Quoted 5 lines

By swapping time configuration some hardware constraints can be supported. Fixes the error: Set parameter to device error: buffer time: 500000 hw:tqmtlv320aic32: Invalid argument(-22)

Any feedback here? Or should I create a PR on github instead?

Sorry, it was just overlooked.
Now applied the patch. Thanks!

Takashi