WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Correct Method To Swap Between HDMI and Analog Sound on TC 13.0.3  (Read 3038 times)

Offline onelife

  • Full Member
  • ***
  • Posts: 141
Hi there,

I'm wondering what is the correct method to have "hot swap" between HDMI and 3,5mm jack now on TC 13.0.3.

Previously I used to use commands such as :

amixer cset numid=3 2

But now that the sound seems to have changed this no longer works - Is there now a new method? I see aplay -l lists HDMI and Headphones - So perhaps we now use those names?

Any direction will be appreciated.

Thanks

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1243
Re: Correct Method To Swap Between HDMI and Analog Sound on TC 13.0.3
« Reply #1 on: October 07, 2021, 09:29:26 PM »
No swapping is needed, there are now separate devices.

Headphones.   And B1. (And B2 if you have a pi4)

Offline onelife

  • Full Member
  • ***
  • Posts: 141
Re: Correct Method To Swap Between HDMI and Analog Sound on TC 13.0.3
« Reply #2 on: October 08, 2021, 02:49:35 AM »
Sure, but how do I tell the system even IF I have an HDMI cable connected - I want sound on the 3,5mm jack.

Currently the issue is I HAD a screen connected and it obviously persisted example /etc/asound.conf perhaps and now the sound is ONLY on HDMI and even though NO screen is connected anymore, the state I assume has been persisted and now I can't get audio out the 3.5mm jack.

As I say, I often have cases where I need sound out the 3.5mm jack even though there is an HDMI cable plugged in.

How would I do that?

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14798
Re: Correct Method To Swap Between HDMI and Analog Sound on TC 13.0.3
« Reply #3 on: October 08, 2021, 04:58:29 AM »
Many alsa cli and gui apps allow you to specify which alsa device to use, for example:
Code: [Select]
$ speaker-test -Ddefault:1 -c2 -t wav -l1
...to play through device 1 (use "aplay -l" to see which is which).

Offline onelife

  • Full Member
  • ***
  • Posts: 141
Re: Correct Method To Swap Between HDMI and Analog Sound on TC 13.0.3
« Reply #4 on: October 08, 2021, 05:12:11 AM »
I'm not using an GUI so looking for the amixer cset command that would work if that is still possible?

I've used aplay -L to get the cards but can't workout the syntax to make it work

how do I set the Headphones as the default without a GUI app? Even alsamixer terminal ui isn't letting me "set" and persist the option.

Any ideas?

Offline Greg Erskine

  • Sr. Member
  • ****
  • Posts: 404
Re: Correct Method To Swap Between HDMI and Analog Sound on TC 13.0.3
« Reply #5 on: October 08, 2021, 06:35:22 AM »
The ALSA default is card 0, which may or may not be Headphones.

b1 or b2 will only appear when the HDMI cable is plugged in. It may take card 0 position instead of Headphones.

For pCP we use to output of " aplay -L | = " and pass it to the sound application (squeezelite). ie hw:CARD=b1,DEV=0

I don't know how to do this with aplay. Follow link below to find some examples.

I advise against using the card number although it seems to be the universal recommendation. Pass the card name via the application command line (if possible).

Another common recommendation will be to redefine the default ALSA card by creating .asoundrc

https://www.volkerschatz.com/noise/alsa.html

ALSA is very flexible so it is more likely you will get 6 ways to do the same thing.





Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14798
Re: Correct Method To Swap Between HDMI and Analog Sound on TC 13.0.3
« Reply #6 on: October 08, 2021, 06:44:57 AM »
You can use the command "sudo alsactl store" after alsa has been set up and then add /usr/local/etc/alsa/asound.state to your backup to make alsa changes persist.

If you search online, there are a couple of ways to swap alsa devices so that the headphone jack will become the default rather than hdmi.

Offline onelife

  • Full Member
  • ***
  • Posts: 141
Re: Correct Method To Swap Between HDMI and Analog Sound on TC 13.0.3
« Reply #7 on: October 08, 2021, 07:34:53 AM »
Not having any luck :( - I have multiple boards - 1 I have had a screen connected at some point shows as :

Code: [Select]
snb@snb:~$ aplay -L
null
    Discard all samples (playback) or generate zero samples (capture)
default
hw:CARD=b1,DEV=0
    bcm2835 HDMI 1, bcm2835 HDMI 1
    Direct hardware device without any conversions
plughw:CARD=b1,DEV=0
    bcm2835 HDMI 1, bcm2835 HDMI 1
    Hardware device with all software conversions
sysdefault:CARD=b1
    bcm2835 HDMI 1, bcm2835 HDMI 1
    Default Audio Device
dmix:CARD=b1,DEV=0
    bcm2835 HDMI 1, bcm2835 HDMI 1
    Direct sample mixing device
hw:CARD=Headphones,DEV=0
    bcm2835 Headphones, bcm2835 Headphones
    Direct hardware device without any conversions
plughw:CARD=Headphones,DEV=0
    bcm2835 Headphones, bcm2835 Headphones
    Hardware device with all software conversions
sysdefault:CARD=Headphones
    bcm2835 Headphones, bcm2835 Headphones
    Default Audio Device
dmix:CARD=Headphones,DEV=0
    bcm2835 Headphones, bcm2835 Headphones
    Direct sample mixing device

And I can't move the sound to the analog port?

Then another I have never plugged a screen into shows aplay -L as :

Code: [Select]
snb@snb:/home/snb# aplay -L
null
    Discard all samples (playback) or generate zero samples (capture)
default
hw:CARD=Headphones,DEV=0
    bcm2835 Headphones, bcm2835 Headphones
    Direct hardware device without any conversions
plughw:CARD=Headphones,DEV=0
    bcm2835 Headphones, bcm2835 Headphones
    Hardware device with all software conversions
sysdefault:CARD=Headphones
    bcm2835 Headphones, bcm2835 Headphones
    Default Audio Device
dmix:CARD=Headphones,DEV=0
    bcm2835 Headphones, bcm2835 Headphones
    Direct sample mixing device

This system has never had a screen connected and is playing by default out the 3.5mm jack.

Surely as there used to be a amixer cset numid= type command that can allow me to move the sound?

ANY HELP PLEASE - I'm going in circles and can't see why the HDMI port is still detected when there is no screen connected - I tried to delete the previous alsa store but still stays the same.

Any ideas - I just need to move the sound between HDMI or 3.5mm jack by simple command?

On previous TC this was as simple as :

Code: [Select]
amixer cset numid=3 1
sudo alsactl store


OR for HDMI

Code: [Select]
sudo amixer cset numid=3 2
sudo alsactl store

But now no idea :(





Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1243
Re: Correct Method To Swap Between HDMI and Analog Sound on TC 13.0.3
« Reply #8 on: October 08, 2021, 08:38:59 AM »
You are not understanding.  You can only change it by changing the device.

When you want to use headphones, you have to use the "Headphone" device.   When you want to use HDMI, you have to use the "b1" device.

There is no other way around it.   That is how the linux kernel has setup the device drivers.

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14798
Re: Correct Method To Swap Between HDMI and Analog Sound on TC 13.0.3
« Reply #9 on: October 08, 2021, 10:52:07 AM »
Does something like this work:
Code: [Select]
$ aplay -D sysdefault:CARD=Headphones music.wav

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: Correct Method To Swap Between HDMI and Analog Sound on TC 13.0.3
« Reply #10 on: October 08, 2021, 11:40:18 AM »
Just to be clear, alsa apps don't support dynamic redirection. Existing sound plays on the device you specified. If you want existing sound to get transferred, without restarting the app, you need a layer like pulseaudio or pipewire.
The only barriers that can stop you are the ones you create yourself.

Offline onelife

  • Full Member
  • ***
  • Posts: 141
Re: Correct Method To Swap Between HDMI and Analog Sound on TC 13.0.3
« Reply #11 on: October 10, 2021, 03:12:29 AM »
Thank you for the help - Appreciated.

I get that the application then needs to call the "correct" sound card - BUT why then on device A does TC detect HDMI when it is no longer connected but used to be and on device B that never had a screen only have Headphones?

Both device A and B are the same version of Raspberry pi - The only difference is in A, a screen was connected at some point but no longer.

How would I "revert" or remove the HDMI driver / default setting? As I will only need that in some cases when a screen is actually connected.

I already have many other Raspberry Pis in "the field" so I can't easily update my application to change sound card when on the existing systems the sound I guess is already on the "default" as there is only 1 card so there is "nothing todo as such".

Can I do a rmmod and it will revert the driver back to initial state and then that will re look at what hardware is present and with no screen connected by device A will then show the same as device B?

Thanks again and any suggestions.



« Last Edit: October 10, 2021, 03:14:40 AM by onelife »

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14798
Re: Correct Method To Swap Between HDMI and Analog Sound on TC 13.0.3
« Reply #12 on: October 10, 2021, 03:43:45 AM »
By default tinycore does not remember any settings, so if your RPi believes an hdmi device is connected, it is probably because the setting is in your backup.

If you want a particular device to always be the default you could, for example, create an .asoundrc that sets "Headphones" as the default and save this in your backup.

Offline mocore

  • Hero Member
  • *****
  • Posts: 633
  • ~.~
Re: Correct Method To Swap Between HDMI and Analog Sound on TC 13.0.3
« Reply #13 on: October 11, 2021, 02:05:14 PM »
if your RPi believes an hdmi device is connected, it is probably because the setting is in your backup.

https://www.raspberrypi.com/documentation/computers/config_txt.html#file-format


Here is an example file:

# Force the monitor to HDMI mode so that sound will be sent over HDMI cable
hdmi_drive=2

so from the above the pi firmware( on gpu!) pre-configures some hdmi things that can affect audio path default  ,
..and firmware reads config.txt defaults that can be changed

this post https://forums.raspberrypi.com/viewtopic.php?t=263942#p1606122


mentions posible alsa sloution ( * presumably with whatever raspbian! kernel and alsa configured defaults at Feb 2020 when the post was writen  )

and another posible method changing config.txt setings

also talks of  " looking at switching default" presumably relating to the firmware , perhaps the complications hit at some kernel related things idk tbh 

wrt rpi config diffrences ,
because the (gpu) firmware handles some pre linux configuration on rpi
 perhaps the firmware version's are diffrent and the firmware defaults (config.txt) have changed between versions ( which happens as is mentioned in the the above post)


« Last Edit: October 11, 2021, 02:15:48 PM by mocore »

Offline mocore

  • Hero Member
  • *****
  • Posts: 633
  • ~.~
Re: Correct Method To Swap Between HDMI and Analog Sound on TC 13.0.3
« Reply #14 on: October 11, 2021, 02:27:42 PM »
posible factors that might influence sound defaults
- pi firmware version AND config.txt & "device tree"  setings
- picore kernel config
- picore backup setings
« Last Edit: October 11, 2021, 02:39:07 PM by mocore »