00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef FMOPLMIDIDRIVER_H_INCLUDED
00020 #define FMOPLMIDIDRIVER_H_INCLUDED
00021
00022 #ifdef USE_FMOPL_MIDI
00023
00024 #include "LowLevelMidiDriver.h"
00025 #include "fmopl.h"
00026
00027 class IDataSource;
00028
00029 class FMOplMidiDriver : public LowLevelMidiDriver
00030 {
00031 const static MidiDriverDesc desc;
00032 static MidiDriver *createInstance() {
00033 return new FMOplMidiDriver();
00034 }
00035
00036 public:
00037 const static MidiDriverDesc* getDesc() { return &desc; }
00038 FMOplMidiDriver();
00039
00040 protected:
00041
00042 virtual int open();
00043 virtual void close();
00044 virtual void send(uint32 b);
00045 virtual void lowLevelProduceSamples(sint16 *samples, uint32 num_samples);
00046
00047
00048 virtual bool isSampleProducer() { return true; }
00049 virtual bool isFMSynth() { return true; }
00050 virtual void loadTimbreLibrary(IDataSource*, TimbreLibraryType type);
00051
00052 private:
00053
00054 static const unsigned char midi_fm_instruments_table[128][11];
00055 static const int my_midi_fm_vol_table[128];
00056 static int lucas_fm_vol_table[128];
00057 static const unsigned char adlib_opadd[9];
00058 static const int fnums[12];
00059 static const double bend_fine[256];
00060 static const double bend_coarse[128];
00061
00062 struct midi_channel {
00063 int inum;
00064 unsigned char ins[12];
00065 bool xmidi;
00066 int xmidi_bank;
00067 int vol;
00068 int expression;
00069 int nshift;
00070 int on;
00071 int pitchbend;
00072 int pan;
00073 };
00074 struct xmidibank {
00075 unsigned char insbank[128][12];
00076 };
00077
00078 enum {
00079 ADLIB_MELODIC = 0,
00080 ADLIB_RYTHM = 1
00081 };
00082
00083 void midi_write_adlib(unsigned int reg, unsigned char val);
00084 void midi_fm_instrument(int voice, unsigned char *inst);
00085 int midi_calc_volume(int chan, int vel);
00086 void midi_update_volume(int chan);
00087 void midi_fm_volume(int voice, int volume);
00088 void midi_fm_playnote(int voice, int note, int volume, int pitchbend);
00089 void midi_fm_endnote(int voice);
00090 unsigned char adlib_data[256];
00091
00092
00093 int chp[9][4];
00094 unsigned char myinsbank[128][12];
00095 xmidibank *xmidibanks[128];
00096 void loadXMIDITimbres(IDataSource *ds);
00097 void loadU7VoiceTimbres(IDataSource *ds);
00098
00099 FMOpl_Pentagram::FM_OPL *opl;
00100 midi_channel ch[16];
00101 };
00102
00103 #endif //USE_FMOPL_MIDI
00104
00105 #endif //FMOPLDRV_H