Skip to content

Commit

Permalink
Do not advertise <32-sample buffer sizes.
Browse files Browse the repository at this point in the history
Fixes #88.
  • Loading branch information
dechamps committed Sep 3, 2020
1 parent 65b47d1 commit bc68c52
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
10 changes: 7 additions & 3 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,11 @@ The default behaviour is to advertise minimum, preferred and maximum buffer
sizes of 1 ms, 20 ms and 1 s, respectively. However, in practice the minimum
buffer size will be advertised as 10 ms as long as the (default) DirectSound
backend is used and the input device isn't disabled; this is to work around a
[known issue](https://github.com/dechamps/FlexASIO/issues/50) with DirectSound
and small input buffer sizes. The resulting sizes in samples are computed based
on whatever sample rate the driver is set to when the application enquires.
[known issue][issue50] with DirectSound and small input buffer sizes. The
resulting sizes in samples are computed based on whatever sample rate the driver
is set to when the application enquires. In addition, by default, FlexASIO will
not advertise any buffer sizes smaller than 32 samples as that tends to [confuse
some applications][issue88].

### `[input]` and `[output]` sections

Expand Down Expand Up @@ -366,6 +368,8 @@ automatic conversion mechanism as the one this option controls.)
[device]: #option-device
[GUI]: https://en.wikipedia.org/wiki/Graphical_user_interface
[INI files]: https://en.wikipedia.org/wiki/INI_file
[issue50]: https://github.com/dechamps/FlexASIO/issues/50
[issue88]: https://github.com/dechamps/FlexASIO/issues/88
[logging]: README.md#logging
[official TOML documentation]: https://github.com/toml-lang/toml#toml
[portaudio287]: https://app.assembla.com/spaces/portaudio/tickets/287-wasapi-interprets-a-zero-suggestedlatency-in-surprising-ways
Expand Down
9 changes: 5 additions & 4 deletions src/flexasio/FlexASIO/flexasio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,13 @@ namespace flexasio {
}
else {
Log() << "Calculating default buffer size based on " << sampleRate << " Hz sample rate";
*minSize = long(sampleRate * (hostApi.info.type == paDirectSound && inputDevice.has_value() ?
// We enforce a minimum of 32 samples as applications tend to choke on extremely small buffers - see https://github.com/dechamps/FlexASIO/issues/88
*minSize = (std::max<long>)(32, long(sampleRate * (hostApi.info.type == paDirectSound && inputDevice.has_value() ?
0.010 : // Cap the min buffer size to 10 ms when using DirectSound with an input device to work around https://github.com/dechamps/FlexASIO/issues/50
0.001 // 1 ms, there's basically no chance we'll get glitch-free streaming below this
));
*maxSize = long(sampleRate); // 1 second, more would be silly
*preferredSize = long(sampleRate * 0.02); // 20 ms
)));
*maxSize = (std::max<long>)(32, long(sampleRate)); // 1 second, more would be silly
*preferredSize = (std::max<long>)(32, long(sampleRate * 0.02)); // 20 ms
*granularity = 1; // Don't care
}
Log() << "Returning: min buffer size " << *minSize << ", max buffer size " << *maxSize << ", preferred buffer size " << *preferredSize << ", granularity " << *granularity;
Expand Down

0 comments on commit bc68c52

Please sign in to comment.