-
Notifications
You must be signed in to change notification settings - Fork 632
fix build and run on OpenBSD #6050
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
Merged
+3
−3
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0e6003e
On OpenBSD the game crashes. Check sample size and adjust aligned acc…
fabienr 6b652b7
fix build on OpenBSD
fabienr 5fd2b24
fix invalid operands to binary expression
fabienr 4105163
please clang-format
fabienr 04a6925
Revert "On OpenBSD the game crashes. Check sample size and adjust ali…
fabienr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when this is unconditional the audio issue still only happens on OpenBSD I assume
wondering why this can't either be unconditional, or if there's some alignment handling aLoadBuffer should be using instead
which is to say I don't really understand what's happening here, & would appreciate explanation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SANITIZE_ADDRESS came from Starship.
Check HarbourMasters/Starship@64442db
I'm mainly debugging there (in Starship) atm. But the following principle still stands and both are very similar.
The CODEC_ADPCM uses 9 bytes to decode into 16 samples. The first byte is important as it provides a hint on how to decode the following 8 bytes into 16 samples. Which means we can't decode half of a frame easily.
The function AudioSynth_ProcessNote calculates a number of samples to process but this isn't aligned to frames, thus the need for some math around (which I don't fully understand yet). In some cases this goes wrong and it tries to decode bytes outside the audioFontSample. OpenBSD is more strict so the software will crash early. Note it doesn't crash on all audioFontSample and I guess it's because of how the memory is allocated vs the size of the book which means there is room after the end of buffer and before the end of memory allocated. But still it's an out of bound read overflow.
My hypothesis is you will start noticing choppy audio on Linux if you enable the this check unconditionally.
I do not have Linux at hand so I can't compare easily. Maybe you could add a printf to check if Linux actually triggers the check ? Otherwise, it would mean something else deviated on OpenBSD and led to this crash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For information.
2ship have a similar issue, see comments in https://github.com/HarbourMasters/2ship2harkinian/blob/6dc782221eb46432f35bfb4cf3f64d70c0b8b640/mm/src/audio/lib/synthesis.c#L1212
SpaghettiKart have an unconditional bound check in https://github.com/HarbourMasters/SpaghettiKart/blob/186ea294aedd05efc9ab799507dd96040a05741c/src/audio/synthesis.c#L488
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does #6089 help? it has some fixes for audio samples
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't try the diff yet, it will fix the crash for sure with the extra padding.
From what I remember, it's a matter of a frame so at most 16 samples which are 9 bytes encoded.
Also, it memset to 0 so I'm curious which sound it will produce.
I doubt it will be exactly like intended but maybe ... will test for sure.
Also, this is the place to pre-decode samples in memory, maybe that would be easier (I guess).
Thanks for the hint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I revert SANITIZE_ADDRESS stuff.
Recently I realised the aLoadBufferImpl use ROUND_DOWN_16.
Shipwright/soh/soh/mixer.c
Line 103 in a92f07e
All games should at least align to 16 when allocating ADPCM bytecode.
I have no idea why there is that constraint on alignment.
From my ears it looks better now (less choppy) but still not correct (noisy, feels like choppy).
There is also skipInitialSamples which may push the buffer too far. I have no idea why it exists at start.
The extra 32 padding in AudioSampleFactory.cpp may not be needed.
Shipwright/soh/src/code/audio_synthesis.c
Line 883 in a92f07e
From my ears it doesn't seem better with the bellow change.
I think I need to record and compare on another OS.
I mean I need to narrow why the sound isn't as good as it should be (compared to emulation).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, these basic fixes are good, the audio stuff is better in its own PR when there's a better handle as to what's going on