Touhou Patch Center:BGM modding

For Team Shanghai Alice games
(Ripped straight from discord)

Supported formats, from highest to lowest priority
Ideally, you've acquired your modded BGM in a lossless format, and FLAC support allows you to provide these directly to your players. Currently the best compromise between compression and sound quality. Limited to 16-bit. Only use this if you have no other choice and your modded BGM is so obscure/ancient that it simply was never released in another format. Also the most difficult to loop correctly, and not repatchable in ≥TH07.
 * FLAC (.flac)
 * Ogg Vorbis (.ogg)
 * MP3 (.mp3)

These formats are compatible with all thcrap supported ZUN shooters (th06-th17).

[https://discord.thpatch.net/ More formats? Talk to me!] (Nmlgc)

Patch stacking

 * When stacking multiple BGM patches, the priority order above is evaluated per-patch, before moving to the next one. Meaning, an MP3 from a higher patch in the stack will always override a FLAC from a lower one.
 * Loop files must always be in the same patch and the same format as the intro file.

How to name your files
Check out the data filename column in Splashman's BGM list, as well as thcrap_log.txt (Ctrl-F for flac > ogg > mp3) to make sure you got the names right.

File layout
You can put the files into either the patch root or the game-specific subdirectory. Usually, you'd go with the patch root – プレイヤーズスコア is th10_17 in TH10–TH12, and th128_08 in ≥TH12.8, and by only putting those two files into the patch root directory, you'd cover all of these (and future) games. But you can still use the game-specific subdirectory if you want a separate Player's Score for specific games, even in addition to putting a generic file into the patch root.

Also, for consistency with later games, BGM mods for TH06 don't go into a separate bgm/ subdirectory, contrary to what the original files might suggest.

As for the patches themselves, I recommend this layout if you offer both lossless and lossy patches:
 * _base: Modded images and Music Room comments, all tracks that are only available as MP3. Dependency on base_tsa
 * : Lossless source tracks converted to Vorbis. Dependency on _base
 * _lossless: Lossless source tracks. Dependency on _base

Looping
Each original track can be represented by two audio files in your patch: An intro file using the same filename as the original, and an optional looping file with .loop before the extension. So, for a TH06 title screen mod in Ogg Vorbis format, these would be th06_01.ogg and th06_01.loop.ogg.

Looping is handled internally by simply rewinding the currently playing file after it finished playing. Any loop values from the game or loop point mods are ignored.

This means that you can omit the .loop file, put the entire track into the "intro file", and thcrap will just loop that.

If you have lossless source files, you'd obviously want to cut those into two before converting the two resulting files to Vorbis, in case you want to offer a lossy patch.

If, for some reason, you want no loop, and the track should just stop after it finished playing: That's equivalent to "looping a short amount of silence". Putting exactly 4 seconds of silence into the corresponding .loop file would be the most performant option.

How to loop MP3 files
For your first MP3, double-check whether the audio editor you want use for loop cutting actually supports the LAME extension for gapless MP3. (GoldWave v6.35 and Audacity 2.3.0 don't.) To do this, convert the MP3 to a FLAC or WAV using something that does (I used foobar2000 v1.4), and check whether your editor shows the same amount of silence at the beginning of both the FLAC/WAV and the MP3.

If it doesn't, always convert to a FLAC/WAV file to "apply" the removal of the MP3 pre-gap, and use that converted file to determine the loop start/end samples. (After the loop works, you'd just throw away that lossless file.) Then, use pcutmp3 on the command line to perform sample-accurate cutting.

Yes, you unfortunately need Java for this. No, mp3DirectCut will not work.

java -jar pcutmp3.jar --crop 1:0-123,1:123-456 "C:\path\to\the\original.mp3" with 123 being the loop start, and 456 being the loop end sample.

Caveats and ZUN bugs
You can purchase fixes for all of those! Please talk to Nmlgc if you're interested!


 * TH06 is the only game where BGM mods can have any sample rate, bit depth, and channel count.


 * TH06: Performance on track switches could be improved a bit.


 * TH09: Make sure that your modded title screen BGM has at least 0.3 seconds of silence in the beginning. For some reason, the game always wants to play the title screen theme for a tiny amount of time before switching to the actual conversation theme at the start of a stage. :zun:


 * TH11: Similar issue, but with the Stage 6 theme: The game starts playing a few milliseconds of it when entering the stage, then pauses playback, and only resumes it ~4.9 seconds later.


 * TH13: Performance when switching to the trance tracks and back could be improved a bit.

Touhou BGM changing for dummies
A simplified step-by-step tutorial

1.Open your thcrap folder and create a new folder. Name it as you wish.

2.Create a new folder within that new folder that you just created and name it if you feel like doing it.

3.Insert your audio file in the folder (the folder inside the folder) IMPORTANT You must use the correct naming scheme otherwise the game won't read it correctly. Use for naming.

4.Make sure the audio file is in .flac format, with 44100Hz sample rate and 16-bit sound depth. Audacity is a recommended program for all those tasks.

5.Go into the following location (still in thcrap folder, NOT THCRAP INSIDE GAME FOLDER) thcrap -> config and open the js file containing game data you wish to edit. The following file starts with '{   "console": false, "dat_dump": false, "patches": [ { IMPORTANT' Keep in mind how you named your game configuration (ex. if you want to replace an audio track in IN, make you are editing IN game configuration)

6.Add this line into the .js file :

}, { "archive": "*insert name of the folder/insert the name of the folder"

and make sure after everything is done that it's ended with:

} ] }

