* simple PCM helper function
@ 2006-01-06 20:10 Jaroslav Kysela
2006-01-07 11:38 ` Conditionally compiling for 1.0.9 and later ? Dave Raggett
2006-01-09 16:21 ` simple PCM helper function James Courtier-Dutton
0 siblings, 2 replies; 5+ messages in thread
From: Jaroslav Kysela @ 2006-01-06 20:10 UTC (permalink / raw)
To: ALSA development
Hi all,
I added three functions to alsa-lib - PCM API:
/*
* application helpers - these functions are implemented on top
* of the basic API
*/
int snd_pcm_recover(snd_pcm_t *pcm, int err, int silent);
int snd_pcm_set_params(snd_pcm_t *pcm,
snd_pcm_format_t format,
snd_pcm_access_t access,
unsigned int channels,
unsigned int rate,
int soft_resample,
unsigned int latency);
int snd_pcm_get_params(snd_pcm_t *pcm,
snd_pcm_uframes_t *buffer_size,
snd_pcm_uframes_t *period_size);
These functions are intended for "lazy" people who are doing just
simple command line players or recorders and don't want to bother with
the ALSA details. The implementation comes from strong attitude against
alsa-lib on LKML by some people.
Please, look to them and tell me, if I missed something useable.
The really "minimalistic" example using these functions is in
alsa-lib/test/pcm_min.c (compile the code typing 'make pcm_min' in the
test directory).
Jaroslav
-----
Jaroslav Kysela <perex@suse.cz>
Linux Kernel Sound Maintainer
ALSA Project, SUSE Labs
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
^ permalink raw reply [flat|nested] 5+ messages in thread
* Conditionally compiling for 1.0.9 and later ?
2006-01-06 20:10 simple PCM helper function Jaroslav Kysela
@ 2006-01-07 11:38 ` Dave Raggett
2006-01-09 16:21 ` simple PCM helper function James Courtier-Dutton
1 sibling, 0 replies; 5+ messages in thread
From: Dave Raggett @ 2006-01-07 11:38 UTC (permalink / raw)
To: ALSA development
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I am looking for advice on the best way to conditionally
compile application code to use hardware resampling for
ALSA when this is available. One possible approach is to
do an #ifdef on SNDRV_PCM_HW_PARAMS_NORESAMPLE as show
below, but is there a better way?
#ifdef SNDRV_PCM_HW_PARAMS_NORESAMPLE
/* set hardware resampling */
err = snd_pcm_hw_params_set_rate_resample(handle,
params, resample);
if (err < 0)
{
printf("Resampling setup failed for playback: %s\n",
snd_strerror(err));
return err;
}
#endif
p.s. I understand that snd_pcm_hw_params_set_rate_resample()
was first introduced in version 1.0.9 and found that
SNDRV_PCM_HW_PARAMS_NORESAMPLE first appeared in that version.
My goal is allow my code to compile with earlier versions of
ALSA when so needed.
Many thanks,
- --
Dave Raggett <dsr@w3.org> W3C lead for multimodal interaction
http://www.w3.org/People/Raggett +44 1225 866240 (or 867351)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFDv6glb3AdEmxAsUsRAgUOAKC2ErZLNeCUw5pvd2XgTatNM5O4+wCg4udi
tA6hKBXy77dMokISn+tJmrU=
=ODw7
-----END PGP SIGNATURE-----
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: simple PCM helper function
2006-01-06 20:10 simple PCM helper function Jaroslav Kysela
2006-01-07 11:38 ` Conditionally compiling for 1.0.9 and later ? Dave Raggett
@ 2006-01-09 16:21 ` James Courtier-Dutton
2006-01-10 12:26 ` Jaroslav Kysela
1 sibling, 1 reply; 5+ messages in thread
From: James Courtier-Dutton @ 2006-01-09 16:21 UTC (permalink / raw)
To: Jaroslav Kysela; +Cc: ALSA development
Jaroslav Kysela wrote:
>Hi all,
>
> I added three functions to alsa-lib - PCM API:
>
>/*
> * application helpers - these functions are implemented on top
> * of the basic API
> */
>
>int snd_pcm_recover(snd_pcm_t *pcm, int err, int silent);
>int snd_pcm_set_params(snd_pcm_t *pcm,
> snd_pcm_format_t format,
> snd_pcm_access_t access,
> unsigned int channels,
> unsigned int rate,
> int soft_resample,
> unsigned int latency);
>int snd_pcm_get_params(snd_pcm_t *pcm,
> snd_pcm_uframes_t *buffer_size,
> snd_pcm_uframes_t *period_size);
>
> These functions are intended for "lazy" people who are doing just
>simple command line players or recorders and don't want to bother with
>the ALSA details. The implementation comes from strong attitude against
>alsa-lib on LKML by some people.
> Please, look to them and tell me, if I missed something useable.
>The really "minimalistic" example using these functions is in
>alsa-lib/test/pcm_min.c (compile the code typing 'make pcm_min' in the
>test directory).
>
> Jaroslav
>
>
Would it not have been better to provide a similar few function calls,
but use a method similar to MaxOSX. I.e. callback based.
I.e. Set parameters, and one of the parameters is the callback function
of the user's program.
The application would then not care how big the sound hardware buffer
size was.
The callback would just be:
snd_pcm_callback(void *private, /* Private information provided by
the user application at set_params call */
void *buffer, /* Frame buffer */
snd_pcm_uframes_t number_of_samples_please, /* number of
samples for frame buffer */
snd_pcm_format_t format, /* Might not be needed, but the
same format. */
snd_pcm_uframe_t delay, /* Estimate of delay between the
current time, and the time when the same will reach the DAC */
int status); /* RUNNING, XRUN etc. */
Where "number_of_samples_please" is likely to be the period size.
One could therefore drop the
snd_pcm_get_params()
and
snd_pcm_recover()
would hardly ever need to be called.
James
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: simple PCM helper function
2006-01-09 16:21 ` simple PCM helper function James Courtier-Dutton
@ 2006-01-10 12:26 ` Jaroslav Kysela
2006-01-14 21:48 ` Giuliano Pochini
0 siblings, 1 reply; 5+ messages in thread
From: Jaroslav Kysela @ 2006-01-10 12:26 UTC (permalink / raw)
To: James Courtier-Dutton; +Cc: ALSA development
On Mon, 9 Jan 2006, James Courtier-Dutton wrote:
> Jaroslav Kysela wrote:
>
> > Hi all,
> >
> > I added three functions to alsa-lib - PCM API:
> >
> > /*
> > * application helpers - these functions are implemented on top
> > * of the basic API
> > */
> >
> > int snd_pcm_recover(snd_pcm_t *pcm, int err, int silent);
> > int snd_pcm_set_params(snd_pcm_t *pcm,
> > snd_pcm_format_t format,
> > snd_pcm_access_t access,
> > unsigned int channels,
> > unsigned int rate,
> > int soft_resample,
> > unsigned int latency);
> > int snd_pcm_get_params(snd_pcm_t *pcm,
> > snd_pcm_uframes_t *buffer_size,
> > snd_pcm_uframes_t *period_size);
> >
> > These functions are intended for "lazy" people who are doing just
> > simple command line players or recorders and don't want to bother with
> > the ALSA details. The implementation comes from strong attitude against
> > alsa-lib on LKML by some people.
> > Please, look to them and tell me, if I missed something useable.
> > The really "minimalistic" example using these functions is in
> > alsa-lib/test/pcm_min.c (compile the code typing 'make pcm_min' in the
> > test directory).
> >
> > Jaroslav
> >
> >
> Would it not have been better to provide a similar few function calls,
> but use a method similar to MaxOSX. I.e. callback based. I.e. Set
> parameters, and one of the parameters is the callback function of the
> user's program. The application would then not care how big the sound
> hardware buffer size was.
Yes, the callback method might be an alternative, but the standard way is
simply write samples to device, so we shouldn't remove it.
The callback would just be:
> snd_pcm_callback(void *private, /* Private information provided by the
> user application at set_params call */ void *buffer, /* Frame buffer */
> snd_pcm_uframes_t number_of_samples_please, /* number of samples for
> frame buffer */
> snd_pcm_format_t format, /* Might not be needed, but the same
> format. */
> snd_pcm_uframe_t delay, /* Estimate of delay between the current
> time, and the time when the same will reach the DAC */
> int status); /* RUNNING, XRUN etc. */
>
> Where "number_of_samples_please" is likely to be the period size.
> One could therefore drop the
You must also add a new function "snd_pcm_check_for_space()" or something
like this. The app callback will be called from this function. Also, the
app callback function should probably take same parameters as
snd_pcm_mmap_begin() handles (areas, offset), because we support more
ring buffer organization schemes.
So, to all others, is this mechanism worth to implement?
audio_callback(areas, offset, samples, status) {
if (status)
status = snd_pcm_recover();
if (status) {
/* handle error here */
return;
}
... process new samples here, i/o from areas at specified offset ...
}
main() {
snd_pcm_open()
snd_pcm_set_params()
snd_pcm_set_callback(audio_callback);
while (1) {
poll();
if (poll_set_audio_fd)
if (snd_pcm_check_for_space() < 0)
/* handle error here */
}
}
Jaroslav
-----
Jaroslav Kysela <perex@suse.cz>
Linux Kernel Sound Maintainer
ALSA Project, SUSE Labs
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: simple PCM helper function
2006-01-10 12:26 ` Jaroslav Kysela
@ 2006-01-14 21:48 ` Giuliano Pochini
0 siblings, 0 replies; 5+ messages in thread
From: Giuliano Pochini @ 2006-01-14 21:48 UTC (permalink / raw)
To: Jaroslav Kysela; +Cc: James, alsa-devel
On Tue, 10 Jan 2006 13:26:58 +0100 (CET)
Jaroslav Kysela <perex@suse.cz> wrote:
> You must also add a new function "snd_pcm_check_for_space()" or something
> like this. The app callback will be called from this function. Also, the
> app callback function should probably take same parameters as
> snd_pcm_mmap_begin() handles (areas, offset), because we support more
> ring buffer organization schemes.
>
> So, to all others, is this mechanism worth to implement?
IMHO they should be as simple as possible. I thing the first proposal is
more obvious and straightforward. That callback mechanism just moves the
complexity somewhere else.
--
Giuliano.
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2006-01-14 21:48 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-01-06 20:10 simple PCM helper function Jaroslav Kysela
2006-01-07 11:38 ` Conditionally compiling for 1.0.9 and later ? Dave Raggett
2006-01-09 16:21 ` simple PCM helper function James Courtier-Dutton
2006-01-10 12:26 ` Jaroslav Kysela
2006-01-14 21:48 ` Giuliano Pochini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox