changeset 323:0f54006e91ea

- AIMCopy v5 for just smooth NAP features - Reporting of all modules and versions
author tomwalters
date Sun, 11 Jul 2010 03:46:06 +0000
parents 1c0723041971
children 6130fe7f6409
files trunk/SConstruct trunk/src/Main/AIMCopy_SSI_Features_v3.cc trunk/src/Main/AIMCopy_SSI_Features_v5_smooth_nap.cc trunk/src/Modules/Strobes/ModuleLocalMax.cc trunk/src/Support/Module.cc trunk/src/Support/Module.h
diffstat 6 files changed, 260 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/SConstruct	Mon Jun 07 08:38:21 2010 +0000
+++ b/trunk/SConstruct	Sun Jul 11 03:46:06 2010 +0000
@@ -52,7 +52,7 @@
 
 # File which contains main()
 #sources = common_sources + ['Main/AIMCopy_SSI_Features_v4_PZFC.cc']
-sources = common_sources + ['Main/aimc.cc']
+sources = common_sources + ['Main/AIMCopy_SSI_Features_v5_smooth_nap.cc']
 
 # Test sources
 test_sources = ['Modules/Profile/ModuleSlice_unittest.cc']
@@ -79,7 +79,8 @@
 
 # Build products location and executable name
 build_dir = os.path.join('build', target_platform + '-release')
-target_executable = 'aimc'
+#target_executable = 'aimc'
+target_executable = 'AIMCopy'
 test_executable = 'aimc_tests'
 
 # Create build products directory if necessary
--- a/trunk/src/Main/AIMCopy_SSI_Features_v3.cc	Mon Jun 07 08:38:21 2010 +0000
+++ b/trunk/src/Main/AIMCopy_SSI_Features_v3.cc	Sun Jul 11 03:46:06 2010 +0000
@@ -242,40 +242,13 @@
     if (descr) {
       outfile << "# By user: " << descr <<"\n";
     }
-    outfile << "#Module chain: ";
-    outfile << "#input";
-    outfile << "# noise_maker";
-    outfile << "#  gt";
-    outfile << "#   nap";
-    outfile << "#    slice";
-    outfile << "#     scaler";
-    outfile << "#      features";
-    outfile << "#       output";
-    outfile << "#    local_max";
-    outfile << "#     sai_weighted";
-    outfile << "#      ssi";
-    outfile << "#       slice";
-    outfile << "#        features";
-    outfile << "#          output";
-    outfile << "#       slice";
-    outfile << "#        features";
-    outfile << "#          output";
-    outfile << "#       slice";
-    outfile << "#        features";
-    outfile << "#          output";
-    outfile << "#       slice";
-    outfile << "#        features";
-    outfile << "#          output";
-    outfile << "#       slice";
-    outfile << "#        features";
-    outfile << "#          output";
-    outfile << "# ";
-    outfile << "# Module versions:\n";
-    outfile << "# " << input.id() << " : " << input.version() << "\n";
-    outfile << "# " << bmm.id() << " : " << bmm.version() << "\n";
-    outfile << "# " << nap.id() << " : " << nap.version() << "\n";
-    outfile << "# " << strobes.id() << " : " << strobes.version() << "\n";
-    outfile << "# " << sai.id() << " : " << sai.version() << "\n";
+    outfile << "# Module chain:\n";
+    outfile << "#";
+    input.PrintTargets(outfile);
+    outfile << "\n";
+    outfile << "#\n";
+    input.PrintVersions(outfile);
+    outfile << "\n";
     outfile << "#\n";
     outfile << "# Parameters:\n";
     outfile << params.WriteString();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/trunk/src/Main/AIMCopy_SSI_Features_v5_smooth_nap.cc	Sun Jul 11 03:46:06 2010 +0000
