I'm working on releasing an WinRT version of one of my games on the Windows Store. So far, so good, except that a background sound loop that should play forever doesn't repeat, and simply stops after being played once. I'm using Gideros 2015.10 at the moment. It works on the Gideros Player on Windows, and I haven't had any trouble with the Android or iOS versions, but after building the exported giderosgame.Windows project and running the result, the sounds don't seem to loop.
Has anyone else encountered this? Does anyone have any suggestions?
Paul
Comments
http://giderosmobile.com/forum/discussion/5644/gideros-player-2015-04-08-not-functioning/p1
Likes: SinisterSoft
I'd forgotten that some time ago, for a number of reasons including to avoid slight gaps in playback and some strange crashes related to looping sounds, I changed the way this game plays its looping background. Rather than using the built-in looping feature, I continually check the position of the sound player, and if it's within a quarter second of the end, I jump it back to a quarter second in from the beginning. Doing this a quarter second before the end prevents the sound from ending between checks, and starting a quarter second in prevents a slight stutter I get if I try to start at the very beginning. The code to keep the sound looping looks like this:
if (sound_player[cat]:getPosition() > sound_length[cat] - 250) then
sound_player[cat]:setPosition(250)
end
This seems to be what's failing on the WinRT build. Perhaps SoundChannel:getPosition() or SoundChannel:setPosition() doesn't work on all systems. I'll try a few experiments to see if I can rule out either of those.
Paul
While I'm not seeing that happen when jumping back in the sound file a full second before the end, it's possible that in some environments even that may fail. So I've also added a safety measure - if it finds the sound is no longer playing, indicating it reached its end before any call to getPosition() showed it was close to doing so, the sound will be restarted. If that happens there's a tiny gap in the sound. In this case the background sound loop is that of a running river or stream of various speeds. In the louder and faster sounds, the tiny gap to replay the sound is noticeable, but it's far better than the sound simply stopping.
Paul
Likes: MobAmuse
https://deluxepixel.com
I think I can see a source of error in getPosition:
https://github.com/gideros/gideros/blob/master/libgid/src/gaudio-sample-xaudio2.cpp#L233
so offset is the number of seconds from the start of the sample and this is cast to an int before being multiplied by 1000 and returned so this would explain highly inaccurate numbers (no better accuracy than 1 second). I will fix this, sorry!
WinRT using an audio system called XAudio2 (all other platforms use OpenAL). On XAudio2, setPosition is potentially an expensive operation as there is no way to change the position of a "sourceVoice" directly as there is in OpenAL. Instead you need to destroy the sourceVoice and recreate it to start at the new desired position.
So overall, it might be better to simply use the built in looping feature and perhaps accept a slight glitch in the sound as it loops.
https://github.com/gideros/gideros
https://www.youtube.com/c/JohnBlackburn1975
I'm shooting content for a future version of this game, and the full set of content will far exceed 50 MB, so I'll have to work out the issues with expansion files in one form or another. Perhaps then I'll make the switch to WAV files. I might be able to tighten up a few things to free enough space to make the few sounds that loop into WAVs.
In the meantime things seem to be working well.
Thanks looking into the getPosition issue. Regardless of looping issues, it will be helpful to have that returning more precise values.
Paul