ScummVM API documentation
audio.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  * This file is dual-licensed.
22  * In addition to the GPLv3 license mentioned above, MojoTouch has
23  * exclusively licensed this code on March 23th, 2024, to be used in
24  * closed-source products.
25  * Therefore, any contributions (commits) to it will also be dual-licensed.
26  *
27  */
28 
29 #ifndef TOON_AUDIO_H
30 #define TOON_AUDIO_H
31 
32 #include "audio/audiostream.h"
33 #include "audio/mixer.h"
34 #include "toon/toon.h"
35 
36 namespace Toon {
37 
38 // used for music/voice/everything
39 class AudioManager;
41 
42 public:
43  AudioStreamInstance(AudioManager *man, Audio::Mixer *mixer, Common::SeekableReadStream *stream, bool looping = false, bool deleteFileStreamAtEnd = false);
44  ~AudioStreamInstance() override;
45  void play(bool fade = false, Audio::Mixer::SoundType soundType = Audio::Mixer::kMusicSoundType);
46  void stop(bool fade = false);
47 
48  bool isPlaying() {
49  return !_stopped;
50  }
51  bool isLooping() {
52  return _looping;
53  }
54  bool isFading() {
55  return _fadingIn || _fadingOut;
56  }
57 
58  int32 getPlayedSampleCount() {
59  return _playedSamples;
60  }
61 
62  void setVolume(int32 volume);
63 protected:
64  int readBuffer(int16 *buffer, const int numSamples) override;
65  bool isStereo() const override {
66  return false;
67  }
68  int getRate() const override {
69  return 22100;
70  }
71  bool endOfData() const override {
72  return _stopped;
73  }
74  void handleFade(int32 numSamples);
75  void stopNow();
76 
77  bool readPacket();
78  void decodeADPCM(uint8 *comp, int16 *dest, int32 packetSize);
79 
81  bool _fadingIn;
82  bool _fadingOut;
83  int32 _fadeTime;
84  uint8 *_compBuffer;
85  int16 *_buffer;
86  int32 _bufferSize;
87  int32 _bufferMaxSize;
88  int32 _bufferOffset;
89  int32 _compBufferSize;
90  Audio::SoundHandle _handle;
91  Audio::Mixer::SoundType _soundType;
92  Audio::Mixer *_mixer;
93  int32 _lastSample;
94  int32 _lastStepIndex;
95  bool _stopped;
96  AudioManager *_man;
97  int32 _totalSize;
98  int32 _currentReadSize;
99  bool _looping;
100  int32 _volume;
101  int32 _musicAttenuation;
102  bool _deleteFileStream;
103  int32 _playedSamples;
104 };
105 
107 
108 public:
111 
112  bool loadAudioPackage(const Common::Path &indexFile, const Common::Path &streamFile);
113  void getInfo(int32 id, int32 *offset, int32 *size);
114  Common::SeekableReadStream *getStream(int32 id, bool ownMemory = false);
115 protected:
117  uint32 *_indexBuffer;
118  ToonEngine *_vm;
119 };
120 
122  int32 _id;
123  int32 _volume;
124  int32 _lastTimer;
125  int32 _delay;
126  int32 _mode;
127  int32 _channel;
128  bool _enabled;
129 };
130 
132 public:
133  void removeInstance(AudioStreamInstance *inst); // called by destructor
134 
135  AudioManager(ToonEngine *vm, Audio::Mixer *mixer);
136  ~AudioManager();
137 
138  bool voiceStillPlaying();
139 
140  int playMusic(const Common::String &dir, const Common::String &music);
141  void playVoice(int32 id, bool genericVoice);
142  int32 playSFX(int32 id, int volume, bool genericSFX);
143  void stopCurrentVoice();
144  void stopAllSfxs();
145  void setMusicVolume(uint8 volume);
146  void stopMusicChannel(int channelId, bool fade);
147  void stopMusic(bool fade = true);
148  void muteVoice(bool mute);
149  void muteMusic(bool mute);
150  void muteSfx(bool mute);
151  bool isVoiceMuted() const { return _voiceMuted; }
152  bool isMusicMuted() const { return _musicMuted; }
153  bool isSfxMuted() const { return _sfxMuted; }
154 
155  void startAmbientSFX(int32 id, int32 delay, int32 mode, int32 volume);
156  void killAmbientSFX(int32 id);
157  void killAllAmbientSFX();
158  void updateAmbientSFX();
159  void setAmbientSFXVolume(int32 id, int volume);
160 
161  void closeAudioPack(int32 id);
162  bool loadAudioPack(int32 id, const Common::Path &indexFile, const Common::Path &packFile);
163 
164  AudioStreamInstance *_channels[16]; // 0-1 : music
165  // 2 : voice
166  // 3-15 : SFX
167 
168  AudioStreamPackage *_audioPacks[4]; // 0 : generic streams
169  // 1 : local streams
170  // 2 : generic SFX
171  // 3 : local SFX
172 
173  int _currentMusicChannel;
174  Common::String _currentMusicName;
175  ToonEngine *_vm;
176  Audio::Mixer *_mixer;
177 
178 protected:
179  bool _voiceMuted;
180  bool _musicMuted;
181  bool _sfxMuted;
182 
183  AudioAmbientSFX _ambientSFXs[4];
184 };
185 
186 } // End of namespace Toon
187 
188 #endif
Definition: mixer.h:65
Definition: str.h:59
bool endOfData() const override
Definition: audio.h:71
Definition: path.h:52
Definition: stream.h:745
Definition: audio.h:121
int readBuffer(int16 *buffer, const int numSamples) override
int getRate() const override
Definition: audio.h:68
Definition: toon.h:118
Definition: mixer.h:49
SoundType
Definition: mixer.h:62
Definition: mixer.h:59
Definition: audio.h:40
Definition: audio.h:106
Definition: audiostream.h:50
Definition: audio.h:131
Definition: anim.h:39
bool isStereo() const override
Definition: audio.h:65