@@ -0,0 +1,219 @@
+// Copyright 2008-2010, Thomas Walters
+//
+// AIM-C: A C++ implementation of the Auditory Image Model
+// http://www.acousticscale.org/AIMC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+/*!
+ * \file AIMCopy.cpp
+ * \brief AIM-C replacement for HTK's HCopy
+ *
+ * The following subset of the command-line flags
+ * should be implemented from HCopy:
+ *  -A      Print command line arguments         off
+ *  -C cf   Set config file to cf                default 
+ * (should be able to take multiple config files)
+ *  -S f    Set script file to f                 none
+ *  //! \todo -T N    Set trace flags to N                 0
+ *  -V      Print version information            off
+ *  -D of   Write configuration data to of       none
+ *
+ * \author Thomas Walters <tom@acousticscale.org>
+ * \date created 2008/05/08
+ * \version \$Id$
+ */
+
+#include <fstream>
+#include <iostream>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include <stdlib.h>
+#include <time.h>
+
+#include "Modules/Input/ModuleFileInput.h"
+#include "Modules/BMM/ModuleGammatone.h"
+#include "Modules/BMM/ModulePZFC.h"
+#include "Modules/NAP/ModuleHCL.h"
+#include "Modules/Strobes/ModuleParabola.h"
+#include "Modules/Strobes/ModuleLocalMax.h"
+#include "Modules/SAI/ModuleSAI.h"
+#include "Modules/SSI/ModuleSSI.h"
+#include "Modules/SNR/ModuleNoise.h"
+#include "Modules/Profile/ModuleSlice.h"
+#include "Modules/Profile/ModuleScaler.h"
+#include "Modules/Features/ModuleGaussians.h"
+#include "Modules/Output/FileOutputHTK.h"
+#include "Support/Common.h"
+#include "Support/FileList.h"
+#include "Support/Parameters.h"
+
+using std::ofstream;
+using std::pair;
+using std::vector;
+using std::string;
+int main(int argc, char* argv[]) {
+  string sound_file;
+  string data_file;
+  string config_file;
+  string script_file;
+  bool write_data = false;
+  bool print_version = false;
+
+  string version_string(
+    " AIM-C AIMCopy\n"
+    "  (c) 2006-2010, Thomas Walters and Willem van Engen\n"
+    "  http://www.acoustiscale.org/AIMC/\n"
+    "\n");
+
+  if (argc < 2) {
+    printf("%s", version_string.c_str());
+    printf("AIMCopy is intended as a drop-in replacement for HTK's HCopy\n");
+    printf("command. It is used for making features from audio files for\n");
+    printf("use with HTK.\n");
+    printf("Usage: \n");
+    printf("  -A      Print command line arguments  off\n");
+    printf("  -C cf   Set config file to cf         none\n");
+    printf("  -S f    Set script file to f          none\n");
+    printf("  -V      Print version information     off\n");
+    printf("  -D g    Write configuration data to g none\n");
+    return -1;
+  }
+
+  bool use_config_file = false;
+
+  // Parse command-line arguments
+  for (int i = 1; i < argc; i++) {
+    if (strcmp(argv[i],"-A") == 0) {
+      for (int j = 0; j < argc; j++)
+        printf("%s ",argv[j]);
+      printf("\n");
+      fflush(stdout);
+      continue;
+    }
+    if (strcmp(argv[i],"-C") == 0) {
+      if (++i >= argc) {
+        aimc::LOG_ERROR(_T("Configuration file name expected after -C"));
+        return(-1);
+      }
+      config_file = argv[i];
+      use_config_file = true;
+      continue;
+    }
+    if (strcmp(argv[i],"-S") == 0) {
+      if (++i >= argc) {
+        aimc::LOG_ERROR(_T("Script file name expected after -S"));
+        return(-1);
+      }
+      script_file = argv[i];
+      continue;
+    }
+    if (strcmp(argv[i],"-D") == 0) {
+      if (++i >= argc) {
+        aimc::LOG_ERROR(_T("Data file name expected after -D"));
+        return(-1);
+      }
+      data_file = argv[i];
+      write_data = true;
+      continue;
+    }
+    if (strcmp(argv[i],"-V") == 0) {
+      print_version = true;
+      continue;
+    }
+    aimc::LOG_ERROR(_T("Unrecognized command-line argument: %s"), argv[i]);
+  }
+
+  if (print_version)
+    printf("%s", version_string.c_str());
+
+  aimc::Parameters params;
+
+  if (use_config_file) {
+    if (!params.Load(config_file.c_str())) {
+      aimc::LOG_ERROR(_T("Couldn't load parameters from file %s"),
+                      config_file.c_str());
+      return -1;
+    }
+  }
+
+  vector<pair<string, string> > file_list = aimc::FileList::Load(script_file);
+  if (file_list.size() == 0) {
+    aimc::LOG_ERROR("No data read from file %s", script_file.c_str());
+    return -1;
+  }
+
+  // Set up AIM-C processor here
+  aimc::ModuleFileInput input(&params);
+  aimc::ModuleGammatone bmm(&params);
+  params.SetFloat("nap.lowpass_cutoff", 100.0);
+  aimc::ModuleHCL smooth_nap(&params);
+  params.SetBool("slice.all", true);
+  aimc::ModuleSlice nap_profile(&params);
+  aimc::ModuleScaler nap_scaler(&params);
+  aimc::ModuleGaussians nap_features(&params);
+  aimc::FileOutputHTK nap_out(&params);
+
+  input.AddTarget(&bmm);
+  bmm.AddTarget(&smooth_nap);
+  smooth_nap.AddTarget(&nap_profile);
+  nap_profile.AddTarget(&nap_scaler);
+  nap_scaler.AddTarget(&nap_features);
+  nap_features.AddTarget(&nap_out);
+
+  if (write_data) {
+    ofstream outfile(data_file.c_str());
+    if (outfile.fail()) {
+      aimc::LOG_ERROR("Couldn't open data file %s for writing",
+                      data_file.c_str());
+      return -1;
+    }
+    time_t rawtime;
+    struct tm * timeinfo;
+    time(&rawtime);
+    timeinfo = localtime(&rawtime);
+
+
+    outfile << "# AIM-C AIMCopy\n";
+    outfile << "# Run on: " << asctime(timeinfo);
+    char * descr = getenv("USER");
+    if (descr) {
+      outfile << "# By user: " << descr <<"\n";
+    }
+    outfile << "# Module chain:\n";
+    outfile << "# ";
+    input.PrintTargets(outfile);
+    outfile << "\n";
+    outfile << "# Parameters:\n";
+    outfile << params.WriteString();
+    outfile.close();
+  }
+
+  for (unsigned int i = 0; i < file_list.size(); ++i) {
+    aimc::LOG_INFO(_T("Out: %s"), file_list[i].second.c_str());
+
+    string filename = file_list[i].second + ".smooth_nap_profile";
+    nap_out.OpenFile(filename.c_str(), 10.0f);
+
+    if (input.LoadFile(file_list[i].first.c_str())) {
+      input.Process();
+    } else {
+      printf("LoadFile failed for file %s\n", file_list[i].first.c_str());
+    }
+    input.Reset();
+  }
+
+  return 0;
+}
--- a/trunk/src/Modules/Strobes/ModuleLocalMax.cc	Mon Jun 07 08:38:21 2010 +0000
+++ b/trunk/src/Modules/Strobes/ModuleLocalMax.cc	Sun Jul 11 03:46:06 2010 +0000
@@ -33,7 +33,7 @@
                         "with timeout";
   module_identifier_ = "local_max";
   module_type_ = "strobes";
