With
the recent changes in music handling, I encountered occasional micro-stuttering when playing.
A brief investigation revealed that it's caused by contention on
MusInfo::CritSec.
This is quite noticeable with VSync enabled and (if you have fast CPU) using Debug configuration.
The problem is
ZMusic_FillStream() may take a while to process the next chunk of data.
Other functions called from the main thread,
ZMusic_Update() and
ZMusic_IsPlaying() in particular, have close to zero costs.
Although, they wait on the mentioned mutex. I saw 20 to 30 ms stalls because of that.
This is really annoying with VSync as 60 FPS becomes 30 every two or three seconds.
At the moment, I don't see how this can be fixed without moving back to old code with a bunch of internal critical sections.
Apparently, this "global" lock solves any kind of race conditions, but it introduced another problem.
In fact, this is quite similar to music playback on the main thread in the early version of OpenAL backend.
With [url=https://github.com/coelckers/gzdoom/commit/6854a509e9d11c5915c2c867ce6ad34527478224]the recent changes[/url] in music handling, I encountered occasional micro-stuttering when playing.
A brief investigation revealed that it's caused by contention on [url=https://github.com/coelckers/gzdoom/blob/777798ede4b68cc71d1e1313d491e70c0eef9593/libraries/zmusic/zmusic/musinfo.h#L41]MusInfo::CritSec[/url].
This is quite noticeable with VSync enabled and (if you have fast CPU) using Debug configuration.
The problem is [url=https://github.com/coelckers/gzdoom/blob/777798ede4b68cc71d1e1313d491e70c0eef9593/libraries/zmusic/zmusic/zmusic.cpp#L315-L320]ZMusic_FillStream()[/url] may take a while to process the next chunk of data.
Other functions called from the main thread, [b]ZMusic_Update()[/b] and [b]ZMusic_IsPlaying()[/b] in particular, have close to zero costs.
Although, they wait on the mentioned mutex. I saw 20 to 30 ms stalls because of that.
This is really annoying with VSync as 60 FPS becomes 30 every two or three seconds.
At the moment, I don't see how this can be fixed without moving back to old code with a bunch of internal critical sections.
Apparently, this "global" lock solves any kind of race conditions, but it introduced another problem.
In fact, this is quite similar to music playback on the main thread in the early version of OpenAL backend.