Recording while playing doesn't work

Moderator: flatmax

Post Reply
rfelg
Posts: 3
Joined: Thu Aug 17, 2017 3:30 pm

Recording while playing doesn't work

Post by rfelg » Thu Aug 17, 2017 3:42 pm

Hi,

I recently purchased an octo sound card with RCA breakout to do the following:
a) Output mono sound from an arbitrary application on the raspberry
b) Record and analyze all output sound via playback
c) Record and analyze sound from two analog inputs from the same application as in (b)

I only have SSH access, neither a screen nor internet on the raspberry, so I installed alsa and all other packages directly via .deb files, and followed the instructions for "Manual setup" at How to setup. I skipped "High Level setup" though because I didn't have a /etc/asound.conf file. Recording and playing seems to work.

From my understanding, recording playback audio (b) requires a sound server like pulseaudio. So I also installed pulseaudio afterwards from .deb and used the system-mode config from ktb as specified here.

I now have the pulseaudio sink "output" and the sources "input" and "output.monitor". Playing and recording sound seems to work fine on all three devices if I do it separately, but while I'm playing sound on "output", I can only record on "output.monitor" and not on "input". Likewise I can not play any audio while I'm recording on "input". After playing, I can't record for about 5 seconds, and vice versa.

Do you have an idea how I could solve this? I don't really care to uninstall pulseaudio and install something else as long as I can do what I'm trying to.

I am using a very fresh installation of Raspbian Jessie with these packages:

Code: Select all

$ dpkg -l | egrep 'pulse|alsa' | awk '{print $2}'
alsa-base
alsa-tools
alsa-utils
gstreamer1.0-alsa:armhf
gstreamer1.0-pulseaudio:armhf
libpulse-dev:armhf
libpulse-mainloop-glib0:armhf
libpulse0:armhf
libpulsedsp:armhf
pulseaudio
pulseaudio-module-x11
pulseaudio-utils

flatmax
Posts: 609
Joined: Sat Jul 23, 2016 11:39 pm

Re: Recording while playing doesn't work

Post by flatmax » Sat Aug 19, 2017 7:08 pm

Hi there,

high level audio plugins with raspbian don't work with more then 2 channels, you will have to use ALSA directly .

My suggestion is to log into your Pi using ssh -X :

Code: Select all

ssh -X pi@ip
The "-X" argument will allow you to open GUIs over SSH on your local Linux box.

Install audacity.

Open audacity and try to play and record at the same time. It should work no problems. To do that load an audio file with audacity. The hit the record button... Plug RCAs from output to input and you should see the audio being recorded.

Let me know how you go and perhaps we can work out something which suits your needs - in terms of software.

Matt
Check out our audiophile quality crossovers : https://bit.ly/2kb1nzZ
Please review the Zero sound card on Amazon USA : https://www.amazon.com/dp/B075V1VNDD
---
Check out our new forum on github : https://github.com/Audio-Injector

rfelg
Posts: 3
Joined: Thu Aug 17, 2017 3:30 pm

Re: Recording while playing doesn't work

Post by rfelg » Sat Aug 19, 2017 9:39 pm

Hi,

after lots of time I figured out a decent workaround. I didn't know that asynchronous playback and recording doesn't work as stated by you here.

So I installed Jack Audio to handle that for me. Patched versions of jackd2 are available at this repository. I had to reinstall GStreamer, so it was satisfied with the older version of libjack-jackd2 as its dependency. Good articles about Jack on the Raspberry can be found here and here.

To enable the part with arbitrary applications (without a Jack interface of course) being able to output sound, I then installed pulseaudio-module-jack, so pulseaudio could run as a Jack client. I made sure pulseaudio wasn't enabled at startup and commented out the part in the /etc/pulse/default.pa about automatic detection of jack to gain a little bit control. Pulseaudio has a few quirks when it's started without a x11 or dbus-launch in the background, so after starting the Jack Server, I first do

Code: Select all

pax11publish -r
to reset the environment variables and then

Code: Select all

pulseaudio --start
pactl load-module module-jack-sink 
pactl load-module module-jack-source
An approach over a fake x11 server instead of pax11publish seems to work as well if you like that better.

Finally, I'm able to record both jack_out.monitor and jack_in while arbitrary applications are playing sound over jack_out.

Final problems about this are:
  • As you said, recording doesn't work for more than two channels for whatever reason.
    When plugging sound into the 6xRCA breakout, it arrives at stereo like this:

    Code: Select all

    | Both left and right | Left only  | Left only  |
    |   Completely dead   | Right only | Right only |
    As I said above, two channels is enough for me at the moment, but it's still a bummer.
  • Recording latencies are horrible for the analog inputs (I've had up to 30 seconds delay). At the moment I'm using the pulse sources in my GStreamer application, and I'll try to convert it to use Jack directly next week which will most likely solve that, after all I only really need pulse for the output part.
  • When using PulseAudio without Jack, the output.monitor produces silence when no audio is being played on output, and this is a desired behaviour. When using PulseAudio on Jack, jack_out.monitor produces nothing when no audio is being played, the stream simply stops. This comes with a little bit of lag when the stream is being paused and unpaused.
Nothing really critical for my special use case, but maybe the issues with sound servers should be solved for other people doing something similar.

flatmax
Posts: 609
Joined: Sat Jul 23, 2016 11:39 pm

Re: Recording while playing doesn't work

Post by flatmax » Wed Aug 23, 2017 10:23 am

OK - nice work !

Pulse must be doing some serious audio buffering to explain those latencies. It is a pity ssh -X doesn't work for your use case.

Matt
Check out our audiophile quality crossovers : https://bit.ly/2kb1nzZ
Please review the Zero sound card on Amazon USA : https://www.amazon.com/dp/B075V1VNDD
---
Check out our new forum on github : https://github.com/Audio-Injector

rfelg
Posts: 3
Joined: Thu Aug 17, 2017 3:30 pm

Re: Recording while playing doesn't work

Post by rfelg » Wed Sep 13, 2017 11:24 pm

Update:

As it turned out, porting my GStreamer application to completely use Jack Audio instead of PulseAudio was hard.

The jack plugin from the old version of gstreamer in the Raspbian Jessie repos doesn't have the capability to choose a jack port with a specified pattern. I had to compile gstreamer 1.10.4 from sources anyways, so that solved that.

With the new GStreamer and Jack, I can now finally choose every input channel separately. Since I'm staring Jack with

Code: Select all

jackd -s -d alsa -r 48000 --monitor
I can also use the monitor ports.

The recording latencies are extremely small. Looks like the Raspberry isn't really able to handle all that PulseAudio buffering.

The final problem with the stopping pipeline has been solved by a dodgy workaround. I simply output silence to PulseAudio while my application is running, so the pipeline is echoing silence when no applications play any sound.

Looks like that part of my project is finally working like a charm :)

flatmax
Posts: 609
Joined: Sat Jul 23, 2016 11:39 pm

Re: Recording while playing doesn't work

Post by flatmax » Thu Sep 14, 2017 9:52 pm

Nice one, thanks for running through this ... I am sure others will be able to use the information.

Matt
Check out our audiophile quality crossovers : https://bit.ly/2kb1nzZ
Please review the Zero sound card on Amazon USA : https://www.amazon.com/dp/B075V1VNDD
---
Check out our new forum on github : https://github.com/Audio-Injector

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests