annotate trunk/src/Main/AIMCopy.cc @ 316:66a23c0545b6

-Added MFCCs back to the feature generation script
author tomwalters
date Thu, 04 Mar 2010 17:38:58 +0000
parents 09f6050303f8
children 30dde71d0230
rev   line source
tomwalters@296 1 // Copyright 2008-2010, Thomas Walters
tomwalters@296 2 //
tomwalters@296 3 // AIM-C: A C++ implementation of the Auditory Image Model
tomwalters@296 4 // http://www.acousticscale.org/AIMC
tomwalters@296 5 //
tomwalters@296 6 // This program is free software: you can redistribute it and/or modify
tomwalters@296 7 // it under the terms of the GNU General Public License as published by
tomwalters@296 8 // the Free Software Foundation, either version 3 of the License, or
tomwalters@296 9 // (at your option) any later version.
tomwalters@296 10 //
tomwalters@296 11 // This program is distributed in the hope that it will be useful,
tomwalters@296 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
tomwalters@296 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
tomwalters@296 14 // GNU General Public License for more details.
tomwalters@296 15 //
tomwalters@296 16 // You should have received a copy of the GNU General Public License
tomwalters@296 17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
tomwalters@296 18
tomwalters@296 19 /*!
tomwalters@296 20 * \file AIMCopy.cpp
tomwalters@296 21 * \brief AIM-C replacement for HTK's HCopy
tomwalters@296 22 *
tomwalters@296 23 * The following subset of the command-line flags
tomwalters@296 24 * should be implemented from HCopy:
tomwalters@296 25 * -A Print command line arguments off
tomwalters@296 26 * -C cf Set config file to cf default
tomwalters@296 27 * (should be able to take multiple config files)
tomwalters@296 28 * -S f Set script file to f none
tomwalters@296 29 * //! \todo -T N Set trace flags to N 0
tomwalters@296 30 * -V Print version information off
tomwalters@296 31 * -D of Write configuration data to of none
tomwalters@296 32 *
tomwalters@296 33 * \author Thomas Walters <tom@acousticscale.org>
tomwalters@296 34 * \date created 2008/05/08
tomwalters@296 35 * \version \$Id$
tomwalters@296 36 */
tomwalters@296 37
tomwalters@296 38 #include <fstream>
tomwalters@296 39 #include <iostream>
tomwalters@296 40 #include <string>
tomwalters@296 41 #include <utility>
tomwalters@296 42 #include <vector>
tomwalters@296 43
tomwalters@296 44 #include <stdlib.h>
tomwalters@297 45 #include <time.h>
tomwalters@296 46
tomwalters@296 47 #include "Modules/Input/ModuleFileInput.h"
tomwalters@296 48 #include "Modules/BMM/ModuleGammatone.h"
tomwalters@296 49 #include "Modules/BMM/ModulePZFC.h"
tomwalters@296 50 #include "Modules/NAP/ModuleHCL.h"
tomwalters@296 51 #include "Modules/Strobes/ModuleParabola.h"
tomwalters@296 52 #include "Modules/SAI/ModuleSAI.h"
tomwalters@296 53 #include "Modules/SSI/ModuleSSI.h"
tomwalters@296 54 #include "Modules/Profile/ModuleSlice.h"
tomwalters@296 55 #include "Modules/Profile/ModuleScaler.h"
tomwalters@296 56 #include "Modules/Features/ModuleGaussians.h"
tomwalters@296 57 #include "Modules/Output/FileOutputHTK.h"
tomwalters@296 58 #include "Support/Common.h"
tomwalters@296 59 #include "Support/FileList.h"
tomwalters@296 60 #include "Support/Parameters.h"
tomwalters@296 61
tomwalters@296 62 using std::ofstream;
tomwalters@296 63 using std::pair;
tomwalters@296 64 using std::vector;
tomwalters@296 65 using std::string;
tomwalters@296 66 int main(int argc, char* argv[]) {
tomwalters@296 67 string sound_file;
tomwalters@296 68 string data_file;
tomwalters@296 69 string config_file;
tomwalters@296 70 string script_file;
tomwalters@296 71 bool write_data = false;
tomwalters@296 72 bool print_version = false;
tomwalters@296 73
tomwalters@296 74 string version_string(
tomwalters@296 75 " AIM-C AIMCopy\n"
tomwalters@296 76 " (c) 2006-2010, Thomas Walters and Willem van Engen\n"
tomwalters@296 77 " http://www.acoustiscale.org/AIMC/\n"
tomwalters@296 78 "\n");
tomwalters@296 79
tomwalters@296 80 if (argc < 2) {
tomwalters@296 81 printf("%s", version_string.c_str());
tomwalters@296 82 printf("AIMCopy is intended as a drop-in replacement for HTK's HCopy\n");
tomwalters@296 83 printf("command. It is used for making features from audio files for\n");
tomwalters@296 84 printf("use with HTK.\n");
tomwalters@296 85 printf("Usage: \n");
tomwalters@296 86 printf(" -A Print command line arguments off\n");
tomwalters@296 87 printf(" -C cf Set config file to cf none\n");
tomwalters@296 88 printf(" -S f Set script file to f none\n");
tomwalters@296 89 printf(" -V Print version information off\n");
tomwalters@296 90 printf(" -D g Write configuration data to g none\n");
tomwalters@296 91 return -1;
tomwalters@296 92 }
tomwalters@296 93
tomwalters@296 94 // Parse command-line arguments
tomwalters@296 95 for (int i = 1; i < argc; i++) {
tomwalters@296 96 if (strcmp(argv[i],"-A") == 0) {
tomwalters@296 97 for (int j = 0; j < argc; j++)
tomwalters@296 98 printf("%s ",argv[j]);
tomwalters@296 99 printf("\n");
tomwalters@296 100 fflush(stdout);
tomwalters@296 101 continue;
tomwalters@296 102 }
tomwalters@296 103 if (strcmp(argv[i],"-C") == 0) {
tomwalters@296 104 if (++i >= argc) {
tomwalters@296 105 aimc::LOG_ERROR(_T("Configuration file name expected after -C"));
tomwalters@296 106 return(-1);
tomwalters@296 107 }
tomwalters@296 108 config_file = argv[i];
tomwalters@296 109 continue;
tomwalters@296 110 }
tomwalters@296 111 if (strcmp(argv[i],"-S") == 0) {
tomwalters@296 112 if (++i >= argc) {
tomwalters@296 113 aimc::LOG_ERROR(_T("Script file name expected after -S"));
tomwalters@296 114 return(-1);
tomwalters@296 115 }
tomwalters@296 116 script_file = argv[i];
tomwalters@296 117 continue;
tomwalters@296 118 }
tomwalters@296 119 if (strcmp(argv[i],"-D") == 0) {
tomwalters@296 120 if (++i >= argc) {
tomwalters@296 121 aimc::LOG_ERROR(_T("Data file name expected after -D"));
tomwalters@296 122 return(-1);
tomwalters@296 123 }
tomwalters@296 124 data_file = argv[i];
tomwalters@296 125 write_data = true;
tomwalters@296 126 continue;
tomwalters@296 127 }
tomwalters@296 128 if (strcmp(argv[i],"-V") == 0) {
tomwalters@296 129 print_version = true;
tomwalters@296 130 continue;
tomwalters@296 131 }
tomwalters@296 132 aimc::LOG_ERROR(_T("Unrecognized command-line argument: %s"), argv[i]);
tomwalters@296 133 }
tomwalters@296 134
tomwalters@296 135 if (print_version)
tomwalters@296 136 printf("%s", version_string.c_str());
tomwalters@296 137
tomwalters@296 138 aimc::Parameters params;
tomwalters@296 139
tomwalters@296 140 if (!params.Load(config_file.c_str())) {
tomwalters@296 141 aimc::LOG_ERROR(_T("Couldn't load parameters from file %s"),
tomwalters@296 142 config_file.c_str());
tomwalters@296 143 return -1;
tomwalters@296 144 }
tomwalters@296 145
tomwalters@296 146 vector<pair<string, string> > file_list = aimc::FileList::Load(script_file);
tomwalters@296 147 if (file_list.size() == 0) {
tomwalters@296 148 aimc::LOG_ERROR("No data read from file %s", script_file.c_str());
tomwalters@296 149 return -1;
tomwalters@296 150 }
tomwalters@296 151
tomwalters@296 152 // Set up AIM-C processor here
tomwalters@296 153 aimc::ModuleFileInput input(&params);
tomwalters@296 154 aimc::ModuleGammatone bmm(&params);
tomwalters@296 155 aimc::ModuleHCL nap(&params);
tomwalters@296 156 aimc::ModuleSlice profile(&params);
tomwalters@296 157 aimc::ModuleScaler scaler(&params);
tomwalters@296 158 aimc::ModuleGaussians features(&params);
tomwalters@296 159 aimc::FileOutputHTK output(&params);
tomwalters@296 160
tomwalters@296 161 input.AddTarget(&bmm);
tomwalters@296 162 bmm.AddTarget(&nap);
tomwalters@296 163 nap.AddTarget(&profile);
tomwalters@296 164 profile.AddTarget(&scaler);
tomwalters@296 165 scaler.AddTarget(&features);
tomwalters@296 166 features.AddTarget(&output);
tomwalters@296 167
tomwalters@296 168 if (write_data) {
tomwalters@296 169 ofstream outfile(data_file.c_str());
tomwalters@296 170 if (outfile.fail()) {
tomwalters@296 171 aimc::LOG_ERROR("Couldn't open data file %s for writing",
tomwalters@296 172 data_file.c_str());
tomwalters@296 173 return -1;
tomwalters@296 174 }
tomwalters@297 175 time_t rawtime;
tomwalters@297 176 struct tm * timeinfo;
tomwalters@297 177 time(&rawtime);
tomwalters@297 178 timeinfo = localtime(&rawtime);
tomwalters@297 179
tomwalters@297 180
tomwalters@296 181 outfile << "# AIM-C AIMCopy\n";
tomwalters@297 182 outfile << "# Run on: " << asctime(timeinfo);
tomwalters@297 183 char * descr = getenv("USER");
tomwalters@297 184 if (descr) {
tomwalters@297 185 outfile << "# By user: " << descr <<"\n";
tomwalters@297 186 }
tomwalters@297 187 outfile << "# Module chain: file_input->gt->hcl->slice->scaler->";
tomwalters@297 188 outfile << "gaussians->out_htk\n";
tomwalters@296 189 outfile << "# Module versions:\n";
tomwalters@296 190 outfile << "# " << input.id() << " : " << input.version() << "\n";
tomwalters@296 191 outfile << "# " << bmm.id() << " : " << bmm.version() << "\n";
tomwalters@296 192 outfile << "# " << nap.id() << " : " << nap.version() << "\n";
tomwalters@296 193 outfile << "# " << profile.id() << " : " << profile.version() << "\n";
tomwalters@296 194 outfile << "# " << scaler.id() << " : " << scaler.version() << "\n";
tomwalters@296 195 outfile << "# " << features.id() << " : " << features.version() << "\n";
tomwalters@296 196 outfile << "# " << output.id() << " : " << output.version() << "\n";
tomwalters@296 197 outfile << "#\n";
tomwalters@296 198 outfile << "# Parameters:\n";
tomwalters@296 199 outfile << params.WriteString();
tomwalters@296 200 outfile.close();
tomwalters@296 201 }
tomwalters@296 202
tomwalters@296 203 for (unsigned int i = 0; i < file_list.size(); ++i) {
tomwalters@296 204 aimc::LOG_INFO(_T("In: %s"), file_list[i].first.c_str());
tomwalters@296 205 aimc::LOG_INFO(_T("Out: %s"), file_list[i].second.c_str());
tomwalters@296 206
tomwalters@296 207 output.OpenFile(file_list[i].second.c_str(), 10.0f);
tomwalters@296 208 if (input.LoadFile(file_list[i].first.c_str())) {
tomwalters@296 209 input.Process();
tomwalters@296 210 } else {
tomwalters@296 211 printf("LoadFile failed for file %s\n", file_list[i].first.c_str());
tomwalters@296 212 }
tomwalters@296 213 input.Reset();
tomwalters@296 214 }
tomwalters@296 215
tomwalters@296 216 return 0;
tomwalters@296 217 }