On 10/07/2007 07:04 PM, Peteris Krisjanis wrote:
"Current sample rate" only has meaning with the device open , and if I
understand you right, a "cat
/proc/asound/card0/pcm0{p,c}/sub0/hw_params will then get you what you
want as to the "get" part (substitute for 0 in the above as required).
I actually meant what kind of sample rate is set in sound card. For
example, my onboard sound card has fixed Hz. I would like to know such
information _before_ I touch sound card :)
Okay, you want the information that the driver author supplied in the struct
snd_pcm_hardware for the stream. I've in fact also wanted that information
on a number of occasions and just looked at the driver source then.
So you suggest to open device via any means and then read that file? I
did this and it works.
I guess I can even try to implement it in app and check for sample
rate everytime before I play.
But is this only solution? It's rather hack, and I would like to have
more reliable method.
You might consider this less of of a hack -- it uses the ALSA API to query
the information from the PCM handle directly. Please see the library
docoumentation for other information you can extract from a hw_params struct.
(I don't suppose you can ever get anything but dir == 0 for "hw" devices).
Introducing a /proc/asound/card0/pcm0{p,c}/hw_limits or similar might not be
a bad idea though?
Rene
/* gcc -W -Wall -o snd_rate snd_rate.c -l asound */
#include <stdio.h>
#include <alsa/asoundlib.h>
int main(void)
{
snd_pcm_t *handle;
snd_pcm_hw_params_t *params;
unsigned int val;
int dir;
int err;
snd_pcm_hw_params_alloca(¶ms);
err = snd_pcm_open(&handle, "hw:0,0", SND_PCM_STREAM_PLAYBACK, 0);
if (err < 0) {
fprintf(stderr, "snd_pcm_open: %s\n", snd_strerror(err));
return -1;
}
err = snd_pcm_hw_params_any(handle, params);
if (err < 0) {
fprintf(stderr, "snd_pcm_hw_params_any: %s\n",
snd_strerror(err));
return -1;
}
err = snd_pcm_hw_params_get_rate_min(params, &val, &dir);
if (err < 0) {
fprintf(stderr, "snd_pcm_hw_params_get_rate_min: %s\n",
snd_strerror(err));
return -1;
}
printf("min: (%c) %u\n", "<=>"[dir + 1], val);
err = snd_pcm_hw_params_get_rate_max(params, &val, &dir);
if (err < 0) {
fprintf(stderr, "snd_pcm_hw_params_get_rate_max: %s\n",
snd_strerror(err));
return -1;
}
printf("max: (%c) %u\n", "<=>"[dir + 1], val);
snd_pcm_close(handle);
return 0;
}
_______________________________________________
Alsa-devel mailing list
Alsa-devel@xxxxxxxxxxxxxxxx
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel