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 AWE_SOUND_H
23 #define AWE_SOUND_H
24 
25 #include "audio/mixer.h"
26 #include "audio/audiostream.h"
27 #include "awe/intern.h"
28 #include "awe/sfx_player.h"
29 
30 namespace Awe {
31 
32 #define MAX_CHANNELS 8
33 
35 private:
36  SfxPlayer *_player;
37 
38 public:
39  explicit SfxMusicStream(SfxPlayer *player) : _player(player) {}
40 
41  bool isStereo() const override {
42  return true;
43  }
44 
45  virtual int getRate() const override { return _player->_rate; }
46  virtual bool endOfData() const override { return false; }
47 
48  int readBuffer(int16 *buffer, const int numSamples) override {
49  assert(_player != nullptr);
50  memset(buffer, 0, numSamples * sizeof(int16));
51  _player->readSamples(buffer, numSamples);
52 
53  return numSamples;
54  }
55 };
56 
57 class Sound {
58 private:
59  Audio::Mixer *_mixer;
60  Audio::SoundHandle _musicHandle;
61  SfxPlayer *_sfx = nullptr;
62  SfxMusicStream *_sfxStream = nullptr;
63  Audio::SoundHandle _channels[MAX_CHANNELS];
64 
65 public:
66  explicit Sound(Audio::Mixer *mixer) : _mixer(mixer) {
67  }
68 
69  void setPlayer(SfxPlayer *player);
70 
71  void stopAll();
72  void playMusic(const char *path, int loops);
73  void playAifcMusic(const char *path, uint32 offset);
74  void playSfxMusic(int num);
75  void stopMusic();
76  void stopAifcMusic();
77  void stopSfxMusic();
78 
79  void preloadSoundAiff(byte num, const byte *data);
80  void playSoundRaw(byte channel, const byte *data, size_t size,
81  int freq, byte volume);
82  void playSoundWav(byte channel, const byte *data, size_t size,
83  uint16 freq, byte volume, byte loop);
84  void playSoundAiff(byte channel, byte num, byte volume);
85  void stopSound(byte channel);
86 };
87 
88 #ifdef TODO
89 
90 struct AifcPlayer;
91 struct SfxPlayer;
92 struct Mixer_impl;
93 
94 struct Mixer {
95  AifcPlayer *_aifc;
96  SfxPlayer *_sfx;
97  Mixer_impl *_impl;
98 
99  Mixer(SfxPlayer *sfx);
100  void init(MixerType mixerType);
101  void quit();
102  void update();
103 
104  void playSoundRaw(byte channel, const byte *data, uint16 freq, byte volume);
105  void playSoundWav(byte channel, const byte *data, uint16 freq, byte volume, byte loop);
106  void stopSound(byte channel);
107  void setChannelVolume(byte channel, byte volume);
108  void playMusic(const char *path, byte loop);
109  void stopMusic();
110  void playAifcMusic(const char *path, uint32 offset);
111  void stopAifcMusic();
112  void playSfxMusic(int num);
113  void stopSfxMusic();
114  void stopAll();
115  void preloadSoundAiff(byte num, const byte *data);
116  void playSoundAiff(byte channel, byte num, byte volume);
117 };
118 #endif
119 
120 } // namespace Awe
121 
122 #endif
virtual bool endOfData() const override
Definition: sound.h:46
virtual int getRate() const override
Definition: sound.h:45
Definition: sound.h:34
Definition: aifc_player.h:31
Definition: sound.h:57
Definition: mixer.h:49
Definition: mixer.h:70
bool isStereo() const override
Definition: sound.h:41
Definition: audiostream.h:50
Definition: aifc_player.h:29
int readBuffer(int16 *buffer, const int numSamples) override
Definition: sound.h:48
Definition: sfx_player.h:70