sness@607: // Copyright 2006-2010, Thomas Walters, Willem van Engen sness@607: // sness@607: // AIM-C: A C++ implementation of the Auditory Image Model sness@607: // http://www.acousticscale.org/AIMC sness@607: // sness@607: // Licensed under the Apache License, Version 2.0 (the "License"); sness@607: // you may not use this file except in compliance with the License. sness@607: // You may obtain a copy of the License at sness@607: // sness@607: // http://www.apache.org/licenses/LICENSE-2.0 sness@607: // sness@607: // Unless required by applicable law or agreed to in writing, software sness@607: // distributed under the License is distributed on an "AS IS" BASIS, sness@607: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. sness@607: // See the License for the specific language governing permissions and sness@607: // limitations under the License. sness@607: sness@607: /*! sness@607: * \file sness@607: * \brief File output to JSON format sness@607: * sness@607: * \author Thomas Walters sness@607: * \author Willem van Engen sness@607: * \date created 2006/10/30 sness@607: * \version \$Header$ sness@607: */ sness@607: sness@607: #ifndef AIMC_MODULES_OUTPUT_JSON_H_ sness@607: #define AIMC_MODULES_OUTPUT_JSON_H_ sness@607: sness@607: #include sness@607: #include sness@607: #include sness@607: sness@607: // using namespace std; sness@607: sness@607: #include "Support/Module.h" sness@607: #include "Support/SignalBank.h" sness@607: sness@607: namespace aimc { sness@607: class FileOutputJSON : public Module { sness@607: public: sness@607: /*! \brief Create a new file output for an JSON format file. sness@607: */ sness@607: explicit FileOutputJSON(Parameters *pParam); sness@607: ~FileOutputJSON(); sness@607: virtual void Process(const SignalBank &input); sness@607: private: sness@607: /*! \brief Initialize the output to JSON. sness@607: * \param *filename Filename of the ouptut file to be created. sness@607: * If the file exists it will be overwritten sness@607: * \return Returns true on success of initialization. sness@607: */ sness@607: bool OpenFile(string &filename); sness@607: bool CloseFile(); sness@607: bool OpenStrobesFile(string &filename); sness@607: bool CloseStrobesFile(); sness@607: sness@607: virtual bool InitializeInternal(const SignalBank &input); sness@607: virtual void ResetInternal(); sness@607: sness@607: void WriteHeader(); sness@607: sness@607: /*! \brief Whether initialization is done or not sness@607: */ sness@607: bool header_written_; sness@607: sness@607: /*! \brief Internal pointer to the output file sness@607: */ sness@607: // FILE *file_handle_; sness@607: // FILE *strobes_file_handle_; sness@607: std::ofstream file_handle_; sness@607: sness@607: /*! \brief Count of the number of samples in the file, written on close sness@607: */ sness@607: int frame_count_; sness@607: sness@607: int channel_count_; sness@607: int buffer_length_; sness@607: float sample_rate_; sness@607: float frame_period_ms_; sness@607: string file_suffix_; sness@607: bool dump_strobes_; sness@607: string strobes_file_suffix_; sness@607: }; sness@607: } // namespace aimc sness@607: sness@607: #endif // AIMC_MODULES_OUTPUT_JSON_H_ sness@607: