Monitor audio playback

Raspberry Pi related support

Monitor audio playback

Postby ofurpesi » 05 Mar 2018, 15:31

Hi guys

Just wondering if it´s possible to monitor the actual audio playback?

Right now i´m monitoring the MPD service using zabbix, and that works fine. But if someone where to unplug the cord from the jack output, the MPD service would of course keep running and play, but the audio would not be audible.
ofurpesi
 
Posts: 2
Joined: 23 Feb 2018, 18:32

Re: Monitor audio playback

Postby janui » 05 Mar 2018, 17:53

Hi ofurpesi,
ofurpesi wrote:Just wondering if it´s possible to monitor the actual audio playback?
The following command (after logging in via SSH) will return ‘closed’ per registered soundcard when nothing is playing:
Code: Select all
cat /proc/asound/card?/pcm?p/sub?/hw_params
If something is playing it will return information about the actual sound quality settings. Try this:
Code: Select all
cat /proc/asound/card?/pcm?p/sub?/hw_params | grep -v closed
It will return the quality setting when something is playing and nothing when inactive. This will also work for Spotify, UPnP/DLNA and AirPlay when MPD is inactive.
janui
User avatar
janui
 
Posts: 704
Joined: 20 Dec 2014, 12:55
Location: Ollanda

Re: Monitor audio playback

Postby szymonz » 10 Mar 2018, 10:15

Hi,

I was facing the similar challenge and the post above has inspired me to solve my problem. The goal was to turn on my AVR (ARCAM350) when RPi is playing musing and turn it off when there is no music. So I have created 3 files:

1) To control my Arcam AVR
Code: Select all
#! /bin/sh
# avr300

ARCAM=/dev/ttyUSB0

case "$1" in
  on)
    stty 38400 < $ARCAM
        echo -e "PC_*11\r" > $ARCAM
        echo -e "PC_110\r" > $ARCAM
  ;;
  off)
    stty 38400 < $ARCAM
        echo -e "PC_*10\r" > $ARCAM
  ;;
  cmd)
    if [ -n "$2" ]; then
      stty 38400 < $ARCAM
      echo -e "$2\r" > $ARCAM
    else
      echo "Usage: $0 $1 {command}"
    fi
  ;;
  *)
    echo "Usage: $0 {on | off |cmd command}"
    exit 1
  ;;
esac
exit 0


2) Is a Servicing monitoring soundcard (based on post above)
Code: Select all
#! /bin/sh
# ctrlavr

TMPFILE=/tmp/test_sound.tmp
TURNOFFDELAY=300
TERNOFFPULL=10
TESTSOUNDPULL=1
COUNTOFSILENCE=0

soundTest()
{
        cat /proc/asound/card?/pcm?p/sub?/hw_params | grep -v closed > "$TMPFILE"
        FILESIZE=$(stat -c%s "$TMPFILE")

        return $FILESIZE
}

#wait for playing
while sleep $TESTSOUNDPULL;
do
         soundTest
         if [ $? -ne 0 ]; then
                #Playing turn on amp
                echo "Playing audio ..."
                avr300 on
                COUNTOFSILENCE=0

                #Wait for stop playing
                soundTest
                while [ $? -ne 0 ];
                do
                        sleep $TERNOFFPULL
                        soundTest
                done
                echo "Sound of silence ..."
         else
                COUNTOFSILENCE=$(($TESTSOUNDPULL + $COUNTOFSILENCE))

                if [ $COUNTOFSILENCE -gt $TURNOFFDELAY ]; then
                        COUNTOFSILENCE=0
                        echo "Turn off external AMP"
                        avr300 off
                fi
         fi
done


3) Is Service descriptor for ArchLinux to start service on boot

Code: Select all
Description=Turns on/off the Arcam AVR300
Requires=
After=

[Service]
Type=simple
ExecStart=/usr/local/bin/ctrlavr
TimeoutSec=0

[Install]
WantedBy=multi-user.target


Script no. 1 & 2 are located in /usr/local/bin/ and needs to have execution priviledges.
File no. 3 is located in /usr/lib/systemd/system/ and needs to be enabled using systemctl enable command.

I am not a Linux geek, so please do not be cruel about judging my scripting skills ;-). Any comments are welcome and I hope you can find it useful to make your own RPI network audio player controlling your AVR.

Have a fun,
Szymon
szymonz
 
Posts: 1
Joined: 10 Mar 2018, 09:59

support RuneAudio Donate with PayPal


Return to Raspberry Pi

Who is online

Users browsing this forum: Bing [Bot] and 15 guests