ScummVM API documentation
adlib.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef AGOS_DRIVERS_ACCOLADE_ADLIB_H
23 #define AGOS_DRIVERS_ACCOLADE_ADLIB_H
24 
25 #include "audio/adlib_ms.h"
26 
27 namespace AGOS {
28 
30 protected:
31  static const byte RHYTHM_NOTE_INSTRUMENT_TYPES[40];
32  static const uint16 OPL_NOTE_FREQUENCIES_INSTR_DAT[12];
33  static const uint16 OPL_NOTE_FREQUENCIES_MUSIC_DRV[12];
34 
35 public:
36  MidiDriver_Accolade_AdLib(OPL::Config::OplType oplType, bool newVersion, int timerFrequency);
37  ~MidiDriver_Accolade_AdLib() override;
38 
39  int open() override;
41  void send(int8 source, uint32 b) override;
42  void deinitSource(uint8 source) override;
43 
44  // Read the specified data from INSTR.DAT or MUSIC.DRV.
45  void readDriverData(byte *driverData, uint16 driverDataSize, bool isMusicDrv);
46 
47  // Returns the number of simultaneous SFX sources supported by the current
48  // driver configuration.
49  byte getNumberOfSfxSources();
50  // Loads the specified instrument for the specified instrument source.
51  void loadSfxInstrument(uint8 source, byte *instrumentData);
52  // Sets the note (upper byte) and note fraction (lower byte; 1/256th notes)
53  // for the specified SFX source.
54  void setSfxNoteFraction(uint8 source, uint16 noteFraction);
55  // Writes out the current frequency for the specified SFX source.
56  void updateSfxNote(uint8 source);
57  // Applies a workaround for an Elvira 1 OPL3 instrument issue.
58  void patchE1Instruments();
59  // Applies a workaround for a Waxworks OPL3 instrument issue.
60  void patchWwInstruments();
61 
62 protected:
63  InstrumentInfo determineInstrument(uint8 channel, uint8 source, uint8 note) override;
64 
65  uint8 allocateOplChannel(uint8 channel, uint8 source, uint8 instrumentId) override;
66  uint16 calculateFrequency(uint8 channel, uint8 source, uint8 note) override;
67  uint8 calculateUnscaledVolume(uint8 channel, uint8 source, uint8 velocity, OplInstrumentDefinition &instrumentDef, uint8 operatorNum) override;
68 
69  void writePanning(uint8 oplChannel, OplInstrumentRhythmType rhythmType = RHYTHM_TYPE_UNDEFINED) override;
70  void writeFrequency(uint8 oplChannel, OplInstrumentRhythmType rhythmType = RHYTHM_TYPE_UNDEFINED) override;
71 
72  // Copies the specified instrument data (in INSTR.DAT/MUSIC.DRV format)
73  // into the specified instrument definition.
74  void loadInstrumentData(OplInstrumentDefinition &definition, byte *instrumentData,
75  OplInstrumentRhythmType rhythmType, byte rhythmNote, bool newVersion);
76 
77  // False if the driver should have the behavior of the Elvira 1 driver;
78  // true if it should have the behavior of the Elvira 2 / Waxworks version.
79  bool _newVersion;
80 
81  // from INSTR.DAT/MUSIC.DRV - volume adjustment per instrument
82  int8 _volumeAdjustments[128];
83  // from INSTR.DAT/MUSIC.DRV - simple mapping between MIDI channel and AdLib channel
84  byte _channelRemapping[16];
85  // from INSTR.DAT/MUSIC.DRV - simple mapping between MIDI instruments and AdLib instruments
86  byte _instrumentRemapping[128];
87  // Points to one of the OPL_NOTE_FREQUENCIES arrays, depending on the driver version
88  const uint16 *_oplNoteFrequencies;
89 
90  // Data used by AdLib SFX (Elvira 2 / Waxworks)
91 
92  // Instrument definition for each SFX source
93  OplInstrumentDefinition _sfxInstruments[4];
94  // Current MIDI note fraction (1/256th notes) for each SFX source
95  byte _sfxNoteFractions[4];
96 };
97 
98 } // End of namespace AGOS
99 
100 #endif
void writeFrequency(uint8 oplChannel, OplInstrumentRhythmType rhythmType=RHYTHM_TYPE_UNDEFINED) override
void deinitSource(uint8 source) override
void send(int8 source, uint32 b) override
uint8 calculateUnscaledVolume(uint8 channel, uint8 source, uint8 velocity, OplInstrumentDefinition &instrumentDef, uint8 operatorNum) override
void writePanning(uint8 oplChannel, OplInstrumentRhythmType rhythmType=RHYTHM_TYPE_UNDEFINED) override
Definition: adlib_ms.h:289
Definition: agos.h:70
OplType
Definition: fmopl.h:58
InstrumentInfo determineInstrument(uint8 channel, uint8 source, uint8 note) override
void send(int8 source, uint32 b) override
uint8 allocateOplChannel(uint8 channel, uint8 source, uint8 instrumentId) override
Definition: adlib_ms.h:79
uint16 calculateFrequency(uint8 channel, uint8 source, uint8 note) override
Definition: adlib.h:29