Mercurial > hg > aimc
comparison trunk/src/Main/AIMCopy_SSI_Features.cc @ 305:ed91095d9240
-New AIMCopy main for the SSI features (temporary hack till I get a working module load system)
-LocalMax strobe criterion. This is faster and better than the parabola version, which still seems buggy.
-Noise generator module. Adds noise to a signal. Uses boost for the random number generator.
-New options for the SSI
-Slice now respects all its flags (oops!).
-MATLAB functions for visualisation
-Scripts for generating data to view in MATLAB
-Script to download and build HTK - useful for running experiments
author | tomwalters |
---|---|
date | Thu, 25 Feb 2010 22:02:00 +0000 |
parents | |
children | 42d154648b93 |
comparison
equal
deleted
inserted
replaced
304:e4f704f67ca6 | 305:ed91095d9240 |
---|---|
1 // Copyright 2008-2010, Thomas Walters | |
2 // | |
3 // AIM-C: A C++ implementation of the Auditory Image Model | |
4 // http://www.acousticscale.org/AIMC | |
5 // | |
6 // This program is free software: you can redistribute it and/or modify | |
7 // it under the terms of the GNU General Public License as published by | |
8 // the Free Software Foundation, either version 3 of the License, or | |
9 // (at your option) any later version. | |
10 // | |
11 // This program is distributed in the hope that it will be useful, | |
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 // GNU General Public License for more details. | |
15 // | |
16 // You should have received a copy of the GNU General Public License | |
17 // along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | |
19 /*! | |
20 * \file AIMCopy.cpp | |
21 * \brief AIM-C replacement for HTK's HCopy | |
22 * | |
23 * The following subset of the command-line flags | |
24 * should be implemented from HCopy: | |
25 * -A Print command line arguments off | |
26 * -C cf Set config file to cf default | |
27 * (should be able to take multiple config files) | |
28 * -S f Set script file to f none | |
29 * //! \todo -T N Set trace flags to N 0 | |
30 * -V Print version information off | |
31 * -D of Write configuration data to of none | |
32 * | |
33 * \author Thomas Walters <tom@acousticscale.org> | |
34 * \date created 2008/05/08 | |
35 * \version \$Id$ | |
36 */ | |
37 | |
38 #include <fstream> | |
39 #include <iostream> | |
40 #include <string> | |
41 #include <utility> | |
42 #include <vector> | |
43 | |
44 #include <stdlib.h> | |
45 #include <time.h> | |
46 | |
47 #include "Modules/Input/ModuleFileInput.h" | |
48 #include "Modules/BMM/ModuleGammatone.h" | |
49 #include "Modules/BMM/ModulePZFC.h" | |
50 #include "Modules/NAP/ModuleHCL.h" | |
51 #include "Modules/Strobes/ModuleParabola.h" | |
52 #include "Modules/SAI/ModuleSAI.h" | |
53 #include "Modules/SSI/ModuleSSI.h" | |
54 #include "Modules/SNR/ModuleNoise.h" | |
55 #include "Modules/Profile/ModuleSlice.h" | |
56 #include "Modules/Profile/ModuleScaler.h" | |
57 #include "Modules/Features/ModuleGaussians.h" | |
58 #include "Modules/Output/FileOutputHTK.h" | |
59 #include "Support/Common.h" | |
60 #include "Support/FileList.h" | |
61 #include "Support/Parameters.h" | |
62 | |
63 using std::ofstream; | |
64 using std::pair; | |
65 using std::vector; | |
66 using std::string; | |
67 int main(int argc, char* argv[]) { | |
68 string sound_file; | |
69 string data_file; | |
70 string config_file; | |
71 string script_file; | |
72 bool write_data = false; | |
73 bool print_version = false; | |
74 | |
75 string version_string( | |
76 " AIM-C AIMCopy\n" | |
77 " (c) 2006-2010, Thomas Walters and Willem van Engen\n" | |
78 " http://www.acoustiscale.org/AIMC/\n" | |
79 "\n"); | |
80 | |
81 if (argc < 2) { | |
82 printf("%s", version_string.c_str()); | |
83 printf("AIMCopy is intended as a drop-in replacement for HTK's HCopy\n"); | |
84 printf("command. It is used for making features from audio files for\n"); | |
85 printf("use with HTK.\n"); | |
86 printf("Usage: \n"); | |
87 printf(" -A Print command line arguments off\n"); | |
88 printf(" -C cf Set config file to cf none\n"); | |
89 printf(" -S f Set script file to f none\n"); | |
90 printf(" -V Print version information off\n"); | |
91 printf(" -D g Write configuration data to g none\n"); | |
92 return -1; | |
93 } | |
94 | |
95 // Parse command-line arguments | |
96 for (int i = 1; i < argc; i++) { | |
97 if (strcmp(argv[i],"-A") == 0) { | |
98 for (int j = 0; j < argc; j++) | |
99 printf("%s ",argv[j]); | |
100 printf("\n"); | |
101 fflush(stdout); | |
102 continue; | |
103 } | |
104 if (strcmp(argv[i],"-C") == 0) { | |
105 if (++i >= argc) { | |
106 aimc::LOG_ERROR(_T("Configuration file name expected after -C")); | |
107 return(-1); | |
108 } | |
109 config_file = argv[i]; | |
110 continue; | |
111 } | |
112 if (strcmp(argv[i],"-S") == 0) { | |
113 if (++i >= argc) { | |
114 aimc::LOG_ERROR(_T("Script file name expected after -S")); | |
115 return(-1); | |
116 } | |
117 script_file = argv[i]; | |
118 continue; | |
119 } | |
120 if (strcmp(argv[i],"-D") == 0) { | |
121 if (++i >= argc) { | |
122 aimc::LOG_ERROR(_T("Data file name expected after -D")); | |
123 return(-1); | |
124 } | |
125 data_file = argv[i]; | |
126 write_data = true; | |
127 continue; | |
128 } | |
129 if (strcmp(argv[i],"-V") == 0) { | |
130 print_version = true; | |
131 continue; | |
132 } | |
133 aimc::LOG_ERROR(_T("Unrecognized command-line argument: %s"), argv[i]); | |
134 } | |
135 | |
136 if (print_version) | |
137 printf("%s", version_string.c_str()); | |
138 | |
139 aimc::Parameters params; | |
140 | |
141 if (!params.Load(config_file.c_str())) { | |
142 aimc::LOG_ERROR(_T("Couldn't load parameters from file %s"), | |
143 config_file.c_str()); | |
144 return -1; | |
145 } | |
146 | |
147 vector<pair<string, string> > file_list = aimc::FileList::Load(script_file); | |
148 if (file_list.size() == 0) { | |
149 aimc::LOG_ERROR("No data read from file %s", script_file.c_str()); | |
150 return -1; | |
151 } | |
152 | |
153 // Set up AIM-C processor here | |
154 aimc::ModuleFileInput input(¶ms); | |
155 //aimc::ModuleNoise noise_maker(¶ms); | |
156 aimc::ModuleGammatone bmm(¶ms); | |
157 aimc::ModuleHCL nap(¶ms); | |
158 aimc::ModuleParabola strobes(¶ms); | |
159 aimc::ModuleSAI sai(¶ms); | |
160 aimc::ModuleSSI ssi(¶ms); | |
161 | |
162 params.SetBool("slice.all", false); | |
163 params.SetInt("slice.lower_index", 40); | |
164 params.SetInt("slice.upper_index", 56); | |
165 aimc::ModuleSlice slice_1(¶ms); | |
166 | |
167 params.SetInt("slice.lower_index", 88); | |
168 params.SetInt("slice.upper_index", 104); | |
169 aimc::ModuleSlice slice_2(¶ms); | |
170 | |
171 params.SetInt("slice.lower_index", 184); | |
172 params.SetInt("slice.upper_index", 200); | |
173 aimc::ModuleSlice slice_3(¶ms); | |
174 | |
175 params.SetInt("slice.lower_index", 376); | |
176 params.SetInt("slice.upper_index", 392); | |
177 aimc::ModuleSlice slice_4(¶ms); | |
178 | |
179 params.SetBool("slice.all", true); | |
180 aimc::ModuleSlice slice_5(¶ms); | |
181 | |
182 aimc::ModuleGaussians features_1(¶ms); | |
183 aimc::ModuleGaussians features_2(¶ms); | |
184 aimc::ModuleGaussians features_3(¶ms); | |
185 aimc::ModuleGaussians features_4(¶ms); | |
186 aimc::ModuleGaussians features_5(¶ms); | |
187 | |
188 aimc::FileOutputHTK output_1(¶ms); | |
189 aimc::FileOutputHTK output_2(¶ms); | |
190 aimc::FileOutputHTK output_3(¶ms); | |
191 aimc::FileOutputHTK output_4(¶ms); | |
192 aimc::FileOutputHTK output_5(¶ms); | |
193 | |
194 input.AddTarget(&bmm); | |
195 // No noise for now | |
196 //noise_maker.AddTarget(&bmm); | |
197 bmm.AddTarget(&nap); | |
198 nap.AddTarget(&strobes); | |
199 strobes.AddTarget(&sai); | |
200 sai.AddTarget(&ssi); | |
201 | |
202 ssi.AddTarget(&slice_1); | |
203 ssi.AddTarget(&slice_2); | |
204 ssi.AddTarget(&slice_3); | |
205 ssi.AddTarget(&slice_4); | |
206 ssi.AddTarget(&slice_5); | |
207 | |
208 slice_1.AddTarget(&features_1); | |
209 slice_2.AddTarget(&features_2); | |
210 slice_3.AddTarget(&features_3); | |
211 slice_4.AddTarget(&features_4); | |
212 slice_5.AddTarget(&features_5); | |
213 | |
214 features_1.AddTarget(&output_1); | |
215 features_2.AddTarget(&output_2); | |
216 features_3.AddTarget(&output_3); | |
217 features_4.AddTarget(&output_4); | |
218 features_5.AddTarget(&output_5); | |
219 | |
220 if (write_data) { | |
221 ofstream outfile(data_file.c_str()); | |
222 if (outfile.fail()) { | |
223 aimc::LOG_ERROR("Couldn't open data file %s for writing", | |
224 data_file.c_str()); | |
225 return -1; | |
226 } | |
227 time_t rawtime; | |
228 struct tm * timeinfo; | |
229 time(&rawtime); | |
230 timeinfo = localtime(&rawtime); | |
231 | |
232 | |
233 outfile << "# AIM-C AIMCopy\n"; | |
234 outfile << "# Run on: " << asctime(timeinfo); | |
235 char * descr = getenv("USER"); | |
236 if (descr) { | |
237 outfile << "# By user: " << descr <<"\n"; | |
238 } | |
239 outfile << "# Module chain: "; | |
240 outfile << "# gt"; | |
241 outfile << "# parabola"; | |
242 outfile << "# sai_weighted"; | |
243 outfile << "# ssi"; | |
244 outfile << "# slice"; | |
245 outfile << "# features"; | |
246 outfile << "# output"; | |
247 outfile << "# slice"; | |
248 outfile << "# features"; | |
249 outfile << "# output"; | |
250 outfile << "# slice"; | |
251 outfile << "# features"; | |
252 outfile << "# output"; | |
253 outfile << "# slice"; | |
254 outfile << "# features"; | |
255 outfile << "# output"; | |
256 outfile << "# slice"; | |
257 outfile << "# features"; | |
258 outfile << "# output"; | |
259 outfile << "# "; | |
260 outfile << "# Module versions:\n"; | |
261 outfile << "# " << input.id() << " : " << input.version() << "\n"; | |
262 outfile << "# " << bmm.id() << " : " << bmm.version() << "\n"; | |
263 outfile << "# " << nap.id() << " : " << nap.version() << "\n"; | |
264 outfile << "# " << strobes.id() << " : " << strobes.version() << "\n"; | |
265 outfile << "# " << sai.id() << " : " << sai.version() << "\n"; | |
266 outfile << "# " << slice_1.id() << " : " << slice_1.version() << "\n"; | |
267 // outfile << "# " << profile.id() << " : " << profile.version() << "\n"; | |
268 // outfile << "# " << scaler.id() << " : " << scaler.version() << "\n"; | |
269 outfile << "# " << features_1.id() << " : " << features_1.version() << "\n"; | |
270 outfile << "# " << output_1.id() << " : " << output_1.version() << "\n"; | |
271 outfile << "#\n"; | |
272 outfile << "# Parameters:\n"; | |
273 outfile << params.WriteString(); | |
274 outfile.close(); | |
275 } | |
276 | |
277 for (unsigned int i = 0; i < file_list.size(); ++i) { | |
278 aimc::LOG_INFO(_T("In: %s"), file_list[i].first.c_str()); | |
279 aimc::LOG_INFO(_T("Out: %s"), file_list[i].second.c_str()); | |
280 | |
281 string filename = file_list[i].second + "_1"; | |
282 output_1.OpenFile(filename.c_str(), 10.0f); | |
283 filename = file_list[i].second + "_2"; | |
284 output_2.OpenFile(filename.c_str(), 10.0f); | |
285 filename = file_list[i].second + "_3"; | |
286 output_3.OpenFile(filename.c_str(), 10.0f); | |
287 filename = file_list[i].second + "_4"; | |
288 output_4.OpenFile(filename.c_str(), 10.0f); | |
289 filename = file_list[i].second + "_5"; | |
290 output_5.OpenFile(filename.c_str(), 10.0f); | |
291 | |
292 if (input.LoadFile(file_list[i].first.c_str())) { | |
293 input.Process(); | |
294 } else { | |
295 printf("LoadFile failed for file %s\n", file_list[i].first.c_str()); | |
296 } | |
297 input.Reset(); | |
298 } | |
299 | |
300 return 0; | |
301 } |