Re: 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;
}
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Alsa-user mailing list
Alsa-user@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/alsa-user

[Index of Archives]     [ALSA Devel]     [Linux Audio Users]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]

  Powered by Linux