Added aqua_speed for rite geo 50 tryker
[ryzomcore.git] / nel / tools / 3d / object_viewer / sound_system.cpp
blob22d4a374bffb11cf918c02dd78367cc1ebc22cc0
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
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 Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "std_afx.h"
21 #include "resource.h"
22 #include "sound_system.h"
23 #include "nel/sound/u_audio_mixer.h"
24 #include "nel/sound/u_listener.h"
25 #include "nel/sound/sound_anim_manager.h"
26 #include "nel/sound/sound_animation.h"
27 #include "nel/misc/path.h"
28 #include "edit_ps_sound.h"
30 using namespace std;
31 using namespace NLMISC;
32 using namespace NLSOUND;
35 UAudioMixer *CSoundSystem::_AudioMixer = NULL;
36 //set<string> CSoundSystem::_SoundBanksFileName;
37 set<string> CSoundSystem::_SampleBanksFileName;
38 CSoundAnimManager *CSoundSystem::_AnimManager = NULL;
39 //TSoundAnimId CSoundSystem::_CurrentAnimation = CSoundAnimation::NoId;
40 //sint32 CSoundSystem::_CurrentPlayback = -1;
41 CVector CSoundSystem::_Zero = CVector::Null;
42 string CSoundSystem::_SamplePath;
43 string CSoundSystem::_PackedSheetPath;
44 //sint CSoundSystem::_AnimIndex = -1;
46 void CSoundSystem::setListenerMatrix(const NLMISC::CMatrix &m)
48 if (_AudioMixer)
50 static CMatrix oldMatrix;
51 if(m.getPos() != oldMatrix.getPos() || m.getJ() != oldMatrix.getJ() || m.getK() != oldMatrix.getK())
53 UListener *l = _AudioMixer->getListener();
54 l->setPos(m.getPos());
55 l->setOrientation(m.getJ(), m.getK());
56 oldMatrix = m;
62 void CSoundSystem::initSoundSystem ()
64 _AudioMixer = NULL;
65 _AnimManager = NULL;
66 _AudioMixer = NLSOUND::UAudioMixer::createAudioMixer();
67 try
69 _AudioMixer->setSamplePath(_SamplePath);
70 _AudioMixer->setPackedSheetOption(_PackedSheetPath, true);
71 _AudioMixer->init(32, true, false, NULL, true);
73 catch(const NLMISC::Exception &e)
75 // in case of exeption during mixer init, the mixer is destroyed !
76 string mess = string("Unable to init sound :") + e.what();
77 nlwarning ("Init sound: %s", mess.c_str());
78 _AudioMixer = NULL;
79 return;
82 // ok for the mixer, now create the sound anim manager
83 try
85 // TODO : boris : Hum, as far as I know, throwing exeption in constructor is a very BAD idea...
86 _AnimManager = new CSoundAnimManager(_AudioMixer);
88 catch (const NLMISC::Exception &e)
90 string mess = string("Unable to init sound :") + e.what();
91 nlwarning ("Init sound: %s", mess.c_str());
92 if (_AnimManager)
94 delete _AnimManager;
95 _AnimManager = NULL;
98 delete _AudioMixer;
99 _AudioMixer = NULL;
101 return;
103 setPSSoundSystem(_AudioMixer);
106 for (set<string>::const_iterator it1 = _SampleBanksFileName.begin();
107 it1 != _SampleBanksFileName.end();
108 ++it1)
112 //_AudioMixer->loadSampleBank(NLMISC::CPath::lookup(*it).c_str());
113 _AudioMixer->loadSampleBank(false, (*it1));
115 catch (const NLMISC::Exception &e)
117 string mess = "Unable to load sound file :" + *it1
118 + "\n" + e.what();
119 nlwarning ("Init sound: %s", mess.c_str());
123 /* for (set<string>::const_iterator it2 = _SoundBanksFileName.begin();
124 it2 != _SoundBanksFileName.end();
125 ++it2)
129 //_AudioMixer->loadSoundBank(NLMISC::CPath::lookup(*it).c_str());
130 _AudioMixer->loadSoundBank((*it2).c_str());
132 catch (const NLMISC::Exception &e)
134 string mess = "Unable to load sound file :" + *it2
135 + "\n" + e.what();
136 nlwarning ("Init sound: %s", mess.c_str());
144 void CSoundSystem::poll()
146 if (_AudioMixer)
148 _AudioMixer->update();
154 void CSoundSystem::releaseSoundSystem(void)
156 setPSSoundSystem(NULL);
157 if (_AnimManager)
159 delete _AnimManager;
160 _AnimManager = NULL;
162 if (_AudioMixer)
164 delete _AudioMixer;
165 _AudioMixer = NULL;
170 void CSoundSystem::play(const string &soundName)
172 if (_AudioMixer)
174 NLSOUND::USource *src = _AudioMixer->createSource(CStringMapper::map(soundName), true);
175 if (src)
177 src->setLooping(false);
178 const CVector &pos = _AudioMixer->getListener()->getPos();
179 src->setPos(pos);
180 src->play();
182 else
184 MessageBox(NULL, _T("Can't play the sound (perhaps it's contextual sound)"), _T("warning"), MB_OK|MB_ICONWARNING );
189 USource *CSoundSystem::create(const std::string &soundName)
191 if (_AudioMixer)
193 NLSOUND::USource *src = _AudioMixer->createSource(CStringMapper::map(soundName), false);
194 if (src)
196 src->setLooping(false);
197 const CVector &pos = _AudioMixer->getListener()->getPos();
198 src->setPos(pos);
199 src->play();
200 return src;
202 else
204 MessageBox(NULL, _T("Can't play the sound (perhaps it's contextual sound)"), _T("warning"), MB_OK|MB_ICONWARNING );
205 } return NULL;
207 return NULL;
211 void CSoundSystem::playAnimation(string& name, float lastTime, float curTime, CSoundContext &context)
213 if (_AnimManager == NULL)
215 return;
218 TSoundAnimId id = _AnimManager->getAnimationFromName(name);
220 if (id != CSoundAnimationNoId)
222 _AnimManager->playAnimation(id, lastTime, curTime, NULL, context);