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

3.6.0: implement audio playback speed using resampling #1511

Merged
merged 2 commits into from
Jan 30, 2022

Conversation

ivan-mogilko
Copy link
Contributor

@ivan-mogilko ivan-mogilko commented Jan 22, 2022

Fixes #1503.

It's unclear whether AL_PITCH attribute in OpenAL actually means playback speed or not, the available specification is not clear about this, and in the mojoAL implementation we're using AL_PITCH scales the sample pitch but not the frequency, therefore speed stays the same.

This PR implements playback speed by resampling a portion of sound before we pass it into OpenAL. The result should be equivalent to pre-3.6.0 functionality where the dynamic frequency shift was supported by allegro 4.

So far the only problem I experienced was with calculating playback position, as we no longer may rely only on offset time the OpenAL reports. This is solved by keeping a record of speed and "sped up" time per each queued buffer, and applying these as the buffers are processed.
There's still some mistake which I was not able to track down to the end, which causes the calculated position jump back a little when the speed is changed from high to low (or maybe vice versa too, but that's harder to notice). To avoid confusing game scripts would they rely on sound pos, the audio player remembers last reported position and clamps new calculated value to it.

But it's still best to test this more to ensure that the position matches (or is at least close enough to) the original un-sped playback, and that it reaches the full duration in the end.

To be able to do so we have to remember playback speed per queued buffer and apply as necessary.

Unfortunately, there's still a mistake somewhere, which I was not able to track to the end: because of it the reported position may jump slightly backwards when the playback speed changes. Usually this happens when speed goes from high to low. As a dirty fix we remember the last reported position and clamp new report to it.
@ivan-mogilko ivan-mogilko merged commit 01e7358 into adventuregamestudio:master Jan 30, 2022
@ivan-mogilko ivan-mogilko deleted the 360--audiospeed branch January 30, 2022 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3.6.0: AudioChannel.Speed has no effect
1 participant