Description
When a stream is built with an unknown buffer size, it would be very useful to get at least an upper limit, so that any intermediate buffers can be constructed up front. The WASAPI host already appears to have access to such a value through the IAudioClient::GetBufferSize
method. However, this is only available after the client has been initialized, which requires some information from the config, which is only available during the call to build_output_stream
.
As I see it, these are the possible ways that this could be achieved:
-
Putting this value in the
OutputCallbackInfo
. I don't think this would be optimal, as it would force some setup logic into the callback, likely behind anif first_run
or something. -
Either obtaining an
IAudioClient2
or higher that exposes theIAudioClient2::GetBufferSizeLimits
before it is initialized, or initializing theIAudioClient
early, and using theIAudioClient::GetBufferSize
method.
Both of these require aWAVEFORMATEX
, which needs some info from the config (channels, sample rate, etc.). One solution would be simply feeding it back its own list of supported configs and finding the biggest value, but this seems a bit inefficient and imprecise, since a more appropriate value could have been gotten by knowing the actual configuration. -
Altering the API by breaking up the
build_output_stream
method. One part initializes the client and returns the max buffer size, allowing the intermediate buffers to be constructed, and another part takes the callback closure with ownership of the buffers. These could even coexist with the current method.