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

Changes for SFXSound::setPosition(time) #2220

merged 4 commits into from Mar 30, 2019


None yet
2 participants
Copy link

commented Mar 11, 2018

Note: Only tested with OpenAL.

The method sfxSound.setPosition(time) has some issues:
-The engine method has a miscalculation in some values.
-It doesn't work when the sound is stopped (so you can't modify the time before play).
-It doesn't work at all for files longer than 24 seconds that are streaming and looping (if they're shorter than 24 s, internally they're changed to not-streaming -sfxSystem.cpp: ~line 714-).

To check that you need a datablock SFXProfile with looping and streaming like:

datablock SFXProfile(SoundLength31sLS)
filename = "data/sfxSetPosTest/scripts/atime_31s";
description = AudioMusicLoop2D;

With that datablock loaded you create the sound with:
$sound_object = sfxCreateSource(SoundLength31sLS);

Then you can test various things like:


This pull request tries to fix those issues.
I'm not 100% sure if all it is alright.
Specially the changes to asyncPacketStream.h. But I don't see anywhere else where it is used.
Also not sure the effect with internet streaming sounds.
The SFXSound::_play() part is a bit "hack" but I don't know how to easily add the option for setPosition to work before playing.

Finally let me warn about a possible issue:
source\sfx\openal\sfxALBuffer.cpp(156,0): {Fatal} - SFXALBuffer::write() - buffer invalid

That may happen when setting the position immediatly after sfxCreateSource all in one line very fast like:

$sound_object = sfxCreateSource(SoundLength31sLS); $; $sound_object.setPosition(28);

But it's very hard for it to appear, as:
-It seems to appear only the first time a datablock is used.
-It seems to be affected by buffer load so you have to force continuous loads of sound.

I have no idea how to fix it. I'd love any help on that. Probably a while(true){ -check if buffer is ready then break the while;- } is needed somewhere.

To try to replicate it you can use the module I include at the end.
With that loaded start any level and just call

If it doesn't explode then you need to restart the game to try again (for the datablocks to be again 1st time). You can change that 500 to change how fast the files are reload, too.
And actually it is troublesome because the sound plays but the setPosition fails.

Ah, that error appears too before these pull request changes. But only in the cases where setPosition worked.

Example with some files you can use in this module:

irei1as added some commits Mar 11, 2018

@Areloch Areloch merged commit b618537 into GarageGames:development Mar 30, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.