Wallpaper Engine

Wallpaper Engine

View Stats:
OMGparticles Feb 24, 2020 @ 1:18am
Scripting an event at a specific time in a sound
I'm looping some music, but I'm doing it through script instead of the layer's loop setting because I want it to loop at a specific time in the song rather than playing all the way to the end. I'm also doing a bit of a crossfade effect when it loops. I've got this working by adding up engine.frametime for each frame that the sound is playing until I reach my desired threshold, at which point I loop the audio.

I've run into a couple issues with this, the first being with the "Other application playing audio: Mute" setting. It seems that when another application plays audio, it will first fade out the volume to 0 which is fine. But after that, rather than it simply sitting at 0 volume, it seems that it instead pauses all sound layers. The sounds will then resume where they left off once all other applications stop playing audio. This throws off my looping behavior as the time accumulator keeps adding up while the music is paused. I tried checking isPlaying() on the music layer, but it unfortunately seems to return true even though the layer acts like it is paused during this time.

I'm not sure how to get around this since I don't see any way to check in script whether the audio is paused in this way so that I can stop accumulating my timer.

The second issue I've run into is that engine.frametime is multiplied by the wallpaper's playback rate, whereas the playback of sounds is not affected by this setting. So It's no longer an accurate way of measuring where I am in the sound if it's anything other than 100% playback rate.

Possible solution:
Add a new property to ISoundLayer that gets (and potentially sets) the current elapsed time for the sound being played. Another property that gets the total length of the sound would be nice as well.
Last edited by OMGparticles; Feb 24, 2020 @ 9:37am
< >
Showing 1-2 of 2 comments
Biohazard  [developer] Feb 24, 2020 @ 9:48am 
It's true that it pauses instead of muting, I think naming the option 'mute' is just more intuitive for users, even if not technically accurate.

I can't think of a solution right now that wouldn't require replacing the whole audio system and trying whatever else I might find. The issue is that the audio system that scenes use is just a bit buggy. It's not too serious, but you can completely forget about getting reliable playback state from the audio instances, including the time elapsed.

The frametime is decelerated/accelerated when pausing, yeah. This is done globally for a scene since the visuals look better this way, the audio system is running on it's own threads and too independently to hook it up to this (and it would sound worse since it'd normally pitch shift anyway).

If the elapsed time from sounds could be read reliably, I could expose it via scripts in the future, but I have no idea whether the library we're using has a fix for this already or gets better support in the future.
OMGparticles Feb 24, 2020 @ 9:57am 
Hmm I see, well thanks anyways. I'll just have to deal with it for now I guess.
< >
Showing 1-2 of 2 comments
Per page: 1530 50

Date Posted: Feb 24, 2020 @ 1:18am
Posts: 2