comparison src/Main/AIMCopy_SSI_Features_v2.cc @ 40:814dd2a74cdb

-New features code for just ssi profile and slice 1
author tomwalters
date Mon, 01 Mar 2010 19:22:15 +0000
parents
children c5f5e9569863
comparison
equal deleted inserted replaced
39:6dd731fc6d0d 40:814dd2a74cdb
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/Strobes/ModuleLocalMax.h"
53 #include "Modules/SAI/ModuleSAI.h"
54 #include "Modules/SSI/ModuleSSI.h"
55 #include "Modules/SNR/ModuleNoise.h"
56 #include "Modules/Profile/ModuleSlice.h"
57 #include "Modules/Profile/ModuleScaler.h"
58 #include "Modules/Features/ModuleGaussians.h"
59 #include "Modules/Output/FileOutputHTK.h"
60 #include "Support/Common.h"
61 #include "Support/FileList.h"
62 #include "Support/Parameters.h"
63
64 using std::ofstream;
65 using std::pair;
66 using std::vector;
67 using std::string;
68 int main(int argc, char* argv[]) {
69 string sound_file;
70 string data_file;
71 string config_file;
72 string script_file;
73 bool write_data = false;
74 bool print_version = false;
75
76 string version_string(
77 " AIM-C AIMCopy\n"
78 " (c) 2006-2010, Thomas Walters and Willem van Engen\n"
79 " http://www.acoustiscale.org/AIMC/\n"
80 "\n");
81
82 if (argc < 2) {
83 printf("%s", version_string.c_str());
84 printf("AIMCopy is intended as a drop-in replacement for HTK's HCopy\n");
85 printf("command. It is used for making features from audio files for\n");
86 printf("use with HTK.\n");
87 printf("Usage: \n");
88 printf(" -A Print command line arguments off\n");
89 printf(" -C cf Set config file to cf none\n");
90 printf(" -S f Set script file to f none\n");
91 printf(" -V Print version information off\n");
92 printf(" -D g Write configuration data to g none\n");
93 return -1;
94 }
95
96 // Parse command-line arguments
97 for (int i = 1; i < argc; i++) {
98 if (strcmp(argv[i],"-A") == 0) {
99 for (int j = 0; j < argc; j++)
100 printf("%s ",argv[j]);
101 printf("\n");
102 fflush(stdout);
103 continue;
104 }
105 if (strcmp(argv[i],"-C") == 0) {
106 if (++i >= argc) {
107 aimc::LOG_ERROR(_T("Configuration file name expected after -C"));
108 return(-1);
109 }
110 config_file = argv[i];
111 continue;
112 }
113 if (strcmp(argv[i],"-S") == 0) {
114 if (++i >= argc) {
115 aimc::LOG_ERROR(_T("Script file name expected after -S"));
116 return(-1);
117 }
118 script_file = argv[i];
119 continue;
120 }
121 if (strcmp(argv[i],"-D") == 0) {
122 if (++i >= argc) {
123 aimc::LOG_ERROR(_T("Data file name expected after -D"));
124 return(-1);
125 }
126 data_file = argv[i];
127 write_data = true;
128 continue;
129 }
130 if (strcmp(argv[i],"-V") == 0) {
131 print_version = true;
132 continue;
133 }
134 aimc::LOG_ERROR(_T("Unrecognized command-line argument: %s"), argv[i]);
135 }
136
137 if (print_version)
138 printf("%s", version_string.c_str());
139
140 aimc::Parameters params;
141
142 if (!params.Load(config_file.c_str())) {
143 aimc::LOG_ERROR(_T("Couldn't load parameters from file %s"),
144 config_file.c_str());
145 return -1;
146 }
147
148 vector<pair<string, string> > file_list = aimc::FileList::Load(script_file);
149 if (file_list.size() == 0) {
150 aimc::LOG_ERROR("No data read from file %s", script_file.c_str());
151 return -1;
152 }
153
154 // Set up AIM-C processor here
155 aimc::ModuleFileInput input(&params);
156 aimc::ModuleNoise noise_maker(&params);
157 aimc::ModuleGammatone bmm(&params);
158 aimc::ModuleHCL nap(&params);
159 aimc::ModuleLocalMax strobes(&params);
160 aimc::ModuleSAI sai(&params);
161 aimc::ModuleSSI ssi(&params);
162
163 params.SetBool("slice.all", false);
164 params.SetInt("slice.lower_index", 77);
165 params.SetInt("slice.upper_index", 150);
166 aimc::ModuleSlice slice_1(&params);
167
168 //params.SetInt("slice.lower_index", 210);
169 //params.SetInt("slice.upper_index", 240);
170 //aimc::ModuleSlice slice_2(&params);
171
172 //params.SetInt("slice.lower_index", 280);
173 //params.SetInt("slice.upper_index", 304);
174 //aimc::ModuleSlice slice_3(&params);
175
176 //params.SetInt("slice.lower_index", 328);
177 //params.SetInt("slice.upper_index", 352);
178 //aimc::ModuleSlice slice_4(&params);
179
180 params.SetBool("slice.all", true);
181 aimc::ModuleSlice slice_5(&params);
182
183 //params.SetFloat("nap.lowpass_cutoff", 100.0);
184 //aimc::ModuleHCL smooth_nap(&params);
185 //params.SetBool("slice.all", true);
186 //aimc::ModuleSlice nap_profile(&params);
187 //aimc::ModuleScaler nap_scaler(&params);
188 //aimc::ModuleGaussians nap_features(&params);
189 //aimc::FileOutputHTK nap_out(&params);
190
191 aimc::ModuleGaussians features_1(&params);
192 //aimc::ModuleGaussians features_2(&params);
193 //aimc::ModuleGaussians features_3(&params);
194 //aimc::ModuleGaussians features_4(&params);
195 aimc::ModuleGaussians features_5(&params);
196
197 aimc::FileOutputHTK output_1(&params);
198 //aimc::FileOutputHTK output_2(&params);
199 //aimc::FileOutputHTK output_3(&params);
200 //aimc::FileOutputHTK output_4(&params);
201 aimc::FileOutputHTK output_5(&params);
202
203 input.AddTarget(&noise_maker);
204 noise_maker.AddTarget(&bmm);
205 bmm.AddTarget(&nap);
206 //bmm.AddTarget(&smooth_nap);
207 //smooth_nap.AddTarget(&nap_profile);
208 //nap_profile.AddTarget(&nap_scaler);
209 //nap_scaler.AddTarget(&nap_features);
210 //nap_features.AddTarget(&nap_out);
211 nap.AddTarget(&strobes);
212 strobes.AddTarget(&sai);
213 sai.AddTarget(&ssi);
214
215 ssi.AddTarget(&slice_1);
216 //ssi.AddTarget(&slice_2);
217 //ssi.AddTarget(&slice_3);
218 //ssi.AddTarget(&slice_4);
219 ssi.AddTarget(&slice_5);
220
221 slice_1.AddTarget(&features_1);
222 //slice_2.AddTarget(&features_2);
223 //slice_3.AddTarget(&features_3);
224 //slice_4.AddTarget(&features_4);
225 slice_5.AddTarget(&features_5);
226
227 features_1.AddTarget(&output_1);
228 //features_2.AddTarget(&output_2);
229 //features_3.AddTarget(&output_3);
230 //features_4.AddTarget(&output_4);
231 features_5.AddTarget(&output_5);
232
233 if (write_data) {
234 ofstream outfile(data_file.c_str());
235 if (outfile.fail()) {
236 aimc::LOG_ERROR("Couldn't open data file %s for writing",
237 data_file.c_str());
238 return -1;
239 }
240 time_t rawtime;
241 struct tm * timeinfo;
242 time(&rawtime);
243 timeinfo = localtime(&rawtime);
244
245
246 outfile << "# AIM-C AIMCopy\n";
247 outfile << "# Run on: " << asctime(timeinfo);
248 char * descr = getenv("USER");
249 if (descr) {
250 outfile << "# By user: " << descr <<"\n";
251 }
252 outfile << "#Module chain: ";
253 outfile << "#input";
254 outfile << "# noise_maker";
255 outfile << "# gt";
256 outfile << "# nap";
257 outfile << "# slice";
258 outfile << "# scaler";
259 outfile << "# features";
260 outfile << "# output";
261 outfile << "# local_max";
262 outfile << "# sai_weighted";
263 outfile << "# ssi";
264 outfile << "# slice";
265 outfile << "# features";
266 outfile << "# output";
267 outfile << "# slice";
268 outfile << "# features";
269 outfile << "# output";
270 outfile << "# slice";
271 outfile << "# features";
272 outfile << "# output";
273 outfile << "# slice";
274 outfile << "# features";
275 outfile << "# output";
276 outfile << "# slice";
277 outfile << "# features";
278 outfile << "# output";
279 outfile << "# ";
280 outfile << "# Module versions:\n";
281 outfile << "# " << input.id() << " : " << input.version() << "\n";
282 outfile << "# " << bmm.id() << " : " << bmm.version() << "\n";
283 outfile << "# " << nap.id() << " : " << nap.version() << "\n";
284 outfile << "# " << strobes.id() << " : " << strobes.version() << "\n";
285 outfile << "# " << sai.id() << " : " << sai.version() << "\n";
286 outfile << "# " << slice_1.id() << " : " << slice_1.version() << "\n";
287 // outfile << "# " << profile.id() << " : " << profile.version() << "\n";
288 // outfile << "# " << scaler.id() << " : " << scaler.version() << "\n";
289 outfile << "# " << features_1.id() << " : " << features_1.version() << "\n";
290 outfile << "# " << output_1.id() << " : " << output_1.version() << "\n";
291 outfile << "#\n";
292 outfile << "# Parameters:\n";
293 outfile << params.WriteString();
294 outfile.close();
295 }
296
297 for (unsigned int i = 0; i < file_list.size(); ++i) {
298 // aimc::LOG_INFO(_T("In: %s"), file_list[i].first.c_str());
299 aimc::LOG_INFO(_T("Out: %s"), file_list[i].second.c_str());
300
301 string filename = file_list[i].second + ".slice_1";
302 output_1.OpenFile(filename.c_str(), 10.0f);
303 //filename = file_list[i].second + ".slice_2";
304 //output_2.OpenFile(filename.c_str(), 10.0f);
305 //filename = file_list[i].second + ".slice_3";
306 //output_3.OpenFile(filename.c_str(), 10.0f);
307 //filename = file_list[i].second + ".slice_4";
308 //output_4.OpenFile(filename.c_str(), 10.0f);
309 filename = file_list[i].second + ".ssi_profile";
310 output_5.OpenFile(filename.c_str(), 10.0f);
311 //filename = file_list[i].second + ".smooth_nap_profile";
312 //nap_out.OpenFile(filename.c_str(), 10.0f);
313
314 if (input.LoadFile(file_list[i].first.c_str())) {
315 input.Process();
316 } else {
317 printf("LoadFile failed for file %s\n", file_list[i].first.c_str());
318 }
319 input.Reset();
320 }
321
322 return 0;
323 }