ALSAPulseAudio: Difference between revisions

From GNU Radio
Jump to navigation Jump to search
Line 9: Line 9:


=== Audience ===
=== Audience ===
Linux users wanting to get Audio in and/or out of their GNU Radio application, but are having problems ===
Linux users wanting to get Audio in and/or out of their GNU Radio application, but are having problems.


=== Problem ===
=== Problem ===

Revision as of 09:41, 3 March 2020

Working with ALSA and Pulse Audio

General

  • Sound cards don't support arbitrary sampling rates. If your audio is choppy, check the rate of your audio sink or source: 44100 Hz works under all audio cards known, 48000 Hz on many, 32000 usually does not work.
  • Don't clip: The maximum amplitude in your signal must not exceed 1.0.

Talking to ALSA

Audience

Linux users wanting to get Audio in and/or out of their GNU Radio application, but are having problems.

Problem

The GNU Radio Audio sink and source use ALSA (unless ALSA support was disabled during build time). ALSA has been the standard sound API under Linux for a decade or so, so basically all programs that produce Audio know how to deal with it, or use a sound server like PulseAudio that takes care of dealing with all the low-level details for the application.

PulseAudio itself also provides a "fake" ALSA device, so to make ALSA applications talk to PulseAudio instead of directly with the hardware driver, allowing one central volume control etc.

However, PulseAudio's device isn't always perfect. PulseAudio is internally capable of resampling, but the results aren't always predictable. For GNU Radio applications, it's often desirable to know the raw device.

Solution

You can figure out the playback devices using the aplay program, that usually ships with modern linux distributions:

aplay -L

yields something like

null
    Discard all samples (playback) or generate zero samples (capture)
pulse
    PulseAudio Sound Server
default
    Default ALSA Output (currently PulseAudio Sound Server)
hdmi:CARD=HDMI_1,DEV=0
    HDA Intel HDMI, HDMI 0
    HDMI Audio Output
hdmi:CARD=HDMI_1,DEV=1
    HDA Intel HDMI, HDMI 1
    HDMI Audio Output
hdmi:CARD=HDMI_1,DEV=2
    HDA Intel HDMI, HDMI 2
    HDMI Audio Output
sysdefault:CARD=PCH
    HDA Intel PCH, ALC887-VD Analog
    Default Audio Device
front:CARD=PCH,DEV=0
    HDA Intel PCH, ALC887-VD Analog
    Front speakers
...

here, using somethig like front or sysdefault in the Audio Sink's "Device" property makes a lot of sense.

In analogy

arecord -L

lists all recording devices.

Monitoring the output of your system

Audience

Users wanting to process what the Sound system currently is producing

Problem

ALSA is badly documented, and PulseAudio is mainly documented through fragmented Wiki Entries, mainly done by the ArchLinux community.

Solution

Find PulseAudio monitors

PulseAudio has its own monitor "ports"; you can list all PulseAudio endpoints by running

pactl list

We want to find monitors. Because we're too lazy to read through the nautic mile of output that pactl list produces:

pactl list|grep "Monitor Source"|sed 's/^[[:space:]]*Monitor Source: //g'

Will give you one or more lines containing something like

alsa_output.pci-0000_00_03.0.hdmi-stereo.monitor
alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
alsa_output.pci-0000_06_00.1.hdmi-stereo.monitor

Select the right name; assuming we use the analog output, the second line would be the right.

Add ALSA Pseudodevice for monitor

Now, we need to edit (and create, if it doesn't already exist) ~/.asoundrc.
Add

pcm.pulse_monitor {
    type pulse
    device alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
}

ctl.pulse_monitor {
    type pulse
    device alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
}

of course, replacing the device name with the correct one from the last step.

Using the newly created device

In the Audio Source block, use pulse_monitor as the device name:
PulseAudio-ALSA-Monitoring.png