Choosing a suitable output configuration.. #1316
|
I've used Cpal for a while now and imho it excels at abstracting away all the details from the underlying audio API's. Mostly it picks the right default configuration for you, which is good. But sometimes it doesn't. For instance, what happens when you have multiple sound cards with a wide variety of sample rates? Another thing is sample format.. Sometimes it returns I16, when the underlying API definitely supports F32.. I'd like to make explicit choices here, as I'm sure would many others. The enumerate example explains how to iterate through all possible configurations. But to actually match and choose one that's an entirely different thing. cpal::SupportedStreamConfigRange consists of private members, so how are we supposed to match a suitable configuration? More examples would definitely be welcome! Thanks in advance. |
Replies: 3 comments
|
Ok, I found out how to pick a specific configuration by comparing. There's something weird with setting the sample rate, though. At this point I'm just using the
|
@pietervandermeer I believe this bug was fixed in #462 though I don't recall whether or not this has been published yet. You could try switching your dependency to the master branch of this repo to see if this results in the specified sample rate. |
|
Indeed, this has since been fixed. |
Ok, I found out how to pick a specific configuration by comparing.
SupportedStreamConfigRangehas member functions to read out the specs.pub fn channels(&self) -> ChannelCountfor instance.There's something weird with setting the sample rate, though. At this point I'm just using the
with_sample_rate()member function to boil down toSupportedStreamConfigand then theconfig()function to extract aStreamConfig.. Then I change the sample_rate member variable by hand.SupportedStreamConfigRange::with_sample_rate()seems to be malfunctioning though. It just returns the maximum supported sample_rate.. Which in some cases is 2**32-1.. Maybe I'll have to check again.. I'm running on Linux (AL…