* maintaining fixed latency between output and input?
@ 2008-09-26 1:05 Aaron J. Grier
2008-09-26 6:33 ` Clemens Ladisch
0 siblings, 1 reply; 3+ messages in thread
From: Aaron J. Grier @ 2008-09-26 1:05 UTC (permalink / raw)
To: alsa-devel
what's the most straight-forward way to maintain fixed latency between
output and input without sitting in loop and continuously checking
snd_pcm_avail_update() for the output and input descriptors?
I was originally going to use callbacks, but I've recently read that is
not a good idea. poll() seems to be the reccomended method.
I could use separate threads for output and input, but then I have to
perform synchronization between them, marshal external requests between
the two threads, and make a lot more work for myself.
I'm visualizing something like this:
for(;;)
{
poll()
if (output_is_ready)
{
/* write output buffer */
/* do output-side housekeeping */
}
if (input_is_ready)
{
/* read input buffer */
/* do input-side housekeeping */
}
/* communicate with other threads */
}
combining the output and input snd_pcm_t into a single descriptor list
for poll() seems straight-forward, but can I pass this superset list to
snd_pcm_poll_descriptors_revents() without it getting confused?
--
Aaron J. Grier | "Not your ordinary poofy goof." | agrier@poofygoof.com
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: maintaining fixed latency between output and input?
2008-09-26 1:05 maintaining fixed latency between output and input? Aaron J. Grier
@ 2008-09-26 6:33 ` Clemens Ladisch
2008-09-29 23:34 ` Aaron J. Grier
0 siblings, 1 reply; 3+ messages in thread
From: Clemens Ladisch @ 2008-09-26 6:33 UTC (permalink / raw)
To: Aaron J. Grier, alsa-devel
Aaron J. Grier wrote:
> what's the most straight-forward way to maintain fixed latency between
> output and input without sitting in loop and continuously checking
> snd_pcm_avail_update() for the output and input descriptors?
>
> I was originally going to use callbacks, but I've recently read that is
> not a good idea. poll() seems to be the reccomended method.
Yes.
> I'm visualizing something like this:
>
> for(;;)
> {
> poll()
>
> if (output_is_ready)
> {
> /* write output buffer */
> /* do output-side housekeeping */
> }
>
> if (input_is_ready)
> {
> /* read input buffer */
> /* do input-side housekeeping */
> }
>
> /* communicate with other threads */
> }
This is exactly how a full-duplex application should be structured.
To communicate with other threads, you can use a pipe so that you have
a file descriptor that can be used with the poll().
> combining the output and input snd_pcm_t into a single descriptor list
> for poll() seems straight-forward, but can I pass this superset list to
> snd_pcm_poll_descriptors_revents() without it getting confused?
No, snd_pcm_poll_descriptors_revents() looks at the file descriptors of
a single device and returns the ready status of that device.
HTH
Clemens
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: maintaining fixed latency between output and input?
2008-09-26 6:33 ` Clemens Ladisch
@ 2008-09-29 23:34 ` Aaron J. Grier
0 siblings, 0 replies; 3+ messages in thread
From: Aaron J. Grier @ 2008-09-29 23:34 UTC (permalink / raw)
To: alsa-devel
On Fri, Sep 26, 2008 at 08:33:19AM +0200, Clemens Ladisch wrote:
> To communicate with other threads, you can use a pipe so that you have
> a file descriptor that can be used with the poll().
now how to get posix message queues available to poll()? (=
> Aaron J. Grier wrote:
> > combining the output and input snd_pcm_t into a single descriptor
> > list for poll() seems straight-forward, but can I pass this superset
> > list to snd_pcm_poll_descriptors_revents() without it getting
> > confused?
>
> No, snd_pcm_poll_descriptors_revents() looks at the file descriptors of
> a single device and returns the ready status of that device.
to follow up to myself, I was able to allocate a contiguous array of
struct pollfd, and point ALSA at different sections of it. the entire
array was handed to poll(). it seems to work as described, and my
timing is now a bit tighter than it previously was.
--
Aaron J. Grier | "Not your ordinary poofy goof." | agrier@poofygoof.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-09-29 23:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-26 1:05 maintaining fixed latency between output and input? Aaron J. Grier
2008-09-26 6:33 ` Clemens Ladisch
2008-09-29 23:34 ` Aaron J. Grier
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.