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

Rene Herman rene.herman at keyaccess.nl
Mon Oct 8 00:07:37 CEST 2007


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
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: snd_rate.c
Url: http://mailman.alsa-project.org/pipermail/alsa-devel/attachments/20071008/d5da6769/attachment.bat 


More information about the Alsa-devel mailing list