ScummVM API documentation
player_towns.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_TOWNS_H
23 #define SCUMM_PLAYERS_PLAYER_TOWNS_H
24 
25 #include "scumm/scumm.h"
26 #include "scumm/imuse/imuse.h"
27 #include "scumm/imuse/drivers/fmtowns.h"
28 #include "audio/softsynth/fmtowns_pc98/towns_euphony.h"
29 
30 namespace Scumm {
31 
32 class Player_Towns : public MusicEngine {
33 public:
34  Player_Towns(ScummEngine *vm, bool isVersion2);
35  ~Player_Towns() override {}
36 
37  virtual bool init() = 0;
38 
39  void setSfxVolume(int vol) override;
40 
41  int getSoundStatus(int sound) const override;
42 
43  virtual int32 doCommand(int numargs, int args[]) = 0;
44 
45  void saveLoadWithSerializer(Common::Serializer &ser) override;
46  void restoreAfterLoad() override;
47 
48  // version 1 specific
49  virtual int getCurrentCdaSound() { return 0; }
50  virtual int getCurrentCdaVolume() { return 0; }
51  virtual void setVolumeCD(int left, int right) {}
52  virtual void setSoundVolume(int sound, int left, int right) {}
53  virtual void setSoundNote(int sound, int note) {}
54 
55 protected:
56  void playPcmTrack(int sound, const uint8 *data, int velo = 0, int pan = 64, int note = 0, int priority = 0);
57  void stopPcmTrack(int sound);
58 
59  int allocatePcmChannel(int sound, int sfxChanRelIndex, uint32 priority);
60 
61  struct PcmCurrentSound {
62  uint16 index;
63  uint16 chan;
64  uint8 note;
65  uint8 velo;
66  uint8 pan;
67  uint8 paused;
68  uint8 looping;
69  uint32 priority;
70  } _pcmCurrentSound[9];
71  friend void syncWithSerializer(Common::Serializer &, PcmCurrentSound &);
72 
73  uint8 _unkFlags = 0x33;
74 
75  TownsAudioInterface *_intf = nullptr;
76  ScummEngine *_vm;
77 
78  const int _numSoundMax;
79  const bool _v2;
80 };
81 
82 class Player_Towns_v1 : public Player_Towns {
83 public:
85  ~Player_Towns_v1() override;
86 
87  bool init() override;
88 
89  void setMusicVolume(int vol) override;
90  void startSound(int sound) override;
91  void stopSound(int sound) override;
92  void stopAllSounds() override;
93 
94  int getSoundStatus(int sound) const override;
95  int getCurrentCdaSound() override { return _cdaCurrentSound; }
96  int getCurrentCdaVolume() override { return (_cdaVolLeft + _cdaVolRight + 1) >> 1; }
97 
98  int32 doCommand(int numargs, int args[]) override;
99 
100  void setVolumeCD(int left, int right) override;
101  void setSoundVolume(int sound, int left, int right) override;
102  void setSoundNote(int sound, int note) override;
103 
104  void saveLoadWithSerializer(Common::Serializer &ser) override;
105  void restoreAfterLoad() override;
106 
107 private:
108  void restartLoopingSounds();
109  void startSoundEx(int sound, int velo, int pan, int note);
110  void stopSoundSuspendLooping(int sound);
111 
112  void playEuphonyTrack(int sound, const uint8 *data);
113  void playCdaTrack(int sound, const uint8 *data, bool skipTrackVelo = false);
114 
115  struct SoundOvrParameters {
116  uint8 vLeft;
117  uint8 vRight;
118  uint8 note;
119  };
120 
121  SoundOvrParameters *_soundOverride = nullptr;
122 
123  uint8 _cdaVolLeft = 0;
124  uint8 _cdaVolRight = 0;
125 
126  uint8 _eupCurrentSound = 0;
127  uint8 _eupLooping = 0;
128  uint8 _eupVolLeft = 0;
129  uint8 _eupVolRight = 0;
130 
131  uint8 _cdaCurrentSound = 0;
132  uint8 _cdaNumLoops = 0;
133  uint8 _cdaForceRestart = 0;
134 
135  uint8 _cdaCurrentSoundTemp = 0;
136  uint8 _cdaNumLoopsTemp = 0;
137 
138  EuphonyPlayer *_player = nullptr;
139 };
140 
142 public:
143  Player_Towns_v2(ScummEngine *vm, Audio::Mixer *mixer, IMuse *imuse, bool disposeIMuse);
144  ~Player_Towns_v2() override;
145 
146  bool init() override;
147 
148  void setMusicVolume(int vol) override;
149 
150  int getSoundStatus(int sound) const override;
151  void startSound(int sound) override;
152  void stopSound(int sound) override;
153  void stopAllSounds() override;
154 
155  int32 doCommand(int numargs, int args[]) override;
156 
157  void saveLoadWithSerializer(Common::Serializer &ser) override;
158 
159 private:
160  void playVocTrack(const uint8 *data);
161 
162  struct SoundOvrParameters {
163  uint8 velo;
164  uint8 pan;
165  uint8 type;
166  };
167 
168  SoundOvrParameters *_soundOverride = nullptr;
169 
170  uint8 *_sblData = nullptr;
171 
172  IMuse *_imuse = nullptr;
173  const bool _imuseDispose;
174 };
175 
176 } // End of namespace Scumm
177 
178 #endif
Definition: player_towns.h:141
virtual void stopAllSounds()=0
virtual void startSound(int sound)=0
void setSfxVolume(int vol) override
Definition: player_towns.h:61
Definition: music.h:40
void restoreAfterLoad() override
Definition: serializer.h:79
Definition: scumm.h:518
Definition: towns_audio.h:37
virtual void setMusicVolume(int vol)=0
int getSoundStatus(int sound) const override
Definition: mixer.h:59
Definition: player_towns.h:32
Definition: towns_euphony.h:115
Definition: imuse.h:50
Definition: player_towns.h:82
void saveLoadWithSerializer(Common::Serializer &ser) override
Definition: actor.h:30
virtual void stopSound(int sound)=0