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

Support selecting cards based on card name #6

Open
languitar opened this issue Jan 10, 2016 · 5 comments
Open

Support selecting cards based on card name #6

languitar opened this issue Jan 10, 2016 · 5 comments
Labels
C-enhancement Category: A PR with an enhancement or an issue with an enhancement proposal

Comments

@languitar
Copy link

Numeric indexing of cards is sometimes hard to get persistent across reboots. Please also allow to use card names instead of the index for selecting the device to change.

@jodal jodal added the C-enhancement Category: A PR with an enhancement or an issue with an enhancement proposal label Jan 15, 2016
@jodal
Copy link
Member

jodal commented Feb 12, 2017

I agree that this would be a big improvement, but I don't immediately see a way to implement it using the current pyalsaudio API:

  • We need a cardindex or device to create the alsaaudio.Mixer.
  • cardindex is an integer like 0, 1... that maps to a hardware card by name: hw:0, hw:1...
  • device is the name of a virtual device, where "default" is the only value I've found working.
  • alsaaudio.cards() lists the names of all available cards, but the index of a name in the list doesn't necessarily match the cardindex we need for alsaaudio.Mixer(), as cards may be disabled and thus not be present in the list, offsetting the index for the rest of the cards (see Bug with disabled on-board audio using an external sound card #8 for details). Thus, we cannot rely on the card list returned by alsaaudio.cards().
  • We can try to create mixers for range(len(alsaaudio.cards())), an check if we've found the correct one by looking at the name returned from Mixer.cardname(), but on my system, this simply returns hw:2, which doesn't tell me more than this being the card with cardindex "2".

If anyone has suggestions how to implement this using the current pyalsaaudio API, I'm all ears.

@riegaz
Copy link

riegaz commented Mar 15, 2017

@jodal could you add an option which uses the currently selected audio device? For example, on my raspberry pi zero w I do have Analog, HDMI and the connected bluetooth speakers. Now I selected the speakers to be the default output. Would be nice to automatically output to the current audio device.

@robcee
Copy link

robcee commented Mar 23, 2021

Taking a look at this. Not sure if @jodal's comments from 2017 are still valid or not. If I can enumerate properties of audio devices using PyAlsaAudio, we can probably map name to id.

@robcee
Copy link

robcee commented Mar 25, 2021

just a quick comment, setting up my dev environment to work on this I noticed that we're depending on Gi, which requires Gtk and Cairo and a bunch of other high level libraries that might not be applicable on a headless environment.

It looks like we're only using it for the GstAudio.StreamVolume.convert_volume() method.

Has anyone looked at using one of the numeric libraries (e.g., numpy) for doing the equivalent without the big overhead? Happy to file a follow-up issue to do that conversion.

edit: looks even simpler than something we'd need numpy for.

@robcee
Copy link

robcee commented Apr 8, 2021

just an update, I have looked at this, and my initial thoughts were to just pull alsaaudio.cards() and do a lookup, but as stated above,

  • alsaaudio.cards() lists the names of all available cards, but the index of a name in the list doesn't necessarily match the cardindex we need for alsaaudio.Mixer(), as cards may be disabled and thus not be present in the list, offsetting the index for the rest of the cards (see Bug with disabled on-board audio using an external sound card #8 for details). Thus, we cannot rely on the card list returned by alsaaudio.cards().
  • We can try to create mixers for range(len(alsaaudio.cards())), an check if we've found the correct one by looking at the name returned from Mixer.cardname(), but on my system, this simply returns hw:2, which doesn't tell me more than this being the card with cardindex "2".

I think the real fix for this would be to implement an "allcards" method in alsaaudio, which, well, doesn't really apply to this issue.

edit: from the alsaaudio docs,

alsaaudio.cards()
List the available ALSA cards by name. This function is only moderately useful. If you want to see a list of available PCM devices, use pcms() instead.

aplay -L produces similar output, but is pretty noisy. I wonder if we could parse the returned contents for hw: prefixes and extract the names? Still not really a clean solution.

I did manage to get my environment setup for Mopidy development though, so hey, that's something. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: A PR with an enhancement or an issue with an enhancement proposal
Projects
None yet
Development

No branches or pull requests

4 participants