00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "stdsound.h"
00026
00027 #include "background_sound.h"
00028 #include "nel/misc/path.h"
00029 #include <numeric>
00030
00031
00032
00033
00034
00035
00036 using namespace std;
00037 using namespace NLMISC;
00038
00039
00040 namespace NLSOUND {
00041
00042 CBackgroundSound::CBackgroundSound()
00043 : _Duration(0), _DurationValid(false)
00044 {
00045 }
00046
00047 CBackgroundSound::~CBackgroundSound()
00048 {
00049 }
00050
00051 void CBackgroundSound::serial(NLMISC::IStream &s)
00052 {
00053 CSound::serial(s);
00054
00055 s.serialCont(_Sounds);
00056
00057 if (s.isReading())
00058 _DurationValid = false;
00059 }
00060
00061 void CBackgroundSound::importForm(const std::string& filename, NLGEORGES::UFormElm& formRoot)
00062 {
00063 NLGEORGES::UFormElm *psoundType;
00064 std::string dfnName;
00065
00066
00067 formRoot.getNodeByName(&psoundType, ".SoundType");
00068 nlassert(psoundType != NULL);
00069 psoundType->getDfnName(dfnName);
00070 nlassert(dfnName == "background_sound.dfn");
00071
00072
00073 CSound::importForm(filename, formRoot);
00074
00075
00076 {
00077 _Sounds.clear();
00078
00079 NLGEORGES::UFormElm *psoundList;
00080
00081 formRoot.getNodeByName(&psoundList, ".SoundType.Sounds");
00082
00083 if (psoundList != 0 && psoundList->isArray())
00084 {
00085 uint size;
00086 psoundList->getArraySize(size);
00087
00088 for (uint i=0; i<size; ++i)
00089 {
00090 TSoundInfo sound;
00091 NLGEORGES::UFormElm *psoundItem;
00092
00093 psoundList->getArrayNode(&psoundItem, i);
00094
00095 if (psoundItem != NULL)
00096 {
00097
00098 psoundItem->getValueByName(sound.SoundName, "Sound");
00099 sound.SoundName = CFile::getFilenameWithoutExtension(sound.SoundName);
00100
00101 psoundItem->getValueByName(sound.FilterFadeIn, "FilterFadeIn");
00102 psoundItem->getValueByName(sound.FilterFadeOut, "FilterFadeOut");
00103
00104
00105
00106 for (uint j=0; j<16; j++)
00107 {
00108 char tmp[200];
00109 sprintf(tmp, "Filter%2.2u", j);
00110 psoundItem->getValueByName(sound.Filter.Flags[j], tmp);
00111 }
00112 }
00113
00114 _Sounds.push_back(sound);
00115 }
00116 }
00117 }
00118
00119 _DurationValid = false;
00120 }
00121
00122 uint32 CBackgroundSound::getDuration()
00123 {
00124 if (_DurationValid)
00125 return _Duration;
00126
00127 vector<sint32> durations;
00128 CAudioMixerUser *mixer = CAudioMixerUser::instance();
00129 std::vector<TSoundInfo>::const_iterator first(_Sounds.begin()), last(_Sounds.end());
00130 for (; first != last; ++first)
00131 {
00132 CSound *sound = mixer->getSoundId(first->SoundName);
00133 if (sound != NULL)
00134 durations.push_back(sound->getDuration());
00135 }
00136 if (durations.empty())
00137 return 0;
00138 _Duration = *(std::max_element(durations.begin(), durations.end()));
00139 _DurationValid = true;
00140
00141 return _Duration;
00142 }
00143
00144 void CBackgroundSound::getSubSoundList(std::vector<std::pair<std::string, CSound*> > &subsounds) const
00145 {
00146 CAudioMixerUser *mixer = CAudioMixerUser::instance();
00147 std::vector<TSoundInfo>::const_iterator first(_Sounds.begin()), last(_Sounds.end());
00148 for (; first != last; ++first)
00149 {
00150 CSound *sound = mixer->getSoundId(first->SoundName);
00151 subsounds.push_back(make_pair(first->SoundName, sound));
00152 }
00153 }
00154
00155 float CBackgroundSound::getMaxDistance() const
00156 {
00157 CAudioMixerUser *mixer = CAudioMixerUser::instance();
00158 float ret = 0.0f;
00159 std::vector<TSoundInfo>::const_iterator first(_Sounds.begin()), last(_Sounds.end());
00160 for (; first != last; ++first)
00161 {
00162 CSound *sound = mixer->getSoundId(first->SoundName);
00163 if (sound != 0)
00164 {
00165 ret = max(ret, sound->getMaxDistance());
00166 }
00167 }
00168 if (ret == 0)
00169 ret = 1;
00170
00171 return ret;
00172 }
00173
00174
00175
00176 }