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 CINE_SOUND_H_
23 #define CINE_SOUND_H_
24 
25 #include "common/util.h"
26 #include "common/mutex.h"
27 #include "audio/mixer.h"
28 #include "audio/mididrv.h"
29 
30 namespace Audio {
31 class AudioStream;
32 }
33 
34 namespace Cine {
35 
36 class CineEngine;
37 
38 class Sound {
39 public:
40 
41  Sound(Audio::Mixer *mixer, CineEngine *vm) : _mixer(mixer), _vm(vm), _musicType(MT_INVALID) {}
42  virtual ~Sound() {}
43 
44  virtual MusicType musicType();
45  virtual void loadMusic(const char *name) = 0;
46  virtual void playMusic() = 0;
47  virtual void stopMusic() = 0;
48  virtual void fadeOutMusic() = 0;
49 
50  virtual void playSound(int mode, int channel, int param3, int param4, int param5, int size) = 0;
51  virtual void playSound(int channel, int frequency, const uint8 *data, int size, int volumeStep, int stepCount, int volume, int repeat) = 0;
52  virtual void stopSound(int channel) = 0;
53  virtual void setBgMusic(int num) = 0;
54 
55 protected:
56 
57  Audio::Mixer *_mixer;
58  CineEngine *_vm;
59  MusicType _musicType;
60 };
61 
62 class PCSoundDriver;
63 class PCSoundFxPlayer;
64 
65 class PCSound : public Sound {
66 public:
67 
68  PCSound(Audio::Mixer *mixer, CineEngine *vm);
69  ~PCSound() override;
70 
71  void loadMusic(const char *name) override;
72  void playMusic() override;
73  void stopMusic() override;
74  void fadeOutMusic() override;
75 
76  void playSound(int mode, int channel, int param3, int param4, int param5, int size) override;
77  void playSound(int channel, int frequency, const uint8 *data, int size, int volumeStep, int stepCount, int volume, int repeat) override;
78  void stopSound(int channel) override;
79  void setBgMusic(int num) override;
80 
81 protected:
82 
83  PCSoundDriver *_soundDriver;
84  PCSoundFxPlayer *_player;
85 
86  uint8 _currentMusic, _currentMusicStatus, _currentBgSlot;
87 };
88 
89 class PaulaSound : public Sound {
90 public:
91 
92  PaulaSound(Audio::Mixer *mixer, CineEngine *vm);
93  ~PaulaSound() override;
94 
95  void loadMusic(const char *name) override;
96  void playMusic() override;
97  void stopMusic() override;
98  void fadeOutMusic() override;
99 
100  void playSound(int mode, int channel, int param3, int param4, int param5, int size) override;
101  void playSound(int channel, int frequency, const uint8 *data, int size, int volumeStep, int stepCount, int volume, int repeat) override;
102  void stopSound(int channel) override;
103  void setBgMusic(int num) override;
104 
105  enum {
106  PAULA_FREQ = 3579545,
107  NUM_CHANNELS = 4
108  };
109 
110 protected:
111 
112  struct SfxChannel {
113  Audio::SoundHandle handle;
114  int volume;
115  int volumeStep;
116  int curStep;
117  int stepCount;
118 
119  void initialize(int vol, int volStep, int stepCnt) {
120  volume = vol;
121  volumeStep = volStep;
122  curStep = stepCount = stepCnt;
123  }
124  };
125  SfxChannel _channelsTable[NUM_CHANNELS];
126  static const int _channelBalance[NUM_CHANNELS];
127  Common::Mutex _sfxMutex;
128  int _sfxTimer;
129  static void sfxTimerProc(void *param);
130  void sfxTimerCallback();
131 
132  Common::Mutex _musicMutex;
133  int _musicTimer;
134  int _musicFadeTimer;
135  static void musicTimerProc(void *param);
136  void musicTimerCallback();
137  Audio::SoundHandle _moduleHandle;
138  Audio::AudioStream *_moduleStream;
139 };
140 
141 extern Sound *g_sound;
142 
143 } // End of namespace Cine
144 
145 #endif /* CINE_SOUND_H_ */
Definition: sound.h:89
Definition: anim.h:29
MusicType
Definition: mididrv.h:44
Definition: mixer.h:49
Definition: sound.h:38
Definition: mixer.h:59
Definition: cine.h:127
Definition: mutex.h:67
Definition: audiostream.h:50
Definition: sound.h:112
Definition: system.h:38
Definition: sound.h:65