ALSAPulseAudio: Difference between revisions
(reformat; clarify) |
|||
Line 2: | Line 2: | ||
== Working with ALSA and Pulse Audio == | == Working with ALSA and Pulse Audio == | ||
* Don't clip: The maximum amplitude in your signal '''must not''' exceed 1.0. | * Don't clip: The maximum amplitude in your signal '''must not''' exceed 1.0. | ||
* Set "OK to Block" to "No" when the flowgraph is throttled by another hardware device. | * Set "OK to Block" to "No" when the flowgraph is throttled by another hardware device. | ||
* 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 known audio cards, 48000 Hz on most, others may not. | |||
* If you get lots of <code>aU</code> (audio underruns) on your terminal, try creating or editing ~/.gnuradio/config.conf as follows: | |||
<pre> | |||
[audio_alsa] | |||
default_input_device = default | |||
default_output_device = default | |||
nperiods = 32 | |||
period_time = 0.010 | |||
verbose = false | |||
</pre> | |||
== Talking to ALSA == | == Talking to ALSA == |
Revision as of 15:23, 17 January 2021
Working with ALSA and Pulse Audio
- Don't clip: The maximum amplitude in your signal must not exceed 1.0.
- Set "OK to Block" to "No" when the flowgraph is throttled by another hardware device.
- 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 known audio cards, 48000 Hz on most, others may not.
- If you get lots of
aU
(audio underruns) on your terminal, try creating or editing ~/.gnuradio/config.conf as follows:
[audio_alsa] default_input_device = default default_output_device = default nperiods = 32 period_time = 0.010 verbose = false
Talking to ALSA
The GNU Radio Audio Sink and Source blocks use ALSA (unless ALSA support was disabled during build time). ALSA has been the standard sound API under Linux for a decade or more, so basically all programs that produce Audio know how to deal with it. Alternately one can use a sound server like PulseAudio that takes care of dealing with all the low-level details for the application.
PulseAudio also provides a "fake" ALSA device 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 capable of resampling internally, but the results aren't always predictable. For GNU Radio applications, it's often desirable to use the raw device.
You can obtain a list the playback devices (for an Audio Sink) using the aplay
program.
- from a terminal window enter:
aplay -L
- a long list of options will be displayed, such as:
default Playback/recording through the PulseAudio sound server null Discard all samples (playback) or generate zero samples (capture) pulse PulseAudio Sound Server hdmi:CARD=HDMI,DEV=0 HDA ATI HDMI, HDMI 0 HDMI Audio Output hw:CARD=Generic,DEV=0 HD-Audio Generic, ALC662 rev3 Analog Direct hardware device without any conversions plughw:CARD=Generic,DEV=0 HD-Audio Generic, ALC662 rev3 Analog Hardware device with all software conversions ...
- find the entry such as:
hw:CARD=Generic,DEV=0 HD-Audio Generic, ALC662 rev3 Analog Direct hardware device without any conversions
in the list which matches your desired device.
- use the first line of that entry (e.g. "hw:CARD=Generic,DEV=0") as the device name (without the quotes).
For audio input devices (an Audio Source), use:
arecord -L
to obtain a similar list.
Monitoring the audio input of your system with PulseAudio
IMPORTANT: this procedure only applies to an Audio Source block!
PulseAudio has its own monitor "ports". You can list all PulseAudio monitor sources by running:
pactl list|grep "Monitor Source"|sed 's/^[[:space:]]*Monitor Source: //g'
This 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 input, the second line would be the right.
Add ALSA Pseudodevice for monitor
Now, we need to edit (or 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 previous step.
Using the newly created device
In the Audio Source block, use pulse_monitor
as the device name: