Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DietPi-Config | RPi: Changed onboard audio interface #3887

Closed
corasaniti opened this issue Nov 2, 2020 · 10 comments · Fixed by #3938
Closed

DietPi-Config | RPi: Changed onboard audio interface #3887

corasaniti opened this issue Nov 2, 2020 · 10 comments · Fixed by #3938
Labels
Bug 🐞 RPi Solution available 🥂 Definite solution has been done
Milestone

Comments

@corasaniti
Copy link

Unable to hear audio on analog 3.5 jack

  • DietPi version
    G_DIETPI_VERSION_CORE=6
    G_DIETPI_VERSION_SUB=33
    G_DIETPI_VERSION_RC=3
    G_GITBRANCH='master'
    G_GITOWNER='MichaIng'

  • Distro version | buster 10.6

  • Kernel version | Linux DietPi 5.4.72-v7l+ https not working for Punycode domain #1356 SMP Thu Oct 22 13:57:51 BST 2020 armv7l GNU/Linux

  • SBC model Rpi4

  • SDcard used | SanDisk ultra

I set the option in the Audio Options of the DietPiConfig tool
rpi-bcm2835-3.5mm
I am not able to hear the sound from the speakers connected via the analog jack to my Rasp4
Thanks

@MichaIng
Copy link
Owner

MichaIng commented Nov 3, 2020

Many thanks for your report.

Could you please paste the output of the following commands:

amixer contents
cat /etc/asound.conf

And did you try it with speaker-test or with a different audio device to rule out a sound source/player issue?

@corasaniti
Copy link
Author

This is the output of my file

/etc/asound.conf

pcm.!default {
        type hw
        card 0
        device 0
}
ctl.!default {
        type hw
        card 0
}

If I try speaker-test I am not able to hear anything and in console I see the following log

Playback device is default
Stream parameters are 48000Hz, S16_LE, 1 channels
Using 16 octaves of pink noise
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 512 to 65536
Period size range from 512 to 65536
Using max buffer size 65536
Periods = 4
was set period_size = 16384
was set buffer_size = 65536

0 - Front Left
Time per period = 1.378552
0 - Front Left
Time per period = 2.729755
0 - Front Left
Time per period = 2.730159
0 - Front Left
Time per period = 2.729889
0 - Front Left

Thanks

@MichaIng
Copy link
Owner

MichaIng commented Nov 3, 2020

Can you also paste the output of:

amixer contents

@corasaniti
Copy link
Author

Hi this is my amixer content
Thanks

root@DietPi:~# amixer
Simple mixer control 'HDMI',0
Capabilities: pvolume pvolume-joined pswitch pswitch-joined
Playback channels: Mono
Limits: Playback -10239 - 400
Mono: Playback 400 [100%] [4.00dB] [on]

@MichaIng
Copy link
Owner

MichaIng commented Nov 4, 2020

I think I found the reason: https://www.raspberrypi.org/blog/latest-raspberry-pi-os-update-may-2020/
It seems they changed the way how output channels are accessible. A shame since there seem to be no "auto" choice anymore, i.e. no way to have audio output to HDMI automatically, if plugged, else through 3.5mm, which was a good default choice before. Also it is now not possible to switch output with a simple amixer or alsamixer switch but the ALSA config file needs to be edited. What was meant to simplify things, IMO made it more complicated, aside of the fact that it broke all 3rd party configuration tools and personal scripts and the way users were used to the last years...
Another question is if this is RPi4 only or affects all RPi models, in prior case it would further complicate our scripts. And I was already wondering why the amixer instructions on official docs have gone and replaced by raspi-config instructions, i.e. too complicated now to do it with low-level tools.

@corasaniti
Let's assure what I assume it is, please paste the output of the following:

aplay -l

It should show you two audio cards now, the first being HDMI output, the second being 3.5mm jack. If that is so, you should be able to get output to 3.5mm via:

sed -i 's/card 0/card 1/' /etc/asound.conf

I'll also check this on RPi2 later.

@MichaIng MichaIng added the RPi label Nov 4, 2020
@MichaIng MichaIng added this to the v6.34 milestone Nov 4, 2020
@corasaniti
Copy link
Author

Hi this is my output of
aplay -l

root@DietPi:~# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: b1 [bcm2835 HDMI 1], device 0: bcm2835 HDMI 1 [bcm2835 HDMI 1]
Subdevices: 4/4
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
card 1: Headphones [bcm2835 Headphones], device 0: bcm2835 Headphones [bcm2835 Headphones]
Subdevices: 4/4
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3

So with command
sed -i 's/card 0/card 1/' /etc/asound.conf

I should be able to hear audio on analog 3.5jack

if I want to restore the configuration on the HDMI audio output, do I have to execute the following command? Correct?
sed -i 's/card 1/card 0/' /etc/asound.conf

right
Thanks

@corasaniti
Copy link
Author

Hi the command

sed -i 's/card 0/card 1/' /etc/asound.conf

it worked perfectly for me :-)

Now I am able to listen to the music on my speakers connected in analog on the 3.5mm jack and listen to the noise of the floppy drive emulated in Amiberry

Thanks: - /

@MichaIng
Copy link
Owner

MichaIng commented Nov 5, 2020

Okay, that is great.

I think 3.5mm jack for default sound output is fine as well.

@MichaIng
Copy link
Owner

MichaIng commented Nov 5, 2020

It is even worse. If no HDMI monitor is attached (or HDMI forcefully disabled), card 0 is the 3.5mm jack and the HDMI card is not available. It seems to make sense, but the problem is that is is extremely complicated (too complicated to implement) now to know which card ID which output channel will finally have. That alone could be solved with a two stage implemention:

  1. A dedicated selector to enable/disable audio drivers: Onboard audio, dtoverlays for external cards etc.
  2. Make the sound card selection an auto detection only, so only "available" sound cards are listed.

This assures that the correct sound card is chosen, regardless of its ID, which as well solves another issue better, where the KMS driver adds an additional sound card 0, which we currently work around by incrementing the IDs. But in general these sound card IDs are not fixed and it depends on the order in which all available output devices are loaded.

The big downside is that a sound card cannot be chosen with a single selection or even via dietpi.txt or scripted at boot, but includes mostly selecting the driver/overlay/module first, then the selecting the now available cards as a 2nd manual step.

But the worst thing is: If one selects the audio jack and then disables HDMI or unplugs the monitor or switches to hdmi_drive=1 (DVI mode, no sound), the previously chosen sound card 1 does not exist anymore and it needs to be re-selected...

This could be worked around by directly setting hdmi_drive=1 when selecting 3.5mm jack. It it is as I assume, then the card ID should be 0 as well. Sadly this does not work the other way round: hdmi_drive=2 does not force the HDMI card 0 being available, it seems an HDMI monitor needs to be attached.

@corasaniti
If you are in mood, could you do some tests to verify that RPi4 behaves the same:

G_CONFIG_INJECT 'hdmi_drive:0=' `hdmi_drive:0=1` /boot/config.txt # forces DVI mode on HDMI port 0
G_CONFIG_INJECT 'hdmi_drive:1=' `hdmi_drive:1=1` /boot/config.txt # forces DVI mode on HDMI port 1
reboot
cat /proc/asound/cards

Check if the last command now only lists "Headphones" (3.5mm jack) with ID 0, like:

2020-11-05 15:36:50 root@micha:~# cat /proc/asound/cards
 0 [Headphones     ]: bcm2835_headphonbcm2835 Headphones - bcm2835 Headphones
                      bcm2835 Headphones

If HDMI output is still shown, detach HDMI screen, then:

sed -i '/^hdmi_drive:[01]=/d' /boot/config.txt # Removes the HDMI drive entries to check effect of attached screen alone
reboot
cat /proc/asound/cards

The second test of course needs to be done via SSH then, when no HDMI monitor is attached 😉.

@MichaIng MichaIng changed the title Unable to hear audio on analog 3.5 jack DietPi-Config | RPi: Changed onboard audio interface Nov 5, 2020
@MichaIng MichaIng linked a pull request Nov 30, 2020 that will close this issue
@MichaIng
Copy link
Owner

MichaIng commented Dec 7, 2020

Issue now solved via device tree overlay to disable HDMI or 3.5mm jack completely, if the other one is wanted: #3938
With this, the chosen onboard sound will always be on card0. The downside is that a reboot is required to chance it. But this is true in most cases anyway, e.g. enabled onboard audio the first time requires a reboot due to dtparam=audio=off => on and all other sound card selections are implemented via device tree overlays as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐞 RPi Solution available 🥂 Definite solution has been done
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants