Skip to content

Fix ASIO callback and audio buffer contract bugs - #638

Merged
mdias merged 1 commit into
mdias:masterfrom
L0FKA:fix/asio-contract-audio-formats
Sep 8, 2026
Merged

mdias merged 1 commit into
mdias:masterfrom
L0FKA:fix/asio-contract-audio-formats

Conversation

@L0FKA

@L0FKA L0FKA commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Below is autogenerated summary I distilled from my upstream, theres part of my next pr about calibration.

Summary

Fix five small correctness issues in the existing ASIO/WASAPI adapter code:

  • return the asioMessage result that was already computed and logged;
  • decode and write ASIOSTInt24LSB samples in little-endian byte order during software volume processing;
  • report success after processing ASIOSTFloat32LSB volume;
  • use the correct four-byte input width for Int32-to-Float64 conversion;
  • reject partial capture-buffer releases with AUDCLNT_E_INVALID_SIZE while preserving the documented zero-frame discard case.

Failure modes

AsioCalback_asioMessage previously logged ret but returned 0, so selectors such as kAsioEngineVersion never received the advertised result.

The Int24 volume path treated the third (most-significant) byte as the low byte. Negative values were not sign-extended from bit 23, and the result was written back in a different byte order.

The Int32-to-Float64 matrix selected AudioCopyConvertI2F<5, double> even though each input sample is four bytes. That advances through the source with the wrong sample width and can read beyond the final sample.

The Float32 volume path completed its work but fell through and returned false.

IAudioCaptureClient::ReleaseBuffer accepted arbitrary partial frame counts. For this fixed-size packet implementation, only zero or the complete acquired packet size is valid.

@mdias

mdias commented Sep 8, 2026

Copy link
Copy Markdown
Owner

These look very nice to me!
I do have a vague memory of playing around with the return value of AsioSharedHost::AsioCalback_asioMessage but I don't recall if this was left like this on purpose or by accident 😅
In any case, your change does the correct thing.

Did you check if this is still working fine ingame? If so, I'll just merge it :)

@L0FKA

L0FKA commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Game works but I only ran synthetic tests since my device is Int32LSB only. It also part of my fork so this code wont cause trouble for regular users on standard rates. I made a test for forced Int32 - float64 - Int24 - Int32 path and theres zero errors/xruns.

Up my other pr sleeve is:
Type conversion table init thread safe fix
Tests for the conversion matrix
Sample type clamp and smid optimizations (above 100% input gain clamp)
Software volume control(pcm frames mod)
RMS detector for all suportef formats
SMID deinterleave transport feature
With fised stereo transfer (sse2)
Suport for MSB LSB formats conversion, endiannes conversion etc.

I need real hardware to see formats support work on real hw cleanly.

@mdias
mdias merged commit c18cfe2 into mdias:master Sep 8, 2026
1 check passed
@mdias

mdias commented Sep 8, 2026

Copy link
Copy Markdown
Owner

Yeah, every interface I have also only works with Int32LSB, so we just have to rely on user reports if other formats are an issue :(

Anyway, merged! Thank you 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants