-
Notifications
You must be signed in to change notification settings - Fork 442
refactor(alsa): optimize period configuration and audio callback performance #1013
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
f979570
to
cbb9b03
Compare
@abique this implements the full-block writes & double-buffering strategy, as we discussed. I expect it should have much better latency too, as there are no longer any (re-)allocations, where previously there were multiple per callback. |
I've tested it and it works fine, though I haven't read the change. I think that the device list with ALSA is wrong and overwhelming. |
When I run in debug, I have lots of:
Also I get a
|
I don't really know why, but I can't debug with ALSA, maybe it is because of my buffer size (64). |
Can you successfully run in debug with cpal v0.16? (the “old” code with ~4 periods)
JACK sets 3 periods, I believe.
Yes that’s another thing to look into later. It was recently cleaned up for CoreAudio, we can take a similar approach in a later PR for ALSA. |
The issue in debug is not really about drop outs, it is more that it crashes. |
I see. Could you let me know if it also happens on v0.16? That would be very helpful to isolate if it’s this PR or something else. |
@abique or others with more feedback on this? I'd like to include this in v0.17 but only if it's found not to be a regression from v0.16. |
…ormance Implement device-aware period configuration strategy: - Query device limits to determine optimal approach - Prefer double buffering when buffer fits within device period size limits - Use multi-period configuration for larger buffers with calculated period distribution - Fallback to buffer-size-only configuration for maximum device compatibility Performance optimizations: - Pre-allocate worker thread buffers and silence templates - Cache period_frames and period_samples in StreamInner for hot path performance - Pre-fill descriptors array once instead of reallocating on each poll
b18b54e
to
87137b4
Compare
f434bbc
to
26b1092
Compare
Merging this - got things cooking for the other hosts' buffer behavior as well, and need this as basis. Don't hesitate to reopen if this causes regressions from v0.16 (remembering that used four periods and this two - so you may want a larger buffer now). |
Improves audio callback performance through device-aware buffering, pre-allocation and period-aligned writes. This results in more consistent latency control and improved hot path performance.
Also fixes a DC offset issue with unsigned formats by proper silence (equilibrium) handling.
Period Configuration Strategy
Queries device capabilities to determine which approach to use:
Audio Quality Improvements
sink.sleep_until_end()
Performance & Real-Time Improvements
transfer_buffer
,silence_template
,descriptors
) at stream creationperiod_frames
andperiod_samples
inStreamInner
to avoid repeated calculationsThanks to @abique for the discussions
Supersedes: