Mercurial > hg > aimc
changeset 278:5b8b9ea1218a
- 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 | 6b4921704eb1 |
children | f469d936337f |
files | 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/SAI/ModuleSAI.cc trunk/src/Support/Common.cc trunk/src/Support/Common.h trunk/src/Support/Module.cc |
diffstat | 8 files changed, 91 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/trunk/src/Main/aimc.cc Thu Feb 18 16:55:40 2010 +0000 +++ b/trunk/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(¶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::ModuleProfile profile(¶ms); + aimc::ModuleGaussians features(¶ms); + aimc::FileOutputHTK output(¶ms); + + 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/trunk/src/Modules/Features/ModuleGaussians.cc Thu Feb 18 16:55:40 2010 +0000 +++ b/trunk/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/trunk/src/Modules/Input/ModuleFileInput.cc Thu Feb 18 16:55:40 2010 +0000 +++ b/trunk/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/trunk/src/Modules/Output/FileOutputHTK.cc Thu Feb 18 16:55:40 2010 +0000 +++ b/trunk/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/trunk/src/Modules/SAI/ModuleSAI.cc Thu Feb 18 16:55:40 2010 +0000 +++ b/trunk/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/trunk/src/Support/Common.cc Thu Feb 18 16:55:40 2010 +0000 +++ b/trunk/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/trunk/src/Support/Common.h Thu Feb 18 16:55:40 2010 +0000 +++ b/trunk/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/trunk/src/Support/Module.cc Thu Feb 18 16:55:40 2010 +0000 +++ b/trunk/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;