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

Music stutter #18

Closed
ghost opened this issue Oct 27, 2012 · 11 comments
Closed

Music stutter #18

ghost opened this issue Oct 27, 2012 · 11 comments

Comments

@ghost
Copy link

ghost commented Oct 27, 2012

I noticed that music stutter sometimes. Can't tell what kind of music format is that.
This happened in Ben Jordan 8 and King's Quest 2 so far (but I just did not test much games).

Does not happen when I run original game's executable (and it's quite distinctive).
It's like AGS repeats a small bit of music every 3-4 seconds.

@jjsat
Copy link
Contributor

jjsat commented Nov 1, 2012

Interestingly I don't experience this problem in either BJ8 or KQ2, but in The Apprentice. At least in the Windows version, not on Android though. This is the only game I ever had this specific sound issue.

@ghost
Copy link
Author

ghost commented Nov 1, 2012

I'll test this more some time later. Might be there are more conditions for this to happen.

@ghost
Copy link
Author

ghost commented Nov 27, 2013

A long due update: this seem to be related to threaded audio feature. Occurs not all times and not in all games, but when threaded audio is off this never happened.
Authors of the upcoming "Heroine Quest" game reported that this happens nearly 100% time when their game is run on Windows 8 with threaded audio on, and never if it is off.

May or may not be related to #82.

@jjsat
Copy link
Contributor

jjsat commented Nov 27, 2013

Tried it in Virtualbox with Windows 8. Sound always stutters in this particular way with threaded audio enabled. Bummer. Also checked out monkey's build but it didn't make a difference for me.

E: I also tried my branch with the updated libraries. Unfortunately this doesn't help with the issue either.

@jjsat
Copy link
Contributor

jjsat commented Nov 28, 2013

Just noticed: The stuttering stops if the polling loop runs more often. Changing https://github.com/adventuregamestudio/ags/blob/master/Engine/main/engine.cpp#L1275 to 20 ms completely cures the problem for me on Win 8.

In the non-threaded version the polling loop runs multiple times per frame, I would assume that it runs less often even with 10 ms delay. But that would have to be measured. I was initially just choosing a value that "works" while not wasting cycles.

@ghost
Copy link
Author

ghost commented Nov 28, 2013

I do not know how the audio poll works in detail, but is there a way to calculate delay by knowing minimal size of data chunk buffered at a time?

@rofl0r

This comment was marked as abuse.

@jjsat
Copy link
Contributor

jjsat commented Dec 1, 2013

The engine request 16/32 kiB buffers for static/streaming ogg and mp3. This is enough for 100/200 ms of audio data at 44.1 kHz in 16Bit stereo.

But the problem is that the Sleep() call in the Windows platform driver is split into 5 ms chunks. It seems like the standard timer resolution of Windows is 15 ms, which therefore causes 3 times the requested delay. That's why it stutters. Running Windows Media Player in the background brings the resolution down to about 8 ms, I remember reading something about that effect too.

For some reason Windows switches to a 1 ms timer resolution when you start an AGS game on my Windows 7. It does not do this on Windows 8.

@jjsat
Copy link
Contributor

jjsat commented Dec 1, 2013

Putting timeBeginPeriod (http://msdn.microsoft.com/en-us/library/windows/desktop/dd757624%28v=vs.85%29.aspx) with 1 ms into the startup code fixes the issue for me. Since we do something to that effect anyway (it just doesn't work on Windows 8) we might as well go this route. Other apps do it too, e.g. Firefox also sets 1 ms. This is a program that can show the current value of the timer: http://www.lucashale.com/timer-resolution/

@jjsat
Copy link
Contributor

jjsat commented Dec 10, 2013

I pushed a possible fix here: ade47ce

@ghost
Copy link
Author

ghost commented Dec 18, 2013

According to game devs' replies the stuttering is gone. There's still a minor problem with Pamela lip-sync, but that is probably different issue.
I am closing this one now.

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

3 participants