Re: Any standard ALSA application for simultaneous capture and playabck ?????

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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




       
____________________________________________________________________________________Luggage? GPS? Comic books? 
Check out fitting gifts for grads at Yahoo! Search
http://search.yahoo.com/search?fr=oni_on_mail&p=graduation+gifts&cs=bz

Attachment: fullduplex.c
Description: Binary data

_______________________________________________
Alsa-devel mailing list
Alsa-devel@xxxxxxxxxxxxxxxx
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux