00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "stdsound.h"
00027
00028 #include "sound.h"
00029 #include "nel/misc/path.h"
00030 #include "sound_bank.h"
00031
00032 #include "simple_sound.h"
00033 #include "complex_sound.h"
00034 #include "context_sound.h"
00035
00036 using namespace std;
00037 using namespace NLMISC;
00038
00039
00040 namespace NLSOUND {
00041
00042 CSound *CSound::createSound(const std::string &filename, NLGEORGES::UFormElm& formRoot)
00043 {
00044 CSound *ret = NULL;
00045 string soundType;
00046
00047 NLGEORGES::UFormElm *psoundType;
00048
00049 if (!formRoot.getNodeByName(&psoundType, ".SoundType"))
00050 {
00051 nlwarning("No SoundType in : %s", filename.c_str());
00052 return 0;
00053 }
00054
00055 if (psoundType != NULL)
00056 {
00057 std::string dfnName;
00058 psoundType->getDfnName(dfnName);
00059
00060 if (dfnName == "simple_sound.dfn")
00061 {
00062 ret = new CSimpleSound();
00063 ret->importForm(filename, formRoot);
00064 }
00065 else if (dfnName == "complex_sound.dfn")
00066 {
00067 ret = new CComplexSound();
00068 ret->importForm(filename, formRoot);
00069 }
00070 else if (dfnName == "background_sound.dfn")
00071 {
00072 ret = new CBackgroundSound();
00073 ret->importForm(filename, formRoot);
00074 }
00075 else if (dfnName == "context_sound.dfn")
00076 {
00077 ret = new CContextSound();
00078 ret->importForm(filename, formRoot);
00079 }
00080 else
00081 {
00082 nlassertex(false, ("SoundType unsuported : %s", dfnName.c_str()));
00083 }
00084
00085 }
00086
00087 return ret;
00088 }
00089
00090
00091
00092
00093
00094
00095 CSound::CSound() :
00096 _Gain(1.0f),
00097 _Pitch(1.0f),
00098 _MaxDist(1000000.0f),
00099 _Priority(MidPri),
00100 _Looping(false),
00101 _ConeInnerAngle(6.283185f),
00102 _ConeOuterAngle(6.283185f),
00103 _ConeOuterGain( 1.0f )
00104 {
00105 }
00106
00107 CSound::~CSound()
00108 {}
00109
00110
00111 void CSound::serial(NLMISC::IStream &s)
00112 {
00113 s.serial(_Gain);
00114 s.serial(_Pitch);
00115 s.serialEnum(_Priority);
00116 s.serial(_ConeInnerAngle, _ConeOuterAngle, _ConeOuterGain);
00117 s.serial(_Direction);
00118 s.serial(_Looping);
00119 s.serial(_MaxDist);
00120 s.serial(_Name);
00121 }
00122
00123
00127 void CSound::importForm(const std::string& filename, NLGEORGES::UFormElm& root)
00128 {
00129
00130 _Name = CFile::getFilenameWithoutExtension(filename);
00131
00132
00133 uint32 inner;
00134 root.getValueByName(inner, ".InternalConeAngle");
00135 if (inner > 360)
00136 {
00137 inner = 360;
00138 }
00139 _ConeInnerAngle = (float) (Pi * inner / 180.0f);
00140
00141
00142 uint32 outer;
00143 root.getValueByName(outer, ".ExternalConeAngle");
00144 if (outer > 360)
00145 {
00146 outer = 360;
00147 }
00148 _ConeOuterAngle= (float) (Pi * outer / 180.0f);
00149
00150
00151 root.getValueByName(_Looping, ".Loop");
00152
00153
00154 sint32 gain;
00155 root.getValueByName(gain, ".Gain");
00156 if (gain > 0)
00157 {
00158 gain = 0;
00159 }
00160 if (gain < -100)
00161 {
00162 gain = -100;
00163 }
00164 _Gain = (float) pow(10.0, gain / 20.0);
00165
00166
00167 root.getValueByName(gain, ".ExternalGain");
00168 if (gain > 0)
00169 {
00170 gain = 0;
00171 }
00172 if (gain < -100)
00173 {
00174 gain = -100;
00175 }
00176 _ConeOuterGain = (float) pow(10.0, gain / 20.0);
00177
00178
00179 float x, y, z;
00180
00181 root.getValueByName(x, ".Direction.X");
00182 root.getValueByName(y, ".Direction.Y");
00183 root.getValueByName(z, ".Direction.Z");
00184 _Direction = CVector(x, y, z);
00185
00186
00187
00188 sint32 trans;
00189 root.getValueByName(trans, ".Transpose");
00190 _Pitch = (float) pow(Sqrt12_2, trans);
00191
00192
00193 uint32 prio = 0;
00194 root.getValueByName(prio, ".Priority");
00195 switch (prio)
00196 {
00197 case 0: _Priority = LowPri; break;
00198 default:
00199 case 1: _Priority = MidPri; break;
00200 case 2: _Priority = HighPri; break;
00201 case 3: _Priority = HighestPri; break;
00202 }
00203 }
00204
00205
00206
00207 }