Mercurial > hg > aimc
changeset 121:3cdaa81c3aca
- Massive refactoring to make module tree stuff work. In theory we now support configuration files again. The graphics stuff is untested as yet.
line wrap: on
line diff
--- a/SConstruct Sun Oct 17 02:42:12 2010 +0000 +++ b/SConstruct Mon Oct 18 04:42:28 2010 +0000 @@ -38,6 +38,7 @@ 'Support/Parameters.cc', 'Support/Module.cc', 'Support/ModuleFactory.cc', + 'Support/ModuleTree.cc', 'Modules/Input/ModuleFileInput.cc', 'Modules/BMM/ModuleGammatone.cc', 'Modules/BMM/ModulePZFC.cc', @@ -50,26 +51,28 @@ 'Modules/Profile/ModuleScaler.cc', 'Modules/Output/FileOutputHTK.cc', 'Modules/Output/FileOutputAIMC.cc', - 'Modules/Features/ModuleGaussians.cc'] + 'Modules/Features/ModuleGaussians.cc', + 'Modules/Features/ModuleDCT.cc' ] graphics_sources = [ 'Modules/Output/Graphics/GraphAxisSpec.cc', 'Modules/Output/Graphics/GraphicsView.cc', 'Modules/Output/Graphics/GraphicsViewTime.cc', + 'Modules/Output/Graphics/Scale/Scale.cc', 'Modules/Output/Graphics/Devices/GraphicsOutputDevice.cc', 'Modules/Output/Graphics/Devices/GraphicsOutputDeviceCairo.cc', - 'Modules/Output/Graphics/Devices/GraphicsOutputDeviceMovie.cc', - 'Modules/Output/Graphics/Devices/GraphicsOutputDeviceMovieDirect.cc' ] + 'Modules/Output/Graphics/Devices/GraphicsOutputDeviceMovie.cc',] + #'Modules/Output/Graphics/Devices/GraphicsOutputDeviceMovieDirect.cc' ] graphics_libraries = [ 'cairo', - '' ] + ] # List of currently incative source files which we may want to add back in sources_disabled = ['Modules/SNR/ModuleNoise.cc', ] # File which contains main() -sources = common_sources + ['Main/AIMCopy_SSI_Features_v3.cc'] +#sources = common_sources + graphics_sources + ['Main/AIMCopy_SSI_Features_v3.cc'] #sources = common_sources + ['Main/AIMCopy_SSI_Features_v4_PZFC.cc'] -#sources = common_sources + ['Main/AIMCopy_SSI_Features_v5_smooth_nap.cc'] +sources = common_sources + graphics_sources + ['Main/AIMCopy.cc'] #sources = common_sources + ['Main/aimc.cc'] # Test sources @@ -134,7 +137,7 @@ elif compiler == 'gcc': env['STRIP'] = 'strip' env.AppendUnique(CPPFLAGS = ['-Wall']) - env.AppendUnique(CPPFLAGS = ['-O3', '-fomit-frame-pointer']) + env.AppendUnique(CPPFLAGS = ['-O2',])# '-fomit-frame-pointer']) if env['symbols']: env.AppendUnique(CPPFLAGS = ['-g']) if env['mingw']: @@ -170,6 +173,7 @@ # Dependencies deplibs = ['sndfile'] +deplibs += graphics_libraries if target_platform != 'win32': for depname in deplibs:
--- a/experiments/scripts/cnbh-syllables/feature_generation/nap_profile_features.aimcopycfg Sun Oct 17 02:42:12 2010 +0000 +++ b/experiments/scripts/cnbh-syllables/feature_generation/nap_profile_features.aimcopycfg Mon Oct 18 04:42:28 2010 +0000 @@ -10,7 +10,7 @@ module2.child1 = SmoothNAP module3.name = SmoothNAP -module3.id = nap +module3.id = hcl module3.parameters = <<<ENDPARAMS nap.lowpass_cutoff = 100.0 ENDPARAMS @@ -27,5 +27,5 @@ module5.id = gaussians module5.child1 = SmoothNAPOutput -moudule6.name = SmoothNAPOutput -module6.id = htk_out \ No newline at end of file +module6.name = SmoothNAPOutput +module6.id = htk_out
--- a/experiments/scripts/cnbh-syllables/feature_generation/ssi_profile_features.aimcopycfg Sun Oct 17 02:42:12 2010 +0000 +++ b/experiments/scripts/cnbh-syllables/feature_generation/ssi_profile_features.aimcopycfg Mon Oct 18 04:42:28 2010 +0000 @@ -11,7 +11,7 @@ module2.child2 = SmoothNAP module3.name = SmoothNAP -module3.id = nap +module3.id = hcl module3.parameters = <<<ENDPARAMS nap.lowpass_cutoff = 100.0 ENDPARAMS @@ -22,13 +22,127 @@ module4.parameters = <<<ENDPARAMS slice.all = true ENDPARAMS -module4.child1 = SmoothNAPFeatures +module4.child1 = NAPScaler -module5.name = SmoothNAPFeatures -module5.id = gaussians -module5.child1 = SmoothNAPOutput +module5.name = NAPScaler +module5.id = scaler +module5.child1 = SmoothNAPFeatures -moudule6.name = SmoothNAPOutput -module6.id = htk_out +module6.name = SmoothNAPFeatures +module6.id = gaussians +module6.child1 = SmoothNAPOutput -module7.name = \ No newline at end of file +module7.name = SmoothNAPOutput +module7.id = htk_out +module7.parameters = <<<ENDPARAMS +htk_out.file_suffix=.smooth_nap_profile +ENDPARAMS + +module8.name = StandardNAP +module8.id = hcl +module8.child1 = Strobes + +module9.name = Strobes +module9.id = local_max +module9.child1 = SAI + +module10.name = SAI +module10.id = weighted_sai +module10.child1 = SSINoPitchCutoff +module10.child2 = SSIPitchCutoff + +module11.name = SSINoPitchCutoff +module11.id = ssi +module11.parameters = <<<ENDPARAMS +ssi.pitch_cutoff = false +ENDPARAMS +module11.child1 = SSINoCutoffCycle1Slice +module11.child2 = SSINoCutoffWholeSlice + +module12.name = SSIPitchCutoff +module12.id = ssi +module12.parameters = <<<ENDPARAMS +ssi.pitch_cutoff = true +ssi.pitch_search_start_ms = 4.6 +ENDPARAMS +module12.child1 = SSICutoffCycle1Slice +module12.child2 = SSICutoffWholeSlice + +module13.name = SSICutoffCycle1Slice +module13.id = slice +module13.parameters = <<<ENDPARAMS +slice.all = false +slice.lower_index = 77 +slice.upper_index = 150 +ENDPARAMS +module13.child1 = SSICutoffCycle1SliceFeatures + +module14.name = SSICutoffWholeSlice +module14.id = slice +module14.parameters = <<<ENDPARAMS +slice.all = true +ENDPARAMS +module14.child1 = SSICutoffWholeSliceFeatures + +module15.name = SSINoCutoffCycle1Slice +module15.id = slice +module15.parameters = <<<ENDPARAMS +slice.all = false +slice.lower_index = 77 +slice.upper_index = 150 +ENDPARAMS +module15.child1 = SSINoCutoffCycle1SliceFeatures + +module16.name = SSINoCutoffWholeSlice +module16.id = slice +module16.parameters = <<<ENDPARAMS +slice.all = true +ENDPARAMS +module16.child1 = SSINoCutoffWholeSliceFeatures + +module17.name = SSICutoffCycle1SliceFeatures +module17.id = gaussians +module17.child1 = SSICutoffCycle1SliceOutput + +module18.name = SSINoCutoffCycle1SliceFeatures +module18.id = gaussians +module18.child1 = SSINoCutoffCycle1SliceOutput + +module19.name = SSICutoffWholeSliceFeatures +module19.id = gaussians +module19.child1 = SSICutoffWholeSliceOutput + +module20.name = SSINoCutoffWholeSliceFeatures +module20.id = gaussians +module20.child1 = SSINoCutoffWholeSliceOutput + + +module21.name = SSICutoffCycle1SliceOutput +module21.parameters = <<<ENDPARAMS +htk_out.file_suffix = .slice_1_cutoff +ENDPARAMS +module21.id = htk_out + +module22.name = SSINoCutoffCycle1SliceOutput +module22.parameters = <<<ENDPARAMS +htk_out.file_suffix = .slice_1_no_cutoff +ENDPARAMS +module22.id = htk_out + +module23.name = SSICutoffWholeSliceOutput +module23.parameters = <<<ENDPARAMS +htk_out.file_suffix = .ssi_profile_cutoff +ENDPARAMS +module23.id = htk_out + +module24.name = SSINoCutoffWholeSliceOutput +module24.parameters = <<<ENDPARAMS +htk_out.file_suffix = .ssi_profile_no_cutoff +ENDPARAMS +module24.id = htk_out + + + + + +
--- a/src/Main/AIMCopy.cc Sun Oct 17 02:42:12 2010 +0000 +++ b/src/Main/AIMCopy.cc Mon Oct 18 04:42:28 2010 +0000 @@ -43,50 +43,166 @@ #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/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" #include "Support/Common.h" #include "Support/FileList.h" +#include "Support/ModuleTree.h" #include "Support/Parameters.h" +namespace aimc { using std::ofstream; using std::pair; using std::vector; using std::string; +class AIMCopy { + public: + AIMCopy(); + + bool Initialize(string script_filename, + string config_filename); + + bool WriteConfig(string config_dump_filename, + string config_graph_filename); + + bool Process(); + + private: + bool initialized_; + Parameters global_parameters_; + ModuleTree tree_; + vector<pair<string, string> > script_; +}; + + +AIMCopy::AIMCopy() : initialized_(false) { + +} + +bool AIMCopy::Initialize(string script_filename, + string config_filename) { + + LOG_INFO("AIMCopy: Loading script"); + script_ = FileList::Load(script_filename); + if (script_.size() == 0) { + LOG_ERROR("No data read from script file %s", script_filename.c_str()); + return false; + } + + LOG_INFO("AIMCopy: Loading configuration"); + if (!tree_.LoadConfigFile(config_filename)) { + LOG_ERROR(_T("Failed to load configuration file")); + return false; + } + LOG_INFO("AIMCopy: Successfully loaded configuration"); + initialized_ = true; + return true; +} + +bool AIMCopy::WriteConfig(string config_dump_filename, + string config_graph_filename) { + if (!initialized_) { + return false; + } + + if (script_.size() > 0) { + global_parameters_.SetString("input_filename", script_[0].first.c_str()); + global_parameters_.SetString("output_filename_base", script_[0].second.c_str()); + LOG_INFO("AIMCopy: Initializing tree for initial parameter write."); + if (!tree_.Initialize(&global_parameters_)) { + LOG_ERROR(_T("Failed to initialize tree.")); + return false; + } + } else { + LOG_ERROR(_T("No input files in script.")); + return false; + } + + if (!config_dump_filename.empty()) { + LOG_INFO("AIMCopy: Dumping configuration."); + ofstream output_stream; + output_stream.open(config_dump_filename.c_str()); + if (output_stream.fail()) { + LOG_ERROR(_T("Failed to open configuration file %s for writing."), + config_dump_filename.c_str()); + return false; + } + + time_t rawtime; + struct tm * timeinfo; + time(&rawtime); + timeinfo = localtime(&rawtime); + output_stream << "# AIM-C AIMCopy\n"; + output_stream << "# Run at: " << asctime(timeinfo); + char * descr = getenv("USER"); + if (descr) { + output_stream << "# By user: " << descr <<"\n"; + } + tree_.PrintConfiguration(output_stream); + output_stream.close(); + } + + if (!config_graph_filename.empty()) { + ofstream output_stream; + output_stream.open(config_graph_filename.c_str()); + if (output_stream.fail()) { + LOG_ERROR(_T("Failed to open graph file %s for writing."), + config_graph_filename.c_str()); + return false; + } + tree_.MakeDotGraph(output_stream); + output_stream.close(); + } + return true; +} + +bool AIMCopy::Process() { + if (!initialized_) { + return false; + } + for (unsigned int i = 0; i < script_.size(); ++i) { + global_parameters_.SetString("input_filename", script_[i].first.c_str()); + global_parameters_.SetString("output_filename_base", script_[i].second.c_str()); + if (!tree_.Initialize(&global_parameters_)) { + return false; + } + aimc::LOG_INFO(_T("%s -> %s"), + script_[i].first.c_str(), + script_[i].second.c_str()); + tree_.Reset(); + tree_.Process(); + } + return true; +} + +} // namespace aimc + 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; + std::string data_file; + std::string dot_file; + std::string config_file; + std::string script_file; - string version_string( + const std::string version_string( " AIM-C AIMCopy\n" " (c) 2006-2010, Thomas Walters and Willem van Engen\n" " http://www.acoustiscale.org/AIMC/\n" - "\n"); + "\n"); + + const std::string usage_string( + "AIMCopy is intended as a drop-in replacement for HTK's HCopy\n" + "command. It is used for making features from audio files for\n" + "use with HTK.\n" + "Usage: \n" + " <flag> <meaning> <default>\n" + " -A Print command line arguments off\n" + " -C cf Set config file to cf none\n" + " -S f Set script file to f none\n" + " -V Print version information off\n" + " -D d Write complete parameter set to file d none\n" + " -G g Write graph to file g none\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"); + std::cout << version_string.c_str(); + std::cout << usage_string.c_str(); return -1; } @@ -121,95 +237,42 @@ return(-1); } data_file = argv[i]; - write_data = true; continue; } - if (strcmp(argv[i],"-V") == 0) { - print_version = true; + if (strcmp(argv[i],"-G") == 0) { + if (++i >= argc) { + aimc::LOG_ERROR(_T("Graph file name expected after -D")); + return(-1); + } + dot_file = argv[i]; + continue; + } + if (strcmp(argv[i],"-V") == 0) { + std::cout << version_string; 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 (!params.Load(config_file.c_str())) { - aimc::LOG_ERROR(_T("Couldn't load parameters from file %s"), - config_file.c_str()); + std::cout << "Configuration file: " << config_file << std::endl; + std::cout << "Script file: " << script_file << std::endl; + std::cout << "Data file: " << data_file << std::endl; + std::cout << "Graph file: " << dot_file << std::endl; + + aimc::AIMCopy processor; + aimc::LOG_INFO("main: Initializing..."); + if (!processor.Initialize(script_file, config_file)) { 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()); + + aimc::LOG_INFO("main: Writing confg..."); + if (!processor.WriteConfig(data_file, dot_file)) { return -1; } - - // Set up AIM-C processor here - aimc::ModuleFileInput input(¶ms); - aimc::ModuleGammatone bmm(¶ms); - aimc::ModuleHCL nap(¶ms); - aimc::ModuleSlice profile(¶ms); - aimc::ModuleScaler scaler(¶ms); - aimc::ModuleGaussians features(¶ms); - aimc::FileOutputHTK output(¶ms); - - input.AddTarget(&bmm); - bmm.AddTarget(&nap); - nap.AddTarget(&profile); - profile.AddTarget(&scaler); - scaler.AddTarget(&features); - features.AddTarget(&output); - - 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: file_input->gt->hcl->slice->scaler->"; - outfile << "gaussians->out_htk\n"; - outfile << "# Module versions:\n"; - outfile << "# " << input.id() << " : " << input.version() << "\n"; - outfile << "# " << bmm.id() << " : " << bmm.version() << "\n"; - outfile << "# " << nap.id() << " : " << nap.version() << "\n"; - outfile << "# " << profile.id() << " : " << profile.version() << "\n"; - outfile << "# " << scaler.id() << " : " << scaler.version() << "\n"; - outfile << "# " << features.id() << " : " << features.version() << "\n"; - outfile << "# " << output.id() << " : " << output.version() << "\n"; - outfile << "#\n"; - outfile << "# Parameters:\n"; - outfile << params.WriteString(); - outfile.close(); - } - - for (unsigned int i = 0; i < file_list.size(); ++i) { - aimc::LOG_INFO(_T("In: %s"), file_list[i].first.c_str()); - aimc::LOG_INFO(_T("Out: %s"), file_list[i].second.c_str()); - - output.OpenFile(file_list[i].second.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(); + + aimc::LOG_INFO("main: Processing..."); + if (!processor.Process()) { + return -1; } return 0;
--- a/src/Modules/BMM/ModuleGammatone.cc Sun Oct 17 02:42:12 2010 +0000 +++ b/src/Modules/BMM/ModuleGammatone.cc Mon Oct 18 04:42:28 2010 +0000 @@ -52,9 +52,13 @@ state_3_.resize(num_channels_); state_4_.resize(num_channels_); for (int i = 0; i < num_channels_; ++i) { + state_1_[i].clear(); state_1_[i].resize(3, 0.0f); + state_2_[i].clear(); state_2_[i].resize(3, 0.0f); + state_3_[i].clear(); state_3_[i].resize(3, 0.0f); + state_4_[i].clear(); state_4_[i].resize(3, 0.0f); } }
--- a/src/Modules/Input/ModuleFileInput.cc Sun Oct 17 02:42:12 2010 +0000 +++ b/src/Modules/Input/ModuleFileInput.cc Mon Oct 18 04:42:28 2010 +0000 @@ -52,11 +52,14 @@ } void ModuleFileInput::ResetInternal() { - output_.Initialize(audio_channels_, buffer_length_, sample_rate_); - output_.set_start_time(0); + // If there's a file open, rewind to the beginning. + if (file_handle_ != NULL) { + sf_seek(file_handle_, 0, SEEK_SET); + file_position_samples_ = 0; + } } -bool ModuleFileInput::LoadFile(const char* filename) { +bool ModuleFileInput::InitializeInternal(const SignalBank& input) { // If there's a file open. Close it. if (file_handle_ != NULL) { sf_close(file_handle_); @@ -66,98 +69,74 @@ SF_INFO sfinfo; memset(reinterpret_cast<void*>(&sfinfo), 0, sizeof(SF_INFO)); - file_handle_ = sf_open(filename, SFM_READ, &sfinfo); + file_loaded_ = false; + file_handle_ = sf_open(global_parameters_->GetString("input_filename"), + SFM_READ, + &sfinfo); if (file_handle_ == NULL) { /*! \todo Also display error reason */ - LOG_ERROR(_T("Couldn't read audio file '%s'"), filename); + LOG_ERROR(_T("Couldn't read audio file '%s'"), + global_parameters_->GetString("input_filename")); return false; } - + file_loaded_ = true; + done_ = false; audio_channels_ = sfinfo.channels; sample_rate_ = sfinfo.samplerate; file_position_samples_ = 0; - // A dummy signal bank to be passed to the Initialize() function. - SignalBank s; - s.Initialize(1, 1, 1); + if (audio_channels_ < 1 || buffer_length_ < 1 || sample_rate_ < 0.0f) { + LOG_ERROR(_T("Problem with file: audio_channels = %d, buffer_length_ = %d, sample_rate = %f"), audio_channels_, buffer_length_, sample_rate_); + return false; + } - // Self-initialize by calling Module::Initialize() explicitly. - // The Initialize() call in this subclass is overloaded to prevent it from - // being called drectly. - 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. " - "This will automatically initialize the module.")); - return false; + output_.Initialize(audio_channels_, buffer_length_, sample_rate_); + output_.set_start_time(0); + + return true; } void ModuleFileInput::Process(const SignalBank& input) { - LOG_ERROR(_T("Call Process() on ModuleFileInput instead of passing in " - "a SignalBank")); -} - -bool ModuleFileInput::InitializeInternal(const SignalBank& input) { - 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_); - while (true) { - // Read buffersize bytes into buffer - read = sf_readf_float(file_handle_, &buffer[0], buffer_length_); + // Read buffersize bytes into buffer + read = sf_readf_float(file_handle_, &buffer[0], buffer_length_); + + // Place the contents of the buffer into the signal bank + int counter = 0; + for (int c = 0; c < audio_channels_; ++c) { + for (int i = 0; i < read; ++i) { + output_.set_sample(c, i, buffer[counter]); + ++counter; + } + } - // Place the contents of the buffer into the signal bank - int counter = 0; + // If the number of saples read is less than the buffer length, the end + // of the file has been reached. + if (read < buffer_length_) { + // Zero samples at end for (int c = 0; c < audio_channels_; ++c) { - for (int i = 0; i < read; ++i) { - output_.set_sample(c, i, buffer[counter]); - ++counter; + for (int i = read; i < buffer_length_; ++i) { + output_.set_sample(c, i, 0.0f); } } + // When we're past the end of the buffer, set the + // module state to 'done' and exit. + if (read == 0) + done_ = true; + return; + } - // If the number of saples read is less than the buffer length, the end - // of the file has been reached. - if (read < buffer_length_) { - // Zero samples at end - for (int c = 0; c < audio_channels_; ++c) { - for (int i = read; i < buffer_length_; ++i) { - output_.set_sample(c, i, 0.0f); - } - } - // When we're past the end of the buffer, stop looping. - if (read == 0) - break; - } - - // Update time - output_.set_start_time(file_position_samples_); - file_position_samples_ += read; - PushOutput(); - } + // Update time. + output_.set_start_time(file_position_samples_); + file_position_samples_ += read; + PushOutput(); } } // namespace aimc
--- a/src/Modules/Input/ModuleFileInput.h Sun Oct 17 02:42:12 2010 +0000 +++ b/src/Modules/Input/ModuleFileInput.h Mon Oct 18 04:42:28 2010 +0000 @@ -39,23 +39,6 @@ explicit ModuleFileInput(Parameters *pParam); virtual ~ModuleFileInput(); - /*! \brief Initializes this input device using an audio file - * \param sFilename Path of the file to load - * \return true on success, false on error - */ - bool LoadFile(const char *sFilename); - - /*! \brief Process the loaded file. - */ - void Process(); - - /*! \brief Dummy Initialize function. Call LoadFile instead. - */ - virtual bool Initialize(const SignalBank &input); - - /*! \brief Dummy funciton to comply with the Module specification. Gives an - * error message when called. - */ virtual void Process(const SignalBank &input); private:
--- a/src/Modules/Output/FileOutputAIMC.cc Sun Oct 17 02:42:12 2010 +0000 +++ b/src/Modules/Output/FileOutputAIMC.cc Mon Oct 18 04:42:28 2010 +0000 @@ -42,7 +42,7 @@ namespace aimc { FileOutputAIMC::FileOutputAIMC(Parameters *params) : Module(params) { module_description_ = "File output in AIMC format"; - module_identifier_ = "htk_out"; + module_identifier_ = "aimc_out"; module_type_ = "output"; module_version_ = "$Id: FileOutputAIMC.cc 51 2010-03-30 22:06:24Z tomwalters $";
--- a/src/Modules/Output/FileOutputHTK.cc Sun Oct 17 02:42:12 2010 +0000 +++ b/src/Modules/Output/FileOutputHTK.cc Mon Oct 18 04:42:28 2010 +0000 @@ -45,10 +45,13 @@ module_identifier_ = "htk_out"; module_type_ = "output"; module_version_ = "$Id$"; + + file_suffix_ = parameters_->DefaultString("htk_out.file_suffix", ".htk"); file_handle_ = NULL; header_written_ = false; frame_period_ms_ = 0.0f; + previous_start_time_ = 0; } FileOutputHTK::~FileOutputHTK() { @@ -56,51 +59,42 @@ CloseFile(); } -bool FileOutputHTK::OpenFile(const char* filename, float frame_period_ms) { - if (file_handle_ != NULL) { - LOG_ERROR(_T("Couldn't open output file. A file is already open.")); +bool FileOutputHTK::InitializeInternal(const SignalBank &input) { + channel_count_ = input.channel_count(); + buffer_length_ = input.buffer_length(); + ResetInternal(); + if (file_handle_ == NULL) { + LOG_ERROR(_T("Couldn't initialize file output.")); return false; } - - // Check that the output file exists and is writeable - if ((file_handle_ = fopen(filename, "wb")) == NULL) { - LOG_ERROR(_T("Couldn't open output file '%s' for writing."), filename); - return false; - } - sample_count_ = 0; - frame_period_ms_ = frame_period_ms; - header_written_ = false; - if (initialized_) { + if (!header_written_) { WriteHeader(channel_count_ * buffer_length_, frame_period_ms_); } - return true; -} - -bool FileOutputHTK::InitializeInternal(const SignalBank &input) { - if (file_handle_ == NULL) { - LOG_ERROR(_T("Couldn't initialize file output. " - "Please call FileOutputHTK::OpenFile first")); - return false; - } - if (header_written_) { - 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.")); - return false; - } - channel_count_ = input.channel_count(); - buffer_length_ = input.buffer_length(); - WriteHeader(channel_count_ * buffer_length_, frame_period_ms_); + return true; } void FileOutputHTK::ResetInternal() { + // Finalize and close the open file, if there is one. if (file_handle_ != NULL && !header_written_) { WriteHeader(channel_count_ * buffer_length_, frame_period_ms_); } if (file_handle_ != NULL) CloseFile(); + + // Now open and set up the new file. + // Check that the output file exists and is writeable. + string out_filename; + out_filename = global_parameters_->GetString("output_filename_base") + file_suffix_; + if ((file_handle_ = fopen(out_filename.c_str(), + "wb")) == NULL) { + LOG_ERROR(_T("Couldn't open output file '%s' for writing."), + out_filename.c_str()); + return; + } + sample_count_ = 0; + header_written_ = false; + WriteHeader(channel_count_ * buffer_length_, frame_period_ms_); } void FileOutputHTK::WriteHeader(int num_elements, float period_ms) { @@ -150,8 +144,8 @@ if (!header_written_) { LOG_ERROR(_T("No header has been written on the output file yet. Please " - "call FileOutputHTK::Initialize() before calling " - "FileOutputHTK::Process()")); + "call FileOutputHTK::Initialize() or FileOutputHTK::Reset() " + " before calling FileOutputHTK::Process()")); return; } float s; @@ -164,6 +158,10 @@ } } sample_count_++; + frame_period_ms_ = 1000.0 + * (input.start_time() - previous_start_time_) + / input.sample_rate(); + previous_start_time_ = input.start_time(); } bool FileOutputHTK::CloseFile() {
--- a/src/Modules/Output/FileOutputHTK.h Sun Oct 17 02:42:12 2010 +0000 +++ b/src/Modules/Output/FileOutputHTK.h Mon Oct 18 04:42:28 2010 +0000 @@ -28,10 +28,12 @@ #ifndef AIMC_MODULES_OUTPUT_HTK_H_ #define AIMC_MODULES_OUTPUT_HTK_H_ +#include <string> + #include "Support/Module.h" #include "Support/SignalBank.h" -// Defines taken from HTKwrite.c and The HTK Book +// Defines from HTKwrite.c and The HTK Book #define H_WAVEFORM 0 // sampled waveform #define H_LPC 1 // linear prediction filter coefficients #define H_LPREFC 2 // linear prediction reflection coefficients @@ -69,6 +71,7 @@ ((((uint32_t) n) >> 24) & 0x000000FF) ) namespace aimc { +using std::string; class FileOutputHTK : public Module { public: /*! \brief Create a new file output for an HTK format file. Use of this @@ -82,7 +85,6 @@ * If the file exists it will be overwritten * \return Returns true on success of initialization. */ - bool OpenFile(const char *filename, float frame_period_ms); bool CloseFile(); virtual void Process(const SignalBank &input); private: @@ -104,10 +106,12 @@ /*! \brief Count of the number of samples in the file, written on close */ int sample_count_; + string file_suffix_; int channel_count_; int buffer_length_; float frame_period_ms_; + int previous_start_time_; }; } // namespace aimc
--- a/src/Modules/Output/Graphics/Devices/GraphicsOutputDeviceCairo.cc Sun Oct 17 02:42:12 2010 +0000 +++ b/src/Modules/Output/Graphics/Devices/GraphicsOutputDeviceCairo.cc Mon Oct 18 04:42:28 2010 +0000 @@ -263,7 +263,7 @@ float z, const char *sStr, bool bRotated) { - cairo_text_extents_t te; + //cairo_text_extents_t te; if (bRotated) { cairo_rotate(m_cCr, M_PI/2); cairo_move_to(m_cCr, x ,1-y);
--- a/src/Modules/Output/Graphics/Devices/GraphicsOutputDeviceMovie.cc Sun Oct 17 02:42:12 2010 +0000 +++ b/src/Modules/Output/Graphics/Devices/GraphicsOutputDeviceMovie.cc Mon Oct 18 04:42:28 2010 +0000 @@ -203,7 +203,7 @@ LOG_ERROR(_T("Couldn't remove files in temporary directory.")); return; } - while (dirent = readdir(dir)) { + while ((dirent = readdir(dir))) { snprintf(sCmdLine, sizeof(sCmdLine)/sizeof(sCmdLine[0]), "%s%s",
--- a/src/Modules/Output/Graphics/GraphicsView.cc Sun Oct 17 02:42:12 2010 +0000 +++ b/src/Modules/Output/Graphics/GraphicsView.cc Mon Oct 18 04:42:28 2010 +0000 @@ -25,7 +25,7 @@ namespace aimc { GraphicsView::GraphicsView(Parameters *parameters) : Module(parameters) { - module_description_ = ""; + module_description_ = "Graphics output."; module_identifier_ = "graphics"; module_type_ = "output"; module_version_ = "$Id: $";
--- a/src/Modules/Output/Graphics/GraphicsViewTime.cc Sun Oct 17 02:42:12 2010 +0000 +++ b/src/Modules/Output/Graphics/GraphicsViewTime.cc Mon Oct 18 04:42:28 2010 +0000 @@ -36,6 +36,10 @@ GraphicsViewTime::GraphicsViewTime(Parameters *pParam) : GraphicsView(pParam) { + module_description_ = "Graphics output."; + module_identifier_ = "graphics_time"; + module_type_ = "output"; + module_version_ = "$Id: $"; } GraphicsViewTime *GraphicsViewTime::Clone(GraphicsOutputDevice *pDev) { @@ -75,11 +79,11 @@ m_pAxisFreq->m_pScale->getName()); m_pDev->gText2f(0.0025f, 0.35f, sTxt, true); snprintf(sTxt, sizeof(sTxt) / sizeof(sTxt[0]), - _S("%s [%.2f..%.2f ms, %s scale]"), - m_pAxisX->m_sLabel ? m_pAxisX->m_sLabel : "", - m_pAxisX->m_fMin, - m_pAxisX->m_fMax, - m_pAxisX->m_pScale->getName()); + _S("%s [%.2f..%.2f ms, %s scale]"), + m_pAxisX->m_sLabel ? m_pAxisX->m_sLabel : "", + m_pAxisX->m_fMin, + m_pAxisX->m_fMax, + m_pAxisX->m_pScale->getName()); m_pDev->gText2f(m_fMarginLeft, 0.0025f, sTxt, false);
--- a/src/Modules/Output/Graphics/GraphicsViewTime.h Sun Oct 17 02:42:12 2010 +0000 +++ b/src/Modules/Output/Graphics/GraphicsViewTime.h Mon Oct 18 04:42:28 2010 +0000 @@ -35,10 +35,10 @@ private: void PlotData(const vector<float> &signal, - float sample_rate, - float yOffset, - float height, - float xScale = 1.0); + float sample_rate, + float yOffset, + float height, + float xScale = 1.0); void PlotAxes(const vector<float> &signal); void PlotAxes(const SignalBank &pBank); };
--- a/src/Support/Module.cc Sun Oct 17 02:42:12 2010 +0000 +++ b/src/Support/Module.cc Mon Oct 18 04:42:28 2010 +0000 @@ -31,6 +31,7 @@ namespace aimc { using std::pair; using std::ostream; +using std::endl; Module::Module(Parameters *parameters) { initialized_ = false; targets_.clear(); @@ -39,6 +40,8 @@ module_type_ = "MODULE TYPE NOT SET"; module_description_ = "MODULE DESCRIPTION NOT SET"; module_version_ = "MODULE VERSION NOT SET"; + instance_name_ = ""; + done_ = false; }; Module::~Module() { @@ -46,6 +49,9 @@ bool Module::Initialize(const SignalBank &input, Parameters *global_parameters) { + if (global_parameters == NULL) { + return false; + } global_parameters_ = global_parameters; // Validate the input if (!input.Validate()) { @@ -73,7 +79,7 @@ // this is not checked. set<Module*>::const_iterator it; for (it = targets_.begin(); it != targets_.end(); ++it) { - if (!(*it)->initialized()) + //if (!(*it)->initialized()) if (!(*it)->Initialize(output_, global_parameters_)) return false; } @@ -106,8 +112,8 @@ ret = targets_.insert(target_module); result = ret.second; if (result) { - if(initialized_) { - if(output_.initialized()) { + if (initialized_) { + if (output_.initialized()) { if (!target_module->initialized()) { target_module->Initialize(output_, global_parameters_); } @@ -141,26 +147,37 @@ } } -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::PrintTargetsForDot(ostream &out) { + //string parameters_string = parameters_->WriteString(); + out << " " << instance_name() << " [shape = none, margin = 0, label = <" << endl; + out << " <TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"4\"> " << endl; + out << " <TR><TD>" << instance_name() << "</TD></TR><TR><TD>" << id(); + out << "</TD></TR></TABLE>>]" << ";" << endl; + // <TD><TR>" << parameters_string << "</TD></TR> + set<Module*>::const_iterator it; + for (it = targets_.begin(); it != targets_.end(); ++it) { + out << " " << instance_name() << " -> " << (*it)->instance_name() << ";" << endl; + (*it)->PrintTargetsForDot(out); } } -void Module::PrintVersions(ostream &out) { - out << version() << "\n"; +void Module::PrintTargets(ostream &out) { set<Module*>::const_iterator it; for (it = targets_.begin(); it != targets_.end(); ++it) { - (*it)->PrintVersions(out); + out << " " << instance_name() << " -> " << (*it)->instance_name() << ";" << endl; + (*it)->PrintTargets(out); + } +} + +void Module::PrintConfiguration(ostream &out) { + out << "# " << id() << endl; + out << "# " << instance_name() << endl; + out << "# " << version() << endl; + string parameters_string = parameters_->WriteString(); + out << parameters_string << endl; + set<Module*>::const_iterator it; + for (it = targets_.begin(); it != targets_.end(); ++it) { + (*it)->PrintConfiguration(out); } } } // namespace aimc
--- a/src/Support/Module.h Sun Oct 17 02:42:12 2010 +0000 +++ b/src/Support/Module.h Mon Oct 18 04:42:28 2010 +0000 @@ -168,12 +168,6 @@ */ void Reset(); - /*! \brief Provide a pointer to the global parameters store. - * - - */ - void SetGlobalParameters(); - /*! \brief Return a pointer to the output SignalBank_ for this class. * \return pointer to the SignalBank that this module uses to store its * output. @@ -181,8 +175,8 @@ const SignalBank* GetOutputBank() const; void PrintTargets(ostream &out); - - void PrintVersions(ostream &out); + void PrintTargetsForDot(ostream &out); + void PrintConfiguration(ostream &out); string version() const { return module_version_; @@ -199,6 +193,18 @@ string type() const { return module_type_; } + + bool done() { + return done_; + } + + void set_instance_name(string instance_name) { + instance_name_ = instance_name; + } + + string instance_name() { + return instance_name_; + } protected: void PushOutput(); @@ -208,6 +214,7 @@ virtual bool InitializeInternal(const SignalBank &input) = 0; bool initialized_; + bool done_; set<Module*> targets_; SignalBank output_; Parameters* parameters_; @@ -217,6 +224,8 @@ string module_type_; string module_description_; string module_version_; + + string instance_name_; private: DISALLOW_COPY_AND_ASSIGN(Module);
--- a/src/Support/ModuleFactory.cc Sun Oct 17 02:42:12 2010 +0000 +++ b/src/Support/ModuleFactory.cc Mon Oct 18 04:42:28 2010 +0000 @@ -15,31 +15,39 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "Modules/Input/ModuleFileInput.h" +#include "Modules/Features/ModuleGaussians.h" +#include "Modules/Features/ModuleDCT.h" #include "Modules/BMM/ModuleGammatone.h" #include "Modules/BMM/ModulePZFC.h" +#include "Modules/Input/ModuleFileInput.h" #include "Modules/NAP/ModuleHCL.h" -#include "Modules/Strobes/ModuleParabola.h" +#include "Modules/Output/FileOutputHTK.h" +#include "Modules/Output/FileOutputAIMC.h" +#include "Modules/Output/Graphics/GraphicsViewTime.h" +#include "Modules/Profile/ModuleSlice.h" +#include "Modules/Profile/ModuleScaler.h" #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" +#include "Modules/SNR/ModuleNoise.h" +#include "Modules/Strobes/ModuleParabola.h" +#include "Modules/Strobes/ModuleLocalMax.h" #include "Support/ModuleFactory.h" namespace aimc { Module* ModuleFactory::Create(string module_name_, Parameters* params) { + if (module_name_.compare("gaussians") == 0) + return new ModuleGaussians(params); + + if (module_name_.compare("dct") == 0) + return new ModuleDCT(params); + if (module_name_.compare("gt") == 0) return new ModuleGammatone(params); if (module_name_.compare("pzfc") == 0) return new ModulePZFC(params); - //if (module_name_.compare("gaussians") == 0) - // return new ModuleGaussians(params); - if (module_name_.compare("file_input") == 0) return new ModuleFileInput(params); @@ -49,6 +57,12 @@ if (module_name_.compare("htk_out") == 0) return new FileOutputHTK(params); + if (module_name_.compare("aimc_out") == 0) + return new FileOutputAIMC(params); + + if (module_name_.compare("graphics_time") == 0) + return new GraphicsViewTime(params); + if (module_name_.compare("scaler") == 0) return new ModuleScaler(params); @@ -64,6 +78,9 @@ if (module_name_.compare("parabola") == 0) return new ModuleParabola(params); + if (module_name_.compare("local_max") == 0) + return new ModuleLocalMax(params); + return NULL; } } // namespace aimc
--- a/src/Support/ModuleTree.cc Sun Oct 17 02:42:12 2010 +0000 +++ b/src/Support/ModuleTree.cc Mon Oct 18 04:42:28 2010 +0000 @@ -24,13 +24,17 @@ * \version \$Id: $ */ +#include "Support/ModuleFactory.h" +#include "Support/Module.h" #include "Support/ModuleTree.h" -#include "Support/ModuleFactory.h" -#include "Support/Module.h" -#include "Support/Parameters.h" - namespace aimc { +using std::endl; +ModuleTree::ModuleTree() : root_module_(NULL), + initialized_(false) { + +} + bool ModuleTree::LoadConfigFile(const string &filename) { config_.Load(filename.c_str()); return ConstructTree(); @@ -46,27 +50,38 @@ // The first pass creates all the named modules with their parameters. bool done = false; bool error = false; - char module_name_var[AimParameters::MaxParamNameLength]; - char module_id_var[AimParameters::MaxParamNameLength]; - char module_parameters_var[AimParameters::MaxParamNameLength]; int module_number = 1; - while (!done) { + LOG_INFO("Parsing tree..."); + while (!done) { + char module_name_var[Parameters::MaxParamNameLength]; + char module_id_var[Parameters::MaxParamNameLength]; + char module_parameters_var[Parameters::MaxParamNameLength]; sprintf(module_name_var, "module%d.name", module_number); sprintf(module_id_var, "module%d.id", module_number); sprintf(module_parameters_var, "module%d.parameters", module_number); - if (config_.IsSet(module_name_var) { - char* name = config_.GetString(module_name_var)); - if (module_number == 1) { - root_name_ = name; - } + if (config_.IsSet(module_name_var)) { + string module_name(config_.GetString(module_name_var)); + LOG_INFO("Module number %d, name %s", module_number, module_name.c_str()); if (config_.IsSet(module_id_var)) { - char* id = config_.GetString(module_id_var)); - char* parameters = config_.DefaultString(module_parameters_var), ""); - parameters_[name] = new Parameters(); - parameters_[name]->Parse(parameters); - modules_[name] = factory_.Create(id, parameters_[name].get()); + const char* id = config_.GetString(module_id_var); + const char* parameters = config_.DefaultString(module_parameters_var, ""); + linked_ptr<Parameters> params(new Parameters); + parameters_[module_name] = params; + parameters_[module_name]->Parse(parameters); + linked_ptr<Module> module(ModuleFactory::Create(id, parameters_[module_name].get())); + if (module.get() != NULL) { + module->set_instance_name(module_name); + modules_[module_name] = module; + } else { + LOG_ERROR("Module name: %s of type %s not created", module_name.c_str(), id); + done = true; + error = true; + } + if (module_number == 1) { + root_module_ = module.get(); + } } else { - LOG_ERROR("id field missing for module named %s", name); + LOG_ERROR("id field missing for module named %s", module_name.c_str()); error = true; done = true; } @@ -76,34 +91,85 @@ ++module_number; } // The second pass connects up all the modules into a tree. - char module_child_var[AimParameters::MaxParamNameLength]; - for (int i = 0; i < modules_.size(); ++i) { + char module_child_var[Parameters::MaxParamNameLength]; + char module_name_var[Parameters::MaxParamNameLength]; + LOG_INFO("A total of %d modules", modules_.size()); + for (unsigned int i = 1; i < modules_.size() + 1; ++i) { int child_number = 1; done = false; - sprintf(module_name_var, "module%d.name", module_number); - if (config_.IsSet(module_name_var) { - char* name = config_.GetString(module_name_var)); + sprintf(module_name_var, "module%d.name", i); + if (config_.IsSet(module_name_var)) { + string module_name(config_.GetString(module_name_var)); while (!done) { sprintf(module_child_var, "module%d.child%d", i, child_number); - if (config_.IsSet(module_child_var) { - char* child = config_.GetString(module_child_var); - modules_[name]->AddTarget(modules_[child].get()); + LOG_INFO("Trying %s", module_child_var); + if (config_.IsSet(module_child_var)) { + string child(config_.GetString(module_child_var)); + if ((modules_.find(module_name) != modules_.end()) + && (modules_.find(child) != modules_.end())) { + modules_[module_name]->AddTarget(modules_[child].get()); + } else { + LOG_ERROR("Module name not found"); + } } else { done = true; } + ++child_number; } - ++child_number; } else { + LOG_ERROR("field missing for entry %s", module_name_var); error = true; break; } } - return error; + return !error; } bool ModuleTree::Initialize(Parameters *global_parameters) { - SignalBank s(1,1,1); - modules_[root_name_]->Initialize(s, global_parameters); + if (root_module_ == NULL) { + return false; + } + // Dummy signal bank for the root module. + s_.Initialize(1, 1, 1); + initialized_ = root_module_->Initialize(s_, global_parameters); + return initialized_; +} + +void ModuleTree::Reset() { + if (root_module_ == NULL) { + return; + } + root_module_->Reset(); +} + +void ModuleTree::PrintConfiguration(ostream &out) { + if (root_module_ == NULL) { + return; + } + root_module_->PrintTargets(out); + root_module_->PrintConfiguration(out); +} + +void ModuleTree::Process() { + if (root_module_ == NULL) { + return; + } + if (!initialized_) { + LOG_ERROR(_T("Module tree not initialized.")); + return; + } + while (!root_module_->done()) { + root_module_->Process(s_); + } +} + +void ModuleTree::MakeDotGraph(ostream &out) { + if (root_module_ == NULL) { + return; + } + out << "digraph G {" << endl; + root_module_->PrintTargetsForDot(out); + out << "}" << endl; } } // namespace aimc
--- a/src/Support/ModuleTree.h Sun Oct 17 02:42:12 2010 +0000 +++ b/src/Support/ModuleTree.h Mon Oct 18 04:42:28 2010 +0000 @@ -24,32 +24,47 @@ * \version \$Id: $ */ -#include <boost/scoped_ptr.hpp> -#include <hash_map> +#include <iostream> +#include <map> #include <string> +#include "Support/Common.h" +#include "Support/Module.h" +#include "Support/Parameters.h" +#include "Support/SignalBank.h" +#include "Support/linked_ptr.h" + namespace aimc { using std::string; -class Module; -class Parameters; +using std::map; +using std::ostream; class ModuleTree { public: - bool ParseConfigFile(const string &filename); - bool ParseConfigText(const string &config_text); - string GetFullConfig() + ModuleTree(); + bool LoadConfigFile(const string &filename); + bool LoadConfigText(const string &config_text); + string GetFullConfig(); + bool Initialize(Parameters *global_parameters); + void Reset(); + void PrintConfiguration(ostream &out); + void Process(); + void MakeDotGraph(ostream &out); void set_output_filename_prefix(const string &prefix) { output_filename_prefix_ = prefix; - } + }; string output_filename_prefix() { return output_filename_prefix_; - } + }; private: - Paramters config_; + bool ConstructTree(); + Parameters config_; + SignalBank s_; string output_filename_prefix_; - hash_map<string, scoped_ptr<Module> > modules_; - hash_map<string, scoped_ptr<Parameters> > parameters_; - string root_name_; + map<string, linked_ptr<Module> > modules_; + Module *root_module_; + map<string, linked_ptr<Parameters> > parameters_; + bool initialized_; DISALLOW_COPY_AND_ASSIGN(ModuleTree); }; } // namespace aimc \ No newline at end of file