Fix crash
[ryzomcore.git] / nel / tools / sound / build_sound / build_sound.cpp
blob98cf45a646fcc478dc64bc1053885422fb52af51
1 /**
2 * Build Sound
3 * \file build_sound.cpp
4 * \brief Build Sound
5 * \date 2009-06-02 21:25GMT
6 * \author Jan Boon (Kaetemi)
7 */
9 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
10 // Copyright (C) 2009-2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
12 // This program is free software: you can redistribute it and/or modify
13 // it under the terms of the GNU Affero General Public License as
14 // published by the Free Software Foundation, either version 3 of the
15 // License, or (at your option) any later version.
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU Affero General Public License for more details.
22 // You should have received a copy of the GNU Affero General Public License
23 // along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include <nel/misc/types_nl.h>
27 // STL includes
28 #include <vector>
29 #include <string>
30 #include <map>
31 #include <iostream>
32 #include <fstream>
34 // NeL includes
35 #include <nel/misc/common.h>
36 #include <nel/misc/file.h>
37 #include <nel/misc/log.h>
38 #include <nel/misc/path.h>
39 #include <nel/sound/u_audio_mixer.h>
41 // Project includes
42 // ...
44 using namespace std;
45 using namespace NLMISC;
46 using namespace NLSOUND;
48 namespace {
50 } /* anonymous namespace */
52 ////////////////////////////////////////////////////////////////////////
53 // note: *.packed_sheets files are placed in <build_packed_sheets> //
54 // *.sample_bank files are placed in <source_samplebanks>, //
55 // and will need to be moved to the right location by //
56 // your build script system. //
57 ////////////////////////////////////////////////////////////////////////
59 /////////////////////////////////////////////////////////////////////
60 // this tool is deprecated by build_samplebank and build_soundbank //
61 /////////////////////////////////////////////////////////////////////
63 int main(int nNbArg, char **ppArgs)
65 // create debug stuff
66 createDebug();
68 // verify all params
69 if (nNbArg < 5)
71 nlinfo("ERROR : Wrong number of arguments\n");
72 nlinfo("USAGE : build_sound <leveldesign> <dfn> <source_samplebanks> <build_packed_sheets> <build_samplebanks>\n");
73 return EXIT_FAILURE;
75 string leveldesignDir = string(ppArgs[1]);
76 if (!CFile::isDirectory(leveldesignDir))
78 nlerrornoex("Directory leveldesign '%s' does not exist", leveldesignDir.c_str());
79 return EXIT_FAILURE;
81 string dfnDir = string(ppArgs[2]);
82 if (!CFile::isDirectory(dfnDir))
84 nlerrornoex("Directory dfn '%s' does not exist", dfnDir.c_str());
85 return EXIT_FAILURE;
87 string samplebanksDir = string(ppArgs[3]);
88 if (!CFile::isDirectory(samplebanksDir))
90 nlerrornoex("Directory source_samplebanks '%s' does not exist", samplebanksDir.c_str());
91 return EXIT_FAILURE;
93 string exportDir = string(ppArgs[4]);
94 if (!CFile::isDirectory(exportDir))
96 nlerrornoex("Directory build_packed_sheets '%s' does not exist", exportDir.c_str());
97 return EXIT_FAILURE;
99 string buildSampleBanksDir;
100 if (nNbArg == 6) buildSampleBanksDir = string(ppArgs[5]);
101 else buildSampleBanksDir = samplebanksDir;
102 if (!CFile::isDirectory(buildSampleBanksDir))
104 nlerrornoex("Directory build_samplebanks '%s' does not exist", buildSampleBanksDir.c_str());
105 return EXIT_FAILURE;
108 // add search paths
109 CPath::addSearchPath(leveldesignDir, true, false);
110 std::string relativeDfnDir = dfnDir; // only add dfn if not a subdir of leveldesignDir
111 if (!CPath::makePathRelative(leveldesignDir, dfnDir) || relativeDfnDir.size() < 2 || (relativeDfnDir[0] == '.' && relativeDfnDir[1] == '.'))
112 CPath::addSearchPath(dfnDir, true, false);
114 // create the audio mixer
115 UAudioMixer *audioMixer = UAudioMixer::createAudioMixer();
116 // set the sample path, sample banks will be found and built here
117 audioMixer->setSamplePaths(samplebanksDir, buildSampleBanksDir);
118 // set the location where the packed_sheets will be exported
119 audioMixer->setPackedSheetOption(exportDir, true);
121 // this here does the magic, we actually don't need the driver but whatever
122 try { audioMixer->init(0, false, false, NULL, true, UAudioMixer::DriverOpenAl); } catch (...) {
123 try { audioMixer->init(0, false, false, NULL, true, UAudioMixer::DriverXAudio2); } catch (...) {
124 try { audioMixer->init(0, false, false, NULL, true, UAudioMixer::DriverFMod); }
125 catch (...) { return EXIT_FAILURE; } } }
127 // and that's all folks
128 delete audioMixer;
129 return EXIT_SUCCESS;
132 /* end of file */