-  module_version_ = "$Id$";
+  module_version_ = "$Id: $";
 
   decay_time_ms_ = parameters_->DefaultFloat("strobes.decay_time_ms", 20.0f);
   timeout_ms_ = parameters_->DefaultFloat("strobes.timeout_ms", 3.0f);
--- a/trunk/src/Support/Module.cc	Mon Jun 07 08:38:21 2010 +0000
+++ b/trunk/src/Support/Module.cc	Sun Jul 11 03:46:06 2010 +0000
@@ -30,6 +30,7 @@
 
 namespace aimc {
 using std::pair;
+using std::ostream;
 Module::Module(Parameters *parameters) {
   initialized_ = false;
   targets_.clear();
@@ -131,5 +132,28 @@
     }
   }
 }
+
+void Module::PrintTargets(ostream &out) {
+  out << id();
+  if (targets_.size() > 0) {
+    out << "->(";
+    set<Module*>::const_iterator it;
+    for (it = targets_.begin(); it != targets_.end(); ++it) {
+      (*it)->PrintTargets(out);
+      if (targets_.size() > 1) {
+         out << ",";
+      }
+    }
+    out << ")";
+  }
+}
+
+void Module::PrintVersions(ostream &out) {
+  out << version() << "\n";
+  set<Module*>::const_iterator it;
+  for (it = targets_.begin(); it != targets_.end(); ++it) {
+     (*it)->PrintVersions(out);
+  }
+}
 }  // namespace aimc
 
--- a/trunk/src/Support/Module.h	Mon Jun 07 08:38:21 2010 +0000
+++ b/trunk/src/Support/Module.h	Sun Jul 11 03:46:06 2010 +0000
@@ -27,6 +27,7 @@
 #ifndef AIMC_SUPPORT_MODULE_H_
 #define AIMC_SUPPORT_MODULE_H_
 
+#include <iostream>
 #include <set>
 #include <string>
 
@@ -35,6 +36,7 @@
 #include "Support/SignalBank.h"
 
 namespace aimc {
+using std::ostream;
 using std::set;
 using std::string;
 
@@ -159,6 +161,10 @@
    */
   const SignalBank* GetOutputBank() const;
 
+  void PrintTargets(ostream &out);
+
+  void PrintVersions(ostream &out);
+
   string version() const {
     return module_version_;
   }