1
votes

I have questions about the ALSA sound library.

Let me first state that a usual reply to questions like mine is "use JACK", and that that anwer is not helpful, since I probably cannot use JACK. I am running a native linux program on an Android device (not NDK, but really native), and from what I gathered, JACK does not work on Android since some libc and posix stuff incompatabilities.

The questions:

1) can I use 2 different threads, for a) reading captured samples and b) playing back samples? All ALSA "full duplex" examples I've seen just use alternating reading from / writing to the sound card with blocking functions, which seems not to work too great, especially if your program is supposed to do a little more than that.

2) As I understood, ALSA mixes audio played by different applications, much like the windows audio mixer. Is it possible to get exclusive access to an audio device, such that my application is guaranteed to be the only one playing back audio, with no mixing & degrading of dynamic range going on?

1
As far I know Android OS is in charge of managing system sounds and there is no way to directly access ALSA on non-rooted/non-modified device.Kristopher
More to the point, there's no guarantee that the underlying layer is actually ALSA.marko
What do you mean by that / could you elaborate, Marko?user1847129
As for rooted device, this is not really a concern for what I'm doing, fiddling with a custom device.user1847129

1 Answers

2
votes
  1. You can use two threads for the two playback/capture devices (see the documentation).

  2. ALSA mixes audio only if the dmix plugin is used. By default, this is configured only for most desktop sound cards.

    If you open a hw or plughw device, any software mixing will be bypassed.

    (As long as only one stream is playing, the data will not be degraded in any way.)