Skip to content
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

FlexASIO never waits for ASIOOutputReady() #180

Closed
dechamps opened this issue Jan 21, 2023 · 2 comments
Closed

FlexASIO never waits for ASIOOutputReady() #180

dechamps opened this issue Jan 21, 2023 · 2 comments
Labels
Milestone

Comments

@dechamps
Copy link
Owner

dechamps commented Jan 21, 2023

While reviewing some FlexASIO code I stumbled upon this:

std::unique_lock outputReadyLock(outputReadyMutex);
if (!outputReady) {
if (IsLoggingEnabled()) Log() << "Waiting for the ASIO Host Application to signal OutputReady";
outputReadyCondition.wait(outputReadyLock, [&] { return outputReady; });
outputReady = false;
}

I suspect this is subtly wrong. With this code outputReady only gets reset if it happened to get set after we started waiting for the condition. If outputReady was already true before we entered this block, then it will stay true forever. That doesn't seem right. The reset should happen unconditionally.

The consequence of outputReady being stuck at true is that ASIO output buffers will be transferred to PortAudio before the ASIO host application is done writing them, leading to corrupted audio output.

One reason why this went unnoticed until now is probably because this only has consequences in ASIO Host Applications that support OutputReady and return from bufferSwitch before they call it. I suspect such applications are rare.

@dechamps dechamps added the bug label Jan 21, 2023
@dechamps dechamps added this to the FlexASIO 1.10 milestone Jan 22, 2023
@dechamps
Copy link
Owner Author

This is fixed in FlexASIO 1.10.

@dechamps
Copy link
Owner Author

In retrospect, given the investigation in #235, it turns out this bug was worse than I originally thought: indeed the initial value of outputReady is true, which means we would never wait for outputReady, period. The wait code was basically dead until the fix. Thankfully, it looks most ASIO applications call outputReady before returning before bufferSwitch anyway, which means this bug would have no consequences for them.

@dechamps dechamps changed the title FlexASIO skips waiting for ASIOOutputReady() if it is called early FlexASIO never waits for ASIOOutputReady() May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant