osu-framework icon indicating copy to clipboard operation
osu-framework copied to clipboard

Add an option to change behavior of `IsAlive` in SampleChannel

Open hwsmm opened this issue 1 year ago • 5 comments

This PR provides an option to change behavior of IsAlive in SampleChannel. To make auto-free work, https://github.com/ppy/osu-framework/pull/6397 is required.

If ManualFree is false (default), it works the same as before: IsAlive will be false after Stop or the end of playback. If ManualFree is true, IsAlive will never be true until the user explicitly calls Dispose.

It also contains a fix for an issue where calling Play after disposal makes Playing true.

hwsmm avatar Oct 25 '24 12:10 hwsmm

Should we make SampleChannels not resumable?

How about we add a bool ManualFree { get; set; } to the interface? Opposite of BASS' auto-free because interfaces can't have default values (we really should be doing sample.GetChannel(new ChannelProperties { ... }) or similar, but...).

And then, every other case should auto-free when playback ends or Stop() is called.

I believe everywhere in osu! we operate under the assumption that channels are auto-freeing by default as I believe that's effectively how they work in BASS when they're HCHANNELs, so this could be considered a regression from when mixers were added (and they were made into HSTREAMs).

smoogipoo avatar Nov 20 '24 07:11 smoogipoo

I think adding ManualFree flag is unnecessary as it's only relevant when Looping is true. Adding a comment about this may be helpful?

When Looping is false, SampleChannel is automatically disposed once playback ends, but when Looping is true, you're responsible for disposing this channel manually, as the framework can't detect its end.

hwsmm avatar Nov 23 '24 07:11 hwsmm

So what happens when the channel is played, manually stopped, and the ISample is just left to live (as we never dispose samples in game)? It sounds like in this case samples would never be disposed, no?

smoogipoo avatar Nov 26 '24 15:11 smoogipoo

That's right. I'll live until it gets disposed somehow.

I think there is a misunderstanding about ManualFree. Do you want channels to be unable to resume playback once it is stopped when ManualFree is false?

I first assumed that you don't want such behavior, but I guess I misread your comment.

I'm okay with that if that's what you mean.

hwsmm avatar Nov 26 '24 15:11 hwsmm

Yeah, my idea is to consider Stop() the same as playback end. That way everything is safe except when you set ManualFree = true, which is the only case you need to make a conscious effort to handle it.

smoogipoo avatar Nov 28 '24 10:11 smoogipoo