• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Forum moderator applications are now open! Click here for details.
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Tool: midfix4agb - A MIDI preperation tool for GBA insertion

ipatix

Sound Expert
145
Posts
15
Years
midfix4agb - What the ???

Introduction:
You read the title "midfix4agb" and think "OMFG what is this crazy guy talking about?". So let me explain you what this tool and this thread should be all about:
I orginally got the intention to make this tool when I was working on my DPPt music patch for Pokemon Emerald. Back in 2012 I had several issues with the results how my songs turned out after insertion. I analyzed the issues and listed them:
The first problem I was having that the tracks from the DPPt MIDIs had some weird volume glitches where the overall volume balance off all the track wasn't correctly. Some track always were too dominant in certain parts of the music while it was too quiet in other parts. The reason for this is that both MIDI and AGB have a volume range of 0-127. So on MIDI volume 127 means max volume, 64 half and 0 silence. On the AGB this is a little bit different. Due to sound processing speed reasons this is simplified to 127 max amplitude, 64 half amplitude and 0 silence. The problem is that half amplitude doesn't mean half the volume (I'll explain this further below) The second one was that modulation (in my patch only the pitch modulation) always was a little too intense and the modulation speed was too slow. The 3rd thing I always had to do manually was to manusally insert the pitch bend range manually in the s-file (because mid2agb programmers at Nintendo were lazy) to make pitch bending work correctly. The 4th one: Looping with the [ ] brackets is awesome but again it doesn't do everything for you automatically (lazy mid2agb programmers!). Let's explain the problem like this:
Let's say song X has a loop start and end. It also has a MIDI program change in the middle of that loop. Before the loop song X will use instrument #25 (guitar). X will enter the loop and still use this instrument like it should. In the middle of the loop the instrument changes to #48 (strings). But when X reaches the end of the loop it will jump back to the loop start but will still use instrument #48 (it stores this in variables). As you still might remeber X should use instrument #25 at the beginning of the loop but it doesn't.
This scheme can happen with all different kind of events: Volume, Panning, Pitch Bend, Modultion, Tempo, etc. This resulted in some songs using wrong instrument and not sounding like they should.

Later in 2013 GoGoJJTech started doing the HGSS music patch and reported me some problems too. The first one was that he needed some way of permanently changing the modulation type to panpot instead of the default pitch modulation. Another problem was (I actually expected this previously) occuring with the Expression controller events. The Nintendo Sound SDK doesn't have a second event to control volume (like General MIDI and DS SSEQ have) so mid2agb just ignores all the expression events and only converts volume events.

So I first wrote a really unstable and "luckyly working" first version of this tool which I never released. I did a recode and I want to present you the results here.
My tool was met to fix all those problems mentioned above.

Features:
To summarize, midfix4agb ...

  • inserts additional events to the MIDI that mid2agb will recognize correctly as bend range events
  • inserts LFO speed events to make the modulation sound more realistic
  • inserts a special event that will make mid2agb change the modulation type to match your setting
  • applys a customizable modulation scale to adjust it to match your choice
  • combines expression and volume events to volume events only
  • applys a custom volume scale to all volume events and note velocitys
  • fixes the loop problem I mentioned above
Usage:
This is a command line tool. The usage is like this (you may also just launch the program without arguments):


midfix4agb.exe "inputfile.mid" ["outputfile.mid"] [additional settings]
[] mean optional parameters

If no outputfile is specified it will automatically place the outputfile in the same directory with this name original-file-name_FINAL.
Optional arguments are:

  • modscale=1.0 (default 0.5); applies the modscale mentioned above; you might need a different character for the point depending on your country; this setting is overflow safe, the events are capped at a max value of 127
  • modt=2 (default 0); changes the modulation type of the song;
  • fixloop=true (default true, recommended); fixes the loop problems
  • fixvolscale=true (default true, recommended); applies the custom volume scale; DO NOT USE MORE THEN ONCE
Download:
Binary (.NET 3.5):
~link dead~

Source (VC# 2008):
https://github.com/ipatix/midfix4agb


Explanation of the Volume Scale:
I already mentioned above the MIDI files use the note velocitiys and the volume events to linearily control the loudness while the AGB controls linearily the amplitude.
The way I came up with a conversion algorithm was done by some math I came across:
What I want to have is a function that I put the loudness (0-127) in and returns the amplitude (0-127). Here is the brainstorming (to simplify things we'll use loudness 0.0-1.0 and amplitude 0.0-1.0):



  • In audio acoustics double the amplitude is defined by a signal amplification of 6 dB
  • double the loudness the human ear percieves is a amplification by 10 dB
  • so to calculate the final amplitude by the signal level (in dB) is a = 2^(decibels/6)
  • so now we just need to find a way of calculating the dB value of the loudness level (0.0 - 1.0) to (-oo - 0 dB)
  • we can do this by using a logarithmic function: decibels = 10 * log_10 (loudness)
  • if we combine this function this results amplitude = 10 ^ ((10 * log_10 (loudness))/6)
  • simplified this results amplitude = x ^ (10 / 6)
So each value is calcualted by scaling down the loudness from 0-127 to 0.0-1.0, putting it into the function and scaling it ip to 0-127 again.


Conclusion:
So I hope you find this tool useful for future midi insertion. I've planned adding a function to remove redundant events to reduce the amount of events but that isn't implemented yet.
 
Last edited:

Wobbu

bunger bunger bunger bunger
2,794
Posts
12
Years
Thank you a lot for this tool! It saves me a lot of time from manually editing midis with Anville Studio. My favorite part about your tool is that it solves the expression problem, an issue that took way too long to fix with Anville Studio. The songs that I've tested sound really good, and I plan on reinserting all of my custom music with this tool.

I can't thank you enough for your contributions to the music hacking community :D
 

ipatix

Sound Expert
145
Posts
15
Years
Actually I think there is still some issues with the loop event fixing. It doesn't break anything but sometimes it won't insert the loopback events correctly. I'm working on fixing it though.
 

Wobbu

bunger bunger bunger bunger
2,794
Posts
12
Years
When ripping HoOh's battle theme from HG/SS, and applying the mid to midfix4agb and assembling it in Sappy, it will crash soon before the organ goes through extreme modulations.

Right around this part:
http://youtu.be/O2Hs4s9LLVg?t=2m20s

I'm having this problem with Windows 8.1. After further research I see that there was a problem with both Sappy's compatibility with my OS and the midfix4agb. It will always crash no matter the condition of the midi on Windows 8.1... After trying an unedited midi with Windows Vista, the whole song played fine, but after applying the midi to midfix4agb, it crashed at the same spot.
 
12
Posts
5
Years
  • Age 36
  • Seen Dec 26, 2018
32bit Windows version of ipatix/midi2agb
Can you provide binary?
At least the MIDI production environment is 32bits better
It is convenient in various ways.
I can patch to the PAE kernel of 32bit version Windows and use 4GB or more RAM.
 
Back
Top