Mutliple sound streams with configurable volume level using ALSA lib - linux

I would like to use ALSA library to play mutliple sound streams, with each stream having its own customizable volume level. Would like to avoid using higher level abstractions like pulseaudio, since this is to be used on a ARM target board with single channel output, would like to avoid compiling pulseaudio and the associated issue. Please suggest in what all possible ways such an implementation can be done. Any guidance with usage of ALSA plugins dmix / softvol is welcome

Related

Alternative to ALSA dmix

In an embedded Linux project I have exactly two processes that need to access the audio device. So far I'm using ALSA dmix for that. However, dmix is giving me a lot of trouble (as explained in this question).
Now I'm wondering - are there any simple alternatives to dmix? I can imagine that PulseAudio is doing a much better job, but I'm not sure if its not an overkill to bring a general-usage sound server into a small embedded project, just for mixing two audio streams.

ALSA individual PCM volume control

I'm playing PCM sounds simultaneously using ALSA device "plug:dmix" (one call of snd_pcm_open() for each sound), but I can't find a way to control each sound's volume separately (like DirectSound does), I've only managed to set MASTER and PCM volumes, using simple mixer interface. Is there a way to do this using ALSA's C API? I know how to do it by hand, but I prefer to use the library API, if it is possible at all. Already searched the documentation and related questions, can't find an answer.

Do I need my codec to be ALSA or not?

I have a project that I am working on, for the purposes of this question, lets say they are wireless speakers.
We are using the raspberry pi for development right now but we plan to move to our own embedded solution. The codec we've chosen fits our needs best, although it isn't an "ALSA supported" codec. As in the ALSA webpage doesn't have info on it.
Much of the PCM code I've found to develop this on the raspberry pi use ALSA streams. Is it a standard to use an ALSA codec for these types of projects?
I haven't worked much with embedded linux or RTOS. I work with bare-metal systems quite frequently though which explains my confusion on what ALSA exactly is. It seems like some odd middleware or something.
ALSA is
the API that application that want to use sound use; and
the library that implements this API; and
the interface between this library and the kernel; and
the kernel implementation of this interface; and
the framework to be used by sound drivers.
To have your codec supported in Linux, you must write an ALSA driver.

manipulating audio input buffer on Ubuntu Linux

Suppose that I want to code an audio filter in C++ that is applied on every audio or to a specific microphone/source, where should I start with this on ubuntu ?
edit, to be clear I don't get how to do this and what is the role of Pulseaudio, ALSA and Gstreamer.
Alsa provides an API for accessing and controlling audio and MIDI hardware. One portion of ALSA is a series of kernel-mode device drivers, whilst the other is a user-space library that applications link against. Alsa is single-client.
PulseAudio is framework that facilitates multiple client applications accessing a single audio interface (alsa is single-client). It provides a daemon process which 'owns' the audio interface and provides a IPC transport for audio between the daemon and applications using it. This is used heavily in open source desktop environments. Use of Pulse is largely transparent to applications - they continue to access the audio input and output using the alsa API with audio transport and mixing. There is also Jack which is targeted more towards 'professional' audio applications - perhaps a bit of a misnomer, although what is meant here is low latency music production tools.
gStreamer is a general purpose multi-media framework based on the signal-graph pattern, in which components have a number of inputs and output pins and provide a transformation function. A Graph of these components is build to implement operations such as media decoding, with special nodes for audio and video input or output. It is similar in concept to CoreAudio and DirectShow. VLC and libAV are both open source alternatives that operate along similar lines. Your choice between these is a matter of API style, and implementation language. gStreamer, in particular, is an OO API implemented in C. VLC is C++.
The obvious way of implementing the problem you describe is to implement a gStreamer/libAV/VLC component. If you want to process the audio and then route it to another application, this can be achieved by looping it back through Pulse or Jack.
Alsa provides a plug-in mechanism, but I suspect that implementing this from the ALSA documentation will be tough going.
The de-facto architecture for building effects plug-ins of the type you describe is Steinberg's VST. There are plenty of open source hosts and examples of plug-ins that can be used on Linux, and crucially, there is decent documentation. As with a gStreamer/libAV/VLC, you be able to route audio in an out of this.
Out of these, VST is probably the easiest to pick up.

Attach sameplerate or dmix ALSA plugin to OSS device

I have an application in an embedded system that has a application which is OSS based. Unfortunately, this application is at a fixed sample rate (8K), but I need it to be at 48K. Furthermore, I can't change the application.
I'm researching sample rate conversion plugins, such as dmix or libsamplerate, but I don't see how to use that with OSS.
Can somebody please point me in the right direction? Can I configure ALSA in such a way as to convert the OSS interface from 8K->48K in/out of the system?
TIA
Mike
What you want is the alsa-oss package which provides a tool you can use to run a program and redirect it's OSS sound output into ALSA where all the normal ALSA tools are available.

Resources