comparison src/Main/AIMCopy_SSI_Features_v3.cc @ 41:65e9aed2e800

-New experimental system with pre-noised signals.
author tomwalters
date Thu, 04 Mar 2010 11:01:39 +0000
parents
children 8af8f145ed21
comparison
equal deleted inserted replaced
40:814dd2a74cdb 41:65e9aed2e800
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 params.SetBool("ssi.pitch_cutoff", false);
162 aimc::ModuleSSI ssi_no_cutoff(&params);
163
164 params.SetBool("ssi.pitch_cutoff", true);
165 params.SetFloat("ssi.pitch_search_start_ms", 4.6f);
166 aimc::ModuleSSI ssi_cutoff(&params);
167
168 params.SetBool("slice.all", false);
169 params.SetInt("slice.lower_index", 77);
170 params.SetInt("slice.upper_index", 150);
171 aimc::ModuleSlice slice_ssi_slice_1_no_cutoff(&params);
172 aimc::ModuleSlice slice_ssi_slice_1_cutoff(&params);
173
174 params.SetBool("slice.all", true);
175 aimc::ModuleSlice slice_ssi_all_no_cutoff(&params);
176 aimc::ModuleSlice slice_ssi_all_cutoff(&params);
177
178 params.SetFloat("nap.lowpass_cutoff", 100.0);
179 aimc::ModuleHCL smooth_nap(&params);
180 params.SetBool("slice.all", true);
181 aimc::ModuleSlice nap_profile(&params);
182 aimc::ModuleScaler nap_scaler(&params);
183
184 aimc::ModuleGaussians nap_features(&params);
185 aimc::ModuleGaussians features_ssi_slice1_no_cutoff(&params);
186 aimc::ModuleGaussians features_ssi_slice1_cutoff(&params);
187 aimc::ModuleGaussians features_ssi_all_no_cutoff(&params);
188 aimc::ModuleGaussians features_ssi_all_cutoff(&params);
189
190 aimc::FileOutputHTK nap_out(&params);
191 aimc::FileOutputHTK output_ssi_slice1_no_cutoff(&params);
192 aimc::FileOutputHTK output_ssi_slice1_cutoff(&params);
193 aimc::FileOutputHTK output_ssi_all_no_cutoff(&params);
194 aimc::FileOutputHTK output_ssi_all_cutoff(&params);
195
196 input.AddTarget(&bmm);
197 //noise_maker.AddTarget(&bmm);
198 bmm.AddTarget(&nap);
199 bmm.AddTarget(&smooth_nap);
200 smooth_nap.AddTarget(&nap_profile);
201 nap_profile.AddTarget(&nap_scaler);
202 nap_scaler.AddTarget(&nap_features);
203 nap_features.AddTarget(&nap_out);
204
205 nap.AddTarget(&strobes);
206 strobes.AddTarget(&sai);
207 sai.AddTarget(&ssi_no_cutoff);
208 sai.AddTarget(&ssi_cutoff);
209
210 ssi_no_cutoff.AddTarget(&output_ssi_slice1_no_cutoff);
211 ssi_no_cutoff.AddTarget(&output_ssi_all_no_cutoff);
212 ssi_cutoff.AddTarget(&output_ssi_slice1_cutoff);
213 ssi_cutoff.AddTarget(&output_ssi_all_cutoff);
214
215 slice_ssi_slice_1_no_cutoff.AddTarget(&features_ssi_slice1_no_cutoff);
216 slice_ssi_all_no_cutoff.AddTarget(&features_ssi_all_no_cutoff);
217 slice_ssi_slice_1_cutoff.AddTarget(&features_ssi_slice1_cutoff);
218 slice_ssi_all_cutoff.AddTarget(&features_ssi_all_cutoff);
219
220
221 features_ssi_slice1_no_cutoff.AddTarget(&output_ssi_slice1_no_cutoff);
222 features_ssi_all_no_cutoff.AddTarget(&output_ssi_all_no_cutoff);
223 features_ssi_slice1_cutoff.AddTarget(&output_ssi_slice1_cutoff);
224 features_ssi_all_cutoff.AddTarget(&output_ssi_all_cutoff);
225
226
227 if (write_data) {
228 ofstream outfile(data_file.c_str());
229 if (outfile.fail()) {
230 aimc::LOG_ERROR("Couldn't open data file %s for writing",
231 data_file.c_str());
232 return -1;
233 }
234 time_t rawtime;
235 struct tm * timeinfo;
236 time(&rawtime);
237 timeinfo = localtime(&rawtime);
238
239
240 outfile << "# AIM-C AIMCopy\n";
241 outfile << "# Run on: " << asctime(timeinfo);
242 char * descr = getenv("USER");
243 if (descr) {
244 outfile << "# By user: " << descr <<"\n";
245 }
246 outfile << "#Module chain: ";
247 outfile << "#input";
248 outfile << "# noise_maker";
249 outfile << "# gt";
250 outfile << "# nap";
251 outfile << "# slice";
252 outfile << "# scaler";
253 outfile << "# features";
254 outfile << "# output";
255 outfile << "# local_max";
256 outfile << "# sai_weighted";
257 outfile << "# ssi";
258 outfile << "# slice";
259 outfile << "# features";
260 outfile << "# output";
261 outfile << "# slice";
262 outfile << "# features";
263 outfile << "# output";
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 << "# ";
274 outfile << "# Module versions:\n";
275 outfile << "# " << input.id() << " : " << input.version() << "\n";
276 outfile << "# " << bmm.id() << " : " << bmm.version() << "\n";
277 outfile << "# " << nap.id() << " : " << nap.version() << "\n";
278 outfile << "# " << strobes.id() << " : " << strobes.version() << "\n";
279 outfile << "# " << sai.id() << " : " << sai.version() << "\n";
280 outfile << "#\n";
281 outfile << "# Parameters:\n";
282 outfile << params.WriteString();
283 outfile.close();
284 }
285
286 for (unsigned int i = 0; i < file_list.size(); ++i) {
287 // aimc::LOG_INFO(_T("In: %s"), file_list[i].first.c_str());
288 aimc::LOG_INFO(_T("Out: %s"), file_list[i].second.c_str());
289
290 string filename = file_list[i].second + ".slice_1_no_cutoff";
291 output_ssi_slice1_no_cutoff.OpenFile(filename.c_str(), 10.0f);
292 filename = file_list[i].second + ".ssi_profile_no_cutoff";
293 output_ssi_all_no_cutoff.OpenFile(filename.c_str(), 10.0f);
294 filename = file_list[i].second + ".slice_1_cutoff";
295 output_ssi_slice1_cutoff.OpenFile(filename.c_str(), 10.0f);
296 filename = file_list[i].second + ".ssi_profile_cutoff";
297 output_ssi_all_cutoff.OpenFile(filename.c_str(), 10.0f);
298 filename = file_list[i].second + ".smooth_nap_profile";
299 nap_out.OpenFile(filename.c_str(), 10.0f);
300
301 if (input.LoadFile(file_list[i].first.c_str())) {
302 input.Process();
303 } else {
304 printf("LoadFile failed for file %s\n", file_list[i].first.c_str());
305 }
306 input.Reset();
307 }
308
309 return 0;
310 }