Skip to content

Sound banks disassembly#760

Open
freshollie wants to merge 11 commits inton64decomp:masterfrom
freshollie:banks_extract
Open

Sound banks disassembly#760
freshollie wants to merge 11 commits inton64decomp:masterfrom
freshollie:banks_extract

Conversation

@freshollie
Copy link

@freshollie freshollie commented Mar 14, 2026

I'm using this to help me port to the PS2, but I thought that it might be useful to upstream this change.

A0.aiff and 68.aiff samples cannot be matching decoded yet. The permutation has to give up after 1 million tries. For now, these are extraced as compressed aifc but not decoded.

The files for dissasmbly come from the sm64 project and have been hand modified to handle the format of the files for mk64. Specifically:

  • The drums_list can contain null values in mk64 so those need to be included in the json files
  • Some of the samples contain a flags value of non zero (was always zero in sm64), so we decode that value and store it in the aiff as a custom VADPCMFLAGS header. I had to update the decoder, vadpcm encoder, and the sound assembler to handle this

@MegaMech
Copy link
Collaborator

MegaMech commented Mar 14, 2026

Does mk64 use unconventional aifc? Is the sample data itself different from sm64?

Maybe oot supports aifc?

@freshollie
Copy link
Author

I tried the oot decoder and couldn't handle the files.

mk64 does store a flag value of in some of the samples, which in the latest commit I have managed to extract and store in the aiff files.

The aifc non matching is likely because the permute logic in the decoder is good enough to handle the ~5 frames of samples which can't be directly matches as aiff.

Copy link
Author

Choose a reason for hiding this comment

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

Copied straight from the sm64 repo

Copy link
Author

@freshollie freshollie Mar 14, 2026

Choose a reason for hiding this comment

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

adpcm copied straight from sm64, though vadpcm_enc.c has been modified for handling the VADPCMFLAGS header

Comment on lines +233 to +237
if (strcmp("VADPCMFLAGS", ChunkName) == 0)
{
fread(&vadpcmFlags, sizeof(vadpcmFlags), 1, ifile);
BSWAP32(vadpcmFlags)
}
Copy link
Author

Choose a reason for hiding this comment

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

Read the value

Comment on lines +331 to +341
strnLen = sizeof("VADPCMFLAGS") - 1;
AppChunk.ckID = 0x4150504c; // APPL
AppChunk.ckSize = 4 + 1 + strnLen + 4;
AppChunk.formType = 0x73746f63; // stoc
BSWAP32(AppChunk.ckID)
BSWAP32(AppChunk.ckSize)
BSWAP32(AppChunk.formType)
fwrite(&AppChunk, sizeof(Chunk), 1, ofile);
fwrite(&strnLen, 1, 1, ofile);
fwrite(appFlagName, strnLen, 1, ofile);
fwrite(&vadpcmFlags, sizeof(vadpcmFlags), 1, ofile);
Copy link
Author

Choose a reason for hiding this comment

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

Write the value into the aifc so that it can be read by assemble_sound.py

Copy link
Author

Choose a reason for hiding this comment

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

Copied directly from sm64

Comment on lines +513 to +515
} else if (strcmp("VADPCMFLAGS", ChunkName) == 0) {
checked_fread(&vadpcmFlags, sizeof(u32), 1, ifile);
BSWAP32(vadpcmFlags);
Copy link
Author

Choose a reason for hiding this comment

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

Read the flag from the aifc file generated by disassemble_sound.py

Comment on lines +664 to +667
write_header(ofile, "APPL", 4 + 12 + sizeof(vadpcmFlags));
fwrite("stoc", 4, 1, ofile);
fwrite("\x0bVADPCMFLAGS", 12, 1, ofile);
fwrite(&vadpcmFlags, sizeof(vadpcmFlags), 1, ofile);
Copy link
Author

Choose a reason for hiding this comment

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

Store the VADPCMFLAGS value in the aiff file

Copy link
Author

Choose a reason for hiding this comment

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

Unmodified from sm64

Copy link
Author

Choose a reason for hiding this comment

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

from sm64

if len(pos) == 1:
rom_offset = None
block_offset = None
elif pos[0] == "@sound":
Copy link
Author

Choose a reason for hiding this comment

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

Changes ported over from sm64

Copy link
Author

Choose a reason for hiding this comment

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

Copied in from sm64 with minor changes

Comment on lines +567 to +570
if (++iter > 1000000) {
printf("Failed to match frame %d after 1000000 attempts\n", currPos);
break;
}
Copy link
Author

Choose a reason for hiding this comment

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

TODO: remove this once we can figure out a way to match A0.aiff and 63.aiff

$(BUILD_DIR)/data/sound_data/audiobanks.o: $(SOUND_BIN_DIR)/sound_data.ctl
$(BUILD_DIR)/data/sound_data/audiotables.o: $(SOUND_BIN_DIR)/sound_data.tbl

# TODO: the rest of these rules are currently not used by the build since sequences.json has not been dissambled
Copy link
Author

Choose a reason for hiding this comment

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

Not sure how to create a sequences.json. It would be cleaner if we could but I can't see any scripts to do this.

@MegaMech
Copy link
Collaborator

MegaMech commented Mar 14, 2026

Also,

Torch supports extracting aiff, aifc, and m64.

@MegaMech
Copy link
Collaborator

@MegaMech
Copy link
Collaborator

If you join the Discord it might be easier to chat.

@freshollie
Copy link
Author

Getting closer to a match. I realised that I think I messed something up before and the assemble_sound script can indeed read the raw aifc files for the ones which can't be matching decoded.

@freshollie freshollie changed the title [WIP] sound disassembly [WIP] sound banks disassembly Mar 14, 2026
@freshollie freshollie changed the title [WIP] sound banks disassembly Sound banks disassembly Mar 19, 2026
@freshollie
Copy link
Author

Matches :)

@freshollie freshollie marked this pull request as ready for review March 19, 2026 01:57
@freshollie
Copy link
Author

Btw I checked and if I used torch for extraction, the decoder does not produce matching aiff's due to this (if 0) https://github.com/HarbourMasters/Torch/blob/654b451ddc6cf25db201b2c858948f430784cc5f/src/factories/naudio/v0/AIFCDecode.cpp#L557

Also I'm not sure about the the banks because to me it looks like the BanksFactory write a custom format asset file output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants