Jump to content

FE7 music hacking ramblings and a cry for help


Agro
 Share

Recommended Posts

I've got two things I need to address:

First, I've observed an odd phenomenon whereby the number of tracks FE7 is allowing has mysteriously decreased from 8 to 7. Somewhere in the course of my hacking, my FE7 ROM decided that it didn't like 8 tracks and has cut down on it, leaving be absolutely bewildered as to why this is happening. I'm planning on backtracking through my older ROMs to see exactly where/when it happened, but in the meantime, would anyone be able to propose a reason as to why this might happen? My first thought was that because some of my data is now located in a "later" part of the ROM (I'm sitting at around $1390000 for maps and events) the game might need to devote more CPU to other things, and it cuts out song tracks to compensate?

Certainly when I play songs in the title screen/opening menu they all play fine, but in the actual chapters/maps and the sound room it is definitely no longer 8 tracks that it allows. Is it possible that this is the case? I have applied the sound improvement patch but also undone those changes and it doesn't seem to have helped at all. I've tried repointing the RAM, too, and that didn't work. Honestly, this has had such a big impact on me that if backtracking doesn't work, I'm ready to start on a fresh ROM.

Second, I've been scouring the FE7 ROM looking for a way to increase the number of tracks the game allows by default, but I simply can't seem to find anything at all. What I've been going off is a little bit from the sappy doc:

*******************************************
** Appendix A) Sound driver operation mode **
 *******************************************
 
This chapter is about how direct sound channels are created by the engine. (none of this affects the PSG channels)
 
First it is neccesarly to know a minimum how the direct sound channels work. The GBA just reads some numbers from a buffer sitting in RAM, and sends them directly to the speaker. This is why, when you remove a cartidge while a GBA game is runnin, or when a game crashes, horrible sound is heard. All contents of RAM is send to the speaker unconditionally, and of course it sounds awful. How many times I had to hear this while reversing the sound engine... anyways.
 
Basically the sound engine has what we call a "software sound mixer" or plain "sound driver", which simulates sound channels, and will produce a series of numbers in the RAM buffer, corresponding to the output waveform. If the mixer is in stereo, the buffer is truncated in two halves, one buffer for left and the other for right.
 
The mixer has been made so it can work with different parameters. I found how to change a few of them :
 
1) Find the address of the track-group RAM pointers (right after the GB channel 3 waveforms) using the technique I mentioned above
2) Search in the ROM for that address. There will be many occurrences of it, but you should look the 8-bytes that there is before it. The previous 4 bytes should be a low number followed by 3 times 0x00. Then the 4 bytes even before that might be the sound driver operation mode, coming in this format (this is from nocash's site) :
 
       Bit    Expl.
       0-7    Not used (should be 0x00)
       8-11   Direct Sound Playback Frequency (1-12 = 5734,7884,10512,13379, 15768,18157,21024,26758,31536,36314,40137,42048, def 4=13379 Hz)
       12-15  Final number of D/A converter bits (8-11 = 9-6bits, def. 9=8bits)
       16-19   Direct Sound Simultaneously-produced (1-12 channels, default 8)
       20-23  Direct Sound Master volume (1-15, default 15)
       24-30    Direct Sound Reverb value (0-127, default=0) (ignored if Bit7=0)
       31      Direct Sound Reverb set (0=ignore, 1=apply reverb value)
 
For example : 0x00, 0xF8, 0x94, 0x00 means the game has reverb disabled, maximum global volume, 8 channels, 8 bits DAC and a sampling rate of 13379 Hz (this is the default values). If any value is '0' (which normally shouldn't be the case) the specified default value seems used instead.
 
Here you are all the field explained :
1) Direct Sound Playback Frequency
   This is just another term that means "mixing sampling rate" really. Should be obvious. Higher values allows for better quality sound, at the expense of more CPU time.
   Appendix C has a chart to estimate the CPU time used.
 
2) Final number of D/A converter bits
   This directly affects an obscure I/O register in the GBA called "SGBIAS". I think it comes to play in the D->A conversion stage.
   The value of this register makes no differences on emus, but on hardware it makes a huge difference !
   I really recommend letting this number to 8 = 8 bit DAC, because other values will sound awful (you'd expect 9 bits to sound better than 8 but it doesn't).
 
3) Direct sound Simultaneously-produced
   This is simply the # of emulated Direct Sound channels.
 
4) Direct Sound Master volume
   Simple, it affects the volume of all channels. This is more important than what it sounds however :
   If the volume of the instruments is too lood, the values in the buffer will overflow and warp arround, making horrible clicking sound (Nintendo didn't code something to make the sound saturate instead).
 
5) Direct Sound Reverb value
   Reverb applies unconditionaly to all direct sound channels. It's done through a very simple formula such as this :
 
   Newsample = Feedback*OldSample
 
   Because of this (and because they don't use an actual reverb buffer), the length of the sound buffer(s) directly alter the delay between echo repeats, and cannot be easily changed. Of course the sample rate will change the reverb length too.
 
   If the dalay is too short (short enough to be in the audible range), it sounds really bad (like if the music was playing in a garage). The only way to make the delay longer is to reduce the sampling rate or to increase the size of the buffer.
 
   Basically, this is why my Final Fantasy VI Advance sound restoration hack was changed from stero to mono. Since I only had a single buffer, I could make it twice as long, and having good sounding reverb while having a sampling rate which is high enough. For my Final Fantasy IV hack however I made it different - I kept it stereo, but lowered the sample rate.
 
 
However, there is many issues when changing the operation mode. When actually running a game, it often happens that the game manages to "force" it's own parameters (and ignore your changes), but when dumping the music with saptapper, it seems to always take effect.
 
If you increase the # of channels or the sampling rate, the creation of the direct sound channels will take more CPU time, and the game can lag, or even possibly crash. Even if no lagging happens, using more CPU can draw more power from the GBA forcing the user to change/recharge batteries more often.
I suspect some games intentionally change the sound driver op[sic; mysteriously the paragraph ends here]

there was some text here, but the forum made it disappear, i'll rewrite it tomorrow when it's not 3am

Edited by Agro
Link to comment
Share on other sites

Yeah, I've had a look at it, and I don't think that it can play any more than 8 tracks anyway (I could be wrong). It can definitely READ more than 8 tracks but if anything exceeds 8 it doesn't play, so in effect it's not really anything that I can't do, since I already figured out how to do that.

Upon further investigation it seems as though it can play more than 8 tracks, but I have no idea how it does this. I'll definitely have to look into it more...

Edited by Agro
Link to comment
Share on other sites

Use patch diff on FE7if and Jap game and find areas relevant to music loading, then compare the code, find the similar place in the English version and implement it

1000x easier said than done

as for why it's happening idk but I feel like that happened in TLP too >_<;

Link to comment
Share on other sites

Yeah, I've tried that too ._.

The furthest I can seem to get is going to $BE578 (the sound driver operation mode) in the US FE7 ROM and changing stuff there--by default it's 00 D7 94 00, and changing 94 to 99 improves sound quality a lot (though it screws up some other sounds if you haven't got a proper fix in place) but changing D7 to anything else doesn't seem to do anything. The 7 should correspond to the number of DS tracks available but it doesn't because A. FE7 can handle 8 and B. changing it does nothing. In the JP FE7if ROM (can't remember the offset) it's something like 00 DA 94 00.

I'm just so confused and I have nowhere else to look ._.

Link to comment
Share on other sites

ALRIGHT

I HAVE DISCOVERED MORE ODD THINGS

Upon rewinding through my backups, I found the most recent ROM that doesn't cut off the number of tracks. But here is the weird thing: if I place the ROM in the same folder as the glitchy ROM, it cuts off the 8th track.

If I place the ROM on the desktop, it doesn't.

wtf is this

Whatever it was I just saw seems to have disappeared, because the working ROM is now in the folder of the glitchy ROM and it works fine. I don't have much to go back over, so I'm actually quite alright, but I'm just afraid that this will happen again and I will (again) have no explanation as to why. Over the next few days/week I'm going to be paying very close attention to what I do, I guess. I'll report back to you guys once I know more.

Edited by Agro
Link to comment
Share on other sites

ALRIGHT

I HAVE DISCOVERED MORE ODD THINGS

Upon rewinding through my backups, I found the most recent ROM that doesn't cut off the number of tracks. But here is the weird thing: if I place the ROM in the same folder as the glitchy ROM, it cuts off the 8th track.

If I place the ROM on the desktop, it doesn't.

wtf is this

Whatever it was I just saw seems to have disappeared, because the working ROM is now in the folder of the glitchy ROM and it works fine. I don't have much to go back over, so I'm actually quite alright, but I'm just afraid that this will happen again and I will (again) have no explanation as to why. Over the next few days/week I'm going to be paying very close attention to what I do, I guess. I'll report back to you guys once I know more.

Have you tried different emulators to see if the problem persists? Might as well rule out the possibility of it being a bad emulator or you exploiting bad emulation. Give no$GBA a kick if you haven't already.

Link to comment
Share on other sites

  • 4 weeks later...

Okay! I think I've found the source of the problem.

It seems that certain music table entries have a "hard limit" of 7 tracks imposed on them. From what I've been looking at, I'd guess that this is any entry that lies between 0x0000 and 0x007F. I'd wager that this is related to the very same problem wherein music table entries past 0x007F won't appear in the sound room unless you hack the sound room to unlock completely. There are some notable exceptions to this, however--I think 0x005A, among others such as battle music, have a hard limit of 8 tracks. The reason it seemed as though I was "losing" tracks was that when I tested my songs, I would put them in 0x005A's place, and then when I inserted them into the ROM I'd put them into, say, 0x0002, which is why I didn't notice the decrease in tracks until later.

Upon testing, it seems that you can get the full 8 tracks if you put music in entries past 0x007F (exclusive). Anything before that will oddly result in the game only allowing 7 tracks. Moral of the story is probably this--place BGM in entries past 0x007F.

Consequently, this poses a new problem: for the most part the game will only allow 1-byte entries for songs (apart from in events) and the majority of entries between 0x80 and 0xFF are taken up by sound effects, so you've only a very limited number of new songs you can put in. Obviously things like mamkute sound effects and the like can be cut if you're not using them, but I think at most there's only enough room for about 30 more songs. If anyone knows a way to easily find the commands for sound effects and swap them into another table entry, uh, please step forward!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...