EmulationStation
EmulationStation copied to clipboard
Sound Settings / Audio Card Not Selecting ALSA default or sysdefault Hardware Device
Good day,
Here is my system information: Pi 4 (8 gig ram) CanaKit 3.5A USB-C Power Supply with Noise Filter Retropie Version 4.8.2 - Last Commit: 3 weeks ago (f271ce9d) Image downloaded from retropie website HiFiBerry DAC2 HD installed
This problem might be a simple understanding of my misinterpreting how audio-cards work in EmulationStation...
I have been just having a terrible time getting my HiFiBerry DAC to work properly.
I have read numerous examples of how to properly setup ALSA.
For now, I have settled on the following setup in my /etc/asound.conf file:
# Works for hifiberry
pcm.!default {
type plug
slave.pcm "dmix:sndrpihifiberry,0"
}
# Works for hdmi, plug works with hw but not dmix
pcm.!sysdefault {
type plug
slave.pcm "hw:b1,0"
}
My goal is to be able to select using my hifi berry or hdmi via the sound settings in retropie.
However, I am unable to get switching back and forth between the two devices/audio cards to work...
Here is what I am expecting to work.
When I go to Sound Settings -> Audio Card when I select default, the sound should come through the hifi berry (see the asound.conf above). This actually works and is expected behavior.
However, I don't always want the sound to go through my receiver and speakers.
So, I have hdmi setup as sysdefault in ALSA and when I go to Sound Settings -> Audio Card and select sysdefault, I would expect the sound to start coming though the hdmi (see the asound.conf above).
However, the sound still comes though the receiver/speakers (the default device) and not the hdmi (sysdefault).
What am I doing wrong and how can I achieve my goal of being able to select which device plays sound?
Does Sound Settings -> Audio Device have to be set to a different specific value for this plan/idea to work?
Any friendly advice would be greatly appreciated.
BTW, I am able to play sounds through both the hdmi and hifiberry using omxplayer.
Here are the two different commands:
# Plays through the hifi berry -> receiver -> speakers
$ omxplayer -o alsa:default -g --pos 00:00:15 "Banco De Gaia - Last Train To Lhasa (cd 1).mp3"
# Plays though the hdmi -> tv
$ omxplayer -o alsa:sysdefault -g --pos 00:00:15 "Banco De Gaia - Last Train To Lhasa (cd 1).mp3"
~~~
Hi @nathan-hook ,
Thanks for taking the time here. I'll be honest, I don't think anyone here will have a similar device and will be able to assist. The best recommendation for issues is normally to send them to the forums, as the odds of finding someone with a similar setup and experience are higher.
To be fair, this specific use case you're describing might be a bit more niche than usual, with wanting to re-route different audio devices depending on the setting by changing a system file. In principle, it seems you're going about it the right way, but I don't have such a device I can't replicate it or explore further, and I believe other contributors here will be in the same situation.
I suggest you go here and share your feedback. Hopefully someone will have run into a similar situation and might be able to shed some light.
Best of luck.
@pjft there is already a topic opened https://retropie.org.uk/forum/topic/33069/ and I took a look at it.
The issue is not tied to a particular sound card, but rather by the fact that the AudioManager (as opposed to the VolumeManager) always opens the default card, ignoring any other values.
Got it.
Is there anything I can do to help?
If I am pointed in the right(ish) direction, I might be able to donate a bit of time to get this problem solved.
@nathan-hook not sure how familiar you are with SDL, the changes needed are to be implemented in the AudioManager class, where the output device is (not) chosen during initialization.
The issue is that the device/card selection is used by VolumeManager (which uses the ALSA API underneath), just to get/set the audio volume, but the options set there are not used in the AudioManager.
Underneath, AudioManager uses the SDL Audio API to play audio files/samples. SDL_Audio, in turn, may use PulseAudio/ALSA/OSS to play audio, though ALSA is usually picked up, if PulseAudio is not present and active on the system.
I'm not sure whether SDL_Audio can choose an audio card for playing, but I assume it may, since it can enumerate them (see testaudioinfo). Note that default or sysdefault are not some of the values that are returned by SDL_GetAudioDeviceName when ALSA is used as the SDL Audio driver.
The issue is also a disconnect between the names used in the VolumeManager's options (card/device) right now and the real device names as queried by the SDL Audio API, so some changes may also be needed in VolumeManager.
Ideally, both VolumeManager and AudioManager would know the SDL Audio implementation (PulseAudio/ALSA/OSS?) and:
VolumeManagerwould show only the detected audio devices/cards (+ add some known names asdefault/systemdefaultwhen ALSA is detected). Since the SDL Audio API doesn't have any methods to get the mixer (card) names, some direct API must be used (like it's doing right now just for ALSA). AFAIKSDL_Mixeralso doesn't have any methods to retrieve the device/mixer names, so that's why a direct API (i.e.libasound,libpulse, etc.) is needed.AudioManagerwould pick the values for card/device from the settings and initialize the SDL Audio API accordingly, hence fixing the issue at hand.
To reproduce this with just the Pi audio devices (analog/HDMI), the following $HOME/.asoundrc can be used (tested on a Pi4):
# DEFAULT goes via the analog jack
pcm.!default {
type hw
card 1
}
# SYSDEFAULT goes to HDMI (1st port).
pcm.!sysdefault {
type plug
slave.pcm "hw:b1,0"
}
Using omxplayer to specify the ALSA device (as @nathan-hook mentioned in the initial post) would play audio on different devices, but changing between default/sysdefault in EmulationStation will always play on the default device.
@nathan-hook a workaround you can employ for the moment is to have 2 asound.conf/.asoundrc files, one where default points to the Hifiberry and one where default points to HDMI. Then have a set of .sh scripts copied in $HOME/RetroPie/retropiemenu that would enable one of outputs when needed. This will affect the entire system (not only ES, but emulators also).