soundmanager.h

main 73 lines · 2.4 KB Raw
Alex Alex Commit Client Upload Part 2 19/10/2026 00:06
1/*
2 * Copyright (c) 2010-2017 OTClient <https://github.com/edubart/otclient>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#ifdef FW_SOUND
24
25#ifndef SOUNDMANAGER_H
26#define SOUNDMANAGER_H
27
28#include "declarations.h"
29#include "soundchannel.h"
30
31//@bindsingleton g_sounds
32class SoundManager
33{
34 enum {
35 MAX_CACHE_SIZE = 100000,
36 POLL_DELAY = 100
37 };
38public:
39 void init();
40 void terminate();
41 void poll();
42
43 void setAudioEnabled(bool enable);
44 bool isAudioEnabled() { return m_device && m_context && m_audioEnabled ; }
45 void enableAudio() { setAudioEnabled(true); }
46 void disableAudio() { setAudioEnabled(true); }
47 void stopAll();
48
49 void preload(std::string filename);
50 SoundSourcePtr play(std::string filename, float fadetime = 0, float gain = 0);
51 SoundChannelPtr getChannel(int channel);
52
53 std::string resolveSoundFile(std::string file);
54 void ensureContext();
55
56private:
57 SoundSourcePtr createSoundSource(const std::string& filename);
58
59 ALCdevice *m_device;
60 ALCcontext *m_context;
61
62 std::map<StreamSoundSourcePtr, std::shared_future<SoundFilePtr>> m_streamFiles;
63 std::unordered_map<std::string, SoundBufferPtr> m_buffers;
64 std::vector<SoundSourcePtr> m_sources;
65 stdext::boolean<true> m_audioEnabled;
66 std::unordered_map<int, SoundChannelPtr> m_channels;
67};
68
69extern SoundManager g_sounds;
70
71#endif
72
73#endif
Top