After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 753601 - alsa: Probe a fixed set of rates instead of a range
alsa: Probe a fixed set of rates instead of a range
Status: RESOLVED INCOMPLETE
Product: GStreamer
Classification: Platform
Component: gst-plugins-base
git master
Other Linux
: Normal enhancement
: git master
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2015-08-13 21:54 UTC by Carlos Rafael Giani
Modified: 2018-05-06 13:15 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch for probing a fixed set of sample rates (16.40 KB, patch)
2016-05-02 20:22 UTC, Carlos Rafael Giani
none Details | Review

Description Carlos Rafael Giani 2015-08-13 21:54:10 UTC
The ALSA library lacks PCM functions to query for a set of supported sample rates, and instead only allows for probing an allowed range. This however is at odds with many modern DACs, which only support specific sample rates. For example, some TI codecs support 44100, 48000, 96000, 192000, but not, say, 88200.

A solution would be to instead call snd_pcm_hw_params_test_rate() for a fixed set of sample rates, like: 8000, 11025, 22050, 24000, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 352800, 384000. Sample rates other than these are pretty uncommon these days.

This alternative behavior could be added as an opt-in, and the existing range-based probing could still be the default.

Thoughts?
Comment 1 Tim-Philipp Müller 2015-08-15 07:55:37 UTC
What problem are you trying to solve with this exactly?
Comment 2 Carlos Rafael Giani 2015-08-15 09:03:01 UTC
Suppose an audio device can only output 48000 and 96000 Hz. But you try to play an 88200 Hz signal. The range will be [48000, 96000] and mislead the pipeline into thinking that the alsasink can handle 88200 Hz.
Comment 3 Tim-Philipp Müller 2015-08-15 09:18:33 UTC
Right, the probing mechanism should not announce [48000, 96000] if the device doesn't actually support the values in between.

I thought the probing mechanism covers this already (tries random 'uneven' rates to see if it's a range or not), but perhaps it doesn't work right or I'm imagining things again.
Comment 4 Tim-Philipp Müller 2015-12-29 18:03:52 UTC
Do you intend to make a patch?
Comment 5 Carlos Rafael Giani 2015-12-30 09:39:19 UTC
Yes. I won't have time for it before mid January though. I do however have a proof of concept patch already, just need to rework it.
Comment 6 Carlos Rafael Giani 2016-05-02 20:22:09 UTC
Created attachment 327185 [details] [review]
Patch for probing a fixed set of sample rates

Here is a patch for this enhancement. The list of possible sample rates is given as a GstCaps. There is currently no "good" way of specifying a list of integers as a property, and parsing a string that contains a comma-separated list of integers would duplicate a lot of what GstCaps & GstStructure already do.
Comment 7 Tim-Philipp Müller 2016-05-02 20:35:37 UTC
That doesn't sound like the kind of patch I had in mind. The probing mechanism should figure out automatically if the device supports any random sample rate within the range, and if not it should just probe/try a set of common rates. It should be possible to do the right thing without a property / user input, no?
Comment 8 Carlos Rafael Giani 2016-05-02 20:55:57 UTC
The question is: how? By probing if it can use 48001 Hz? Doesn't sound that stable or clean to me. Also, without any user input, you'd have to call snd_pcm_hw_params_test_rate () for every single integer from rate_min to rate_max , which is wasteful.
Comment 9 Carlos Rafael Giani 2016-05-02 20:56:50 UTC
Well, about the last point: we could try a patch that does exactly that (probe every single integer), and see how it performs on a beaglebone for example..
Comment 10 Carlos Rafael Giani 2016-05-02 21:20:13 UTC
Hmm ok it seems that this would actually be safe to do, since no syscalls appear to actually be invoked. I'll try probing like this on such an embedded platform and upload a new patch.
Comment 11 Tim-Philipp Müller 2016-05-02 21:51:28 UTC
My suggestion would be to try a few 'unusual' sample rates within the advertised range, and if the device is okay with them we assume that it's probably okay with anything, and if it's not okay with those it's probably not okay with other unusual rates either. What do you think?

I'm sure I've seen such code somewhere, maybe in another audio sink.
Comment 12 Carlos Rafael Giani 2016-05-03 07:57:25 UTC
(In reply to Tim-Philipp Müller from comment #11)
> My suggestion would be to try a few 'unusual' sample rates within the
> advertised range, and if the device is okay with them we assume that it's
> probably okay with anything, and if it's not okay with those it's probably
> not okay with other unusual rates either. What do you think?
> 
> I'm sure I've seen such code somewhere, maybe in another audio sink.

The problem is: what is the "unusual rate"? 48001 Hz? 44000 Hz? Etc. It seems fairly arbitrary. And I have seen hardware where the crystal was chosen badly, so you got something like a 46.02 kHz sample rate etc.

Also, if you detect that this unusual rate isn't supported ... what then? You test a hardcoded set of sample rates? If so, shouldn't this set be configurable?

If we stick with the "unusual rate" idea, then I think this one should be configurable too.

Or, we simply do a brute-force probing of ALL sample rates between the min and max rates. If this doesn't consume a lot of resources, it is probably the easiest option. When I get the chance, I'll try it on a single-core TI platform.
Comment 13 Nicolas Dufresne (ndufresne) 2016-05-03 19:15:19 UTC
I've been reading TI McASP controller doc last week. It works with a single rate master clock (hard wired) and use sampling and bit clock dividers. HW engineer usually will chose a master clock the properly divides into most used rates, which is why we get the same set of rate all over the place.

Other fact, is that Pulseaudio probing routing uses a fixed list of rates. It's a bit unfortunate that ALSA API does not provide this information directly though. Long term, proposing a new API through linux-media mailing list would probably be more constructive.
Comment 14 Carlos Rafael Giani 2016-05-04 10:16:20 UTC
I ran a test with a Sitara AM3352 based platform, and probing all sample rates in the min-max range took 3 seconds. So this is not a viable option.

So I guess we'll have to live with the fixed list of sample rates and make it configurable.
Comment 15 Tim-Philipp Müller 2016-05-04 10:30:24 UTC
I would suggest to first implement the discrete rates detection/option with a fixed list.

If we then find a need for a configuration option we can add that on top of that later.
Comment 16 Tim-Philipp Müller 2018-05-06 13:15:31 UTC
Let's close this.

You know what to do if you'd like to improve this in alsasink ;)

I don't think having a philosophical discussion about what constitutes an "unusual" sample rate and what not makes much sense here. I'm fairly sure that a few data points will be decent-enough heuristics to determine if we can assume the full range is supported or just discrete rates.