Re: [Alsa-user] How to get set/fixed sample rate of ALSA device?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10/08/2007 12:41 AM, Mark Constable wrote:

Any chance that your program could take an arg to investigate
other cards (or perhaps plugins) and also return an errno so
it could be used in scripts ?

Only if you promise to never drop CCs again (although I don't know about plugins).

 # gcc -W -Wall -o snd_rate snd_rate.c -l asound
 snd_rate.c: In function 'main':
 snd_rate.c:14: warning: the address of ‘params’ will always evaluate as 'true'

That's the ALSA snd_pcm_hw_params_alloca(). No such warning here, but I've made it a regular malloc.

 # snd_rate
 snd_pcm_open: Device or resource busy

In fact, why isn't there a single simple "alsainfo" type
program that tells a user some (or a lot) of info about
their hardware and alsa-lib install ?

I guess because noone wrote one :-)

It seems by the way that dir != 0 _can_ be returned for hw devices, and this just ignores it. Just some rounding issue I guess.

Rene.

/* gcc -W -Wall -o alsa-rate alsa-rate.c -lasound */

#include <stdio.h>
#include <alsa/asoundlib.h>

int main(int argc, char *argv[])
{
	char *device;
	snd_pcm_t *handle;
	snd_pcm_hw_params_t *params;
	unsigned int min;
	unsigned int max;
	int dir;
	int err;

	device = argc > 1 ? argv[1] : "hw:0,0";

	err = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, 0);
	if (err < 0) {
		fprintf(stderr, "snd_pcm_open: %s\n", snd_strerror(err));
		return err;
	}
	err = snd_pcm_hw_params_malloc(&params);
	if (err < 0) {
		fprintf(stderr, "snd_pcm_hw_params_alloc: %s\n",
			snd_strerror(err));
		return err;
	}
	err = snd_pcm_hw_params_any(handle, params);
	if (err < 0) {
		fprintf(stderr, "snd_pcm_hw_params_any: %s\n",
			snd_strerror(err));
		return err;
	}
	err = snd_pcm_close(handle);
	if (err < 0) {
		fprintf(stderr, "snd_pcm_close: %s\n", snd_strerror(err));
		return err;
	}
	err = snd_pcm_hw_params_get_rate_min(params, &min, &dir);
	if (err < 0) {
		fprintf(stderr, "snd_pcm_hw_params_get_rate_min: %s\n",
			snd_strerror(err));
		return err;
	}
	err = snd_pcm_hw_params_get_rate_max(params, &max, &dir);
	if (err < 0) {
		fprintf(stderr, "snd_pcm_hw_params_get_rate_max: %s\n",
			snd_strerror(err));
		return err;
	}
	snd_pcm_hw_params_free(params);

	printf("%u-%u\n", min, max);
	return 0;
}
_______________________________________________
Alsa-devel mailing list
Alsa-devel@xxxxxxxxxxxxxxxx
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux