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

fixed audio (we're done here) #80084

Merged
merged 4 commits into from
Mar 10, 2025

Conversation

redpenguiney
Copy link
Contributor

Summary

None

Purpose of change

While cleaning up the code for PR #80033, I accidentally completely ruined the control flow, causing sound effects to never get halted, so sound effects stopped working after enough sounds had been played to use up all the available channels.

Describe the solution

Fixed the control flow, making it so audio loops (silently) until it is halted by the main thread.

Describe alternatives you've considered

None

Testing

Played a great deal of sound effects over ~10 minutes, some of which were done in slow motion. Seemed okay.
Even when I set it so that only two audio channels were available for sound effects, it still worked correctly (although, as expected in that case it could only play two sounds at a time).

Additional context

It's possible that when I did a bunch of git suffering to get this on its own branch that I messed something up (although I did test it after moving it here).

@Maleclypse Maleclypse changed the title we're done here we're done here (sound effects stop again) Mar 9, 2025
@Maleclypse
Copy link
Member

I love a good title pun, but I also want it to be readable enough that when I include that pun in the permanent changelog it makes sense. Sorry for adding context to your title.

@github-actions github-actions bot added [C++] Changes (can be) made in C++. Previously named `Code` astyled astyled PR, label is assigned by github actions json-styled JSON lint passed, label assigned by github actions labels Mar 9, 2025
@redpenguiney
Copy link
Contributor Author

redpenguiney commented Mar 9, 2025

I love a good title pun, but I also want it to be readable enough that when I include that pun in the permanent changelog it makes sense. Sorry for adding context to your title.

oh whoops, i forgot it defaulted to the name of the commit, lol

@redpenguiney redpenguiney changed the title we're done here (sound effects stop again) fixed audio (again, again) Mar 9, 2025
@redpenguiney redpenguiney changed the title fixed audio (again, again) fixed audio (we're done here) Mar 9, 2025
@github-actions github-actions bot removed the astyled astyled PR, label is assigned by github actions label Mar 9, 2025
@github-actions github-actions bot added astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions labels Mar 9, 2025
@GuardianDll GuardianDll merged commit b6fcf1e into CleverRaven:master Mar 10, 2025
28 checks passed
@akrieger
Copy link
Member

I took a look into it while on the plane, and a more straightforward option instead of this juggling of responsibility back and forth would be to call something like Mix_FadeOutChannel with a 0ms timeout. This internally lets the sdl mixer framework handle cleanup naturally. It seems like the audio callback gets invoked one more time but we can just return all zeroes for the sample.

}

// check if the sound effect should end bc we done looping
if( !handler->marked_for_termination && handler->loops_remaining < -1 ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is handler->loops_remaining < -1 necessary here? If we're in this branch it's already -1 or less which means we've already played all zeroes before.

Copy link
Contributor Author

@redpenguiney redpenguiney Mar 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it seemed necessary: I found that when I stopped it immediately, the last part of the sound effect got cut off (I theorize this is because when loops_remaining goes from 0 to -1, while we're done sending the audio data, the audio device hasn't finished playing it quite yet)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe going with Mix_FadeOutChannel handles that since it seems to allow the current sample to play out.

I may put up my own PR to try that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although IDK at this rate we'd probably expose some other edge case where the fadeout triggers immediately and truncates the audio that we just returned.

@redpenguiney
Copy link
Contributor Author

I took a look into it while on the plane, and a more straightforward option instead of this juggling of responsibility back and forth would be to call something like Mix_FadeOutChannel with a 0ms timeout. This internally lets the sdl mixer framework handle cleanup naturally. It seems like the audio callback gets invoked one more time but we can just return all zeroes for the sample.

Oh, that would've been convenient. I'd never messed with anything SDL or even audio-related before these PRs so I didn't know. If, god forbid, more issues spring up I'll swap it out to remove complexity.

@redpenguiney redpenguiney deleted the audio_work_fix_5 branch March 10, 2025 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions [C++] Changes (can be) made in C++. Previously named `Code` json-styled JSON lint passed, label assigned by github actions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants