Go Back   The PokéCommunity Forums > ROM Hacking > Tools, Tutorials & Resources
Reload this Page [Tool] midfix4agb - A MIDI preperation tool for GBA insertion

Notices
For all updates, view the main page.

Tools, Tutorials & Resources Various tools to help you develop your hacks can be found here.
New threads in this forum are to be approved by a moderator before they are displayed.



Reply
 
Thread Tools
  #1    
Old June 16th, 2014 (04:18 PM). Edited June 17th, 2014 by ipatix.
ipatix's Avatar
ipatix ipatix is offline
Sound Expert
 
Join Date: May 2008
Location: Germany
Gender: Male
Nature: Relaxed
Posts: 137
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
  • isn't that bad in performance. It processes MIDIs in about 50ms to 100ms on my machine
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):
https://dl.dropboxusercontent.com/u/28573353/Programs/midfix4agb.7z

Source (VC# 2008):
https://dl.dropboxusercontent.com/u/28573353/Programs/Source/midfix4agb.7z


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_2 (loudness)
  • if we combine this function this results amplitude = 2 ^ ((10 * log_2 (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.
__________________
Visit my YouTube channel (music hacking and other stuff): http://www.youtube.com/user/theipatix
Reply With Quote
  #2    
Old July 4th, 2014 (04:34 PM).
Wobbu's Avatar
Wobbu Wobbu is offline
ffet
Moderator
 
Join Date: Mar 2012
Location: Betnikh
Gender: Male
Nature: Relaxed
Posts: 2,529
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
__________________
Wobbu - Khajiit DK
Aldmeri Dominion PC/Mac NA
Staff Antagonists Collab 2015
Reply With Quote
  #3    
Old July 5th, 2014 (12:34 PM).
ipatix's Avatar
ipatix ipatix is offline
Sound Expert
 
Join Date: May 2008
Location: Germany
Gender: Male
Nature: Relaxed
Posts: 137
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.
__________________
Visit my YouTube channel (music hacking and other stuff): http://www.youtube.com/user/theipatix
Reply With Quote
  #4    
Old July 14th, 2014 (06:06 PM).
mrtienduc1999's Avatar
mrtienduc1999 mrtienduc1999 is offline
 
Join Date: Jan 2013
Gender: Male
Posts: 24
Its Good i can add a new song now, thanks. but, i dont make a song can come back. You can show to me, please Ipatix!
__________________
This signature has been disabled.
Linking to a website with ROMs.
Please review and fix the issues by reading the signature rules.

You must edit it to meet the limits set by the rules before you may remove the [sig-reason] code from your signature. Removing this tag will re-enable it.

Do not remove the tag until you fix the issues in your signature. You may be infracted for removing this tag if you do not fix the specified issues. Do not use this tag for decoration purposes.
Reply With Quote
  #5    
Old July 14th, 2014 (06:09 PM).
GoldfishHorde's Avatar
GoldfishHorde GoldfishHorde is offline
Whoa! A horde of Goldfish appeared!
 
Join Date: Jul 2014
Location: Outside of a Sewage Treatment Plant
Gender: Male
Nature: Quirky
Posts: 123
Err...do I download Binary or Source? I'm a bit confused.
Reply With Quote
  #6    
Old July 15th, 2014 (03:36 AM).
Windsong Windsong is offline
—the dream is dead
 
Join Date: Dec 2007
Location: Germany
Age: 22
Gender: Male
Nature: Quiet
Posts: 30
Quote originally posted by GoldfishHorde:
Err...do I download Binary or Source? I'm a bit confused. ~_~
I am pretty sure you want the binary.
__________________
あなたがいつか消えて行くの?
working on something
Reply With Quote
  #7    
Old August 13th, 2014 (06:44 AM).
Wobbu's Avatar
Wobbu Wobbu is offline
ffet
Moderator
 
Join Date: Mar 2012
Location: Betnikh
Gender: Male
Nature: Relaxed
Posts: 2,529
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.
__________________
Wobbu - Khajiit DK
Aldmeri Dominion PC/Mac NA
Staff Antagonists Collab 2015
Reply With Quote
Reply
Quick Reply

Sponsored Links

You may also like.. (Beta)
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are UTC -8. The time now is 02:20 PM.