Repository navigation
Closed
Labels
Description
On Manjaro mal_enumerate_devices returns only null and pulse, I looked over your code and I understand what you want to achieve in mal_enumerate_devices__alsa the problem is that on my system this check if (colonPos == -1 || (colonPos == 2 && (NAME[0]=='h' && NAME[1]=='w'))) can only be true for null or pulse because these don't contain : and there's no entry starting with hw:something.
I wrote this function to check my entries:
int enumerateAlsaDevices()
{
char **hints;
/* Enumerate sound devices */
int err = snd_device_name_hint(-1, "pcm", (void***)&hints);
if (err != 0) return -1;//Error! Just return
char** n = hints;
while (*n != NULL)
{
char *name = snd_device_name_get_hint(*n, "NAME");
char *desc = snd_device_name_get_hint(*n, "DESC");
char *ioid = snd_device_name_get_hint(*n, "IOID");
//printf("name len %lu, desc len %lu ioid len %lu\n", strlen(name), strlen(desc), strlen(ioid)); //There's no terminator...
if (name != NULL && 0 != strcmp("null", name))
{
//Copy name to another buffer and then free it
char hwID[16] = {'\0'};
if(strcmp(name, "pulse") == 0)
{
sprintf(hwID, name);
printf("Name: %s\nDescription: %s\nIOID: %s\nhwID: %s\n\n", name, desc, ioid, hwID);
}
else
{
char* aux = strstr(name, ":");
if(aux != NULL)
{
char* prop = aux + 1;
aux = strtok(prop, ",");
int cardIndex = snd_card_get_index(aux + 5);
aux = strtok(NULL, ",");
if(aux != NULL)
{
sprintf(hwID, "hw:%d,%s", cardIndex, aux + 4);
}
else
{
sprintf(hwID, "hw:%d,%d", cardIndex, 0);
}
}
printf("Name: %s\nDescription: %s\nIOID: %s\nhwID: %s\n\n", name, desc, ioid, hwID);
}
free(name);
free(desc);
free(ioid);
}
n++;
}
snd_device_name_free_hint((void**)hints);
return 0;
}
and they look like this:
...
Name: sysdefault:CARD=U7
Description: Xonar U7, USB Audio
Default Audio Device
IOID: (null)
hwIDhw:1,0
Name: front:CARD=U7
Description: Xonar U7, USB Audio
Front speakers
IOID: (null)
hwIDhw:1,0
Name: surround21:CARD=U7
Description: Xonar U7, USB Audio
2.1 Surround output to Front and Subwoofer speakers
IOID: (null)
hwIDhw:1,0
...
Now I agree that it prints every kind of thing every card can do but there must be a middle ground so that you can enumerate and choose at run time what card you want to push sound through.
I am using it with your dr_flac.h and it's pretty solid other than this problem.
Versions
cat /proc/asound/version
Advanced Linux Sound Architecture Driver Version k4.9.60-1-MANJARO.
aplay --version
aplay: version 1.1.4 by Jaroslav Kysela <perex@perex.cz>
latest mini_al.h and dr_flac.h
Activity
mackron commentedon Nov 6, 2017
Thanks for your feedback on this. I'll get onto this later tonight when I get a chance.
mackron commentedon Nov 6, 2017
I've taken a look at this and I didn't realize how bad I was handling device enumeration! Take a look at branch "issue_2" for work on improving this. Still work in progress.
So far what I've done is basically just simplified the whole thing and return every device without trying to strip anything. The problem with this is that it's so unfriendly for the end user...
What do you think of the idea of giving applications the option to choose whether or not they want verbose device enumeration or compact enumeration? What I'm thinking of doing is adding a mal_context_config structure which is passed into mal_context_init() and would look something like this:
When useVerboseDeviceEnumeration is set to true it will return every device that ALSA returns. When set to false it returns only unique devices based on card/dev pairs and uses "hw:%d,%d" when opening the device. Do you think that API design seems reasonable?
VelvetyWhite commentedon Nov 6, 2017
Now it's listing them all but there are still some problems.
Here I had to advance the
srcpointer because it was on the colon and when it copied the card namemal_strncpy_s(card, sizeof(card), src+5, (size_t)-1);,src+5was on=and it was also getting the=sign and sending it like this tosnd_card_get_indexthe returningcardIndexwas an error (For me the value ofcardwas"=U7").In
mal_device_init__alsaif
pDeviceIDis notNULLandpConfig->alsa.preferPlugHWis0it will only copy that name fromsnd_device_name_get_hint(*n, "NAME");which is inpDeviceID->alsa, never callingmal_convert_device_name_to_hw_format__alsabut it will call it ifpConfig->alsa.preferPlugHWis true and then it proceeds towith that name which seems to work because I don't see that "Failed 1" printed but then I get this
which seems related to issue 1 maybe? Because if I do
config.alsa.preferPlugHW = 0;it works.
However if I do this
when
pDeviceIDis notNULLandpConfig->alsa.preferPlugHWis0it will initialize directly with the id generated bymal_convert_device_name_to_hw_format__alsaand it will work even withconfig.alsa.preferPlugHW = 1;, but thenpulseordefaultwon't work for obvious reasons...So, I think this initialization should somehow be reordered, try to use by default the
hwidand treatpDeviceID ==NULLdefaultandpulseas special cases.That API design looks good and extensible to me but you know best, its your thing.
mackron commentedon Nov 7, 2017
Thanks for your feedback! Indeed, I didn't have the time to properly test that stuff last night. I've implemented bug fixes in the issue_2 branch.
The prioritization logic works in my head... Take the devices below as an example:
NAME: front:CARD=I82801AAICH,DEV=0 (hw:0,0)
NAME: surround21:CARD=I82801AAICH,DEV=0 (hw:0,0)
Note how these have the same "hw:0,0" ID.
If, for example, the end-user specifically wants to use the "front" device, wouldn't you want to try opening that specific device first, as the highest priority? If I were to change the priority so that the "hw:0,0" device is attempted first, wouldn't the user lose control of the specific device that's opened? How would it distinguish between the "front" device and the "surround21" device? My idea was to try the specific device selection first, and then fall back to the more general "hw:0,0" selection if that fails.
That's intended behaviour. My idea was to have it so the NAME property is used verbatim as the device identifier in snd_pcm_open(), then falling back to "hw:%d,%d" upon failure. Is using the NAME property verbatim as the device ID for snd_pcm_open() valid, do you know?
The preferPlugHW config is just a suggestion. It's not going to be used for the "default" nor "pulse" devices and I'm not considering it a critical error if a device cannot be converted to "plughw" format.
It's interesting that you are getting the same error as that from issue #1. I've got a potential fix in that branch so hopefully that'll be cleaned up soon, after which I'll get that merged into the issue_2 branch as well.
I've also decided to commit to that API design - I think it'll be good for extensibility like you say, and it'll allow me to add backend-specific configs in the future to give applications more control. I've not yet had a chance to implement that, though.
Thanks for taking the time to help figure this out!
VelvetyWhite commentedon Nov 7, 2017
Yes, yes, you are right, I thought about that after I wrote the message and this way, I think, it should also read multichannel configs from
alsa.conf. I saw this pcm naming conventions and they have these examplesand I thought that's how it has to be but, I guess not really.
So, now
works alright,
gives
mal_device__read_frames_from_client: Assertion `frameCount > 0' failedworks,
works,
gives
mal_device_init__alsa: Assertion `pChmap->channels == pDevice->internalChannels' failedas expected.With mini_al.h from branch issue_1
works alright,
this just hangs, it's the same one that gives the issue_1 assertion,
works, and the front also works.
Now, it may be that there is something dubious with sysdefault in Manjaro.
Thank you for your work, I really appreciate it!
mackron commentedon Nov 7, 2017
Thanks for your work on testing this! I don't fully understand what's going on with that failed assertion. It's most likely that I'm just doing something wrong, but I can't reproduce it so it's been hard to figure it out.
I'll fix this one. mini_al should Just Work no matter how the device is configured - it should just do a channel conversion in this case.
ALSA: Improvements to device enumeration.
mackron commentedon Nov 8, 2017
I went ahead and pushed some work to improve device enumeration. See the commit message for details. I'll leave this issue open pending a fix for the channel map assertion, but I'll refer you to issue #1 for continued discussion about the mmap error.
Thanks for your help with this!
mackron commentedon Nov 11, 2017
A fix for the chmap assertion error is in the new version on the master branch. Thanks for your help testing all of that for me.
I ended up changing the logic for opening devices again. It's a bit simpler now and doesn't use the "plughw" fallback stuff any more.