# HG changeset patch # User tomwalters@google.com # Date 1367936673 0 # Node ID 087f3b3c36d3f59525203e055040589adcc86897 # Parent 256caa099e32ee1694c9a72da54f2fd4744e3f3b Add option to dump strobes diff -r 256caa099e32 -r 087f3b3c36d3 matlab/AIMCread.m --- a/matlab/AIMCread.m Fri Apr 19 00:26:23 2013 +0000 +++ b/matlab/AIMCread.m Tue May 07 14:24:33 2013 +0000 @@ -1,15 +1,22 @@ -function [data, nFrames, period, nChannels, nSamples, sample_rate] = AIMCread(filename) +function [data, nFrames, period, nChannels, nSamples, sample_rate] = ... + AIMCread(filename, strobes_filename) %[data, nFrames, period, nChannels, nSamples ] = AIMCread( filename) % % data ... matrix (or array) of size [nFrames,nChannels,nSamples] % in case vertical/horizontal profiles are read, you should use squeeze % nFrames ... number of frames % period ... Frame interval in ms -% nChannels ... points on vertical axis of an auditori image -% nSamples ... points on horizontal axis of an auditori image +% nChannels ... points on vertical axis of an auditory image +% nSamples ... points on horizontal axis of an auditory image fid = fopen(filename); +strobes_fid = -1; +if nargin > 1 + strobes_fid = fopen(strobes_filename); + strobes_raw = fread(strobes_fid, [], 'int32'); +end + debug = 0; nFrames = fread( fid, 1, 'uint32'); diff -r 256caa099e32 -r 087f3b3c36d3 src/Modules/Output/FileOutputAIMC.cc --- a/src/Modules/Output/FileOutputAIMC.cc Fri Apr 19 00:26:23 2013 +0000 +++ b/src/Modules/Output/FileOutputAIMC.cc Tue May 07 14:24:33 2013 +0000 @@ -25,6 +25,8 @@ * \version \$Id: $ */ +#include "Modules/Output/FileOutputAIMC.h" + #ifdef _WINDOWS # include // for _mkdir & _rmdir #else @@ -38,8 +40,6 @@ #include #include -#include "Modules/Output/FileOutputAIMC.h" - namespace aimc { FileOutputAIMC::FileOutputAIMC(Parameters *params) : Module(params) { module_description_ = "File output in AIMC format"; @@ -47,8 +47,11 @@ module_type_ = "output"; module_version_ = "$Id: FileOutputAIMC.cc 51 2010-03-30 22:06:24Z tomwalters $"; file_suffix_ = parameters_->DefaultString("file_suffix", ".aimc"); + dump_strobes_ = parameters_->DefaultBool("dump_strobes", false); + strobes_file_suffix_ = parameters_->DefaultString("strobes_file_suffix", ".strobes"); file_handle_ = NULL; + strobes_file_handle_ = NULL; header_written_ = false; frame_period_ms_ = 0.0f; } @@ -56,6 +59,21 @@ FileOutputAIMC::~FileOutputAIMC() { if (file_handle_ != NULL) CloseFile(); + if (strobes_file_handle_ != NULL) + CloseStrobesFile(); +} + +bool FileOutputAIMC::OpenStrobesFile(string &filename) { + if (strobes_file_handle_ != NULL) { + LOG_ERROR(_T("Couldn't open strobes output file. A file is already open.")); + return false; + } + // Check that the output file exists and is writeable + if ((strobes_file_handle_ = fopen(filename.c_str(), "wb")) == NULL) { + LOG_ERROR(_T("Couldn't open output file '%s' for writing."), filename.c_str()); + return false; + } + return true; } bool FileOutputAIMC::OpenFile(string &filename) { @@ -76,6 +94,7 @@ if (initialized_) { WriteHeader(); } + return true; } @@ -101,7 +120,15 @@ string out_filename; out_filename = global_parameters_->GetString("output_filename_base") + file_suffix_; OpenFile(out_filename); - + if (dump_strobes_) { + if (strobes_file_handle_ != NULL) { + CloseStrobesFile(); + } + string strobes_filename = + global_parameters_->GetString("output_filename_base") + + strobes_file_suffix_; + OpenStrobesFile(strobes_filename); + } } void FileOutputAIMC::WriteHeader() { @@ -157,6 +184,36 @@ } } frame_count_++; + + if (dump_strobes_) { + if (strobes_file_handle_ == NULL) { + LOG_ERROR(_T("Couldn't process file output for strobes. No srobes file is open." + "Please call FileOutputAIMC::OpenStrobesFile first")); + return; + } + int strobe; + for (int ch = 0; ch < input.channel_count(); ch++) { + const int kStartOfStrobeRow = -65535; + strobe = kStartOfStrobeRow; + fwrite(&strobe, sizeof(strobe), 1, strobes_file_handle_); + for (int i = 0; i < static_cast(input.get_strobes(ch).size()); + i++) { + strobe = input.get_strobes(ch)[i]; + fwrite(&strobe, sizeof(strobe), 1, strobes_file_handle_); + } + } + } + +} + +bool FileOutputAIMC::CloseStrobesFile() { + if (strobes_file_handle_ == NULL) + return false; + + // And close the file + fclose(strobes_file_handle_); + strobes_file_handle_ = NULL; + return true; } bool FileOutputAIMC::CloseFile() { diff -r 256caa099e32 -r 087f3b3c36d3 src/Modules/Output/FileOutputAIMC.h --- a/src/Modules/Output/FileOutputAIMC.h Fri Apr 19 00:26:23 2013 +0000 +++ b/src/Modules/Output/FileOutputAIMC.h Tue May 07 14:24:33 2013 +0000 @@ -40,16 +40,18 @@ */ explicit FileOutputAIMC(Parameters *pParam); ~FileOutputAIMC(); - - /*! \brief Initialize the output to AIMC. + virtual void Process(const SignalBank &input); + private: + /*! \brief Initialize the output to AIMC. * \param *filename Filename of the ouptut file to be created. * If the file exists it will be overwritten * \return Returns true on success of initialization. */ bool OpenFile(string &filename); bool CloseFile(); - virtual void Process(const SignalBank &input); - private: + bool OpenStrobesFile(string &filename); + bool CloseStrobesFile(); + virtual bool InitializeInternal(const SignalBank &input); virtual void ResetInternal(); @@ -62,6 +64,7 @@ /*! \brief Internal pointer to the output file */ FILE *file_handle_; + FILE *strobes_file_handle_; /*! \brief Count of the number of samples in the file, written on close */ @@ -72,6 +75,8 @@ float sample_rate_; float frame_period_ms_; string file_suffix_; + bool dump_strobes_; + string strobes_file_suffix_; }; } // namespace aimc diff -r 256caa099e32 -r 087f3b3c36d3 src/Modules/Output/Graphics/Devices/GraphicsOutputDeviceMovie.cc --- a/src/Modules/Output/Graphics/Devices/GraphicsOutputDeviceMovie.cc Fri Apr 19 00:26:23 2013 +0000 +++ b/src/Modules/Output/Graphics/Devices/GraphicsOutputDeviceMovie.cc Tue May 07 14:24:33 2013 +0000 @@ -168,7 +168,7 @@ char sCmdLine[1024]; //!\todo check that snprintf does not want a larger buffer snprintf(sCmdLine, sizeof(sCmdLine)/sizeof(sCmdLine[0]), "%s -y -i \"%s\" -r %.2f -i \"%s%%06d.png\" " - "-sameq -r %.2f -ar 44100 -acodec pcm_s16le %s \"%s\"", + "-qscale 0 -r %.2f -ar 44100 -acodec pcm_s16le %s \"%s\"", sffmpegPath, sound_filename_.c_str(), frame_rate, directory_.c_str(), frame_rate, sCodecOptions, movie_filename_.c_str()); printf("%s", sCmdLine);