-
Notifications
You must be signed in to change notification settings - Fork 14
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
SPC Import functionality #23
Conversation
ChrisBlueStone
commented
Feb 17, 2022
- Added limited SPC import functionality.
- Cleaned up blank template SPC.
* Added limited SPC import functionality. * Cleaned up blank template SPC.
* Refactored some BRR decoding logic. * Added code to verify the loop position aligns with a BRR block, which fixed a bug where the `decoding_start` position would be larger than it should be and corrupt memory in the `decode_brr_block` call.
* Added an out of bounds check when counting BRR blocks. * Added back a line that was accidentally removed.
Updated SPC loading to be able to load SPC files more generically and not be limited to SPCs from EarthBound.
Added a different music address searching algorithm that scans the patterns pointed to by $F0. If that fails it falls back to trying to use the music table if it found one.
Updated SPC exporting to scape out a portion of the program block and cram as many samples into the SPC as it can. This required moving the note lengths table as well and updating the program to point to the new location. Also note, exported SPCs can play but can't be reimported for some reason.
- Fixed exporting of the sample pointer table to include the loop addresses. Oops. - Changed the internal reference to the sample pointer table to use an offset instead of an actual address.
src/main.c
Outdated
const unsigned int NUM_INSTRUMENTS = 128; | ||
const WORD dstSamplePointers = dstMusic + 0x100 + (size & 0xFF00); | ||
const WORD dstInstruments = dstSamplePointers + 0x2*NUM_INSTRUMENTS; | ||
const WORD inst_size = NUM_INSTRUMENTS*6; | ||
const WORD dstSamples = dstInstruments + inst_size; |
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 think NUM_INSTRUMENTS should be 64. This matches with Earthbound's memory layout:
6C00-6DFF: Sample table: struct { WORD start; WORD loop; } [64] // Okay actually this doesn't match, only takes up 0x100 bytes - so you could maybe move it closer and get more space!
6E00-6F7F: Instrument table: byte [6*64] // 6*64=0x180 bytes, the exact size normally allocated
6F80-6F97: Misc data tables, 0x18 bytes
Notably, having 128 instruments takes up 0x300 bytes for the instrument table, which is 2x the normal space, which is what leads me to say that NUM_INSTRUMENTS should be 64. Have you seen games with more than 64 instruments?
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.
Space Armada from StarFox uses 74 apparently unless something else is wrong somewhere. I've bumped it down to 80 and that seems to work.
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.
Perhaps we should bump this back up just to be safe of other SPCs?
- Fixed a bug where the sample pointers weren't not being indexed into correctly. (`brr_copy[i]` instead of `brr_copy[2*i]`) - Fixed BRR block counting to return 0 if invalid. - Updated number of instruments to export to 80. - Updating logging information. - Added a 16 byte buffer between exported data.
Fixed crashes that occur when playing an SPC while opening a ROM.
Fixed a crash caused by the last commit where closing and opening a rom would crash the app
Fixed for a potential memory leak by freeing samples before decoding them when importing an SPC
Loading a ROM used to clear the playback state, but it stopped working with one of the previous commits. This change changes the functionality to assume `close_rom` means to close the the current ROM and/or any currently loaded SPCs and will correctly reset the playback state in either case to prevent crashes.
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.
Kinda tired, but hopefully that's all the important bits to consider.
Pointer casts always make me nervous, but since the rest of ebmused uses them they can't be too awful I guess?
- Added file read validation when importing SPCs. - Added safer parsing when searching for a music address. - Put constants in an enum. - Changed memset calls for single-byte changes. - Changed addressing while exporting an SPC file to use array indexing.
Fixed potential bug when using memcpy to copy to/from different locations of the same array.
- Fixed a value that changed since casting a pointer to a WORD* - Updated `maxPatterns` to prevent misaligned pointer arithmetic and round down.