DC music for Shenmue II

Joined
Jul 26, 2018
Location
Germany
Favourite title
Shenmue II
Okay here's something that should get some brainstorming and work done: Replacing the wrong music tracks in I&II's Shenmue II.

The intention here is not to fix how the rerelease make some tunes sound slightly wrong, though it would be cool if that was possible and what I have in mind might require some work in that direction.

When Shenmue II was ported to the Xbox, they used the wrong assets in a couple of places and that also affects the music.
In particular, these are (some of) the tracks that sound noticably different in the Xbox version and 100% for the worse.
  • Zhangyu's Wude lesson
  • Beverly Hills Wharf
  • Guilin arrival
  • The Saga continues
The idea is to replace the music tracks in question with files from the Dreamcast version to get the right melodies back.
This is very much possible in concept, as the audio system are pretty much the same and files are interchangeable.

I have already tried messing around with this and the result were... well not pleaseant to the ears.
I did manage to get music from the Dreamcast version into I&II cutscenes and while the melodies were played correctly there were some harsh, loud and really irritating noises in about every track I tried. I also tried pulling some files from the Xbox version just for testing. As they should be identical to what I&II uses, they still sounded exactly the same way wrong as the DC files.

So bummer... Shenmue I&II must have some adjustments to each of the music tracks so they play right in the rather iffy sound engine or the engine itself has specific adjustments per track. Remember how random areas of the game got improved music with each patch? It must be either one and that causes an unmodified track from the original to not play correctly at all.

There are some issues beyond that. Zhangyu's music is a file with multiple tracks. There are a bunch of these in the game and they did this to save space where instruments were very similar between more than one piece of music. There is a single byte in the scenes file that defines wich of the tracks should play and of course also what file to load for that area/cutscene to begin with. Luckily for this case there is also a standalone file with exactly the music needed. I was able to tell the game to use this music for the barber shop and so far this works, but with the afformentioned sound problems.

As for the Guilin arrival music, I have no idea where that is even stored. I'm talking about the erhu tune that plays when Ryo steps off the boat.
The Xbox version reuses the erhu music of Shenhua's memories instead. This isn't from a split track, even though they are very similar and I haven't found this piece of music in the Shenmue II DSF music collection. Didn't find the correspoding scene file for this cutscene either.

Obviously there is way more research required for this, hence why I put it in the title. Unfortunately I didn't quite manage to get a hold of a music file from Shenmue I & II as the process of extrating these kinda went over my head with the tools there are.
I can of course provide more information on where the music tracks in question are stored, their file names and how the whole thing about telling the game what track to play works.

Hope we can improve the music in the rerelease of Shenmue II eventually!
 
Good modding suggestion. The Saga Continues music alone would make me far happier if this were to happen. The rest are a pure bonus.
 
Would it be possible to make a mod to patch the Shenmue 2 themes from the Shenmue Online OST into the game?
Yes, this has been done with other games. It involves finding the appropriate function calls (things like LoadTrack, Play, Pause, Stop, etc.) and basically substituting an entirely different audio playback engine over the original, sometimes selectively if you only want to replace certain tracks. For example, there's a mod for the 2004 PC version of Sonic Adventure DX which used .WMA audio and the mod replaces the audio system with a port of vgmstream, allowing the original Dreamcast/Gamecube ADX files to be used along with other formats supported by vgmstream.

In a case like this, reverse engineering the music playback logic is probably more time consuming than actually writing a replacement for it. There are other ways to "cheat" and simplify the process (instead of a mod, mute in-game music, watch game memory like Cheat Engine would in order to see what track is supposed to be playing and play it yourself with external code) but such an approach would be less reliable than a proper mod since you'd be missing out on any special playback events or if things aren't done consistently. It'd be more of a proof of concept.
 
From what I found, Dreamcast Shenmue I&II music files uses PCM and Yamaha ADPCM sound formats. In Shenmue HD all yamaha samples were converted to normal PCM. And Shenmue HD doesn't seem to recognize Yahama samples at all. This is why while normal PCM samples from dreamcast plays just fine, samples in yamaha formats will sound like garbage. So these type of samples will require a conversion before importing to Shenmue HD. The problem is that after conversion samples will most likely increase in size and will require a change of offsets in "data block".

Fortunately, I think i might have found some data related to it, for example, this is Abe store music (BGM122.snd)
H6fgJIs.jpg

If I understand correctly the highlighted block points to the start offset of each sample, but in reverse i.e 50 27->2750 A0 7F->7FA0 and etc.. theres also other data related to samples that i'm not sure about yet..

Edit: I think I might be wrong about these being the beginnings of offsets, but i'm sure this data is related to samples.
Edit2: Now I think I am right after all :) its just I forgot to add an additional byte before, so the last sample offset is not CA32 but 01CA32 and before that is 01C42C and etc.
PS: this is screenshot of original dreamcast file.

So basically in theory the idea is, to convert samples, fix offsets and replace file in Shenmue HD with a new one.

But honestly, I think streaming audio would have been the better and easier way, i don't know why they didn't go that route with Shenmue HD.
 
Last edited:
Yeah I'm also puzzled why they didn't just record the music from the Dreamcast and then put it in as some modern compression looped streaming audio file. Lost of initial work but better than fiddling with each and every file to make the samples sound right. Already said this early after the release. Of course that takes quite a lot more space.

Anyway I'm glad to see that some more research is already being carried out!
 
If I understand correctly the highlighted block points to the start offset of each sample, but in reverse i.e 50 27->2750 A0 7F->7FA0 and etc.. theres also other data related to samples that i'm not sure about yet..
That's called Little Endian. x86 processors (and the Dreamcast's SH4) store numbers larger than 8 bits in that order, so they're stored in files the same way and the entire number can be loaded at once. You're looking at 16-bit Little Endian. For some reason it's just not very common for processors to store numbers in reading order or "Big Endian" where the big end comes first. PPC based processors like in the Gamecube / Wii were Big Endian, but that's the only example I can think of like that. (ARM used in mobile devices is an exception, which can go either way but Little is more common.)

If the difference really is just the samples, it may actually be easier to write a converter than patching the audio playback engine. I'll see if I can verify what you've posted regarding the formats, I don't remember seeing any raw PCM data on Dreamcast ~15 years ago just ADPCM.

Edit: More news to come after I've confirmed what I have before posting it. I think I understand enough of the format now to write a sample extractor. They're packing sample location, format and encoding into the same 32-bit value. The lower 23 bits are the location while bits 24, 25 and 26 are format flags. There's a pointer to the sample table in the header so you always know where it is.

Edit 2: Have a proof of concept tool written that extracts all instrument samples from a DTPK and decompresses the ADPCM ones. Not quite right just yet, but I'm on the right track. Will post that when it's working correctly, but for now I need to sleep. Here are my notes thus far:
Code:
AM2 DTPK SND format

All numeric values are Little Endian
0x00 - 4 bytes - Header: DTPK
0x08 - 4 bytes - 32 bit Size of file
0x3C - 4 bytes - 32 bit Sample Table Location

Sample Table:
0x00 - 4 bytes - 32 bit Index of last sample (Add 1 for number of samples)
0x04 - Start of Sample entries (0x10 bytes each)

Sample Entry:
0x00 - 4 bytes - 32 bit Sample Location & Type
    +- & 0x007FFFFF - Sample offset
    +- & 0x00800000 - Unknown flag.
    +- & 0x01000000 - Format flag - 0 PCM, 1 ADPCM
    +- & 0x02000000 - Unknown flag. Definitely NOT Mono/Stereo
0x04 - 2 bytes - 16 bit Sample Loop point start
0x06 - 2 bytes - 16 bit Sample Loop point end
0x08 - 4 bytes - Always 0 (?)
0x0C - 4 bytes - 32 bit length of sample data
 
Last edited:
As for the Guilin arrival music, I have no idea where that is even stored. I'm talking about the erhu tune that plays when Ryo steps off the boat
funatukiba2
It's recorded audio, so it's not DSF but some of the .genh files in the DSF rip. The ending scene is the same deal, "bigrelief.genh" in the DSF rip.

Edit: This was actually supposed to be a post where I ask for some assistance identifying the sample compression format - it's not using standard Dreamcast ACIA ADPCM. But I'm going to post a tool that extracts samples and let people play around with that.

Edit 2: Work in progress code is on GitHub, along with Windows and Mac builds for anyone who wants to play around.

This version will load a .SND and list all of the samples in the file, along with their location, size, whether they're compressed or not, and the values of the two unknown flags. It also gives the values of the unknown low and high values which I'm still calling Loop Start & Loop End but that might be wrong!

If you use the tool to extract samples, they're all extracted as .RAW files with no Headers. If you use something like Audacity, you'll want to "Import RAW" and pick 32 bit signed PCM. Sample rate varies between samples, I enter 22050 for most files. If you choose NOT to decompress ADPCM (the checkbox unchecked) the .raw file contains the compressed audio. If you choose to decompress, it uses the AICA ADPCM decoding logic borrowed from bero's Dreamcast ADPCM2WAV tool. This appears to be the wrong decompression to use for these samples, so they will be audible but there will be clipping & distortion.

TODO:
  1. Figure out unknown flags & values
  2. Figure out how to decompress the ADPCM properly. Done, see below.
Once 1 & 2 are done, then...
3. Add the ability to repack .SND files with new samples. I think this part will actually be pretty easy since sample data is at the end of the file and we know enough about the sample table to be able to repack a file making it bigger without breaking it. (Theoretically)

If anyone else is interested, please let me know. I'm more interested in figuring out #2 right now, so if someone wants to load up a bunch of files and look at them to try and figure out what the unknown flags are that might be helpful.

Edit 3: Everything posted thus far is based on the Dreamcast version of these file formats. Didn't realize they created a separate xboxDTPK format for 2x. The compressed samples there are still 8-bit ADPCM but it differs from the Dreamcast versions. I'll look into that afterward since it just appears to be an updated version of the same format with some additional stuff and the sample table pointer in a different place.
 
Last edited:
This is the mod I've most been wanting so good luck guys.
 
I think we're already sorta looking into this, regardless, I have the majority of stuff unpacked. @Dewey can you elaborate?

Yes, please elaborate because you just linked to a 7z file that when decompressed contains two more 7z files inside, and inside of those 7z are a bunch of .DSF and .miniDsf files that don't play in a DSF player because they're invalid somehow.


TODO:
  1. Figure out unknown flags & values
  2. Figure out how to decompress the ADPCM properly.
#2 has been addressed. It is indeed stock Dreamcast AICA chip ADPCM compression. The problem is that Bero's implementation from wav2adpcm, the command line converter that has been around since 2001 and the same code was integrated into FFMPEG... is incorrect.

There's a 2015 fork of the AudioOverload SDK on GitHub, a newer version of the same library that most DSF players are based on, and it contains some fixes to AICA and additions like Midi dumping. I implemented its version of AICA ADPCM decoding into my tool and it's now extracting compressed samples correctly. At this point I have enough information to be able to repack Dreamcast DSF's with uncompressed samples. I guess I could add XBOX support as well.

New WIP build of DTPKUtil posted, can extract all samples from a Dreamcast .snd package and decompress the compressed one. Will add the ability to repack a file with decompressed samples in the next release, however I'll hold on until we know more about the post above this. I should resume work on this later in the week.
 
Last edited:
So I haven't gotten around to actually trying this myself yet, but I finally looked at both the XBOX and PC version files as I had primarily focused on unpacking Dreamcast prior to that.

I had assumed the Xbox file format would be similar to DC, just with the additional header and using Microsoft ADPCM instead of AICA, but it's far more different than that. The file table still appears to be the last pointer in the header, (although it's in a different place) but the only thing in common with the Dreamcast version is that the first 32-bit value is the number of samples. Each entry still seems to be 16 bytes each as the table ends in the same place it would on DC based on size, but there's no consistency after that point from what I see. There are numbers that seem like they could be sample pointers, but they don't actually point to the start of samples and they're not consistently spaced. There are also not consistently placed 00's either to determine alignment. None of the aligned values are sequential, and comparing songs to their equivalent Dreamcast counterparts the samples aren't usually in the same order either. Sometimes samples that were uncompressed on DC are compressed on XBOX and probably vice versa. I found that to be rather strange and unexpected.
I did manage to get music from the Dreamcast version into I&II cutscenes and while the melodies were played correctly there were some harsh, loud and really irritating noises in about every track I tried. I also tried pulling some files from the Xbox version just for testing. As they should be identical to what I&II uses, they still sounded exactly the same way wrong as the DC files.
So after looking at the PC version too, the first oddity that jumps out is that they have a mix of both Dreamcast and Xbox format music files inside the .tad archive. But out of the random ones I spot checked all seemed to be Xbox format, I don't see any Dreamcast ones being used. I don't remember anyone pointing out this discrepancy before - has this been noticed already?

Does the PC port of Shenmue 2 accept Dreamcast format files then out of the box, or did you do some manipulation up front to make it happy?

Wondering if I'm missing any previous knowledge before I continue looking into this. In the event I can't figure out the Xbox format by observation, I might need to actually start looking at the game itself to figure out how it works.
 
I didn't make any adjustments to the game beyond just putting the DC and Xbox files in there.

Really sucks that it's so hard to get under the hood of all this. Really too many unnecessary changes in the rerelease.
 
Interesting.. Indeed It seems like Shenmue II does contain already converted dreamcast files and it does looks like game only uses files form Xbox. While PC port plays dreamcast files out of the box i'm not 100% sure that they are being handled correctly,at least I don't know if there any difference in quality between dreamcast and xbox files. also idk if there any easy way to identify which file is which with proper file name in archive.

If anyone interested, dreamcast *.snd files can be extracted, for example, using Shenmue HD modtools https://www.shenmuedojo.com/forum/index.php?threads/shenmue-hd-modtools-v1-2-now-with-filenames.366/ and found in "_UNKNOWN" folder.
 
Last edited:
I pushed some changes into the DTPKUtil repository linked earlier in this thread. The changes add a new WIP feature to save an existing .SND file with all samples decompressed. No new compiled release yet, since I need to do more testing to confirm that everything is correct. I'll probably end up testing against the Dreamcast version to ensure things are right before messing with PC more.

When you decompress the samples via the current WIP version of the tool, the PC version no longer has static garbage for some instruments. But also a bunch of instruments are maybe silent(?) instead. I know they're decompressed correctly because you can open the .SND in RAW mode in an audio editor and everything's good now. I am regenerating the sample table with new offsets and sizes and adjusting the loop values on the samples.

If someone knows what you're doing, you're welcome to grab the code and try out some decompressed DC songs. They're not going to work correctly as I said, but it's better than what unmodified DC tracks are doing. I suppose at this point I could also compare some tracks from the first game, maybe that would help me figure out what other changes they made.

Edit 2019-May 9th: I did some additional testing today, this time against the Dreamcast version. The biggest obstacle there is the DC only has 2MB of audio memory, so most songs unpack to be larger than would fit. But I found an easy one to test with. The "Roll it on top" song (0015__024) is one of the smallest songs in the game, at 81k compressed and 477k decompressed. The intro music (0002_006) is 783k compressed, so a decompressed version of "Roll it on top" makes for a great replacement track to test.
In my test, the DC version accepts and plays the song, but some of the instruments sound wrong / out of tune. This is perfect because it means I'm rebuilding a valid file but there's just a mistake somewhere. The PC version sounds similar to Dreamcast with the same file (although slightly better IMO). Once I figure out the mistake and get DC correct I'm hoping PC will be the same. Then I'll post a new build of DTPKUtil so you can port whatever songs you want from the DC version.
 
Last edited:
Bumping this with a new build of DTPKUtil:

It can now successfully produce a decompressed .SND file that plays back correctly on the original Dreamcast version. My mistake in the previous post was that I assumed AICA used 32-bit uncompressed samples but they're actually all 16-bit. Also I finally looked at the PC version files and saw that they don't adjust loop points when decompressing songs, so I followed suit and stopped doing that. PC version oddity: All samples are decompressed, but they did not clear the compression flag. Don't try to decompress these with DTPKUtil, as it will just produce garbage.

Unfortunately, time for the bad news. The although the 'correctly' decompressed files sound great on Dreamcast, they're sometimes out of tune and have other issues on PC just like the game did when it came out. They're not distorted so at least it's a start. I still need to check to see if they made any other changes for PC version files besides decompressing the samples - maybe they changed the samples or something. The actual sample metadata (the compression flag & unknown flags) is the same in both versions, so I at least know that part is done.

For accuracy, maybe I should add two different decompress modes - One that matches the current behavior and produces a file that works on Dreamcast and the other that retains the original flags for PC in addition to whatever other changes we figure out need to be made later. Anyone have feature requests for this app? Can't promise much beyond converting DC files to work with PC, but I'm probably going to ignore XBOX since we don't actually need it and 'finish' the app in the next week or two.
 
That's amazing Phil! Been keeping an eye on this, and it is actually possible? Would it be difficult to implement once complete, or how exactly does it work.
 
Which user is Phil?

The thing I posted can be used now. Just grab some files from the DC version, decompress them and drop them in the appropriate mod folder so forklift uses them. They have problems, but no more static / garbage that you'd have using the DC files as-is
 
Back
Top