7. Run your game and it should be working.

''Note: In future games, the sampling rate might not be required to be 44100Hz and 16bit sound depth but I cannot confirm this statement. ''

'Still not working? Mail me (ratchet12663@gmail.com) or find me on reddit (u/d12trg)'

For Tasofighters (TH13.5, TH14.5, TH15.5)
From VasteelXolotl's AoCF Wiki Page

The above link includes example music replacement packs.

Music replacements are fully client-side and do not affect netplay in any way. You also don't actually touch the game's files, as this is a "softmod" through thcrap.

1) Setup
Make a new folder under thcrap's "repos" directory. Name it whatever you want, I just went with "bgm155" for simplicity.

In that folder, make another called "th155", then under that one make "data", then "bgm". Go back to the main thcrap folder, then go into the "config" folder. Somewhere in there should be a .js file named after your default configuration. If you haven't messed with anything when installing the english patch, it should be "en.js". Copy and paste it. Rename the copy to "bgm155.js". Open it in a text editor of your choice. The opened file should look similar to this

https://cdn.discordapp.com/attachments/475336678379356172/658734848982253579/1.PNG

Add your patch to this. Throw it in after all the other ones to prevent any issues. Make the file look more or less like this and save it.

https://cdn.discordapp.com/attachments/475336678379356172/658734850970484736/2.PNG Now find your th155 thcrap shortcut (in the main thcrap folder) and once again copy-paste it. Rename it to something convenient. Right click it and click Properties, then go into the Shortcut tab in the window that shows up. At the end of the Target field, change "en.js" to "bgm155.js". Press OK. You've got everything set up. Neat.

2) Actually replacing music
Each theme has 3 files - two .ogg files (one of which is simply just the music to play in-game, and the other is a 20-second preview for the stage select) and an .sfl file containing loop metadata for the in-game theme.

Rename them to fit AoCF's file names. For convenience, here they are.

Remember all those folders you made? Go down to the "bgm" folder and place the files you want there. Boom, you did it.

3) Changing in-game music titles
So you changed Marisa's theme to the objectively superior one, switched Nitori's theme to Aya's or something else entirely. There's one small problem, though - the music title doesn't match. You wanna fix that? Sure you do, or else it'll keep bugging you for all eternity. In the "bgm" folder, make a new file called "bgm.csv.jdiff". Open it in a text editor of your choice. Remember the numbers in brackets in the other paste? They'll come in handy now. Open a curly bracket in the first line. In the second line, type in the number of the theme you want to change in quotes, then a colon and another curly bracket, e.g "2": { In the next line, type in "7": "[track title]" If you want to change the name of the arranger/composer as well, you can do it as such in the next line: "8": "[composer name]" Afterwards, close the curly bracket in the next line with }. Repeat the above as many times as necessary, then add another }. You're done. Here's my jdiff file, if you need a reference

https://cdn.discordapp.com/attachments/475336678379356172/475367273134293022/jdiff.PNG

4) Custom loop points
Use Egor's .sfl loop tool.