ScummVM API documentation
player_v2cms.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 SCUMM_PLAYERS_PLAYER_V2CMS_H
23 #define SCUMM_PLAYERS_PLAYER_V2CMS_H
24 
25 #include "scumm/players/player_v2base.h" // for channel_data
26 
27 namespace CMS {
28 class CMS;
29 }
30 
31 namespace Scumm {
32 
36 class Player_V2CMS : public Player_V2Base {
37 public:
38  Player_V2CMS(ScummEngine *scumm);
39  ~Player_V2CMS() override;
40 
41  // MusicEngine API
42  void setMusicVolume(int vol) override;
43  void startSound(int sound) override;
44  void stopSound(int sound) override;
45  void stopAllSounds() override;
46  int getMusicTimer() override;
47  int getSoundStatus(int sound) const override;
48 
49  void onTimer();
50 
51 private:
52  struct Voice {
53  byte attack;
54  byte decay;
55  byte sustain;
56  byte release;
57  byte octadd;
58  int16 vibrato;
59  int16 vibrato2;
60  int16 noise;
61  };
62 
63  struct Voice2 {
64  byte *amplitudeOutput;
65  byte *freqOutput;
66  byte *octaveOutput;
67 
68  uint8 channel;
69  int8 sustainLevel;
70  uint8 attackRate;
71  uint8 maxAmpl;
72  uint8 decayRate;
73  uint8 sustainRate;
74  uint8 releaseRate;
75  uint8 releaseTime;
76  int8 vibratoRate;
77  int8 vibratoDepth;
78 
79  int8 curVibratoRate;
80  int8 curVibratoUnk;
81 
82  int8 unkVibratoRate;
83  int8 unkVibratoDepth;
84 
85  int8 unkRate;
86  int8 unkCount;
87 
88  enum EnvelopeState {
89  kEnvelopeAttack,
90  kEnvelopeDecay,
91  kEnvelopeSustain,
92  kEnvelopeRelease
93  };
94 
95  EnvelopeState nextProcessState;
96  uint8 curVolume;
97  uint8 curOctave;
98  uint8 curFreq;
99 
100  int8 octaveAdd;
101 
102  int8 playingNote;
103  Voice2 *nextVoice;
104 
105  byte chanNumber;
106  };
107 
108  struct MusicChip {
109  byte ampl[4];
110  byte freq[4];
111  byte octave[2];
112  };
113 
114  Voice _cmsVoicesBase[16];
115  Voice2 _cmsVoices[8];
116  MusicChip _cmsChips[2];
117 
118  uint8 _tempo;
119  uint8 _tempoSum;
120  byte _looping;
121  byte _octaveMask;
122  int16 _midiDelay;
123  Voice2 *_midiChannel[16];
124  byte _midiChannelUse[16];
125  byte *_midiData;
126  byte *_midiSongBegin;
127 
128  int _loadedMidiSong;
129 
130  byte _sfxFreq[4], _sfxAmpl[4], _sfxOctave[2];
131 
132  byte _lastMidiCommand;
133  uint _outputTableReady;
134  byte _voiceTimer;
135 
136  int _musicTimer, _musicTimerTicks;
137 
138  void loadMidiData(byte *data, int sound);
139  void play();
140 
141  void processChannel(Voice2 *channel);
142  void processRelease(Voice2 *channel);
143  void processAttack(Voice2 *channel);
144  void processDecay(Voice2 *channel);
145  void processSustain(Voice2 *channel);
146  void processVibrato(Voice2 *channel);
147 
148  void playMusicChips(const MusicChip *table);
149  void playNote(byte *&data);
150  void clearNote(byte *&data);
151  void offAllChannels();
152  void playVoice();
153  void processMidiData();
154 
155  Voice2 *getFreeVoice();
156  Voice2 *getPlayVoice(byte param);
157 
158  struct MidiNote {
159  byte frequency;
160  byte baseOctave;
161  };
162 
163  static const MidiNote _midiNotes[132];
164  static const byte _attackRate[16];
165  static const byte _decayRate[16];
166  static const byte _sustainRate[16];
167  static const byte _releaseRate[16];
168  static const byte _volumeTable[16];
169  static const byte _cmsInitData[26];
170 
171  CMS::CMS *_cmsEmu;
172 
173  Common::Mutex _mutex;
174 };
175 
176 } // End of namespace Scumm
177 
178 #endif
Definition: cms.h:27
Definition: scumm.h:518
Definition: player_v2base.h:66
Definition: mutex.h:67
Definition: cms.h:39
Definition: actor.h:30
Definition: player_v2cms.h:36