I've already seen Audio over HDMI not working on Pi 3 (audio not working though HDMI, but working though speakers) but the actions described by @Vader did not work for me. The fact is that it worked at some time in the past, without configuring /boot/config.txt or any other thing, but now it does not anymore.
I have a SONY BRAVIA TV, and following the instructions from https://www.raspberrypi.org/documentation/configuration/config-txt/README.md (edidparser output) I got all the specs from the TV, and I see:
HDMI:EDID features - videodef 0x80 !standby !suspend !active off; colour encoding:RGB444|YCbCr422; sRGB is not default colourspace; preferred format is native; does not support GTF
....
HDMI:EDID parsing v3 CEA extension 0
HDMI:EDID monitor support - underscan IT formats:no, basic audio:yes, yuv444:yes, yuv422:yes, #native DTD:0
....
HDMI:EDID found audio format 2 channels PCM, sample rate: 32|44|48 kHz, sample size: 16|20|24 bits
....
HDMI:EDID best score mode is now DMT (39) 1360x768p @ 60 Hz with pixel clock 85 MHz (score 5188004)
I also see:
$ /opt/vc/bin/tvservice -s
state 0x12000a [HDMI CEA (4) RGB lim 16:9], 1280x720 @ 60.00Hz, progressive
As @Vader said I modified the /boot/config.txt to have the following:
# uncomment to force a specific HDMI mode (this will force VGA)
hdmi_group=1
hdmi_mode=4
# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
hdmi_drive=2
hdmi_force_edid_audio=1
I rebooted, and verified that the volume is right and not muted:
$ amixer
Simple mixer control 'PCM',0
Capabilities: pvolume pvolume-joined pswitch pswitch-joined
Playback channels: Mono
Limits: Playback -10239 - 400
Mono: Playback -2 [96%] [-0.02dB] [on]
,that the sound is routed through HDMI:
$ amixer cget numid=3
numid=3,iface=MIXER,name='PCM Playback Route'
; type=INTEGER,access=rw------,values=1,min=0,max=2,step=0
: values=2
The sound driver is loaded:
$ lsmod | grep snd
snd_bcm2835 24427 1
snd_pcm 98501 1 snd_bcm2835
snd_timer 23968 1 snd_pcm
snd 70032 5 snd_timer,snd_bcm2835,snd_pcm
I compiled the /opt/vc/src/hello_pi/hello_audio/ application and ran it:
$ sudo ./hello_audio.bin # I get sound though the speakers
Outputting audio to analogue
$ sudo ./hello_audio.bin 1 # I do not get sound in the TV though HDMI
Outputting audio to hdmi
I have the same behaviour with any application that I tested: speaker-test, aplay, lxmusic ... when I switch the audio output with amixer cset numid=3 2 or amixer cset numid=3 1
I do not have the .asoundrc and/or /etc/asound.conf files. I uploaded an ALSA diagnosis file to: http://www.alsa-project.org/db/?f=1c82d15d3df173fefc2b618f02cf7ccc172bf7d7, in case you want to see it (there you can find the output of alsactl )
The same HDMI cable and TV give sound with a windows barebone, so it is not a hw problem with those items. I doubt that it is a hw problem with the Rpi, because I borrowed another RPi3b and I tested it (same SD card) and it didn't work either.
My OS is Raspbian GNU/Linux 9.l
Any hint on what could have happened? Can I do something more to debug the issue?
Thanks in advance.