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

Audio configuration for Linux #104

Closed
deliciouslytyped opened this issue May 5, 2019 · 20 comments
Closed

Audio configuration for Linux #104

deliciouslytyped opened this issue May 5, 2019 · 20 comments

Comments

@deliciouslytyped
Copy link

deliciouslytyped commented May 5, 2019

What is the correct configuration for audio input to work for the FFT on Linux?
I don't see a way to configure the input device.

Edit: summary:

@deliciouslytyped
Copy link
Author

My end goal is to loop back my speaker output - my audio configuration does appear to have a monitor device already.

@PoroCYon
Copy link
Contributor

PoroCYon commented May 5, 2019

Unfortunately, miniaudio (the audio library Bonzomatic uses) only looks at the default devices, and there's no environment variable to override it (unlike with, say, SDL).

On ALSA (when NOT using PulseAudio), the default is dsnoop (or dsnoop:0 or dsnoop:0,0), and if that fails, miniaudio tries to open hw:0,0.

On PulseAudio and JACK, it simply uses whatever the default device is the APIs are giving it.

You could try modifying this code if you want it to force-select a certain backend or device.

@deliciouslytyped
Copy link
Author

deliciouslytyped commented May 5, 2019

I tried poking around there yesterday but I couldn't really find a way to enumerate devices with miniaudio. I tried changing the backends away from NULL but that always failed. I'm also not too great with C++.

@Gargaj
Copy link
Owner

Gargaj commented May 5, 2019

I tried poking around there yesterday but I couldn't really find a way to enumerate devices with miniaudio. I tried changing the backends away from NULL but that always failed. I'm also not too great with C++.

Look for ma_context_get_devices

@deliciouslytyped
Copy link
Author

deliciouslytyped commented May 5, 2019

The snippet I used was

    ma_device_info* devinfoarr;
    ma_uint32 devinfocnt;
    ma_context_get_devices(&context, NULL, NULL, &devinfoarr, &devinfocnt);
    printf("devcnt: %i\n");
    for(int i = 0; i < devinfocnt; i++) {
        printf("name:%s\n", (devinfoarr[i]).name);
        }`

but devinfocnt is zero.

EDIT: Yes the devcnt printf is missing it's integer argument.

@Gargaj
Copy link
Owner

Gargaj commented May 5, 2019

That's strange, on Windows that returns my correct number of devices.

@deliciouslytyped
Copy link
Author

deliciouslytyped commented May 5, 2019

I guess there could be any number of reasons this goes wrong. The problem then is I'm not sure how to debug it and constrain the possibilities.

@Gargaj
Copy link
Owner

Gargaj commented May 5, 2019

Did you try other backends? (First parameter of ma_context_init)

@deliciouslytyped
Copy link
Author

    ma_backend backends[] = { ma_backend_pulseaudio, ma_backend_alsa };
    ma_result result = ma_context_init( backends, 0, &context_config, &context );

gives [FFT] Failed to initialize context: -103

@deliciouslytyped
Copy link
Author

deliciouslytyped commented May 5, 2019

I tried listing playback devices with the earlier snippet:

[FFT] MAL context initialized, backend is 'Null'
devcnt: 0
name:NULL Playback Device

Edit: devcnt says 0 but it should have said 1, see edit @ #104 (comment)

@deliciouslytyped
Copy link
Author

deliciouslytyped commented May 5, 2019

miniaudio uses dlopen so I'll try to check that it's loading the libraries successfully. Setting LD_DEBUG=all in the env gives output that suggests it might not be finding libasound.so and libpulse.so.

@deliciouslytyped
Copy link
Author

deliciouslytyped commented May 5, 2019

Ok, much better. I have devices now at least. Thanks for your patience.
Edit: (Temporarily fixed with LD_PRELOAD)

@Gargaj
Copy link
Owner

Gargaj commented May 5, 2019

Can you go into a bit more detail? I don't want this to be one of those threads where years down the line someone else has the same problem and then the final post is "k fixed" with no indication of what was wrong and how it got fixed :)

@deliciouslytyped
Copy link
Author

deliciouslytyped commented May 5, 2019

Ah yeah, I usually do that, thanks for the reminder.
I'm actually working on an updated package for NixOS. We basically have everything in a nonstandard location. I don't remember how dlopen searches for paths (something something RPATH?) but after seeing no devices at all, I got suspicious that miniaudio wasn't seeing anything because it failed to load the audio libraries. So I threw LD_DEBUG=all at it and looked for mentions of libasound.so. I found some, and there weren't any log messages containing search paths that looked right, so I passed a path I knew was correct manually via LD_PRELOAD.

Does miniaudio have some kind of "enable debug messages" mode? It would have been nice to see something like a list of loaded / not loaded backends.

I still have to figure out how to get the right device though.

I'm hoping I can just set the default input device in pavucontrol or something. (technically that's pulseaudio, not alsa, but it doesn't make a difference to me).

@Gargaj
Copy link
Owner

Gargaj commented May 5, 2019

Does miniaudio have some kind of "enable debug messages" mode? It would have been nice to see something like a list of loaded / not loaded backends.

Yes, put this before #include <miniaudio.h>:

#define MA_LOG_LEVEL <Level>
  Sets the logging level. Set level to one of the following:
    MA_LOG_LEVEL_VERBOSE
    MA_LOG_LEVEL_INFO
    MA_LOG_LEVEL_WARNING
    MA_LOG_LEVEL_ERROR

@deliciouslytyped
Copy link
Author

deliciouslytyped commented May 5, 2019

I put #define MA_LOG_LEVEL MA_LOG_LEVEL_VERBOSE on the first line of FFT.cpp but it doesn't seem to leave any more messages than before.

@Gargaj
Copy link
Owner

Gargaj commented May 5, 2019

There's not a lot of logging going on in MA; if you feel there's an issue on their side, you could probably head over to https://github.com/dr-soft/miniaudio and see if you can suggest something on their end.

@deliciouslytyped
Copy link
Author

I think I'll open an issue requesting more logging then.

By the way, here's an example of the output of my printf:

devinfocnt: 2
name:Discard all samples (playback) or generate zero samples (capture)
name:Default Audio Device (via PulseAudio)

@deliciouslytyped
Copy link
Author

Sweet! I got it to work!
In pavucontrol, after starting Bonzomatic, an entry showed up under the Recording tab, and I was able to select Monuitor of Built-in Audio Analog Stereo as the input device.

image

@mackron
Copy link

mackron commented May 5, 2019

I've gone ahead and added some logging to dlopen/dlsym upstream. It's in the dev branch at the moment, but I'll merge it to master soonish.

Unfortunately, miniaudio (the audio library Bonzomatic uses) only looks at the default devices

This isn't exactly true. This is only on select backends where it's either not possible or not practical. The ALSA and PulseAudio backends have full support for device enumeration and selection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants