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) 2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
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/>.
24 #include <nel/misc/types_nl.h>
29 #include <nel/misc/vector.h>
30 #include <nel/misc/command.h>
32 #include <nel/sound/u_audio_mixer.h>
33 #include <nel/sound/u_listener.h>
34 #include <nel/sound/u_source.h>
36 #include "snowballs_client.h"
39 #include "configuration.h"
46 using namespace NLMISC
;
47 using namespace NLSOUND
;
56 #ifdef SBCLIENT_WITH_SOUND
57 UAudioMixer
*AudioMixer
= NULL
;
59 //const vector<TSoundId> *SoundIdArray;
60 static bool SoundEnabled
;
67 #ifdef SBCLIENT_WITH_SOUND
72 void cbConfigFileSoundMaxTracks(NLMISC::CConfigFile::CVar
&var
)
75 AudioMixer
->changeMaxTrack(var
.asInt());
78 void cbConfigFileSoundEnabled(NLMISC::CConfigFile::CVar
&var
)
80 if (var
.asBool() != SoundEnabled
)
89 void cbConfigFileMusicVolume(NLMISC::CConfigFile::CVar
&var
)
92 AudioMixer
->setMusicVolume(var
.asFloat());
95 void cbConfigFileFail(NLMISC::CConfigFile::CVar
&var
)
97 nlwarning("You can't modify the config variable '%s' at runtime for now, please restart the game", var
.asString().c_str());
102 AudioMixer
= UAudioMixer::createAudioMixer();
103 std::string driverName
;
104 NLSOUND::UAudioMixer::TDriver driverType
;
105 if (!ConfigFile
->exists("SoundDriver"))
107 driverType
= NLSOUND::UAudioMixer::DriverFMod
;
108 #elif defined(NL_OS_UNIX)
109 driverType
= NLSOUND::UAudioMixer::DriverOpenAl
;
111 driverType
= NLSOUND::UAudioMixer::DriverAuto
;
115 driverName
= ConfigFile
->getVar("SoundDriver").asString();
116 if (driverName
== "Auto")
117 driverType
= NLSOUND::UAudioMixer::DriverAuto
;
118 else if (driverName
== "FMod")
119 driverType
= NLSOUND::UAudioMixer::DriverFMod
;
120 else if (driverName
== "DSound")
121 driverType
= NLSOUND::UAudioMixer::DriverDSound
;
122 else if (driverName
== "OpenAl")
123 driverType
= NLSOUND::UAudioMixer::DriverOpenAl
;
125 nlerror("SoundDriver value '%s' is invalid.", driverName
.c_str());
129 ConfigFile
->exists("SoundMaxTracks")
130 ? ConfigFile
->getVar("SoundMaxTracks").asInt()
132 ConfigFile
->exists("SoundUseEax")
133 ? ConfigFile
->getVar("SoundUseEax").asBool()
135 ConfigFile
->exists("SoundUseADPCM")
136 ? ConfigFile
->getVar("SoundUseADPCM").asBool()
138 NULL
, true, driverType
,
139 ConfigFile
->exists("SoundForceSoftware")
140 ? ConfigFile
->getVar("SoundForceSoftware").asBool()
143 ConfigFile
->setCallback("SoundMaxTracks", cbConfigFileSoundMaxTracks
);
144 ConfigFile
->setCallback("SoundUseEax", cbConfigFileFail
);
145 ConfigFile
->setCallback("SoundUseADPCM", cbConfigFileFail
);
146 ConfigFile
->setCallback("SoundForceSoftware", cbConfigFileFail
);
147 ConfigFile
->setCallback("SoundDriver", cbConfigFileFail
);
148 CConfiguration::setAndCallback("MusicVolume", cbConfigFileMusicVolume
);
150 // PlaylistManager = new SBCLIENT::CMusicPlaylistManager(AudioMixer, ConfigFile, "SoundPlaylist");
152 /* AudioMixer->loadSoundBuffers ("sounds.nss", &SoundIdArray);
153 nlassert( SoundIdArray->size() == 2 );
154 SoundId = (*SoundIdArray)[0];
155 // StSoundId = (*SoundIdArray)[1]; */
162 SoundEnabled
= false;
163 ConfigFile
->setCallback("SoundMaxTracks", NULL
);
164 ConfigFile
->setCallback("SoundUseEax", NULL
);
165 ConfigFile
->setCallback("SoundUseADPCM", NULL
);
166 ConfigFile
->setCallback("SoundForceSoftware", NULL
);
167 ConfigFile
->setCallback("SoundDriver", NULL
);
168 // delete PlaylistManager;
169 // PlaylistManager = NULL;
178 #ifdef SBCLIENT_WITH_SOUND
179 if (ConfigFile
->exists("SoundEnabled") ? ConfigFile
->getVar("SoundEnabled").asBool() : false)
181 ConfigFile
->setCallback("SoundEnabled", cbConfigFileSoundEnabled
);
185 //void playSound (CEntity &entity, TSoundId id)
187 ///* entity.Source = AudioMixer->createSource (id);
188 // entity.Source->setLooping (true);
189 // entity.Source->play ();
192 //void deleteSound (CEntity &entity)
194 ///* if (entity.Source != NULL)
196 // if (entity.Source->isPlaying ())
197 // entity.Source->stop ();
199 // AudioMixer->removeSource (entity.Source);
200 // entity.Source = NULL;
206 #ifdef SBCLIENT_WITH_SOUND
209 // PlaylistManager->update(DiffTime);
210 AudioMixer
->update();
217 #ifdef SBCLIENT_WITH_SOUND
218 ConfigFile
->setCallback("SoundEnabled", NULL
);
219 if (SoundEnabled
) releaseSound2();
223 void playMusic(const char *file
)
225 #ifdef SBCLIENT_WITH_SOUND
227 AudioMixer
->playMusic(file
, 1000, true, true);
231 } /* namespace SBCLIENT */
233 ////#ifdef NL_OS_WINDOWS
235 ////void playMusic(sint32 playlist, sint32 track)
237 //// if (SoundEnabled)
238 //// PlaylistManager->playMusic(playlist, track);
241 ////void setMusicVolume(sint32 playlist, float volume)
243 //// if (SoundEnabled)
244 //// PlaylistManager->setVolume(playlist, volume);
247 NLMISC_COMMAND(music_bg
,"background music","")
249 if (args
.size() != 0) return false;
250 SBCLIENT::playMusic(SBCLIENT_MUSIC_BACKGROUND
);
254 NLMISC_COMMAND(music_bg_beat
,"background music with beat","")
256 if (args
.size() != 0)
258 SBCLIENT::playMusic(SBCLIENT_MUSIC_BACKGROUND_BEAT
);
262 NLMISC_COMMAND(music_wait
,"loading music","")
264 if (args
.size() != 0)
266 SBCLIENT::playMusic(SBCLIENT_MUSIC_WAIT
);
270 NLMISC_COMMAND(music_login
,"login screen music","")
272 if (args
.size() != 0)
274 SBCLIENT::playMusic(SBCLIENT_MUSIC_LOGIN
);