ScummVM API documentation
sounds.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 ALCACHOFA_SOUNDS_H
23#define ALCACHOFA_SOUNDS_H
24
25#include "alcachofa/scheduler.h"
26#include "audio/mixer.h"
27#include "audio/audiostream.h"
28
29namespace Alcachofa {
30
31class Character;
32using ::Audio::SoundHandle;
33
34class Sounds {
35public:
36 Sounds();
37 ~Sounds();
38
39 void update();
40 SoundHandle playVoice(const Common::String &fileName, byte volume = Audio::Mixer::kMaxChannelVolume);
41 SoundHandle playSFX(const Common::String &fileName, byte volume = Audio::Mixer::kMaxChannelVolume);
42 void stopAll();
43 void stopVoice();
44 void pauseAll(bool paused);
45 void fadeOut(SoundHandle id, uint32 duration);
46 void fadeOutVoiceAndSFX(uint32 duration);
47 bool isAlive(SoundHandle id);
48 void setVolume(SoundHandle id, byte volume);
49 void setAppropriateVolume(SoundHandle id,
50 MainCharacterKind processCharacter,
51 Character *speakingCharacter);
52 bool isNoisy(SoundHandle id, float windowSize, float minDifferences);
53
54 void startMusic(int musicId);
55 void queueMusic(int musicId);
56 void fadeMusic(uint32 duration = 500);
57 void setMusicToRoom(int roomMusicId);
58 Task *waitForMusicToEnd(Process &processd);
59 inline bool isMusicPlaying() const { return _isMusicPlaying; }
60 inline int musicID() const { return _nextMusicID; }
61 inline FakeSemaphore &musicSemaphore() { return _musicSemaphore; }
62
63private:
64 struct Playback {
65 void fadeOut(uint32 duration);
66
67 Audio::SoundHandle _handle;
68 Audio::Mixer::SoundType _type = Audio::Mixer::SoundType::kPlainSoundType;
69 uint32 _fadeStart = 0,
70 _fadeDuration = 0;
71 int _inputRate = 0;
72 Common::Array<int16> _samples;
73 };
74 Playback *getPlaybackById(SoundHandle id);
75 SoundHandle playSoundInternal(const Common::String &path, byte volume, Audio::Mixer::SoundType type);
76
77 Common::Array<Playback> _playbacks;
78 Audio::Mixer *_mixer;
79
80 SoundHandle _musicSoundID = {}; // we use another soundID to reuse fading
81 bool _isMusicPlaying = false;
82 int _nextMusicID = -1;
83 FakeSemaphore _musicSemaphore;
84};
85
86struct PlaySoundTask final : public Task {
87 PlaySoundTask(Process &process, SoundHandle soundHandle);
89 TaskReturn run() override;
90 void debugPrint() override;
91 const char *taskName() const override;
92private:
93 SoundHandle _soundHandle;
94};
95
96struct WaitForMusicTask final : public Task {
97 WaitForMusicTask(Process &process);
99 TaskReturn run() override;
100 void debugPrint() override;
101 const char *taskName() const override;
102private:
103 FakeLock _lock;
104};
105
106}
107
108#endif // ALCACHOFA_SOUNDS_H
Definition: objects.h:492
Definition: scheduler.h:164
Definition: sounds.h:34
bool isNoisy(SoundHandle id, float windowSize, float minDifferences)
used for lip-sync
Definition: mixer.h:70
@ kMaxChannelVolume
Definition: mixer.h:82
SoundType
Definition: mixer.h:73
Definition: mixer.h:49
Definition: serializer.h:80
Definition: str.h:59
Definition: common.h:107
Definition: sounds.h:86
Definition: scheduler.h:84
Definition: scheduler.h:60
Definition: sounds.h:96