rhargreaves / mega-drive-midi-interface

Control the Sega Mega Drive's Yamaha YM2612 and PSG with MIDI
GNU General Public License v3.0
95 stars 8 forks source link

VGI to preset.c (js) #38

Open KPY7030P opened 3 months ago

KPY7030P commented 3 months ago

I want to give you a code (JS) that will convert a folder with VGI files into a preset file. this is my contribution to the community. generate_presets_v2.zip

KPY7030P commented 3 months ago

{{4, 7, 1, 0, 0, 1, 0, {{ 15, 0, 22, 0, 8, 1, 9, 31, 15, 0, 0 }, {...}, {...}, {...}}, 36 }; {{algo, Fb, Pan, AMS, FMS, LFO, Ch3 {{ TL, AR, MUL, DT, RS, AM, D1R, D2R, SL, RR, SSG}, {...}, {...}, {...}}, DrumRootNote};

I think my code is not working correctly. Please help me figure out the structure of the presets from the "presets.c" file. I also noticed that the FMS and AMS in the description of the preset of the tool and in the interface are reversed, but I may be mistaken. please correct me if this is the case.

rhargreaves commented 3 months ago

The structure of the instrumental preset is defined by the FmChannel struct, in synth.h:

struct FmChannel {
    u8 algorithm;
    u8 feedback;
    u8 stereo;
    u8 ams;
    u8 fms;
    u8 octave;       // ignored - can be just set to 0
    u16 freqNumber;  // ignored - can be just set to 0
    Operator operators[MAX_FM_OPERATORS]; // MAX_FM_OPERATORS = 4
};

struct Operator {
    u8 multiple;
    u8 detune;
    u8 attackRate;
    u8 rateScaling;
    u8 firstDecayRate;
    u8 amplitudeModulation;
    u8 secondaryAmplitude;
    u8 secondaryDecayRate;
    u8 releaseRate;
    u8 totalLevel;
    u8 ssgEg;
};

Percussive presets are defined by the PercussionPreset struct in midi_fm.h:

struct PercussionPreset {
    FmChannel channel;
    u8 key;
};

They are essentially the same, but have an additional key field, which tells the interface which frequency (defined as a MIDI pitch) the percussion sound should be played at.

KPY7030P commented 2 months ago

image I noticed that the order of the preset parameters (what is described above) and the order of the parameters in the WIKI do not match, I suggest fixing the WIKI? if it doesn't take a lot of time and effort :)

KPY7030P commented 2 months ago

image Among other things, the order of parameters is different in the interface. If possible, I suggest unifying the parameter order based on the VGI file specification. Multiplier Detune Total Level Rate Scaling Attack Rate Decay Rate & AMenable Sustain Rate Release Rate Sustain Level SSG-EG https://vgmrips.net/wiki/VGI_File_Format

rhargreaves commented 2 months ago

Yes you're right there's probably too much variation there. I'll have a think about what to do with the UI and Wiki. I can't do much about the order of fields in the struct as that would be a breaking change for anything which generates those files.

For now, I've fleshed out the FM Presets page of the Wiki to better explain how to define presets.

rhargreaves commented 2 months ago

I'm also considering replacing the terminology of "Second Decay Rate (D2R)" and "Secondary Amplitude (D1L/SL)" to "Sustain Rate (SR)" and "Sustain Level (SL)" accordingly. I think that's the more popular terminology these days.