Alsa HDMI audio distorted and some sounds do not play at all

Post Reply
Jason_25
Posts: 29
Joined: Sun Jan 21, 2018 2:31 am
languages_spoken: english
ODROIDs: 2 x c2, 5 x c0
Contact:

Alsa HDMI audio distorted and some sounds do not play at all

Unread post by Jason_25 » Sat Mar 02, 2019 8:16 am

I am having a problem with HDMI audio sounding distorted or not playing at all. I have no wish to use Pulseaudio. This is a collection of sounds that I have tested:

speaker-test - sounds like a machine gun is going off in the background.
aplay /usr/share/sounds/alsa/Front_Center.wav - sounds like a chipmunk/sped up type of speaking
Linphone synth ring (S16LE, 44100, Stereo) - sounds perfect
Linphone Big Ben ring (S16LE, 22050, Stereo) - no sound at all
Linphone in call - no sound at all

By default there is no sound at all so I had to use a .asoundrc file. I have tried a simpler file with no difference. This is it's contents:

Code: Select all

pcm.!default {
	type plug
	slave.pcm "adafruit"
	ttable {
	0.1 1
	0.0 1
	1.0 1
	1.1 1
	}
}

ctl.!default {
type hw card 0
}

pcm.adafruit {
	type softvol
	slave.pcm "plughw:0,0"
	control.name "toot"
	control.card 0
	max_dB 4.0
}	
Where could the problem be?

User avatar
meveric
Posts: 9761
Joined: Mon Feb 25, 2013 2:41 pm
languages_spoken: german, english
ODROIDs: X2, U2, U3, XU-Lite, XU3, XU3-Lite, C1, XU4, C2, C1+, XU4Q, HC1, N1, Go
Contact:

Re: Alsa HDMI audio distorted and some sounds do not play at all

Unread post by meveric » Sat Mar 02, 2019 8:47 pm

try this instead:

Code: Select all

pcm.!default {
  type plug
  slave {
    pcm "hw:0,1"
  }
}
ctl.!default {
  type hw
  card 0
}
Donate to support my work on the ODROID GameStation Turbo Image for U2/U3 XU3/XU4 X2 X C1 as well as many other releases.
Check out the Games and Emulators section to find some of my work or check the files in my repository to find the software i build for ODROIDs.
If you want to add my repository to your image read my HOWTO integrate my repo into your image.

Jason_25
Posts: 29
Joined: Sun Jan 21, 2018 2:31 am
languages_spoken: english
ODROIDs: 2 x c2, 5 x c0
Contact:

Re: Alsa HDMI audio distorted and some sounds do not play at all

Unread post by Jason_25 » Sat Mar 02, 2019 11:59 pm

That .asoundrc results in a file not found error when attempting playback. My c0 does not have a "0,1" device. HDMI output is "0,0". Changing that .asoundrc to "0,0" instead results in the same glitchy behavior.

A clue may be in the "playback rate". The 44100 rate file played fine while the 22050 file did not.

Still searching for answers.

edit: I will compile all the information I find here.

https://wiki.gnuradio.org/index.php/ALSAPulseAudio
"Sound cards don't support arbitrary sampling rates. If your audio is choppy, check the rate of your audio sink or source: 44100 Hz works under all audio cards known, 48000 Hz on many, 32000 usually does not work."
This is a clue that sound is being played at a frequency unsupported by my hdmi device.

https://unix.stackexchange.com/question ... ut-44-1khz
"defaults.pcm.dmix.rate 44100"
This is supposedly a method of forcing output to 44100. Another thread shows that this can be configured in /usr/share/alsa/alsa.conf. Changing the parameter to 44100 instead of 48000 in this file had no affect. There was no .asoundrc because I have no idea how that relates to the changes in this file or what dmix or mixing or audio rates really are.

https://askubuntu.com/questions/638978/ ... s-and-alsa
"Using the hw device disables all automatic sample format conversions."
This is a clue that specifying "hw" anywhere in the .asoundrc is probably not going to work if I want to do a "sample rate conversion".

https://unix.stackexchange.com/question ... te-in-alsa
"Alsa by default uses the same sampling rate and format as the source. It is however possible to force the sample rate up (or down)."
This goes on to mention a way of setting up .asoundrc. I set the .asoundrc like this:

Code: Select all

pcm.device{
        format S32_LE
        rate 44100
        type hw
        card 0
        device 0
}

pcm.!default{
    type plug
    slave.pcm "device"
}
The error was: "unable to set HW params for playback: invalid argument"

https://bbs.archlinux.org/viewtopic.php?id=52642
"A workaround could be to put this in ~/.asoundrc"
This goes on to mention a way of setting up .asoundrc. I set the .asoundrc like this:

Code: Select all

pcm.!default {
type rate
slave {
pcm "plughw:0,0"
rate 44100
}
}
The error was: "unable to set buffersize 35664 for playback: invalid argument"

https://forums.gentoo.org/viewtopic-t-1 ... art-0.html
"Dmix only runs a single rate and format, usually 48000 and S16 for standard devices, but you can force the rate and format in dmix with something like the following:"
This goes on to mention a way of setting up .asoundrc. I set the .asoundrc like this:

Code: Select all

pcm.!default {
        type plug
        slave.pcm "dmixer"
}
ctl.!default {
        type hw
        card 0
}
pcm.dmixer {
        type dmix
        ipc_key 1024
        slave {
                pcm "hw:0,0"
                channels 2
                rate 44100
                format S32_LE
        }
}
The error was: "alsa slave plugin does not support mmap interleaved"

There are three potential workarounds to fix this so far:
raw - original rate - must ensure all audio is 44100 at application level
dmix plugin - modified rate - apparently unsupported by this driver
pulseaudio - modified rate - unacceptable

The questions is why is this happening in the first place?
Playing audio files of any type should "just work".
The problem is on the SBC side not screen/amplifier side.
Lattepanda plays hdmi audio fine without any of these modifications.
HP laptop plays hdmi audio fine without any of these modifications.
Last edited by Jason_25 on Sun Mar 03, 2019 3:36 am, edited 7 times in total.

User avatar
meveric
Posts: 9761
Joined: Mon Feb 25, 2013 2:41 pm
languages_spoken: german, english
ODROIDs: X2, U2, U3, XU-Lite, XU3, XU3-Lite, C1, XU4, C2, C1+, XU4Q, HC1, N1, Go
Contact:

Re: Alsa HDMI audio distorted and some sounds do not play at all

Unread post by meveric » Sun Mar 03, 2019 1:17 am

Ah yes, that's true, the hw:0,1 was the old config file I they changed it along the way to 0,0.
Regarding playback rate.
I think only really 44.1kHz are working correctly under ALSA, you should check if you can force 44.1kHz for all output that might solve your issue.
Donate to support my work on the ODROID GameStation Turbo Image for U2/U3 XU3/XU4 X2 X C1 as well as many other releases.
Check out the Games and Emulators section to find some of my work or check the files in my repository to find the software i build for ODROIDs.
If you want to add my repository to your image read my HOWTO integrate my repo into your image.

Jason_25
Posts: 29
Joined: Sun Jan 21, 2018 2:31 am
languages_spoken: english
ODROIDs: 2 x c2, 5 x c0
Contact:

Re: Alsa HDMI audio distorted and some sounds do not play at all

Unread post by Jason_25 » Sun Mar 03, 2019 1:32 am

Thank you. I came to that conclusion as well. If you look above I am documenting my efforts to do so.

edit: I had some different results from this configuration and I did not want to clog up the other post so I will post here.

https://askubuntu.com/questions/898637/ ... ly-in-alsa
"The default target sample rate is 48 kHz. If you want to prevent applications from using any other rate, add this device to /etc/asound.conf or your ~/.asoundrc"
This goes on to mention a way of setting up .asoundrc. I set the .asoundrc like this:

Code: Select all

pcm.only48k {
    type hw
    card 0
    device 0
    rate 44100
}
pcm.!default = only48k
- speaker-test no longer works - big red herring here
= mplayer still errors on toy-mono ring
= mplayer still errors on Front_Center.wav
+ aplay can play Big Ben ring but still distorted - was silent before
+ mplayer can play Big Ben ring fine - was silent before
+ mplayer can play mp4 test video - errored out before
+ linphone call works but is sped up - was silent before

This is an improvement but not yet there unfortunately.

edit:
I installed pulseaudio to see if I could get it to work.
sudo apt-get install pulseaudio
This was also required.
sudo apt-get install consolekit
.asoundrc:

Code: Select all

pcm.pulse {
    type pulse
}
ctl.pulse { type pulse
}
pcm.!default { type pulse
}
ctl.!default { type pulse
}
This works but I want to use just Alsa. I don't want another unnecessary layer
and something else to go wrong.

Post Reply

Return to “General Topics”

Who is online

Users browsing this forum: No registered users and 1 guest