Mercurial > hg > aimc
changeset 253:988c8b6f7946
- AIMC format file output
author | tom@acousticscale.org |
---|---|
date | Thu, 04 Nov 2010 19:48:53 +0000 |
parents | de2b483654ee |
children | 9c9c539c0ea8 |
files | experiments/scripts/cnbh-syllables/results_plotting/plot_munged_results.py matlab/AIMCread.m src/Modules/BMM/ModulePZFC.cc src/Modules/Features/ModuleGaussians.cc src/Modules/Output/FileOutputAIMC.cc src/Modules/Output/FileOutputAIMC.h src/Modules/Output/Graphics/Devices/GraphicsOutputDeviceMovie.cc |
diffstat | 7 files changed, 58 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/experiments/scripts/cnbh-syllables/results_plotting/plot_munged_results.py Tue Nov 02 23:46:56 2010 +0000 +++ b/experiments/scripts/cnbh-syllables/results_plotting/plot_munged_results.py Thu Nov 04 19:48:53 2010 +0000 @@ -4,12 +4,11 @@ """ +import matplotlib as mpl +mpl.use('PDF') import numpy as np import pylab as p -import matplotlib as mpl -mpl.use('PDF') -import matplotlib.pyplot as plt - +#import matplotlib.pyplot as plt f=open("results_test_all.csv","r") results = dict() @@ -24,30 +23,35 @@ results[values[3]][values[0]][values[1]][int(values[4])][int(values[5])].setdefault(int(values[6]), dict()) if values[2] == 'clean': snr = 50 + results[values[3]][values[0]][values[1]][int(values[4])][int(values[5])][int(values[6])][snr] = float(values[7]) else: snr = int(values[2]) results[values[3]][values[0]][values[1]][int(values[4])][int(values[5])][int(values[6])][snr] = float(values[7]) # results[values[3]].append((values[1],values[2],values[2],values[4])) -ax = plt.subplot(111) - +ax = mpl.pyplot.subplot(111) train_set = 'inner' -lines = [] -labels = [] -hmm_iterations = 2 -hmm_states = 4 -hmm_components = 4 -for feature_type in ('mfcc', 'mfcc_vtln', 'aim'): - for feature_subtype in results[train_set][feature_type].keys(): - this_line = results[train_set][feature_type][feature_subtype][hmm_states][hmm_components][hmm_iterations].items() - this_line.sort(cmp=lambda x,y: x[0] - y[0]) - xs, ys = zip(*this_line) - xs = list(xs) - ys = list(ys) - line, = ax.plot(xs,ys,'-o',linewidth=2) - lines.append(line) - labels.append(feature_type + "_" + feature_subtype) -p.legend(lines, labels, 'upper left', shadow=True) -p.xlabel('SNR/dB') -p.ylabel('Recognition performance %') -plt.savefig(output_file) +for hmm_iterations in [2,3,15]: + for hmm_states in [3,4]: + for hmm_components in [3,4]: + lines = [] + labels = [] + ax.cla() + for feature_type in ('mfcc', 'mfcc_vtln', 'aim'): + for feature_subtype in results[train_set][feature_type].keys(): + try: + this_line = results[train_set][feature_type][feature_subtype][hmm_states][hmm_components][hmm_iterations].items() + this_line.sort(cmp=lambda x,y: x[0] - y[0]) + xs, ys = zip(*this_line) + xs = list(xs) + ys = list(ys) + line, = ax.plot(xs,ys,'-o',linewidth=2) + lines.append(line) + labels.append(feature_type + "_" + feature_subtype) + except KeyError: + print "Data not found" + p.legend(lines, labels, 'upper left', shadow=True) + p.xlabel('SNR/dB') + p.ylabel('Recognition performance %') + output_file = ("recognition_vs_snr_%diterations_%dstates_%d_components.pdf" % (hmm_iterations, hmm_states, hmm_components)) + p.savefig(output_file) \ No newline at end of file
--- a/matlab/AIMCread.m Tue Nov 02 23:46:56 2010 +0000 +++ b/matlab/AIMCread.m Thu Nov 04 19:48:53 2010 +0000 @@ -12,10 +12,10 @@ debug = 0; -nFrames = fread( fid, 1, 'int32'); +nFrames = fread( fid, 1, 'uint32'); period = fread( fid, 1, 'float32'); % Frame period in ms -nChannels = fread( fid, 1, 'int32'); % vertical axis of an AI -nSamples = fread( fid, 1, 'int32'); % horizontal axis of an AI +nChannels = fread( fid, 1, 'uint32'); % vertical axis of an AI +nSamples = fread( fid, 1, 'uint32'); % horizontal axis of an AI sample_rate = fread(fid, 1, 'float32'); % sample rate of each channel in Hz if nChannels == 1 % temporal profiles
--- a/src/Modules/BMM/ModulePZFC.cc Tue Nov 02 23:46:56 2010 +0000 +++ b/src/Modules/BMM/ModulePZFC.cc Thu Nov 04 19:48:53 2010 +0000 @@ -169,7 +169,7 @@ // channel output_.set_centre_frequency(i, frequency); - float zero_frequency = Minimum(M_PI, zero_factor_ * pole_frequency); + float zero_frequency = Minimum(M_PI, zero_factor_ * pole_frequency); // Impulse-invariance mapping float z_plane_theta = zero_frequency * sqrt(1.0f - pow(zero_damping_, 2));
--- a/src/Modules/Features/ModuleGaussians.cc Tue Nov 02 23:46:56 2010 +0000 +++ b/src/Modules/Features/ModuleGaussians.cc Thu Nov 04 19:48:53 2010 +0000 @@ -27,7 +27,7 @@ #include <math.h> -#ifdef _MSC_VER +#ifdef _WINDOWS #include <float.h> #endif
--- a/src/Modules/Output/FileOutputAIMC.cc Tue Nov 02 23:46:56 2010 +0000 +++ b/src/Modules/Output/FileOutputAIMC.cc Thu Nov 04 19:48:53 2010 +0000 @@ -36,6 +36,7 @@ #include <stdio.h> #include <string.h> #include <cmath> +#include <string> #include "Modules/Output/FileOutputAIMC.h" @@ -45,6 +46,7 @@ module_identifier_ = "aimc_out"; module_type_ = "output"; module_version_ = "$Id: FileOutputAIMC.cc 51 2010-03-30 22:06:24Z tomwalters $"; + file_suffix_ = parameters_->DefaultString("file_suffix", ".aimc"); file_handle_ = NULL; header_written_ = false; @@ -56,19 +58,20 @@ CloseFile(); } -bool FileOutputAIMC::OpenFile(const char* filename, float frame_period_ms) { +bool FileOutputAIMC::OpenFile(string &filename) { if (file_handle_ != NULL) { LOG_ERROR(_T("Couldn't open output file. A file is already open.")); 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); + if ((file_handle_ = fopen(filename.c_str(), "wb")) == NULL) { + LOG_ERROR(_T("Couldn't open output file '%s' for writing."), filename.c_str()); return false; } + // Write temporary values for the frame count and frame period. frame_count_ = 0; - frame_period_ms_ = frame_period_ms; + frame_period_ms_ = 0.0; header_written_ = false; if (initialized_) { WriteHeader(); @@ -77,22 +80,14 @@ } bool FileOutputAIMC::InitializeInternal(const SignalBank &input) { + channel_count_ = input.channel_count(); + buffer_length_ = input.buffer_length(); + sample_rate_ = input.sample_rate(); + ResetInternal(); if (file_handle_ == NULL) { - LOG_ERROR(_T("Couldn't initialize file output. " - "Please call FileOutputAIMC::OpenFile first")); + LOG_ERROR(_T("Couldn't initialize file output.")); return false; } - if (header_written_) { - LOG_ERROR(_T("A header has already been written on the output file. " - "Please call FileOutputAIMC::CloseFile to close that file, " - "and FileOutputAIMC::OpenFile to open an new one before " - "calling FileOutputAIMC::Initialize again.")); - return false; - } - channel_count_ = input.channel_count(); - buffer_length_ = input.buffer_length(); - sample_rate_ = input.sample_rate(); - WriteHeader(); return true; } @@ -102,6 +97,11 @@ } if (file_handle_ != NULL) CloseFile(); + + string out_filename; + out_filename = global_parameters_->GetString("output_filename_base") + file_suffix_; + OpenFile(out_filename); + } void FileOutputAIMC::WriteHeader() { @@ -169,7 +169,9 @@ rewind(file_handle_); fflush(file_handle_); uint32_t frame_count = frame_count_; + float sample_period_out = frame_period_ms_; fwrite(&frame_count, sizeof(frame_count), 1, file_handle_); + fwrite(&sample_period_out, sizeof(sample_period_out), 1, file_handle_); // And close the file fclose(file_handle_);
--- a/src/Modules/Output/FileOutputAIMC.h Tue Nov 02 23:46:56 2010 +0000 +++ b/src/Modules/Output/FileOutputAIMC.h Thu Nov 04 19:48:53 2010 +0000 @@ -28,6 +28,8 @@ #ifndef AIMC_MODULES_OUTPUT_AIMC_H_ #define AIMC_MODULES_OUTPUT_AIMC_H_ +#include <string> + #include "Support/Module.h" #include "Support/SignalBank.h" @@ -44,7 +46,7 @@ * 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 OpenFile(string &filename); bool CloseFile(); virtual void Process(const SignalBank &input); private: @@ -69,6 +71,7 @@ int buffer_length_; float sample_rate_; float frame_period_ms_; + string file_suffix_; }; } // namespace aimc
--- a/src/Modules/Output/Graphics/Devices/GraphicsOutputDeviceMovie.cc Tue Nov 02 23:46:56 2010 +0000 +++ b/src/Modules/Output/Graphics/Devices/GraphicsOutputDeviceMovie.cc Thu Nov 04 19:48:53 2010 +0000 @@ -141,6 +141,7 @@ void GraphicsOutputDeviceMovie::Stop() { GraphicsOutputDeviceCairo::Stop(); CloseFile(); + m_iFileNumber = 0; #ifdef __WX__ // GUI only: popup dialog