ScummVM API documentation
sound.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 AGI_SOUND_H
23 #define AGI_SOUND_H
24 
25 namespace Audio {
26 class Mixer;
27 class SoundHandle;
28 }
29 
30 namespace Agi {
31 
32 #define SOUND_EMU_NONE 0
33 #define SOUND_EMU_PC 1
34 #define SOUND_EMU_PCJR 2
35 #define SOUND_EMU_MAC 3
36 #define SOUND_EMU_AMIGA 4
37 #define SOUND_EMU_APPLE2GS 5
38 #define SOUND_EMU_COCO3 6
39 #define SOUND_EMU_MIDI 7
40 
44 struct AgiNote {
45  uint16 duration;
46  uint16 freqDiv;
47  uint8 attenuation;
48 
50  void read(const uint8 *ptr) {
51  duration = READ_LE_UINT16(ptr);
52  uint16 freqByte0 = *(ptr + 2); // Bits 4-9 of the frequency divisor
53  uint16 freqByte1 = *(ptr + 3); // Bits 0-3 of the frequency divisor
54  // Merge the frequency divisor's bits together into a single variable
55  freqDiv = ((freqByte0 & 0x3F) << 4) | (freqByte1 & 0x0F);
56  attenuation = *(ptr + 4) & 0x0F;
57  }
58 };
59 
67  AGI_SOUND_SAMPLE = 0x0001,
68  AGI_SOUND_MIDI = 0x0002,
69  AGI_SOUND_4CHN = 0x0008
70 };
71 
72 class SoundMgr;
73 
74 class SoundGen {
75 public:
76  SoundGen(AgiBase *vm, Audio::Mixer *pMixer);
77  virtual ~SoundGen();
78 
79  virtual void play(int resnum) = 0;
80  virtual void stop() = 0;
81 
82  AgiBase *_vm;
83 
84  Audio::Mixer *_mixer;
85  Audio::SoundHandle *_soundHandle;
86 
87  uint32 _sampleRate;
88 };
89 
93 class AgiSound {
94 public:
95  AgiSound() : _isPlaying(false), _isValid(false) {}
96  virtual ~AgiSound() {}
97  virtual void play() { _isPlaying = true; }
98  virtual void stop() { _isPlaying = false; }
99  virtual bool isPlaying() { return _isPlaying; }
100  virtual uint16 type() = 0;
101 
110  static AgiSound *createFromRawResource(uint8 *data, uint32 len, int resnum, int soundemu);
111 
112 protected:
113  bool _isPlaying;
114  bool _isValid;
115 };
116 
117 class PCjrSound : public AgiSound {
118 public:
119  PCjrSound(uint8 *data, uint32 len, int resnum);
120  ~PCjrSound() override { free(_data); }
121  uint16 type() override { return _type; }
122  const uint8 *getVoicePointer(uint voiceNum);
123  uint8 *getData() { return _data; }
124  uint32 getLength() { return _len; }
125 protected:
126  uint8 *_data;
127  uint32 _len;
128  uint16 _type;
129 };
130 
131 class SoundMgr {
132 
133 public:
134  SoundMgr(AgiBase *agi, Audio::Mixer *pMixer);
135  ~SoundMgr();
136 
137  void setVolume(uint8 volume);
138 
139  void unloadSound(int);
140  void startSound(int, int);
141  void stopSound();
142 
143  void soundIsFinished();
144 
145 private:
146  int _endflag;
147  AgiBase *_vm;
148 
149  SoundGen *_soundGen;
150 
151  int _playingSound;
152 };
153 
154 } // End of namespace Agi
155 
156 #endif /* AGI_SOUND_H */
Definition: sound.h:117
Definition: agi.h:663
uint8 * _data
Raw sound resource data.
Definition: sound.h:126
Definition: sound.h:74
uint32 _len
Length of the raw sound resource.
Definition: sound.h:127
bool _isPlaying
Is the sound playing?
Definition: sound.h:113
Definition: mixer.h:49
bool _isValid
Is this a valid sound object?
Definition: sound.h:114
Definition: mixer.h:59
Definition: sound.h:93
uint16 _type
Sound resource type.
Definition: sound.h:128
uint8 attenuation
Note volume attenuation (4-bit)
Definition: sound.h:47
uint16 duration
Note duration.
Definition: sound.h:45
void read(const uint8 *ptr)
Definition: sound.h:50
AgiSoundEmuType
Definition: sound.h:66
uint16 freqDiv
Note frequency divisor (10-bit)
Definition: sound.h:46
Definition: sound.h:131
Definition: sound.h:44
Definition: agi.h:63
Definition: system.h:37