⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readme.m2m

📁 MIDI解码程序(用VC编写)
💻 M2M
字号:
m2m: mod->midi file converter for TiMidity++BRIEF SYNOPSIS:This adds the new -OM output mode to TiMidity++, which will read in a mod fileand output a midi file.  All parameters needed for the conversion arecontained in a .m2m file of the same base name as the mod.  If this file cannot be found, it will generate one for you.  Chord assignment andtransposition values can be very difficult and tedious to assign by hand.  Itis STRONGLY recommended that you let the program generate the initial .m2mfile, so that it can do most (if not all) of this for you.  You will stillneed to assign drums, correct banks/programs, and tweak volume amps by hand.EXAMPLE USAGE:timidity -c c:\timidity\timidity.cfg -OM -V 2 -idt foo.modThis will try to read in foo.m2m as the config file for the conversion, andwill output a file called foo.mid.  -V 2 tells it to generate midi for useon a device that uses an X^2 volume curve (all GM/GS/XG hardware).  You canuse the -o flag to specify any other output name you wish.If you don't have timidity installed, so that you don't have a validtimidity.cfg file, just create a 0 byte file and use it instead of the realthing.  Since you're playing mod files, timidity doesn't need to load anymidi instruments, so you don't need to have a set of patches or a realtimidity.cfg file :)BACKGROUND:MOD files are a lot like MIDI files.  Both formats are basicly a series ofevents that control how notes get played with which instruments.  MODspackage the instruments along with the events into a single file, while MIDIrelies on external sources of instruments.  It is this fundamentaldifference that creates the most difficulty in performing a mod->midi fileconversion.  The mod file does not need to know what pitch each sample istuned to, if it is a drum, or if it is a chord.  MOD players simply play thepackaged sample at the requested pitch, assuming all samples are tuned tothe same fixed frequency, whether they actually are or not.  Thus, if youwere to do a direct mod->midi event conversion, you would wind up with midiinstruments playing in the wrong keys, snare drums being treated as normalmelodic instruments, and single notes where there should be chords. Transposition, drum related channel movements, and chord emissions are themost noticable obstacles to overcome when performing an accurace mod->midiconversoin.Paolo Bonzini has already done half of my job for me.  He contributed a goodamount of code that turns TiMidity++ into a first rate mod player.  This,alone, would not have helped me very much; it was how he implemented it.  Rather than handle the events like every other mod player known to man,TiMidity++ converts them into standard midi events, loads the mod instrumentsin as special patches, and then renders them just like it would any normalmidi file.  The mod event parsing, instrument parsing, and direct eventconversion was already done!  All I had to do was handle the problems Imentioned above, along with many more minor ones I haven't mentioned, beforewriting the internal TiMidity++ events out to a midi file.  See the commentsat the top of m2m.c if you are interested in some of the other issues thatneeded to be addressed during the conversion process.  Although some ofthese other issues were non-trivial to deal with, and pitch bends beyond 4octaves may still sound a bit odd, they are nothing that the average userneeds to know about or keep in mind when trying to succesfully convert a modfile.  The only thing you need to know is that, in order to address theconversion problems disscussed above, some information about each sample inthe mod must be specified in a config file (.m2m) associated with each modfile.  The format of this file is given below.M2M CONFIG FILE FORMAT:Comment lines must begin with a #.  Blank lines (no spaces or any othercharacter besides a newline or carriage return) are allowed.  All other linesmust specify ALL FIVE of the fields described below.  Each field is separatedby white space.FIELD 1: Sample NumberThis is the number of the sample that you are defining information for. The first sample in the mod file is 1 (not zero).FIELD 2: Bank/Program, drum flag, chord, silent flagThis field specifies several different properties of the sample.  Optionalparamaters are given surrounded by parentheses.  The format for this fieldis:(!)(bank/)program(chord)(*)If the field begins with an exclaimation mark, ! , then no notes will beissued for this sample.  This can be used to silence samples that you cannot assign to a general midi instrument, such as speech, complicated drumtracks, or any sound effect that you can not create a close approximation tousing GS sfx banks.The bank portion of the field specifies an optional bank selection.  This isthe number of the bank to use, followed by a / to separate it from theprogram number.The program number is the midi instrument you are assigning to the sample. If the sample is a drum, this is the note that the drum is mapped to in thedrum set.The optional chord field specifies what type of chord the sample is composedof.  There are 4 types of chords, each of which has 3 subtypes.  Thesupported chord types are (M)ajor, (m)inor, (d)iminished minor, and (f)ifth.Each chord is specified by the letter surrounded by parantheses in theprevious line.  The subtype of the chord describes how much the chord is"rotated" from a standard chord, which can be 0, 1, or 2.  As an example ofwhat I mean by "rotated", a major chord is composed of the following notesemitone offsets: 0,4,7.  If you were to rotate the chord one to the left, itwould be: -5,0,4.  Two to the left is: -8,-5,0.  If no subtype is given,zero rotation is assumed.The final part specifies if the sample is a drum.  Put a * at the end of thefield to indicate this.  Chord assignments will be ignored if the drum flagis set.Examples:8/48M     bank 8, program 48 (Orchestra Strings), with a normal major chord!8/48M    silence this sample8/48M2    same as the first example, only the chord is rotated down twice48        normal Marcato Strings in tone bank 016/38*    Power drum set, Snare138*       Snare1 on the regular drum set 0FIELD 3: TranspositionThis is how much to transpose the original note specified in the mod file. If the sample is tuned at middle C (pitch 60), it will need to be transposed+24 semitones for the midi instrument to play on the correct pitch.  Samplesmarked as drums will not be transposed, since they are fixed to a singlenote on the drum channel.  You must still enter a value for thetransposition field, even if it is ignored by the drums, so that the configfile parser will not crash.FIELD 4: Fine TuningAll pitch bend events for this sample will be adjusted by the given fractionof a pitch.  This is sometimes necessary for highly out of tune samples.Some MOD composers, instead of tuning their samples correctly, use pitchbends to tune the samples.  When you play this music with correctly tunedsamples, these pitch bends detune the note and it sounds out of tune.  So thefine tuning value is used to compensate for these detuning pitchbends.It is also common to find out of tune samples that were NOT tuned withpitchbends, so adding in a pitch bend adjustment would only make them soundworse in a midi file.  To disable fine tuning, an optional ! can be placedbefore the fine tuning value.  This is the DEFAULT SETTING in the automaticconfig file generator.  If you find that a mod requires fine tuning for asample, simply delete the ! and redo the conversion.This feature is not yet fully implemented.  Only existing pitch bend eventsare affected, so no new pitch bend events are issued.  This is not usually aproblem, however, since most cases where this feature needs to be appliedinvolve mods that issue pitch bends before the affected notes, since theywere intended to tune the samples to begin with.  I plan to eventuallyimplement insertion of new pitch bend events, so that this will be a truefine tuning feature. FIELD 5: %VolumeEach sample can be amplified by scaling the expression events.  100 is thedefault amount, which is 100% of the original volume.  50 would decrease itto half of the original volume, while 150 would be 1.5 times the originalvolume.  Don't forget that the maximum expression value is 127, so anyexpression events that get scaled higher than this will cap off at 127 andyou won't hear any difference.  It is mainly used for quieting instrumentsthat are too loud in the midi file, or for amplifying instruments whooseexpression values are too low to begin with.Any fields beyond the first 5 will not be parsed.  You can type anythinghere that you want.  You do not have to place a # before comment text, butit is conventional to do so.FREQUENCY ANALYSIS:So, how do you figure out how much to transpose each sample and what chordit is?  Load it up in a program that can perform an FFT on the sample anddisplay the frequency peaks.  The first peak is usually, but not always, thefundamental pitch of the sample.  If the sample is a chord, take the first 3major peaks and assign the chord from these.  Then enter the appropriatechord and transposition values in the .m2m file and see if it sounds correct.It is VERY time consuming to do all of this by hand....  So, I wrote routinesto do all of the assignments for you :)  It is not 100% accurate, but it'spretty darn close.  And when it does miss a pitch or a chord, it alwaysassigns it the correct LOOKING answer.  That is, if I were to visuallyinspect the FFT data, I would pick the same pitch the algorithm does.  I'mno expert at this, but after spending so many hours testing this on manydifferent difficult to assign pitches, I think I'm pretty good at it now :) The only way I can see to improve it is to build in some sort ofpsychoacoustical model that takes into account how the human ear percievesthe sound.  And I don't think I want to do that at the moment....  It does anabove average job at dealing with samples that have more than one pitch orchord in them, but don't be surprised if a noisy or multi-tonal sampledoesn't get assigned correctly.  Garbage in, garbage out :)  The automaticassignment is very good for the vast majority of samples and should DEFINATELYbe tried first before you start changing things by hand.  When it does messup, it's usually only off by a single semitone or an octave multiple, so it'seasy to tweak from there.Before I wrote the automatic frequency analysis routines, I knew very littleabout the field.  Pitch detection is a very old problem in the audio signalprocessing literature.  I looked up references in the library dating fromthe 1960's.  The stuff from back then is just as relevant as the laterliterature, since the methods really haven't improved much since then.  Thetwo major camps on how to do this are "autocorrelation" and "cepstrum"analysis.  It turns out that autocorrelation was not the answer to myproblems.  While it works well on "well behaved" samples, it breaks downvery quickly on synth instruments, noisy instruments, and instruments withmultiple fundamental frequencies.  A large number of samples encountered inmod files exhibit these properties.  No matter what I did to try to tweak it,and I tried a lot of good things, I just could not make it robust enough tohandle real world samples.  It's a good theory, but it falls apart inpractice.Cepstrum analysis proved to be much more robust.  But even so, I had to do agood deal of pitch filtering and peak weighting before I could get it to workwell.  The 2nd FFT analysis kept giving me frequency peaks that didn't existin the 1st FFT spectrum.  They were, however, very close to real peaks.  So Ithrow away all frequencies that fall below a pitch peak area and maximummagnitude filter, then force the cepstrum analysis to only choose pitches thathave made it through the filter in the 1st FFT spectrum.  I set a maximumfrequency based on zero point crossing analysis, going out two zero crossingsfrom the largest amplitude in the sample.  This was necessary to preventoctave jumping errors.  I found that it is also important to weight thecepstrum peak areas by the maximum magnitude within the corresponding pitchpeak in the 1st FFT.  This was a desperate attempt to get some especiallytroublesome bass samples to assign correctly.  Surprisingly enough, it worksgreat, giving me a higher success rate on all my samples without inducing anynew misassignments!  The only catch is that the weighting only works well for< 2 seconds of audio analysis.  Any larger than that and the FFT size getsso big that the pitch peaks are too diffused, so the maximum magnitudes forthe pitches are too small, and the weighting starts to give wrong answers. If anyone wants to analyze >= 2 seconds of data, which isn't neccessary forassigning pitches to mod/midi instruments, it would be easy to implement asliding window average that calls the existing frequency assignmentfunction.It appears to work better than any of the other sample analysis software Ihave.  If you are interested in more details of how I did the cepstrumanalysis, try looking over the code in freq.c and/or email me for a morecomplete description of the algorithm I wound up with.  The new FFT routinesare not mine, but are public domain.  From all the benchmarks I could find,this is the best FFT implementation for doing what I need to do (and forfuture effects processing, should they ever be added to TiMidity++).  Seefft4g.c for info on where to get the original FFT package.SUGGESTIONS ?:Feel free to email me with any suggestions you may have on how I can do abetter job of converting the mods, or how I can implement things on the TODOor WISH lists in m2m.c.  I am considering turning this into a stand aloneprogram, but until I get more free time and energy, it's going to stay asjust an addon for TiMidity++.LEGAL STUFF:TiMidity++ is distributed under the GPL, and since my code is derived fromand makes use of it, I guess it's under the GPL too.  So blah blah blah,legal stuff, blah blah blah, etc..  You know the drill.Eric A. Welsh <ewelsh@ccb.wustl.edu>Center for Molecular DesignCenter for Computational BiologyWashington UniversitySt. Louis, MO

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -