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

Freeze caused by waiting forever for audio buffer write #26

Open
andrew-hoffman opened this issue Feb 21, 2016 · 0 comments
Open

Freeze caused by waiting forever for audio buffer write #26

andrew-hoffman opened this issue Feb 21, 2016 · 0 comments

Comments

@andrew-hoffman
Copy link
Owner

My laptop has an occasional issue where the sound device stops working completely, This affects various programs differently. Most browsers will still play video without the sound, Winamp won't start playback at all. I can fix that by disabling and re-enabling it in the Device Manager but it exposes a bug in my own software that I thought I'd mention here.

With HalfNES, with the sound disabled in Preferences things work normally. But if I turn on the sound everything freezes. The reason for this is that the SourceDataLine doesn't throw any exceptions when creating it with the system in this state but when I actually try to write to the buffer it blocks forever in a wait() loop.

Now I currently depend on the audio buffer blocking at least a little bit to maintain synchronization but I can't tell if its just going to block for a little bit or if no data is being drained from the buffer at all as far as I can tell.

Having an extra sentinel thread to interrupt the waiting if it's taking far too long doesn't work because of this lovely bit of code in the Swing mixer:
https://community.oracle.com/thread/2381571

I think to fix this will require changing to a different audio system, or rewriting my code to never attempt to block on the audio buffer at all. That will require outputting much finer grained chunks of audio, maybe a line worth rather than a frame worth (a good idea anyway) and finding some other more accurate source of 60/ 50 hz timing. I can't get anything like a vblank interrupt from Swing but JavaFX does have an animation timer that might work.

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

No branches or pull requests

1 participant