tomwalters@23: // Copyright 2008-2010, Thomas Walters
tomwalters@23: //
tomwalters@23: // AIM-C: A C++ implementation of the Auditory Image Model
tomwalters@23: // http://www.acousticscale.org/AIMC
tomwalters@23: //
tomwalters@23: // This program is free software: you can redistribute it and/or modify
tomwalters@23: // it under the terms of the GNU General Public License as published by
tomwalters@23: // the Free Software Foundation, either version 3 of the License, or
tomwalters@23: // (at your option) any later version.
tomwalters@23: //
tomwalters@23: // This program is distributed in the hope that it will be useful,
tomwalters@23: // but WITHOUT ANY WARRANTY; without even the implied warranty of
tomwalters@23: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
tomwalters@23: // GNU General Public License for more details.
tomwalters@23: //
tomwalters@23: // You should have received a copy of the GNU General Public License
tomwalters@23: // along with this program. If not, see .
tomwalters@23:
tomwalters@23: /*!
tomwalters@23: * \file AIMCopy.cpp
tomwalters@23: * \brief AIM-C replacement for HTK's HCopy
tomwalters@23: *
tomwalters@23: * The following subset of the command-line flags
tomwalters@23: * should be implemented from HCopy:
tomwalters@23: * -A Print command line arguments off
tomwalters@23: * -C cf Set config file to cf default
tomwalters@23: * (should be able to take multiple config files)
tomwalters@23: * -S f Set script file to f none
tomwalters@23: * //! \todo -T N Set trace flags to N 0
tomwalters@23: * -V Print version information off
tomwalters@23: * -D of Write configuration data to of none
tomwalters@23: *
tomwalters@23: * \author Thomas Walters
tomwalters@23: * \date created 2008/05/08
tomwalters@23: * \version \$Id$
tomwalters@23: */
tomwalters@23:
tomwalters@23: #include
tomwalters@23: #include
tomwalters@23: #include
tomwalters@23: #include
tomwalters@23: #include
tomwalters@23:
tomwalters@23: #include
tomwalters@23:
tomwalters@23: #include "Modules/Input/ModuleFileInput.h"
tomwalters@23: #include "Modules/BMM/ModuleGammatone.h"
tomwalters@23: #include "Modules/BMM/ModulePZFC.h"
tomwalters@23: #include "Modules/NAP/ModuleHCL.h"
tomwalters@23: #include "Modules/Strobes/ModuleParabola.h"
tomwalters@23: #include "Modules/SAI/ModuleSAI.h"
tomwalters@23: #include "Modules/SSI/ModuleSSI.h"
tomwalters@23: #include "Modules/Profile/ModuleSlice.h"
tomwalters@23: #include "Modules/Profile/ModuleScaler.h"
tomwalters@23: #include "Modules/Features/ModuleGaussians.h"
tomwalters@23: #include "Modules/Output/FileOutputHTK.h"
tomwalters@23: #include "Support/Common.h"
tomwalters@23: #include "Support/FileList.h"
tomwalters@23: #include "Support/Parameters.h"
tomwalters@23:
tomwalters@23: using std::ofstream;
tomwalters@23: using std::pair;
tomwalters@23: using std::vector;
tomwalters@23: using std::string;
tomwalters@23: int main(int argc, char* argv[]) {
tomwalters@23: string sound_file;
tomwalters@23: string data_file;
tomwalters@23: string config_file;
tomwalters@23: string script_file;
tomwalters@23: bool write_data = false;
tomwalters@23: bool print_version = false;
tomwalters@23:
tomwalters@23: string version_string(
tomwalters@23: " AIM-C AIMCopy\n"
tomwalters@23: " (c) 2006-2010, Thomas Walters and Willem van Engen\n"
tomwalters@23: " http://www.acoustiscale.org/AIMC/\n"
tomwalters@23: "\n");
tomwalters@23:
tomwalters@23: if (argc < 2) {
tomwalters@23: printf("%s", version_string.c_str());
tomwalters@23: printf("AIMCopy is intended as a drop-in replacement for HTK's HCopy\n");
tomwalters@23: printf("command. It is used for making features from audio files for\n");
tomwalters@23: printf("use with HTK.\n");
tomwalters@23: printf("Usage: \n");
tomwalters@23: printf(" -A Print command line arguments off\n");
tomwalters@23: printf(" -C cf Set config file to cf none\n");
tomwalters@23: printf(" -S f Set script file to f none\n");
tomwalters@23: printf(" -V Print version information off\n");
tomwalters@23: printf(" -D g Write configuration data to g none\n");
tomwalters@23: return -1;
tomwalters@23: }
tomwalters@23:
tomwalters@23: // Parse command-line arguments
tomwalters@23: for (int i = 1; i < argc; i++) {
tomwalters@23: if (strcmp(argv[i],"-A") == 0) {
tomwalters@23: for (int j = 0; j < argc; j++)
tomwalters@23: printf("%s ",argv[j]);
tomwalters@23: printf("\n");
tomwalters@23: fflush(stdout);
tomwalters@23: continue;
tomwalters@23: }
tomwalters@23: if (strcmp(argv[i],"-C") == 0) {
tomwalters@23: if (++i >= argc) {
tomwalters@23: aimc::LOG_ERROR(_T("Configuration file name expected after -C"));
tomwalters@23: return(-1);
tomwalters@23: }
tomwalters@23: config_file = argv[i];
tomwalters@23: continue;
tomwalters@23: }
tomwalters@23: if (strcmp(argv[i],"-S") == 0) {
tomwalters@23: if (++i >= argc) {
tomwalters@23: aimc::LOG_ERROR(_T("Script file name expected after -S"));
tomwalters@23: return(-1);
tomwalters@23: }
tomwalters@23: script_file = argv[i];
tomwalters@23: continue;
tomwalters@23: }
tomwalters@23: if (strcmp(argv[i],"-D") == 0) {
tomwalters@23: if (++i >= argc) {
tomwalters@23: aimc::LOG_ERROR(_T("Data file name expected after -D"));
tomwalters@23: return(-1);
tomwalters@23: }
tomwalters@23: data_file = argv[i];
tomwalters@23: write_data = true;
tomwalters@23: continue;
tomwalters@23: }
tomwalters@23: if (strcmp(argv[i],"-V") == 0) {
tomwalters@23: print_version = true;
tomwalters@23: continue;
tomwalters@23: }
tomwalters@23: aimc::LOG_ERROR(_T("Unrecognized command-line argument: %s"), argv[i]);
tomwalters@23: }
tomwalters@23:
tomwalters@23: if (print_version)
tomwalters@23: printf("%s", version_string.c_str());
tomwalters@23:
tomwalters@23: aimc::Parameters params;
tomwalters@23:
tomwalters@23: if (!params.Load(config_file.c_str())) {
tomwalters@23: aimc::LOG_ERROR(_T("Couldn't load parameters from file %s"),
tomwalters@23: config_file.c_str());
tomwalters@23: return -1;
tomwalters@23: }
tomwalters@23:
tomwalters@23: vector > file_list = aimc::FileList::Load(script_file);
tomwalters@23: if (file_list.size() == 0) {
tomwalters@23: aimc::LOG_ERROR("No data read from file %s", script_file.c_str());
tomwalters@23: return -1;
tomwalters@23: }
tomwalters@23:
tomwalters@23: // Set up AIM-C processor here
tomwalters@23: aimc::ModuleFileInput input(¶ms);
tomwalters@23: aimc::ModuleGammatone bmm(¶ms);
tomwalters@23: aimc::ModuleHCL nap(¶ms);
tomwalters@23: aimc::ModuleSlice profile(¶ms);
tomwalters@23: aimc::ModuleScaler scaler(¶ms);
tomwalters@23: aimc::ModuleGaussians features(¶ms);
tomwalters@23: aimc::FileOutputHTK output(¶ms);
tomwalters@23:
tomwalters@23: input.AddTarget(&bmm);
tomwalters@23: bmm.AddTarget(&nap);
tomwalters@23: nap.AddTarget(&profile);
tomwalters@23: profile.AddTarget(&scaler);
tomwalters@23: scaler.AddTarget(&features);
tomwalters@23: features.AddTarget(&output);
tomwalters@23:
tomwalters@23: if (write_data) {
tomwalters@23: ofstream outfile(data_file.c_str());
tomwalters@23: if (outfile.fail()) {
tomwalters@23: aimc::LOG_ERROR("Couldn't open data file %s for writing",
tomwalters@23: data_file.c_str());
tomwalters@23: return -1;
tomwalters@23: }
tomwalters@23: outfile << "# AIM-C AIMCopy\n";
tomwalters@23: outfile << "# Module versions:\n";
tomwalters@23: outfile << "# " << input.id() << " : " << input.version() << "\n";
tomwalters@23: outfile << "# " << bmm.id() << " : " << bmm.version() << "\n";
tomwalters@23: outfile << "# " << nap.id() << " : " << nap.version() << "\n";
tomwalters@23: outfile << "# " << profile.id() << " : " << profile.version() << "\n";
tomwalters@23: outfile << "# " << scaler.id() << " : " << scaler.version() << "\n";
tomwalters@23: outfile << "# " << features.id() << " : " << features.version() << "\n";
tomwalters@23: outfile << "# " << output.id() << " : " << output.version() << "\n";
tomwalters@23: outfile << "#\n";
tomwalters@23: outfile << "# Parameters:\n";
tomwalters@23: outfile << params.WriteString();
tomwalters@23: outfile.close();
tomwalters@23: }
tomwalters@23:
tomwalters@23: for (unsigned int i = 0; i < file_list.size(); ++i) {
tomwalters@23: aimc::LOG_INFO(_T("In: %s"), file_list[i].first.c_str());
tomwalters@23: aimc::LOG_INFO(_T("Out: %s"), file_list[i].second.c_str());
tomwalters@23:
tomwalters@23: output.OpenFile(file_list[i].second.c_str(), 10.0f);
tomwalters@23: if (input.LoadFile(file_list[i].first.c_str())) {
tomwalters@23: input.Process();
tomwalters@23: } else {
tomwalters@23: printf("LoadFile failed for file %s\n", file_list[i].first.c_str());
tomwalters@23: }
tomwalters@23: input.Reset();
tomwalters@23: }
tomwalters@23:
tomwalters@23: return 0;
tomwalters@23: }