[alsa-devel] Problems with safe API and snd-cs46xx

Takashi Iwai tiwai at suse.de
Wed Sep 9 13:04:08 CEST 2009


At Tue, 08 Sep 2009 10:53:39 +0200,
I wrote:
> 
> At Tue, 8 Sep 2009 08:46:36 +0100,
> Sophie Hamilton wrote:
> > 
> > On 9/8/09, Takashi Iwai <tiwai at suse.de> wrote:
> > >  Sophie, what happens if you use the patch without your change?
> > 
> > Same thing as before, it seems; it doesn't seem to make any
> > difference. I tested all the use cases I tested beforehand and none
> > were any different.
> 
> OK, interesting.  I'd need to check deeply inside.

It turned out that the hw_params determination is done rather inside
the alsa-lib beforehand.

Try the patch below.  This will give you larger buffer size with
audacious.  (And it will work without the driver changes.)

For any apps that require the old behavior, I added the check of
$LIBASOUND_COMPAT variable.


Takashi

---
diff --git a/src/pcm/pcm_params.c b/src/pcm/pcm_params.c
index 80b3fd2..0e1c3fc 100644
--- a/src/pcm/pcm_params.c
+++ b/src/pcm/pcm_params.c
@@ -1081,6 +1081,7 @@ int snd_pcm_hw_param_never_eq(const snd_pcm_hw_params_t *params,
 static int snd_pcm_hw_params_choose(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
 {
 	int err;
+	const char *compat = getenv("LIBASOUND_COMPAT");
 #ifdef CHOOSE_DEBUG
 	snd_output_t *log;
 	snd_output_stdio_attach(&log, stderr, 0);
@@ -1103,15 +1104,29 @@ static int snd_pcm_hw_params_choose(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
 	err = snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_RATE, NULL, 0);
 	if (err < 0)
 		return err;
-	err = snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_PERIOD_TIME, NULL, 0);
-	if (err < 0)
-		return err;
-	err = snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_PERIOD_SIZE, NULL, 0);
-	if (err < 0)
-		return err;
-	err = snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_BUFFER_SIZE, NULL, 0);
-	if (err < 0)
-		return err;
+	if (compat && *compat) {
+		/* old mode */
+		err = snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_PERIOD_TIME, NULL, 0);
+		if (err < 0)
+			return err;
+		err = snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_PERIOD_SIZE, NULL, 0);
+		if (err < 0)
+			return err;
+		err = snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_BUFFER_SIZE, NULL, 0);
+		if (err < 0)
+			return err;
+	} else {
+		/* determine buffer size first */
+		err = snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_BUFFER_SIZE, NULL, 0);
+		if (err < 0)
+			return err;
+		err = snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_PERIOD_SIZE, NULL, 0);
+		if (err < 0)
+			return err;
+		err = snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_PERIOD_TIME, NULL, 0);
+		if (err < 0)
+			return err;
+	}
 	err = snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_TICK_TIME, NULL, 0);
 	if (err < 0)
 		return err;


More information about the Alsa-devel mailing list