Can miniaudio obtain the OS-specified channel configuration? #817
-
In most OSes, it's possible to configure the speaker channels - e.g. via "Speaker Setup" (Windows) or "Audio MIDI Setup" (macOS). I'm trying to determine how to obtain this configuration - essentially, a channel map - so that I can automatically apply it in my application. Ideally, I would like to use the OS-specified settings as the default. For example, when I configure my audio interface (8 output channels) using Audio MIDI Setup, I can specify that a stereo file should be played through channels 3+4. And, for the most part, the setting is applied when playing audio in applications - both ones developed by Apple, and others. It's a bit hit-and-miss though - for example, (otherwise great) foobar2000 doesn't seem to be compliant. So, my question is if it's possible to obtain the OS-specified channel via one of the miniaudio APIs? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
In your device config, if you leave the channel count set to the 0 and the channel map empty, it'll tell the miniaudio to use the native channel configuration as reported by the backend. To access it, you query it from the device.playback.channels; // <-- The channel count as reported by the backend.
device.playback.channelMap; // <-- The channel map as reported by the backend. You can use |
Beta Was this translation helpful? Give feedback.
-
Thanks for the answer! I'm still having some trouble, unfortunately. First, I launched the Audio MIDI Setup utility and configured my audio so that stereo files would be played on channels 3+4, that 5.1 surround files would have a slightly different layout. A quick test (using the Apple Music app and Audacity) confirmed that the settings got applied. I then took the simple playback example and modified it so that the device config specifies a channel count of 0. As for the channelMap ( In any case, this is the debug output when using a device config with 0 channels
From what I can gather, miniaudio determines the channel map to be the maximum available size (10 channels). But there are no rearranged channels at all. I guess what I was hoping that it would enforce my "stereo profile" when playing back 2 channels of audio, my "5.1 surround profile" when playing back 6 channels, and so on. But perhaps this is indeed the problem - miniaudio obtains a full 10-channel configuration no matter what - and the macOS Audio MIDI Setup utility doesn't even have the capability to configure so many channels (8 is the maximum). So I can't actually verify if this is the problem. |
Beta Was this translation helpful? Give feedback.
In your device config, if you leave the channel count set to the 0 and the channel map empty, it'll tell the miniaudio to use the native channel configuration as reported by the backend. To access it, you query it from the
ma_device
object after initialization.You can use
#define MA_DEBUG_OUTPUT
to output to stdout the channel count and channel map so you can easily review what it's given back to you in case you wanted to verify the results.