Jump to content

Configuring Orange PI PC for analogue Line-Out jack audio output (and Simultaneous HDMI output with Software Mixing)


Recommended Posts

Hi All,

 

After I accomplished my IR Red Key Rick Rolling experiment the other day with much success, and from general end-luser use with Armbian, there were two things which irritated me, which are namely due to the default ALSA configuration that comes with stock Debian and that Armbian inherits. These were:

 

Update: 11 September 2017. This guide will not work for newer Armbiam (Debian) installations which comes with Pulseaudio by default. If you really want what this tutorial provides, you will need to uninstall pulseaudio first: sudo apt-get remove pulseaudio

 

1) You can't have simultaneous applications using an Audio device. So, how about if I want to stream Internet Radio with 'Radio Tray' but also get system alert sounds, or anything else? Out of luck, you'll get (for example):

[ao/alsa] Playback open error: Device or resource busy

2) I want to actually have audio going out of the 3.5mm jack (don't really care about video out), better still if it's the same/simultaneous to what is going out via. HDMI. That means if I have a HDMI TV connected then I can get the sound from the TV, if I don't, then I can just use the 3.5mm jack (i.e. If I'm using my Pi to play Rick Astley headless/without a TV). No need to keep editing /etc/asound.conf every time.

 

post-1936-0-92115500-1473032220_thumb.jpg

 

Solution?

 

Step 1) Fix the mute on the analog Line-Out in alsamixer (for a start)

 

There's a lot of noise out there about people not being able to get any sound our of the analog Line-Out jack even when having changed /etc/asound.conf. The reason for this is likely due to a mute by default on the analog audio line-out (i.e. the 3.5mm headphone jack) in alsa that you would unlikely to be aware of. I only found this out thanks to a comment here, otherwise I would have thrown by Pi PC out the window today.

 

So to fix, you need to type in the console:

sudo alsamixer

Then F6 select the 'audiocodec', then tap the right arrow key to select the 'Audio lineout [Off]' item.

 

post-1936-0-74472100-1473032794_thumb.jpg

 

Press 'm' and you'll get the green 'OO', which means it's now active.

 

post-1936-0-07855500-1473032798_thumb.jpg

 

Exit alsamixer, and when you're back at the console type:

sudo alsactl store 0

... to store you mixer settings.

 

For your information, the mixer settings are stored to the file:

/var/lib/alsa/asound.state 

... and if you do a diff of this file after having made the changes in alsamixer, this is what is changed in the alsa asound.state file:

       control.9 {                                                     control.9 {
                iface MIXER                                                     iface MIXER
                name 'Audio lineout'                                            name 'Audio lineout'
                value false                                   |                 value true
                comment {                                                       comment {
                        access 'read write'                                             access 'read write'
                        type BOOLEAN                                                    type BOOLEAN
                        count 1                                                         count 1
                }                                                               }
        }                                                               }

Step 2) Change the /etc/asound.conf file

 

As you might or might not be aware, the default /etc/asound.conf file looks something like this:

 

pcm.!default {
    type hw
    card 1
}


ctl.!default {
    type hw
    card 1
}
All it is configured to do is give applications direct access to the hardware audio device, and pump the sound either out to the analogue line-out ('card 0') or via HDMI ('card 1'). Pretty basic, but does the job.
 
However, what I wanted was two things:
  1. Software mixing before the resulting PCM/Sound is sent to the hardware audio device - This enables me to listen to Internet Radio and Youtube at the same time...
  2. Simultaneous Output to both HDMI and analog line-out.

If you want only (1) above, and only via HDMI, then the /etc/asound.conf file is this:

pcm.!default {
  type plug
  slave.pcm "dmixer"
}

pcm.dmixer  {
  type dmix
  ipc_key 1024
  slave {
    pcm "hw:1,0" # "hw:1,0" means HDMI change to "hw:0,0" for analog lineout jack output
    period_time 0
    period_size 1024
    buffer_size 4096
    rate 44100
  }
  bindings {
    0 0
    1 1
  }
}

ctl.dmixer {
  type hw
  card 0
}

ctl.!default {
    type hw
    card 0
}

If you want (1) and (2) (which of course you do), then the /etc/asound.conf file is this:

# Thanks to: http://alsa.opensrc.org/Asoundrc#Dupe_output_to_multiple_cards
#            https://sourceforge.net/p/alsa/mailman/message/33476395/
# Check that a MUTE doesn't exist on the Audio Line Out for Orange PI PC
# or you'll get no sound other than via HDMI


pcm.!default {
   type plug
   slave.pcm "duplicate"
}


ctl.!default {
    type hw
    card 0
}


# Create the Software Mixer for HDMI and then link to hardware
pcm.hdmi-dmixer  {
  type dmix
  ipc_key 1024
  slave {
    #pcm "hw:0,0"
   # pcm "duplicate"
    pcm "hdmi-hw"
#    pcm "analog-hw"
    period_time 0
    period_size 1024
    buffer_size 4096
    rate 44100
  }
  bindings {
    0 0
    1 1
  }
}


ctl.hdmi-dmixer {
  type hw
  card 0
}


# Create the Software Mixer for Analogue Out and then link to hardware
pcm.analog-dmixer  {
  type dmix
  ipc_key 2048
  slave {
    #pcm "hw:0,0"
   # pcm "duplicate"
 #   pcm "hdmi-hw"
    pcm "analog-hw"
    period_time 0
    period_size 1024
    buffer_size 4096
    rate 44100
  }
  bindings {
    0 0
    1 1
  }
}


ctl.analog-dmixer {
  type hw
  card 0
}




# Route the audio requests to both hardware devices via the mixer.
# For some reason we can't have one mixer and then route to two hardware
# devices (would be more efficient).
pcm.duplicate {
    type route
    slave.pcm {
        type multi
        slaves {
            a { pcm "analog-dmixer" channels 2 }
            h { pcm "hdmi-dmixer" channels 2 }
        }
        bindings [
            { slave a channel 0 }
            { slave a channel 1 }
            { slave h channel 0 }
            { slave h channel 1 }
        ]
    }
    ttable [
        [ 1 0 1 0 ]
        [ 0 1 0 1 ]
    ]
}


ctl.duplicate {
        type hw;
        card 0;
}




# Physical Output Device Mappings - Analogue and HDMI for Orange PI PC
pcm.analog-hw {
    type hw
    card 0
}


pcm.hdmi-hw {
    type hw
    card 1
}
 

 

There you have it. The only downside is that CPU usage for playing music will increase a bit as ALSA will essentially route inputs from applications to two Software Mixers, which are connected to the HDMI and Analog Line-Out hardware devices separately. For some reason you can't have a single Software Mixer route to two hardware devices (or I couldn't get it to work), but whatever. We're talking 20% CPU usage vs. 10% on one core, to play music.
 
 

 

Edited by AnonymousPi
Updated to include notice that it won't work with pulseaudio installed.
Link to comment
Share on other sites

Perform 'Step 1' per my guide above, then copy-paste the /etc/asound.conf file to be:

pcm.!default {
  type plug
  slave.pcm "dmixer"
}

pcm.dmixer  {
  type dmix
  ipc_key 1024
  slave {
    pcm "hw:0,0" # "hw:1,0" means HDMI change to "hw:0,0" for analog lineout jack output
    period_time 0
    period_size 1024
    buffer_size 4096
    rate 44100
  }
  bindings {
    0 0
    1 1
  }
}

ctl.dmixer {
  type hw
  card 0
}

ctl.!default {
    type hw
    card 0
}

The hint on what to do was in my comment within the suggested asound.conf in my original post:

# "hw:1,0" means HDMI change to "hw:0,0" for analog lineout jack output
Link to comment
Share on other sites

How if there are mentioned microphone arrays in the config file? Are you sure, because this ps3 eye camera doesn't have speakers, just microphones.

 

Aha nevermind you meant regarding your tutorial that its meant just for audio output.

Link to comment
Share on other sites

Thanks @AnonymousPi but I try both config and I get cutting whit noise on hdmi while analogue outline working well.

what did i do wrong?

can it be a bad configuration on alsamixer ? 

lqqqqqqqqqqqqqqqqqqqqqqqqqqqqq AlsaMixer v1.0.28 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
x Card: audiocodec                                    F1:  Help               x
x Chip:                                               F2:  System information x
x View: F3:[Playback] F4: Capture  F5: All            F6:  Select sound card  x
x Item: Lineout volume control                        Esc: Exit               x
x                                                                             x
x     lqqk     lqqk                                         lqqk     lqqk     x
x     xaax     xaax                                         xaax     xaax     x
x     xaax     xaax                                         xaax     xaax     x
x     xaax     xaax                                         xaax     xaax     →
x     xaax     xaax                                         xaax     xaax     →
x     xaax     xaax                                         xaax     xaax     →
x     xaax     xaax                                         xaax     xaax     →
x     xaax     xaax                                         xaax     xaax     →
x     xaax     xaax                                         xaax     xaax     →
x     xaax     xaax                                         xaax     xaax     →
x     xaax     xaax                                         xaax     xaax     x
x     xaax     xaax                                         xaax     xaax     x
x     mqqj     mqqj     lqqk     lqqk     lqqk     lqqk     mqqj     mqqj     x
x                       xOOx     xOOx     xOOx     xOOx                       x
x                       mqqj     mqqj     mqqj     mqqj                       x
x     100      100                                          100      100      x
x  <Lineout >ADC inpu Audio ad Audio ad Audio li Audio li LINEIN_G MIC1 boo   x
mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
Link to comment
Share on other sites

Problem Solved alsamixer `hdmi audio function` may set to `pcm` [open alsamixer / press F6 / select hdmi ... / up-down to find pcm]

lqqqqqqqqqqqqqqqqqqqqqqqqqqqqq AlsaMixer v1.0.28 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
x Card: sndhdmi                                       F1:  Help               x
x Chip:                                               F2:  System information x
x View: F3:[Playback] F4: Capture  F5: All            F6:  Select sound card  x
x Item: hdmi audio format Function [pcm]              Esc: Exit               x
x                                                                             x
x                                                                             x
x                                                                             x
x                                                                             x
x                                                                             x
x                                                                             x
x                                                                             x
x                                                                             x
x                                    pcm                                      x
x                        <hdmi audio format Function>                         x
x                                                                             x
x                                                                             x
x                                                                             x
x                                                                             x
x                                                                             x
x                                                                             x
x                                                                             x
x                                                                             x
mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
Link to comment
Share on other sites

 

Perform 'Step 1' per my guide above, then copy-paste the /etc/asound.conf file to be:

pcm.!default {
  type plug
  slave.pcm "dmixer"
}

pcm.dmixer  {
  type dmix
  ipc_key 1024
  slave {
    pcm "hw:0,0" # "hw:1,0" means HDMI change to "hw:0,0" for analog lineout jack output
    period_time 0
    period_size 1024
    buffer_size 4096
    rate 44100
  }
  bindings {
    0 0
    1 1
  }
}

ctl.dmixer {
  type hw
  card 0
}

ctl.!default {
    type hw
    card 0
}

The hint on what to do was in my comment within the suggested asound.conf in my original post:

# "hw:1,0" means HDMI change to "hw:0,0" for analog lineout jack output

 

Hi, i did configure it, like you mentioned, it works great, i am using Orange Pi PC with Retro Orange and now I can have HDMI video only and analog audio only working simultaneously in games and menu. But when I select Kodi, it only allows to select one audio output and this is HDMI audio. I would like to have option to select HDMI or analog. Do you think that this is because config change or that Kodi is bugged? Thanks

Link to comment
Share on other sites

On 1/26/2017 at 3:36 AM, lakyljuk said:

 i am using Orange Pi PC with Retro Orange and now I can have HDMI video only and analog audio only working simultaneously in games and menu.

Can you help/tell me how you get games sound? 

 

Followed them step above and got my sound thru avjack but when play games there's no sound. I figured it is in the retro configuration but couldn't find any info except for raapberry.

Link to comment
Share on other sites

On 2017-4-30 at 0:31 AM, Armnlegs said:

Can you help/tell me how you get games sound? 

 

Followed them step above and got my sound thru avjack but when play games there's no sound. I figured it is in the retro configuration but couldn't find any info except for raapberry.

Had the same issue...

 

underneath ipc_key 1024 for both hdmi and analog

put ipc_perm 0666

this will give all users permission.

reboot and enter command speaker-test to verify

Link to comment
Share on other sites

On ‎05‎/‎20‎/‎2017 at 12:27 PM, GoNzOBiRdY said:

Had the same issue...

 

underneath ipc_key 1024 for both hdmi and analog

put ipc_perm 0666

this will give all users permission.

reboot and enter command speaker-test to verify

Had my project on hold and now just getting back to the game.

Just so that we are on the same page. The modification is for IF:

Retro-Orangepi sound = Yes

Game sound = No

 

This will give games sound?

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines