2013-05-22 23:40:56 +02:00
|
|
|
/* Copyright (C) 2013 Wildfire Games.
|
2012-08-15 02:10:44 +02:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INCLUDED_SOUNDMANAGER_H
|
|
|
|
#define INCLUDED_SOUNDMANAGER_H
|
|
|
|
|
2012-08-31 21:08:41 +02:00
|
|
|
#include "lib/config2.h"
|
|
|
|
|
|
|
|
#if CONFIG2_AUDIO
|
|
|
|
|
2013-06-06 13:13:57 +02:00
|
|
|
#include "lib/external_libraries/openal.h"
|
|
|
|
|
|
|
|
|
2012-08-15 02:10:44 +02:00
|
|
|
#include "lib/file/vfs/vfs_path.h"
|
2013-06-06 13:13:57 +02:00
|
|
|
#include "soundmanager/ISoundManager.h"
|
2012-08-31 21:08:41 +02:00
|
|
|
#include "soundmanager/items/ISoundItem.h"
|
2013-03-01 15:22:28 +01:00
|
|
|
#include "simulation2/system/Entity.h"
|
|
|
|
#include "soundmanager/data/SoundData.h"
|
|
|
|
#include "soundmanager/items/ISoundItem.h"
|
2013-06-13 14:12:44 +02:00
|
|
|
#include "soundmanager/scripting/SoundGroup.h"
|
2013-03-01 15:22:28 +01:00
|
|
|
#include "ps/Profiler2.h"
|
2012-08-15 02:10:44 +02:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
|
|
|
|
2012-08-31 21:08:41 +02:00
|
|
|
#define AL_CHECK CSoundManager::al_check(__func__, __LINE__);
|
|
|
|
|
2013-03-01 15:22:28 +01:00
|
|
|
struct ALSourceHolder
|
|
|
|
{
|
|
|
|
/// Title of the column
|
|
|
|
ALuint ALSource;
|
|
|
|
ISoundItem* SourceItem;
|
|
|
|
};
|
|
|
|
|
2013-06-06 13:13:57 +02:00
|
|
|
typedef std::vector<VfsPath> PlayList;
|
|
|
|
typedef std::vector<ISoundItem*> ItemsList;
|
|
|
|
typedef std::map<entity_id_t, ISoundItem*> ItemsMap;
|
2013-06-13 14:12:44 +02:00
|
|
|
typedef std::map<std::wstring, CSoundGroup*> SoundGroupMap;
|
2013-06-06 13:13:57 +02:00
|
|
|
|
|
|
|
class CSoundManagerWorker;
|
|
|
|
|
|
|
|
|
|
|
|
class CSoundManager : public ISoundManager
|
2012-08-15 02:10:44 +02:00
|
|
|
{
|
2013-05-22 23:40:56 +02:00
|
|
|
NONCOPYABLE(CSoundManager);
|
|
|
|
|
2012-08-15 02:10:44 +02:00
|
|
|
protected:
|
|
|
|
|
|
|
|
ALuint m_ALEnvironment;
|
|
|
|
ALCcontext* m_Context;
|
|
|
|
ALCdevice* m_Device;
|
|
|
|
ISoundItem* m_CurrentTune;
|
|
|
|
ISoundItem* m_CurrentEnvirons;
|
2012-09-27 04:42:03 +02:00
|
|
|
CSoundManagerWorker* m_Worker;
|
2013-03-01 15:22:28 +01:00
|
|
|
CMutex m_DistressMutex;
|
2013-04-24 14:03:42 +02:00
|
|
|
PlayList* m_PlayListItems;
|
2013-06-13 14:12:44 +02:00
|
|
|
SoundGroupMap m_SoundGroups;
|
2013-03-01 15:22:28 +01:00
|
|
|
|
2012-08-15 02:10:44 +02:00
|
|
|
float m_Gain;
|
|
|
|
float m_MusicGain;
|
|
|
|
float m_AmbientGain;
|
|
|
|
float m_ActionGain;
|
2013-06-10 15:58:43 +02:00
|
|
|
float m_UIGain;
|
2012-08-15 02:10:44 +02:00
|
|
|
bool m_Enabled;
|
|
|
|
long m_BufferSize;
|
|
|
|
int m_BufferCount;
|
|
|
|
bool m_MusicEnabled;
|
2012-08-31 21:08:41 +02:00
|
|
|
bool m_SoundEnabled;
|
2012-08-15 02:10:44 +02:00
|
|
|
|
2013-04-07 06:13:15 +02:00
|
|
|
bool m_MusicPaused;
|
|
|
|
bool m_AmbientPaused;
|
|
|
|
bool m_ActionPaused;
|
2013-04-24 14:03:42 +02:00
|
|
|
bool m_RunningPlaylist;
|
2014-02-20 23:45:43 +01:00
|
|
|
bool m_PlayingPlaylist;
|
|
|
|
bool m_LoopingPlaylist;
|
2013-04-07 06:13:15 +02:00
|
|
|
|
2013-04-24 14:03:42 +02:00
|
|
|
long m_PlaylistGap;
|
2013-03-01 15:22:28 +01:00
|
|
|
long m_DistressErrCount;
|
|
|
|
long m_DistressTime;
|
|
|
|
|
|
|
|
ALSourceHolder* m_ALSourceBuffer;
|
|
|
|
|
2012-08-15 02:10:44 +02:00
|
|
|
public:
|
|
|
|
CSoundManager();
|
|
|
|
virtual ~CSoundManager();
|
|
|
|
|
2012-08-16 03:41:45 +02:00
|
|
|
ISoundItem* LoadItem(const VfsPath& itemPath);
|
2013-03-01 15:22:28 +01:00
|
|
|
ISoundItem* ItemForData(CSoundData* itemData);
|
|
|
|
ISoundItem* ItemForEntity( entity_id_t source, CSoundData* sndData);
|
2012-08-15 02:10:44 +02:00
|
|
|
|
2013-09-10 16:17:04 +02:00
|
|
|
Status ReloadChangedFiles(const VfsPath& path);
|
|
|
|
|
2013-04-24 14:03:42 +02:00
|
|
|
void ClearPlayListItems();
|
|
|
|
void StartPlayList( bool doLoop );
|
2013-09-30 03:09:16 +02:00
|
|
|
void AddPlayListItem(const VfsPath& itemPath);
|
2013-04-24 14:03:42 +02:00
|
|
|
|
2012-08-31 21:08:41 +02:00
|
|
|
static void CreateSoundManager();
|
|
|
|
static void SetEnabled(bool doEnable);
|
2013-09-10 16:17:04 +02:00
|
|
|
static Status ReloadChangedFileCB(void* param, const VfsPath& path);
|
|
|
|
|
2013-08-29 15:20:55 +02:00
|
|
|
static void CloseGame();
|
|
|
|
|
2012-08-31 21:08:41 +02:00
|
|
|
static void al_ReportError(ALenum err, const char* caller, int line);
|
|
|
|
static void al_check(const char* caller, int line);
|
2012-08-15 02:10:44 +02:00
|
|
|
|
|
|
|
void SetMusicEnabled (bool isEnabled);
|
2012-08-31 21:08:41 +02:00
|
|
|
void setSoundEnabled( bool enabled );
|
2012-08-15 02:10:44 +02:00
|
|
|
|
2013-03-01 15:22:28 +01:00
|
|
|
ALuint GetALSource(ISoundItem* anItem);
|
|
|
|
void ReleaseALSource(ALuint theSource);
|
|
|
|
ISoundItem* ItemFromData(CSoundData* itemData);
|
|
|
|
|
2012-08-15 02:10:44 +02:00
|
|
|
ISoundItem* ItemFromWAV(VfsPath& fname);
|
|
|
|
ISoundItem* ItemFromOgg(VfsPath& fname);
|
|
|
|
|
|
|
|
ISoundItem* GetSoundItem(unsigned long itemRow);
|
|
|
|
unsigned long Count();
|
|
|
|
void IdleTask();
|
|
|
|
|
|
|
|
void SetMemoryUsage(long bufferSize, int bufferCount);
|
|
|
|
long GetBufferCount();
|
|
|
|
long GetBufferSize();
|
|
|
|
|
2014-02-20 23:45:43 +01:00
|
|
|
void PlayAsMusic( const VfsPath& itemPath, bool looping);
|
|
|
|
void PlayAsAmbient( const VfsPath& itemPath, bool looping);
|
2013-06-10 15:58:43 +02:00
|
|
|
void PlayAsUI(const VfsPath& itemPath, bool looping);
|
2013-06-17 04:30:40 +02:00
|
|
|
void PlayAsGroup(const VfsPath& groupPath, CVector3D sourcePos, entity_id_t source, bool ownedSound);
|
2013-06-10 15:58:43 +02:00
|
|
|
|
2012-08-15 02:10:44 +02:00
|
|
|
void PlayGroupItem(ISoundItem* anItem, ALfloat groupGain);
|
|
|
|
|
2013-03-01 15:22:28 +01:00
|
|
|
bool InDistress();
|
|
|
|
void SetDistressThroughShortage();
|
|
|
|
void SetDistressThroughError();
|
|
|
|
|
2013-04-18 05:24:20 +02:00
|
|
|
void Pause(bool pauseIt);
|
|
|
|
void PauseMusic (bool pauseIt);
|
|
|
|
void PauseAmbient (bool pauseIt);
|
|
|
|
void PauseAction (bool pauseIt);
|
2013-08-29 15:20:55 +02:00
|
|
|
void SetAmbientItem(ISoundItem* anItem);
|
2013-04-07 06:13:15 +02:00
|
|
|
|
2013-06-10 15:58:43 +02:00
|
|
|
void SetMasterGain(float gain);
|
|
|
|
void SetMusicGain(float gain);
|
|
|
|
void SetAmbientGain(float gain);
|
|
|
|
void SetActionGain(float gain);
|
|
|
|
void SetUIGain(float gain);
|
2012-08-15 02:10:44 +02:00
|
|
|
|
2014-02-20 23:45:43 +01:00
|
|
|
protected:
|
|
|
|
void InitListener();
|
|
|
|
Status AlcInit();
|
|
|
|
void SetMusicItem(ISoundItem* anItem);
|
|
|
|
|
2013-04-12 05:10:54 +02:00
|
|
|
private:
|
|
|
|
CSoundManager(CSoundManager* UNUSED(other)){};
|
2012-08-15 02:10:44 +02:00
|
|
|
};
|
|
|
|
|
2012-08-31 21:08:41 +02:00
|
|
|
#else // !CONFIG2_AUDIO
|
2012-08-15 02:10:44 +02:00
|
|
|
|
2012-08-31 21:08:41 +02:00
|
|
|
#define AL_CHECK
|
|
|
|
|
|
|
|
#endif // !CONFIG2_AUDIO
|
|
|
|
|
2012-08-15 02:10:44 +02:00
|
|
|
#endif // INCLUDED_SOUNDMANAGER_H
|
2012-08-31 21:08:41 +02:00
|
|
|
|