[Alsa-devel] card_id() in initval.h

2003-12-23 Thread Andre Batista de Oliveira
I'm facing some problems passing the ALSA drivers'
parameters from the kernel command line.

When I try to specify the ID string for the card
(snd-sgalaxy=1,0,Waverider,0x220,0x530,10,3),
the kernel just reboots immediately, even before printing anything!

But when I leave the ID string unspecified
(snd-sgalaxy=1,0,,0x220,0x530,10,3), it boots and works fine,
and the card gets the default Galaxy ID.

I believe this has something to do with the kmalloc() call
in the get_id() function in the initval.h include file.
Perhaps kmalloc() can not be used at this early boot stage?!?
I fixed it by replacing kmalloc() with alloc_bootmem(),
and now it works, but there's probably a better way to do it!

Does this make any sense? Is this a known bug? Is this a bug, at all?
Thanks.

Here's the diff:

--- initval.h.orig  Tue Dec 23 16:56:26 2003
+++ initval.h   Tue Dec 23 18:00:10 2003
@@ -136,25 +136,23 @@
 #if defined(SNDRV_GET_ID)  !defined(MODULE)
 #include linux/ctype.h
 #include linux/init.h
+#include linux/bootmem.h
 static int __init get_id(char **str, char **dst)
 {
-   char *s, *d;
+   char *s;
 
if (!(*str) || !(**str))
return 0;
for (s = *str; isalpha(*s) || isdigit(*s) || *s == '_'; s++);
if (s != *str) {
-   *dst = (char *)kmalloc((s - *str) + 1, GFP_KERNEL);
-   s = *str; d = *dst;
-   while (isalpha(*s) || isdigit(*s) || *s == '_') {
-   if (d != NULL)
-   *d++ = *s;
-   s++;
-   }
-   if (d != NULL)
+   char *d = alloc_bootmem(s - *str + 1);
+   if (d != NULL) {
+   *dst = d;
+   while (s != *str) *d++ = *(*str)++;
*d = '\0';
+   } else
+   *str = s;
}
-   *str = s;
if (*s == ',') {
(*str)++;
return 2;



-- 
André Batista de Oliveira
http://mega.ist.utl.pt/~abo


---
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id78alloc_id371op=click
___
Alsa-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/alsa-devel


[Alsa-devel] pcm_plug.c:882: snd_pcm_plug_hw_params: Assertion `err = 0' failed.

2003-12-23 Thread Glenn Maynard
The attached program results in:

./a.out
a.out: pcm_plug.c:882: snd_pcm_plug_hw_params: Assertion `err = 0' failed.
zsh: 22948 abort  ./a.out

This is with CVS alsa-utils (and 0.9.6 or 0.9.8), whatever is in 2.6.0 test9,
and an SBLive.  It goes away if the sample rate block is uncommented.

This only seems to happen with the plug device; it works fine with hw:0.
It also goes away if I don't specify a buffer size (which is why I havn't
seen this problem until now).

(What I'm really doing is setting up the subdevice on initialization,
and then when a sound really starts playing, I reconfigure it to the
sample rate of the sound.  This works very well in Windows: it lets the
drivers resample, possibly in hardware, so I don't have to--the resampling
code I'm using is too slow.  I havn't tested it as thoroughly in ALSA,
but it seems to work.)

-- 
Glenn Maynard
#define ALSA_PCM_NEW_HW_PARAMS_API
#define ALSA_PCM_NEW_SW_PARAMS_API
#include alsa/asoundlib.h

#define ALSA_CHECK(x) \
   if ( err  0 ) { printf(ALSA9: %s: %s\n, x, snd_strerror(err)); return false; }


main()
{
	/* Open the device. */
	int err;
	snd_pcm_t *pcm;
	err = snd_pcm_open( pcm, default, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK );
	assert( err = 0 );

	/* allocate the hardware parameters structure */
	snd_pcm_hw_params_t *hwparams;
	snd_pcm_hw_params_alloca( hwparams );

	err = snd_pcm_hw_params_any(pcm, hwparams);
	ALSA_CHECK(snd_pcm_hw_params_any);

	/* set to mmap mode (with channels interleaved) */
	err = snd_pcm_hw_params_set_access(pcm, hwparams, SND_PCM_ACCESS_MMAP_INTERLEAVED);
	ALSA_CHECK(snd_pcm_hw_params_set_access);

	/* set PCM format (signed 16bit, little endian) */
	err = snd_pcm_hw_params_set_format(pcm, hwparams, SND_PCM_FORMAT_S16_LE);
	ALSA_CHECK(snd_pcm_hw_params_set_format);

	/* set number of channels */
	err = snd_pcm_hw_params_set_channels(pcm, hwparams, 2);
	ALSA_CHECK(snd_pcm_hw_params_set_channels);

//	unsigned int rate = samplerate;
//	err = snd_pcm_hw_params_set_rate_near(pcm, hwparams, rate, 0);
//	ALSA_CHECK(snd_pcm_hw_params_set_rate_near);

	snd_pcm_uframes_t periodsize = 1024*32;
	err = snd_pcm_hw_params_set_buffer_size_near( pcm, hwparams, periodsize );
	ALSA_CHECK(snd_pcm_hw_params_set_buffer_size_near);

	/* write the hardware parameters to the device */
	err = snd_pcm_hw_params( pcm, hwparams );
	ALSA_CHECK(snd_pcm_hw_params);
}