-
Notifications
You must be signed in to change notification settings - Fork 134
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
Player is locked too much #188
Comments
Thanks!
The current lock is used not only for buffers but also for other members like I'll try the example later, thanks! |
The core issue is that an interface call |
We cannot expect what would happen in an external function call, and this might block unexpectedly. Actually this causes stutters. This changes fixes this issue by not locking when calling an external interface function Read. Closes #188
Couldn't have summarized it better. Thanks for the quick reply. |
We cannot expect what would happen in an external function call, and this might block unexpectedly. Actually this causes stutters. This changes fixes this issue by not locking when calling an external interface function Read. Closes #188
Hey there 👋 ,
I was seeing if I could make Beep working with Oto v2.0. I ran into a problem where the sound stutters when playing from an mp3 file. I think I've narrowed it down to the following:
There are two "loops"; one fills the player's buffer and the other consumes the buffer. The filling loop uses readSourceToBuffer and the consuming loop uses readBufferAndAdd. For both functions, during the entire duration of the function, they lock a lock.
I don't think this is intentional. This defeats the purpose of the buffer. For example, if filling of the buffer takes longer than the time between consuming function calls, the consumer has to wait for the filling to be done.
Instead I would expect
readSourceToBuffer
to fill the player'sp.tmpBuf
, then lock and append thep.tmpBuf
top.buf
. In this case it matters less that reading fromsrc
takes a bit long because thereadBufferAndAdd
can consume buffer still and appendingp.tmpBuf
top.buf
is fast.The mp3 streaming example in the README doesn't have this problem. This is because the mp3 decoder reader returns less bytes than player requested. The requested number of bytes is about 0.5 sec worth of samples long by default. With Beep, the current implementation of the Mixer does try to fill the whole buffer by repeatedly calling the mp3 reader. This takes long enough that the above problem occurs on my laptop (about 60ms).
I've made an example so you can hear the problem yourself. The following code has a reader which will sleep for 100ms every 0.5sec of samples. On my machine, the sounds starts stuttering around 65ms of delay, 100ms is used to make it more obvious. It should take <200ms to read 0.5sec of samples. Which should be enough if the buffer worked correctly, but isn't.
Change the path in the example to an existing mp3 file on your computer.
Note that I'm not sure how much of this Beep will use in the future. But I hope this bug report helps.
Sidenote:
readSourceToBuffer
could be called in parallel for all players instead of sequentially. This would give even more wiggle room for readers to be slow. But that's a nice to have.The text was updated successfully, but these errors were encountered: