[alsa-devel] Any standard ALSA application for simultaneous capture and playabck ?????

Ciaccia ciacciax at yahoo.com
Tue May 22 09:01:29 CEST 2007

> What are the complications in implementing simultaneous playback and
> capture in ALSA???

I would like to add something to this post: what is the "best" way to
program a full duplex application? I would like to have an application
that does full-duplex, with the lowest possible latency and using less
CPU resource as possible. I tried different approaches, but I was not
completely satisfied with none of them....

Here is what I tried:
-having two threads, one for playback and one for capture
-defining 2 callbacks with async_handles and do all the processing in the callback functions
(the last attempt)
-using poll() to wait for one of the streams to be ready (see attached file fullduplex.c)

Could some of you look at the attached code (it is not generic and contains lots of asserts, but it's supposed to work only on one single machine) and tell me if the last approach using poll is well structured?

The main loop looks as following:

>    while (1) {
>        err = poll(ufds, 2, -1);
>        for (i = 0; i < 2; i++)
>        {
>            if (snd_pcm_poll_descriptors_revents(handles[i], &ufds[i], 1, &revents) < 0)
>            {
>                printf("Error getting revents for %s\n", descriptors[i].name);
>                exit(1);
>            }
>            if (revents & descriptors[i].poll_flag)
>            {
>                if (transfer_loop(handles[i], &first[i], descriptors[i].func) < 0)
>                {
>                    printf("transfer_loop error for %s\n", descriptors[i].name);
>                    // TODO exit?!?
>                }
>            }
>        }
>    }

and the transfer_loop is a modified version of the loop found in the ALSA examples (pcm.c and latency.c).
Is this strategy optimal in respect to low latency and low CPU usage? 

Every comment is greatly appreciated

____________________________________________________________________________________Luggage? GPS? Comic books? 
Check out fitting gifts for grads at Yahoo! Search
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fullduplex.c
Type: application/octet-stream
Size: 8803 bytes
Desc: not available
Url : http://mailman.alsa-project.org/pipermail/alsa-devel/attachments/20070522/bfe5efd2/attachment.dll 

More information about the Alsa-devel mailing list