Author Topic: Inject custom spc music into CT  (Read 15357 times)

utunnels

  • Guru of Reason Emeritus
  • Zurvan Surfer (+2500)
  • *
  • Posts: 2797
    • View Profile
Inject custom spc music into CT
« on: January 20, 2009, 11:12:49 am »
How music stored in ROM

Basically, the music are scores and samples.

Scores part includes several parts of data: sequence data, instrument table, drum set, volume information.
Sequence data is similar to midis, it contains commands(or we say events) to play the music.
Instrument table defines instruments that are used in the sequence, it's a list of sample indexes.
Drum set defines a set of notes and instruments that are used in drum mode, some games just don't use it.
Volume information control the piece's volume of course.

Samples part includes several parts of data: sample data, ADSR information, loop point information, pitch correction.
Sample data is a compressed sound format(BRR, Bit Rate Reduction).
Introduction of ADSR can be found here: http://en.wikipedia.org/wiki/ADSR, I'm not sure how it works(which takes how many bits, such).
Loop point defines from which point does the sample begin to loop, if it is set to loop.
I'm not sure how pitch correction works, most times you can leave it to zero.

If you use samples ripped from another game, just copy everything, it should be fine, unlike scores.

Folders and files

out\spc contains score data from CT, there are totally 83(0x53) pieces, from 00 to 53.
Files with no extensions are sequence data.
.instrument files are instrument tables.
.volume files are volume informations.
.drum files are drum sets.

out\sample contains sample data from CT, there are totally 62(0x3E) samples, from 01 to 3E.
Files with no extensions are sample data.
.loop files are loop points.
.ADSR files are ADSR informations.
.pitch files are pitch corrections.

out_bak is the back up folder for out.

mml folder contains some sample MML file.

custom sample folder contains a sample used by the example.

About those exe files and source files, check readme.txt for more informations.

Import data

Sometimes, you can just copy spc data from other games and insert into CT. But keep in mind, the games might use different spc cores from CT, which means soem commands might be different.
Another way is convert other music into spc format, for example, midis. But the problem is midi standard is complex, and much different to spc format. Fortunately, there are tools to convert a midi file into MML(Music Macro Language), which is readable by human, and is more close to spc format. What you need is to add some extra commands that are necessary to spc. So I wrote a tool to convert a MML file into spc format, mml2spc.

In theory, you can convert a wave format file into BRR sample, and I have written a tool to do that(wav2brr), but it doesn't contain other informations such as ADSR. Since all snes games use same sample format, so it is much safer to use a sample from another game.

MIDI to SPC

Let's start with an example.

1. Find a midi file. The midi must have at most 8 channels, because a spc score can only support 8 channels.

2. Use a tool to convert it into MML format. I recommend tinymm, you can find it via google.
The raw MML file is simple:
cdefgab are notes, + means sharp, - means flat. Values behind them are length.
o changes octaves, sometimes it is omitted, so you should add it by hand. The default value seems to be o6.
r means rest.
^ will extend the length of previous note.
< means up one octave.
> means down one octave.
For more information, check the wiki: http://en.wikipedia.org/wiki/Music_Macro_Language

3. Add spc commands for the MML file.
There are too many commands and I haven't figure them all out, but only a few of them will keep you new music in shape.
  • #WAVE <instrument id>, <sample id> - This command define an instrument for the spc. Instrument id is a number from 0x20 to 0x2F, it will be used later. Sample id specifies which sample is used by this instrument. You might need to test it for many times...
  • #DRUM <note>, <instrument id>, <pitch>, <volume> - This command define a drum set. Unlike #WAVE, note are from c to b, so there are 12 of them: c, c+, d, d+, e, f, f+, g, g+, a, a+, b. The drum set will be used later if a channel is set to drum mode. I never use this command though.
  • t - tempo, followed by a number from 0 to 255, a greater value will make the channel goes faster.
  • v - volume, followed by a value from 0 to 127, a greater value will make the channel louder.
  • %e1 - echo on. Without this command the sample will stop playing when a new note is reached, bad for some instruments.
  • %e0 - echo off. 0 is optional, so you can just use %e.
  • %v - echo volume. If you use %e1, you should consider this command. The loudness of the rest part of the last sample if a new note is reached.
  • @ - instrument id, from 0x20 to 0x2F are those defined by #WAVE, from 0 to 0x1F are system defined wave shapes, but I haven't try it out.
  • %d1 - drum mode. I haven't tried it out.
  • %d0 - turn off drum mode.
  • p - panning. Check wiki for more information: http://en.wikipedia.org/wiki/Panning_(audio). Usually, p64 is fine.
  • $ - mark loop point. It means when the end of channel is reached, the music will jump back to here.
  • [n<notes>|<notes>] - loop. It defines a loop, [ and ] are start and end point of the loop, n is loop count, | is the break point for the last loop. You can define a loop inside another, but it will make it too complex to read.
  • /:n<notes>/<notes>:/ -  same as above.
  • ; - end of channel. You will need it at the end of a channel.
  • {anything you want for a comment, of course, except "}" }
