element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Raspberry Pi Forum Is it possible to send audio from "SPDIF In" to the Lineout using the mixer?
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
Raspberry Pi Wishlist
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 21 replies
  • Answers 3 answers
  • Subscribers 678 subscribers
  • Views 3449 views
  • Users 0 members are here
  • raspberry_pi
  • raspeberry_pi_accessories
Related

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

eveready1010
eveready1010 over 11 years ago

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).

  • Sign in to reply
  • Cancel
Parents
  • Former Member
    0 Former Member over 11 years ago

    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.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to Former Member

    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

    Attachments:
    https://community.element14.com/cfs-file/__key/communityserver-discussions-components-files/91/Listen_5F00_to_5F00_SPDIF.sh
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to eveready1010

    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

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • eveready1010
    0 eveready1010 over 11 years ago in reply to Former Member

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

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • eveready1010
    0 eveready1010 over 11 years ago in reply to 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
    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to eveready1010

    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 image

    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 image

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

    --

    Ragnar

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • eveready1010
    0 eveready1010 over 11 years ago in reply to Former Member

    Yes!  That also worked like a charm!

     

    Thanks for the help!

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to Former Member

    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

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to Former Member

    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

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to Former Member

                   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

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to Former Member

    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

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to Former Member

    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!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • Former Member
    0 Former Member over 10 years ago in reply to Former Member

    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!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • Former Member
    0 Former Member over 10 years ago in reply to Former Member

    Ok, I gave up. I´ll just use .desktop shortcuts for a little more convenience. I put one in the autostart folder, but it still doesn´t run automatically:

     

     

     

    GNU nano 2.2.6Datei: /etc/xdg/autostart/Setrate4816.desktop         

     

    [Desktop Entry]

    Type=Application

    Name=Setrate4816

    Exec=/usr/local/bin/SetRate48_16.sh

    Terminal=true

    X-MATE-Autostart-enabled=true

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube