21 Replies Latest reply on Nov 19, 2017 8:04 AM by 0d0a

    Is it possible to send audio from "SPDIF In" to the Lineout using the mixer?

    eveready1010

      I have been trying to figure this out for a while now...

       

      I can record audio coming in from the "SPDIF In" to a file, and then I can play back the same file to the Lineout, but is it possible to "mix" the incoming audio from the SPDIF In to the Lineout only using the mixer?

       

      I know it should be possible since my windows pc does allow for just this scenario (Except it used the Line In instead of SPDIF In).

        • Re: Is it possible to send audio from "SPDIF In" to the Lineout using the mixer?
          tomph

          I managed to do this by editing the Playback_to_Lineout.sh usage script so that the value after 'HPOUT2L Input 1' is AIF2RX1 and 'HPOUT2R Input 1' is AIF2RX2. I then ran that modified script and the SPDIF_record.sh usage script.

          1 of 2 people found this helpful
            • Re: Re: Is it possible to send audio from "SPDIF In" to the Lineout using the mixer?
              ragnar.jensen

              I did like youtomph, but put it all in one script. And for good measure, I added the possibility to use the equalizers on the Wolfson chip.

              The attached script takes an optional argument "eq". Run it without that argument and the sound goes straight from SPDIFin to LineOut.

               

              --

              Ragnar

              3 of 3 people found this helpful
                • Re: Re: Is it possible to send audio from "SPDIF In" to the Lineout using the mixer?
                  eveready1010

                  Thanks for the reply.  Yes, both your solution and tomph's solution worked!  I guess I just did not know what input on the mixer was the SPDIF In.

                   

                  Maybe this is for another topic, but is there a way to increase the sample rate of the SPDIF In?  The features say that the audio chip is capable of 192kHz at 24 bits.

                   

                  Is this done through the driver, mixer, etc.?  Maybe the Pi cannot handle that high of a resolution?

                    • Re: Re: Re: Is it possible to send audio from "SPDIF In" to the Lineout using the mixer?
                      ragnar.jensen

                      As I have seen it, it's automatic. If the recording application requests 192k, the drivers switch the input accordingly.

                      E.g: arecord -Dhw:0 -r 192000 -c 2 -f S32_LE myfile.wav

                      I have done recordings at 192k with a couple of different recording programs. I select the rate I want in the program and it just works

                      --

                      Ragnar

                       



                        • Re: Re: Re: Is it possible to send audio from "SPDIF In" to the Lineout using the mixer?
                          eveready1010

                          Thanks for the response.  Actually I am not trying to record anything on the Pi, just pass through audio from my PC's SPDIF Out to the Pi's SPDIF In and then out to the Line Out of the Pi.  I checked my PC and the SPDIF Out was set to 16bits, 44100 Hz.  I tried changing the format on my PC to higher settings but the sound actually got worse as I increased it.

                           

                          Here are the settings that are available on the PC:

                           

                          16bit, 44100 Hz     Sounded fine

                          16bit, 48000 Hz     Sounded the same but with a little bit of static

                          16bit, 96000 Hz     Nothing but pops and static

                          16bit, 192000 Hz     Nothing but static

                          24bit, 44100 Hz     Sounded fine

                          24bit, 48000 Hz     Sounded the same but with a little bit of static

                          24bit, 96000 Hz     Nothing but pops and static

                          24bit, 192000 Hz     Nothing but static

                           

                          Since I am not recording anything and just passing audio for SPDIF In to Line Out, is it possible to change the Pi SPDIF In Sample Rate to match the PC settings?

                            • Re: Re: Re: Re: Is it possible to send audio from "SPDIF In" to the Lineout using the mixer?
                              ragnar.jensen

                              I just record a second at the desired rate and bit depth to the null device, to force the SPDIF input to change.

                              E.g. to switch it to 96k/24bit:

                              arecord -Dhw:0 -r 96000 -c 2 -d 1 -f S24_LE /dev/null

                               

                              Here's a small script to set rate and bit depth:

                              #!/bin/bash
                              if [ "$1" = 44 ] || [ "$1" = 48 ] || [ "$1" = 96 ] || [ "$1" = 192 ]
                              then
                                recrate=$1"000"
                                [ $1 = 44 ] && recrate=44100
                              else
                                echo "Invalid rate $1"
                                echo "Valid values 44, 48, 96 and 192"
                                exit
                              fi
                              if [ "$2" = 16 ] || [ "$2" = 24 ] || [ "$2" = 32 ]
                              then
                                recformat=S${2}_LE
                              else
                                echo "Invalid bit depth $2"
                                echo "Valid values 16, 24 and 32"
                                exit
                              fi
                              arecord -q -Dhw:0 -r $recrate -c2 -d 1 -f $recformat /dev/null
                              
                              

                               

                              Save as set_SPDIF_rate.sh, make it executable with chmod +x set_SPDIF_rate.sh
                              and then run it: ./set_SPDIF_rate.sh 96 24

                               

                              --

                              Ragnar

                              4 of 4 people found this helpful
                                • Re: Re: Re: Re: Is it possible to send audio from "SPDIF In" to the Lineout using the mixer?
                                  eveready1010

                                  Wow!  That did it!  Thanks for your help and the scripts...  They were helpful.

                                    • Re: Re: Re: Is it possible to send audio from "SPDIF In" to the Lineout using the mixer?
                                      eveready1010

                                      Thanks again for all of your help.  The tips have worked great so far!

                                       

                                      Ok, sorry to keep asking about this but I have another question...

                                       

                                      When I reboot the Pi, the record settings default back to 44100kHz 16bit and my speakers emit garbled sound.  Now I did try to put the script into an upstart script and also tried putting the arecord command directly into the upstart script, but unfortunately doing so basically disabled my Pi!  I cannot SSH into it, nor login to it on the X Session.  (I did find a way to revert the settings back so I could get into it once again, by taking out the SD card and starting into Single User Mode, removing the upstart script, and then booting up the pi again.)  The strange thing is that even though I cannot use the Pi for anything else, the static happens for about 5-10 seconds during boot, and then the arecord settings kick in and the sound goes back to normal!  But the side effect of using the Upstart script is that I just cannot use the Pi for anything else.

                                       

                                      Is there some other way of having the Wolfson default to 192000Hz and 24bit besides using Upstart?  Maybe in the cmdline.txt file or the config.txt file?

                                       

                                      Or, maybe I am not writing the script correctly?  Below is the contents of my upstart script "setsound.conf".

                                       

                                      It would be nice if the settings could be applied at drive load time to prevent the 5-10 second burst of garbled sound.

                                       

                                       

                                      start on runlevel [2345] stop on runlevel [016] script   arecord -q -Dhw:0 -r 192000 -c2 -d 1 -f S24_LE /dev/null end script

                                       

                                      Also tried:

                                       

                                      start on runlevel [2345] stop on runlevel [016] script   /home/pi/Set_SPDIF_Rate.sh 192 24 end script
                                        • Re: Re: Re: Re: Is it possible to send audio from "SPDIF In" to the Lineout using the mixer?
                                          ragnar.jensen

                                          Your scripts look OK. But...

                                          I think I know what happens. When the script runs at boot-up, it runs with root privileges.

                                          I don't know why, but when root writes to /dev/null early in the boot sequence, the permissions on it change to -rw-r--r--

                                          Suddenly only root can write to /dev/null! Not good. That's probably why the login (and much else) fails.

                                          You should be able to get a text console login prompt by pressing Ctrl-Alt-F2, though.

                                           

                                          I have observed that arecord -q -Dhw:0 -r 192000 -c2 -d 1 -f S24_LE always fails if it is the first command to the sound system after boot.

                                          For some reason it likes to be tickled with its default values first, so this sequence (run in a terminal) works:

                                          arecord -q -Dhw:0 -r 44100 -c2 -d 1 -f S16_LE  /dev/null

                                          arecord -q -Dhw:0 -r 192000 -c2 -d 1 -f S24_LE /dev/null

                                           

                                          I have never used Upstart myself, I'm old and set in my ways

                                          So, I have started on an old-fashioned init script.

                                          I have quick-hacked in some code that might make it just about usable for you.

                                          On my RPi it works OK.

                                           

                                          #!/bin/sh
                                          #
                                          # wolfson sound card initscript
                                          #
                                          # This is still very much just the start of a work in progress.
                                          # For now, it only mutes/unmutes SPDIF In and Line Out
                                          # and sets the SPDIF rate and bit depth, using hardcoded defaults.
                                          #
                                          # TODO: Lots...
                                          #      A configuration file in /etc/default would be nice.
                                          #
                                          #
                                          ### BEGIN INIT INFO
                                          # Provides:          wolfson-snd
                                          # Required-Start:    $local_fs $remote_fs
                                          # Required-Stop:    $remote_fs
                                          # Default-Start:    S
                                          # Default-Stop:      0 1 6
                                          # Short-Description: Set Wolfson Audio Card SPDIF sampling rate and bit depth.
                                          # Description:       This script unmutes SPDIF In and Line Out and sets SPDIF sample rate on bootup.
                                          #                    It mutes SPDIF In and Line-Out on shutdown and reboot.
                                          ### END INIT INFO
                                          DEFAULT_SPDIF_RATE=96000
                                          DEFAULT_SPDIF_BITS=24
                                          
                                          # Don't use set -e; check exit status instead
                                          
                                          # Exit silently if ALSA package is no longer installed
                                          [ -x /usr/sbin/alsactl ] || exit 0
                                          
                                          PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
                                          MYNAME=/etc/init.d/wolfson-snd
                                          
                                          . /lib/lsb/init-functions
                                          . /usr/share/alsa/utils.sh
                                          
                                          # $1 EXITSTATUS
                                          # [$2 MESSAGE]
                                          log_action_end_msg_and_exit()
                                          {
                                                  log_action_end_msg "$1" ${2:+"$2"}
                                                  exit $1
                                          }
                                          
                                          # $1 PROGRAM
                                          executable()
                                          {
                                                  # If which is not available then we must be running before
                                                  # /usr is mounted on a system that has which in /usr/bin/.
                                                  # Conclude that $1 is not executable.
                                                  [ -x /bin/which ] || [ -x /usr/bin/which ] || return 1
                                                  which "$1" >/dev/null 2>&1
                                          }
                                          
                                          executable amixer  || { echo "${MYNAME}: Error: No amixer program available." >&2 ; exit 1 ; }
                                          executable arecord || { echo "${MYNAME}: Error: No arecord program available." >&2 ; exit 1 ; }
                                          
                                          TEMPFILE=/tmp/wolfson-snd.wav # Don't use /dev/null, it gets write-protected by root running arecord(!)
                                          # Get card number
                                          WOLFSON_CARD=`arecord -l | grep sndrpiwsp | awk '{print $2}' | sed 's/://g'`
                                          [ -z "$WOLFSON_CARD" ] && { echo "${MYNAME}: Error: Wolfson Sound Card not found!"  >&2 ; exit 1 ; }
                                          
                                          # Set defaults
                                          TARGET_CARD="hw:"${WOLFSON_CARD}
                                          EXITSTATUS=0
                                          RATE="$2"
                                          BITS="$3"
                                          [ ! -z "$4" ] && TARGET_CARD="$4"
                                          [ -z "$RATE" ] && RATE=${DEFAULT_SPDIF_RATE}
                                          [ -z "$BITS" ] && BITS=${DEFAULT_SPDIF_BITS}
                                          # [ -z "$TARGET_CARD" ] &&  TARGET_CARD="hw:0"
                                          
                                          case "$1" in
                                            start)
                                                  log_action_begin_msg "Setting up Wolfson Audio Card ${TARGET_CARD} $RATE $BITS"
                                                  amixer -q -D${TARGET_CARD} cset name='SPDIF in Switch'  on
                                          # Card needs to do something (anything?) at 44.1k for some reason before we can switch to other rates.
                                                  arecord -q -D${TARGET_CARD} -r 44100 -c2 -d 1 -f S16_LE $TEMPFILE
                                                  arecord -q -D${TARGET_CARD} -r ${RATE} -c2 -d 1 -f S${BITS}_LE $TEMPFILE
                                                  amixer  -q -D${TARGET_CARD} cset name='HPOUT2 Digital Switch' on
                                                  EXITSTATUS=$?
                                                  rm -f $TEMPFILE
                                                  log_action_end_msg_and_exit "$EXITSTATUS"
                                                  ;;
                                            stop)
                                                  # Mute SPDIF-in and Line-Out...
                                                  amixer -q -D${TARGET_CARD} cset name='HPOUT2 Digital Switch' off
                                                  amixer -q -D${TARGET_CARD} cset name='SPDIF in Switch' off
                                                  # ... and save the muted state to keep silent during bootup.
                                                  if MSG="$(alsactl store sndrpiwsp 2>&1)" ; then
                                                          EXITSTATUS=$?
                                                          sleep 1
                                                  else
                                                          log_action_cont_msg "warning: 'alsactl store${TARGET_CARD:+ $TARGET_CARD}' failed with error message '$MSG'"
                                                  fi
                                                  EXITSTATUS=$?
                                                  ;;
                                            restart|force-reload)
                                                  EXITSTATUS=0
                                                  $0 stop || EXITSTATUS=1
                                                  $0 start || EXITSTATUS=1
                                                  exit $EXITSTATUS
                                                  ;;
                                            *)
                                                  echo "Usage: $MYNAME {start | stop} [RATE] [BITS] [CARD]"  >&2
                                                  exit 3
                                                  ;;
                                          esac
                                          
                                          
                                          
                                          

                                           

                                          Save this script as /etc/init.d/wolfson-snd

                                          Only root can write in /etc/init.d, so sudo is your friend.

                                          Change the values in lines 23 and 24 to what you need and then run

                                          sudo update-rc.d  wolfson-snd start 17 S . stop 17 0 1 6 .

                                          The two dots are important!

                                           

                                          Then, try a reboot and cross your fingers

                                          Oh, and don't forget to remove your upstart script first.

                                          --

                                          Ragnar

                                          2 of 2 people found this helpful
                                            • Re: Re: Re: Re: Is it possible to send audio from "SPDIF In" to the Lineout using the mixer?
                                              kickass

                                              Hi I tried the script, but when it is loaded on bootup, it only counts secounds and never stops.

                                              In case it makes a differents, I'm running Ubuntu MATE, on kernel 3.18

                                                • Re: Is it possible to send audio from "SPDIF In" to the Lineout using the mixer?
                                                  ragnar.jensen

                                                  Hi I tried the script, but when it is loaded on bootup, it only counts secounds and never stops.

                                                  Which of the two scripts?

                                                  There is nothing in my scripts that counts seconds, so that must be something else.

                                                  What do you see on screen? Any error messages or other clues?

                                                  In case it makes a differents, I'm running Ubuntu MATE, on kernel 3.18

                                                  The scripts were made for the Wolfson card on Raspbian. Anything else is uncharted territory and anything could happen.

                                                  --

                                                  Ragnar

                                                    • Re: Re: Re: Re: Is it possible to send audio from "SPDIF In" to the Lineout using the mixer?
                                                      kickass

                                                                     It´s the init.d script. I deleted it and retried. Now I get this:

                                                       

                                                      ubuntu@UbuntuMATE:~$ sudo update-rc.d  wolfson-snd start 17 S . stop 17 0 1 6 .

                                                      [sudo] password for ubuntu:

                                                      insserv: Script wolfson-snd is broken: incomplete LSB comment.

                                                      insserv: missing `Provides:' entry: please add.

                                                      insserv: missing `Required-Start:' entry: please add even if empty.

                                                      insserv: missing `Required-Stop:'  entry: please add even if empty.

                                                      insserv: missing `Default-Start:'  entry: please add even if empty.

                                                      insserv: missing `Default-Stop:'   entry: please add even if empty.

                                                      insserv: Default-Start undefined, assuming empty start runlevel(s) for script `wolfson-snd'

                                                      insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `wolfson-snd'

                                                       

                                                                      Should I reomove the #´s from the INIT INFO?

                                                       

                                                      ### BEGIN INIT INFO

                                                          # Provides:          wolfson-snd

                                                          # Required-Start:    $local_fs $remote_fs

                                                          # Required-Stop:    $remote_fs

                                                          # Default-Start:    S

                                                          # Default-Stop:      0 1 6

                                                          # Short-Description: Set Wolfson Audio Card SPDIF sampling rate and bit dep$

                                                          # Description:       This script unmutes SPDIF In and Line Out and sets SPD$

                                                          #                    It mutes SPDIF In and Line-Out on shutdown and reboot.$

                                                          ### END INIT INFO

                                                        • Re: Is it possible to send audio from "SPDIF In" to the Lineout using the mixer?
                                                          ragnar.jensen

                                                          No, the # signs should be there.

                                                          I think you have gotten junk characters into the script. It's common when you copy-paste from web sites.

                                                          If you copy from this site, choose "expand source" and copy from there. Don't choose "view plain", it's known to introduce extra, invisible characters in some cases.

                                                           

                                                          Some of the mixer controls have changed names in the 3.18 drivers, change "SPDIF in" to "SPDIF In" on lines 76 and 88.

                                                          --

                                                          Ragnar

                                                            • Re: Re: Re: Re: Is it possible to send audio from "SPDIF In" to the Lineout using the mixer?
                                                              kickass

                                                              Unit wolfson-snd.service has begun starting up.

                                                              Apr 30 11:01:17 UbuntuMATE systemd[1660]: Failed at step EXEC spawning /etc/init.d/wolfson-snd: Exec format error

                                                              -- Subject: Process /etc/init.d/wolfson-snd could not be executed

                                                              -- Defined-By: systemd

                                                              -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel

                                                              --

                                                              -- The process /etc/init.d/wolfson-snd could not be executed and failed.

                                                              --

                                                              -- The error number returned by this process is 8.

                                                              Apr 30 11:01:17 UbuntuMATE systemd[1]: wolfson-snd.service: control process exited, code=exited status=203

                                                              Apr 30 11:01:17 UbuntuMATE systemd[1]: Failed to start LSB: Set Wolfson Audio Card SPDIF sampling rate and bit depth..

                                                              -- Subject: Unit wolfson-snd.service has failed

                                                              -- Defined-By: systemd

                                                              -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel

                                                              --

                                                              -- Unit wolfson-snd.service has failed.

                                                              --

                                                              -- The result is failed.

                                                              Apr 30 11:01:17 UbuntuMATE systemd[1]: Unit wolfson-snd.service entered failed state.

                                                              Apr 30 11:01:17 UbuntuMATE systemd[1]: wolfson-snd.service failed.

                                                              Apr 30 11:01:17 UbuntuMATE polkitd(authority=local)[617]: Unregistered Authentication Agent for unix-process:1655:232095 (

                                                              Apr 30 11:01:17 UbuntuMATE sudo[1645]: pam_unix(sudo:session): session closed for user root

                                                               

                                                              ubuntu@UbuntuMATE:~$ sudo chmod 755 /etc/init.d/wolfson-snd

                                                              ubuntu@UbuntuMATE:~$ sudo /etc/init.d/wolfson-snd start

                                                              [....] Starting wolfson-snd (via systemctl): wolfson-snd.serviceJob for wolfson-snd.service failed. See "systemctl status wolfson-snd.service" and "journalctl -xe" for details.

                                                              failed!

                                                      • Re: Is it possible to send audio from "SPDIF In" to the Lineout using the mixer?
                                                        eveready1010

                                                        This script worked perfectly up until about a month ago, when the SD card would no longer write, so I was forced to rebuild the Wolfson Pi with the latest from Driver fixes and updates to kernel 3.18.16 and 4.0.5 but I am struggling with getting the script to work with the new build.  I have tried the script with the 4.1.19 and 4.4.6 build on the PiB with the Wolfson card, and also on the Pi2 with the Cirrus Card, but I get the same thing:

                                                         

                                                        $ wolfson-snd start

                                                        [....] Setting up Wolfson Audio Card hw:0 192000 24...amixer: Cannot find the given element from control hw:0

                                                         

                                                        Then it just hangs.  So I CTRL-Z:

                                                         

                                                        ^Z
                                                        [1]+  Stopped                 ./wolfson-snd start

                                                         

                                                        And then I looked in the /tmp folder, and there were a bunch of .wav files:

                                                        wolfson-snd-01.wav

                                                        wolfson-snd-02.wav

                                                        ...

                                                        All were exactly 44 bytes long.

                                                         

                                                        Plus the arecord process and the wolfson-snd process were still in memory and needed to be killed.

                                                         

                                                        It seems that there have been some changes between the original version and the current version of the driver, and/or alsa.

                                                         

                                                        It seems that the card does at least partially work, because I can play a wav file to the Line Out without issues.  The one thing that I noticed is that there are a lot of levels missing in the alsamixer application.  A bunch say "None" instead of having an adjustable volume or level control.  Not sure why this is that way.

                                                         

                                                        I have tried going through the script and running each command individually, and there are many anomalies.  Like some of the amixer commands complain that the control does not exist.  I tried running the amixer command to get all of the controls and output it to a file, which I then looked for an alternate or different but similarly named control.  It seemed I was partially successful at finding some but not all of the new control names.

                                                         

                                                        I am not sure what else to do.  I know this exact same card (WolfsonPi) was able to do what the script is designed to tell it to do, but now suddenly it no longer works.

                                                         

                                                        Any help or a point in the right direction would be appreciated.

                                                  • Re: Is it possible to send audio from "SPDIF In" to the Lineout using the mixer?
                                                    cirrusaudiofanatic

                                                    I had the problem of using the cirrus for converting spdif to analog line out with lots of noise.

                                                     

                                                    By using your script I was able to eliminate that noise:

                                                    "set_SPDIF_rate.sh 48 16"

                                                     

                                                    By using your script in this way i got back to that terrible noise which seems to be the default variant:

                                                    "set_SPDIF_rate.sh 44 16"

                                          • Re: Is it possible to send audio from "SPDIF In" to the Lineout using the mixer?
                                            0d0a

                                            How about doing this withe new 4.9 kernel? Any idea?