ScummVM API documentation
pc_base.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 
23 #ifndef KYRA_SOUND_PCDRIVER_H
24 #define KYRA_SOUND_PCDRIVER_H
25 
26 #include "kyra/resource/resource.h"
27 
28 namespace Audio {
29  class Mixer;
30 }
31 
32 namespace Kyra {
33 
35 public:
36  PCSoundDriver() : _soundData(0), _soundDataSize(0) {}
37  virtual ~PCSoundDriver() {}
38 
39  virtual void initDriver() = 0;
40  virtual void setSoundData(uint8 *data, uint32 size) = 0;
41  virtual void startSound(int track, int volume) = 0;
42  virtual bool isChannelPlaying(int channel) const = 0;
43  virtual void stopAllChannels() = 0;
44 
45  virtual int getSoundTrigger() const { return 0; }
46  virtual void resetSoundTrigger() {}
47 
48  virtual void setMusicVolume(uint8 volume) = 0;
49  virtual void setSfxVolume(uint8 volume) = 0;
50 
51  // AdLiB (Kyra 1) specific
52  virtual void setSyncJumpMask(uint16) {}
53 
54 protected:
55  uint8 *getProgram(int progId) {
56  // Safety check: invalid progId would crash.
57  if (progId < 0 || progId >= (int32)_soundDataSize / 2)
58  return nullptr;
59 
60  const uint16 offset = READ_LE_UINT16(_soundData + 2 * progId);
61 
62  // In case an invalid offset is specified we return nullptr to
63  // indicate an error. 0xFFFF seems to indicate "this is not a valid
64  // program/instrument". However, 0 is also invalid because it points
65  // inside the offset table itself. We also ignore any offsets outside
66  // of the actual data size.
67  // The original does not contain any safety checks and will simply
68  // read outside of the valid sound data in case an invalid offset is
69  // encountered.
70  if (offset == 0 || offset >= _soundDataSize) {
71  return nullptr;
72  } else {
73  return _soundData + offset;
74  }
75  }
76 
77  uint8 *_soundData;
78  uint32 _soundDataSize;
79 
80 public:
81  static PCSoundDriver *createAdLib(Audio::Mixer *mixer, int version);
82 #ifdef ENABLE_EOB
83  static PCSoundDriver *createPCSpk(Audio::Mixer *mixer, bool pcJRMode);
84 #endif
85 };
86 
87 } // End of namespace Kyra
88 
89 #endif
Definition: pc_base.h:34
Definition: mixer.h:59
Definition: detection.h:27
Definition: system.h:38