Mercurial > hg > aimc
changeset 162:9fcf55c040fe
- Added property svn:eol-style native to all text files
author | tomwalters |
---|---|
date | Thu, 22 Jul 2010 04:14:20 +0000 |
parents | 0420c86456c1 |
children | c155e7fbe76e |
files | src/Main/AIMCopy.cc src/Modules/BMM/ModuleGammatone.cc src/Modules/Features/ModuleGaussians.cc src/Modules/Input/ModuleFileInput.cc src/Modules/SAI/ModuleSAI.cc src/Modules/SSI/ModuleSSI.cc src/Support/FileList.cc src/Support/ModuleFactory.cc src/Support/Parameters.cc src/Support/SignalBank.cc swig/example.py swig/setup.py |
diffstat | 12 files changed, 268 insertions(+), 410 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Main/AIMCopy.cc Thu Jul 22 01:19:52 2010 +0000 +++ b/src/Main/AIMCopy.cc Thu Jul 22 04:14:20 2010 +0000 @@ -43,176 +43,50 @@ #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_; -}; +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; - -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; - } - tree_.Reset(); - } 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; - } - bool tree_initialized = 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_initialized) { - if (!tree_.Initialize(&global_parameters_)) { - return false; - } - tree_initialized = true; - } else { - tree_.Reset(); - } - aimc::LOG_INFO(_T("%s -> %s"), - script_[i].first.c_str(), - script_[i].second.c_str()); - tree_.Process(); - } - // A final call to Reset() is required to close any open files. - global_parameters_.SetString("input_filename", ""); - global_parameters_.SetString("output_filename_base", ""); - tree_.Reset(); - return true; -} - -} // namespace aimc - -int main(int argc, char* argv[]) { - std::string data_file; - std::string dot_file; - std::string config_file; - std::string script_file; - - const std::string version_string( + string version_string( " AIM-C AIMCopy\n" " (c) 2006-2010, Thomas Walters and Willem van Engen\n" " http://www.acoustiscale.org/AIMC/\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"); + "\n"); if (argc < 2) { - std::cout << version_string.c_str(); - std::cout << usage_string.c_str(); + 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; } @@ -247,42 +121,95 @@ return(-1); } data_file = argv[i]; + write_data = true; continue; } - 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; + if (strcmp(argv[i],"-V") == 0) { + print_version = true; continue; } aimc::LOG_ERROR(_T("Unrecognized command-line argument: %s"), argv[i]); } - 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)) { + 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()); return -1; } - - aimc::LOG_INFO("main: Writing confg..."); - if (!processor.WriteConfig(data_file, dot_file)) { + + 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; } - - aimc::LOG_INFO("main: Processing..."); - if (!processor.Process()) { - 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(); } return 0;
--- a/src/Modules/BMM/ModuleGammatone.cc Thu Jul 22 01:19:52 2010 +0000 +++ b/src/Modules/BMM/ModuleGammatone.cc Thu Jul 22 04:14:20 2010 +0000 @@ -52,13 +52,9 @@ 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/Features/ModuleGaussians.cc Thu Jul 22 01:19:52 2010 +0000 +++ b/src/Modules/Features/ModuleGaussians.cc Thu Jul 22 04:14:20 2010 +0000 @@ -27,10 +27,6 @@ #include <math.h> -#ifdef _WINDOWS -#include <float.h> -#endif - #include "Modules/Features/ModuleGaussians.h" #include "Support/Common.h" @@ -42,17 +38,17 @@ module_type_ = "features"; module_version_ = "$Id$"; - m_iParamNComp = parameters_->DefaultInt("gaussians.ncomp", 4); - m_fParamVar = parameters_->DefaultFloat("gaussians.var", 115.0); - m_fParamPosteriorExp = parameters_->DefaultFloat("gaussians.posterior_exp", - 6.0); - m_iParamMaxIt = parameters_->DefaultInt("gaussians.maxit", 250); + m_iParamNComp = parameters_->DefaultInt("features.gaussians.ncomp", 4); + m_fParamVar = parameters_->DefaultFloat("features.gaussians.var", 115.0); + m_fParamPosteriorExp = + parameters_->DefaultFloat("features.gaussians.posterior_exp", 6.0); + m_iParamMaxIt = parameters_->DefaultInt("features.gaussians.maxit", 250); // The parameters system doesn't support tiny numbers well, to define this // variable as a string, then convert it to a float afterwards - parameters_->DefaultString("gaussians.priors_converged", "1e-7"); - priors_converged_ = parameters_->GetFloat("gaussians.priors_converged"); - output_positions_ = parameters_->DefaultBool("gaussians.positions", false); + parameters_->DefaultString("features.gaussians.priors_converged", "1e-7"); + m_fParamPriorsConverged = + parameters_->GetFloat("features.gaussians.priors_converged"); } ModuleGaussians::~ModuleGaussians() { @@ -64,9 +60,8 @@ // Assuming the number of channels is greater than twice the number of // Gaussian components, this is ok - output_component_count_ = 1; // Energy component if (input.channel_count() >= 2 * m_iParamNComp) { - output_component_count_ += (m_iParamNComp - 1); + output_.Initialize(m_iParamNComp, 1, input.sample_rate()); } else { LOG_ERROR(_T("Too few channels in filterbank to produce sensible " "Gaussian features. Either increase the number of filterbank" @@ -74,12 +69,6 @@ return false; } - if (output_positions_) { - output_component_count_ += m_iParamNComp; - } - - output_.Initialize(output_component_count_, 1, input.sample_rate()); - m_iNumChannels = input.channel_count(); m_pSpectralProfile.resize(m_iNumChannels, 0.0f); @@ -100,14 +89,17 @@ LOG_ERROR(_T("Module ModuleGaussians not initialized.")); return; } - output_.set_start_time(input.start_time()); // Calculate spectral profile - for (int ch = 0; ch < input.channel_count(); ++ch) { - m_pSpectralProfile[ch] = 0.0f; - for (int i = 0; i < input.buffer_length(); ++i) { - m_pSpectralProfile[ch] += input[ch][i]; + for (int iChannel = 0; + iChannel < input.channel_count(); + ++iChannel) { + m_pSpectralProfile[iChannel] = 0.0f; + for (int iSample = 0; + iSample < input.buffer_length(); + ++iSample) { + m_pSpectralProfile[iChannel] += input[iChannel][iSample]; } - m_pSpectralProfile[ch] /= static_cast<float>(input.buffer_length()); + m_pSpectralProfile[iChannel] /= static_cast<float>(input.buffer_length()); } float spectral_profile_sum = 0.0f; @@ -115,35 +107,36 @@ spectral_profile_sum += m_pSpectralProfile[i]; } - // Set the last component of the feature vector to be the log energy float logsum = log(spectral_profile_sum); if (!isinf(logsum)) { - output_.set_sample(output_component_count_ - 1, 0, logsum); + output_.set_sample(m_iParamNComp - 1, 0, logsum); } else { - output_.set_sample(output_component_count_ - 1, 0, -1000.0); + output_.set_sample(m_iParamNComp - 1, 0, -1000.0); } - for (int ch = 0; ch < input.channel_count(); ++ch) { - m_pSpectralProfile[ch] = pow(m_pSpectralProfile[ch], 0.8f); + for (int iChannel = 0; + iChannel < input.channel_count(); + ++iChannel) { + m_pSpectralProfile[iChannel] = pow(m_pSpectralProfile[iChannel], 0.8); } RubberGMMCore(2, true); - float mean1 = m_pMu[0]; - float mean2 = m_pMu[1]; + float fMean1 = m_pMu[0]; + float fMean2 = m_pMu[1]; // LOG_INFO(_T("Orig. mean 0 = %f"), m_pMu[0]); // LOG_INFO(_T("Orig. mean 1 = %f"), m_pMu[1]); // LOG_INFO(_T("Orig. prob 0 = %f"), m_pA[0]); // LOG_INFO(_T("Orig. prob 1 = %f"), m_pA[1]); - float a1 = 0.05 * m_pA[0]; - float a2 = 1.0 - 0.25 * m_pA[1]; + float fA1 = 0.05 * m_pA[0]; + float fA2 = 1.0 - 0.25 * m_pA[1]; // LOG_INFO(_T("fA1 = %f"), fA1); // LOG_INFO(_T("fA2 = %f"), fA2); - float gradient = (mean2 - mean1) / (a2 - a1); - float intercept = mean2 - gradient * a2; + float fGradient = (fMean2 - fMean1) / (fA2 - fA1); + float fIntercept = fMean2 - fGradient * fA2; // LOG_INFO(_T("fGradient = %f"), fGradient); // LOG_INFO(_T("fIntercept = %f"), fIntercept); @@ -151,7 +144,7 @@ for (int i = 0; i < m_iParamNComp; ++i) { m_pMu[i] = (static_cast<float>(i) / (static_cast<float>(m_iParamNComp) - 1.0f)) - * gradient + intercept; + * fGradient + fIntercept; // LOG_INFO(_T("mean %d = %f"), i, m_pMu[i]); } @@ -161,7 +154,6 @@ RubberGMMCore(m_iParamNComp, false); - // Amplitudes first for (int i = 0; i < m_iParamNComp - 1; ++i) { if (!isnan(m_pA[i])) { output_.set_sample(i, 0, m_pA[i]); @@ -170,19 +162,6 @@ } } - // Then means if required - if (output_positions_) { - int idx = 0; - for (int i = m_iParamNComp - 1; i < 2 * m_iParamNComp - 1; ++i) { - if (!isnan(m_pMu[i])) { - output_.set_sample(i, 0, m_pMu[idx]); - } else { - output_.set_sample(i, 0, 0.0f); - } - ++idx; - } - } - PushOutput(); } @@ -190,12 +169,12 @@ int iSizeX = m_iNumChannels; // Normalise the spectral profile - float SpectralProfileTotal = 0.0f; + float fSpectralProfileTotal = 0.0f; for (int iCount = 0; iCount < iSizeX; iCount++) { - SpectralProfileTotal += m_pSpectralProfile[iCount]; + fSpectralProfileTotal += m_pSpectralProfile[iCount]; } for (int iCount = 0; iCount < iSizeX; iCount++) { - m_pSpectralProfile[iCount] /= SpectralProfileTotal; + m_pSpectralProfile[iCount] /= fSpectralProfileTotal; } if (bDoInit) { @@ -221,12 +200,12 @@ pP_mod_X[i] = 0.0f; } - for (int c = 0; c < iNComponents; c++) { + for (int i = 0; i < iNComponents; i++) { for (int iCount = 0; iCount < iSizeX; iCount++) { pP_mod_X[iCount] += 1.0f / sqrt(2.0f * M_PI * m_fParamVar) * exp((-0.5f) - * pow(static_cast<float>(iCount+1) - m_pMu[c], 2) - / m_fParamVar) * m_pA[c]; + * pow(static_cast<float>(iCount+1) - m_pMu[i], 2) + / m_fParamVar) * m_pA[i]; } } @@ -272,7 +251,7 @@ } fPrdist /= iNComponents; - if (fPrdist < priors_converged_) { + if (fPrdist < m_fParamPriorsConverged) { // LOG_INFO("Converged!"); break; }
--- a/src/Modules/Input/ModuleFileInput.cc Thu Jul 22 01:19:52 2010 +0000 +++ b/src/Modules/Input/ModuleFileInput.cc Thu Jul 22 04:14:20 2010 +0000 @@ -52,86 +52,112 @@ } void ModuleFileInput::ResetInternal() { + output_.Initialize(audio_channels_, buffer_length_, sample_rate_); + output_.set_start_time(0); +} + +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 a file + // Open the file SF_INFO sfinfo; memset(reinterpret_cast<void*>(&sfinfo), 0, sizeof(SF_INFO)); - file_loaded_ = false; - file_handle_ = sf_open(global_parameters_->GetString("input_filename"), - SFM_READ, - &sfinfo); + file_handle_ = sf_open(filename, SFM_READ, &sfinfo); if (file_handle_ == NULL) { /*! \todo Also display error reason */ - LOG_ERROR(_T("Couldn't read audio file '%s'"), - global_parameters_->GetString("input_filename")); - return; + LOG_ERROR(_T("Couldn't read audio file '%s'"), filename); + return false; } - + file_loaded_ = true; - done_ = false; audio_channels_ = sfinfo.channels; sample_rate_ = sfinfo.samplerate; file_position_samples_ = 0; - 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; - } + // A dummy signal bank to be passed to the Initialize() function. + SignalBank s; + s.Initialize(1, 1, 1); - output_.Initialize(audio_channels_, buffer_length_, sample_rate_); - output_.set_start_time(0); + // 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; +} + +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(const SignalBank& input) { +void ModuleFileInput::Process() { if (!file_loaded_) return; sf_count_t read; vector<float> buffer; buffer.resize(buffer_length_ * audio_channels_); - // 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 i = 0; i < read; ++i) { - for (int c = 0; c < audio_channels_; ++c) { - output_.set_sample(c, i, buffer[counter]); - ++counter; - } - } + while (true) { + // Read buffersize bytes into buffer + read = sf_readf_float(file_handle_, &buffer[0], buffer_length_); - // If the number of samples 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 i = read; i < buffer_length_; ++i) { - for (int c = 0; c < audio_channels_; ++c) { - output_.set_sample(c, i, 0.0f); + // 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; } } - // 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/SAI/ModuleSAI.cc Thu Jul 22 01:19:52 2010 +0000 +++ b/src/Modules/SAI/ModuleSAI.cc Thu Jul 22 04:14:20 2010 +0000 @@ -107,8 +107,6 @@ void ModuleSAI::ResetInternal() { // Active Strobes - output_.Clear(); - sai_temp_.Clear(); active_strobes_.clear(); active_strobes_.resize(channel_count_); fire_counter_ = frame_period_samples_ - 1;
--- a/src/Modules/SSI/ModuleSSI.cc Thu Jul 22 01:19:52 2010 +0000 +++ b/src/Modules/SSI/ModuleSSI.cc Thu Jul 22 04:14:20 2010 +0000 @@ -26,13 +26,6 @@ #include "Modules/SSI/ModuleSSI.h" namespace aimc { -#ifdef _MSC_VER -// MSVC doesn't define log2() -float log2(float n) { - return log(n) / log(2.0); -} -#endif - ModuleSSI::ModuleSSI(Parameters *params) : Module(params) { module_description_ = "Size-shape image (aka the 'sscAI')"; module_identifier_ = "ssi"; @@ -57,7 +50,7 @@ // Time from the zero-lag line of the SAI from which to start searching // for a maximum in the input SAI's temporal profile. pitch_search_start_ms_ = parameters_->DefaultFloat( - "ssi.pitch_search_start_ms", 2.0f); + "ssi.pitch_search_start_ms", 2.0f); // Total width in cycles of the whole SSI ssi_width_cycles_ = parameters_->DefaultFloat("ssi.width_cycles", 10.0f); @@ -69,13 +62,6 @@ // The centre frequency of the channel which will just fill the complete // width of the SSI buffer pivot_cf_ = parameters_->DefaultFloat("ssi.pivot_cf", 1000.0f); - - // Whether or not to do smooth offset when the pitch cutoff is active. - do_smooth_offset_ = parameters_->DefaultBool("ssi.do_smooth_offset", false); - - // The number of cycles, centered on the pitch line, over which the SSI is taken - // to zero when doing the pitch cutoff. - smooth_offset_cycles_ = parameters_->DefaultFloat("ssi.smooth_offset_cycles", 3.0f); } ModuleSSI::~ModuleSSI() { @@ -99,25 +85,6 @@ ssi_width_samples_, cycles); ssi_width_cycles_ = cycles; } - for (int i = 0; i < input.channel_count(); ++i) { - output_.set_centre_frequency(i, input.centre_frequency(i)); - } - - h_.resize(ssi_width_samples_, 0.0); - float gamma_min = -1.0f; - float gamma_max = log2(ssi_width_cycles_); - for (int i = 0; i < ssi_width_samples_; ++i) { - if (log_cycles_axis_) { - float gamma = gamma_min + (gamma_max - gamma_min) - * static_cast<float>(i) - / static_cast<float>(ssi_width_samples_); - h_[i]= pow(2.0f, gamma); - } else { - h_[i] = static_cast<float>(i) * ssi_width_cycles_ - / static_cast<float>(ssi_width_samples_); - } - } - output_.Initialize(channel_count_, ssi_width_samples_, sample_rate_); return true; } @@ -175,46 +142,41 @@ for (int ch = 0; ch < channel_count_; ++ch) { float centre_frequency = input.centre_frequency(ch); - float cycle_samples = sample_rate_ / centre_frequency; - - float channel_weight = 1.0f; - int cutoff_index = buffer_length_ - 1; - if (do_pitch_cutoff_) { - if (pitch_index < cutoff_index) { - if (weight_by_cutoff_) { - channel_weight = static_cast<float>(buffer_length_) - / static_cast<float>(pitch_index); - } - cutoff_index = pitch_index; + // Copy the buffer from input to output, addressing by h-value + for (int i = 0; i < ssi_width_samples_; ++i) { + float h; + float cycle_samples = sample_rate_ / centre_frequency; + if (log_cycles_axis_) { + float gamma_min = -1.0f; + float gamma_max = log2(ssi_width_cycles_); + float gamma = gamma_min + (gamma_max - gamma_min) + * static_cast<float>(i) + / static_cast<float>(ssi_width_samples_); + h = pow(2.0f, gamma); + } else { + h = static_cast<float>(i) * ssi_width_cycles_ + / static_cast<float>(ssi_width_samples_); } - } - - // tanh(3) is about 0.995. Seems reasonable. - float smooth_pitch_constant = 3.0f / smooth_offset_cycles_; - float pitch_h = 0.0f; - if (do_smooth_offset_) { - pitch_h = static_cast<float>(pitch_index) / cycle_samples; - } - - // Copy the buffer from input to output, addressing by h-value. - for (int i = 0; i < ssi_width_samples_; ++i) { - + // The index into the input array is a floating-point number, which is // split into a whole part and a fractional part. The whole part and // fractional part are found, and are used to linearly interpolate // between input samples to yield an output sample. double whole_part; - float frac_part = modf(h_[i] * cycle_samples, &whole_part); + float frac_part = modf(h * cycle_samples, &whole_part); int sample = floor(whole_part); - float weight = channel_weight; - - if (do_smooth_offset_ && do_pitch_cutoff_) { - // Smoothing around the pitch cutoff line. - float pitch_weight = (1.0f + tanh((pitch_h - h_[i]) - * smooth_pitch_constant)) / 2.0f; - weight *= pitch_weight; - //LOG_INFO("Channel %d, Sample %d. Pitch weight: %f", ch, i, pitch_weight); + float weight = 1.0f; + + int cutoff_index = buffer_length_ - 1; + if (do_pitch_cutoff_) { + if (pitch_index < cutoff_index) { + if (weight_by_cutoff_) { + weight *= static_cast<float>(buffer_length_) + / static_cast<float>(pitch_index); + } + cutoff_index = pitch_index; + } } if (weight_by_scaling_) { @@ -224,7 +186,7 @@ } float val; - if (sample < cutoff_index || do_smooth_offset_) { + if (sample < cutoff_index) { float curr_sample = input.sample(ch, sample); float next_sample = input.sample(ch, sample + 1); val = weight * (curr_sample
--- a/src/Support/FileList.cc Thu Jul 22 01:19:52 2010 +0000 +++ b/src/Support/FileList.cc Thu Jul 22 04:14:20 2010 +0000 @@ -33,19 +33,19 @@ FILE* file_handle; vector<pair<string, string> > file_list; if ((file_handle = fopen(filename.c_str(), "r"))==NULL) { - LOG_ERROR(_T("Couldn't open file '%s' for reading."), filename.c_str()); - return file_list; - } + LOG_ERROR(_T("Couldn't open file '%s' for reading."), filename.c_str()); + return file_list; + } string out_1; string out_2; char n1[PATH_MAX]; char n2[PATH_MAX]; - while (fscanf(file_handle, "%s\t%s", n1, n2) != EOF) { + while (fscanf(file_handle, "%s\t%s", n1, n2) != EOF) { out_1 = n1; out_2 = n2; file_list.push_back(make_pair(out_1, out_2)); - } + } fclose(file_handle); return file_list; }
--- a/src/Support/ModuleFactory.cc Thu Jul 22 01:19:52 2010 +0000 +++ b/src/Support/ModuleFactory.cc Thu Jul 22 04:14:20 2010 +0000 @@ -15,39 +15,31 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "Modules/Features/ModuleGaussians.h" -//#include "Modules/Features/ModuleDCT.h" +#include "Modules/Input/ModuleFileInput.h" #include "Modules/BMM/ModuleGammatone.h" #include "Modules/BMM/ModulePZFC.h" -#include "Modules/Input/ModuleFileInput.h" #include "Modules/NAP/ModuleHCL.h" -#include "Modules/Output/FileOutputHTK.h" -#include "Modules/Output/FileOutputAIMC.h" -#include "Modules/Output/Graphics/GraphicsViewTime.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/SAI/ModuleSAI.h" -#include "Modules/SSI/ModuleSSI.h" -//#include "Modules/SNR/ModuleNoise.h" -#include "Modules/Strobes/ModuleParabola.h" -#include "Modules/Strobes/ModuleLocalMax.h" +#include "Modules/Features/ModuleGaussians.h" +#include "Modules/Output/FileOutputHTK.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); @@ -57,12 +49,6 @@ 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); @@ -78,9 +64,6 @@ 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/Parameters.cc Thu Jul 22 01:19:52 2010 +0000 +++ b/src/Support/Parameters.cc Thu Jul 22 04:14:20 2010 +0000 @@ -31,10 +31,6 @@ #include "Support/Common.h" #include "Support/Parameters.h" -#ifdef _MSC_VER -#define snprintf _snprintf -#endif - namespace aimc { const char *Parameters::m_SDefaultIniSection = "";
--- a/src/Support/SignalBank.cc Thu Jul 22 01:19:52 2010 +0000 +++ b/src/Support/SignalBank.cc Thu Jul 22 04:14:20 2010 +0000 @@ -94,13 +94,6 @@ return true; } -void SignalBank::Clear() { - for (int i = 0; i < channel_count_; ++i) { - signals_[i].assign(buffer_length_, 0.0f); - strobes_[i].resize(0); - } -} - bool SignalBank::Validate() const { if (sample_rate_ <= 0.0f) return false;
--- a/swig/example.py Thu Jul 22 01:19:52 2010 +0000 +++ b/swig/example.py Thu Jul 22 04:14:20 2010 +0000 @@ -17,11 +17,10 @@ # limitations under the License. import aimc -module_params = aimc.Parameters() -global_params = aimc.Parameters() -mod_gauss = aimc.ModuleGaussians(module_params) +params = aimc.Parameters() +mod_gauss = aimc.ModuleGaussians(params) sig = aimc.SignalBank() sig.Initialize(115, 1, 44100) -mod_gauss.Initialize(sig, global_params) +mod_gauss.Initialize(sig) mod_gauss.Process(sig)
--- a/swig/setup.py Thu Jul 22 01:19:52 2010 +0000 +++ b/swig/setup.py Thu Jul 22 04:14:20 2010 +0000 @@ -28,16 +28,18 @@ '../src/Support/Parameters.cc', '../src/Support/SignalBank.cc', '../src/Support/Module.cc', + '../src/Modules/Features/ModuleGaussians.cc', '../src/Modules/BMM/ModuleGammatone.cc', - '../src/Modules/Features/ModuleGaussians.cc', '../src/Modules/BMM/ModulePZFC.cc', '../src/Modules/NAP/ModuleHCL.cc', '../src/Modules/Strobes/ModuleParabola.cc', '../src/Modules/Strobes/ModuleLocalMax.cc', '../src/Modules/SAI/ModuleSAI.cc', '../src/Modules/SSI/ModuleSSI.cc', + '../src/Modules/SNR/ModuleNoise.cc', '../src/Modules/Profile/ModuleSlice.cc', - '../src/Modules/Profile/ModuleScaler.cc'], + '../src/Modules/Profile/ModuleScaler.cc', + '../src/Modules/Output/FileOutputHTK.cc'], swig_opts = ['-c++','-I../src/'], include_dirs=['../src/', '/opt/local/include/'] ) @@ -46,9 +48,6 @@ version = '0.1', author = "Thomas Walters <tom@acousticscale.org>", description = """SWIG wrapper round the core of aimc""", - # A bug with some versions of SWIG/distutils/python and some configurations requires - # us to repeat the swig_opts here. - options={'build_ext':{'swig_opts':'-c++ -I../src/'}}, ext_modules = [aimc_module], py_modules = ["aimc"], - ) + ) \ No newline at end of file