There's an example in mml folder of this package.

4. Convert MML to SPC data using command below:
mml2spc -m "your mml file path" -f -i your_spc_index
This will replace the spc data inside out/spc with the same spc index. Although, you can use a number larger than 0x52, but you have to hack the rom to let it be used.

*Note:
If you want to make a looping piece(with $ command), you need to check the output message, and add some r commands at the end of those shorter channels.
A full note has a length of 64, for example, the longest channel has a length of n,  a shorter channel has a length of n-1282, you need to add 20 "r1"s at the end of the shorter channel(64x20=128) and a "r32"(64/32=2), all methods below work:

blahblah...
r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r32;

blahblah...
r1^1^1^1^1^1^1^1^1^1^1^1^1^1^1^1^1^1^1^1^32;

blanblah...
[20r1]r32;


5. Expand your CT ROM.
Yeah, you need an expanded ROM(NA release). You can do that using Temporal Flux, for example.

6. Inject the data using command below:
inject "your rom file path" position
The position must be greater than 0x410000, or it will override other data. Although, if you plan to add data behind it, do check the actual output size. This tool packs all data and put it at the position you specified, and change some values inside the ROM to let the game look for the new position.

Links

Sample list for CT
http://www.chronocompendium.com/Term/Importing_SPCs.html
http://slickproductions.org/forum/index.php?topic=612.0, most mml commands are same as those used by RS3 tool, you can check Vehek's topic here.


Later.

http://cc.ffsky.cn/TEMP/ctspctool.rar
« Last Edit: May 09, 2009, 05:36:38 am by utunnels »

utunnels

  • Guru of Reason Emeritus
  • Zurvan Surfer (+2500)
  • *
  • Posts: 2797
    • View Profile
Re: MML to SPC Convertor
« Reply #1 on: January 20, 2009, 11:46:55 am »
Yeah, found a bug of RS3 tool, so I have to change my code a bit.

Vehek

  • Errare Explorer (+1500)
  • *
  • Posts: 1757
    • View Profile
Re: MML to SPC Convertor
« Reply #2 on: January 20, 2009, 01:37:00 pm »
"Macro" is probably mostly used by Japanese manually-made MMLs.

"DRUM" is used to set up the drum-set/percussion set used by Drums Mode.

utunnels

  • Guru of Reason Emeritus
  • Zurvan Surfer (+2500)
  • *
  • Posts: 2797
    • View Profile
Re: Inject custom spc music into CT
« Reply #3 on: January 26, 2009, 09:19:00 am »
OK, I think I've complete the toolset.
If there're something missed I will add them later.

FaustWolf

  • Guru of Time Emeritus
  • Arbiter (+8000)
  • *
  • Posts: 8972
  • Fan Power Advocate
    • View Profile
Re: Inject custom spc music into CT
« Reply #4 on: January 26, 2009, 01:52:33 pm »
Suh-weeet. So, what would be the process for importing an SPC into Chrono Trigger if the SPC is from a different sound core? Would the process be something like this?

*Original SPC > MIDI
*MIDI > MML
*MML > CT-compatibel SPC. Now you have the sequence data you need.
*Rip the instrument samples from the original SPC and import them into Chrono Trigger's instrument table?

Vehek

  • Errare Explorer (+1500)
  • *
  • Posts: 1757
    • View Profile
Re: Inject custom spc music into CT
« Reply #5 on: January 26, 2009, 01:53:24 pm »
Sorry, but I forgot to make something clear in my SPC notes.
In RS3, SPC command 0xF4 is Channel Volume Multiplier, which was on command 0xFD in CT.

utunnels

  • Guru of Reason Emeritus
  • Zurvan Surfer (+2500)
  • *
  • Posts: 2797
    • View Profile
Re: Inject custom spc music into CT
« Reply #6 on: January 26, 2009, 11:04:15 pm »
Suh-weeet. So, what would be the process for importing an SPC into Chrono Trigger if the SPC is from a different sound core? Would the process be something like this?

*Original SPC > MIDI
*MIDI > MML
*MML > CT-compatibel SPC. Now you have the sequence data you need.
*Rip the instrument samples from the original SPC and import them into Chrono Trigger's instrument table?
Yeah, that's right.

Sorry, but I forgot to make something clear in my SPC notes.
In RS3, SPC command 0xF4 is Channel Volume Multiplier, which was on command 0xFD in CT.

 F7 F8の引数が2Byte(ツールでは1Byte目を無視)
 FD xx      エクスプレッション
 F4は無し?

Hmm, yeah, they are listed in RS3 tool document...is that command %x, right?
It can be fixed by change a 0xf4 to 0xfd in the code.

------
Done.
« Last Edit: January 26, 2009, 11:39:05 pm by utunnels »

utunnels

  • Guru of Reason Emeritus
  • Zurvan Surfer (+2500)
  • *
  • Posts: 2797
    • View Profile
Re: Inject custom spc music into CT
« Reply #7 on: January 27, 2009, 01:12:08 pm »
http://www.youtube.com/watch?v=OrpMmBIMSCk
Copy "Gale" from RD, also its samples.
I know it is a waste(8 new samples)...

FaustWolf

  • Guru of Time Emeritus
  • Arbiter (+8000)
  • *
  • Posts: 8972
  • Fan Power Advocate
    • View Profile
Re: Inject custom spc music into CT
« Reply #8 on: January 27, 2009, 01:14:10 pm »
Brilliant!! Custom soundtracks, here we come!
« Last Edit: January 27, 2009, 01:16:58 pm by FaustWolf »

utunnels

  • Guru of Reason Emeritus
  • Zurvan Surfer (+2500)
  • *
  • Posts: 2797
    • View Profile
Re: Inject custom spc music into CT
« Reply #9 on: January 27, 2009, 01:25:41 pm »
That just confirmed again RD music can be imported directly.
I believe there's already someone did that job(copy SPC from other games), so I may ask if there's already some lists of instruments of other SNES games?
Ripping samples is easy, but  figuring out the instruments may be hard.

I used to convert those samples into .wav files, but they are just too short, hard to discriminate by ear.

FaustWolf

  • Guru of Time Emeritus
  • Arbiter (+8000)
  • *
  • Posts: 8972
  • Fan Power Advocate
    • View Profile
Re: Inject custom spc music into CT
« Reply #10 on: January 27, 2009, 02:15:18 pm »
You know what? JCE3000GT had a list of instrument samples for Chrono Cross...I wonder if those can be imported in a format that works with the CT sound engine?

Also, from what Vehek told me earlier, instrument data should be in the .SPCs readily available for download at Zophar.net. Maybe we should pick a song from another SNES game and see how conversion works out?

utunnels

  • Guru of Reason Emeritus
  • Zurvan Surfer (+2500)
  • *
  • Posts: 2797
    • View Profile
Re: Inject custom spc music into CT
« Reply #11 on: January 27, 2009, 02:50:09 pm »
Yeah, but I think we should consider CT's native samples first unless we can't find a suitable one.
It will be a waste of space if a spc contains its own samples.

Wait, you said Cross? Maybe you were talking about another thing?

FaustWolf

  • Guru of Time Emeritus
  • Arbiter (+8000)
  • *
  • Posts: 8972
  • Fan Power Advocate
    • View Profile
Re: Inject custom spc music into CT
« Reply #12 on: January 27, 2009, 03:36:24 pm »
True, in many cases only a few instrument samples may need to be added.

You can find the Compendium's Chrono Cross sample archive here:
http://www.chronocompendium.com/Term/Modification.html#Chrono_Cross

utunnels

  • Guru of Reason Emeritus
  • Zurvan Surfer (+2500)
  • *
  • Posts: 2797
    • View Profile
Re: Inject custom spc music into CT
« Reply #13 on: January 27, 2009, 03:44:20 pm »
They are in different formats.
Yeah, although it is easy to convert a wav file into SNES sample's brr format. But That's is not enough.
And even if the samples are converted, I don't think it will sound as good as in psx version or maybe ever worse than snes games.
So I think the most realistic way is finding similar samples in SNES games...

justin3009

  • Fan Project Leader
  • God of War (+3000)
  • *
  • Posts: 3296
    • View Profile
Re: Inject custom spc music into CT
« Reply #14 on: January 27, 2009, 06:05:10 pm »
Chrono Trigger Prerelease
Front Mission: Gun Hazard (Chrono composer's)
Front Mission
Final Fantasy 6
Radical Dreamers
Romancing Saga 3
Treasure Conflix
« Last Edit: January 27, 2009, 07:11:00 pm by justin3009 »