changeset 6:8c859ef1fb75

- Added a basic main function to test that all the can be fitted together - Fixed an initialisation bug in ModuleFileInput that left the buffer size at zero - Added proper description strings to the input and output modules - Fixed an out-by-a-factor-of-1000 bug in the SAI memory allocation (oops) - Added LOG_INFO_NN fucnction to log without a newline. Useful for the ASCII art module chain in aimc.cc.
author tomwalters
date Thu, 18 Feb 2010 19:35:07 +0000
parents 3c782dec2fc0
children 1a1988ec40e7
files src/Main/aimc.cc src/Modules/Features/ModuleGaussians.cc src/Modules/Input/ModuleFileInput.cc src/Modules/Output/FileOutputHTK.cc src/Modules/SAI/ModuleSAI.cc src/Support/Common.cc src/Support/Common.h src/Support/Module.cc
diffstat 8 files changed, 91 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/Main/aimc.cc	Thu Feb 18 16:55:40 2010 +0000
+++ b/src/Main/aimc.cc	Thu Feb 18 19:35:07 2010 +0000
@@ -1,4 +1,4 @@
-// Copyright 2006-2010, Thomas Walters
+// Copyright 2008-2010, Thomas Walters
 //
 // AIM-C: A C++ implementation of the Auditory Image Model
 // http://www.acousticscale.org/AIMC
@@ -16,6 +16,50 @@
 // You should have received a copy of the GNU General Public License
 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-int main () {
- // TODO
+#include <string>
+
+#include <stdlib.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/SAI/ModuleSAI.h"
+//#include "Modules/SSI/ModuleSSI.h"
+//#include "Modules/Profile/ModuleProfile.h"
+#include "Modules/Features/ModuleGaussians.h"
+#include "Modules/Output/FileOutputHTK.h"
+
+int main (int argc, char* argv[]) {
+  aimc::Parameters params;
+  aimc::ModuleFileInput input(&params);
+  //aimc::ModuleGammatone bmm(&params);
+  aimc::ModulePZFC bmm(&params);
+  aimc::ModuleHCL nap(&params);
+  aimc::ModuleParabola strobes(&params);
+  aimc::ModuleSAI sai(&params);
+  //aimc::ModuleSSI ssi(&params);
+  //aimc::ModuleProfile profile(&params);
+  aimc::ModuleGaussians features(&params);
+  aimc::FileOutputHTK output(&params);
+
+  std::string parameters_string = params.WriteString();
+  printf("%s", parameters_string.c_str());
+
+  input.AddTarget(&bmm);
+  bmm.AddTarget(&nap);
+  nap.AddTarget(&strobes);
+  strobes.AddTarget(&sai);
+  sai.AddTarget(&features);
+  //ssi.AddTarget(&profile);
+  //profile.AddTarget(&features);
+  features.AddTarget(&output);
+
+  output.OpenFile("test_output.htk", params.GetFloat("sai.frame_period_ms"));
+  if (input.LoadFile("test.wav")) {
+    input.Process();
+  } else {
+    printf("LoadFile failed");
+  }
 }
\ No newline at end of file
--- a/src/Modules/Features/ModuleGaussians.cc	Thu Feb 18 16:55:40 2010 +0000
+++ b/src/Modules/Features/ModuleGaussians.cc	Thu Feb 18 19:35:07 2010 +0000
@@ -32,8 +32,7 @@
 #include "Support/Common.h"
 
 namespace aimc {
-ModuleGaussians::ModuleGaussians(Parameters *pParam)
-: Module(pParam) {
+ModuleGaussians::ModuleGaussians(Parameters *params) : Module(params) {
   // Set module metadata
   module_description_ = "Gaussian Fitting to SSI profile";
   module_identifier_ = "gaussians";
--- a/src/Modules/Input/ModuleFileInput.cc	Thu Feb 18 16:55:40 2010 +0000
+++ b/src/Modules/Input/ModuleFileInput.cc	Thu Feb 18 19:35:07 2010 +0000
@@ -31,13 +31,17 @@
 
 namespace aimc {
 ModuleFileInput::ModuleFileInput(Parameters *params) : Module(params) {
+  module_description_ = "File input using libsndfile";
+  module_identifier_ = "file_input";
+  module_type_ = "input";
+  module_version_ = "$Id$";
+
 	file_handle_ = NULL;
 	buffer_length_ = parameters_->DefaultInt("input.buffersize", 1024);
 
   file_position_samples_ = 0;
   file_loaded_ = false;
   audio_channels_ = 0;
-  buffer_length_ = 0;
   sample_rate_ = 0.0f;
 }
 
@@ -78,6 +82,11 @@
   return Module::Initialize(s);
 }
 
+
+/* Do not call Initialize() on ModuleFileInput directly
+ * instead call LoadFile() with a filename to load.
+ * This will automatically initialize the module.
+ */
 bool ModuleFileInput::Initialize(const SignalBank& input) {
   LOG_ERROR(_T("Do not call Initialize() on ModuleFileInput directly "
                "instead call LoadFile() with a filename to load. "
@@ -91,13 +100,21 @@
 }
 
 bool ModuleFileInput::InitializeInternal(const SignalBank& input) {
-  if (!file_loaded_)
+  if (!file_loaded_) {
+    LOG_ERROR(_T("No file loaded in FileOutputHTK"));
     return false;
+  }
+  if (audio_channels_ < 1 || buffer_length_ < 1 || sample_rate_ < 0.0f) {
+    LOG_ERROR(_T("audio_channels, buffer_length_ or sample_rate too small"));
+    return false;
+  }
   ResetInternal();
 	return true;
 }
 
 void ModuleFileInput::Process() {
+  if (!file_loaded_)
+    return;
 	sf_count_t read;
   vector<float> buffer;
   buffer.resize(buffer_length_ * audio_channels_);
--- a/src/Modules/Output/FileOutputHTK.cc	Thu Feb 18 16:55:40 2010 +0000
+++ b/src/Modules/Output/FileOutputHTK.cc	Thu Feb 18 19:35:07 2010 +0000
@@ -40,6 +40,11 @@
 
 namespace aimc {
 FileOutputHTK::FileOutputHTK(Parameters *params) : Module(params) {
+  module_description_ = "File output in HTK format";
+  module_identifier_ = "htk_out";
+  module_type_ = "output";
+  module_version_ = "$Id$";
+
 	file_handle_ = NULL;
 	header_written_ = false;
   filename_[0] = '\0';
--- a/src/Modules/SAI/ModuleSAI.cc	Thu Feb 18 16:55:40 2010 +0000
+++ b/src/Modules/SAI/ModuleSAI.cc	Thu Feb 18 19:35:07 2010 +0000
@@ -57,7 +57,8 @@
   // The SAI output bank must be as long as the SAI's Maximum delay.
   // One sample is added to the SAI buffer length to account for the
   // zero-lag point
-  int sai_buffer_length = 1 + floor(input.sample_rate() * max_delay_ms_);
+  int sai_buffer_length = 1 + floor(input.sample_rate() * max_delay_ms_
+                                    / 1000.0f);
   channel_count_ = input.channel_count();
 
   // Make an output SignalBank with the same number of channels and centre
--- a/src/Support/Common.cc	Thu Feb 18 16:55:40 2010 +0000
+++ b/src/Support/Common.cc	Thu Feb 18 19:35:07 2010 +0000
@@ -35,4 +35,12 @@
   printf("\n");
   va_end(args);
 }
+
+void LOG_INFO_NN(const char *sFmt, ...) {
+  va_list args;
+  va_start(args, sFmt);
+  // Just print message to console (will be lost on windows with gui)
+  vprintf(sFmt, args);
+  va_end(args);
+}
 }  // namespace aimc
--- a/src/Support/Common.h	Thu Feb 18 16:55:40 2010 +0000
+++ b/src/Support/Common.h	Thu Feb 18 19:35:07 2010 +0000
@@ -96,6 +96,7 @@
 namespace aimc {
 void LOG_ERROR(const char *sFmt, ...);
 void LOG_INFO(const char *sFmt, ...);
+void LOG_INFO_NN(const char *sFmt, ...);
 }  // namespace aimc
 
 #endif  // _AIMC_SUPPORT_COMMON_H_
--- a/src/Support/Module.cc	Thu Feb 18 16:55:40 2010 +0000
+++ b/src/Support/Module.cc	Thu Feb 18 19:35:07 2010 +0000
@@ -45,13 +45,15 @@
 };
 
 bool Module::Initialize(const SignalBank &input) {
+  LOG_INFO_NN(_T("-> %s "), module_identifier_.c_str());
   // Validate the input
   if (!input.Validate()) {
-    LOG_ERROR("Input SignalBank not valid");
+    LOG_ERROR(_T("Input SignalBank not valid"));
     return false;
   }
   if (!InitializeInternal(input)) {
-    LOG_ERROR("Module initialization failed");
+    LOG_ERROR(_T("Initialization failed in module %s"),
+              module_identifier_.c_str());
     return false;
   }
   // If the module has an output bank, then we can set up the targets
@@ -59,7 +61,8 @@
   if (output_.initialized()) {
     // Check that the output SignalBank has been set up correctly
     if (!output_.Validate()) {
-      LOG_ERROR("Output SignalBank not valid");
+      LOG_ERROR(_T("Output SignalBank not valid in module %s"),
+                module_identifier_.c_str());
       return false;
     }
     // Iterate through all the targets of this module, initializing
@@ -73,6 +76,8 @@
         if (!(*it)->Initialize(output_))
           return false;
     }
+  } else {
+    LOG_INFO(_T("|"));
   }
   initialized_ = true;
   return true;