AWE Core OS 8.B.19 Documentation
|
ALSA (Advanced Linux Sound Architecture) is the defacto standard for Linux audio. This section is not meant to explain ALSA, it is simply meant to aid the user in finding the correct ALSA identifier string for the desired audio device.
RTAudio-alsa implements the ALSA C API to enable realtime audio, and therefore needs to know which audio hardware device to use. The user tells RTAudio-alsa which device to use at runtime via command line arguments.
See RTAudio-alsa.c and AudioStream.c for a reference implementation of ALSA as the audio driver for a Linux application.
Although the RTAudio-alsa example app binary comes prebuilt with ALSA, the processes described in this guide requires the ALSA development tools to be installed on the Linux system. To install them on an Ubuntu system, issue the following command:
sudo apt-get install libasound-dev
As mentioned above, the RTAudio-alsa example app needs to know which audio input and output device to use. This is done by passing in an ALSA specific device identifier string at runtime.
By default RTAudio-alsa uses the ID string “hw:0,0” for both the input and the output device. At a basic level, this ID string can be translated to “Use plugin type 'hw', on card 0, on device 0”.
Chances are that on some systems, "hw:0,0" will not represent the desired audio device, and the user will need to pass in specific identifiers for the desired device.
To find the desired device's ALSA ID, we can use the ALSA development tools to enumerate all available devices and their information. To list the output devices, execute the command:
aplay -l
A list of output devices should appear as well as some information about them. Here is some sample output from a RaspberryPi 3 with a USB soundcard connected:
**** List of PLAYBACK Hardware Devices **** card 1: Device [USB Audio Device], device 0: USB Audio [USB Audio] Subdevices: 1/1 Subdevice #0: subdevice #0
This output says that the USB Audio Device is identified as card 1, device 0. However, it does not tell us the plugin type.
To list the plugin types available for the device, execute the command...
aplay -L
The output will be similar to the previous “aplay -l” command, but with additional details about the devices, as well as some information about the system default (not covered in this guide). See the following excerpt of sample output from “aplay -L” on the same device as used in the example above…
hw:CARD=Device,DEV=0 USB Audio Device, USB Audio Direct hardware device without any conversions plughw:CARD=Device,DEV=0 USB Audio Device, USB Audio Hardware device with all software conversions
This output says that there are two available plugin types for the USB Audio Device, “hw” and “plughw”. “plughw” uses software conversions at the driver level (rebuffering, sample rate conversion, etc), and “hw” does no conversions. For a USB audio device, chances are the “plughw” is the desired type, as the driver author has probably optimized performance of the device with some driver level conversions.
Getting this information about the input devices follows the same process, but with “arecord -l” and “arecord -L” as opposed to the aplay commands. For the example in this guide, the output is exactly the same.
For the given example it is known that the plugin type is going to be “plughw”, the card identifier is 1, and the device identifier is 0 (for both input and output device). Translating this back into an ALSA ID string results in...
“plughw:1,0”
RTAudio-alsa takes a command line argument for both the input and output ALSA device ID strings
-inputdevice:”<device ID string>” -outputdevice:”<device ID string>”
For the given example, the runtime command would be as follows...
./RTAudio-alsa -inputdevice:”plughw:1,0” -outputdevice:”plughw:1,0”