Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Super 3D Noah's Ark MIDI -> OPL instruments
- #include <cstdio>
- #include <stdint.h>
- #include <cstring>
- #pragma pack(1)
- struct Instrument
- {
- uint8_t
- mtrem, ctrem,
- mvol, cvol,
- matt, catt,
- msus, csus,
- mwav, cwav,
- feed,
- unused;
- };
- struct OP2Instrument
- {
- uint16_t flags;
- uint8_t finetune;
- uint8_t notebase;
- struct Voice
- {
- uint8_t
- mtrem, matt, msus, mwav, mkey, mout,
- feed,
- ctrem, catt, csus, cwav, ckey, cout,
- unused;
- uint16_t baseoffset;
- } voice[2];
- };
- #pragma pack()
- enum EInst
- {
- I42DDC,
- I42DE8,
- I42DF4,
- I42E00,
- I42E0C,
- I42E18,
- I42E24,
- I42E30,
- I42E3C,
- I42E48,
- I42E54,
- I42E60,
- I42E6C,
- I42E78,
- NUM_INST
- };
- static const char* const EInstNames[NUM_INST] = {
- "stru_42DDC",
- "stru_42DE8",
- "stru_42DF4",
- "stru_42E00",
- "stru_42E0C",
- "stru_42E18",
- "stru_42E24",
- "stru_42E30",
- "stru_42E3C",
- "stru_42E48",
- "stru_42E54",
- "stru_42E60",
- "stru_42E6C",
- "stru_42E78"
- };
- static const Instrument instr[NUM_INST] = {
- {0x21,0x31,0x4F,0x00,0xF2,0xD2,0x52,0x73,0x00,0x00,0x06,0x00},
- {0x01,0x31,0x4F,0x04,0xF0,0x90,0xFF,0x0F,0x00,0x00,0x06,0x00},
- {0x31,0x22,0x10,0x04,0x83,0xF4,0x9F,0x78,0x00,0x00,0x0A,0x00},
- {0x11,0x31,0x05,0x00,0xF9,0xF1,0x25,0x34,0x00,0x00,0x0A,0x00},
- {0x31,0x61,0x1C,0x80,0x41,0x92,0x0B,0x3B,0x00,0x00,0x0E,0x00},
- {0x21,0x21,0x19,0x80,0x43,0x85,0x8C,0x2F,0x00,0x00,0x0C,0x00},
- {0x21,0x24,0x94,0x05,0xF0,0x90,0x09,0x0A,0x00,0x00,0x0A,0x00},
- {0x21,0xA2,0x83,0x8D,0x74,0x65,0x17,0x17,0x00,0x00,0x07,0x00},
- {0x01,0x01,0x00,0x00,0xFF,0xFF,0x07,0x07,0x00,0x00,0x07,0x00},
- {0x10,0x00,0x00,0x00,0xD8,0x87,0x4A,0x3C,0x00,0x00,0x00,0x00},
- {0x00,0x00,0x11,0x11,0xFA,0xFA,0xB5,0xB5,0x00,0x00,0x00,0x00},
- {0x00,0x00,0x00,0x00,0xF8,0xF8,0x88,0xB5,0x00,0x00,0x00,0x00},
- {0x15,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00},
- {0x21,0x11,0x4C,0x00,0xF1,0xF2,0x63,0x72,0x00,0x00,0xC0,0x00}
- };
- #define NUM_MIDI_INST 175
- static const EInst instrmap[NUM_MIDI_INST/8 + 1] = {
- I42E48, // 0 (1-7 should technically be 42DDC)
- I42E3C, // 8
- I42DE8, // 16
- I42DDC, // 24
- I42DF4, // 32
- I42DDC, // 40
- I42DDC, // 48
- I42E24, // 56
- I42E24, // 64
- I42E30, // 72
- I42DDC, // 80
- I42DDC, // 88
- I42DDC, // 96
- I42E3C, // 104
- I42E3C, // 112
- I42E3C, // 120
- I42E48, // 128
- I42E48, // 136
- I42E48, // 144
- I42E48, // 152
- I42E48, // 160
- I42E48 // 168
- };
- int main(int argc, char* argv[])
- {
- FILE *gm = fopen("noah.OP2", "wb");
- fwrite("#OPL_II#", 1, 8, gm);
- for(unsigned int i = 0;i < NUM_MIDI_INST;++i)
- {
- const Instrument &minst = instr[instrmap[i/8]];
- OP2Instrument op2;
- memset(&op2, 0, sizeof(op2));
- op2.finetune = 0x80u;
- op2.voice[0].mtrem = minst.mtrem;
- op2.voice[0].matt = minst.matt;
- op2.voice[0].msus = minst.msus;
- op2.voice[0].mwav = minst.mwav;
- op2.voice[0].mkey = (minst.mvol&0xC0)>>6;
- op2.voice[0].mout = minst.mvol&0x3F;
- op2.voice[0].feed = minst.feed;
- op2.voice[0].ctrem = minst.ctrem;
- op2.voice[0].catt = minst.catt;
- op2.voice[0].csus = minst.csus;
- op2.voice[0].cwav = minst.cwav;
- op2.voice[0].ckey = (minst.cvol&0xC0)>>6;
- op2.voice[0].cout = minst.cvol&0x3F;
- op2.voice[0].unused = minst.unused;
- fwrite(&op2, sizeof(op2), 1, gm);
- }
- for(unsigned int i = 0;i < NUM_MIDI_INST;++i)
- {
- char name[32];
- memset(name, 0, 32);
- strcpy(name, EInstNames[instrmap[i/8]]);
- fwrite(name, 1, 32, gm);
- }
- fclose(gm);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement