1

I have failed to pipe the recorded audio input on my audio device (an alsa driven hifiberry with an adc hosted on a raspberry pi) despite trying my best to pipe the output into tee after arecord, install and set up pulseaudio and utilize parec, as well as jackd and jack_capture.

Critical diagram of my mission:

Line level audio -> ADC -> PCM/Wav File -> DAC -> line level audio.

The problem is that no output ever plays during recording.

I am recording a line level input and would like to hear it. Latency is not critical but I expect it to be 200ms or less.

I have succeeded in this incredibly hackish solution which is just to "arecord" in one terminal window and "aplay" in another (which works) but this cannot possibly be the solution to my problem.

To compound the issue, my attempts at googling this have failed miserably as google believes I simply must be trying to capture the output of one application to a file. I am not. I want to monitor the sound card's input. In Apple's Logic Pro this is referred to as "software monitoring" -- I figured this would be easy. I have also seen it referred to as "play-through" but maybe this is something else.

My hopes were raised with pulseaudio -- it's just "sources and sinks" they said.

I did succeed to record a pcm file with pulseaudio's parec, alsa's arecord and jackd + jack_capture. I'm clearly missing something obvious.

parec -d alsa_input.platform-soc_sound.stereo-fallback | sox -t raw -b 16 -e signed -c 2 -r 44100 - /mnt/audio/pulsetest.wav

Clearly my os and hardware can "duplex" because I can arecord and aplay at the same time.

Can this be done or should I continue using arecord and aplay?

6
  • To clarify: do you want to monitor "Line in", by directly copying it to "Line out", or do you somehow want to monitor the file you are recording? Do you want ALSA only, Jack + ALSA, or Pulseaudio + ALSA? If you do not have low latency requirement, the simplest solution is Pulseaudio + ALSA (no Jack), then module-loopback (there are at least two stackexchange Q&A's for this, either here or on superuser).
    – dirkt
    Commented Jun 19, 2021 at 6:03
  • Directly copying it to line out. Literally exactly like any recording app would implement basic "software monitoring". That's amazing that you know of two other answers. I was not able to find those but again it's amazing that you did.
    – Plywood
    Commented Jun 19, 2021 at 16:16
  • 1
    A recording app would do it differently. Anyhow, look here or here for module-loopback, though you don't need the null sink. And I know because I've answered variants of this question quite a few times now ...
    – dirkt
    Commented Jun 19, 2021 at 17:17
  • module-loopback was the missing link. I thought "loopback" is a term relegated to capturing system audio. In the linux audio world, is there just a simple audio stream router? I don't know how this got so complicated. Can my filesystem/file be a sink? Please say yes.
    – Plywood
    Commented Jun 19, 2021 at 19:09
  • I set default-sample-format and rate in the pulse conf and now nothing works; even when I revert back to defaults. Restarted pulseaudio. Is there anything that works? Anyone? What a nightmare. It should be so simple. Streams man. Just data streams. And all alsa has to do is send stream info to the chips. What a mess.
    – Plywood
    Commented Jun 19, 2021 at 19:39

1 Answer 1

1

Please try something like

pacmd load-module module-loopback source="alsa_input.platform-soc_sound.stereo-fallback" sink="alsa_output.whatever"

where "alsa_output.whatever" is the actual name of the line-out sink. You can see the sinks with

pacmd list-sinks | grep name:

I thought "loopback" is a term relegated to capturing system audio

"Loopback" is a generic term for sending some output back to some input. You have a loopback interface for networking (lo), a loopback function on real LAN devices, an ALSA loopback driver, and the Pulseaudio loopback module, and probably many more.

I set default-sample-format and rate in the pulse conf

Don't do this, Pulseaudio does resampling. Don't mess with anything else, just establish a module-loopback connection from your source to your sink.

It should be so simple.

It is simple. I have no idea what you are doing to make it difficult.

I guess i should bust out a sniffer and probe the chips to see what alsa is doing.

This is a fun thing to do (in particular on real PC, with Intel HDA drivers - on a RaspPi it's very boring), but since you are working on the Pulseaudio level, and not ALSA, probably not helpful. As you have a working aplay and arecord, this shouldn't be an issue.


If you have the additional requirement (which you never mentioned in your question) of having the source and the sink use 96k/24bit, then this is going to be a journey in Pulseaudio: Pulseaudio is designed to run ALSA hardware sources/sinks with reasonable defaults, and then will upsample/downsample when streaming, as required. Fiddling with Pulseaudio internals to change that is tricky.

Have a look at the module-loopback docs: You can set the desired rate and format with extra parameters (and that's what you should do), but there's no guarantee that the source and sink will end up in this mode, and Pulseaudio won't do resampling somewhere.

You also didn't say where this requirement comes from; if you want to use the RaspPi to do professional-grade audio-processing (DAW, digital audio workstation), then JACK is a better choice than Pulseaudio. But all of this depends on your situation.

That said, if you are running module-loopback together with parec --rate=96000 --format=s24le, then of course it cannot change bitrate and format on a running sink, but if you already got the format and bitrate you want, then just leave it alone and be happy.

And yes, with Pulseaudio, you can have multiple streams from a source, and multiple streams into a sink.

4
  • Okay I eventually got it working with the help of --verbose and watching the log output to see that somehow the sink name stopped working. pacmd list-sources and list-sinks was incredibly helpful to get the precise names. However, now I'm trying to figure out how to get the 96k/24bit instructions down the alsa wire to the chips. I'm able to pipe parec into sox but according to my pulseaudio log I'm seeing: Created output 1 "parec" on alsa_input.platform-soc_sound.stereo-fallback with sample spec s16le 2ch 44100Hz and channel map front-left,front-right
    – Plywood
    Commented Jun 19, 2021 at 21:10
  • Edit: I can't seem to figure out where in this process pulseaudio is telling alsa to instruct my ADC and DAC to be in 96k/24 (s32le s24le either way). I still have no idea what pulseaudio's role in this even is. module-loopback solved 90% of my problems and I'm hoping I can figure out the sample rate issue. Once the module-loopback is connected, what determines the sample rate and bit rate? pulseaudio has no rate/depth arguments that I can find. parec does, but I don't want any downsampling/upsamping etc.
    – Plywood
    Commented Jun 19, 2021 at 21:16
  • Command: parec --rate=96000 --format=s24le -d alsa_input.platform-soc_sound.stereo-fallback | sox -t raw -b 24 -e signed -c 2 -r 96000 - /mnt/audio/pulse.wav (I am not sure if this is being upsampled) also see " Cannot update rate, SOURCE_IS_RUNNING, will keep using 96000 Hz" in the log which makes sense to me because I heard no rate change hiccups.
    – Plywood
    Commented Jun 19, 2021 at 21:23
  • I was able to play the raw pcm data using the command: "AUDIODEV=hw:1,0 play -r 96000 -b 24 -c 2 -e signed-integer /mnt/audio/pulse.wav" and even send this into the sink while monitoring the input amazing: paplay -d alsa_output.platform-soc_sound.stereo-fallback /mnt/audio/pulse.wav
    – Plywood
    Commented Jun 19, 2021 at 22:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .