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

Use SourceDataLine instead of Clip for playback #77

Merged
merged 1 commit into from
Oct 24, 2024

Conversation

Nianna
Copy link
Owner

@Nianna Nianna commented Oct 24, 2024

Clip does not have any methods for specifying the place where the playback should end - it always plays the sound till the end of the file.
Previous approach that used Thread.sleep combined with getMicrosecondPosition method is less than ideal, the method itself is inaccurate as the position is updated only once every 10 ms or so. Moreover it takes about 20 ms more from the clip.stop() method call to the time the playback actually stops, increasing the error. All in all, the starting point is deterministic, but the ending point is not - it is always 20+ ms late.

New approach uses more low-level solution by passing only the bytes from relevant frames to SourceDataLine for playback. Both the starting and the ending points are now fully deterministic and as accurate as they can be (down to one frame).

The audio file data is still loaded only once and kept in-mem.

@Nianna Nianna merged commit e4284c2 into master Oct 24, 2024
1 check passed
@Nianna Nianna deleted the fix/increase-accuracy-of-non-mp3-playback branch October 24, 2024 13:05
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.

1 participant