Hi

I decided to try to find out what the problems I've been having with my
ALSA setup were myself, and I used the ALSA howto and wrote a small test
program (attached).

The strange thing is that when I set the rate to 48000 I get 
"Error setting HW params. Invalid argument."
I can set the rate to anything else, but not 48000.

Any ideas why? 

I've got alsa-lib from CVS, alsa compiled into 2.6.0-test4 kernel (I
would use alsa driver from CVS, but I'm not sure how to build it with
the new 2.6 kernels. Do I just copy the alsa-kernel stuff directly into
the 2.6 tree?), and an Extigy card.

I've attached my .asoundrc file as well, just in case its setup wrongly.

iain
-- 
"Miss Celine Dion sings lovesongs while our cities burn"
pcm.extigy {
        type hw
        card 0
}

pcm.realex {
        type plug
        slave {
                pcm extigy
        }
        route_policy default
}

ctl.extigy {
        type hw
        card 0
}

pcm.emu10k1 {
        type hw
        card 1
}

ctl.emu10k1 {
        type hw
        card 1
}
#include <alsa/asoundlib.h>

int
main (int argc,
      char *argv[])
{
	snd_pcm_t *pcm_handle;

	snd_pcm_stream_t stream = SND_PCM_STREAM_PLAYBACK;

	snd_pcm_hw_params_t *hwparams;

	char *pcm_name;

	int rate = atoi (argv[1]);
	int exact_rate;
	int dir;
	int periods = 2;
	int periodsize = 8192;
	snd_pcm_uframes_t buffer_frames = (periods * periodsize) >> 2;
	int frames;
	int ret;
	
	unsigned char *data;
	
	pcm_name = strdup ("plug:extigy");

	snd_pcm_hw_params_alloca (&hwparams);

	if (snd_pcm_open (&pcm_handle, pcm_name, stream, 0) < 0) {
		fprintf (stderr, "Error opening PCM device %s\n", pcm_name);
		return -1;
	}

	if (snd_pcm_hw_params_any (pcm_handle, hwparams) < 0) {
		fprintf (stderr, "Cannot configure this PCM device.\n");
		return -1;
	}

	if (snd_pcm_hw_params_set_access (pcm_handle, hwparams,
					  SND_PCM_ACCESS_RW_INTERLEAVED) < 0) {
		fprintf (stderr, "Error setting access\n");
		return -1;
	}

	if (snd_pcm_hw_params_set_format (pcm_handle, hwparams, SND_PCM_FORMAT_S16_LE) < 0) {
		fprintf (stderr, "Error setting format.\n");
		return -1;
	}

	exact_rate = snd_pcm_hw_params_set_rate_near (pcm_handle, hwparams,
						      rate, &dir);
	if (dir != 0) {
		fprintf (stderr, "The rate %d Hz is not supported by the hardware.\n"
			 "==> Using %d Hz instead.\n", rate, exact_rate);
	}

	if (snd_pcm_hw_params_set_channels (pcm_handle, hwparams, 2) < 0) {
		fprintf (stderr, "Error setting channels.\n");
		return -1;
	}

	if (snd_pcm_hw_params_set_periods_near (pcm_handle, hwparams, periods, 0) < 0) {
		fprintf (stderr, "Error setting periods.\n");
		return -1;
	}

	if (snd_pcm_hw_params_set_buffer_size_near (pcm_handle, hwparams,
						    buffer_frames) < 0) {
		fprintf (stderr, "Error setting buffersize %d.\n", (periodsize * periods) >> 2);
		return -1;
	}

	ret = snd_pcm_hw_params (pcm_handle, hwparams);
	if (ret < 0) {
		fprintf (stderr, "Error setting HW params.\n%s.\n",
			 snd_strerror (ret));
		return -1;
	}

	data = (unsigned char *) malloc (periodsize);
	frames = periodsize >> 2;
	
	while (1) {
		int pcmreturn, l1, l2;
		short s1, s2;

		for (l1 = 0; l1 < 100; l1++) {
			for (l2 = 0; l2 < frames; l2++) {
				s1 = (l2 % 128) * 100 - 5000;
				s2 = (l2 % 256) * !00 - 5000;

				data[4*l2] = (unsigned char) s1;
				data[4*l2+1] = s1 >> 8;
				data[4*l2+2] = (unsigned char) s2;
				data[4*l2+3] = s2 >> 8;
			}

			while ((pcmreturn = snd_pcm_writei (pcm_handle, data,
							    frames)) < 0) {
				snd_pcm_prepare (pcm_handle);
				fprintf (stderr, "<<<<<<< Buffer Underrun >>>>>>\n");
			}
		}
	}
}
		

Reply via email to