All of lore.kernel.org
 help / color / mirror / Atom feed
From: Clemens Ladisch <clemens@ladisch.de>
To: public-hk <public-hk@ind.rwth-aachen.de>
Cc: alsa-devel@alsa-project.org
Subject: Re: Some questions related to ALSA based duplex audio processing
Date: Tue, 31 Jan 2012 14:30:53 +0100	[thread overview]
Message-ID: <4F27ED0D.9030002@ladisch.de> (raw)
In-Reply-To: <4F27D30B.6010607@ind.rwth-aachen.de>

public-hk wrote:
>>> I have understood from the docs that the snd_pcm_read/snd_pcm_write
>>> functions do nothing else than addressing the memory mapped areas. As a conclusion, I realize
>>> this access myself to have more control about it.
>>
>> Why do you want to duplicate snd_pcm_read/write?  What do you "control"
>> there, i.e., what are you doing differently?
>
> The additional degree of freedom is that I see the amount of samples which are available in the mmap'ed buffer whereas with read and write, I only get the notification that
> a specific amount of samples has been available (based on the number of samples to be read/written specified when calling the function).

snd_pcm_avail()

>>> And by using the async callbacks, I do not have to deal with blocking or non-blocking read functions or polling related issues.
>>
>> But instead you have to deal with signal delivery.  Besides being
>> nonportable, you are not allowed to do anything useful inside a signal
>> handler.
>
> Why is this nonportable?

Not every sound device type supports async callbacks.

> The sound APIs that I dealt with before more or less by definition work based on callback mechanisms (ASIO, CoreAudio).
> What is the restriction considering the processing that I plan within the signal handler?

Signals are _not_ threads; they are sent to an existing process or
thread, and interrupt it.

Most functions are not reentrant and therefore cannot be called from
a signal handler.  The only useful thing you _can_ do is to write to
a pipe to wake up another thread that waits with poll() for this
notification, but then you could just as well wait for the device
itself.

> Is that a documented restriction?

http://pubs.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_04.html

(ALSA uses SIGIO.  SIGEV_THREAD is not supported.)

> A possible alternative realization would be to start a thread in which I do
> 1) pcm_read
> 2) process audio samples
> 3) pcm_write
> in an infinite loop. In this case, however, the "read" would also block the "write" for a specific
> time. This architecture would
> a) introduce additional delay if I miss the next required "write" due to the blocking "read".
> b) might reduce the available processing time (operation "process audio samples")  since I have "wasted" time in the blocking "read".

Then use non-blocking mode.
(Or use a library that does this for you.)


Regards,
Clemens

      parent reply	other threads:[~2012-01-31 13:28 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-29 19:19 Some questions related to ALSA based duplex audio processing public-hk
2012-01-29 20:31 ` Fons Adriaensen
2012-01-31 11:07   ` public-hk
2012-01-31 10:40 ` Clemens Ladisch
2012-01-31 11:39   ` public-hk
2012-01-31 12:10     ` Fons Adriaensen
2012-02-02  9:45       ` public-hk
2012-01-31 13:30     ` Clemens Ladisch [this message]

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=4F27ED0D.9030002@ladisch.de \
    --to=clemens@ladisch.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=public-hk@ind.rwth-aachen.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 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.