2012-04-13 21:54:08 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SOUNDMANAGER_H
|
|
|
|
#define SOUNDMANAGER_H
|
|
|
|
|
|
|
|
#include "declarations.h"
|
|
|
|
|
2012-06-22 05:14:13 +02:00
|
|
|
//@bindsingleton g_sounds
|
2012-04-13 21:54:08 +02:00
|
|
|
class SoundManager
|
|
|
|
{
|
|
|
|
enum {
|
2012-04-14 11:53:32 +02:00
|
|
|
MAX_CACHE_SIZE = 100000,
|
2012-04-14 16:19:58 +02:00
|
|
|
POLL_DELAY = 100
|
2012-04-13 21:54:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
void init();
|
|
|
|
void terminate();
|
2012-04-14 11:53:32 +02:00
|
|
|
void poll();
|
2012-04-13 21:54:08 +02:00
|
|
|
|
2012-07-18 10:34:17 +02:00
|
|
|
void preload(std::string filename);
|
2012-04-13 21:54:08 +02:00
|
|
|
void enableSound(bool enable);
|
2012-07-18 10:34:17 +02:00
|
|
|
void play(std::string filename);
|
2012-04-13 21:54:08 +02:00
|
|
|
|
|
|
|
void enableMusic(bool enable);
|
2012-07-18 10:34:17 +02:00
|
|
|
void playMusic(std::string filename, float fadetime);
|
2012-04-13 21:54:08 +02:00
|
|
|
void stopMusic(float fadetime = 0);
|
|
|
|
|
|
|
|
bool isMusicEnabled() { return m_musicEnabled; }
|
|
|
|
bool isSoundEnabled() { return m_soundEnabled; }
|
|
|
|
bool isAudioEnabled() { return m_device && m_context; }
|
|
|
|
std::string getCurrentMusic() { return m_currentMusic; }
|
|
|
|
|
|
|
|
private:
|
2012-04-14 16:19:58 +02:00
|
|
|
StreamSoundSourcePtr createStreamSoundSource(const std::string& filename);
|
2012-04-13 21:54:08 +02:00
|
|
|
SoundSourcePtr createSoundSource(const std::string& filename);
|
2012-06-22 05:14:13 +02:00
|
|
|
uint loadFileIntoBuffer(const SoundFilePtr& soundFile);
|
2012-04-13 21:54:08 +02:00
|
|
|
|
2012-07-26 08:10:28 +02:00
|
|
|
std::unordered_map<std::string, SoundBufferPtr> m_buffers;
|
2012-04-13 21:54:08 +02:00
|
|
|
std::vector<SoundSourcePtr> m_sources;
|
2012-04-14 16:19:58 +02:00
|
|
|
SoundSourcePtr m_musicSource;
|
2012-04-13 21:54:08 +02:00
|
|
|
ALCdevice *m_device;
|
|
|
|
ALCcontext *m_context;
|
2012-07-31 02:47:21 +02:00
|
|
|
stdext::boolean<false> m_musicEnabled;
|
|
|
|
stdext::boolean<false> m_soundEnabled;
|
2012-04-13 21:54:08 +02:00
|
|
|
std::string m_currentMusic;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern SoundManager g_sounds;
|
|
|
|
|
|
|
|
#endif
|