fmopldrv.h

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2000, 2001, 2002  Ryan Nunn
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 */
00018 
00019 #ifndef FMOPLDRV_H
00020 #define FMOPLDRV_H
00021 
00022 #ifdef USE_FMOPL_MIDI
00023 
00024 #include "common_types.h"
00025 #include "fmopl.h"
00026 
00027 struct midi_event;
00028 
00029 //
00030 // The Internal OplDriver. Only slightly modified for exult
00031 //
00032 class OplDriver {
00033 
00034 public:
00035 
00036   /* error codes returned by open.
00037    * can be converted to a string with get_error_name()
00038    */
00039   enum {
00040     MERR_CANNOT_CONNECT = 1,
00041     MERR_STREAMING_NOT_AVAILABLE = 2,
00042     MERR_DEVICE_NOT_AVAILABLE = 3,
00043     MERR_ALREADY_OPEN = 4,
00044   };
00045 
00046   // Modulation Registers
00047   #define INDEX_AVEKM_M 0
00048   #define INDEX_KSLTL_M 2
00049   #define INDEX_AD_M    4
00050   #define INDEX_SR_M    6
00051   #define INDEX_WAVE_M  8
00052 
00053   // Carrier Registers
00054   #define INDEX_AVEKM_C 1
00055   #define INDEX_KSLTL_C 3
00056   #define INDEX_AD_C    5
00057   #define INDEX_SR_C    7
00058   #define INDEX_WAVE_C  9
00059 
00060   #define INDEX_FB_C    10
00061   #define INDEX_PERC    11
00062 
00063   #define CHP_CHAN    0
00064   #define CHP_NOTE    1
00065   #define CHP_COUNTER   2
00066   #define CHP_VEL     3
00067 
00068   /* open the midi driver.
00069    * returns 0 if successful.
00070    * otherwise an error code. */
00071   int open(int sample_rate);
00072 
00073   /* close the midi driver */
00074   void close();
00075 
00076   /* output a packed midi command to the midi stream
00077    * valid only if mode is MO_SIMPLE
00078    */
00079   void send(uint32 b);
00080 
00081   /* retrieve a string representation of an error code */
00082   static const char *get_error_name(int error_code);
00083 
00084   // Loads the mt32 bank from <STATIC>/XMIDI.AD
00085   void LoadMT32Bank(bool force_xmidi);
00086 
00087   void generate_samples(sint16 *buf, uint32 len);
00088 
00089   OplDriver();
00090   ~OplDriver();
00091 
00092 private:
00093   struct midi_channel {
00094     int inum;
00095     unsigned char ins[12];
00096     bool xmidi;
00097     int xmidi_bank;
00098     int vol;
00099     int expression;
00100     int nshift;
00101     int on;
00102     int pitchbend;
00103   };
00104   struct xmidibank {
00105     unsigned char insbank[128][12];
00106   };
00107 
00108   enum {
00109     ADLIB_MELODIC = 0,
00110     ADLIB_RYTHM = 1
00111   };
00112 
00113   void midi_write_adlib(unsigned int reg, unsigned char val);
00114   void midi_fm_instrument(int voice, unsigned char *inst);
00115   int  midi_calc_volume(int chan, int vel);
00116   void midi_update_volume(int chan);
00117   void midi_fm_volume(int voice, int volume);
00118   void midi_fm_playnote(int voice, int note, int volume, int pitchbend);
00119   void midi_fm_endnote(int voice);
00120   unsigned char adlib_data[256];
00121 
00122   void LoadXMIDIBank(const char *fn);
00123   void LoadU7VBank(const char *fn);
00124 
00125 
00126   int chp[9][4];
00127   unsigned char myinsbank[128][12];
00128   xmidibank   *xmidibanks[128];
00129 
00130   FM_OPL *_opl;
00131   midi_channel ch[16];
00132 };
00133 
00134 #endif //USE_FMOPL_MIDI
00135 
00136 #endif //FMOPLDRV_H

Generated on Mon Jul 9 14:42:41 2007 for ExultEngine by  doxygen 1.5.1