// file: $isip/class/algo/Output/Output.h // version: $Id: Output.h 9236 2003-06-23 18:12:22Z gao $ // // make sure definitions are only made once // #ifndef ISIP_OUTPUT #define ISIP_OUTPUT // isip include files // #ifndef ISIP_ALGORITHM_BASE #include #endif #ifndef ISIP_COMMAND_LINE #include #endif #ifndef ISIP_AUDIO_FILE #include #endif #ifndef ISIP_FEATURE_FILE #include #endif #ifndef ISIP_FILENAME #include #endif #ifndef ISIP_STRING #include #endif #ifndef ISIP_MEMORY_MANAGER #include #endif // Output: this is another class that is primarily used to facilitate // recipe processing. this class is used to output data to a file. // a recipe can have multiple outputs, and each output can write // multichannel data in a variety of formats. // class Output : public AlgorithmBase { //--------------------------------------------------------------------------- // // public Outputs // //--------------------------------------------------------------------------- public: // define the class name // static const String CLASS_NAME; //---------------------------------------- // // other important constants // //---------------------------------------- // define the algorithm choices // enum ALGORITHM { DATA = 0, DEF_ALGORITHM = DATA}; // define the implementation choices // enum IMPLEMENTATION { FEATURES = 0, SAMPLED_DATA, DEF_IMPLEMENTATION = FEATURES}; // define the static NameMap objects // static const NameMap ALGO_MAP; static const NameMap IMPL_MAP; //---------------------------------------- // // i/o related constants // //---------------------------------------- static const String DEF_PARAM; static const String PARAM_ALGORITHM; static const String PARAM_IMPLEMENTATION; static const String PARAM_BASENAME; static const String PARAM_AUDIO_OUTPUT; static const String PARAM_FEATURE_OUTPUT; static const String PARAM_DMODE; //---------------------------------------- // // default values and arguments // //---------------------------------------- // the default filename // static const String DEF_FILENAME; // a default temporary filename // static const String DEF_TMP_FILE; //---------------------------------------- // // error codes // //---------------------------------------- static const int32 ERR = 71400; //--------------------------------------------------------------------------- // // protected data // //--------------------------------------------------------------------------- protected: // algorithm name // ALGORITHM algorithm_d; // implementation name // IMPLEMENTATION implementation_d; // declare variables to hold filename information // Filename input_filename_d; Filename output_filename_d; String output_basename_d; String output_directory_d; String output_extension_d; Long output_preserve_d; String output_suffix_d; // the audiofile or featurefile to write out // AudioFile audio_output_d; FeatureFile feature_output_d; // static memory manager // static MemoryManager mgr_d; //--------------------------------------------------------------------------- // // required public methods // //--------------------------------------------------------------------------- public: // method: name // static const String& name() { return CLASS_NAME; } // other static methods // static bool8 diagnose(Integral::DEBUG debug_level); // debug methods: // setDebug is inherited from the base class // bool8 debug(const unichar* msg) const; // method: destructor // ~Output() {} // method: default constructor // Output(ALGORITHM algorithm = DEF_ALGORITHM, IMPLEMENTATION implementation = DEF_IMPLEMENTATION) { algorithm_d = algorithm; implementation_d = implementation; output_extension_d.assign(Filename::DEF_EXTENSION); output_suffix_d.assign(Filename::DEF_SUFFIX); output_directory_d.clear(); output_preserve_d.clear(); is_valid_d = false; } // method: copy constructor // Output(const Output& arg) { assign(arg); } // assign methods // bool8 assign(const Output& arg); // method: operator= // Output& operator= (const Output& arg) { assign(arg); return *this; } // i/o methods // int32 sofSize() const; bool8 read(Sof& sof, int32 tag, const String& name = CLASS_NAME); bool8 write(Sof& sof, int32 tag, const String& name = CLASS_NAME) const; bool8 readData(Sof& sof, const String& pname = DEF_PARAM, int32 size = SofParser::FULL_OBJECT, bool8 param = true, bool8 nested = false); bool8 writeData(Sof& sof, const String& pname = DEF_PARAM) const; // equality methods // bool8 eq(const Output& arg) const; // method: new // static void* operator new(size_t size) { return mgr_d.get(); } // method: new[] // static void* operator new[](size_t size) { return mgr_d.getBlock(size); } // method: delete // static void operator delete(void* ptr) { mgr_d.release(ptr); } // method: delete[] // static void operator delete[](void* ptr) { mgr_d.releaseBlock(ptr); } // method: setGrowSize // static bool8 setGrowSize(int32 grow_size) { return mgr_d.setGrow(grow_size); } // other memory management methods // bool8 clear(Integral::CMODE ctype = Integral::DEF_CMODE); //--------------------------------------------------------------------------- // // class-specific public methods: // set methods // //--------------------------------------------------------------------------- // method: setAlgorithm // bool8 setAlgorithm(ALGORITHM algorithm) { algorithm_d = algorithm; is_valid_d = false; return true; } // method: setImplementation // bool8 setImplementation(IMPLEMENTATION implementation) { implementation_d = implementation; is_valid_d = false; return true; } // method: setInputFilename // bool8 setInputFilename(String& inputfilename) { return input_filename_d.assign(inputfilename); } // method: setOutputFilename // bool8 setOutputFilename(String& filename) { output_filename_d.assign(filename); is_valid_d = false; return true; } // method: setOutputDirectory // bool8 setOutputDirectory(const String& new_dir) { output_directory_d.assign(new_dir); is_valid_d = false; return true; } // method: setOutputBasename // bool8 setOutputBasename(String& basename) { output_basename_d.assign(basename); is_valid_d = false; return true; } // method: setOutputExtension // bool8 setOutputExtension(const String& extension) { output_extension_d = extension; is_valid_d = false; return true; } // method: setOutputPreserve // bool8 setOutputPreserve(int32 new_preserve_level) { output_preserve_d.assign(new_preserve_level); is_valid_d = false; return true; } // method: setOutputSuffix // bool8 setOutputSuffix(String& suffix) { output_suffix_d = suffix; is_valid_d = false; return true; } // method: setOutputType // bool8 setOutputType(File::TYPE type) { if (type == File::TEXT) { feature_output_d.setFileType(FeatureFile::TEXT); audio_output_d.setFileType(AudioFile::TEXT); } else { feature_output_d.setFileType(FeatureFile::BINARY); audio_output_d.setFileType(AudioFile::BINARY); } return true; } // method: setFileType // bool8 setFileType(AudioFile::FILE_TYPE file_type) { audio_output_d.setFileType(file_type); return true; } // method: setFileType // bool8 setFileType(FeatureFile::FILE_TYPE file_type) { feature_output_d.setFileType(file_type); return true; } // method: setFileFormat // bool8 setFileFormat(AudioFile::FILE_FORMAT file_format) { audio_output_d.setFileFormat(file_format); return true; } // method: setFileFormat // bool8 setFileFormat(FeatureFile::FILE_FORMAT file_format) { feature_output_d.setFileFormat(file_format); return true; } // method: set // bool8 set(ALGORITHM algorithm = DEF_ALGORITHM, IMPLEMENTATION implementation = DEF_IMPLEMENTATION) { algorithm_d = algorithm; implementation_d = implementation; is_valid_d = false; return true; } //--------------------------------------------------------------------------- // // class-specific public methods: // get methods // //--------------------------------------------------------------------------- // method: getAlgorithm // ALGORITHM getAlgorithm() const { return algorithm_d; } // method: getImplementation // IMPLEMENTATION getImplementation() const { return implementation_d; } // method: getInputFilename // bool8 getInputFilename(Filename& inputfilename) const{ return inputfilename.assign(input_filename_d); } // method: getOutputFilename // bool8 getOutputFilename(String& filename) { init(); filename = output_filename_d; return true; } // method: getOutputDirectory // bool8 getOutputDirectory(String& directory) const { directory = output_directory_d; return true; } // method: getOutputBasename // bool8 getOutputBasename(String& basename) const{ basename = output_basename_d; return true; } // method: getOutputExtension // bool8 getOutputExtension(String& extension) const{ extension = output_extension_d; return true; } // method: getOutputPreserve // int32 getOutputPreserve() const { return (int32)output_preserve_d; } // method: getOutputSuffix // bool8 getOutputSuffix(String& suffix) const{ suffix = output_suffix_d; return true; } // method: get // bool8 get(ALGORITHM& algorithm, IMPLEMENTATION& implementation) const{ algorithm = algorithm_d; implementation = implementation_d; return true; } //--------------------------------------------------------------------------- // // class-specific public methods: // computational methods // //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- // // class-specific public methods: // public methods required by the AlgorithmBase interface contract // //--------------------------------------------------------------------------- // assign method // bool8 assign(const AlgorithmBase& arg); // equality method // bool8 eq(const AlgorithmBase& arg) const; // method: className // const String& className() const { return CLASS_NAME; } // initialization method // bool8 init(); // apply method // bool8 apply(Vector& output, const Vector< CircularBuffer >& input); // method to set the parser // bool8 setParser(SofParser* parser); //--------------------------------------------------------------------------- // // private methods // //--------------------------------------------------------------------------- private: // algorithm-specific i/o methods: DATA // bool8 readDataData(Sof& sof, const String& pname, int32 size, bool8 param, bool8 nested); bool8 writeDataData(Sof& sof, const String& pname) const; // implementation specific compute methods: FEATURES // bool8 computeFeatures(Vector& output, const Vector< CircularBuffer >& input); // implementation specific compute methods: SAMPLED_DATA // bool8 computeSampledData(Vector& output, const Vector< CircularBuffer >& input); // transformation methods // bool8 transformName(); }; // end of include file // #endif