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