From: Andrew Eikum <aeikum@codeweavers.com>
To: Clemens Ladisch <clemens@ladisch.de>
Cc: Andrew Eikum <aeikum@codeweavers.com>,
alsa-devel <alsa-devel@alsa-project.org>
Subject: Re: [PATCH 2/2] Improve hw_params documentation
Date: Wed, 16 Nov 2011 15:31:35 -0600 [thread overview]
Message-ID: <20111116213135.GJ30602@foghorn.codeweavers.com> (raw)
In-Reply-To: <4EC42907.80104@ladisch.de>
[-- Attachment #1: Type: text/plain, Size: 1556 bytes --]
On Wed, Nov 16, 2011 at 10:20:07PM +0100, Clemens Ladisch wrote:
> Andrew Eikum wrote:
> > +++ b/include/pcm.h
> > @@ -44,8 +44,20 @@ extern "C" {
> >
> > /** PCM generic info container */
> > typedef struct _snd_pcm_info snd_pcm_info_t;
> > -/** PCM hardware configuration space container */
> > +
> > +/** PCM hardware configuration space container
> > + *
> > + * snd_pcm_hw_params_t is an opaque structure which contains a set of possible
> > + * PCM hardware configurations. For example, a given instance might include a
> > + * range of buffer sizes, a range of period sizes, and a set of several sample
> > + * formats. Some subset of all possible combinations these sets may be valid,
> > + * but not necessarily any combination will be valid.
> > + *
> > + * No validation is done by the various snd_pcm_hw_params_set* functions.
>
> These functions do validate the value that the application is trying to set
> and adjust all other dependent limits.
>
I didn't find that to be the case in my testing, at least between
periods, period_size, and buffer_size. I've attached a test program
here. It sets periods to 10, period_size to 1024, and buffer_size_max
to be the same as the return from get_buffer_size_min (in my case,
80). The first call to fail is snd_pcm_hw_params(). If what you said
is true, I would expect the set_buffer_size_max() call to fail.
$ gcc -I /usr/include/alsa -lasound -o alsa_period_count alsa_period_count.c
$ ./alsa_period_count
min_buffer_frames: 80
set max buffer size: 80
snd_pcm_hw_params: -12
$
Andrew
[-- Attachment #2: alsa_period_count.c --]
[-- Type: text/x-csrc, Size: 3306 bytes --]
#include <asoundlib.h>
int main(int argc, char **argv)
{
snd_pcm_t *pcm;
snd_pcm_hw_params_t *hw_params;
snd_pcm_uframes_t buffer_frames, period_frames;
unsigned int periods, min_periods, max_periods;
int period_dir, periods_dir, min_periods_dir, max_periods_dir;
int err;
err = snd_pcm_open(&pcm, "default", SND_PCM_STREAM_PLAYBACK, 0);
if(err < 0){
printf("snd_pcm_open: %d\n", err);
return 1;
}
hw_params = malloc(snd_pcm_hw_params_sizeof());
if(!hw_params){
perror("malloc");
return 1;
}
err = snd_pcm_hw_params_any(pcm, hw_params);
if(err < 0){
printf("snd_pcm_hw_params_current: %d\n", err);
return 1;
}
min_periods = 0xdeadbeef;
min_periods_dir = 0xdeadbeef;
err = snd_pcm_hw_params_get_periods_min(hw_params, &min_periods, &min_periods_dir);
if(err < 0){
printf("snd_pcm_hw_params_get_periods_min: %d\n", err);
return 1;
}
max_periods = 0xdeadbeef;
max_periods_dir = 0xdeadbeef;
err = snd_pcm_hw_params_get_periods_max(hw_params, &max_periods, &max_periods_dir);
if(err < 0){
printf("snd_pcm_hw_params_get_periods_max: %d\n", err);
return 1;
}
err = snd_pcm_hw_params_set_periods(pcm, hw_params, 10, 0);
if(err < 0){
printf("snd_pcm_hw_params_set_periods: %d\n", err);
return 1;
}
err = snd_pcm_hw_params_set_period_size(pcm, hw_params, 1024, 0);
if(err < 0){
printf("snd_pcm_hw_params_set_period_size: %d\n", err);
return 1;
}
err = snd_pcm_hw_params_get_buffer_size_max(hw_params, &buffer_frames);
if(err < 0){
printf("snd_pcm_hw_params_get_buffer_size: %d\n", err);
return 1;
}
err = snd_pcm_hw_params_get_buffer_size_min(hw_params, &buffer_frames);
if(err < 0){
printf("snd_pcm_hw_params_get_buffer_size: %d\n", err);
return 1;
}
printf("min_buffer_frames: %u\n", buffer_frames);
err = snd_pcm_hw_params_set_buffer_size_max(pcm, hw_params, &buffer_frames);
if(err < 0){
printf("snd_pcm_hw_params_get_buffer_size: %d\n", err);
return 1;
}
printf("set max buffer size: %u\n", buffer_frames);
err = snd_pcm_hw_params(pcm, hw_params);
if(err < 0){
printf("snd_pcm_hw_params: %d\n", err);
return 1;
}
err = snd_pcm_hw_params_get_buffer_size(hw_params, &buffer_frames);
if(err < 0){
printf("snd_pcm_hw_params_get_buffer_size: %d\n", err);
return 1;
}
err = snd_pcm_hw_params_get_period_size(hw_params, &period_frames, &period_dir);
if(err < 0){
printf("snd_pcm_hw_params_get_period_size: %d\n", err);
return 1;
}
periods = 0xdeadbeef;
periods_dir = 0xdeadbeef;
err = snd_pcm_hw_params_get_periods(hw_params, &periods, &periods_dir);
if(err < 0){
printf("snd_pcm_hw_params_get_periods: %d\n", err);
return 1;
}
printf("min_periods: %u, max_periods: %u, buffer_frames: %lu, period_frames: %lu, buf/per: %f, periods: %u, periods_dir: %d\n",
min_periods, max_periods, buffer_frames, period_frames, buffer_frames / (double)period_frames, periods, periods_dir);
free(hw_params);
snd_pcm_close(pcm);
return 0;
}
[-- Attachment #3: Type: text/plain, Size: 0 bytes --]
next prev parent reply other threads:[~2011-11-16 21:31 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-16 19:56 [PATCH 2/2] Improve hw_params documentation Andrew Eikum
2011-11-16 21:20 ` Clemens Ladisch
2011-11-16 21:31 ` Andrew Eikum [this message]
2011-11-16 22:08 ` Clemens Ladisch
2011-11-17 14:02 ` Andrew Eikum
2011-11-21 22:31 ` Raymond Yau
2011-11-22 13:41 ` Andrew Eikum
2011-11-22 23:57 ` Raymond Yau
2011-11-17 0:45 ` Raymond Yau
2011-11-17 13:27 ` Clemens Ladisch
2011-11-19 1:28 ` Raymond Yau
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=20111116213135.GJ30602@foghorn.codeweavers.com \
--to=aeikum@codeweavers.com \
--cc=alsa-devel@alsa-project.org \
--cc=clemens@ladisch.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox