All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rene Herman <rene.herman@keyaccess.nl>
To: Peteris Krisjanis <pecisk@gmail.com>
Cc: alsa-user@lists.sourceforge.net,
	ALSA devel <alsa-devel@alsa-project.org>
Subject: Re: How to get set/fixed sample rate of ALSA device?
Date: Mon, 08 Oct 2007 00:07:37 +0200	[thread overview]
Message-ID: <470958A9.7040607@keyaccess.nl> (raw)
In-Reply-To: <b97f4ee40710071004o23ea40a1w8c8f754b47083b95@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1425 bytes --]

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

[-- Attachment #2: snd_rate.c --]
[-- Type: text/plain, Size: 1035 bytes --]

/* 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(&params);

	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;
}

[-- Attachment #3: Type: text/plain, Size: 314 bytes --]

-------------------------------------------------------------------------
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/

[-- Attachment #4: Type: text/plain, Size: 158 bytes --]

_______________________________________________
Alsa-user mailing list
Alsa-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/alsa-user

       reply	other threads:[~2007-10-07 22:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <b97f4ee40710061456l5aa0764alce22c505401c7e6f@mail.gmail.com>
     [not found] ` <4708F918.3060207@keyaccess.nl>
     [not found]   ` <b97f4ee40710071004o23ea40a1w8c8f754b47083b95@mail.gmail.com>
2007-10-07 22:07     ` Rene Herman [this message]
2007-10-07 22:27       ` How to get set/fixed sample rate of ALSA device? Rene Herman
     [not found]       ` <200710080841.37709.markc@renta.net>
2007-10-07 23:52         ` Rene Herman
2007-10-08 19:09       ` Peteris Krisjanis
2007-10-08 19:14         ` Bill Unruh
2007-10-08 19:30           ` Rene Herman
2007-10-09  0:23             ` Rene Herman
2007-10-15 20:20               ` [Alsa-user] " Rene Herman
2007-10-16 13:26                 ` [alsa-devel] " Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=470958A9.7040607@keyaccess.nl \
    --to=rene.herman@keyaccess.nl \
    --cc=alsa-devel@alsa-project.org \
    --cc=alsa-user@lists.sourceforge.net \
    --cc=pecisk@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.