Mercurial > hg > aimc
comparison src/Main/AIMCopy.cc @ 23:491b1b1d1dc5
-Added AIMCopy, a replacement for HTK's HCopy
-Set "Id" keyword on all .cc, .h and .py files
-Added FileList class to aupport AIMCopy
-Added a first go at a Module factory class. It's not to be used at the moment, but it will serve as a reminder to implement a proper factory soon.
author | tomwalters |
---|---|
date | Tue, 23 Feb 2010 12:47:01 +0000 |
parents | |
children | f7321fcaac7e |
comparison
equal
deleted
inserted
replaced
22:645cfd371cff | 23:491b1b1d1dc5 |
---|---|
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 | |
46 #include "Modules/Input/ModuleFileInput.h" | |
47 #include "Modules/BMM/ModuleGammatone.h" | |
48 #include "Modules/BMM/ModulePZFC.h" | |
49 #include "Modules/NAP/ModuleHCL.h" | |
50 #include "Modules/Strobes/ModuleParabola.h" | |
51 #include "Modules/SAI/ModuleSAI.h" | |
52 #include "Modules/SSI/ModuleSSI.h" | |
53 #include "Modules/Profile/ModuleSlice.h" | |
54 #include "Modules/Profile/ModuleScaler.h" | |
55 #include "Modules/Features/ModuleGaussians.h" | |
56 #include "Modules/Output/FileOutputHTK.h" | |
57 #include "Support/Common.h" | |
58 #include "Support/FileList.h" | |
59 #include "Support/Parameters.h" | |
60 | |
61 using std::ofstream; | |
62 using std::pair; | |
63 using std::vector; | |
64 using std::string; | |
65 int main(int argc, char* argv[]) { | |
66 string sound_file; | |
67 string data_file; | |
68 string config_file; | |
69 string script_file; | |
70 bool write_data = false; | |
71 bool print_version = false; | |
72 | |
73 string version_string( | |
74 " AIM-C AIMCopy\n" | |
75 " (c) 2006-2010, Thomas Walters and Willem van Engen\n" | |
76 " http://www.acoustiscale.org/AIMC/\n" | |
77 "\n"); | |
78 | |
79 if (argc < 2) { | |
80 printf("%s", version_string.c_str()); | |
81 printf("AIMCopy is intended as a drop-in replacement for HTK's HCopy\n"); | |
82 printf("command. It is used for making features from audio files for\n"); | |
83 printf("use with HTK.\n"); | |
84 printf("Usage: \n"); | |
85 printf(" -A Print command line arguments off\n"); | |
86 printf(" -C cf Set config file to cf none\n"); | |
87 printf(" -S f Set script file to f none\n"); | |
88 printf(" -V Print version information off\n"); | |
89 printf(" -D g Write configuration data to g none\n"); | |
90 return -1; | |
91 } | |
92 | |
93 // Parse command-line arguments | |
94 for (int i = 1; i < argc; i++) { | |
95 if (strcmp(argv[i],"-A") == 0) { | |
96 for (int j = 0; j < argc; j++) | |
97 printf("%s ",argv[j]); | |
98 printf("\n"); | |
99 fflush(stdout); | |
100 continue; | |
101 } | |
102 if (strcmp(argv[i],"-C") == 0) { | |
103 if (++i >= argc) { | |
104 aimc::LOG_ERROR(_T("Configuration file name expected after -C")); | |
105 return(-1); | |
106 } | |
107 config_file = argv[i]; | |
108 continue; | |
109 } | |
110 if (strcmp(argv[i],"-S") == 0) { | |
111 if (++i >= argc) { | |
112 aimc::LOG_ERROR(_T("Script file name expected after -S")); | |
113 return(-1); | |
114 } | |
115 script_file = argv[i]; | |
116 continue; | |
117 } | |
118 if (strcmp(argv[i],"-D") == 0) { | |
119 if (++i >= argc) { | |
120 aimc::LOG_ERROR(_T("Data file name expected after -D")); | |
121 return(-1); | |
122 } | |
123 data_file = argv[i]; | |
124 write_data = true; | |
125 continue; | |
126 } | |
127 if (strcmp(argv[i],"-V") == 0) { | |
128 print_version = true; | |
129 continue; | |
130 } | |
131 aimc::LOG_ERROR(_T("Unrecognized command-line argument: %s"), argv[i]); | |
132 } | |
133 | |
134 if (print_version) | |
135 printf("%s", version_string.c_str()); | |
136 | |
137 aimc::Parameters params; | |
138 | |
139 if (!params.Load(config_file.c_str())) { | |
140 aimc::LOG_ERROR(_T("Couldn't load parameters from file %s"), | |
141 config_file.c_str()); | |
142 return -1; | |
143 } | |
144 | |
145 vector<pair<string, string> > file_list = aimc::FileList::Load(script_file); | |
146 if (file_list.size() == 0) { | |
147 aimc::LOG_ERROR("No data read from file %s", script_file.c_str()); | |
148 return -1; | |
149 } | |
150 | |
151 // Set up AIM-C processor here | |
152 aimc::ModuleFileInput input(¶ms); | |
153 aimc::ModuleGammatone bmm(¶ms); | |
154 aimc::ModuleHCL nap(¶ms); | |
155 aimc::ModuleSlice profile(¶ms); | |
156 aimc::ModuleScaler scaler(¶ms); | |
157 aimc::ModuleGaussians features(¶ms); | |
158 aimc::FileOutputHTK output(¶ms); | |
159 | |
160 input.AddTarget(&bmm); | |
161 bmm.AddTarget(&nap); | |
162 nap.AddTarget(&profile); | |
163 profile.AddTarget(&scaler); | |
164 scaler.AddTarget(&features); | |
165 features.AddTarget(&output); | |
166 | |
167 if (write_data) { | |
168 ofstream outfile(data_file.c_str()); | |
169 if (outfile.fail()) { | |
170 aimc::LOG_ERROR("Couldn't open data file %s for writing", | |
171 data_file.c_str()); | |
172 return -1; | |
173 } | |
174 outfile << "# AIM-C AIMCopy\n"; | |
175 outfile << "# Module versions:\n"; | |
176 outfile << "# " << input.id() << " : " << input.version() << "\n"; | |
177 outfile << "# " << bmm.id() << " : " << bmm.version() << "\n"; | |
178 outfile << "# " << nap.id() << " : " << nap.version() << "\n"; | |
179 outfile << "# " << profile.id() << " : " << profile.version() << "\n"; | |
180 outfile << "# " << scaler.id() << " : " << scaler.version() << "\n"; | |
181 outfile << "# " << features.id() << " : " << features.version() << "\n"; | |
182 outfile << "# " << output.id() << " : " << output.version() << "\n"; | |
183 outfile << "#\n"; | |
184 outfile << "# Parameters:\n"; | |
185 outfile << params.WriteString(); | |
186 outfile.close(); | |
187 } | |
188 | |
189 for (unsigned int i = 0; i < file_list.size(); ++i) { | |
190 aimc::LOG_INFO(_T("In: %s"), file_list[i].first.c_str()); | |
191 aimc::LOG_INFO(_T("Out: %s"), file_list[i].second.c_str()); | |
192 | |
193 output.OpenFile(file_list[i].second.c_str(), 10.0f); | |
194 if (input.LoadFile(file_list[i].first.c_str())) { | |
195 input.Process(); | |
196 } else { | |
197 printf("LoadFile failed for file %s\n", file_list[i].first.c_str()); | |
198 } | |
199 input.Reset(); | |
200 } | |
201 | |
202 return 0; | |
203 } |