tomwalters@313
|
1 // Copyright 2008-2010, Thomas Walters
|
tomwalters@313
|
2 //
|
tomwalters@313
|
3 // AIM-C: A C++ implementation of the Auditory Image Model
|
tomwalters@313
|
4 // http://www.acousticscale.org/AIMC
|
tomwalters@313
|
5 //
|
tomwalters@318
|
6 // Licensed under the Apache License, Version 2.0 (the "License");
|
tomwalters@318
|
7 // you may not use this file except in compliance with the License.
|
tomwalters@318
|
8 // You may obtain a copy of the License at
|
tomwalters@313
|
9 //
|
tomwalters@318
|
10 // http://www.apache.org/licenses/LICENSE-2.0
|
tomwalters@313
|
11 //
|
tomwalters@318
|
12 // Unless required by applicable law or agreed to in writing, software
|
tomwalters@318
|
13 // distributed under the License is distributed on an "AS IS" BASIS,
|
tomwalters@318
|
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
tomwalters@318
|
15 // See the License for the specific language governing permissions and
|
tomwalters@318
|
16 // limitations under the License.
|
tomwalters@313
|
17
|
tomwalters@313
|
18 /*!
|
tomwalters@313
|
19 * \file AIMCopy.cpp
|
tomwalters@313
|
20 * \brief AIM-C replacement for HTK's HCopy
|
tomwalters@313
|
21 *
|
tomwalters@313
|
22 * The following subset of the command-line flags
|
tomwalters@313
|
23 * should be implemented from HCopy:
|
tomwalters@313
|
24 * -A Print command line arguments off
|
tomwalters@313
|
25 * -C cf Set config file to cf default
|
tomwalters@313
|
26 * (should be able to take multiple config files)
|
tomwalters@313
|
27 * -S f Set script file to f none
|
tomwalters@313
|
28 * //! \todo -T N Set trace flags to N 0
|
tomwalters@313
|
29 * -V Print version information off
|
tomwalters@313
|
30 * -D of Write configuration data to of none
|
tomwalters@313
|
31 *
|
tomwalters@313
|
32 * \author Thomas Walters <tom@acousticscale.org>
|
tomwalters@313
|
33 * \date created 2008/05/08
|
tomwalters@313
|
34 * \version \$Id$
|
tomwalters@313
|
35 */
|
tomwalters@313
|
36
|
tomwalters@313
|
37 #include <fstream>
|
tomwalters@313
|
38 #include <iostream>
|
tomwalters@313
|
39 #include <string>
|
tomwalters@313
|
40 #include <utility>
|
tomwalters@313
|
41 #include <vector>
|
tomwalters@313
|
42
|
tomwalters@313
|
43 #include <stdlib.h>
|
tomwalters@313
|
44 #include <time.h>
|
tomwalters@313
|
45
|
tomwalters@313
|
46 #include "Modules/Input/ModuleFileInput.h"
|
tomwalters@313
|
47 #include "Modules/BMM/ModuleGammatone.h"
|
tomwalters@313
|
48 #include "Modules/BMM/ModulePZFC.h"
|
tomwalters@313
|
49 #include "Modules/NAP/ModuleHCL.h"
|
tomwalters@313
|
50 #include "Modules/Strobes/ModuleParabola.h"
|
tomwalters@313
|
51 #include "Modules/Strobes/ModuleLocalMax.h"
|
tomwalters@313
|
52 #include "Modules/SAI/ModuleSAI.h"
|
tomwalters@313
|
53 #include "Modules/SSI/ModuleSSI.h"
|
tomwalters@313
|
54 #include "Modules/SNR/ModuleNoise.h"
|
tomwalters@313
|
55 #include "Modules/Profile/ModuleSlice.h"
|
tomwalters@313
|
56 #include "Modules/Profile/ModuleScaler.h"
|
tomwalters@313
|
57 #include "Modules/Features/ModuleGaussians.h"
|
tomwalters@313
|
58 #include "Modules/Output/FileOutputHTK.h"
|
tomwalters@313
|
59 #include "Support/Common.h"
|
tomwalters@313
|
60 #include "Support/FileList.h"
|
tomwalters@313
|
61 #include "Support/Parameters.h"
|
tomwalters@313
|
62
|
tomwalters@313
|
63 using std::ofstream;
|
tomwalters@313
|
64 using std::pair;
|
tomwalters@313
|
65 using std::vector;
|
tomwalters@313
|
66 using std::string;
|
tomwalters@313
|
67 int main(int argc, char* argv[]) {
|
tomwalters@313
|
68 string sound_file;
|
tomwalters@313
|
69 string data_file;
|
tomwalters@313
|
70 string config_file;
|
tomwalters@313
|
71 string script_file;
|
tomwalters@313
|
72 bool write_data = false;
|
tomwalters@313
|
73 bool print_version = false;
|
tomwalters@313
|
74
|
tomwalters@313
|
75 string version_string(
|
tomwalters@313
|
76 " AIM-C AIMCopy\n"
|
tomwalters@313
|
77 " (c) 2006-2010, Thomas Walters and Willem van Engen\n"
|
tomwalters@313
|
78 " http://www.acoustiscale.org/AIMC/\n"
|
tomwalters@313
|
79 "\n");
|
tomwalters@313
|
80
|
tomwalters@313
|
81 if (argc < 2) {
|
tomwalters@313
|
82 printf("%s", version_string.c_str());
|
tomwalters@313
|
83 printf("AIMCopy is intended as a drop-in replacement for HTK's HCopy\n");
|
tomwalters@313
|
84 printf("command. It is used for making features from audio files for\n");
|
tomwalters@313
|
85 printf("use with HTK.\n");
|
tomwalters@313
|
86 printf("Usage: \n");
|
tomwalters@313
|
87 printf(" -A Print command line arguments off\n");
|
tomwalters@313
|
88 printf(" -C cf Set config file to cf none\n");
|
tomwalters@313
|
89 printf(" -S f Set script file to f none\n");
|
tomwalters@313
|
90 printf(" -V Print version information off\n");
|
tomwalters@313
|
91 printf(" -D g Write configuration data to g none\n");
|
tomwalters@313
|
92 return -1;
|
tomwalters@313
|
93 }
|
tomwalters@313
|
94
|
tomwalters@313
|
95 // Parse command-line arguments
|
tomwalters@313
|
96 for (int i = 1; i < argc; i++) {
|
tomwalters@313
|
97 if (strcmp(argv[i],"-A") == 0) {
|
tomwalters@313
|
98 for (int j = 0; j < argc; j++)
|
tomwalters@313
|
99 printf("%s ",argv[j]);
|
tomwalters@313
|
100 printf("\n");
|
tomwalters@313
|
101 fflush(stdout);
|
tomwalters@313
|
102 continue;
|
tomwalters@313
|
103 }
|
tomwalters@313
|
104 if (strcmp(argv[i],"-C") == 0) {
|
tomwalters@313
|
105 if (++i >= argc) {
|
tomwalters@313
|
106 aimc::LOG_ERROR(_T("Configuration file name expected after -C"));
|
tomwalters@313
|
107 return(-1);
|
tomwalters@313
|
108 }
|
tomwalters@313
|
109 config_file = argv[i];
|
tomwalters@313
|
110 continue;
|
tomwalters@313
|
111 }
|
tomwalters@313
|
112 if (strcmp(argv[i],"-S") == 0) {
|
tomwalters@313
|
113 if (++i >= argc) {
|
tomwalters@313
|
114 aimc::LOG_ERROR(_T("Script file name expected after -S"));
|
tomwalters@313
|
115 return(-1);
|
tomwalters@313
|
116 }
|
tomwalters@313
|
117 script_file = argv[i];
|
tomwalters@313
|
118 continue;
|
tomwalters@313
|
119 }
|
tomwalters@313
|
120 if (strcmp(argv[i],"-D") == 0) {
|
tomwalters@313
|
121 if (++i >= argc) {
|
tomwalters@313
|
122 aimc::LOG_ERROR(_T("Data file name expected after -D"));
|
tomwalters@313
|
123 return(-1);
|
tomwalters@313
|
124 }
|
tomwalters@313
|
125 data_file = argv[i];
|
tomwalters@313
|
126 write_data = true;
|
tomwalters@313
|
127 continue;
|
tomwalters@313
|
128 }
|
tomwalters@313
|
129 if (strcmp(argv[i],"-V") == 0) {
|
tomwalters@313
|
130 print_version = true;
|
tomwalters@313
|
131 continue;
|
tomwalters@313
|
132 }
|
tomwalters@313
|
133 aimc::LOG_ERROR(_T("Unrecognized command-line argument: %s"), argv[i]);
|
tomwalters@313
|
134 }
|
tomwalters@313
|
135
|
tomwalters@313
|
136 if (print_version)
|
tomwalters@313
|
137 printf("%s", version_string.c_str());
|
tomwalters@313
|
138
|
tomwalters@313
|
139 aimc::Parameters params;
|
tomwalters@313
|
140
|
tomwalters@313
|
141 if (!params.Load(config_file.c_str())) {
|
tomwalters@313
|
142 aimc::LOG_ERROR(_T("Couldn't load parameters from file %s"),
|
tomwalters@313
|
143 config_file.c_str());
|
tomwalters@313
|
144 return -1;
|
tomwalters@313
|
145 }
|
tomwalters@313
|
146
|
tomwalters@313
|
147 vector<pair<string, string> > file_list = aimc::FileList::Load(script_file);
|
tomwalters@313
|
148 if (file_list.size() == 0) {
|
tomwalters@313
|
149 aimc::LOG_ERROR("No data read from file %s", script_file.c_str());
|
tomwalters@313
|
150 return -1;
|
tomwalters@313
|
151 }
|
tomwalters@313
|
152
|
tomwalters@313
|
153 // Set up AIM-C processor here
|
tomwalters@313
|
154 aimc::ModuleFileInput input(¶ms);
|
tomwalters@313
|
155 aimc::ModuleNoise noise_maker(¶ms);
|
tomwalters@313
|
156 aimc::ModuleGammatone bmm(¶ms);
|
tomwalters@313
|
157 aimc::ModuleHCL nap(¶ms);
|
tomwalters@313
|
158 aimc::ModuleLocalMax strobes(¶ms);
|
tomwalters@313
|
159 aimc::ModuleSAI sai(¶ms);
|
tomwalters@313
|
160 aimc::ModuleSSI ssi(¶ms);
|
tomwalters@313
|
161
|
tomwalters@313
|
162 params.SetBool("slice.all", false);
|
tomwalters@313
|
163 params.SetInt("slice.lower_index", 77);
|
tomwalters@313
|
164 params.SetInt("slice.upper_index", 150);
|
tomwalters@313
|
165 aimc::ModuleSlice slice_1(¶ms);
|
tomwalters@313
|
166
|
tomwalters@313
|
167 //params.SetInt("slice.lower_index", 210);
|
tomwalters@313
|
168 //params.SetInt("slice.upper_index", 240);
|
tomwalters@313
|
169 //aimc::ModuleSlice slice_2(¶ms);
|
tomwalters@313
|
170
|
tomwalters@313
|
171 //params.SetInt("slice.lower_index", 280);
|
tomwalters@313
|
172 //params.SetInt("slice.upper_index", 304);
|
tomwalters@313
|
173 //aimc::ModuleSlice slice_3(¶ms);
|
tomwalters@313
|
174
|
tomwalters@313
|
175 //params.SetInt("slice.lower_index", 328);
|
tomwalters@313
|
176 //params.SetInt("slice.upper_index", 352);
|
tomwalters@313
|
177 //aimc::ModuleSlice slice_4(¶ms);
|
tomwalters@313
|
178
|
tomwalters@313
|
179 params.SetBool("slice.all", true);
|
tomwalters@313
|
180 aimc::ModuleSlice slice_5(¶ms);
|
tomwalters@313
|
181
|
tomwalters@313
|
182 //params.SetFloat("nap.lowpass_cutoff", 100.0);
|
tomwalters@313
|
183 //aimc::ModuleHCL smooth_nap(¶ms);
|
tomwalters@313
|
184 //params.SetBool("slice.all", true);
|
tomwalters@313
|
185 //aimc::ModuleSlice nap_profile(¶ms);
|
tomwalters@313
|
186 //aimc::ModuleScaler nap_scaler(¶ms);
|
tomwalters@313
|
187 //aimc::ModuleGaussians nap_features(¶ms);
|
tomwalters@313
|
188 //aimc::FileOutputHTK nap_out(¶ms);
|
tomwalters@313
|
189
|
tomwalters@313
|
190 aimc::ModuleGaussians features_1(¶ms);
|
tomwalters@313
|
191 //aimc::ModuleGaussians features_2(¶ms);
|
tomwalters@313
|
192 //aimc::ModuleGaussians features_3(¶ms);
|
tomwalters@313
|
193 //aimc::ModuleGaussians features_4(¶ms);
|
tomwalters@313
|
194 aimc::ModuleGaussians features_5(¶ms);
|
tomwalters@313
|
195
|
tomwalters@313
|
196 aimc::FileOutputHTK output_1(¶ms);
|
tomwalters@313
|
197 //aimc::FileOutputHTK output_2(¶ms);
|
tomwalters@313
|
198 //aimc::FileOutputHTK output_3(¶ms);
|
tomwalters@313
|
199 //aimc::FileOutputHTK output_4(¶ms);
|
tomwalters@313
|
200 aimc::FileOutputHTK output_5(¶ms);
|
tomwalters@313
|
201
|
tomwalters@313
|
202 input.AddTarget(&noise_maker);
|
tomwalters@313
|
203 noise_maker.AddTarget(&bmm);
|
tomwalters@313
|
204 bmm.AddTarget(&nap);
|
tomwalters@313
|
205 //bmm.AddTarget(&smooth_nap);
|
tomwalters@313
|
206 //smooth_nap.AddTarget(&nap_profile);
|
tomwalters@313
|
207 //nap_profile.AddTarget(&nap_scaler);
|
tomwalters@313
|
208 //nap_scaler.AddTarget(&nap_features);
|
tomwalters@313
|
209 //nap_features.AddTarget(&nap_out);
|
tomwalters@313
|
210 nap.AddTarget(&strobes);
|
tomwalters@313
|
211 strobes.AddTarget(&sai);
|
tomwalters@313
|
212 sai.AddTarget(&ssi);
|
tomwalters@313
|
213
|
tomwalters@313
|
214 ssi.AddTarget(&slice_1);
|
tomwalters@313
|
215 //ssi.AddTarget(&slice_2);
|
tomwalters@313
|
216 //ssi.AddTarget(&slice_3);
|
tomwalters@313
|
217 //ssi.AddTarget(&slice_4);
|
tomwalters@313
|
218 ssi.AddTarget(&slice_5);
|
tomwalters@313
|
219
|
tomwalters@313
|
220 slice_1.AddTarget(&features_1);
|
tomwalters@313
|
221 //slice_2.AddTarget(&features_2);
|
tomwalters@313
|
222 //slice_3.AddTarget(&features_3);
|
tomwalters@313
|
223 //slice_4.AddTarget(&features_4);
|
tomwalters@313
|
224 slice_5.AddTarget(&features_5);
|
tomwalters@313
|
225
|
tomwalters@313
|
226 features_1.AddTarget(&output_1);
|
tomwalters@313
|
227 //features_2.AddTarget(&output_2);
|
tomwalters@313
|
228 //features_3.AddTarget(&output_3);
|
tomwalters@313
|
229 //features_4.AddTarget(&output_4);
|
tomwalters@313
|
230 features_5.AddTarget(&output_5);
|
tomwalters@313
|
231
|
tomwalters@313
|
232 if (write_data) {
|
tomwalters@313
|
233 ofstream outfile(data_file.c_str());
|
tomwalters@313
|
234 if (outfile.fail()) {
|
tomwalters@313
|
235 aimc::LOG_ERROR("Couldn't open data file %s for writing",
|
tomwalters@313
|
236 data_file.c_str());
|
tomwalters@313
|
237 return -1;
|
tomwalters@313
|
238 }
|
tomwalters@313
|
239 time_t rawtime;
|
tomwalters@313
|
240 struct tm * timeinfo;
|
tomwalters@313
|
241 time(&rawtime);
|
tomwalters@313
|
242 timeinfo = localtime(&rawtime);
|
tomwalters@313
|
243
|
tomwalters@313
|
244
|
tomwalters@313
|
245 outfile << "# AIM-C AIMCopy\n";
|
tomwalters@313
|
246 outfile << "# Run on: " << asctime(timeinfo);
|
tomwalters@313
|
247 char * descr = getenv("USER");
|
tomwalters@313
|
248 if (descr) {
|
tomwalters@313
|
249 outfile << "# By user: " << descr <<"\n";
|
tomwalters@313
|
250 }
|
tomwalters@313
|
251 outfile << "#Module chain: ";
|
tomwalters@313
|
252 outfile << "#input";
|
tomwalters@313
|
253 outfile << "# noise_maker";
|
tomwalters@313
|
254 outfile << "# gt";
|
tomwalters@313
|
255 outfile << "# nap";
|
tomwalters@313
|
256 outfile << "# slice";
|
tomwalters@313
|
257 outfile << "# scaler";
|
tomwalters@313
|
258 outfile << "# features";
|
tomwalters@313
|
259 outfile << "# output";
|
tomwalters@313
|
260 outfile << "# local_max";
|
tomwalters@313
|
261 outfile << "# sai_weighted";
|
tomwalters@313
|
262 outfile << "# ssi";
|
tomwalters@313
|
263 outfile << "# slice";
|
tomwalters@313
|
264 outfile << "# features";
|
tomwalters@313
|
265 outfile << "# output";
|
tomwalters@313
|
266 outfile << "# slice";
|
tomwalters@313
|
267 outfile << "# features";
|
tomwalters@313
|
268 outfile << "# output";
|
tomwalters@313
|
269 outfile << "# slice";
|
tomwalters@313
|
270 outfile << "# features";
|
tomwalters@313
|
271 outfile << "# output";
|
tomwalters@313
|
272 outfile << "# slice";
|
tomwalters@313
|
273 outfile << "# features";
|
tomwalters@313
|
274 outfile << "# output";
|
tomwalters@313
|
275 outfile << "# slice";
|
tomwalters@313
|
276 outfile << "# features";
|
tomwalters@313
|
277 outfile << "# output";
|
tomwalters@313
|
278 outfile << "# ";
|
tomwalters@313
|
279 outfile << "# Module versions:\n";
|
tomwalters@313
|
280 outfile << "# " << input.id() << " : " << input.version() << "\n";
|
tomwalters@313
|
281 outfile << "# " << bmm.id() << " : " << bmm.version() << "\n";
|
tomwalters@313
|
282 outfile << "# " << nap.id() << " : " << nap.version() << "\n";
|
tomwalters@313
|
283 outfile << "# " << strobes.id() << " : " << strobes.version() << "\n";
|
tomwalters@313
|
284 outfile << "# " << sai.id() << " : " << sai.version() << "\n";
|
tomwalters@313
|
285 outfile << "# " << slice_1.id() << " : " << slice_1.version() << "\n";
|
tomwalters@313
|
286 // outfile << "# " << profile.id() << " : " << profile.version() << "\n";
|
tomwalters@313
|
287 // outfile << "# " << scaler.id() << " : " << scaler.version() << "\n";
|
tomwalters@313
|
288 outfile << "# " << features_1.id() << " : " << features_1.version() << "\n";
|
tomwalters@313
|
289 outfile << "# " << output_1.id() << " : " << output_1.version() << "\n";
|
tomwalters@313
|
290 outfile << "#\n";
|
tomwalters@313
|
291 outfile << "# Parameters:\n";
|
tomwalters@313
|
292 outfile << params.WriteString();
|
tomwalters@313
|
293 outfile.close();
|
tomwalters@313
|
294 }
|
tomwalters@313
|
295
|
tomwalters@313
|
296 for (unsigned int i = 0; i < file_list.size(); ++i) {
|
tomwalters@313
|
297 // aimc::LOG_INFO(_T("In: %s"), file_list[i].first.c_str());
|
tomwalters@313
|
298 aimc::LOG_INFO(_T("Out: %s"), file_list[i].second.c_str());
|
tomwalters@313
|
299
|
tomwalters@313
|
300 string filename = file_list[i].second + ".slice_1";
|
tomwalters@313
|
301 output_1.OpenFile(filename.c_str(), 10.0f);
|
tomwalters@313
|
302 //filename = file_list[i].second + ".slice_2";
|
tomwalters@313
|
303 //output_2.OpenFile(filename.c_str(), 10.0f);
|
tomwalters@313
|
304 //filename = file_list[i].second + ".slice_3";
|
tomwalters@313
|
305 //output_3.OpenFile(filename.c_str(), 10.0f);
|
tomwalters@313
|
306 //filename = file_list[i].second + ".slice_4";
|
tomwalters@313
|
307 //output_4.OpenFile(filename.c_str(), 10.0f);
|
tomwalters@313
|
308 filename = file_list[i].second + ".ssi_profile";
|
tomwalters@313
|
309 output_5.OpenFile(filename.c_str(), 10.0f);
|
tomwalters@313
|
310 //filename = file_list[i].second + ".smooth_nap_profile";
|
tomwalters@313
|
311 //nap_out.OpenFile(filename.c_str(), 10.0f);
|
tomwalters@313
|
312
|
tomwalters@313
|
313 if (input.LoadFile(file_list[i].first.c_str())) {
|
tomwalters@313
|
314 input.Process();
|
tomwalters@313
|
315 } else {
|
tomwalters@313
|
316 printf("LoadFile failed for file %s\n", file_list[i].first.c_str());
|
tomwalters@313
|
317 }
|
tomwalters@313
|
318 input.Reset();
|
tomwalters@313
|
319 }
|
tomwalters@313
|
320
|
tomwalters@313
|
321 return 0;
|
tomwalters@313
|
322 }
|