Advertisement
Blzut3

Noah MIDI instruments

May 28th, 2014
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.43 KB | None | 0 0
  1. // Super 3D Noah's Ark MIDI -> OPL instruments
  2.  
  3. #include <cstdio>
  4. #include <stdint.h>
  5. #include <cstring>
  6.  
  7. #pragma pack(1)
  8. struct Instrument
  9. {
  10.     uint8_t
  11.         mtrem, ctrem,
  12.         mvol, cvol,
  13.         matt, catt,
  14.         msus, csus,
  15.         mwav, cwav,
  16.         feed,
  17.         unused;
  18. };
  19.  
  20. struct OP2Instrument
  21. {
  22.     uint16_t flags;
  23.     uint8_t finetune;
  24.     uint8_t notebase;
  25.  
  26.     struct Voice
  27.     {
  28.         uint8_t
  29.             mtrem, matt, msus, mwav, mkey, mout,
  30.             feed,
  31.             ctrem, catt, csus, cwav, ckey, cout,
  32.             unused;
  33.         uint16_t baseoffset;
  34.     } voice[2];
  35. };
  36. #pragma pack()
  37.  
  38. enum EInst
  39. {
  40.     I42DDC,
  41.     I42DE8,
  42.     I42DF4,
  43.     I42E00,
  44.     I42E0C,
  45.     I42E18,
  46.     I42E24,
  47.     I42E30,
  48.     I42E3C,
  49.     I42E48,
  50.     I42E54,
  51.     I42E60,
  52.     I42E6C,
  53.     I42E78,
  54.  
  55.     NUM_INST
  56. };
  57.  
  58. static const char* const EInstNames[NUM_INST] = {
  59.     "stru_42DDC",
  60.     "stru_42DE8",
  61.     "stru_42DF4",
  62.     "stru_42E00",
  63.     "stru_42E0C",
  64.     "stru_42E18",
  65.     "stru_42E24",
  66.     "stru_42E30",
  67.     "stru_42E3C",
  68.     "stru_42E48",
  69.     "stru_42E54",
  70.     "stru_42E60",
  71.     "stru_42E6C",
  72.     "stru_42E78"
  73. };
  74.  
  75. static const Instrument instr[NUM_INST] = {
  76.     {0x21,0x31,0x4F,0x00,0xF2,0xD2,0x52,0x73,0x00,0x00,0x06,0x00},
  77.     {0x01,0x31,0x4F,0x04,0xF0,0x90,0xFF,0x0F,0x00,0x00,0x06,0x00},
  78.     {0x31,0x22,0x10,0x04,0x83,0xF4,0x9F,0x78,0x00,0x00,0x0A,0x00},
  79.     {0x11,0x31,0x05,0x00,0xF9,0xF1,0x25,0x34,0x00,0x00,0x0A,0x00},
  80.     {0x31,0x61,0x1C,0x80,0x41,0x92,0x0B,0x3B,0x00,0x00,0x0E,0x00},
  81.     {0x21,0x21,0x19,0x80,0x43,0x85,0x8C,0x2F,0x00,0x00,0x0C,0x00},
  82.     {0x21,0x24,0x94,0x05,0xF0,0x90,0x09,0x0A,0x00,0x00,0x0A,0x00},
  83.     {0x21,0xA2,0x83,0x8D,0x74,0x65,0x17,0x17,0x00,0x00,0x07,0x00},
  84.     {0x01,0x01,0x00,0x00,0xFF,0xFF,0x07,0x07,0x00,0x00,0x07,0x00},
  85.     {0x10,0x00,0x00,0x00,0xD8,0x87,0x4A,0x3C,0x00,0x00,0x00,0x00},
  86.     {0x00,0x00,0x11,0x11,0xFA,0xFA,0xB5,0xB5,0x00,0x00,0x00,0x00},
  87.     {0x00,0x00,0x00,0x00,0xF8,0xF8,0x88,0xB5,0x00,0x00,0x00,0x00},
  88.     {0x15,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00},
  89.     {0x21,0x11,0x4C,0x00,0xF1,0xF2,0x63,0x72,0x00,0x00,0xC0,0x00}
  90. };
  91.  
  92. #define NUM_MIDI_INST 175
  93. static const EInst instrmap[NUM_MIDI_INST/8 + 1] = {
  94.     I42E48, // 0 (1-7 should technically be 42DDC)
  95.  
  96.     I42E3C, // 8
  97.     I42DE8, // 16
  98.     I42DDC, // 24
  99.     I42DF4, // 32
  100.     I42DDC, // 40
  101.     I42DDC, // 48
  102.     I42E24, // 56
  103.     I42E24, // 64
  104.     I42E30, // 72
  105.     I42DDC, // 80
  106.     I42DDC, // 88
  107.     I42DDC, // 96
  108.     I42E3C, // 104
  109.     I42E3C, // 112
  110.     I42E3C, // 120
  111.  
  112.     I42E48, // 128
  113.     I42E48, // 136
  114.     I42E48, // 144
  115.     I42E48, // 152
  116.     I42E48, // 160
  117.     I42E48  // 168
  118. };
  119.  
  120. int main(int argc, char* argv[])
  121. {
  122.     FILE *gm = fopen("noah.OP2", "wb");
  123.  
  124.     fwrite("#OPL_II#", 1, 8, gm);
  125.  
  126.     for(unsigned int i = 0;i < NUM_MIDI_INST;++i)
  127.     {
  128.         const Instrument &minst = instr[instrmap[i/8]];
  129.         OP2Instrument op2;
  130.         memset(&op2, 0, sizeof(op2));
  131.  
  132.         op2.finetune = 0x80u;
  133.         op2.voice[0].mtrem = minst.mtrem;
  134.         op2.voice[0].matt = minst.matt;
  135.         op2.voice[0].msus = minst.msus;
  136.         op2.voice[0].mwav = minst.mwav;
  137.         op2.voice[0].mkey = (minst.mvol&0xC0)>>6;
  138.         op2.voice[0].mout = minst.mvol&0x3F;
  139.         op2.voice[0].feed = minst.feed;
  140.         op2.voice[0].ctrem = minst.ctrem;
  141.         op2.voice[0].catt = minst.catt;
  142.         op2.voice[0].csus = minst.csus;
  143.         op2.voice[0].cwav = minst.cwav;
  144.         op2.voice[0].ckey = (minst.cvol&0xC0)>>6;
  145.         op2.voice[0].cout = minst.cvol&0x3F;
  146.         op2.voice[0].unused = minst.unused;
  147.  
  148.         fwrite(&op2, sizeof(op2), 1, gm);
  149.     }
  150.  
  151.     for(unsigned int i = 0;i < NUM_MIDI_INST;++i)
  152.     {
  153.         char name[32];
  154.         memset(name, 0, 32);
  155.         strcpy(name, EInstNames[instrmap[i/8]]);
  156.         fwrite(name, 1, 32, gm);
  157.     }
  158.  
  159.     fclose(gm);
  160.     return 0;
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement