Skip to content

SupportedStreamConfig(Range) API inconsistencies - can we have a SupportedStreamConfig.try_with_fixed_buffer_size? #956

@dani-corie

Description

@dani-corie

The SupportedStreamConfigRange, SuportedStreamConfig and StreamConfig types make configuring streams in cpal far more complicated and unpleasant than it would need to be.

  • SupportedStreamConfigRange - range of sampling rates and buffer sizes
  • SupportedStreamConfig - fixed sampling rate, range of buffer sizes
  • StreamConfig - fixed sampling rate, fixed or 'default' buffer size

I'm not sure why there's even a need for SupportedStreamConfig, but the main point why I opened this issue is that the naively expected chain of Iterator<SupportedStreamConfigRange> -> SupportedStreamConfigRange -> SupportedStreamConfig -> StreamConfig is incomplete.

  • I get the iterator, and filter it to get one or more candidates.
  • Then on those, I call try_with_sample_rate to get a SupportedStreamConfig. This is where the first problem is: bad documentation: /// Retrieve a [SupportedStreamConfig] with the given sample rate and buffer size. The signature of the method is (self, sample_rate: SampleRate), no buffer size I could specify.
  • Getting a SupportedStreamConfig, I'd then like to narrow down the buffer size, as at least on Linux, most devices return with a buffer size range of between 1 and MAXINT32 or so. However, there is no method for doing this. As mentioned in Prototyping an API for getting the supported min and max buffersizes #401, the config method on this type just returns a StreamConfig with a Default buffersize setting.

So in the end, I'm still hand-assembling a StreamConfig.

I guess the first step would be to have a try_with_fixed_buffer_size method on SupportedStreamConfig. Then, if there's no good reason for it, it might be meaningful to roll SupportedStreamConfigRange and SupportedStreamConfig into a single type?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions