Mercurial > hg > aimc
changeset 292:10d0803e37ec
-Added a module to scale output values by the channel centre frequency
-Fixed file input to support loading and processing of multiple files
-Updated the aimc main file to generate profiles like in the recognition experiments
author | tomwalters |
---|---|
date | Mon, 22 Feb 2010 17:51:27 +0000 |
parents | 2d3cef76b073 |
children | aeac9e2151c6 |
files | trunk/SConstruct trunk/src/Main/aimc.cc trunk/src/Modules/Features/ModuleGaussians.cc trunk/src/Modules/Input/ModuleFileInput.cc trunk/src/Modules/Output/FileOutputHTK.cc trunk/src/Modules/Profile/ModuleScaler.cc trunk/src/Modules/Profile/ModuleScaler.h trunk/src/Modules/Profile/ModuleSlice.cc trunk/src/Modules/Profile/ModuleSlice.h trunk/src/Support/Module.cc trunk/swig/aim_modules.i trunk/swig/setup.py |
diffstat | 12 files changed, 196 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/trunk/SConstruct Mon Feb 22 12:45:05 2010 +0000 +++ b/trunk/SConstruct Mon Feb 22 17:51:27 2010 +0000 @@ -42,6 +42,7 @@ 'Modules/SAI/ModuleSAI.cc', 'Modules/SSI/ModuleSSI.cc', 'Modules/Profile/ModuleSlice.cc', + 'Modules/Profile/ModuleScaler.cc', 'Modules/Features/ModuleGaussians.cc', 'Modules/Output/FileOutputHTK.cc']
--- a/trunk/src/Main/aimc.cc Mon Feb 22 12:45:05 2010 +0000 +++ b/trunk/src/Main/aimc.cc Mon Feb 22 17:51:27 2010 +0000 @@ -28,19 +28,27 @@ #include "Modules/SAI/ModuleSAI.h" #include "Modules/SSI/ModuleSSI.h" #include "Modules/Profile/ModuleSlice.h" +#include "Modules/Profile/ModuleScaler.h" #include "Modules/Features/ModuleGaussians.h" #include "Modules/Output/FileOutputHTK.h" int main(int argc, char* argv[]) { aimc::Parameters params; + + int buffer_length = 480; + params.SetInt("input.buffersize", buffer_length); + params.SetBool("slice.normalize", true); + params.SetFloat("nap.lowpass_cutoff", 100.0f); + aimc::ModuleFileInput input(¶ms); aimc::ModuleGammatone bmm(¶ms); // aimc::ModulePZFC bmm(¶ms); aimc::ModuleHCL nap(¶ms); - aimc::ModuleParabola strobes(¶ms); - aimc::ModuleSAI sai(¶ms); - aimc::ModuleSSI ssi(¶ms); + // aimc::ModuleParabola strobes(¶ms); + // aimc::ModuleSAI sai(¶ms); + // aimc::ModuleSSI ssi(¶ms); aimc::ModuleSlice profile(¶ms); + aimc::ModuleScaler scaler(¶ms); aimc::ModuleGaussians features(¶ms); aimc::FileOutputHTK output(¶ms); @@ -49,14 +57,26 @@ input.AddTarget(&bmm); bmm.AddTarget(&nap); - nap.AddTarget(&strobes); - strobes.AddTarget(&sai); - sai.AddTarget(&ssi); - ssi.AddTarget(&profile); - profile.AddTarget(&features); + nap.AddTarget(&profile); + //strobes.AddTarget(&sai); + //sai.AddTarget(&ssi); + //ssi.AddTarget(&profile); + profile.AddTarget(&scaler); + scaler.AddTarget(&features); features.AddTarget(&output); - output.OpenFile("test_output.htk", params.GetFloat("sai.frame_period_ms")); + float frame_period_ms = 1000.0f * buffer_length + / input.GetOutputBank()->sample_rate(); + + output.OpenFile("test_output.htk", frame_period_ms); + if (input.LoadFile("test.wav")) { + input.Process(); + } else { + printf("LoadFile failed"); + } + + input.Reset(); + output.OpenFile("test_output_2.htk", frame_period_ms); if (input.LoadFile("test.wav")) { input.Process(); } else {
--- a/trunk/src/Modules/Features/ModuleGaussians.cc Mon Feb 22 12:45:05 2010 +0000 +++ b/trunk/src/Modules/Features/ModuleGaussians.cc Mon Feb 22 17:51:27 2010 +0000 @@ -79,6 +79,10 @@ void ModuleGaussians::ResetInternal() { m_pSpectralProfile.clear(); m_pSpectralProfile.resize(m_iNumChannels, 0.0f); + m_pA.clear(); + m_pA.resize(m_iParamNComp, 0.0f); + m_pMu.clear(); + m_pMu.resize(m_iParamNComp, 0.0f); } void ModuleGaussians::Process(const SignalBank &input) {
--- a/trunk/src/Modules/Input/ModuleFileInput.cc Mon Feb 22 12:45:05 2010 +0000 +++ b/trunk/src/Modules/Input/ModuleFileInput.cc Mon Feb 22 17:51:27 2010 +0000 @@ -46,8 +46,10 @@ } ModuleFileInput::~ModuleFileInput() { - if (file_handle_) + if (file_handle_ != NULL) { sf_close(file_handle_); + file_handle_ = NULL; + } } void ModuleFileInput::ResetInternal() { @@ -56,9 +58,15 @@ } bool ModuleFileInput::LoadFile(const char* filename) { + // If there's a file open. Close it. + if (file_handle_ != NULL) { + sf_close(file_handle_); + file_handle_ = NULL; + } // Open the file SF_INFO sfinfo; memset(reinterpret_cast<void*>(&sfinfo), 0, sizeof(SF_INFO)); + file_handle_ = sf_open(filename, SFM_READ, &sfinfo); if (file_handle_ == NULL) {
--- a/trunk/src/Modules/Output/FileOutputHTK.cc Mon Feb 22 12:45:05 2010 +0000 +++ b/trunk/src/Modules/Output/FileOutputHTK.cc Mon Feb 22 17:51:27 2010 +0000 @@ -69,6 +69,9 @@ sample_count_ = 0; frame_period_ms_ = frame_period_ms; header_written_ = false; + if (initialized_) { + WriteHeader(channel_count_ * buffer_length_, frame_period_ms_); + } return true; } @@ -79,7 +82,7 @@ return false; } if (header_written_) { - LOG_ERROR(_T("A header has already been written on the output file." + LOG_ERROR(_T("A header has already been written on the output file. " "Please call FileOutputHTK::CloseFile to close that file, " "and FileOutputHTK::OpenFile to open an new one before " "calling FileOutputHTK::Initialize again.")); @@ -95,6 +98,8 @@ if (file_handle_ != NULL && !header_written_) { WriteHeader(channel_count_ * buffer_length_, frame_period_ms_); } + if (file_handle_ != NULL) + CloseFile(); } void FileOutputHTK::WriteHeader(int num_elements, float period_ms) { @@ -144,7 +149,7 @@ } if (!header_written_) { - LOG_ERROR(_T("No header has been written on the output file yet. Please" + LOG_ERROR(_T("No header has been written on the output file yet. Please " "call FileOutputHTK::Initialize() before calling " "FileOutputHTK::Process()")); return; @@ -177,6 +182,7 @@ // And close the file fclose(file_handle_); file_handle_ = NULL; + header_written_ = false; return true; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/Modules/Profile/ModuleScaler.cc Mon Feb 22 17:51:27 2010 +0000 @@ -0,0 +1,79 @@ +// Copyright 2010, Thomas Walters +// +// AIM-C: A C++ implementation of the Auditory Image Model +// http://www.acousticscale.org/AIMC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. + +/*! + * \author Thomas Walters <tom@acousticscale.org> + * \date created 2010/02/22 + * \version \$Id$ + */ + +#include "Modules/Profile/ModuleScaler.h" + +namespace aimc { +ModuleScaler::ModuleScaler(Parameters *params) : Module(params) { + module_description_ = "Scale each value by the channel centre frequency"; + module_identifier_ = "scaler"; + module_type_ = "profile"; + module_version_ = "$Id$"; +} + +ModuleScaler::~ModuleScaler() { +} + +bool ModuleScaler::InitializeInternal(const SignalBank &input) { + // Copy the parameters of the input signal bank into internal variables, so + // that they can be checked later. + sample_rate_ = input.sample_rate(); + buffer_length_ = input.buffer_length(); + channel_count_ = input.channel_count(); + output_.Initialize(channel_count_, buffer_length_, sample_rate_); + return true; +} + +void ModuleScaler::ResetInternal() { +} + +void ModuleScaler::Process(const SignalBank &input) { + // Check to see if the module has been initialized. If not, processing + // should not continue. + if (!initialized_) { + LOG_ERROR(_T("Module %s not initialized."), module_identifier_.c_str()); + return; + } + + // Check that ths input this time is the same as the input passed to + // Initialize() + if (buffer_length_ != input.buffer_length() + || channel_count_ != input.channel_count()) { + LOG_ERROR(_T("Mismatch between input to Initialize() and input to " + "Process() in module %s."), module_identifier_.c_str()); + return; + } + + output_.set_start_time(input.start_time()); + + for (int ch = 0; ch < input.channel_count(); ++ch) { + float cf = input.centre_frequency(ch); + for (int i = 0; i < input.buffer_length(); ++i) { + output_.set_sample(ch, i, cf * input.sample(ch, i)); + } + } + PushOutput(); +} +} // namespace aimc +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/Modules/Profile/ModuleScaler.h Mon Feb 22 17:51:27 2010 +0000 @@ -0,0 +1,58 @@ +// Copyright 2010, Thomas Walters +// +// AIM-C: A C++ implementation of the Auditory Image Model +// http://www.acousticscale.org/AIMC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. + +/*! + * \author Thomas Walters <tom@acousticscale.org> + * \date created 2010/02/19 + * \version \$Id$ + */ + +#ifndef AIMC_MODULES_PROFILE_SLICE_H_ +#define AIMC_MODULES_PROFILE_SLICE_H_ + +#include "Support/Module.h" + +namespace aimc { +using std::vector; +class ModuleScaler : public Module { + public: + explicit ModuleScaler(Parameters *pParam); + virtual ~ModuleScaler(); + + /*! \brief Process a buffer + */ + virtual void Process(const SignalBank &input); + + private: + /*! \brief Reset the internal state of the module + */ + virtual void ResetInternal(); + + /*! \brief Prepare the module + * \param input Input signal + * \param output true on success false on failure + */ + virtual bool InitializeInternal(const SignalBank &input); + + float sample_rate_; + int buffer_length_; + int channel_count_; +}; +} // namespace aimc + +#endif // AIMC_MODULES_PROFILE_SLICE_H_
--- a/trunk/src/Modules/Profile/ModuleSlice.cc Mon Feb 22 12:45:05 2010 +0000 +++ b/trunk/src/Modules/Profile/ModuleSlice.cc Mon Feb 22 17:51:27 2010 +0000 @@ -125,6 +125,7 @@ } } else { for (int ch = 0; ch < input.channel_count(); ++ch) { + output_.set_centre_frequency(ch, input.centre_frequency(ch)); float val = 0.0f; for (int i = lower_limit_; i < upper_limit_; ++i) { val += input.sample(ch, i);
--- a/trunk/src/Modules/Profile/ModuleSlice.h Mon Feb 22 12:45:05 2010 +0000 +++ b/trunk/src/Modules/Profile/ModuleSlice.h Mon Feb 22 17:51:27 2010 +0000 @@ -22,8 +22,8 @@ * \version \$Id$ */ -#ifndef AIMC_MODULES_PROFILE_SLICE_H_ -#define AIMC_MODULES_PROFILE_SLICE_H_ +#ifndef AIMC_MODULES_PROFILE_SCALER_H_ +#define AIMC_MODULES_PROFILE_SCALER_H_ #include "Support/Module.h" @@ -62,4 +62,4 @@ }; } // namespace aimc -#endif // AIMC_MODULES_PROFILE_SLICE_H_ +#endif // AIMC_MODULES_PROFILE_SCALER_H_
--- a/trunk/src/Support/Module.cc Mon Feb 22 12:45:05 2010 +0000 +++ b/trunk/src/Support/Module.cc Mon Feb 22 17:51:27 2010 +0000 @@ -87,6 +87,7 @@ if (!initialized_) return; + LOG_INFO("Resetting module %s", module_identifier_.c_str()); ResetInternal(); // Iterate through all the targets of this module, resetting
--- a/trunk/swig/aim_modules.i Mon Feb 22 12:45:05 2010 +0000 +++ b/trunk/swig/aim_modules.i Mon Feb 22 17:51:27 2010 +0000 @@ -30,6 +30,7 @@ #include "Modules/SAI/ModuleSAI.h" #include "Modules/SSI/ModuleSSI.h" #include "Modules/Profile/ModuleSlice.h" +#include "Modules/Profile/ModuleScaler.h" #include "Modules/Features/ModuleGaussians.h" #include "Modules/Output/FileOutputHTK.h" %} @@ -44,5 +45,6 @@ %include "Modules/SAI/ModuleSAI.h" %include "Modules/SSI/ModuleSSI.h" %include "Modules/Profile/ModuleSlice.h" +%include "Modules/Profile/ModuleScaler.h" %include "Modules/Features/ModuleGaussians.h" %include "Modules/Output/FileOutputHTK.h"
--- a/trunk/swig/setup.py Mon Feb 22 12:45:05 2010 +0000 +++ b/trunk/swig/setup.py Mon Feb 22 17:51:27 2010 +0000 @@ -37,6 +37,7 @@ '../src/Modules/SAI/ModuleSAI.cc', '../src/Modules/SSI/ModuleSSI.cc', '../src/Modules/Profile/ModuleSlice.cc', + '../src/Modules/Profile/ModuleScaler.cc', '../src/Modules/Output/FileOutputHTK.cc'], swig_opts = ['-c++','-I../src/'], include_dirs=['../src/']