1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2010 Matt RAYKOWSKI (sfb) <matt.raykowski@gmail.com>
6 // Copyright (C) 2012-2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "nel/sound/sound.h"
24 #include "nel/misc/path.h"
25 #include "nel/sound/sound_bank.h"
27 #include "nel/sound/simple_sound.h"
28 #include "nel/sound/complex_sound.h"
29 #include "nel/sound/background_sound.h"
30 #include "nel/sound/context_sound.h"
31 #include "nel/sound/music_sound.h"
32 #include "nel/sound/stream_sound.h"
33 #include "nel/sound/stream_file_sound.h"
35 #include "nel/sound/group_controller.h"
36 #include "nel/sound/group_controller_root.h"
39 using namespace NLMISC
;
44 CSound
*CSound::createSound(const std::string
&filename
, NLGEORGES::UFormElm
& formRoot
)
49 NLGEORGES::UFormElm
*psoundType
;
51 if (!formRoot
.getNodeByName(&psoundType
, ".SoundType"))
53 nlwarning("No SoundType in : %s", filename
.c_str());
57 if (psoundType
!= NULL
)
60 psoundType
->getDfnName(dfnName
);
62 if (dfnName
== "simple_sound.dfn")
64 ret
= new CSimpleSound();
65 ret
->importForm(filename
, formRoot
);
67 else if (dfnName
== "complex_sound.dfn")
69 ret
= new CComplexSound();
70 ret
->importForm(filename
, formRoot
);
72 else if (dfnName
== "background_sound.dfn")
74 ret
= new CBackgroundSound();
75 ret
->importForm(filename
, formRoot
);
77 else if (dfnName
== "context_sound.dfn")
79 ret
= new CContextSound();
80 ret
->importForm(filename
, formRoot
);
82 else if (dfnName
== "music_sound.dfn")
84 ret
= new CMusicSound();
85 ret
->importForm(filename
, formRoot
);
87 else if (dfnName
== "stream_sound.dfn")
89 ret
= new CStreamSound();
90 ret
->importForm(filename
, formRoot
);
92 else if (dfnName
== "stream_file_sound.dfn")
94 ret
= new CStreamFileSound();
95 ret
->importForm(filename
, formRoot
);
99 nlassertex(false, ("SoundType unsupported: %s", dfnName
.c_str()));
116 _ConeInnerAngle(6.283185f
),
117 _ConeOuterAngle(6.283185f
),
118 _ConeOuterGain( 1.0f
),
121 _MaxDist(1000000.0f
),
122 _UserVarControler(CStringMapper::emptyId()),
123 _GroupController(NULL
)
131 void CSound::serial(NLMISC::IStream
&s
)
135 s
.serialEnum(_Priority
);
136 s
.serial(_ConeInnerAngle
, _ConeOuterAngle
, _ConeOuterGain
);
137 s
.serial(_Direction
);
144 _Name
= CStringMapper::map(name
);
148 std::string name
= CStringMapper::unmap(_Name
);
152 nlassert(CGroupControllerRoot::isInitialized()); // not sure
153 #if NLSOUND_SHEET_VERSION_BUILT < 2
154 if (s
.isReading()) _GroupController
= CGroupControllerRoot::getInstance()->getGroupController(NLSOUND_SHEET_V1_DEFAULT_SOUND_GROUP_CONTROLLER
);
158 std::string groupControllerPath
;
159 s
.serial(groupControllerPath
);
160 _GroupController
= CGroupControllerRoot::getInstance()->getGroupController(groupControllerPath
);
164 std::string groupControllerPath
= _GroupController
->getPath();
165 s
.serial(groupControllerPath
);
172 * Load the sound parameters from georges' form
174 void CSound::importForm(const std::string
& filename
, NLGEORGES::UFormElm
& root
)
177 _Name
= CStringMapper::map(CFile::getFilenameWithoutExtension(filename
));
181 root
.getValueByName(inner
, ".InternalConeAngle");
186 _ConeInnerAngle
= (float) (Pi
* inner
/ 180.0f
); // convert to radians
190 root
.getValueByName(outer
, ".ExternalConeAngle");
195 _ConeOuterAngle
= (float) (Pi
* outer
/ 180.0f
); // convert to radians
198 root
.getValueByName(_Looping
, ".Loop");
202 root
.getValueByName(gain
, ".Gain");
211 _Gain
= (float) pow(10.0, gain
/ 20.0); // convert dB to linear gain
214 root
.getValueByName(gain
, ".ExternalGain");
223 _ConeOuterGain
= (float) pow(10.0, gain
/ 20.0); // convert dB to linear gain
228 root
.getValueByName(x
, ".Direction.X");
229 root
.getValueByName(y
, ".Direction.Y");
230 root
.getValueByName(z
, ".Direction.Z");
231 _Direction
= CVector(x
, y
, z
);
236 root
.getValueByName(trans
, ".Transpose");
237 _Pitch
= (float) pow(Sqrt12_2
, trans
); // convert semi-tones to playback speed
241 root
.getValueByName(prio
, ".Priority");
254 _Priority
= HighestPri
;
260 nlassert(CGroupControllerRoot::isInitialized()); // not sure
261 #if NLSOUND_SHEET_VERSION_BUILT < 2
262 _GroupController
= CGroupControllerRoot::getInstance()->getGroupController(NLSOUND_SHEET_V1_DEFAULT_SOUND_GROUP_CONTROLLER
);
264 std::string groupControllerPath
;
265 root
.getValueByName(groupControllerPath
, ".GroupControllerPath");
266 _GroupController
= CGroupControllerRoot::getInstance()->getGroupController(groupControllerPath
);