// file: $isip/class/search/StackSearch/ssrch_16.cc
// version: $Id: ssrch_16.cc 9296 2003-08-23 20:27:52Z parihar $
//

// isip include files
//
#include "StackSearch.h"

// method: decode
//
// arguments:
//  Vector<FrontEnd>& vector_fe: (input) front-ends providing data
//  long num_frames: (input) number of frames to decode
//
// return: logical error status
//
// this is the decoding wrapper method for the front-end input
//
boolean StackSearch::decode(Vector<FrontEnd>& vector_fe_a, long num_frames_a) {
  
  long num_frames_available =
    vector_fe_a(vector_fe_a.length() - 1).getNumFrames();

  // set the number of frames
  //
  if (num_frames_a == ALL_FRAMES) {
    
    // decode all available data
    //
    num_frames_d = num_frames_available;
  }
  else {
    
    // decode only specified number of frames
    //
    if (num_frames_a > num_frames_available) {
      
      // output warning
      //
      return Error::handle(name(),
			   L"decode - number of frames to decode exceeds the number of features available from front end",
			   Error::ARG, __FILE__, __LINE__, Error::WARNING);
    }
    else {
      num_frames_d = num_frames_a;
    }
  }

  // initialize required number of features
  //
  features_d.setLength(num_frames_d);

  for (long curr_frame = 0; curr_frame < num_frames_d; curr_frame++) {
    
    // assign features from the front end
    //
    // loop over the frontends
    //
    for (long i = 0; i < vector_fe_a.length(); i++) {
      vector_fe_a(i).getVector(features_d(curr_frame), 0, curr_frame);
    }
  }

  // call the core decoding method common for both feature and front
  // end input data
  //
  decode();
  
  // exit gracefully
  //
  return true;
}

// method: decode
//
// arguments:
//  Vector<VectorFloat>& data: (input) feature data
//  long num_frames: (input) number of frames to decode
//
// return: logical error status
//
// this is the decoding wrapper method for the features input
//
boolean StackSearch::decode(Vector<VectorFloat>& data_a, long num_frames_a) {

  long num_frames_available = data_a.length();

  // set the number of frames
  //
  if (num_frames_a == ALL_FRAMES) {
    
    // decode all available data
    //
    num_frames_d = num_frames_available;
  }
  else {
    
    // decode only specified number of frames
    //
    if (num_frames_a > num_frames_available) {
      
      // output warning
      //
      return Error::handle(name(),
			   L"decode - number of frames to decode exceeds the number of features available from the input feature vector",
			   Error::ARG, __FILE__, __LINE__, Error::WARNING);
    }
    else {
      num_frames_d = num_frames_a;
    }
  }

  // initialize required number of features
  //
  features_d.setLength(num_frames_d);

  for (long curr_frame = 0; curr_frame < num_frames_d; curr_frame++) {
    
    // assign features from the input feature vector
    //
    features_d(curr_frame) = data_a(curr_frame);
  }

  // call the core decoding method common for both feature and front
  // end input data
  //
  decode();
  
  // exit gracefully
  //
  return true;
}
