Monitor Pisound input via output while writing to microSD card?


#1

Hi,

Is there a way to monitor the Pisound’s 6.35 mm input jack via headphones plugged into the 6.35 mm output jack while simultaneously writing to the local Raspberry Pi’s microSD card?

We can do each individually, but not both simultaneously…

We’ve successfully got a hydrophone (underwater microphone) plugged into (and powered by) the Pisound 6.35 mm input jack. I can monitor the signal as I adjust the input gain by plugging headphones into the Pisound 6.35 mm output jack after issuing this command:

arecord -f S16_LE -r 48000 -D hw:1,0 -c 2 | aplay -D hw:1,0 -c 2

Once the gain is set, I kill the arecord-aplay process and then begin writing the signal to the microSD card (e.g. in HLS = HTTP Live Streaming format) using something like the following ffmpeg command:

ffmpeg -f alsa -ac 2 -ar 48000 -i hw:1,0 -f segment -segment_list "/tmp/hls/live.m3u8" -segment_list_flags +live -segment_time 10 -segment_format mpegts -ar 4800 -ac 2 -acodec aac "/tmp/hls/live%03d.ts"

(That’s slightly simplified, but gives you an idea of how we’re using ffmpeg to read from the write audio card,device. You can see all the streaming code in our Orcasound orcanode Github repository.)

Thanks in advance! Any solution for sharing/splitting/teeing the input from a hardware device would be welcome, whether it’s a Linux audio trick or a way of using ffmpeg (or any other opensource software) that we’ve not yet discovered.

If we could monitor while writing it would really help us in two ways:

  1. we could adjust levels without interrupting the continuous recording/streaming we’re trying to do, and
  2. we could play ocean sounds locally (e.g. in an aquarium or museum) while simultaneously streaming the sounds to our live-listening web app – live.orcasound.net

Thanks in advance for any guidance you can offer us,
Scott in Seattle (WA, USA)


#2

I use jack audio and jack_capture and record the input while listening to it. Maybe that helps?


#3

Hi, you ALSA utility commands take exclusive control of the audio hardware, but this can be worked around by placing a tee command which forwards std output of first program to a file, and also to the next program via its own std output. See my reply on [Solved] No audio input going to output for an example command doing this.

Alternatively, you may switch to the Jack backend, it allows a bit more flexible use of audio signals involving multiple programs, see here: Overruns with arecord at 192 khz 2 channel. It only details getting audio input stored to a file, but you should be able to just connect the Pisound’s input port directly to the output using jack_connect.


#4

Thank you both, @Giedrius and @microfx! I’ll try the tee method in the short-term, but in the longer-term we are migrating to the Jack backend, so we’ll begin testing that method, too. I’ll report back re success/failure soon…

Best regards,
Scott in Seattle