Otclient  14/8/2020
soundmanager.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 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 #ifndef SOUNDMANAGER_H
24 #define SOUNDMANAGER_H
25 
26 #include "declarations.h"
27 #include "soundchannel.h"
28 
29 //@bindsingleton g_sounds
31 {
32  enum {
33  MAX_CACHE_SIZE = 100000,
34  POLL_DELAY = 100
35  };
36 public:
37  void init();
38  void terminate();
39  void poll();
40 
41  void setAudioEnabled(bool enable);
42  bool isAudioEnabled() { return m_device && m_context && m_audioEnabled ; }
43  void enableAudio() { setAudioEnabled(true); }
44  void disableAudio() { setAudioEnabled(true); }
45  void stopAll();
46 
47  void preload(std::string filename);
48  SoundSourcePtr play(std::string filename, float fadetime = 0, float gain = 0);
49  SoundChannelPtr getChannel(int channel);
50 
51  std::string resolveSoundFile(std::string file);
52  void ensureContext();
53 
54 private:
55  SoundSourcePtr createSoundSource(const std::string& filename);
56 
57  ALCdevice *m_device;
58  ALCcontext *m_context;
59 
60  std::map<StreamSoundSourcePtr, boost::shared_future<SoundFilePtr>> m_streamFiles;
61  std::unordered_map<std::string, SoundBufferPtr> m_buffers;
62  std::vector<SoundSourcePtr> m_sources;
63  stdext::boolean<true> m_audioEnabled;
64  std::unordered_map<int, SoundChannelPtr> m_channels;
65 };
66 
67 extern SoundManager g_sounds;
68 
69 #endif
SoundManager::stopAll
void stopAll()
Definition: soundmanager.cpp:208
SoundManager::isAudioEnabled
bool isAudioEnabled()
Definition: soundmanager.h:42
SoundManager::preload
void preload(std::string filename)
Definition: soundmanager.cpp:149
SoundManager::resolveSoundFile
std::string resolveSoundFile(std::string file)
Definition: soundmanager.cpp:288
SoundManager::getChannel
SoundChannelPtr getChannel(int channel)
Definition: soundmanager.cpp:200
stdext::boolean< true >
SoundManager::disableAudio
void disableAudio()
Definition: soundmanager.h:44
soundchannel.h
SoundManager::ensureContext
void ensureContext()
Definition: soundmanager.cpp:295
SoundManager
Definition: soundmanager.h:30
SoundManager::play
SoundSourcePtr play(std::string filename, float fadetime=0, float gain=0)
Definition: soundmanager.cpp:169
SoundManager::init
void init()
Definition: soundmanager.cpp:38
declarations.h
SoundManager::poll
void poll()
Definition: soundmanager.cpp:87
SoundManager::enableAudio
void enableAudio()
Definition: soundmanager.h:43
stdext::shared_object_ptr< SoundSource >
SoundManager::terminate
void terminate()
Definition: soundmanager.cpp:58
SoundManager::setAudioEnabled
void setAudioEnabled(bool enable)
Definition: soundmanager.cpp:135
g_sounds
SoundManager g_sounds
Definition: soundmanager.cpp:36