// file: $isip/class/sp/FrontEnd/FrontEndBase.h
// version: $Id: FrontEndBase.h 9236 2003-06-23 18:12:22Z gao $
//

// this file defines the FrontEndBase class
//

// make sure definitions are only made once
//
#ifndef ISIP_FRONTEND_BASE
#define ISIP_FRONTEND_BASE

// forward class definitions
//
class Sdb;
class Filename;

// isip include files
//
#ifndef ISIP_STRING
#include <String.h>
#endif

#ifndef ISIP_NAME_MAP
#include <NameMap.h>
#endif

// forward class definitions
//
class VectorFloat;

// FrontEndBase: this class defines an interface contract for all front end
// implementations (e.g., AudioFrontEnd) that allows data (e.g., audio, video)
// to be converted to a feature stream.
//
class FrontEndBase {

  //---------------------------------------------------------------------------
  //
  // public constants
  //
  //---------------------------------------------------------------------------
public:

  static const String CLASS_NAME;
  
  //----------------------------------------
  //
  // i/o related constants
  //
  //----------------------------------------

  //----------------------------------------
  //
  // default values and arguments
  //
  //----------------------------------------

  enum DATA_TYPE { SAMPLED_DATA = 0, FEATURES, DEF_DATA_TYPE = SAMPLED_DATA };

  enum DATA_MODE { NONE = 0, SOF_FEATURES_BINARY, SOF_FEATURES_TEXT, 
		   AUDIO_FILE, RAW_FEATURES,
		   SOF_FEATURES = SOF_FEATURES_BINARY,
		   DEF_DATA_MODE = NONE,
		   DEF_INPUT_DATA_MODE = AUDIO_FILE,
		   DEF_OUTPUT_DATA_MODE = SOF_FEATURES_BINARY };

  static const NameMap DATA_MODE_MAP;
  static const NameMap DATA_TYPE_MAP;
  
  //----------------------------------------
  //
  // error codes
  //
  //----------------------------------------  
  
  static const long ERR = (long)80250;
  
  //---------------------------------------------------------------------------
  //
  // protected data
  //
  //---------------------------------------------------------------------------
protected:

  // declare a verbosity level
  //
  Integral::DEBUG verbosity_d;
  
  // declare a static debug level for all class instantiations
  //
  static Integral::DEBUG debug_level_d;
  
  //---------------------------------------------------------------------------
  //
  // required public methods
  //
  //---------------------------------------------------------------------------
public:

  // method: name
  //
  static const String& name() {
    return CLASS_NAME;
  }
  
  // debug methods
  //
  virtual boolean debug(const unichar* message) const;

  // method: setDebug
  //
  static boolean setDebug(Integral::DEBUG level) {
    debug_level_d = level;
    return true;
  }

  // method: destructor
  //
  virtual ~FrontEndBase() {}

  // method: default constructor
  //
  FrontEndBase() {
    verbosity_d = Integral::NONE;
  }
  
  // assign methods
  //
  virtual boolean assign(const FrontEndBase& arg) = 0;
  
  // i/o methods
  //
  virtual long sofSize() const = 0;
  
  virtual boolean read(Sof& sof_a, long tag, const String& name) = 0;

  virtual boolean write(Sof& sof_a, long tag, const String& name) const = 0;

  virtual boolean readData(Sof& sof_a, const String& pname,
			   long size, boolean param, boolean nested) = 0;

  virtual boolean writeData(Sof& sof_a, const String& param) const = 0;

  // method: setParser
  //
  virtual boolean setParser(SofParser* parser) {
    Error::handle(CLASS_NAME, L"getParser",
		  Error::VIRTUAL_PTR, __FILE__, __LINE__);
    return (SofParser*)NULL;
  }

  // equality methods
  //
  virtual boolean eq(const FrontEndBase& arg) const = 0;

  // clear methods
  //
  virtual boolean clear(Integral::CMODE ctype_a) = 0;
  
  //---------------------------------------------------------------------------
  //
  // class-specific public methods:
  //  set methods
  //
  //---------------------------------------------------------------------------

  // method: setVerbosity
  //
  boolean setVerbosity(Integral::DEBUG verbosity) {
    verbosity_d = verbosity;
    return true;
  }

  // set the number of channels
  //
  virtual boolean setNumChannels(long arg) = 0;

  // set the name of the required features
  //
  virtual boolean setCoefName(const String& name) = 0;

  // set the output basename
  //
  virtual boolean setOutputBasename(String& basename) = 0;

  // set the output extension
  //
  virtual boolean setOutputExtension(String& extension) = 0;  

  // set output directory
  //
  virtual boolean setOutputDirectory(const String& new_dir) = 0;

  // set directory preserve level
  //
  virtual boolean setOutputPreserve(long new_preserve_level) = 0;
    
  // set the output suffix
  //
  virtual boolean setOutputSuffix(String& suffix) = 0;

  // set the output type
  //
  virtual boolean setOutputType(File::TYPE type) = 0;
  
  //---------------------------------------------------------------------------
  //
  // class-specific public methods:
  //  get methods
  //
  //---------------------------------------------------------------------------

  // method: getVerbosity
  //
  Integral::DEBUG getVerbosity() const {
    return verbosity_d;
  }

  // get the total number of frames
  //
  virtual long getNumFeatures() = 0;
  
  // get the number of channels
  //
  virtual long getNumChannels() const = 0;

  // get the total number of frames
  //
  virtual long getNumFrames() = 0;

  // get the frame duration
  //
  virtual float getFrameDuration() const = 0;  

  // get the utterance ID for the given file
  //
  virtual const String& getID() const = 0;

  // get the output basename
  //
  virtual const boolean getOutputBasename(String& basename) const = 0;  

  // get the output extension
  //
  virtual const boolean getOutputExtension(String& extension) const = 0;

  // get the output suffix
  //
  virtual const boolean getOutputSuffix(String& suffix) const = 0;  

  // get the output type
  //
  virtual const File::TYPE& getOutputType() const = 0;
  
  // determine if a coefficient is an input
  //
  virtual boolean isNameInput(const String& name) const = 0;

  //  determine if input file exists
  //
  virtual boolean getInputFlag() const = 0; 
  
  //---------------------------------------------------------------------------
  //
  // class-specific public methods:
  //  core FrontEndBase interface contract methods
  //
  //---------------------------------------------------------------------------

  // identification methods
  //
  virtual const String& className() const = 0;
  
  // get the coeff vector for a given frame
  //
  virtual boolean getVector(VectorFloat& coeffs, long channel,
			    long frame_index) = 0;

  // open and close the input files
  //
  virtual boolean open(const Filename& input) = 0;
  virtual boolean close() = 0;

  // init method
  //
  virtual boolean init(float start_time, float stop_time, int channel) = 0;
  
  // process an entire file at a time
  //
  virtual boolean run(const Filename& input) = 0;

  //---------------------------------------------------------------------------
  //
  // private methods
  //
  //---------------------------------------------------------------------------
private:
};

// end of include file
//
#endif
